]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on netbsd
authorTobias Klauser <tklauser@distanz.ch>
Wed, 6 Aug 2025 15:50:14 +0000 (17:50 +0200)
committerTobias Klauser <tklauser@distanz.ch>
Mon, 11 Aug 2025 22:25:38 +0000 (15:25 -0700)
The posix_fallocate system call is available since NetBSD 7.0, see
https://man.netbsd.org/posix_fallocate.2

Re-use the syscall wrappers already in place for freebsd. Note that
posix_fallocate on netbsd also returns the result in r1 rather than in
errno:

> If successful, posix_fallocate() returns zero. It returns an error on failure, without
> setting errno.

Source: https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES

Cq-Include-Trybots: luci.golang.try:gotip-netbsd-arm64
Change-Id: Iaa1f6a805d511645da7f1d2737235bfd42da3407
Reviewed-on: https://go-review.googlesource.com/c/go/+/480475
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/link/internal/ld/fallocate_test.go
src/cmd/link/internal/ld/outbuf_bsd.go [moved from src/cmd/link/internal/ld/outbuf_freebsd.go with 90% similarity]
src/cmd/link/internal/ld/outbuf_mmap.go
src/cmd/link/internal/ld/outbuf_nofallocate.go
src/internal/syscall/unix/at_sysnum_netbsd.go
src/internal/syscall/unix/fallocate_bsd_386.go [moved from src/internal/syscall/unix/fallocate_freebsd_386.go with 85% similarity]
src/internal/syscall/unix/fallocate_bsd_64bit.go [moved from src/internal/syscall/unix/fallocate_freebsd_64bit.go with 82% similarity]
src/internal/syscall/unix/fallocate_bsd_arm.go [moved from src/internal/syscall/unix/fallocate_freebsd_arm.go with 90% similarity]

index d95fec788a616bf18d6ff700f622883e34717afc..163ffc26e8406a060f4b361709a232d77677caf1 100644 (file)
@@ -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 darwin || (freebsd && go1.21) || linux
+//go:build darwin || (freebsd && go1.21) || linux || (netbsd && go1.25)
 
 package ld
 
similarity index 90%
rename from src/cmd/link/internal/ld/outbuf_freebsd.go
rename to src/cmd/link/internal/ld/outbuf_bsd.go
index 7e718c1408e7304965af5e8836a7179a032e63e1..5dce83fefd2d7c1e6c9c1ead5e801663788fe2bd 100644 (file)
@@ -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 freebsd && go1.21
+//go:build (freebsd && go1.21) || (netbsd && go1.25)
 
 package ld
 
