GNU/Linux: Make sure thread struct is cleared.

Also, added a comment for makecontext.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2021-02-09 16:50:48 +09:00
parent 66f08d87e4
commit 88909bab49
2 changed files with 14 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
2021-02-09 NIIBE Yutaka <gniibe@fsij.org> 2021-02-09 NIIBE Yutaka <gniibe@fsij.org>
* chopstx-gnu-linux.c (chopstx_create_arch): Clear TP.
* example-cdc-gnu-linux/sample.c (main): Handle timeout by canceling * example-cdc-gnu-linux/sample.c (main): Handle timeout by canceling
input. input.

View File

@@ -307,11 +307,23 @@ chopstx_create_arch (uintptr_t stack_addr, size_t stack_size,
* signal blocked. The sigmask will be cleared in chx_thread_start. * signal blocked. The sigmask will be cleared in chx_thread_start.
*/ */
chx_cpu_sched_lock (); chx_cpu_sched_lock ();
memset (tp, 0, sizeof (struct chx_thread));
getcontext (&tp->tc); getcontext (&tp->tc);
tp->tc.uc_stack.ss_sp = (void *)stack_addr; tp->tc.uc_stack.ss_sp = (void *)stack_addr;
tp->tc.uc_stack.ss_size = stack_size; tp->tc.uc_stack.ss_size = stack_size;
tp->tc.uc_link = NULL; tp->tc.uc_link = NULL;
/*
* makecontext is hard to use, actually.
*
* On 32-bit machine, it is not accurate to specify ARGC = 4, because
* it's actually two, but it works.
*
* On 64-bit machine, according to the standard, it should be coded
* to specify (int == 32-bit) arguments that follow ARGC, so it is
* incorrect to specify ARGC=4 and two 64-bit arguments, but it
* works (on x86-64).
*/
makecontext (&tp->tc, (void (*)(void))chx_thread_start, makecontext (&tp->tc, (void (*)(void))chx_thread_start,
4, thread_entry, arg); 4, thread_entry, arg);
chx_cpu_sched_unlock (); chx_cpu_sched_unlock ();