Skip to content

Commit e7fa234

Browse files
committed
runtime: add fcntl wrapper for syscall
Signed-off-by: leongross <[email protected]>
1 parent 01dac8b commit e7fa234

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/runtime/os_linux.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package runtime
55
// This file is for systems that are _actually_ Linux (not systems that pretend
66
// to be Linux, like baremetal systems).
77

8-
import "unsafe"
8+
import (
9+
"unsafe"
10+
)
911

1012
const GOOS = "linux"
1113

@@ -139,3 +141,7 @@ func hardwareRand() (n uint64, ok bool) {
139141
//
140142
//export getrandom
141143
func libc_getrandom(buf unsafe.Pointer, buflen uintptr, flags uint32) uint32
144+
145+
//go:linknam runtime_fcntl syscall/syscall_fcntl
146+
//go:export
147+
func runtime_fcntl(fd, cmd, arg int32) (ret int32, errno int32)

src/syscall/syscall_libc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ func Truncate(path string, length int64) (err error) {
212212
return
213213
}
214214

215+
//go:linkname syscall_fcntl runtime.fcntl
216+
func syscall_fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
217+
// https://cs.opensource.google/go/go/+/master:src/runtime/os_linux.go;l=452?q=runtime.fcntl&ss=go%2Fgo
218+
r, _, err := Syscall6(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)
219+
return int32(r), int32(err)
220+
}
221+
215222
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
216223

217224
func Kill(pid int, sig Signal) (err error) {

0 commit comments

Comments
 (0)