-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: TLS slot index over 64 and crash #59213
Comments
Thanks for reporting this issue @funte. Could you share a code sample for the step 2?
Previous comment aside, Windows does support more than 64 slots (more context here), but the Go runtime does not currently support them because they need some special handling on our side which is not there yet. @golang/windows @golang/compiler |
Reproduce project here https://github.com/funte/59213.git |
@funte I can't run Could you confirm this by debugging your test using windbg, run |
Just i mistake the thread id, after change to main thread and run the |
Thanks the detailed report @funte.
That's the cause of the panic in the Go runtime time. Go does not currently support TLS slot indexes equal or higher than 64, this should be fixed. I'll try to send a CL during this development cycle.
Can you share this project? I doubt it is doing exactly the same as the Go runtime does. |
Small recap: Since Go 1.20, the Go runtime allocates the TLS slot in the TEB TLS slots instead of using the TLS arbitrary slot. 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 we abort: go/src/runtime/sys_windows_amd64.s Lines 295 to 304 in 969ab34
I've tried to find an easy solution to support TLS indices higher than 64 that can be backported, but I haven't. It requires more investigation and I won't have bandwidth to get it done before the go1.21 freeze. On the other hand, a good compromise could be to fallback to use the TLS arbitrary slot (as we were doing before g1.20) when the TEB TLS slots are filled, instead of panicking. Although not ideal, at least the regression would be fixed and we could backport it. Thoughts @alexbrainman? |
Change https://go.dev/cl/486816 mentions this issue: |
@funte @fzwoch could you try if the CL 486816 fixes your issues? You can do that by running |
@qmuntal Its work!! |
CL 486816 hasn't been merged yet, reponing the issue till it happens. |
@gopherbot please backport to Go 1.20 |
Backport issue(s) opened: #60535 (for 1.20). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/504475 mentions this issue: |
…en TLS slots are full Note: This CL is cherry-picked from CL 486816 omitting the changes in sys_windows_386.s, which don't apply to go1.20 release branch because windows/386 started using the TEB TLS slot in go1.21 (CL 454675). 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 #60535 Updates #59213 Change-Id: I39c73286fe2da95aa9c5ec5657ee0979ecbec533 Reviewed-on: https://go-review.googlesource.com/c/go/+/486816 Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Alex Brainman <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 715d53c) Reviewed-on: https://go-review.googlesource.com/c/go/+/504475 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go build -buildmode=c-shared -o="a.dll" "./main.go"
:CreateRemoteThread
injecta.dll
to any process.The TlsAlloc returned slot index over 64 and the golang runtime assertion failed.
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: