Skip to content

Commit a212083

Browse files
committed
runtime: mark mstart as nowritebarrierrec
mstart is the entry point for new threads, so it certainly can't interact with GC enough to have write barriers. We move the one small piece that is allowed to have write barriers out into its own function. Change-Id: Id9c31d6ffac31d0051fab7db15eb428c11cadbad Reviewed-on: https://go-review.googlesource.com/46035 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent 8f7f46f commit a212083

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/runtime/proc.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,15 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 {
11371137
}
11381138

11391139
// Called to start an M.
1140+
//
1141+
// This must not split the stack because we may not even have stack
1142+
// bounds set up yet.
1143+
//
1144+
// May run during STW (because it doesn't have a P yet), so write
1145+
// barriers are not allowed.
1146+
//
11401147
//go:nosplit
1148+
//go:nowritebarrierrec
11411149
func mstart() {
11421150
_g_ := getg()
11431151

@@ -1176,12 +1184,7 @@ func mstart1() {
11761184
// Install signal handlers; after minit so that minit can
11771185
// prepare the thread to be able to handle the signals.
11781186
if _g_.m == &m0 {
1179-
// Create an extra M for callbacks on threads not created by Go.
1180-
if iscgo && !cgoHasExtraM {
1181-
cgoHasExtraM = true
1182-
newextram()
1183-
}
1184-
initsig(false)
1187+
mstartm0()
11851188
}
11861189

11871190
if fn := _g_.m.mstartfn; fn != nil {
@@ -1198,6 +1201,21 @@ func mstart1() {
11981201
schedule()
11991202
}
12001203

1204+
// mstartm0 implements part of mstart1 that only runs on the m0.
1205+
//
1206+
// Write barriers are allowed here because we know the GC can't be
1207+
// running yet, so they'll be no-ops.
1208+
//
1209+
//go:yeswritebarrierrec
1210+
func mstartm0() {
1211+
// Create an extra M for callbacks on threads not created by Go.
1212+
if iscgo && !cgoHasExtraM {
1213+
cgoHasExtraM = true
1214+
newextram()
1215+
}
1216+
initsig(false)
1217+
}
1218+
12011219
// forEachP calls fn(p) for every P p when p reaches a GC safe point.
12021220
// If a P is currently executing code, this will bring the P to a GC
12031221
// safe point and execute fn on that P. If the P is not executing code

0 commit comments

Comments
 (0)