]> Cypherpunks repositories - gostls13.git/commit
runtime: set up read-only dummy TLS space for needm on Windows
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 7 Apr 2021 19:58:01 +0000 (19:58 +0000)
committerMichael Knyszek <mknyszek@google.com>
Thu, 8 Apr 2021 16:37:24 +0000 (16:37 +0000)
commit31d2556273795ae10709d3bc157ec5d3f0e070a2
treecdc1e039271c09774b0cd57ae37755bb6dfd1a77
parent283b02063b470a0f5df7ba99c9fc801d020763ab
runtime: set up read-only dummy TLS space for needm on Windows

On Windows, TLS is uninitialized for C threads calling into Go code.
In this path, before calling into user Go code, we call into needm which
runs without an m, but whose purpose is to pick one up. While in Go
code, we may occasionally restore the G register from TLS for a number
of reasons. Rather than try to flag all these cases, given that needm
(and its callees) are already somewhat special, just set up a dummy TLS
space for it that's read-only. If it ever actually tries to write to
this space (it shouldn't), it will fail loudly. Otherwise, code that
restores the G register will simply load a zero value, but that's OK
since needm is careful never to require the G at any point, because it
doesn't yet have a valid G. Furthermore, by the time needm returns, it
will have set up TLS properly for a Windows C thread, so there's no need
to do anything extra afterwards.

For #40724.

Change-Id: I34e8095059817e4ee663505e89cda8785b634b98
Reviewed-on: https://go-review.googlesource.com/c/go/+/307872
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/asm_amd64.s
src/runtime/runtime2.go