index b8b8dc5158e918491b490f49116550cda4fc9cfb..e92a06dcb25f802960f2cf7dd41b5451bbe4e769 100644 (file)
@@ -28,7 +28,7 @@ func (out *OutBuf) Mmap(filesize uint64) (err error) {
                // Some file systems do not support fallocate. We ignore that error as linking
                // can still take place, but you might SIGBUS when you write to the mmapped
                // area.
-               if err != syscall.ENOTSUP && err != syscall.EPERM && err != errNoFallocate {
+               if err != syscall.ENOTSUP && err != syscall.EOPNOTSUPP && err != syscall.EPERM && err != errNoFallocate {
                        return err
                }
        }
index 435be5e09fe5b950c0a33ffce3d70d0fd9a31363..9169379e23897bd244ca491eef4048c63b8dcb6c 100644 (file)
@@ -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 !darwin && !(freebsd && go1.21) && !linux
+//go:build !darwin && !(freebsd && go1.21) && !linux && !(netbsd && go1.25)
 
 package ld
 
index b59b5e0cf96d0deadcd40c6ebc32d377bf0cbcbb..db17852b748e325ad170343f86242b075d726fd7 100644 (file)
@@ -7,16 +7,17 @@ package unix
 import "syscall"
 
 const (
-       unlinkatTrap   uintptr = syscall.SYS_UNLINKAT
-       openatTrap     uintptr = syscall.SYS_OPENAT
-       fstatatTrap    uintptr = syscall.SYS_FSTATAT
-       readlinkatTrap uintptr = syscall.SYS_READLINKAT
-       mkdiratTrap    uintptr = syscall.SYS_MKDIRAT
-       fchmodatTrap   uintptr = syscall.SYS_FCHMODAT
-       fchownatTrap   uintptr = syscall.SYS_FCHOWNAT
-       renameatTrap   uintptr = syscall.SYS_RENAMEAT
-       linkatTrap     uintptr = syscall.SYS_LINKAT
-       symlinkatTrap  uintptr = syscall.SYS_SYMLINKAT
+       unlinkatTrap       uintptr = syscall.SYS_UNLINKAT
+       openatTrap         uintptr = syscall.SYS_OPENAT
+       fstatatTrap        uintptr = syscall.SYS_FSTATAT
+       readlinkatTrap     uintptr = syscall.SYS_READLINKAT
+       mkdiratTrap        uintptr = syscall.SYS_MKDIRAT
+       fchmodatTrap       uintptr = syscall.SYS_FCHMODAT
+       fchownatTrap       uintptr = syscall.SYS_FCHOWNAT
+       renameatTrap       uintptr = syscall.SYS_RENAMEAT
+       linkatTrap         uintptr = syscall.SYS_LINKAT
+       symlinkatTrap      uintptr = syscall.SYS_SYMLINKAT
+       posixFallocateTrap uintptr = 479
 )
 
 const (
similarity index 85%
rename from src/internal/syscall/unix/fallocate_freebsd_386.go
rename to src/internal/syscall/unix/fallocate_bsd_386.go
index 535b23dbc5b7eb12c1c5e82ba71aa407ee9e0aa9..1dcdff4a5391d0d1d963e1df9da6fd38cc65d155 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build (freebsd || netbsd) && 386
+
 package unix
 
 import "syscall"
@@ -9,6 +11,7 @@ import "syscall"
 func PosixFallocate(fd int, off int64, size int64) error {
        // If successful, posix_fallocate() returns zero. It returns an error on failure, without
        // setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
+       // and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
        r1, _, _ := syscall.Syscall6(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(off>>32), uintptr(size), uintptr(size>>32), 0)
        if r1 != 0 {
                return syscall.Errno(r1)
similarity index 82%
rename from src/internal/syscall/unix/fallocate_freebsd_64bit.go
rename to src/internal/syscall/unix/fallocate_bsd_64bit.go
index a9d52283f06a9b20af28dcf08bf8d0bc48d096ae..177bb48382d54ccf68cca0a16a4b57e1fed8de18 100644 (file)
@@ -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 freebsd && (amd64 || arm64 || riscv64)
+//go:build (freebsd || netbsd) && (amd64 || arm64 || riscv64)
 
 package unix
 
@@ -11,6 +11,7 @@ import "syscall"
 func PosixFallocate(fd int, off int64, size int64) error {
        // If successful, posix_fallocate() returns zero. It returns an error on failure, without
        // setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
+       // and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
        r1, _, _ := syscall.Syscall(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(size))
        if r1 != 0 {
                return syscall.Errno(r1)
similarity index 90%
rename from src/internal/syscall/unix/fallocate_freebsd_arm.go
rename to src/internal/syscall/unix/fallocate_bsd_arm.go
index 1ded50f3b9a168e66c539aef2fe3d54ac157642a..15e99d02b1c790a14a2d2ad8af4a036463b908e8 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build (freebsd || netbsd) && arm
+
 package unix
 
 import "syscall"
@@ -9,6 +11,7 @@ import "syscall"
 func PosixFallocate(fd int, off int64, size int64) error {
        // If successful, posix_fallocate() returns zero. It returns an error on failure, without
        // setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
+       // and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
        //
        // The padding 0 argument is needed because the ARM calling convention requires that if an
        // argument (off in this case) needs double-word alignment (8-byte), the NCRN (next core