detached 999f588

purego: clean syscall after getting from the pool (#284)

Just after getting a syscall variable from the pool, the variable
might be dirty and hold the previous state. Let's clean it explicitly
in order to prevent future potential issues.
commit
999f588e454888ff33d0f31b54c398940a961f53
author
Hajime Hoshi · · 2024-10-18 10:15 UTC
committer
GitHub · · 2024-10-18 10:15 UTC
parent
1f4eb8c
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
1 file · +9 -4
M func.go +9 -4
@@ -253,8 +253,8 @@ func RegisterFunc(fptr any, cfn uintptr) {
253253 runtime.KeepAlive(keepAlive)
254254 runtime.KeepAlive(args)
255255 }()
256- syscall := thePool.Get().(*syscall15Args)
257- defer thePool.Put(syscall)
256+
257+ var arm64_r8 uintptr
258258 if ty.NumOut() == 1 && ty.Out(0).Kind() == reflect.Struct {
259259 outType := ty.Out(0)
260260 if runtime.GOARCH == "amd64" && outType.Size() > maxRegAllocStructSize {
@@ -266,7 +266,7 @@ func RegisterFunc(fptr any, cfn uintptr) {
266266 if !isAllFloats || numFields > 4 {
267267 val := reflect.New(outType)
268268 keepAlive = append(keepAlive, val)
269- syscall.arm64_r8 = val.Pointer()
269+ arm64_r8 = val.Pointer()
270270 }
271271 }
272272 }
@@ -282,6 +282,10 @@ func RegisterFunc(fptr any, cfn uintptr) {
282282 }
283283 keepAlive = addValue(v, keepAlive, addInt, addFloat, addStack, &numInts, &numFloats, &numStack)
284284 }
285+
286+ syscall := thePool.Get().(*syscall15Args)
287+ defer thePool.Put(syscall)
288+
285289 if runtime.GOARCH == "arm64" || runtime.GOOS != "windows" {
286290 // Use the normal arm64 calling convention even on Windows
287291 *syscall = syscall15Args{
@@ -290,10 +294,11 @@ func RegisterFunc(fptr any, cfn uintptr) {
290294 sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],
291295 sysargs[12], sysargs[13], sysargs[14],
292296 floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7],
293- syscall.arm64_r8,
297+ arm64_r8,
294298 }
295299 runtime_cgocall(syscall15XABI0, unsafe.Pointer(syscall))
296300 } else {
301+ *syscall = syscall15Args{}
297302 // This is a fallback for Windows amd64, 386, and arm. Note this may not support floats
298303 syscall.a1, syscall.a2, _ = syscall_syscall15X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4],
299304 sysargs[5], sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],
@@ -253,8 +253,8 @@ func RegisterFunc(fptr any, cfn uintptr) {
253 runtime.KeepAlive(keepAlive)253 runtime.KeepAlive(keepAlive)
254 runtime.KeepAlive(args)254 runtime.KeepAlive(args)
255 }()255 }()
256- syscall := thePool.Get().(*syscall15Args)256+
257- defer thePool.Put(syscall)257+ var arm64_r8 uintptr
258 if ty.NumOut() == 1 && ty.Out(0).Kind() == reflect.Struct {258 if ty.NumOut() == 1 && ty.Out(0).Kind() == reflect.Struct {
259 outType := ty.Out(0)259 outType := ty.Out(0)
260 if runtime.GOARCH == "amd64" && outType.Size() > maxRegAllocStructSize {260 if runtime.GOARCH == "amd64" && outType.Size() > maxRegAllocStructSize {
@@ -266,7 +266,7 @@ func RegisterFunc(fptr any, cfn uintptr) {
266 if !isAllFloats || numFields > 4 {266 if !isAllFloats || numFields > 4 {
267 val := reflect.New(outType)267 val := reflect.New(outType)
268 keepAlive = append(keepAlive, val)268 keepAlive = append(keepAlive, val)
269- syscall.arm64_r8 = val.Pointer()269+ arm64_r8 = val.Pointer()
270 }270 }
271 }271 }
272 }272 }
@@ -282,6 +282,10 @@ func RegisterFunc(fptr any, cfn uintptr) {
282 }282 }
283 keepAlive = addValue(v, keepAlive, addInt, addFloat, addStack, &numInts, &numFloats, &numStack)283 keepAlive = addValue(v, keepAlive, addInt, addFloat, addStack, &numInts, &numFloats, &numStack)
284 }284 }
285+
286+ syscall := thePool.Get().(*syscall15Args)
287+ defer thePool.Put(syscall)
288+
285 if runtime.GOARCH == "arm64" || runtime.GOOS != "windows" {289 if runtime.GOARCH == "arm64" || runtime.GOOS != "windows" {
286 // Use the normal arm64 calling convention even on Windows290 // Use the normal arm64 calling convention even on Windows
287 *syscall = syscall15Args{291 *syscall = syscall15Args{
@@ -290,10 +294,11 @@ func RegisterFunc(fptr any, cfn uintptr) {
290 sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],294 sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],
291 sysargs[12], sysargs[13], sysargs[14],295 sysargs[12], sysargs[13], sysargs[14],
292 floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7],296 floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7],
293- syscall.arm64_r8,297+ arm64_r8,
294 }298 }
295 runtime_cgocall(syscall15XABI0, unsafe.Pointer(syscall))299 runtime_cgocall(syscall15XABI0, unsafe.Pointer(syscall))
296 } else {300 } else {
301+ *syscall = syscall15Args{}
297 // This is a fallback for Windows amd64, 386, and arm. Note this may not support floats302 // This is a fallback for Windows amd64, 386, and arm. Note this may not support floats
298 syscall.a1, syscall.a2, _ = syscall_syscall15X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4],303 syscall.a1, syscall.a2, _ = syscall_syscall15X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4],
299 sysargs[5], sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],304 sysargs[5], sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close