Skip to content

Commit 21cfadf

Browse files
committed
runtime: avoid receiving preemotion signal while exec'ing
The iOS kernel has the same problem as the macOS kernel. Extend the workaround of #41702 (CL 262438 and CL 262817) to iOS. Updates #35851. Change-Id: I7ccec00dc96643c08c5be8b385394856d0fa0f64 Reviewed-on: https://go-review.googlesource.com/c/go/+/275293 Trust: Cherry Zhang <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 7358064 commit 21cfadf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/runtime/proc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ found:
13631363
checkdead()
13641364
unlock(&sched.lock)
13651365

1366-
if GOOS == "darwin" {
1366+
if GOOS == "darwin" || GOOS == "ios" {
13671367
// Make sure pendingPreemptSignals is correct when an M exits.
13681368
// For #41702.
13691369
if atomic.Load(&m.signalPending) != 0 {
@@ -3852,7 +3852,7 @@ func syscall_runtime_BeforeExec() {
38523852

38533853
// On Darwin, wait for all pending preemption signals to
38543854
// be received. See issue #41702.
3855-
if GOOS == "darwin" {
3855+
if GOOS == "darwin" || GOOS == "ios" {
38563856
for int32(atomic.Load(&pendingPreemptSignals)) > 0 {
38573857
osyield()
38583858
}

src/runtime/signal_unix.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func doSigPreempt(gp *g, ctxt *sigctxt) {
336336
atomic.Xadd(&gp.m.preemptGen, 1)
337337
atomic.Store(&gp.m.signalPending, 0)
338338

339-
if GOOS == "darwin" {
339+
if GOOS == "darwin" || GOOS == "ios" {
340340
atomic.Xadd(&pendingPreemptSignals, -1)
341341
}
342342
}
@@ -352,12 +352,12 @@ const preemptMSupported = true
352352
func preemptM(mp *m) {
353353
// On Darwin, don't try to preempt threads during exec.
354354
// Issue #41702.
355-
if GOOS == "darwin" {
355+
if GOOS == "darwin" || GOOS == "ios" {
356356
execLock.rlock()
357357
}
358358

359359
if atomic.Cas(&mp.signalPending, 0, 1) {
360-
if GOOS == "darwin" {
360+
if GOOS == "darwin" || GOOS == "ios" {
361361
atomic.Xadd(&pendingPreemptSignals, 1)
362362
}
363363

@@ -369,7 +369,7 @@ func preemptM(mp *m) {
369369
signalM(mp, sigPreempt)
370370
}
371371

372-
if GOOS == "darwin" {
372+
if GOOS == "darwin" || GOOS == "ios" {
373373
execLock.runlock()
374374
}
375375
}
@@ -432,7 +432,7 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
432432
// no non-Go signal handler for sigPreempt.
433433
// The default behavior for sigPreempt is to ignore
434434
// the signal, so badsignal will be a no-op anyway.
435-
if GOOS == "darwin" {
435+
if GOOS == "darwin" || GOOS == "ios" {
436436
atomic.Xadd(&pendingPreemptSignals, -1)
437437
}
438438
return

0 commit comments

Comments
 (0)