]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: windows/arm fix tracebacks printed from sigpanic
authorJordan Rhee <jordanrh@microsoft.com>
Wed, 21 Nov 2018 22:04:29 +0000 (14:04 -0800)
committerAustin Clements <austin@google.com>
Mon, 26 Nov 2018 19:24:54 +0000 (19:24 +0000)
The exception handler modifies the stack and continuation context so
it looks like the faulting code calls sigpanic() directly. The call was
not set up correctly on ARM, because it did not handle the link register
correctly. This change handles the link register correctly for ARM.

Updates #28854

Change-Id: I7ccf838adfc05cd968a5edd7d19ebba6a2478360
Reviewed-on: https://go-review.googlesource.com/c/150957
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/defs_windows_386.go
src/runtime/defs_windows_amd64.go
src/runtime/defs_windows_arm.go
src/runtime/signal_windows.go

index 38b30b70e3409b094aa4e02cce2f80206bf48f3b..8c0d6d8b98fdcc373bae98699e44078ca0232538 100644 (file)
@@ -105,10 +105,11 @@ func (c *context) ip() uintptr { return uintptr(c.eip) }
 func (c *context) sp() uintptr { return uintptr(c.esp) }
 
 // 386 does not have link register, so this returns 0.
-func (c *context) lr() uintptr { return 0 }
+func (c *context) lr() uintptr      { return 0 }
+func (c *context) set_lr(x uintptr) {}
 
-func (c *context) setip(x uintptr) { c.eip = uint32(x) }
-func (c *context) setsp(x uintptr) { c.esp = uint32(x) }
+func (c *context) set_ip(x uintptr) { c.eip = uint32(x) }
+func (c *context) set_sp(x uintptr) { c.esp = uint32(x) }
 
 func dumpregs(r *context) {
        print("eax     ", hex(r.eax), "\n")
index 37508c09becdcde9ac00167b70155366279e22c5..42a446d3cdfc7a3e0d7f042d161bedf8d537fd2f 100644 (file)
@@ -120,10 +120,11 @@ func (c *context) ip() uintptr { return uintptr(c.rip) }
 func (c *context) sp() uintptr { return uintptr(c.rsp) }
 
 // Amd64 does not have link register, so this returns 0.
-func (c *context) lr() uintptr { return 0 }
+func (c *context) lr() uintptr      { return 0 }
+func (c *context) set_lr(x uintptr) {}
 
-func (c *context) setip(x uintptr) { c.rip = uint64(x) }
-func (c *context) setsp(x uintptr) { c.rsp = uint64(x) }
+func (c *context) set_ip(x uintptr) { c.rip = uint64(x) }
+func (c *context) set_sp(x uintptr) { c.rsp = uint64(x) }
 
 func dumpregs(r *context) {
        print("rax     ", hex(r.rax), "\n")
index 1140f61651f381a746e4b51dc46170ea06f31adc..049f5b613a74d35c5fb466ef250aa5a3d7a9874b 100644 (file)
@@ -104,8 +104,9 @@ func (c *context) ip() uintptr { return uintptr(c.pc) }
 func (c *context) sp() uintptr { return uintptr(c.spr) }
 func (c *context) lr() uintptr { return uintptr(c.lrr) }
 
-func (c *context) setip(x uintptr) { c.pc = uint32(x) }
-func (c *context) setsp(x uintptr) { c.spr = uint32(x) }
+func (c *context) set_ip(x uintptr) { c.pc = uint32(x) }
+func (c *context) set_sp(x uintptr) { c.spr = uint32(x) }
+func (c *context) set_lr(x uintptr) { c.lrr = uint32(x) }
 
 func dumpregs(r *context) {
        print("r0   ", hex(r.r0), "\n")
index e8a64da657961b9d8ee89ccf7c85aad07dbb8720..e6a75a160f2a52552741a8e7dc9e4ab71a36a673 100644 (file)
@@ -117,10 +117,18 @@ func exceptionhandler(info *exceptionrecord, r *context, gp *g) int32 {
        if r.ip() != 0 {
                sp := unsafe.Pointer(r.sp())
                sp = add(sp, ^(unsafe.Sizeof(uintptr(0)) - 1)) // sp--
-               *((*uintptr)(sp)) = r.ip()
-               r.setsp(uintptr(sp))
+               r.set_sp(uintptr(sp))
+               switch GOARCH {
+               default:
+                       panic("unsupported architecture")
+               case "386", "amd64":
+                       *((*uintptr)(sp)) = r.ip()
+               case "arm":
+                       *((*uintptr)(sp)) = r.lr()
+                       r.set_lr(r.ip())
+               }
        }
-       r.setip(funcPC(sigpanic))
+       r.set_ip(funcPC(sigpanic))
        return _EXCEPTION_CONTINUE_EXECUTION
 }