Skip to content

Commit 687d9d5

Browse files
committed
runtime: print a message on bad morestack
If morestack runs on the g0 or gsignal stack, it currently performs some abort operation that typically produces a signal (e.g., it does an INT $3 on x86). This is useful if you're running in a debugger, but if you're not, the runtime tries to trap this signal, which is likely to send the program into a deeper spiral of collapse and lead to very confusing diagnostic output. Help out people trying to debug without a debugger by making morestack print an informative message before blowing up. Change-Id: I2814c64509b137bfe20a00091d8551d18c2c4749 Reviewed-on: https://go-review.googlesource.com/31133 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 0ba3c60 commit 687d9d5

File tree

9 files changed

+52
-16
lines changed

9 files changed

+52
-16
lines changed

src/runtime/asm_386.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,15 @@ TEXT runtime·morestack(SB),NOSPLIT,$0-0
354354
MOVL g_m(BX), BX
355355
MOVL m_g0(BX), SI
356356
CMPL g(CX), SI
357-
JNE 2(PC)
357+
JNE 3(PC)
358+
CALL runtime·badmorestackg0(SB)
358359
INT $3
359360

360361
// Cannot grow signal stack.
361362
MOVL m_gsignal(BX), SI
362363
CMPL g(CX), SI
363-
JNE 2(PC)
364+
JNE 3(PC)
365+
CALL runtime·badmorestackgsignal(SB)
364366
INT $3
365367

366368
// Called from f.

src/runtime/asm_amd64.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,15 @@ TEXT runtime·morestack(SB),NOSPLIT,$0-0
331331
MOVQ g_m(BX), BX
332332
MOVQ m_g0(BX), SI
333333
CMPQ g(CX), SI
334-
JNE 2(PC)
334+
JNE 3(PC)
335+
CALL runtime·badmorestackg0(SB)
335336
INT $3
336337

337338
// Cannot grow signal stack (m->gsignal).
338339
MOVQ m_gsignal(BX), SI
339340
CMPQ g(CX), SI
340-
JNE 2(PC)
341+
JNE 3(PC)
342+
CALL runtime·badmorestackgsignal(SB)
341343
INT $3
342344

343345
// Called from f.

src/runtime/asm_amd64p32.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ TEXT runtime·morestack(SB),NOSPLIT,$0-0
249249
// Cannot grow scheduler stack (m->g0).
250250
MOVL m_g0(BX), SI
251251
CMPL g(CX), SI
252-
JNE 2(PC)
252+
JNE 3(PC)
253+
CALL runtime·badmorestackg0(SB)
253254
MOVL 0, AX
254255

255256
// Cannot grow signal stack (m->gsignal).
256257
MOVL m_gsignal(BX), SI
257258
CMPL g(CX), SI
258-
JNE 2(PC)
259+
JNE 3(PC)
260+
CALL runtime·badmorestackgsignal(SB)
259261
MOVL 0, AX
260262

261263
// Called from f.

src/runtime/asm_arm.s

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,16 @@ TEXT runtime·morestack(SB),NOSPLIT,$-4-0
281281
MOVW g_m(g), R8
282282
MOVW m_g0(R8), R4
283283
CMP g, R4
284-
BL.EQ runtime·abort(SB)
284+
BNE 3(PC)
285+
BL runtime·badmorestackg0(SB)
286+
B runtime·abort(SB)
285287

286288
// Cannot grow signal stack (m->gsignal).
287289
MOVW m_gsignal(R8), R4
288290
CMP g, R4
289-
BL.EQ runtime·abort(SB)
291+
BNE 3(PC)
292+
BL runtime·badmorestackgsignal(SB)
293+
B runtime·abort(SB)
290294

291295
// Called from f.
292296
// Set g->sched to context in f.

src/runtime/asm_arm64.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,15 @@ TEXT runtime·morestack(SB),NOSPLIT,$-8-0
256256
MOVD g_m(g), R8
257257
MOVD m_g0(R8), R4
258258
CMP g, R4
259-
BNE 2(PC)
259+
BNE 3(PC)
260+
BL runtime·badmorestackg0(SB)
260261
B runtime·abort(SB)
261262

262263
// Cannot grow signal stack (m->gsignal).
263264
MOVD m_gsignal(R8), R4
264265
CMP g, R4
265-
BNE 2(PC)
266+
BNE 3(PC)
267+
BL runtime·badmorestackgsignal(SB)
266268
B runtime·abort(SB)
267269

268270
// Called from f.

src/runtime/asm_mips64x.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,14 @@ TEXT runtime·morestack(SB),NOSPLIT,$-8-0
231231
// Cannot grow scheduler stack (m->g0).
232232
MOVV g_m(g), R7
233233
MOVV m_g0(R7), R8
234-
BNE g, R8, 2(PC)
234+
BNE g, R8, 3(PC)
235+
JAL runtime·badmorestackg0(SB)
235236
JAL runtime·abort(SB)
236237

237238
// Cannot grow signal stack (m->gsignal).
238239
MOVV m_gsignal(R7), R8
239-
BNE g, R8, 2(PC)
240+
BNE g, R8, 3(PC)
241+
JAL runtime·badmorestackgsignal(SB)
240242
JAL runtime·abort(SB)
241243

242244
// Called from f.

src/runtime/asm_ppc64x.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
284284
MOVD g_m(g), R7
285285
MOVD m_g0(R7), R8
286286
CMP g, R8
287-
BNE 2(PC)
287+
BNE 3(PC)
288+
BL runtime·badmorestackg0(SB)
288289
BL runtime·abort(SB)
289290

290291
// Cannot grow signal stack (m->gsignal).
291292
MOVD m_gsignal(R7), R8
292293
CMP g, R8
293-
BNE 2(PC)
294+
BNE 3(PC)
295+
BL runtime·badmorestackgsignal(SB)
294296
BL runtime·abort(SB)
295297

296298
// Called from f.

src/runtime/asm_s390x.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,15 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
279279
// Cannot grow scheduler stack (m->g0).
280280
MOVD g_m(g), R7
281281
MOVD m_g0(R7), R8
282-
CMPBNE g, R8, 2(PC)
282+
CMPBNE g, R8, 3(PC)
283+
BL runtime·badmorestackg0(SB)
283284
BL runtime·abort(SB)
284285

285286
// Cannot grow signal stack (m->gsignal).
286287
MOVD m_gsignal(R7), R8
287288
CMP g, R8
288-
BNE 2(PC)
289+
BNE 3(PC)
290+
BL runtime·badmorestackgsignal(SB)
289291
BL runtime·abort(SB)
290292

291293
// Called from f.

src/runtime/proc.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ func badreflectcall() {
381381
panic(plainError("arg size to reflect.call more than 1GB"))
382382
}
383383

384+
var badmorestackg0Msg = "fatal: morestack on g0\n"
385+
386+
//go:nosplit
387+
//go:nowritebarrierrec
388+
func badmorestackg0() {
389+
sp := stringStructOf(&badmorestackg0Msg)
390+
write(2, sp.str, int32(sp.len))
391+
}
392+
393+
var badmorestackgsignalMsg = "fatal: morestack on gsignal\n"
394+
395+
//go:nosplit
396+
//go:nowritebarrierrec
397+
func badmorestackgsignal() {
398+
sp := stringStructOf(&badmorestackgsignalMsg)
399+
write(2, sp.str, int32(sp.len))
400+
}
401+
384402
func lockedOSThread() bool {
385403
gp := getg()
386404
return gp.lockedm != nil && gp.m.lockedg != nil

0 commit comments

Comments
 (0)