aboutsummaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/sys/unix/syscall_freebsd.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2022-11-08 17:04:09 +0100
committerGibheer <gibheer+git@zero-knowledge.org>2022-11-08 17:04:09 +0100
commitdc9dfb76ff9375e6368e9e05a40e6dc07b325a8d (patch)
treedc1dedb62230d9c5b225d890f970f8b8640caca6 /vendor/golang.org/x/sys/unix/syscall_freebsd.go
parentfa05045d31c05c8928020f05f1d281901d983b2b (diff)
update dependencies
Diffstat (limited to 'vendor/golang.org/x/sys/unix/syscall_freebsd.go')
-rw-r--r--vendor/golang.org/x/sys/unix/syscall_freebsd.go342
1 files changed, 42 insertions, 300 deletions
diff --git a/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/vendor/golang.org/x/sys/unix/syscall_freebsd.go
index 18c392c..de7c23e 100644
--- a/vendor/golang.org/x/sys/unix/syscall_freebsd.go
+++ b/vendor/golang.org/x/sys/unix/syscall_freebsd.go
@@ -17,25 +17,12 @@ import (
"unsafe"
)
-const (
- SYS_FSTAT_FREEBSD12 = 551 // { int fstat(int fd, _Out_ struct stat *sb); }
- SYS_FSTATAT_FREEBSD12 = 552 // { int fstatat(int fd, _In_z_ char *path, \
- SYS_GETDIRENTRIES_FREEBSD12 = 554 // { ssize_t getdirentries(int fd, \
- SYS_STATFS_FREEBSD12 = 555 // { int statfs(_In_z_ char *path, \
- SYS_FSTATFS_FREEBSD12 = 556 // { int fstatfs(int fd, \
- SYS_GETFSSTAT_FREEBSD12 = 557 // { int getfsstat( \
- SYS_MKNODAT_FREEBSD12 = 559 // { int mknodat(int fd, _In_z_ char *path, \
-)
-
// See https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html.
var (
osreldateOnce sync.Once
osreldate uint32
)
-// INO64_FIRST from /usr/src/lib/libc/sys/compat-ino64.h
-const _ino64First = 1200031
-
func supportsABI(ver uint32) bool {
osreldateOnce.Do(func() { osreldate, _ = SysctlUint32("kern.osreldate") })
return osreldate >= ver
@@ -110,8 +97,10 @@ func Pipe2(p []int, flags int) error {
}
var pp [2]_C_int
err := pipe2(&pp, flags)
- p[0] = int(pp[0])
- p[1] = int(pp[1])
+ if err == nil {
+ p[0] = int(pp[0])
+ p[1] = int(pp[1])
+ }
return err
}
@@ -157,46 +146,21 @@ func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
var (
- _p0 unsafe.Pointer
- bufsize uintptr
- oldBuf []statfs_freebsd11_t
- needsConvert bool
+ _p0 unsafe.Pointer
+ bufsize uintptr
)
-
if len(buf) > 0 {
- if supportsABI(_ino64First) {
- _p0 = unsafe.Pointer(&buf[0])
- bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
- } else {
- n := len(buf)
- oldBuf = make([]statfs_freebsd11_t, n)
- _p0 = unsafe.Pointer(&oldBuf[0])
- bufsize = unsafe.Sizeof(statfs_freebsd11_t{}) * uintptr(n)
- needsConvert = true
- }
+ _p0 = unsafe.Pointer(&buf[0])
+ bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
}
- var sysno uintptr = SYS_GETFSSTAT
- if supportsABI(_ino64First) {
- sysno = SYS_GETFSSTAT_FREEBSD12
- }
- r0, _, e1 := Syscall(sysno, uintptr(_p0), bufsize, uintptr(flags))
+ r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
n = int(r0)
if e1 != 0 {
err = e1
}
- if e1 == 0 && needsConvert {
- for i := range oldBuf {
- buf[i].convertFrom(&oldBuf[i])
- }
- }
return
}
-func setattrlistTimes(path string, times []Timespec, flags int) error {
- // used on Darwin for UtimesNano
- return ENOSYS
-}
-
//sys ioctl(fd int, req uint, arg uintptr) (err error)
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
@@ -248,87 +212,11 @@ func Uname(uname *Utsname) error {
}
func Stat(path string, st *Stat_t) (err error) {
- var oldStat stat_freebsd11_t
- if supportsABI(_ino64First) {
- return fstatat_freebsd12(AT_FDCWD, path, st, 0)
- }
- err = stat(path, &oldStat)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStat)
- return nil
+ return Fstatat(AT_FDCWD, path, st, 0)
}
func Lstat(path string, st *Stat_t) (err error) {
- var oldStat stat_freebsd11_t
- if supportsABI(_ino64First) {
- return fstatat_freebsd12(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW)
- }
- err = lstat(path, &oldStat)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStat)
- return nil
-}
-
-func Fstat(fd int, st *Stat_t) (err error) {
- var oldStat stat_freebsd11_t
- if supportsABI(_ino64First) {
- return fstat_freebsd12(fd, st)
- }
- err = fstat(fd, &oldStat)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStat)
- return nil
-}
-
-func Fstatat(fd int, path string, st *Stat_t, flags int) (err error) {
- var oldStat stat_freebsd11_t
- if supportsABI(_ino64First) {
- return fstatat_freebsd12(fd, path, st, flags)
- }
- err = fstatat(fd, path, &oldStat, flags)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStat)
- return nil
-}
-
-func Statfs(path string, st *Statfs_t) (err error) {
- var oldStatfs statfs_freebsd11_t
- if supportsABI(_ino64First) {
- return statfs_freebsd12(path, st)
- }
- err = statfs(path, &oldStatfs)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStatfs)
- return nil
-}
-
-func Fstatfs(fd int, st *Statfs_t) (err error) {
- var oldStatfs statfs_freebsd11_t
- if supportsABI(_ino64First) {
- return fstatfs_freebsd12(fd, st)
- }
- err = fstatfs(fd, &oldStatfs)
- if err != nil {
- return err
- }
-
- st.convertFrom(&oldStatfs)
- return nil
+ return Fstatat(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW)
}
func Getdents(fd int, buf []byte) (n int, err error) {
@@ -336,162 +224,25 @@ func Getdents(fd int, buf []byte) (n int, err error) {
}
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
- if supportsABI(_ino64First) {
- if basep == nil || unsafe.Sizeof(*basep) == 8 {
- return getdirentries_freebsd12(fd, buf, (*uint64)(unsafe.Pointer(basep)))
- }
- // The freebsd12 syscall needs a 64-bit base. On 32-bit machines
- // we can't just use the basep passed in. See #32498.
- var base uint64 = uint64(*basep)
- n, err = getdirentries_freebsd12(fd, buf, &base)
- *basep = uintptr(base)
- if base>>32 != 0 {
- // We can't stuff the base back into a uintptr, so any
- // future calls would be suspect. Generate an error.
- // EIO is allowed by getdirentries.
- err = EIO
- }
- return
- }
-
- // The old syscall entries are smaller than the new. Use 1/4 of the original
- // buffer size rounded up to DIRBLKSIZ (see /usr/src/lib/libc/sys/getdirentries.c).
- oldBufLen := roundup(len(buf)/4, _dirblksiz)
- oldBuf := make([]byte, oldBufLen)
- n, err = getdirentries(fd, oldBuf, basep)
- if err == nil && n > 0 {
- n = convertFromDirents11(buf, oldBuf[:n])
+ if basep == nil || unsafe.Sizeof(*basep) == 8 {
+ return getdirentries(fd, buf, (*uint64)(unsafe.Pointer(basep)))
+ }
+ // The syscall needs a 64-bit base. On 32-bit machines
+ // we can't just use the basep passed in. See #32498.
+ var base uint64 = uint64(*basep)
+ n, err = getdirentries(fd, buf, &base)
+ *basep = uintptr(base)
+ if base>>32 != 0 {
+ // We can't stuff the base back into a uintptr, so any
+ // future calls would be suspect. Generate an error.
+ // EIO is allowed by getdirentries.
+ err = EIO
}
return
}
func Mknod(path string, mode uint32, dev uint64) (err error) {
- var oldDev int
- if supportsABI(_ino64First) {
- return mknodat_freebsd12(AT_FDCWD, path, mode, dev)
- }
- oldDev = int(dev)
- return mknod(path, mode, oldDev)
-}
-
-func Mknodat(fd int, path string, mode uint32, dev uint64) (err error) {
- var oldDev int
- if supportsABI(_ino64First) {
- return mknodat_freebsd12(fd, path, mode, dev)
- }
- oldDev = int(dev)
- return mknodat(fd, path, mode, oldDev)
-}
-
-// round x to the nearest multiple of y, larger or equal to x.
-//
-// from /usr/include/sys/param.h Macros for counting and rounding.
-// #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
-func roundup(x, y int) int {
- return ((x + y - 1) / y) * y
-}
-
-func (s *Stat_t) convertFrom(old *stat_freebsd11_t) {
- *s = Stat_t{
- Dev: uint64(old.Dev),
- Ino: uint64(old.Ino),
- Nlink: uint64(old.Nlink),
- Mode: old.Mode,
- Uid: old.Uid,
- Gid: old.Gid,
- Rdev: uint64(old.Rdev),
- Atim: old.Atim,
- Mtim: old.Mtim,
- Ctim: old.Ctim,
- Btim: old.Btim,
- Size: old.Size,
- Blocks: old.Blocks,
- Blksize: old.Blksize,
- Flags: old.Flags,
- Gen: uint64(old.Gen),
- }
-}
-
-func (s *Statfs_t) convertFrom(old *statfs_freebsd11_t) {
- *s = Statfs_t{
- Version: _statfsVersion,
- Type: old.Type,
- Flags: old.Flags,
- Bsize: old.Bsize,
- Iosize: old.Iosize,
- Blocks: old.Blocks,
- Bfree: old.Bfree,
- Bavail: old.Bavail,
- Files: old.Files,
- Ffree: old.Ffree,
- Syncwrites: old.Syncwrites,
- Asyncwrites: old.Asyncwrites,
- Syncreads: old.Syncreads,
- Asyncreads: old.Asyncreads,
- // Spare
- Namemax: old.Namemax,
- Owner: old.Owner,
- Fsid: old.Fsid,
- // Charspare
- // Fstypename
- // Mntfromname
- // Mntonname
- }
-
- sl := old.Fstypename[:]
- n := clen(*(*[]byte)(unsafe.Pointer(&sl)))
- copy(s.Fstypename[:], old.Fstypename[:n])
-
- sl = old.Mntfromname[:]
- n = clen(*(*[]byte)(unsafe.Pointer(&sl)))
- copy(s.Mntfromname[:], old.Mntfromname[:n])
-
- sl = old.Mntonname[:]
- n = clen(*(*[]byte)(unsafe.Pointer(&sl)))
- copy(s.Mntonname[:], old.Mntonname[:n])
-}
-
-func convertFromDirents11(buf []byte, old []byte) int {
- const (
- fixedSize = int(unsafe.Offsetof(Dirent{}.Name))
- oldFixedSize = int(unsafe.Offsetof(dirent_freebsd11{}.Name))
- )
-
- dstPos := 0
- srcPos := 0
- for dstPos+fixedSize < len(buf) && srcPos+oldFixedSize < len(old) {
- var dstDirent Dirent
- var srcDirent dirent_freebsd11
-
- // If multiple direntries are written, sometimes when we reach the final one,
- // we may have cap of old less than size of dirent_freebsd11.
- copy((*[unsafe.Sizeof(srcDirent)]byte)(unsafe.Pointer(&srcDirent))[:], old[srcPos:])
-
- reclen := roundup(fixedSize+int(srcDirent.Namlen)+1, 8)
- if dstPos+reclen > len(buf) {
- break
- }
-
- dstDirent.Fileno = uint64(srcDirent.Fileno)
- dstDirent.Off = 0
- dstDirent.Reclen = uint16(reclen)
- dstDirent.Type = srcDirent.Type
- dstDirent.Pad0 = 0
- dstDirent.Namlen = uint16(srcDirent.Namlen)
- dstDirent.Pad1 = 0
-
- copy(dstDirent.Name[:], srcDirent.Name[:srcDirent.Namlen])
- copy(buf[dstPos:], (*[unsafe.Sizeof(dstDirent)]byte)(unsafe.Pointer(&dstDirent))[:])
- padding := buf[dstPos+fixedSize+int(dstDirent.Namlen) : dstPos+reclen]
- for i := range padding {
- padding[i] = 0
- }
-
- dstPos += int(dstDirent.Reclen)
- srcPos += int(srcDirent.Reclen)
- }
-
- return dstPos
+ return Mknodat(AT_FDCWD, path, mode, dev)
}
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
@@ -504,31 +255,31 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
//sys ptrace(request int, pid int, addr uintptr, data int) (err error)
func PtraceAttach(pid int) (err error) {
- return ptrace(PTRACE_ATTACH, pid, 0, 0)
+ return ptrace(PT_ATTACH, pid, 0, 0)
}
func PtraceCont(pid int, signal int) (err error) {
- return ptrace(PTRACE_CONT, pid, 1, signal)
+ return ptrace(PT_CONTINUE, pid, 1, signal)
}
func PtraceDetach(pid int) (err error) {
- return ptrace(PTRACE_DETACH, pid, 1, 0)
+ return ptrace(PT_DETACH, pid, 1, 0)
}
func PtraceGetFpRegs(pid int, fpregsout *FpReg) (err error) {
- return ptrace(PTRACE_GETFPREGS, pid, uintptr(unsafe.Pointer(fpregsout)), 0)
+ return ptrace(PT_GETFPREGS, pid, uintptr(unsafe.Pointer(fpregsout)), 0)
}
func PtraceGetRegs(pid int, regsout *Reg) (err error) {
- return ptrace(PTRACE_GETREGS, pid, uintptr(unsafe.Pointer(regsout)), 0)
+ return ptrace(PT_GETREGS, pid, uintptr(unsafe.Pointer(regsout)), 0)
}
func PtraceLwpEvents(pid int, enable int) (err error) {
- return ptrace(PTRACE_LWPEVENTS, pid, 0, enable)
+ return ptrace(PT_LWP_EVENTS, pid, 0, enable)
}
func PtraceLwpInfo(pid int, info uintptr) (err error) {
- return ptrace(PTRACE_LWPINFO, pid, info, int(unsafe.Sizeof(PtraceLwpInfoStruct{})))
+ return ptrace(PT_LWPINFO, pid, info, int(unsafe.Sizeof(PtraceLwpInfoStruct{})))
}
func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
@@ -548,11 +299,11 @@ func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) {
}
func PtraceSetRegs(pid int, regs *Reg) (err error) {
- return ptrace(PTRACE_SETREGS, pid, uintptr(unsafe.Pointer(regs)), 0)
+ return ptrace(PT_SETREGS, pid, uintptr(unsafe.Pointer(regs)), 0)
}
func PtraceSingleStep(pid int) (err error) {
- return ptrace(PTRACE_SINGLESTEP, pid, 1, 0)
+ return ptrace(PT_STEP, pid, 1, 0)
}
/*
@@ -594,16 +345,12 @@ func PtraceSingleStep(pid int) (err error) {
//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
//sys Flock(fd int, how int) (err error)
//sys Fpathconf(fd int, name int) (val int, err error)
-//sys fstat(fd int, stat *stat_freebsd11_t) (err error)
-//sys fstat_freebsd12(fd int, stat *Stat_t) (err error)
-//sys fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error)
-//sys fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error)
-//sys fstatfs(fd int, stat *statfs_freebsd11_t) (err error)
-//sys fstatfs_freebsd12(fd int, stat *Statfs_t) (err error)
+//sys Fstat(fd int, stat *Stat_t) (err error)
+//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
+//sys Fstatfs(fd int, stat *Statfs_t) (err error)
//sys Fsync(fd int) (err error)
//sys Ftruncate(fd int, length int64) (err error)
-//sys getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
-//sys getdirentries_freebsd12(fd int, buf []byte, basep *uint64) (n int, err error)
+//sys getdirentries(fd int, buf []byte, basep *uint64) (n int, err error)
//sys Getdtablesize() (size int)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (uid int)
@@ -625,19 +372,16 @@ func PtraceSingleStep(pid int) (err error) {
//sys Link(path string, link string) (err error)
//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)
//sys Listen(s int, backlog int) (err error)
-//sys lstat(path string, stat *stat_freebsd11_t) (err error)
//sys Mkdir(path string, mode uint32) (err error)
//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
//sys Mkfifo(path string, mode uint32) (err error)
-//sys mknod(path string, mode uint32, dev int) (err error)
-//sys mknodat(fd int, path string, mode uint32, dev int) (err error)
-//sys mknodat_freebsd12(fd int, path string, mode uint32, dev uint64) (err error)
+//sys Mknodat(fd int, path string, mode uint32, dev uint64) (err error)
//sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
//sys Open(path string, mode int, perm uint32) (fd int, err error)
//sys Openat(fdat int, path string, mode int, perm uint32) (fd int, err error)
//sys Pathconf(path string, name int) (val int, err error)
-//sys Pread(fd int, p []byte, offset int64) (n int, err error)
-//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
+//sys pread(fd int, p []byte, offset int64) (n int, err error)
+//sys pwrite(fd int, p []byte, offset int64) (n int, err error)
//sys read(fd int, p []byte) (n int, err error)
//sys Readlink(path string, buf []byte) (n int, err error)
//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
@@ -661,9 +405,7 @@ func PtraceSingleStep(pid int) (err error) {
//sysnb Setsid() (pid int, err error)
//sysnb Settimeofday(tp *Timeval) (err error)
//sysnb Setuid(uid int) (err error)
-//sys stat(path string, stat *stat_freebsd11_t) (err error)
-//sys statfs(path string, stat *statfs_freebsd11_t) (err error)
-//sys statfs_freebsd12(path string, stat *Statfs_t) (err error)
+//sys Statfs(path string, stat *Statfs_t) (err error)
//sys Symlink(path string, link string) (err error)
//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
//sys Sync() (err error)