Skip to content

Commit

Permalink
runtime: rename cgocall_errno and asmcgocall_errno into cgocall and a…
Browse files Browse the repository at this point in the history
…smcgocall

Change-Id: I5917bea8bb35b0e725dcc56a68f3a70137cfc180
Reviewed-on: https://go-review.googlesource.com/9387
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
alexbrainman committed Jun 19, 2015
1 parent 1a040c9 commit 9d968cb
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 103 deletions.
5 changes: 2 additions & 3 deletions misc/cgo/test/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ func testCallbackCallers(t *testing.T) {
"runtime.cgocallbackg1",
"runtime.cgocallbackg",
"runtime.cgocallback_gofunc",
"asmcgocall",
"runtime.asmcgocall_errno",
"runtime.cgocall_errno",
"runtime.asmcgocall",
"runtime.cgocall",
"test._Cfunc_callback",
"test.nestedCall",
"test.testCallbackCallers",
Expand Down
4 changes: 2 additions & 2 deletions misc/cgo/test/issue7978.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ func test7978(t *testing.T) {
go issue7978go()
// test in c code, before callback
issue7978wait(0, 1)
issue7978check(t, "runtime.cgocall_errno(", "", 1)
issue7978check(t, "runtime.cgocall(", "", 1)
// test in go code, during callback
issue7978wait(2, 3)
issue7978check(t, "test.issue7978cb(", "test.issue7978go", 3)
// test in c code, after callback
issue7978wait(4, 5)
issue7978check(t, "runtime.cgocall_errno(", "runtime.cgocallback", 1)
issue7978check(t, "runtime.cgocall(", "runtime.cgocallback", 1)
// test in go code, after return from cgo
issue7978wait(6, 7)
issue7978check(t, "test.issue7978go(", "", 3)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cgo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ For example, here is the definition of _Cfunc_puts:
var _cgo_be59f0f25121_Cfunc_puts = unsafe.Pointer(&__cgofn__cgo_be59f0f25121_Cfunc_puts)
func _Cfunc_puts(p0 *_Ctype_char) (r1 _Ctype_int) {
_cgo_runtime_cgocall_errno(_cgo_be59f0f25121_Cfunc_puts, uintptr(unsafe.Pointer(&p0)))
_cgo_runtime_cgocall(_cgo_be59f0f25121_Cfunc_puts, uintptr(unsafe.Pointer(&p0)))
return
}
Expand Down Expand Up @@ -682,7 +682,7 @@ The following code will be generated by cgo:
var _cgo_gcc_Cfunc_sin = unsafe.Pointer(&__cgo_gcc_Cfunc_sin)
func _Cfunc_sin(p0 _Ctype_double) (r1 _Ctype_double) {
_cgo_runtime_cgocall_errno(_cgo_gcc_Cfunc_sin, uintptr(unsafe.Pointer(&p0)))
_cgo_runtime_cgocall(_cgo_gcc_Cfunc_sin, uintptr(unsafe.Pointer(&p0)))
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (p *Package) writeDefsFunc(fgo2 io.Writer, n *Name) {
if n.AddError {
prefix = "errno := "
}
fmt.Fprintf(fgo2, "\t%s_cgo_runtime_cgocall_errno(%s, %s)\n", prefix, cname, arg)
fmt.Fprintf(fgo2, "\t%s_cgo_runtime_cgocall(%s, %s)\n", prefix, cname, arg)
if n.AddError {
fmt.Fprintf(fgo2, "\tif errno != 0 { r2 = syscall.Errno(errno) }\n")
}
Expand Down Expand Up @@ -1232,8 +1232,8 @@ void *_CMalloc(size_t);
`

const goProlog = `
//go:linkname _cgo_runtime_cgocall_errno runtime.cgocall_errno
func _cgo_runtime_cgocall_errno(unsafe.Pointer, uintptr) int32
//go:linkname _cgo_runtime_cgocall runtime.cgocall
func _cgo_runtime_cgocall(unsafe.Pointer, uintptr) int32
//go:linkname _cgo_runtime_cmalloc runtime.cmalloc
func _cgo_runtime_cmalloc(uintptr) unsafe.Pointer
Expand Down
15 changes: 6 additions & 9 deletions src/runtime/asm_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,14 @@ TEXT gosave<>(SB),NOSPLIT,$0
POPL AX
RET

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-12
// See cgocall.go for more details.
TEXT ·asmcgocall(SB),NOSPLIT,$0-12
MOVL fn+0(FP), AX
MOVL arg+4(FP), BX
CALL asmcgocall<>(SB)
MOVL AX, ret+8(FP)
RET

TEXT asmcgocall<>(SB),NOSPLIT,$0-0
// fn in AX, arg in BX
MOVL SP, DX

// Figure out if we need to switch to m->g0 stack.
Expand Down Expand Up @@ -707,6 +702,8 @@ TEXT asmcgocall<>(SB),NOSPLIT,$0-0
SUBL 4(SP), SI
MOVL DI, g(CX)
MOVL SI, SP

MOVL AX, ret+8(FP)
RET

// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Expand All @@ -724,7 +721,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$12-12
RET

// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
// See cgocall.c for more details.
// See cgocall.go for more details.
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$12-12
NO_LOCAL_POINTERS

Expand Down
15 changes: 6 additions & 9 deletions src/runtime/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -641,19 +641,14 @@ TEXT gosave<>(SB),NOSPLIT,$0
MOVQ BP, (g_sched+gobuf_bp)(R8)
RET

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-20
// See cgocall.go for more details.
TEXT ·asmcgocall(SB),NOSPLIT,$0-20
MOVQ fn+0(FP), AX
MOVQ arg+8(FP), BX
CALL asmcgocall<>(SB)
MOVL AX, ret+16(FP)
RET

// asmcgocall common code. fn in AX, arg in BX. returns errno in AX.
TEXT asmcgocall<>(SB),NOSPLIT,$0-0
MOVQ SP, DX

// Figure out if we need to switch to m->g0 stack.
Expand Down Expand Up @@ -696,6 +691,8 @@ nosave:
SUBQ 40(SP), SI
MOVQ DI, g(CX)
MOVQ SI, SP

MOVL AX, ret+16(FP)
RET

// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Expand All @@ -713,7 +710,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$24-24
RET

// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
// See cgocall.c for more details.
// See cgocall.go for more details.
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$8-24
NO_LOCAL_POINTERS

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/asm_amd64p32.s
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ TEXT runtime·jmpdefer(SB), NOSPLIT, $0-8
MOVL 0(DX), BX
JMP BX // but first run the deferred function

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Not implemented.
TEXT runtime·asmcgocall_errno(SB),NOSPLIT,$0-12
TEXT runtime·asmcgocall(SB),NOSPLIT,$0-12
MOVL 0, AX
RET

Expand Down
15 changes: 6 additions & 9 deletions src/runtime/asm_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,14 @@ TEXT gosave<>(SB),NOSPLIT,$0
MOVW R11, (g_sched+gobuf_ctxt)(g)
RET

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-12
// See cgocall.go for more details.
TEXT ·asmcgocall(SB),NOSPLIT,$0-12
MOVW fn+0(FP), R1
MOVW arg+4(FP), R0
BL asmcgocall<>(SB)
MOVW R0, ret+8(FP)
RET

TEXT asmcgocall<>(SB),NOSPLIT,$0-0
// fn in R1, arg in R0.
MOVW R13, R2
MOVW g, R4

Expand Down Expand Up @@ -523,6 +518,8 @@ g0:
SUB R2, R1
MOVW R5, R0
MOVW R1, R13

MOVW R0, ret+8(FP)
RET

// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Expand All @@ -540,7 +537,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$12-12
RET

// cgocallback_gofunc(void (*fn)(void*), void *frame, uintptr framesize)
// See cgocall.c for more details.
// See cgocall.go for more details.
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$8-12
NO_LOCAL_POINTERS

Expand Down
11 changes: 4 additions & 7 deletions src/runtime/asm_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -545,19 +545,14 @@ TEXT gosave<>(SB),NOSPLIT,$-8
MOVD $0, (g_sched+gobuf_ctxt)(g)
RET

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.go for more details.
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-20
TEXT ·asmcgocall(SB),NOSPLIT,$0-20
MOVD fn+0(FP), R1
MOVD arg+8(FP), R0
BL asmcgocall<>(SB)
MOVW R0, ret+16(FP)
RET

// asmcgocall common code. fn in R1, arg in R0. returns errno in R0.
TEXT asmcgocall<>(SB),NOSPLIT,$0-0
MOVD RSP, R2 // save original stack pointer
MOVD g, R4

Expand Down Expand Up @@ -598,6 +593,8 @@ g0:
SUB R6, R5
MOVD R9, R0
MOVD R5, RSP

MOVW R0, ret+16(FP)
RET

// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Expand Down
15 changes: 6 additions & 9 deletions src/runtime/asm_ppc64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -694,19 +694,14 @@ TEXT gosave<>(SB),NOSPLIT,$-8
MOVD R0, (g_sched+gobuf_ctxt)(g)
RET

// asmcgocall(void(*fn)(void*), void *arg)
// func asmcgocall(fn, arg unsafe.Pointer) int32
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-20
// See cgocall.go for more details.
TEXT ·asmcgocall(SB),NOSPLIT,$0-20
MOVD fn+0(FP), R3
MOVD arg+8(FP), R4
BL asmcgocall<>(SB)
MOVW R3, ret+16(FP)
RET

// asmcgocall common code. fn in R3, arg in R4. returns errno in R3.
TEXT asmcgocall<>(SB),NOSPLIT,$0-0
MOVD R1, R2 // save original stack pointer
MOVD g, R5

Expand Down Expand Up @@ -749,6 +744,8 @@ g0:
MOVD 32(R1), R6
SUB R6, R5
MOVD R5, R1

MOVW R3, ret+16(FP)
RET

// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Expand All @@ -767,7 +764,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$24-24
RET

// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
// See cgocall.c for more details.
// See cgocall.go for more details.
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$16-24
NO_LOCAL_POINTERS

Expand Down
8 changes: 4 additions & 4 deletions src/runtime/cgocall.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import "unsafe"

// Call from Go to C.
//go:nosplit
func cgocall_errno(fn, arg unsafe.Pointer) int32 {
func cgocall(fn, arg unsafe.Pointer) int32 {
if !iscgo && GOOS != "solaris" && GOOS != "windows" {
throw("cgocall unavailable")
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func cgocall_errno(fn, arg unsafe.Pointer) int32 {
* the $GOMAXPROCS accounting.
*/
entersyscall(0)
errno := asmcgocall_errno(fn, arg)
errno := asmcgocall(fn, arg)
exitsyscall(0)

return errno
Expand All @@ -143,15 +143,15 @@ func cmalloc(n uintptr) unsafe.Pointer {
ret unsafe.Pointer
}
args.n = uint64(n)
cgocall_errno(_cgo_malloc, unsafe.Pointer(&args))
cgocall(_cgo_malloc, unsafe.Pointer(&args))
if args.ret == nil {
throw("C malloc failed")
}
return args.ret
}

func cfree(p unsafe.Pointer) {
cgocall_errno(_cgo_free, p)
cgocall(_cgo_free, p)
}

// Call from C back to Go.
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/env_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func syscall_setenv_c(k string, v string) {
return
}
arg := [2]unsafe.Pointer{cstring(k), cstring(v)}
asmcgocall_errno(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg))
asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg))
}

// Update the C environment if cgo is loaded.
Expand All @@ -43,7 +43,7 @@ func syscall_unsetenv_c(k string) {
return
}
arg := [1]unsafe.Pointer{cstring(k)}
asmcgocall_errno(unsafe.Pointer(_cgo_unsetenv), unsafe.Pointer(&arg))
asmcgocall(unsafe.Pointer(_cgo_unsetenv), unsafe.Pointer(&arg))
}

func cstring(s string) unsafe.Pointer {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/os1_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func stdcall(fn stdFunction) uintptr {
// all three values to be non-zero, it will use them
mp.libcallsp = getcallersp(unsafe.Pointer(&fn))
}
asmcgocall_errno(asmstdcallAddr, unsafe.Pointer(&mp.libcall))
asmcgocall(asmstdcallAddr, unsafe.Pointer(&mp.libcall))
mp.libcallsp = 0
return mp.libcall.r1
}
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/os3_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func msigsave(mp *m) {
// Called on the new thread, can not allocate memory.
func minit() {
_g_ := getg()
asmcgocall_errno(unsafe.Pointer(funcPC(miniterrno)), unsafe.Pointer(&libc____errno))
asmcgocall(unsafe.Pointer(funcPC(miniterrno)), unsafe.Pointer(&libc____errno))
// Initialize signal handling
signalstack(&_g_.m.gsignal.stack)

Expand Down Expand Up @@ -317,7 +317,7 @@ func semacreate() uintptr {
memclr(unsafe.Pointer(&_g_.m.scratch), uintptr(len(_g_.m.scratch.v)))
_g_.m.scratch.v[0] = unsafe.Sizeof(*sem)
_g_.m.libcall.args = uintptr(unsafe.Pointer(&_g_.m.scratch))
asmcgocall_errno(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_g_.m.libcall))
asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_g_.m.libcall))
sem = (*semt)(unsafe.Pointer(_g_.m.libcall.r1))
if sem_init(sem, 0, 0) != 0 {
throw("sem_init")
Expand All @@ -338,7 +338,7 @@ func semasleep(ns int64) int32 {
_m_.scratch.v[0] = _m_.waitsema
_m_.scratch.v[1] = uintptr(unsafe.Pointer(&_m_.ts))
_m_.libcall.args = uintptr(unsafe.Pointer(&_m_.scratch))
asmcgocall_errno(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_m_.libcall))
asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_m_.libcall))
if *_m_.perrno != 0 {
if *_m_.perrno == _ETIMEDOUT || *_m_.perrno == _EAGAIN || *_m_.perrno == _EINTR {
return -1
Expand All @@ -353,7 +353,7 @@ func semasleep(ns int64) int32 {
memclr(unsafe.Pointer(&_m_.scratch), uintptr(len(_m_.scratch.v)))
_m_.scratch.v[0] = _m_.waitsema
_m_.libcall.args = uintptr(unsafe.Pointer(&_m_.scratch))
asmcgocall_errno(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_m_.libcall))
asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&_m_.libcall))
if _m_.libcall.r1 == 0 {
break
}
Expand Down
Loading

0 comments on commit 9d968cb

Please sign in to comment.