detached 8ebc748

Remove some //go:linkname usages (#253)

* Stop using noescape

This was just a performance improvement. Removing since we want to avoid using linkname to not hinder the Go ecosystem.

* Stop using memmove

* remove memmove linkname
commit
8ebc748ec153c98f58511bcb274540e8b517a56b
author
TotallyGamerJet · · 2024-06-04 02:52 UTC
committer
GitHub · · 2024-06-04 02:52 UTC
parent
88cc579
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
5 files · +7 -14
M func.go +1 -2
@@ -340,8 +340,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
340340 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
341341 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&syscall.a1)))
342342 case reflect.Ptr:
343- // It is safe to have the address of syscall.r1 not escape because it is immediately dereferenced with .Elem()
344- v = reflect.NewAt(outType, runtime_noescape(unsafe.Pointer(&syscall.a1))).Elem()
343+ v = reflect.NewAt(outType, unsafe.Pointer(&syscall.a1)).Elem()
345344 case reflect.Func:
346345 // wrap this C function in a nicely typed Go function
347346 v = reflect.New(outType)
@@ -340,8 +340,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
340 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer340 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
341 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&syscall.a1)))341 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&syscall.a1)))
342 case reflect.Ptr:342 case reflect.Ptr:
343- // It is safe to have the address of syscall.r1 not escape because it is immediately dereferenced with .Elem()343+ v = reflect.NewAt(outType, unsafe.Pointer(&syscall.a1)).Elem()
344- v = reflect.NewAt(outType, runtime_noescape(unsafe.Pointer(&syscall.a1))).Elem()
345 case reflect.Func:344 case reflect.Func:
346 // wrap this C function in a nicely typed Go function345 // wrap this C function in a nicely typed Go function
347 v = reflect.New(outType)346 v = reflect.New(outType)
M go_runtime.go +0 -4
@@ -11,7 +11,3 @@ import (
1111
1212 //go:linkname runtime_cgocall runtime.cgocall
1313 func runtime_cgocall(fn uintptr, arg unsafe.Pointer) int32 // from runtime/sys_libc.go
14-
15-//go:linkname runtime_noescape runtime.noescape
16-//go:noescape
17-func runtime_noescape(p unsafe.Pointer) unsafe.Pointer // from runtime/stubs.go
@@ -11,7 +11,3 @@ import (
11 11
12 //go:linkname runtime_cgocall runtime.cgocall12 //go:linkname runtime_cgocall runtime.cgocall
13 func runtime_cgocall(fn uintptr, arg unsafe.Pointer) int32 // from runtime/sys_libc.go13 func runtime_cgocall(fn uintptr, arg unsafe.Pointer) int32 // from runtime/sys_libc.go
14-
15-//go:linkname runtime_noescape runtime.noescape
16-//go:noescape
17-func runtime_noescape(p unsafe.Pointer) unsafe.Pointer // from runtime/stubs.go
M internal/fakecgo/gen.go +0 -3
@@ -32,9 +32,6 @@ import (
3232 // setg_trampoline calls setg with the G provided
3333 func setg_trampoline(setg uintptr, G uintptr)
3434
35-//go:linkname memmove runtime.memmove
36-func memmove(to, from unsafe.Pointer, n uintptr)
37-
3835 // call5 takes fn the C function and 5 arguments and calls the function with those arguments
3936 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
4037
@@ -32,9 +32,6 @@ import (
32 // setg_trampoline calls setg with the G provided32 // setg_trampoline calls setg with the G provided
33 func setg_trampoline(setg uintptr, G uintptr)33 func setg_trampoline(setg uintptr, G uintptr)
34 34
35-//go:linkname memmove runtime.memmove
36-func memmove(to, from unsafe.Pointer, n uintptr)
37-
38 // call5 takes fn the C function and 5 arguments and calls the function with those arguments35 // call5 takes fn the C function and 5 arguments and calls the function with those arguments
39 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr36 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
40 37
M internal/fakecgo/go_util.go +6 -2
@@ -27,7 +27,11 @@ func x_cgo_thread_start(arg *ThreadStart) {
2727 println("fakecgo: out of memory in thread_start")
2828 abort()
2929 }
30- // *ts = *arg would cause a writebarrier so use memmove instead
31- memmove(unsafe.Pointer(ts), unsafe.Pointer(arg), unsafe.Sizeof(*ts))
30+ // *ts = *arg would cause a writebarrier so copy using slices
31+ s1 := unsafe.Slice((*uintptr)(unsafe.Pointer(ts)), unsafe.Sizeof(*ts)/8)
32+ s2 := unsafe.Slice((*uintptr)(unsafe.Pointer(arg)), unsafe.Sizeof(*arg)/8)
33+ for i := range s2 {
34+ s1[i] = s2[i]
35+ }
3236 _cgo_sys_thread_start(ts) // OS-dependent half
3337 }
@@ -27,7 +27,11 @@ func x_cgo_thread_start(arg *ThreadStart) {
27 println("fakecgo: out of memory in thread_start")27 println("fakecgo: out of memory in thread_start")
28 abort()28 abort()
29 }29 }
30- // *ts = *arg would cause a writebarrier so use memmove instead30+ // *ts = *arg would cause a writebarrier so copy using slices
31- memmove(unsafe.Pointer(ts), unsafe.Pointer(arg), unsafe.Sizeof(*ts))31+ s1 := unsafe.Slice((*uintptr)(unsafe.Pointer(ts)), unsafe.Sizeof(*ts)/8)
32+ s2 := unsafe.Slice((*uintptr)(unsafe.Pointer(arg)), unsafe.Sizeof(*arg)/8)
33+ for i := range s2 {
34+ s1[i] = s2[i]
35+ }
32 _cgo_sys_thread_start(ts) // OS-dependent half36 _cgo_sys_thread_start(ts) // OS-dependent half
33 }37 }
M internal/fakecgo/symbols.go +0 -3
@@ -15,9 +15,6 @@ import (
1515 // setg_trampoline calls setg with the G provided
1616 func setg_trampoline(setg uintptr, G uintptr)
1717
18-//go:linkname memmove runtime.memmove
19-func memmove(to, from unsafe.Pointer, n uintptr)
20-
2118 // call5 takes fn the C function and 5 arguments and calls the function with those arguments
2219 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
2320
@@ -15,9 +15,6 @@ import (
15 // setg_trampoline calls setg with the G provided15 // setg_trampoline calls setg with the G provided
16 func setg_trampoline(setg uintptr, G uintptr)16 func setg_trampoline(setg uintptr, G uintptr)
17 17
18-//go:linkname memmove runtime.memmove
19-func memmove(to, from unsafe.Pointer, n uintptr)
20-
21 // call5 takes fn the C function and 5 arguments and calls the function with those arguments18 // call5 takes fn the C function and 5 arguments and calls the function with those arguments
22 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr19 func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
23 20

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