浏览代码

[LibOS] Correctly initialize TCB to shim_tcb in rs_running_thread()

Isaku Yamahata 6 年之前
父节点
当前提交
4b256bd1ca
共有 2 个文件被更改,包括 14 次插入4 次删除
  1. 13 3
      LibOS/shim/include/shim_tls.h
  2. 1 1
      LibOS/shim/src/bookkeep/shim_thread.c

+ 13 - 3
LibOS/shim/include/shim_tls.h

@@ -78,15 +78,25 @@ struct shim_tcb {
 
 #ifdef IN_SHIM
 
-typedef struct
+/*
+ * This struct must match the one defined in glibc/nptl/sysdeps/x86_64/tls.h
+ * The first 10 members(from tcb to __unused1) are used by Glibc-internal,
+ * they are NOT used by Graphene.
+ * But Graphene needs to preserve the correct offset of shim_tcb so we have to
+ * duplicate these 10 fields from the original Glibc struct.
+ */
+struct __libc_tcb_t;
+typedef struct __libc_tcb_t __libc_tcb_t;
+struct __libc_tcb_t
 {
-    void *                  tcb, * dtv, * self;
+    __libc_tcb_t *          tcb;
+    void *                  dtv, * self;
     int                     mthreads, gscope;
     uintptr_t               sysinfo, sg, pg;
     unsigned long int       vgetcpu_cache[2];
     int                     __unused1;
     shim_tcb_t              shim_tcb;
-} __libc_tcb_t;
+};
 
 #include <stddef.h>
 

+ 1 - 1
LibOS/shim/src/bookkeep/shim_thread.c

@@ -776,7 +776,7 @@ BEGIN_RS_FUNC(running_thread)
              * user_tcb = false
              * in_vm = false
              */
-            init_tcb(shim_libc_tcb()->tcb);
+            init_tcb(&shim_libc_tcb()->shim_tcb);
             set_cur_thread(thread);
         }