aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_windows_amd64.s
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2023-04-20 17:30:38 +0200
committerQuim Muntal <quimmuntal@gmail.com>2023-04-25 15:37:00 +0000
commit715d53c090ea02dbd73c301684ecbd09b476989e (patch)
tree91becbd7765a53639e91d30c4bd95a9ab5f6ab65 /src/runtime/sys_windows_amd64.s
parent14f833f117dde3c370fb6cb47ce45a34c46eb2de (diff)
downloadgo-715d53c090ea02dbd73c301684ecbd09b476989e.tar.xz
runtime: fallback to TEB arbitrary pointer when TLS slots are full
The Go runtime allocates the TLS slot in the TEB TLS slots instead of using the TEB arbitrary pointer. See CL 431775 for more context. The problem is that the TEB TLS slots array only has capacity for 64 indices, allocating more requires some complex logic that we don't support yet. Although the Go runtime only allocates one index, a Go DLL can be loaded in a process with more than 64 TLS slots allocated, in which case it abort. This CL avoids aborting by falling back to the older behavior, that is to use the TEB arbitrary pointer. Fixes #59213 Change-Id: I39c73286fe2da95aa9c5ec5657ee0979ecbec533 Reviewed-on: https://go-review.googlesource.com/c/go/+/486816 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/sys_windows_amd64.s')
-rw-r--r--src/runtime/sys_windows_amd64.s8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s
index 9699c9679c..e66f444ff5 100644
--- a/src/runtime/sys_windows_amd64.s
+++ b/src/runtime/sys_windows_amd64.s
@@ -10,6 +10,7 @@
// Offsets into Thread Environment Block (pointer in GS)
#define TEB_TlsSlots 0x1480
+#define TEB_ArbitraryPtr 0x28
// void runtime·asmstdcall(void *c);
TEXT runtime·asmstdcall(SB),NOSPLIT,$16
@@ -301,7 +302,11 @@ TEXT runtime·wintls(SB),NOSPLIT,$0
// Assert that slot is less than 64 so we can use _TEB->TlsSlots
CMPQ CX, $64
JB ok
- CALL runtime·abort(SB)
+
+ // Fallback to the TEB arbitrary pointer.
+ // TODO: don't use the arbitrary pointer (see go.dev/issue/59824)
+ MOVQ $TEB_ArbitraryPtr, CX
+ JMP settls
ok:
// Convert the TLS index at CX into
// an offset from TEB_TlsSlots.
@@ -309,5 +314,6 @@ ok:
// Save offset from TLS into tls_g.
ADDQ $TEB_TlsSlots, CX
+settls:
MOVQ CX, runtime·tls_g(SB)
RET