From 6dca1a29ab57576807d84485ff7d908d68e5c008 Mon Sep 17 00:00:00 2001 From: Felix Geisendörfer Date: Wed, 26 Apr 2023 10:07:02 +0200 Subject: runtime: add test for systemstack frame pointer adjustment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Cherry Mui Reviewed-by: Michael Knyszek Run-TryBot: Felix Geisendörfer --- src/runtime/stack_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/runtime/stack_test.go') diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go index 4e3f369f2f..042289aa58 100644 --- a/src/runtime/stack_test.go +++ b/src/runtime/stack_test.go @@ -939,3 +939,22 @@ func TestFramePointerAdjust(t *testing.T) { t.Errorf("output:\n%s\n\nwant no output", output) } } + +// TestSystemstackFramePointerAdjust is a regression test for issue 59692 that +// ensures that the frame pointer of systemstack is correctly adjusted. See CL +// 489015 for more details. +func TestSystemstackFramePointerAdjust(t *testing.T) { + growAndShrinkStack(512, [1024]byte{}) +} + +// growAndShrinkStack grows the stack of the current goroutine in order to +// shrink it again and verify that all frame pointers on the new stack have +// been correctly adjusted. stackBallast is used to ensure we're not depending +// on the current heuristics of stack shrinking too much. +func growAndShrinkStack(n int, stackBallast [1024]byte) { + if n <= 0 { + return + } + growAndShrinkStack(n-1, stackBallast) + ShrinkStackAndVerifyFramePointers() +} -- cgit v1.3