detached 2ebcfb9

internal/fakecgo: refactor (#62)

* remove comment about <>

Carrots make the symbol only available in that source file. We need these functions available outside in order for us to call them.

* use syscall.Timespec

Use the syscall version of this type. That way we can clean up our code and not have duplicated types.

* remove duplicate type arguments

* remove // +build tags

* update comment
commit
2ebcfb9c0764eb218b2cf2bb4e8ecaa8213f11f4
author
TotallyGamerJet · · 2022-11-08 04:52 UTC
committer
GitHub · · 2022-11-08 04:52 UTC
parent
6dfb1bb
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
6 files · +14 -20
M dlfcn_stubs.s +0 -1
@@ -2,7 +2,6 @@
22 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
33
44 //go:build darwin
5-// +build darwin
65
76 #include "textflag.h"
87
@@ -2,7 +2,6 @@
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3 3
4 //go:build darwin4 //go:build darwin
5-// +build darwin
6 5
7 #include "textflag.h"6 #include "textflag.h"
8 7
M internal/fakecgo/go_libinit.go +7 -4
@@ -20,9 +20,12 @@ func x_cgo_notify_runtime_init_done() {
2020 //
2121 //go:nosplit
2222 func _cgo_try_pthread_create(thread *pthread_t, attr *pthread_attr_t, pfn unsafe.Pointer, arg *ThreadStart) int {
23- var tries int
23+ var ts syscall.Timespec
24+ // tries needs to be the same type as syscall.Timespec.Nsec
25+ // but the fields are int32 on 32bit and int64 on 64bit.
26+ // tries is assigned to syscall.Timespec.Nsec in order to match its type.
27+ var tries = ts.Nsec
2428 var err int
25- var ts timespec
2629
2730 for tries = 0; tries < 20; tries++ {
2831 err = int(pthread_create(thread, attr, pfn, unsafe.Pointer(arg)))
@@ -33,8 +36,8 @@ func _cgo_try_pthread_create(thread *pthread_t, attr *pthread_attr_t, pfn unsafe
3336 if err != int(syscall.EAGAIN) {
3437 return err
3538 }
36- ts.tv_sec = 0
37- ts.tv_nsec = (tries + 1) * 1000 * 1000 // Milliseconds.
39+ ts.Sec = 0
40+ ts.Nsec = (tries + 1) * 1000 * 1000 // Milliseconds.
3841 nanosleep(&ts, nil)
3942 }
4043 return int(syscall.EAGAIN)
@@ -20,9 +20,12 @@ func x_cgo_notify_runtime_init_done() {
20 //20 //
21 //go:nosplit21 //go:nosplit
22 func _cgo_try_pthread_create(thread *pthread_t, attr *pthread_attr_t, pfn unsafe.Pointer, arg *ThreadStart) int {22 func _cgo_try_pthread_create(thread *pthread_t, attr *pthread_attr_t, pfn unsafe.Pointer, arg *ThreadStart) int {
23- var tries int23+ var ts syscall.Timespec
24+ // tries needs to be the same type as syscall.Timespec.Nsec
25+ // but the fields are int32 on 32bit and int64 on 64bit.
26+ // tries is assigned to syscall.Timespec.Nsec in order to match its type.
27+ var tries = ts.Nsec
24 var err int28 var err int
25- var ts timespec
26 29
27 for tries = 0; tries < 20; tries++ {30 for tries = 0; tries < 20; tries++ {
28 err = int(pthread_create(thread, attr, pfn, unsafe.Pointer(arg)))31 err = int(pthread_create(thread, attr, pfn, unsafe.Pointer(arg)))
@@ -33,8 +36,8 @@ func _cgo_try_pthread_create(thread *pthread_t, attr *pthread_attr_t, pfn unsafe
33 if err != int(syscall.EAGAIN) {36 if err != int(syscall.EAGAIN) {
34 return err37 return err
35 }38 }
36- ts.tv_sec = 039+ ts.Sec = 0
37- ts.tv_nsec = (tries + 1) * 1000 * 1000 // Milliseconds.40+ ts.Nsec = (tries + 1) * 1000 * 1000 // Milliseconds.
38 nanosleep(&ts, nil)41 nanosleep(&ts, nil)
39 }42 }
40 return int(syscall.EAGAIN)43 return int(syscall.EAGAIN)
M internal/fakecgo/libcgo.go +0 -7
@@ -6,17 +6,10 @@
66 package fakecgo
77
88 type size_t uintptr
9-
109 type sigset_t [128]byte // TODO: figure out how big this should be
1110 type pthread_attr_t [56]byte // TODO: figure out how big this should be
1211 type pthread_t int
1312
14-// We could take timespec from syscall - but there it uses int32 and int64 for 32 bit and 64 bit arch, which complicates stuff for us
15-type timespec struct {
16- tv_sec int
17- tv_nsec int
18-}
19-
2013 // for pthread_sigmask:
2114
2215 type sighow int32
@@ -6,17 +6,10 @@
6 package fakecgo6 package fakecgo
7 7
8 type size_t uintptr8 type size_t uintptr
9-
10 type sigset_t [128]byte // TODO: figure out how big this should be9 type sigset_t [128]byte // TODO: figure out how big this should be
11 type pthread_attr_t [56]byte // TODO: figure out how big this should be10 type pthread_attr_t [56]byte // TODO: figure out how big this should be
12 type pthread_t int11 type pthread_t int
13 12
14-// We could take timespec from syscall - but there it uses int32 and int64 for 32 bit and 64 bit arch, which complicates stuff for us
15-type timespec struct {
16- tv_sec int
17- tv_nsec int
18-}
19-
20 // for pthread_sigmask:13 // for pthread_sigmask:
21 14
22 type sighow int3215 type sighow int32
M internal/fakecgo/symbols.go +7 -4
@@ -5,7 +5,10 @@
55
66 package fakecgo
77
8-import "unsafe"
8+import (
9+ "syscall"
10+ "unsafe"
11+)
912
1013 // setg_trampoline calls setg with the G provided
1114 func setg_trampoline(setg uintptr, G uintptr)
@@ -26,7 +29,7 @@ func free(ptr unsafe.Pointer) {
2629 call5(freeABI0, uintptr(ptr), 0, 0, 0, 0)
2730 }
2831
29-func setenv(name *byte, value *byte, overwrite int32) int32 {
32+func setenv(name, value *byte, overwrite int32) int32 {
3033 return int32(call5(setenvABI0, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), uintptr(overwrite), 0, 0))
3134 }
3235
@@ -46,7 +49,7 @@ func pthread_detach(thread pthread_t) int32 {
4649 return int32(call5(pthread_detachABI0, uintptr(thread), 0, 0, 0, 0))
4750 }
4851
49-func pthread_sigmask(how sighow, ign *sigset_t, oset *sigset_t) int32 {
52+func pthread_sigmask(how sighow, ign, oset *sigset_t) int32 {
5053 return int32(call5(pthread_sigmaskABI0, uintptr(how), uintptr(unsafe.Pointer(ign)), uintptr(unsafe.Pointer(oset)), 0, 0))
5154 }
5255
@@ -62,7 +65,7 @@ func sigfillset(set *sigset_t) int32 {
6265 return int32(call5(sigfillsetABI0, uintptr(unsafe.Pointer(set)), 0, 0, 0, 0))
6366 }
6467
65-func nanosleep(ts *timespec, rem *timespec) int32 {
68+func nanosleep(ts, rem *syscall.Timespec) int32 {
6669 return int32(call5(nanosleepABI0, uintptr(unsafe.Pointer(ts)), uintptr(unsafe.Pointer(rem)), 0, 0, 0))
6770 }
6871
@@ -5,7 +5,10 @@
5 5
6 package fakecgo6 package fakecgo
7 7
8-import "unsafe"8+import (
9+ "syscall"
10+ "unsafe"
11+)
9 12
10 // setg_trampoline calls setg with the G provided13 // setg_trampoline calls setg with the G provided
11 func setg_trampoline(setg uintptr, G uintptr)14 func setg_trampoline(setg uintptr, G uintptr)
@@ -26,7 +29,7 @@ func free(ptr unsafe.Pointer) {
26 call5(freeABI0, uintptr(ptr), 0, 0, 0, 0)29 call5(freeABI0, uintptr(ptr), 0, 0, 0, 0)
27 }30 }
28 31
29-func setenv(name *byte, value *byte, overwrite int32) int32 {32+func setenv(name, value *byte, overwrite int32) int32 {
30 return int32(call5(setenvABI0, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), uintptr(overwrite), 0, 0))33 return int32(call5(setenvABI0, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), uintptr(overwrite), 0, 0))
31 }34 }
32 35
@@ -46,7 +49,7 @@ func pthread_detach(thread pthread_t) int32 {
46 return int32(call5(pthread_detachABI0, uintptr(thread), 0, 0, 0, 0))49 return int32(call5(pthread_detachABI0, uintptr(thread), 0, 0, 0, 0))
47 }50 }
48 51
49-func pthread_sigmask(how sighow, ign *sigset_t, oset *sigset_t) int32 {52+func pthread_sigmask(how sighow, ign, oset *sigset_t) int32 {
50 return int32(call5(pthread_sigmaskABI0, uintptr(how), uintptr(unsafe.Pointer(ign)), uintptr(unsafe.Pointer(oset)), 0, 0))53 return int32(call5(pthread_sigmaskABI0, uintptr(how), uintptr(unsafe.Pointer(ign)), uintptr(unsafe.Pointer(oset)), 0, 0))
51 }54 }
52 55
@@ -62,7 +65,7 @@ func sigfillset(set *sigset_t) int32 {
62 return int32(call5(sigfillsetABI0, uintptr(unsafe.Pointer(set)), 0, 0, 0, 0))65 return int32(call5(sigfillsetABI0, uintptr(unsafe.Pointer(set)), 0, 0, 0, 0))
63 }66 }
64 67
65-func nanosleep(ts *timespec, rem *timespec) int32 {68+func nanosleep(ts, rem *syscall.Timespec) int32 {
66 return int32(call5(nanosleepABI0, uintptr(unsafe.Pointer(ts)), uintptr(unsafe.Pointer(rem)), 0, 0, 0))69 return int32(call5(nanosleepABI0, uintptr(unsafe.Pointer(ts)), uintptr(unsafe.Pointer(rem)), 0, 0, 0))
67 }70 }
68 71
M internal/fakecgo/trampolines_amd64.s +0 -2
@@ -2,7 +2,6 @@
22 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
33
44 //go:build darwin
5-// +build darwin
65
76 /*
87 trampoline for emulating required C functions for cgo in go (see cgo.go)
@@ -29,7 +28,6 @@ return value will be in AX
2928
3029 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
3130
32-// TODO: put <> to make these private
3331 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
3432 MOVQ DI, 0(SP)
3533 MOVQ SI, 8(SP)
@@ -2,7 +2,6 @@
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3 3
4 //go:build darwin4 //go:build darwin
5-// +build darwin
6 5
7 /*6 /*
8 trampoline for emulating required C functions for cgo in go (see cgo.go)7 trampoline for emulating required C functions for cgo in go (see cgo.go)
@@ -29,7 +28,6 @@ return value will be in AX
29 28
30 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.29 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
31 30
32-// TODO: put <> to make these private
33 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $1631 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
34 MOVQ DI, 0(SP)32 MOVQ DI, 0(SP)
35 MOVQ SI, 8(SP)33 MOVQ SI, 8(SP)
M internal/fakecgo/trampolines_arm64.s +0 -2
@@ -2,14 +2,12 @@
22 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
33
44 //go:build darwin
5-// +build darwin
65
76 #include "textflag.h"
87 #include "go_asm.h"
98
109 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
1110
12-// TODO: put <> to make these private
1311 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0
1412 MOVD R0, 8(RSP)
1513 MOVD R1, 16(RSP)
@@ -2,14 +2,12 @@
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3 3
4 //go:build darwin4 //go:build darwin
5-// +build darwin
6 5
7 #include "textflag.h"6 #include "textflag.h"
8 #include "go_asm.h"7 #include "go_asm.h"
9 8
10 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.9 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
11 10
12-// TODO: put <> to make these private
13 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-011 TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0
14 MOVD R0, 8(RSP)12 MOVD R0, 8(RSP)
15 MOVD R1, 16(RSP)13 MOVD R1, 16(RSP)

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