aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_linux_386.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/sys_linux_386.s')
-rw-r--r--src/runtime/sys_linux_386.s42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
index 0f6d4bbb5e..f9dec7597c 100644
--- a/src/runtime/sys_linux_386.s
+++ b/src/runtime/sys_linux_386.s
@@ -379,9 +379,18 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
#define SEG_NOT_PRESENT 0x20
#define USEABLE 0x40
+// `-1` means the kernel will pick a TLS entry on the first setldt call,
+// which happens during runtime init, and that we'll store back the saved
+// entry and reuse that on subsequent calls when creating new threads.
+DATA runtime·tls_entry_number+0(SB)/4, $-1
+GLOBL runtime·tls_entry_number(SB), NOPTR, $4
+
// setldt(int entry, int address, int limit)
+// We use set_thread_area, which mucks with the GDT, instead of modify_ldt,
+// which would modify the LDT, but is disabled on some kernels.
+// The name, setldt, is a misnomer, although we leave this name as it is for
+// the compatibility with other platforms.
TEXT runtime·setldt(SB),NOSPLIT,$32
- MOVL entry+0(FP), BX // entry
MOVL address+4(FP), CX // base address
/*
@@ -400,18 +409,19 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
ADDL $0x8, CX // address
MOVL CX, 0(CX)
+ // get entry number
+ MOVL runtime·tls_entry_number(SB), DX
+
// set up user_desc
LEAL 16(SP), AX // struct user_desc
- MOVL BX, 0(AX)
- MOVL CX, 4(AX)
- MOVL $0xfffff, 8(AX)
+ MOVL DX, 0(AX) // unsigned int entry_number
+ MOVL CX, 4(AX) // unsigned long base_addr
+ MOVL $0xfffff, 8(AX) // unsigned int limit
MOVL $(SEG_32BIT|LIMIT_IN_PAGES|USEABLE|CONTENTS_DATA), 12(AX) // flag bits
- // call modify_ldt
- MOVL $1, BX // func = 1 (write)
- MOVL AX, CX // user_desc
- MOVL $16, DX // sizeof(user_desc)
- MOVL $123, AX // syscall - modify_ldt
+ // call set_thread_area
+ MOVL AX, BX // user_desc
+ MOVL $243, AX // syscall - set_thread_area
CALL *runtime·_vdso(SB)
// breakpoint on error
@@ -419,10 +429,18 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
JLS 2(PC)
INT $3
- // compute segment selector - (entry*8+7)
- MOVL entry+0(FP), AX
+ // read allocated entry number back out of user_desc
+ LEAL 16(SP), AX // get our user_desc back
+ MOVL 0(AX), AX
+
+ // store entry number if the kernel allocated it
+ CMPL DX, $-1
+ JNE 2(PC)
+ MOVL AX, runtime·tls_entry_number(SB)
+
+ // compute segment selector - (entry*8+3)
SHLL $3, AX
- ADDL $7, AX
+ ADDL $3, AX
MOVW AX, GS
RET