Skip to content

Commit

Permalink
runtime/cgo: revise for go1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun committed Jan 27, 2019
1 parent 6230d2c commit d9baa4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
6 changes: 3 additions & 3 deletions gosrc/runtime/cgo/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ TEXT crosscall2(SB),NOSPLIT,$0x110-0 /* also need to save xmm6 - xmm15 */
MOVQ DX, 0x0(SP) /* arg */
MOVQ R8, 0x8(SP) /* argsize (includes padding) */
MOVQ R9, 0x10(SP) /* ctxt */

CALL CX /* fn */

MOVQ 0x48(SP), DI
MOVQ 0x50(SP), SI
MOVUPS 0x60(SP), X6
Expand All @@ -64,5 +64,5 @@ TEXT crosscall2(SB),NOSPLIT,$0x110-0 /* also need to save xmm6 - xmm15 */
MOVQ 0x30(SP), R13
MOVQ 0x38(SP), R14
MOVQ 0x40(SP), R15

RET
9 changes: 7 additions & 2 deletions gosrc/runtime/cgo/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ func _runtime_cgocallback(unsafe.Pointer, unsafe.Pointer, uintptr, uintptr)
// /* The function call will not return. */

//go:linkname _runtime_cgo_panic_internal runtime._cgo_panic_internal
var _runtime_cgo_panic_internal byte
func _runtime_cgo_panic_internal(p *byte)

//go:linkname _cgo_panic _cgo_panic
//go:cgo_export_static _cgo_panic
//go:cgo_export_dynamic _cgo_panic
//go:nosplit
//go:norace
func _cgo_panic(a unsafe.Pointer, n int32) {
_runtime_cgocallback(unsafe.Pointer(&_runtime_cgo_panic_internal), a, uintptr(n), 0)
f := _runtime_cgo_panic_internal
type funcval struct {
pc unsafe.Pointer
}
fv := *(**funcval)(unsafe.Pointer(&f))
_runtime_cgocallback(fv.pc, a, uintptr(n), 0)
}

//go:cgo_import_static x_cgo_init
Expand Down
2 changes: 1 addition & 1 deletion gosrc/runtime/cgo/gcc_libinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _cgo_wait_runtime_init_done() {
}

void
x_cgo_notify_runtime_init_done(void* dummy) {
x_cgo_notify_runtime_init_done(void* dummy __attribute__ ((unused))) {
pthread_mutex_lock(&runtime_init_mu);
runtime_init_done = 1;
pthread_cond_broadcast(&runtime_init_cond);
Expand Down
7 changes: 4 additions & 3 deletions gosrc/runtime/cgocall.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func cgocallbackg1(ctxt uintptr) {
case "arm64":
// On arm64, stack frame is four words and there's a saved LR between
// SP and the stack frame and between the stack frame and the arguments.
cb = (*args)(unsafe.Pointer(sp + 5*sys.PtrSize))
// Additional two words (16-byte alignment) are for saving FP.
cb = (*args)(unsafe.Pointer(sp + 7*sys.PtrSize))
case "amd64":
// On amd64, stack frame is two words, plus caller PC.
if framepointer_enabled {
Expand Down Expand Up @@ -579,7 +580,7 @@ func cgoCheckUnknownPointer(p unsafe.Pointer, msg string) (base, i uintptr) {
return
}

// cgoIsGoPointer returns whether the pointer is a Go pointer--a
// cgoIsGoPointer reports whether the pointer is a Go pointer--a
// pointer to Go memory. We only care about Go memory that might
// contain pointers.
//go:nosplit
Expand All @@ -602,7 +603,7 @@ func cgoIsGoPointer(p unsafe.Pointer) bool {
return false
}

// cgoInRange returns whether p is between start and end.
// cgoInRange reports whether p is between start and end.
//go:nosplit
//go:nowritebarrierrec
func cgoInRange(p unsafe.Pointer, start, end uintptr) bool {
Expand Down
9 changes: 8 additions & 1 deletion gosrc/runtime/cgocheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func cgoCheckWriteBarrier(dst *uintptr, src uintptr) {
return
}

// It's OK if writing to memory allocated by persistentalloc.
// Do this check last because it is more expensive and rarely true.
// If it is false the expense doesn't matter since we are crashing.
if inPersistentAlloc(uintptr(unsafe.Pointer(dst))) {
return
}

systemstack(func() {
println("write of Go pointer", hex(src), "to non-Go memory", hex(uintptr(unsafe.Pointer(dst))))
throw(cgoWriteBarrierFail)
Expand Down Expand Up @@ -126,7 +133,7 @@ func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) {
}

s := spanOfUnchecked(uintptr(src))
if s.state == _MSpanManual {
if s.state == mSpanManual {
// There are no heap bits for value stored on the stack.
// For a channel receive src might be on the stack of some
// other goroutine, so we can't unwind the stack even if
Expand Down

0 comments on commit d9baa4a

Please sign in to comment.