Skip to content

Commit

Permalink
fcntl: musl wrapper, move to syscall_unix.go, os_linux
Browse files Browse the repository at this point in the history
Signed-off-by: leongross <[email protected]>
  • Loading branch information
leongross committed Oct 28, 2024
1 parent 6b15f6b commit 7a2e938
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions builder/musl.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var libMusl = Library{
"thread/*.c",
"time/*.c",
"unistd/*.c",
"fcntl/*.c",
}
if arch == "arm" {
// These files need to be added to the start for some reason.
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,5 @@ func hardwareRand() (n uint64, ok bool) {
//export getrandom
func libc_getrandom(buf unsafe.Pointer, buflen uintptr, flags uint32) uint32

func fcntl(fd, cmd, arg int32) (ret int32, errno int32){
return 0, 0
}
//go:linkname fcntl syscall.Fcntl
func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
16 changes: 16 additions & 0 deletions src/syscall/syscall_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,23 @@ func Truncate(path string, length int64) (err error) {
return
}

/*
//go:linkname syscall_fcntl runtime/runtime.fcntl
func syscall_fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
// https://cs.opensource.google/go/go/+/master:src/runtime/os_linux.go;l=452?q=runtime.fcntl&ss=go%2Fgo
r, _, err := Syscall6(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)
return int32(r), int32(err)
}
*/

//go:linkname Fcntl runtime/runtime.fcntl
func Fcntl(fd int, cmd int, args ...int) (int, error) {
ret := libc_fcntl(fd, cmd, args...)
if ret < 0 {
return 0, getErrno()
}
return ret, nil
}

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error)

Expand Down Expand Up @@ -472,3 +483,8 @@ func libc_execve(filename *byte, argv **byte, envp **byte) int
//
//export truncate
func libc_truncate(path *byte, length int64) int32

// int fcntl(int, int, ...);
//
// export fcntl
func libc_fcntl(fd int, cmd int, args ...int) int
9 changes: 9 additions & 0 deletions src/syscall/syscall_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build tinygo && unix && !baremetal && !tinygo.wasm

package syscall

func Exec(argv0 string, argv []string, envv []string) (err error)
Expand All @@ -16,3 +18,10 @@ type SockaddrInet6 struct {
Addr [16]byte
raw RawSockaddrInet6
}

//go:linkname syscall_fcntl runtime/runtime.fcntl
func syscall_fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
// https://cs.opensource.google/go/go/+/master:src/runtime/os_linux.go;l=452?q=runtime.fcntl&ss=go%2Fgo
r, _, err := Syscall6(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)

Check failure on line 25 in src/syscall/syscall_unix.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

undefined: Syscall6

Check failure on line 25 in src/syscall/syscall_unix.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

undefined: SYS_FCNTL

Check failure on line 25 in src/syscall/syscall_unix.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

undefined: Syscall6

Check failure on line 25 in src/syscall/syscall_unix.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

undefined: SYS_FCNTL
return int32(r), int32(err)
}

0 comments on commit 7a2e938

Please sign in to comment.