Skip to content

Commit 414444d

Browse files
committed
runtime: do not calculate asmstdcall address every time we make syscall
Change-Id: If3c8c9035e12d41647ae4982883f6a979313ea9d Reviewed-on: https://go-review.googlesource.com/8682 Reviewed-by: Minux Ma <[email protected]>
1 parent eb44082 commit 414444d

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/runtime/os1_windows.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ var (
9494
_GetQueuedCompletionStatusEx stdFunction
9595
)
9696

97+
// Call a Windows function with stdcall conventions,
98+
// and switch to os stack during the call.
99+
func asmstdcall(fn unsafe.Pointer)
100+
101+
var asmstdcallAddr unsafe.Pointer
102+
97103
func loadOptionalSyscalls() {
98104
var buf [50]byte // large enough for longest string
99105
strtoptr := func(s string) uintptr {
@@ -157,6 +163,8 @@ func getVersion() (major, minor byte) {
157163
}
158164

159165
func osinit() {
166+
asmstdcallAddr = unsafe.Pointer(funcPC(asmstdcall))
167+
160168
setBadSignalMsg()
161169

162170
loadOptionalSyscalls()
@@ -391,7 +399,7 @@ func stdcall(fn stdFunction) uintptr {
391399
// all three values to be non-zero, it will use them
392400
mp.libcallsp = getcallersp(unsafe.Pointer(&fn))
393401
}
394-
asmcgocall(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&mp.libcall))
402+
asmcgocall(asmstdcallAddr, unsafe.Pointer(&mp.libcall))
395403
mp.libcallsp = 0
396404
return mp.libcall.r1
397405
}

src/runtime/os2_windows.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
package runtime
66

7-
import "unsafe"
8-
9-
// Call a Windows function with stdcall conventions,
10-
// and switch to os stack during the call.
11-
func asmstdcall(fn unsafe.Pointer)
12-
137
func getlasterror() uint32
148
func setlasterror(err uint32)
159

src/runtime/syscall_windows.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func syscall_loadlibrary(filename *uint16) (handle, err uintptr) {
9595
c.fn = getLoadLibrary()
9696
c.n = 1
9797
c.args = uintptr(unsafe.Pointer(&filename))
98-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
98+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
9999
handle = c.r1
100100
if handle == 0 {
101101
err = c.err
@@ -110,7 +110,7 @@ func syscall_getprocaddress(handle uintptr, procname *byte) (outhandle, err uint
110110
c.fn = getGetProcAddress()
111111
c.n = 2
112112
c.args = uintptr(unsafe.Pointer(&handle))
113-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
113+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
114114
outhandle = c.r1
115115
if outhandle == 0 {
116116
err = c.err
@@ -125,7 +125,7 @@ func syscall_Syscall(fn, nargs, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
125125
c.fn = fn
126126
c.n = nargs
127127
c.args = uintptr(unsafe.Pointer(&a1))
128-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
128+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
129129
return c.r1, c.r2, c.err
130130
}
131131

@@ -136,7 +136,7 @@ func syscall_Syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err ui
136136
c.fn = fn
137137
c.n = nargs
138138
c.args = uintptr(unsafe.Pointer(&a1))
139-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
139+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
140140
return c.r1, c.r2, c.err
141141
}
142142

@@ -147,7 +147,7 @@ func syscall_Syscall9(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1
147147
c.fn = fn
148148
c.n = nargs
149149
c.args = uintptr(unsafe.Pointer(&a1))
150-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
150+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
151151
return c.r1, c.r2, c.err
152152
}
153153

@@ -158,7 +158,7 @@ func syscall_Syscall12(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
158158
c.fn = fn
159159
c.n = nargs
160160
c.args = uintptr(unsafe.Pointer(&a1))
161-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
161+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
162162
return c.r1, c.r2, c.err
163163
}
164164

@@ -169,6 +169,6 @@ func syscall_Syscall15(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
169169
c.fn = fn
170170
c.n = nargs
171171
c.args = uintptr(unsafe.Pointer(&a1))
172-
cgocall_errno(unsafe.Pointer(funcPC(asmstdcall)), unsafe.Pointer(&c))
172+
cgocall_errno(asmstdcallAddr, unsafe.Pointer(&c))
173173
return c.r1, c.r2, c.err
174174
}

0 commit comments

Comments
 (0)