aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_linux_riscv64.s
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2022-10-18 12:01:18 -0400
committerMichael Pratt <mpratt@google.com>2022-10-18 20:57:24 +0000
commite252dcf9d38ce9192bccacb7e33867cbfbd22b6c (patch)
treea1b53f0729de1a567f3597d85b1170a1ee790d5d /src/runtime/sys_linux_riscv64.s
parenta8e4b8c2a793de420ebbe7120c132f0b090d068c (diff)
downloadgo-e252dcf9d38ce9192bccacb7e33867cbfbd22b6c.tar.xz
runtime: always keep global reference to mp until mexit completes
Ms are allocated via standard heap allocation (`new(m)`), which means we must keep them alive (i.e., reachable by the GC) until we are completely done using them. Ms are primarily reachable through runtime.allm. However, runtime.mexit drops the M from allm fairly early, long before it is done using the M structure. If that was the last reference to the M, it is now at risk of being freed by the GC and used for some other allocation, leading to memory corruption. Ms with a Go-allocated stack coincidentally already keep a reference to the M in sched.freem, so that the stack can be freed lazily. This reference has the side effect of keeping this Ms reachable. However, Ms with an OS stack skip this and are at risk of corruption. Fix this lifetime by extending sched.freem use to all Ms, with the value of mp.freeWait determining whether the stack needs to be freed or not. Fixes #56243. Change-Id: Ic0c01684775f5646970df507111c9abaac0ba52e Reviewed-on: https://go-review.googlesource.com/c/go/+/443716 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/sys_linux_riscv64.s')
-rw-r--r--src/runtime/sys_linux_riscv64.s2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/sys_linux_riscv64.s b/src/runtime/sys_linux_riscv64.s
index f4fb1c124b..d1558fd6f7 100644
--- a/src/runtime/sys_linux_riscv64.s
+++ b/src/runtime/sys_linux_riscv64.s
@@ -57,7 +57,7 @@ TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
ECALL
RET
-// func exitThread(wait *uint32)
+// func exitThread(wait *atomic.Uint32)
TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
MOV wait+0(FP), A0
// We're done using the stack.