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 4, 2024
1 parent 0dc68ce commit d8e381e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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

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)
return int32(r), int32(err)
}

0 comments on commit d8e381e

Please sign in to comment.