From 88909bab49a062c5b2ef8d6470b3d53dcf0b05af Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 9 Feb 2021 16:50:48 +0900 Subject: [PATCH] GNU/Linux: Make sure thread struct is cleared. Also, added a comment for makecontext. Signed-off-by: NIIBE Yutaka --- ChangeLog | 2 ++ chopstx-gnu-linux.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0e8fe04..d361aee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2021-02-09 NIIBE Yutaka + * chopstx-gnu-linux.c (chopstx_create_arch): Clear TP. + * example-cdc-gnu-linux/sample.c (main): Handle timeout by canceling input. diff --git a/chopstx-gnu-linux.c b/chopstx-gnu-linux.c index d562030..fcd7464 100644 --- a/chopstx-gnu-linux.c +++ b/chopstx-gnu-linux.c @@ -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. */ chx_cpu_sched_lock (); + memset (tp, 0, sizeof (struct chx_thread)); getcontext (&tp->tc); tp->tc.uc_stack.ss_sp = (void *)stack_addr; tp->tc.uc_stack.ss_size = stack_size; 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, 4, thread_entry, arg); chx_cpu_sched_unlock ();