|
4 | 4 |
|
5 | 5 | #include <fcntl.h> |
6 | 6 |
|
| 7 | +// sys/ioctl.h is not in lib/macos-minimal-sdk. Declare ioctl here. |
7 | 8 | extern int ioctl(int fd, unsigned long request, ...); |
8 | 9 |
|
9 | | -// Wrapper function because 'open' is a variadic function and variadic functions |
10 | | -// use a different (incompatible) calling convention on darwin/arm64. |
11 | | -// This function is referenced from the compiler, when it sees a |
12 | | -// syscall.libc_open_trampoline function. |
13 | | -int syscall_libc_open(const char *pathname, int flags, mode_t mode) { |
14 | | - return open(pathname, flags, mode); |
| 10 | +// Fixed-signature wrappers for the variadic libc imports. Variadic functions |
| 11 | +// take stack arguments on darwin/arm64. See darwinVariadicImports in |
| 12 | +// compiler/syscall.go. |
| 13 | + |
| 14 | +int syscall_libc_open(uintptr_t pathname, uintptr_t flags, uintptr_t mode) { |
| 15 | + return open((const char *)pathname, (int)flags, (mode_t)mode); |
15 | 16 | } |
16 | 17 |
|
17 | | -// Wrapper for ioctl, which is variadic just like open and therefore also uses |
18 | | -// an incompatible calling convention on darwin/arm64. Use uintptr_t arguments |
19 | | -// to match the fixed-signature call made by tinygo_syscall below. |
20 | 18 | int syscall_libc_ioctl(uintptr_t fd, uintptr_t request, uintptr_t arg) { |
21 | | - return ioctl((int)fd, request, (void *)arg); |
| 19 | + return ioctl((int)fd, (unsigned long)request, (void *)arg); |
22 | 20 | } |
23 | 21 |
|
24 | | -// Wrappers for the remaining variadic libc functions that darwin syscall |
25 | | -// wrappers import with //go:cgo_import_dynamic (see darwinVariadicImports in |
26 | | -// compiler/syscall.go): of the symbols imported by the generated |
27 | | -// zsyscall_darwin_*.go files in golang.org/x/sys/unix and the standard |
28 | | -// library, exactly open, openat, fcntl, and ioctl are declared variadic in |
29 | | -// the Darwin SDK headers (sys/fcntl.h and sys/ioctl.h). The tinygo_syscall* |
30 | | -// functions below call through fixed-signature function pointers that pass |
31 | | -// every argument in a register, while a variadic callee takes its variadic |
32 | | -// arguments from the stack on darwin/arm64, so each of these needs a |
33 | | -// fixed-signature wrapper. The uintptr_t parameters match the uintptr |
34 | | -// arguments the Go syscall engine passes. |
35 | | - |
36 | | -// fcntl's third argument is an int for some commands and a pointer for |
37 | | -// others; passing the raw pointer-sized value covers both. |
| 22 | +// The third fcntl argument is an int for some commands and a pointer for |
| 23 | +// other commands. The raw pointer-sized value is correct for both. |
38 | 24 | int syscall_libc_fcntl(uintptr_t fd, uintptr_t cmd, uintptr_t arg) { |
39 | 25 | return fcntl((int)fd, (int)cmd, (void *)arg); |
40 | 26 | } |
41 | 27 |
|
42 | | -// openat is invoked by x/sys through syscall6 with six arguments, the last |
43 | | -// two of which are zero padding; the two extra register arguments are |
44 | | -// harmless to a four-parameter callee. |
| 28 | +// x/sys calls openat through syscall6 with two trailing zero arguments. The |
| 29 | +// two extra register arguments are harmless to a four-parameter callee. |
45 | 30 | int syscall_libc_openat(uintptr_t dirfd, uintptr_t pathname, uintptr_t flags, uintptr_t mode) { |
46 | 31 | return openat((int)dirfd, (const char *)pathname, (int)flags, (mode_t)mode); |
47 | 32 | } |
|
0 commit comments