1 2 3 4 5 6 | inline u32 GetThreadID(void) { u32 ThreadID; asm ("mov %%fs:0x10,%0" : "=r" (ThreadID)); return ThreadID; } |
1 2 3 4 5 | pthread_t __pthread_self (void) { return (pthread_t) THREAD_SELF; } |
1 2 3 4 5 | # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("movl %%gs:%c1,%0" : "=r" (__self) \ : "i" (offsetof (struct pthread, header.self))); \ __self;}) |
1 2 3 4 5 | # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("mov %%fs:%c1,%0" : "=r" (__self) \ : "i" (offsetof (struct pthread, header.self))); \ __self;}) |
1 2 3 4 5 6 7 8 9 10 11 | struct pthread { union { #if !TLS_DTV_AT_TP /* This overlaps the TCB as used for TLS without threads (see tls.h). */ tcbhead_t header; #else struct { ... |
1 2 3 4 5 6 7 8 | typedef struct { void *tcb; /* Pointer to the TCB. Not necessarily the thread descriptor used by libpthread. */ dtv_t *dtv; void *self; /* Pointer to the thread descriptor. */ ... } tcbhead_t; |
1 2 3 4 5 6 7 8 | typedef struct { void *tcb; /* Pointer to the TCB. Not necessarily the thread descriptor used by libpthread. */ dtv_t *dtv; void *self; /* Pointer to the thread descriptor. */ ... } tcbhead_t; |
1 2 3 4 5 6 7 8 9 10 11 12 | inline u32 GetThreadID(void) { void *ThreadID; #if defined(__i386__) asm("movl %%gs:0x08,%0" : "=r"(ThreadID)); #elif defined(__x86_64__) asm("mov %%fs:0x10,%0" : "=r"(ThreadID)); #else #error Unsupported architecture #endif return (u32)ThreadID; } |