From: Dragos Iulian Argint Date: Wed, 26 Oct 2022 21:05:59 +0000 (+0300) Subject: Set tid to 0 for the main thread X-Git-Tag: RELEASE-0.11.0~22 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=fa60dce817118b648cba9f5a57596d4206b33b3a;p=unikraft%2Flibs%2Fmusl.git Set tid to 0 for the main thread This commit ads in the Config.uk the following default selection: `LIBPOSIX_PROCESS_INIT_PIDS`, which allows pid,tid assignation However, there is a bug in the assignment of tids that makes the tid of the main thread not available when the LIBC TCB (i.e. pthread structure) is initialized. The currently adopted solution is to hardcode the tid to 0. Signed-off-by: Dragos Iulian Argint Signed-off-by: Robert Kuban Reviewed-by: Florin Postolache Reviewed-by: Simon Kuenzer Reviewed-by: Cezar Craciunoiu Reviewed-by: Razvan Deaconescu Reviewed-by: Robert Kuban Approved-by: Simon Kuenzer Tested-by: Unikraft CI GitHub-Closes: #9 --- diff --git a/Config.uk b/Config.uk index 9906e22..9684058 100644 --- a/Config.uk +++ b/Config.uk @@ -9,6 +9,7 @@ menuconfig LIBMUSL select LIBVFSCORE select LIBPOSIX_PROCESS select LIBPOSIX_PROCESS_PIDS + select LIBPOSIX_PROCESS_INIT_PIDS select LIBPOSIX_PROCESS_CLONE select LIBPOSIX_FUTEX select LIBUKSCHED_TCB_INIT diff --git a/__uk_init_tls.c b/__uk_init_tls.c index 1cf3dce..10c1140 100644 --- a/__uk_init_tls.c +++ b/__uk_init_tls.c @@ -119,10 +119,15 @@ static int __uk_init_tp(void *p) * The original musl code will invoke here a `SYS_set_tid_address` * syscall, to set the tid user space address in the Kernel. * FIXME: Currently this does not return the tid assigned for the caller, - * it returns an error code (-95) because probably there is no tid assigned - * at this stage. It is not a really big problem right now. + * it returns an error code (-95, -ENOTSUP) because posix_process_init has not been + * called at this stage, but will be called via uk_late_initcall. + * It is not a really big problem right now. Since this is the main thread, + * nobody should ever wait for it, and we can just assume thread id 0. */ td->tid = uk_syscall_r_set_tid_address(&td->tid); + if (td->tid < 0) { + td->tid = 0; + } td->locale = &libc.global_locale; td->robust_list.head = &td->robust_list.head; return 0;