github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_x86.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build amd64 amd64p32 386 6 7 package runtime 8 9 import ( 10 "runtime/internal/sys" 11 "unsafe" 12 ) 13 14 // adjust Gobuf as it if executed a call to fn with context ctxt 15 // and then did an immediate gosave. 16 func gostartcall(buf *gobuf, fn, ctxt unsafe.Pointer) { 17 sp := buf.sp 18 if sys.RegSize > sys.PtrSize { 19 sp -= sys.PtrSize 20 *(*uintptr)(unsafe.Pointer(sp)) = 0 21 } 22 sp -= sys.PtrSize 23 *(*uintptr)(unsafe.Pointer(sp)) = buf.pc 24 buf.sp = sp 25 buf.pc = uintptr(fn) 26 buf.ctxt = ctxt 27 } 28 29 // Called to rewind context saved during morestack back to beginning of function. 30 // To help us, the linker emits a jmp back to the beginning right after the 31 // call to morestack. We just have to decode and apply that jump. 32 func rewindmorestack(buf *gobuf) { 33 pc := (*[8]byte)(unsafe.Pointer(buf.pc)) 34 if pc[0] == 0xe9 { // jmp 4-byte offset 35 buf.pc = buf.pc + 5 + uintptr(int64(*(*int32)(unsafe.Pointer(&pc[1])))) 36 return 37 } 38 if pc[0] == 0xeb { // jmp 1-byte offset 39 buf.pc = buf.pc + 2 + uintptr(int64(*(*int8)(unsafe.Pointer(&pc[1])))) 40 return 41 } 42 if pc[0] == 0xcc { 43 // This is a breakpoint inserted by gdb. We could use 44 // runtime·findfunc to find the function. But if we 45 // do that, then we will continue execution at the 46 // function entry point, and we will not hit the gdb 47 // breakpoint. So for this case we don't change 48 // buf.pc, so that when we return we will execute 49 // the jump instruction and carry on. This means that 50 // stack unwinding may not work entirely correctly 51 // (https://golang.org/issue/5723) but the user is 52 // running under gdb anyhow. 53 return 54 } 55 print("runtime: pc=", pc, " ", hex(pc[0]), " ", hex(pc[1]), " ", hex(pc[2]), " ", hex(pc[3]), " ", hex(pc[4]), "\n") 56 throw("runtime: misuse of rewindmorestack") 57 }