From 4859392cc29a35a0126e249ecdedbd022c755b20 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 18 May 2023 14:46:20 +0200 Subject: [PATCH] runtime: fix TestSehUnwind This CL fixes two problems: - NewContextStub initialize a context with the wrong FP. That function should dereference the FP returned by getcallerfp, as it returns the callers's FP instead of the caller's caller FP. CL 494857 will rename getcallerfp to getfp to make this fact clearer. - sehCallers skips the bottom frame when it should. Fixes #60053 Change-Id: I7d59b0175fc95281fcc7dd565ced9293064df3a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/496140 Run-TryBot: Quim Muntal Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/runtime/export_windows_test.go | 11 ++++++++--- src/runtime/runtime-seh_windows_test.go | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/runtime/export_windows_test.go b/src/runtime/export_windows_test.go index 8e7662da6e..cf0db576b8 100644 --- a/src/runtime/export_windows_test.go +++ b/src/runtime/export_windows_test.go @@ -29,10 +29,15 @@ func (c ContextStub) GetPC() uintptr { return c.ip() } -func NewContextStub() ContextStub { +func NewContextStub() *ContextStub { var ctx context ctx.set_ip(getcallerpc()) ctx.set_sp(getcallersp()) - ctx.set_fp(getfp()) - return ContextStub{ctx} + fp := getfp() + // getfp is not implemented on windows/386 and windows/arm, + // in which case it returns 0. + if fp != 0 { + ctx.set_fp(*(*uintptr)(unsafe.Pointer(fp))) + } + return &ContextStub{ctx} } diff --git a/src/runtime/runtime-seh_windows_test.go b/src/runtime/runtime-seh_windows_test.go index c8a4a593b9..27e4f49741 100644 --- a/src/runtime/runtime-seh_windows_test.go +++ b/src/runtime/runtime-seh_windows_test.go @@ -78,9 +78,9 @@ func sehCallers() []uintptr { if fn == 0 { break } - windows.RtlVirtualUnwind(0, base, ctx.GetPC(), fn, uintptr(unsafe.Pointer(&ctx)), nil, &frame, nil) - n++ pcs[i] = ctx.GetPC() + n++ + windows.RtlVirtualUnwind(0, base, ctx.GetPC(), fn, uintptr(unsafe.Pointer(ctx)), nil, &frame, nil) } return pcs[:n] } -- 2.50.0