diff options
| author | Felix Geisendörfer <felix.geisendoerfer@datadoghq.com> | 2023-04-26 10:07:02 +0200 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-05-03 14:34:04 +0000 |
| commit | 6dca1a29ab57576807d84485ff7d908d68e5c008 (patch) | |
| tree | eb54119de2e20fe6acfd94c5ad5332c2c5cbde3d /src/runtime/export_test.go | |
| parent | 0d347544cbca0f42b160424f6bc2458ebcc7b3fc (diff) | |
| download | go-6dca1a29ab57576807d84485ff7d908d68e5c008.tar.xz | |
runtime: add test for systemstack frame pointer adjustment
Add TestSystemstackFramePointerAdjust as a regression test for CL
489015.
By turning stackPoisonCopy into a var instead of const and introducing
the ShrinkStackAndVerifyFramePointers() helper function, we are able to
trigger the exact combination of events that can crash traceEvent() if
systemstack restores a frame pointer that is pointing into the old
stack.
Updates #59692
Change-Id: I60fc6940638077e3b60a81d923b5f5b4f6d8a44c
Reviewed-on: https://go-review.googlesource.com/c/go/+/489115
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Diffstat (limited to 'src/runtime/export_test.go')
| -rw-r--r-- | src/runtime/export_test.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 320aff869a..c7c111ce47 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -423,6 +423,23 @@ func ReadMemStatsSlow() (base, slow MemStats) { return } +// ShrinkStackAndVerifyFramePointers attempts to shrink the stack of the current goroutine +// and verifies that unwinding the new stack doesn't crash, even if the old +// stack has been freed or reused (simulated via poisoning). +func ShrinkStackAndVerifyFramePointers() { + before := stackPoisonCopy + defer func() { stackPoisonCopy = before }() + stackPoisonCopy = 1 + + gp := getg() + systemstack(func() { + shrinkstack(gp) + }) + // If our new stack contains frame pointers into the old stack, this will + // crash because the old stack has been poisoned. + FPCallers(0, make([]uintptr, 1024)) +} + // BlockOnSystemStack switches to the system stack, prints "x\n" to // stderr, and blocks in a stack containing // "runtime.blockOnSystemStackInternal". |
