]> xenbits.xensource.com Git - unikraft/libs/musl.git/commitdiff
Set tid to 0 for the main thread
authorDragos Iulian Argint <dragosargint21@gmail.com>
Wed, 26 Oct 2022 21:05:59 +0000 (00:05 +0300)
committerUnikraft <monkey@unikraft.io>
Thu, 24 Nov 2022 11:56:36 +0000 (11:56 +0000)
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 <dragosargint21@gmail.com>
Signed-off-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Florin Postolache <florin.postolache80@gmail.com>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #9

Config.uk
__uk_init_tls.c

index 9906e22578d6f771acdd4896bd0e44a51633b3f7..968405817eb2a6b3d7d6ed284cf9416d1a1534db 100644 (file)
--- 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
index 1cf3dced0710b1b3e8fa0f2595b3ca110eca3629..10c1140b916c8db5b441155bbc72e53815b6348b 100644 (file)
@@ -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;