aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorleongross <[email protected]>2024-11-18 14:44:06 +0100
committerGitHub <[email protected]>2024-11-18 14:44:06 +0100
commit1dcccf87b5825de57eb522feb3d704fda95b62a5 (patch)
treec347345882aa5916d1fdc0904200edcdb49f55bc
parentd51ef253a92e72513986731d7c08486ff60915c4 (diff)
downloadtinygo-1dcccf87b5825de57eb522feb3d704fda95b62a5.tar.gz
tinygo-1dcccf87b5825de57eb522feb3d704fda95b62a5.zip
linux: add runtime.fcntl function
This is needed for the internal/syscall/unix package. Signed-off-by: leongross <[email protected]>
-rw-r--r--GNUmakefile1
-rw-r--r--builder/musl.go1
-rw-r--r--src/runtime/os_linux.go20
3 files changed, 21 insertions, 1 deletions
diff --git a/GNUmakefile b/GNUmakefile
index e66b6af29..2bf023c62 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -926,6 +926,7 @@ endif
@cp -rp lib/musl/src/env build/release/tinygo/lib/musl/src
@cp -rp lib/musl/src/errno build/release/tinygo/lib/musl/src
@cp -rp lib/musl/src/exit build/release/tinygo/lib/musl/src
+ @cp -rp lib/musl/src/fcntl build/release/tinygo/lib/musl/src
@cp -rp lib/musl/src/include build/release/tinygo/lib/musl/src
@cp -rp lib/musl/src/internal build/release/tinygo/lib/musl/src
@cp -rp lib/musl/src/legacy build/release/tinygo/lib/musl/src
diff --git a/builder/musl.go b/builder/musl.go
index a6699ad8d..b156430d4 100644
--- a/builder/musl.go
+++ b/builder/musl.go
@@ -116,6 +116,7 @@ var libMusl = Library{
"env/*.c",
"errno/*.c",
"exit/*.c",
+ "fcntl/*.c",
"internal/defsysinfo.c",
"internal/libc.c",
"internal/syscall_ret.c",
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index df5870a2d..0ae105c5f 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -5,7 +5,9 @@ package runtime
// This file is for systems that are _actually_ Linux (not systems that pretend
// to be Linux, like baremetal systems).
-import "unsafe"
+import (
+ "unsafe"
+)
const GOOS = "linux"
@@ -83,6 +85,11 @@ type elfProgramHeader32 struct {
//go:extern __ehdr_start
var ehdr_start elfHeader
+// int *__errno_location(void);
+//
+//export __errno_location
+func libc_errno_location() *int32
+
// findGlobals finds globals in the .data/.bss sections.
// It parses the ELF program header to find writable segments.
func findGlobals(found func(start, end uintptr)) {
@@ -139,3 +146,14 @@ func hardwareRand() (n uint64, ok bool) {
//
//export getrandom
func libc_getrandom(buf unsafe.Pointer, buflen uintptr, flags uint32) uint32
+
+// int fcntl(int fd, int cmd, int arg);
+//
+//export fcntl
+func libc_fcntl(fd int, cmd int, arg int) (ret int)
+
+func fcntl(fd int32, cmd int32, arg int32) (ret int32, errno int32) {
+ ret = int32(libc_fcntl(int(fd), int(cmd), int(arg)))
+ errno = *libc_errno_location()
+ return
+}