Skip to content

Commit 1dcccf8

Browse files
authored
linux: add runtime.fcntl function
This is needed for the internal/syscall/unix package. Signed-off-by: leongross <leon.gross@9elements.com>
1 parent d51ef25 commit 1dcccf8

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

GNUmakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ endif
926926
@cp -rp lib/musl/src/env build/release/tinygo/lib/musl/src
927927
@cp -rp lib/musl/src/errno build/release/tinygo/lib/musl/src
928928
@cp -rp lib/musl/src/exit build/release/tinygo/lib/musl/src
929+
@cp -rp lib/musl/src/fcntl build/release/tinygo/lib/musl/src
929930
@cp -rp lib/musl/src/include build/release/tinygo/lib/musl/src
930931
@cp -rp lib/musl/src/internal build/release/tinygo/lib/musl/src
931932
@cp -rp lib/musl/src/legacy build/release/tinygo/lib/musl/src

builder/musl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ var libMusl = Library{
116116
"env/*.c",
117117
"errno/*.c",
118118
"exit/*.c",
119+
"fcntl/*.c",
119120
"internal/defsysinfo.c",
120121
"internal/libc.c",
121122
"internal/syscall_ret.c",

src/runtime/os_linux.go

Lines changed: 19 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

@@ -83,6 +85,11 @@ type elfProgramHeader32 struct {
8385
//go:extern __ehdr_start
8486
var ehdr_start elfHeader
8587

88+
// int *__errno_location(void);
89+
//
90+
//export __errno_location
91+
func libc_errno_location() *int32
92+
8693
// findGlobals finds globals in the .data/.bss sections.
8794
// It parses the ELF program header to find writable segments.
8895
func findGlobals(found func(start, end uintptr)) {
@@ -139,3 +146,14 @@ func hardwareRand() (n uint64, ok bool) {
139146
//
140147
//export getrandom
141148
func libc_getrandom(buf unsafe.Pointer, buflen uintptr, flags uint32) uint32
149+
150+
// int fcntl(int fd, int cmd, int arg);
151+
//
152+
//export fcntl
153+
func libc_fcntl(fd int, cmd int, arg int) (ret int)
154+
155+
func fcntl(fd int32, cmd int32, arg int32) (ret int32, errno int32) {
156+
ret = int32(libc_fcntl(int(fd), int(cmd), int(arg)))
157+
errno = *libc_errno_location()
158+
return
159+
}

0 commit comments

Comments
 (0)