]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix TestSehUnwind
authorqmuntal <quimmuntal@gmail.com>
Thu, 18 May 2023 12:46:20 +0000 (14:46 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 22 May 2023 11:50:24 +0000 (11:50 +0000)
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 <quimmuntal@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/runtime/export_windows_test.go
src/runtime/runtime-seh_windows_test.go

index 8e7662da6e793c05f24ee3d9c812ae64480d1320..cf0db576b80babeb0f92da1d892bd0e5f102f6b0 100644 (file)
@@ -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}
 }
index c8a4a593b979c42904fa5fa26cc3c33bc91c3933..27e4f4974113afc609c7cb09a970eab4886b3868 100644 (file)
@@ -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]
 }