aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2024-04-08 11:30:12 +0200
committerGopher Robot <gobot@golang.org>2024-04-11 16:36:52 +0000
commit45703b50a6ae557ebe9bd7b1bea8e49d66fc97ee (patch)
tree7266141321e8748a2a3131354e5622a9a8f64ca5 /src
parent48e00ab70a49652d4b015ac71b80da9f3ae7d1ab (diff)
downloadgo-45703b50a6ae557ebe9bd7b1bea8e49d66fc97ee.tar.xz
internal/syscall/unix: implement Eaccess on openbsd
Like on other BSDs, use faccessat(AT_FDCWD, path, mode, AT_EACCESS) Change-Id: I80f8d327dd152576165b9206e32dfb749b41d187 Reviewed-on: https://go-review.googlesource.com/c/go/+/538836 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/internal/syscall/unix/asm_openbsd.s10
-rw-r--r--src/internal/syscall/unix/at_sysnum_openbsd.go10
-rw-r--r--src/internal/syscall/unix/eaccess_bsd.go2
-rw-r--r--src/internal/syscall/unix/eaccess_openbsd.go36
-rw-r--r--src/internal/syscall/unix/eaccess_other.go2
5 files changed, 55 insertions, 5 deletions
diff --git a/src/internal/syscall/unix/asm_openbsd.s b/src/internal/syscall/unix/asm_openbsd.s
new file mode 100644
index 0000000000..cc54a14ca5
--- /dev/null
+++ b/src/internal/syscall/unix/asm_openbsd.s
@@ -0,0 +1,10 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build openbsd && !mips64
+
+#include "textflag.h"
+
+TEXT ·libc_faccessat_trampoline(SB),NOSPLIT,$0-0
+ JMP libc_faccessat(SB)
diff --git a/src/internal/syscall/unix/at_sysnum_openbsd.go b/src/internal/syscall/unix/at_sysnum_openbsd.go
index fd389477ec..3b0c0dbd19 100644
--- a/src/internal/syscall/unix/at_sysnum_openbsd.go
+++ b/src/internal/syscall/unix/at_sysnum_openbsd.go
@@ -10,7 +10,11 @@ const unlinkatTrap uintptr = syscall.SYS_UNLINKAT
const openatTrap uintptr = syscall.SYS_OPENAT
const fstatatTrap uintptr = syscall.SYS_FSTATAT
-const AT_REMOVEDIR = 0x08
-const AT_SYMLINK_NOFOLLOW = 0x02
+const (
+ AT_EACCESS = 0x1
+ AT_FDCWD = -0x64
+ AT_REMOVEDIR = 0x08
+ AT_SYMLINK_NOFOLLOW = 0x02
-const UTIME_OMIT = -0x1
+ UTIME_OMIT = -0x1
+)
diff --git a/src/internal/syscall/unix/eaccess_bsd.go b/src/internal/syscall/unix/eaccess_bsd.go
index 3411e3ac40..7077af17b6 100644
--- a/src/internal/syscall/unix/eaccess_bsd.go
+++ b/src/internal/syscall/unix/eaccess_bsd.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build dragonfly || freebsd || netbsd
+//go:build dragonfly || freebsd || netbsd || (openbsd && mips64)
package unix
diff --git a/src/internal/syscall/unix/eaccess_openbsd.go b/src/internal/syscall/unix/eaccess_openbsd.go
new file mode 100644
index 0000000000..5e91f11f66
--- /dev/null
+++ b/src/internal/syscall/unix/eaccess_openbsd.go
@@ -0,0 +1,36 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build openbsd && !mips64
+
+package unix
+
+import (
+ "internal/abi"
+ "syscall"
+ "unsafe"
+)
+
+//go:linkname syscall_syscall6 syscall.syscall6
+func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
+
+func libc_faccessat_trampoline()
+
+//go:cgo_import_dynamic libc_faccessat faccessat "libc.so"
+
+func faccessat(dirfd int, path string, mode uint32, flags int) error {
+ p, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return err
+ }
+ _, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_faccessat_trampoline), uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(mode), uintptr(flags), 0, 0)
+ if errno != 0 {
+ return errno
+ }
+ return err
+}
+
+func Eaccess(path string, mode uint32) error {
+ return faccessat(AT_FDCWD, path, mode, AT_EACCESS)
+}
diff --git a/src/internal/syscall/unix/eaccess_other.go b/src/internal/syscall/unix/eaccess_other.go
index 19a2be587e..1a633ae857 100644
--- a/src/internal/syscall/unix/eaccess_other.go
+++ b/src/internal/syscall/unix/eaccess_other.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build unix && !dragonfly && !freebsd && !linux && !netbsd
+//go:build unix && !dragonfly && !freebsd && !linux && !openbsd && !netbsd
package unix