2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
2014-08-24 23:59:13 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type callbacks struct {
|
2014-08-27 21:41:10 -06:00
|
|
|
lock mutex
|
2014-08-24 23:59:13 -06:00
|
|
|
ctxt [cb_max]*wincallbackcontext
|
|
|
|
n int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *wincallbackcontext) isCleanstack() bool {
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
return c.cleanstack
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *wincallbackcontext) setCleanstack(cleanstack bool) {
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
c.cleanstack = cleanstack
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
cbs callbacks
|
|
|
|
cbctxts **wincallbackcontext = &cbs.ctxt[0] // to simplify access to cbs.ctxt in sys_windows_*.s
|
|
|
|
|
|
|
|
callbackasm byte // type isn't really byte, it's code in runtime
|
|
|
|
)
|
|
|
|
|
|
|
|
// callbackasmAddr returns address of runtime.callbackasm
|
|
|
|
// function adjusted by i.
|
|
|
|
// runtime.callbackasm is just a series of CALL instructions
|
|
|
|
// (each is 5 bytes long), and we want callback to arrive at
|
|
|
|
// correspondent call instruction instead of start of
|
|
|
|
// runtime.callbackasm.
|
|
|
|
func callbackasmAddr(i int) uintptr {
|
|
|
|
return uintptr(add(unsafe.Pointer(&callbackasm), uintptr(i*5)))
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname compileCallback syscall.compileCallback
|
2014-08-24 23:59:13 -06:00
|
|
|
func compileCallback(fn eface, cleanstack bool) (code uintptr) {
|
|
|
|
if fn._type == nil || (fn._type.kind&kindMask) != kindFunc {
|
2014-11-19 18:24:03 -07:00
|
|
|
panic("compileCallback: not a function")
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
|
|
|
ft := (*functype)(unsafe.Pointer(fn._type))
|
2015-10-21 11:40:39 -06:00
|
|
|
if len(ft.out) != 1 {
|
2014-11-19 18:24:03 -07:00
|
|
|
panic("compileCallback: function must have one output parameter")
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
uintptrSize := unsafe.Sizeof(uintptr(0))
|
2015-10-21 11:40:39 -06:00
|
|
|
if ft.out[0].size != uintptrSize {
|
2014-11-19 18:24:03 -07:00
|
|
|
panic("compileCallback: output parameter size is wrong")
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
argsize := uintptr(0)
|
2015-10-21 11:40:39 -06:00
|
|
|
for _, t := range ft.in {
|
|
|
|
if t.size > uintptrSize {
|
2014-11-19 18:24:03 -07:00
|
|
|
panic("compileCallback: input parameter size is wrong")
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
|
|
|
argsize += uintptrSize
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:32:49 -06:00
|
|
|
lock(&cbs.lock)
|
|
|
|
defer unlock(&cbs.lock)
|
2014-08-24 23:59:13 -06:00
|
|
|
|
|
|
|
n := cbs.n
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
if cbs.ctxt[i].gobody == fn.data && cbs.ctxt[i].isCleanstack() == cleanstack {
|
|
|
|
return callbackasmAddr(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if n >= cb_max {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("too many callback functions")
|
2014-08-24 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
c := new(wincallbackcontext)
|
|
|
|
c.gobody = fn.data
|
|
|
|
c.argsize = argsize
|
|
|
|
c.setCleanstack(cleanstack)
|
|
|
|
if cleanstack && argsize != 0 {
|
|
|
|
c.restorestack = argsize
|
|
|
|
} else {
|
|
|
|
c.restorestack = 0
|
|
|
|
}
|
|
|
|
cbs.ctxt[n] = c
|
|
|
|
cbs.n++
|
|
|
|
|
|
|
|
return callbackasmAddr(n)
|
|
|
|
}
|
2014-09-14 19:25:44 -06:00
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_loadlibrary syscall.loadlibrary
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_loadlibrary(filename *uint16) (handle, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = getLoadLibrary()
|
|
|
|
c.n = 1
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&filename)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
handle = c.r1
|
|
|
|
if handle == 0 {
|
|
|
|
err = c.err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_getprocaddress syscall.getprocaddress
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_getprocaddress(handle uintptr, procname *byte) (outhandle, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = getGetProcAddress()
|
|
|
|
c.n = 2
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&handle)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
outhandle = c.r1
|
|
|
|
if outhandle == 0 {
|
|
|
|
err = c.err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_Syscall syscall.Syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_Syscall(fn, nargs, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = fn
|
|
|
|
c.n = nargs
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
return c.r1, c.r2, c.err
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_Syscall6 syscall.Syscall6
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_Syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = fn
|
|
|
|
c.n = nargs
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
return c.r1, c.r2, c.err
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_Syscall9 syscall.Syscall9
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_Syscall9(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = fn
|
|
|
|
c.n = nargs
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
return c.r1, c.r2, c.err
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_Syscall12 syscall.Syscall12
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_Syscall12(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 uintptr) (r1, r2, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = fn
|
|
|
|
c.n = nargs
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
return c.r1, c.r2, c.err
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:33:51 -07:00
|
|
|
//go:linkname syscall_Syscall15 syscall.Syscall15
|
2014-09-14 19:25:44 -06:00
|
|
|
//go:nosplit
|
|
|
|
func syscall_Syscall15(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
|
2015-05-21 18:58:57 -06:00
|
|
|
c := &getg().m.syscall
|
2014-09-14 19:25:44 -06:00
|
|
|
c.fn = fn
|
|
|
|
c.n = nargs
|
2015-05-21 18:58:57 -06:00
|
|
|
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
|
|
|
|
cgocall(asmstdcallAddr, unsafe.Pointer(c))
|
2014-09-14 19:25:44 -06:00
|
|
|
return c.r1, c.r2, c.err
|
|
|
|
}
|