X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/cmd/vendor/golang.org/x/sys/unix
opt
/
golang
/
1.22.0
/
src
/
cmd
/
vendor
/
golang.org
/
x
/
sys
/
unix
/
📁
..
📄
.gitignore
(16 B)
📄
README.md
(8.48 KB)
📄
affinity_linux.go
(1.88 KB)
📄
aliases.go
(396 B)
📄
asm_aix_ppc64.s
(407 B)
📄
asm_bsd_386.s
(696 B)
📄
asm_bsd_amd64.s
(722 B)
📄
asm_bsd_arm.s
(686 B)
📄
asm_bsd_arm64.s
(709 B)
📄
asm_bsd_ppc64.s
(716 B)
📄
asm_bsd_riscv64.s
(711 B)
📄
asm_linux_386.s
(1.44 KB)
📄
asm_linux_amd64.s
(1.18 KB)
📄
asm_linux_arm.s
(1.11 KB)
📄
asm_linux_arm64.s
(1.08 KB)
📄
asm_linux_loong64.s
(1.16 KB)
📄
asm_linux_mips64x.s
(1.14 KB)
📄
asm_linux_mipsx.s
(1.14 KB)
📄
asm_linux_ppc64x.s
(909 B)
📄
asm_linux_riscv64.s
(1.02 KB)
📄
asm_linux_s390x.s
(1.12 KB)
📄
asm_openbsd_mips64.s
(677 B)
📄
asm_solaris_amd64.s
(423 B)
📄
asm_zos_s390x.s
(8.4 KB)
📄
bluetooth_linux.go
(680 B)
📄
cap_freebsd.go
(5.01 KB)
📄
constants.go
(318 B)
📄
dev_aix_ppc.go
(739 B)
📄
dev_aix_ppc64.go
(858 B)
📄
dev_darwin.go
(747 B)
📄
dev_dragonfly.go
(1.01 KB)
📄
dev_freebsd.go
(1013 B)
📄
dev_linux.go
(1.54 KB)
📄
dev_netbsd.go
(913 B)
📄
dev_openbsd.go
(918 B)
📄
dev_zos.go
(830 B)
📄
dirent.go
(3.01 KB)
📄
endian_big.go
(330 B)
📄
endian_little.go
(358 B)
📄
env_unix.go
(645 B)
📄
epoll_zos.go
(5.02 KB)
📄
fcntl.go
(1.05 KB)
📄
fcntl_darwin.go
(806 B)
📄
fcntl_linux_32bit.go
(436 B)
📄
fdset.go
(781 B)
📄
fstatfs_zos.go
(4.07 KB)
📄
gccgo.go
(1.91 KB)
📄
gccgo_c.c
(1.49 KB)
📄
gccgo_linux_amd64.go
(436 B)
📄
ifreq_linux.go
(4.27 KB)
📄
ioctl_linux.go
(8.07 KB)
📄
ioctl_signed.go
(2.2 KB)
📄
ioctl_unsigned.go
(2.26 KB)
📄
ioctl_zos.go
(2.03 KB)
📄
mkall.sh
(8.11 KB)
📄
mkerrors.sh
(19.56 KB)
📄
mmap_nomremap.go
(336 B)
📄
mremap.go
(1.36 KB)
📄
pagesize_unix.go
(389 B)
📄
pledge_openbsd.go
(2.33 KB)
📄
ptrace_darwin.go
(315 B)
📄
ptrace_ios.go
(284 B)
📄
race.go
(629 B)
📄
race0.go
(553 B)
📄
readdirent_getdents.go
(401 B)
📄
readdirent_getdirentries.go
(698 B)
📄
sockcmsg_dragonfly.go
(544 B)
📄
sockcmsg_linux.go
(2.6 KB)
📄
sockcmsg_unix.go
(3.14 KB)
📄
sockcmsg_unix_other.go
(1.2 KB)
📄
syscall.go
(2.81 KB)
📄
syscall_aix.go
(16.1 KB)
📄
syscall_aix_ppc.go
(1.27 KB)
📄
syscall_aix_ppc64.go
(1.9 KB)
📄
syscall_bsd.go
(14.96 KB)
📄
syscall_darwin.go
(20.72 KB)
📄
syscall_darwin_amd64.go
(1.49 KB)
📄
syscall_darwin_arm64.go
(1.41 KB)
📄
syscall_darwin_libSystem.go
(1.21 KB)
📄
syscall_dragonfly.go
(11.18 KB)
📄
syscall_dragonfly_amd64.go
(1.25 KB)
📄
syscall_freebsd.go
(15.34 KB)
📄
syscall_freebsd_386.go
(1.48 KB)
📄
syscall_freebsd_amd64.go
(1.44 KB)
📄
syscall_freebsd_arm.go
(1.35 KB)
📄
syscall_freebsd_arm64.go
(1.31 KB)
📄
syscall_freebsd_riscv64.go
(1.32 KB)
📄
syscall_hurd.go
(635 B)
📄
syscall_hurd_386.go
(447 B)
📄
syscall_illumos.go
(1.76 KB)
📄
syscall_linux.go
(74.41 KB)
📄
syscall_linux_386.go
(8.88 KB)
📄
syscall_linux_alarm.go
(440 B)
📄
syscall_linux_amd64.go
(5.28 KB)
📄
syscall_linux_amd64_gc.go
(290 B)
📄
syscall_linux_arm.go
(6.94 KB)
📄
syscall_linux_arm64.go
(5.97 KB)
📄
syscall_linux_gc.go
(495 B)
📄
syscall_linux_gc_386.go
(585 B)
📄
syscall_linux_gc_arm.go
(411 B)
📄
syscall_linux_gccgo_386.go
(986 B)
📄
syscall_linux_gccgo_arm.go
(596 B)
📄
syscall_linux_loong64.go
(6.66 KB)
📄
syscall_linux_mips64x.go
(5.83 KB)
📄
syscall_linux_mipsx.go
(5.81 KB)
📄
syscall_linux_ppc.go
(6.85 KB)
📄
syscall_linux_ppc64x.go
(4.98 KB)
📄
syscall_linux_riscv64.go
(6.13 KB)
📄
syscall_linux_s390x.go
(9.29 KB)
📄
syscall_linux_sparc64.go
(4.37 KB)
📄
syscall_netbsd.go
(12.35 KB)
📄
syscall_netbsd_386.go
(819 B)
📄
syscall_netbsd_amd64.go
(814 B)
📄
syscall_netbsd_arm.go
(819 B)
📄
syscall_netbsd_arm64.go
(814 B)
📄
syscall_openbsd.go
(11.04 KB)
📄
syscall_openbsd_386.go
(1000 B)
📄
syscall_openbsd_amd64.go
(990 B)
📄
syscall_openbsd_arm.go
(1000 B)
📄
syscall_openbsd_arm64.go
(990 B)
📄
syscall_openbsd_libc.go
(1.1 KB)
📄
syscall_openbsd_mips64.go
(955 B)
📄
syscall_openbsd_ppc64.go
(990 B)
📄
syscall_openbsd_riscv64.go
(994 B)
📄
syscall_solaris.go
(31.11 KB)
📄
syscall_solaris_amd64.go
(593 B)
📄
syscall_unix.go
(16.45 KB)
📄
syscall_unix_gc.go
(640 B)
📄
syscall_unix_gc_ppc64x.go
(786 B)
📄
syscall_zos_s390x.go
(52.88 KB)
📄
sysvshm_linux.go
(521 B)
📄
sysvshm_unix.go
(1.42 KB)
📄
sysvshm_unix_other.go
(398 B)
📄
timestruct.go
(2.2 KB)
📄
unveil_openbsd.go
(1.19 KB)
📄
xattr_bsd.go
(5.66 KB)
📄
zerrors_aix_ppc.go
(52.42 KB)
📄
zerrors_aix_ppc64.go
(52.67 KB)
📄
zerrors_darwin_amd64.go
(87.45 KB)
📄
zerrors_darwin_arm64.go
(87.45 KB)
📄
zerrors_dragonfly_amd64.go
(70.7 KB)
📄
zerrors_freebsd_386.go
(79.55 KB)
📄
zerrors_freebsd_amd64.go
(79.44 KB)
📄
zerrors_freebsd_arm.go
(79.19 KB)
📄
zerrors_freebsd_arm64.go
(79.22 KB)
📄
zerrors_freebsd_riscv64.go
(83.75 KB)
📄
zerrors_linux.go
(180.01 KB)
📄
zerrors_linux_386.go
(33.98 KB)
📄
zerrors_linux_amd64.go
(34 KB)
📄
zerrors_linux_arm.go
(34.22 KB)
📄
zerrors_linux_arm64.go
(34.05 KB)
📄
zerrors_linux_loong64.go
(33.73 KB)
📄
zerrors_linux_mips.go
(34.54 KB)
📄
zerrors_linux_mips64.go
(34.54 KB)
📄
zerrors_linux_mips64le.go
(34.55 KB)
📄
zerrors_linux_mipsle.go
(34.54 KB)
📄
zerrors_linux_ppc.go
(36.62 KB)
📄
zerrors_linux_ppc64.go
(36.79 KB)
📄
zerrors_linux_ppc64le.go
(36.8 KB)
📄
zerrors_linux_riscv64.go
(33.59 KB)
📄
zerrors_linux_s390x.go
(36.53 KB)
📄
zerrors_linux_sparc64.go
(38.61 KB)
📄
zerrors_netbsd_386.go
(72.76 KB)
📄
zerrors_netbsd_amd64.go
(72.35 KB)
📄
zerrors_netbsd_arm.go
(71.89 KB)
📄
zerrors_netbsd_arm64.go
(72.35 KB)
📄
zerrors_openbsd_386.go
(78.55 KB)
📄
zerrors_openbsd_amd64.go
(78.55 KB)
📄
zerrors_openbsd_arm.go
(78.54 KB)
📄
zerrors_openbsd_arm64.go
(78.55 KB)
📄
zerrors_openbsd_mips64.go
(78.55 KB)
📄
zerrors_openbsd_ppc64.go
(78.51 KB)
📄
zerrors_openbsd_riscv64.go
(78.47 KB)
📄
zerrors_solaris_amd64.go
(59 KB)
📄
zerrors_zos_s390x.go
(34.47 KB)
📄
zptrace_armnn_linux.go
(1.17 KB)
📄
zptrace_linux_arm64.go
(721 B)
📄
zptrace_mipsnn_linux.go
(1.36 KB)
📄
zptrace_mipsnnle_linux.go
(1.41 KB)
📄
zptrace_x86_linux.go
(1.81 KB)
📄
zsyscall_aix_ppc.go
(35.68 KB)
📄
zsyscall_aix_ppc64.go
(30.04 KB)
📄
zsyscall_aix_ppc64_gc.go
(42.43 KB)
📄
zsyscall_aix_ppc64_gccgo.go
(30.85 KB)
📄
zsyscall_darwin_amd64.go
(66.74 KB)
📄
zsyscall_darwin_amd64.s
(29.28 KB)
📄
zsyscall_darwin_arm64.go
(66.69 KB)
📄
zsyscall_darwin_arm64.s
(29.21 KB)
📄
zsyscall_dragonfly_amd64.go
(38.79 KB)
📄
zsyscall_freebsd_386.go
(45.09 KB)
📄
zsyscall_freebsd_amd64.go
(44.9 KB)
📄
zsyscall_freebsd_arm.go
(45.13 KB)
📄
zsyscall_freebsd_arm64.go
(44.9 KB)
📄
zsyscall_freebsd_riscv64.go
(44.91 KB)
📄
zsyscall_illumos_amd64.go
(2.63 KB)
📄
zsyscall_linux.go
(54.29 KB)
📄
zsyscall_linux_386.go
(12.11 KB)
📄
zsyscall_linux_amd64.go
(16.5 KB)
📄
zsyscall_linux_arm.go
(15.61 KB)
📄
zsyscall_linux_arm64.go
(14.22 KB)
📄
zsyscall_linux_loong64.go
(12.61 KB)
📄
zsyscall_linux_mips.go
(16.76 KB)
📄
zsyscall_linux_mips64.go
(16.27 KB)
📄
zsyscall_linux_mips64le.go
(16.01 KB)
📄
zsyscall_linux_mipsle.go
(16.76 KB)
📄
zsyscall_linux_ppc.go
(16.83 KB)
📄
zsyscall_linux_ppc64.go
(17.79 KB)
📄
zsyscall_linux_ppc64le.go
(17.79 KB)
📄
zsyscall_linux_riscv64.go
(14.2 KB)
📄
zsyscall_linux_s390x.go
(12.11 KB)
📄
zsyscall_linux_sparc64.go
(16.43 KB)
📄
zsyscall_netbsd_386.go
(44.13 KB)
📄
zsyscall_netbsd_amd64.go
(43.94 KB)
📄
zsyscall_netbsd_arm.go
(44.13 KB)
📄
zsyscall_netbsd_arm64.go
(43.94 KB)
📄
zsyscall_openbsd_386.go
(57.67 KB)
📄
zsyscall_openbsd_386.s
(26.7 KB)
📄
zsyscall_openbsd_amd64.go
(57.52 KB)
📄
zsyscall_openbsd_amd64.s
(26.7 KB)
📄
zsyscall_openbsd_arm.go
(57.69 KB)
📄
zsyscall_openbsd_arm.s
(26.7 KB)
📄
zsyscall_openbsd_arm64.go
(57.52 KB)
📄
zsyscall_openbsd_arm64.s
(26.7 KB)
📄
zsyscall_openbsd_mips64.go
(57.52 KB)
📄
zsyscall_openbsd_mips64.s
(26.7 KB)
📄
zsyscall_openbsd_ppc64.go
(57.52 KB)
📄
zsyscall_openbsd_ppc64.s
(27.51 KB)
📄
zsyscall_openbsd_riscv64.go
(57.53 KB)
📄
zsyscall_openbsd_riscv64.s
(26.7 KB)
📄
zsyscall_solaris_amd64.go
(59.74 KB)
📄
zsyscall_zos_s390x.go
(29.82 KB)
📄
zsysctl_openbsd_386.go
(11.93 KB)
📄
zsysctl_openbsd_amd64.go
(11.93 KB)
📄
zsysctl_openbsd_arm.go
(11.93 KB)
📄
zsysctl_openbsd_arm64.go
(11.93 KB)
📄
zsysctl_openbsd_mips64.go
(11.93 KB)
📄
zsysctl_openbsd_ppc64.go
(11.93 KB)
📄
zsysctl_openbsd_riscv64.go
(11.97 KB)
📄
zsysnum_darwin_amd64.go
(17.84 KB)
📄
zsysnum_darwin_arm64.go
(17.76 KB)
📄
zsysnum_dragonfly_amd64.go
(27.61 KB)
📄
zsysnum_freebsd_386.go
(36.09 KB)
📄
zsysnum_freebsd_amd64.go
(36.1 KB)
📄
zsysnum_freebsd_arm.go
(36.09 KB)
📄
zsysnum_freebsd_arm64.go
(36.1 KB)
📄
zsysnum_freebsd_riscv64.go
(36.1 KB)
📄
zsysnum_linux_386.go
(17.38 KB)
📄
zsysnum_linux_amd64.go
(12.59 KB)
📄
zsysnum_linux_arm.go
(15.99 KB)
📄
zsysnum_linux_arm64.go
(10.69 KB)
📄
zsysnum_linux_loong64.go
(10.48 KB)
📄
zsysnum_linux_mips.go
(17.27 KB)
📄
zsysnum_linux_mips64.go
(12.74 KB)
📄
zsysnum_linux_mips64le.go
(12.74 KB)
📄
zsysnum_linux_mipsle.go
(17.28 KB)
📄
zsysnum_linux_ppc.go
(17.02 KB)
📄
zsysnum_linux_ppc64.go
(13.95 KB)
📄
zsysnum_linux_ppc64le.go
(13.96 KB)
📄
zsysnum_linux_riscv64.go
(10.71 KB)
📄
zsysnum_linux_s390x.go
(12.84 KB)
📄
zsysnum_linux_sparc64.go
(13.26 KB)
📄
zsysnum_netbsd_386.go
(25.72 KB)
📄
zsysnum_netbsd_amd64.go
(25.73 KB)
📄
zsysnum_netbsd_arm.go
(25.72 KB)
📄
zsysnum_netbsd_arm64.go
(25.71 KB)
📄
zsysnum_openbsd_386.go
(17.91 KB)
📄
zsysnum_openbsd_amd64.go
(17.91 KB)
📄
zsysnum_openbsd_arm.go
(17.91 KB)
📄
zsysnum_openbsd_arm64.go
(17.82 KB)
📄
zsysnum_openbsd_mips64.go
(18.05 KB)
📄
zsysnum_openbsd_ppc64.go
(17.76 KB)
📄
zsysnum_openbsd_riscv64.go
(17.83 KB)
📄
zsysnum_zos_s390x.go
(116.99 KB)
📄
ztypes_aix_ppc.go
(4.91 KB)
📄
ztypes_aix_ppc64.go
(4.98 KB)
📄
ztypes_darwin_amd64.go
(12.4 KB)
📄
ztypes_darwin_arm64.go
(12.4 KB)
📄
ztypes_dragonfly_amd64.go
(6.91 KB)
📄
ztypes_freebsd_386.go
(9.63 KB)
📄
ztypes_freebsd_amd64.go
(9.68 KB)
📄
ztypes_freebsd_arm.go
(9.5 KB)
📄
ztypes_freebsd_arm64.go
(9.39 KB)
📄
ztypes_freebsd_riscv64.go
(9.46 KB)
📄
ztypes_linux.go
(246.65 KB)
📄
ztypes_linux_386.go
(12.37 KB)
📄
ztypes_linux_amd64.go
(12.56 KB)
📄
ztypes_linux_arm.go
(12.33 KB)
📄
ztypes_linux_arm64.go
(12.21 KB)
📄
ztypes_linux_loong64.go
(12.23 KB)
📄
ztypes_linux_mips.go
(12.39 KB)
📄
ztypes_linux_mips64.go
(12.26 KB)
📄
ztypes_linux_mips64le.go
(12.27 KB)
📄
ztypes_linux_mipsle.go
(12.4 KB)
📄
ztypes_linux_ppc.go
(12.57 KB)
📄
ztypes_linux_ppc64.go
(12.4 KB)
📄
ztypes_linux_ppc64le.go
(12.41 KB)
📄
ztypes_linux_riscv64.go
(13.44 KB)
📄
ztypes_linux_s390x.go
(12.7 KB)
📄
ztypes_linux_sparc64.go
(12.26 KB)
📄
ztypes_netbsd_386.go
(9.46 KB)
📄
ztypes_netbsd_amd64.go
(9.65 KB)
📄
ztypes_netbsd_arm.go
(9.59 KB)
📄
ztypes_netbsd_arm64.go
(9.65 KB)
📄
ztypes_openbsd_386.go
(9.24 KB)
📄
ztypes_openbsd_amd64.go
(9.25 KB)
📄
ztypes_openbsd_arm.go
(9.38 KB)
📄
ztypes_openbsd_arm64.go
(9.26 KB)
📄
ztypes_openbsd_mips64.go
(9.26 KB)
📄
ztypes_openbsd_ppc64.go
(9.28 KB)
📄
ztypes_openbsd_riscv64.go
(9.29 KB)
📄
ztypes_solaris_amd64.go
(7.53 KB)
📄
ztypes_zos_s390x.go
(6.66 KB)
Editing: syscall_darwin.go
// Copyright 2009,2010 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. // Darwin system calls. // This file is compiled as ordinary Go code, // but it is also input to mksyscall, // which parses the //sys lines and generates system call stubs. // Note that sometimes we use a lowercase //sys name and wrap // it in our own nicer implementation, either here or in // syscall_bsd.go or syscall_unix.go. package unix import ( "fmt" "syscall" "unsafe" ) //sys closedir(dir uintptr) (err error) //sys readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) func fdopendir(fd int) (dir uintptr, err error) { r0, _, e1 := syscall_syscallPtr(libc_fdopendir_trampoline_addr, uintptr(fd), 0, 0) dir = uintptr(r0) if e1 != 0 { err = errnoErr(e1) } return } var libc_fdopendir_trampoline_addr uintptr //go:cgo_import_dynamic libc_fdopendir fdopendir "/usr/lib/libSystem.B.dylib" func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { // Simulate Getdirentries using fdopendir/readdir_r/closedir. // We store the number of entries to skip in the seek // offset of fd. See issue #31368. // It's not the full required semantics, but should handle the case // of calling Getdirentries or ReadDirent repeatedly. // It won't handle assigning the results of lseek to *basep, or handle // the directory being edited underfoot. skip, err := Seek(fd, 0, 1 /* SEEK_CUR */) if err != nil { return 0, err } // We need to duplicate the incoming file descriptor // because the caller expects to retain control of it, but // fdopendir expects to take control of its argument. // Just Dup'ing the file descriptor is not enough, as the // result shares underlying state. Use Openat to make a really // new file descriptor referring to the same directory. fd2, err := Openat(fd, ".", O_RDONLY, 0) if err != nil { return 0, err } d, err := fdopendir(fd2) if err != nil { Close(fd2) return 0, err } defer closedir(d) var cnt int64 for { var entry Dirent var entryp *Dirent e := readdir_r(d, &entry, &entryp) if e != 0 { return n, errnoErr(e) } if entryp == nil { break } if skip > 0 { skip-- cnt++ continue } reclen := int(entry.Reclen) if reclen > len(buf) { // Not enough room. Return for now. // The counter will let us know where we should start up again. // Note: this strategy for suspending in the middle and // restarting is O(n^2) in the length of the directory. Oh well. break } // Copy entry into return buffer. s := unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen) copy(buf, s) buf = buf[reclen:] n += reclen cnt++ } // Set the seek offset of the input fd to record // how many files we've already returned. _, err = Seek(fd, cnt, 0 /* SEEK_SET */) if err != nil { return n, err } return n, nil } // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. type SockaddrDatalink struct { Len uint8 Family uint8 Index uint16 Type uint8 Nlen uint8 Alen uint8 Slen uint8 Data [12]int8 raw RawSockaddrDatalink } // SockaddrCtl implements the Sockaddr interface for AF_SYSTEM type sockets. type SockaddrCtl struct { ID uint32 Unit uint32 raw RawSockaddrCtl } func (sa *SockaddrCtl) sockaddr() (unsafe.Pointer, _Socklen, error) { sa.raw.Sc_len = SizeofSockaddrCtl sa.raw.Sc_family = AF_SYSTEM sa.raw.Ss_sysaddr = AF_SYS_CONTROL sa.raw.Sc_id = sa.ID sa.raw.Sc_unit = sa.Unit return unsafe.Pointer(&sa.raw), SizeofSockaddrCtl, nil } // SockaddrVM implements the Sockaddr interface for AF_VSOCK type sockets. // SockaddrVM provides access to Darwin VM sockets: a mechanism that enables // bidirectional communication between a hypervisor and its guest virtual // machines. type SockaddrVM struct { // CID and Port specify a context ID and port address for a VM socket. // Guests have a unique CID, and hosts may have a well-known CID of: // - VMADDR_CID_HYPERVISOR: refers to the hypervisor process. // - VMADDR_CID_LOCAL: refers to local communication (loopback). // - VMADDR_CID_HOST: refers to other processes on the host. CID uint32 Port uint32 raw RawSockaddrVM } func (sa *SockaddrVM) sockaddr() (unsafe.Pointer, _Socklen, error) { sa.raw.Len = SizeofSockaddrVM sa.raw.Family = AF_VSOCK sa.raw.Port = sa.Port sa.raw.Cid = sa.CID return unsafe.Pointer(&sa.raw), SizeofSockaddrVM, nil } func anyToSockaddrGOOS(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { switch rsa.Addr.Family { case AF_SYSTEM: pp := (*RawSockaddrCtl)(unsafe.Pointer(rsa)) if pp.Ss_sysaddr == AF_SYS_CONTROL { sa := new(SockaddrCtl) sa.ID = pp.Sc_id sa.Unit = pp.Sc_unit return sa, nil } case AF_VSOCK: pp := (*RawSockaddrVM)(unsafe.Pointer(rsa)) sa := &SockaddrVM{ CID: pp.Cid, Port: pp.Port, } return sa, nil } return nil, EAFNOSUPPORT } // Some external packages rely on SYS___SYSCTL being defined to implement their // own sysctl wrappers. Provide it here, even though direct syscalls are no // longer supported on darwin. const SYS___SYSCTL = SYS_SYSCTL // Translate "kern.hostname" to []_C_int{0,1,2,3}. func nametomib(name string) (mib []_C_int, err error) { const siz = unsafe.Sizeof(mib[0]) // NOTE(rsc): It seems strange to set the buffer to have // size CTL_MAXNAME+2 but use only CTL_MAXNAME // as the size. I don't know why the +2 is here, but the // kernel uses +2 for its own implementation of this function. // I am scared that if we don't include the +2 here, the kernel // will silently write 2 words farther than we specify // and we'll get memory corruption. var buf [CTL_MAXNAME + 2]_C_int n := uintptr(CTL_MAXNAME) * siz p := (*byte)(unsafe.Pointer(&buf[0])) bytes, err := ByteSliceFromString(name) if err != nil { return nil, err } // Magic sysctl: "setting" 0.3 to a string name // lets you read back the array of integers form. if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { return nil, err } return buf[0 : n/siz], nil } func direntIno(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino)) } func direntReclen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen)) } func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) } func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) } func PtraceDenyAttach() (err error) { return ptrace(PT_DENY_ATTACH, 0, 0, 0) } //sysnb pipe(p *[2]int32) (err error) func Pipe(p []int) (err error) { if len(p) != 2 { return EINVAL } var x [2]int32 err = pipe(&x) if err == nil { p[0] = int(x[0]) p[1] = int(x[1]) } return } func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { var _p0 unsafe.Pointer var bufsize uintptr if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) } return getfsstat(_p0, bufsize, flags) } func xattrPointer(dest []byte) *byte { // It's only when dest is set to NULL that the OS X implementations of // getxattr() and listxattr() return the current sizes of the named attributes. // An empty byte array is not sufficient. To maintain the same behaviour as the // linux implementation, we wrap around the system calls and pass in NULL when // dest is empty. var destp *byte if len(dest) > 0 { destp = &dest[0] } return destp } //sys getxattr(path string, attr string, dest *byte, size int, position uint32, options int) (sz int, err error) func Getxattr(path string, attr string, dest []byte) (sz int, err error) { return getxattr(path, attr, xattrPointer(dest), len(dest), 0, 0) } func Lgetxattr(link string, attr string, dest []byte) (sz int, err error) { return getxattr(link, attr, xattrPointer(dest), len(dest), 0, XATTR_NOFOLLOW) } //sys fgetxattr(fd int, attr string, dest *byte, size int, position uint32, options int) (sz int, err error) func Fgetxattr(fd int, attr string, dest []byte) (sz int, err error) { return fgetxattr(fd, attr, xattrPointer(dest), len(dest), 0, 0) } //sys setxattr(path string, attr string, data *byte, size int, position uint32, options int) (err error) func Setxattr(path string, attr string, data []byte, flags int) (err error) { // The parameters for the OS X implementation vary slightly compared to the // linux system call, specifically the position parameter: // // linux: // int setxattr( // const char *path, // const char *name, // const void *value, // size_t size, // int flags // ); // // darwin: // int setxattr( // const char *path, // const char *name, // void *value, // size_t size, // u_int32_t position, // int options // ); // // position specifies the offset within the extended attribute. In the // current implementation, only the resource fork extended attribute makes // use of this argument. For all others, position is reserved. We simply // default to setting it to zero. return setxattr(path, attr, xattrPointer(data), len(data), 0, flags) } func Lsetxattr(link string, attr string, data []byte, flags int) (err error) { return setxattr(link, attr, xattrPointer(data), len(data), 0, flags|XATTR_NOFOLLOW) } //sys fsetxattr(fd int, attr string, data *byte, size int, position uint32, options int) (err error) func Fsetxattr(fd int, attr string, data []byte, flags int) (err error) { return fsetxattr(fd, attr, xattrPointer(data), len(data), 0, 0) } //sys removexattr(path string, attr string, options int) (err error) func Removexattr(path string, attr string) (err error) { // We wrap around and explicitly zero out the options provided to the OS X // implementation of removexattr, we do so for interoperability with the // linux variant. return removexattr(path, attr, 0) } func Lremovexattr(link string, attr string) (err error) { return removexattr(link, attr, XATTR_NOFOLLOW) } //sys fremovexattr(fd int, attr string, options int) (err error) func Fremovexattr(fd int, attr string) (err error) { return fremovexattr(fd, attr, 0) } //sys listxattr(path string, dest *byte, size int, options int) (sz int, err error) func Listxattr(path string, dest []byte) (sz int, err error) { return listxattr(path, xattrPointer(dest), len(dest), 0) } func Llistxattr(link string, dest []byte) (sz int, err error) { return listxattr(link, xattrPointer(dest), len(dest), XATTR_NOFOLLOW) } //sys flistxattr(fd int, dest *byte, size int, options int) (sz int, err error) func Flistxattr(fd int, dest []byte) (sz int, err error) { return flistxattr(fd, xattrPointer(dest), len(dest), 0) } //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) /* * Wrapped */ //sys fcntl(fd int, cmd int, arg int) (val int, err error) //sys kill(pid int, signum int, posix int) (err error) func Kill(pid int, signum syscall.Signal) (err error) { return kill(pid, int(signum), 1) } //sys ioctl(fd int, req uint, arg uintptr) (err error) //sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error { return ioctlPtr(fd, CTLIOCGINFO, unsafe.Pointer(ctlInfo)) } // IfreqMTU is struct ifreq used to get or set a network device's MTU. type IfreqMTU struct { Name [IFNAMSIZ]byte MTU int32 } // IoctlGetIfreqMTU performs the SIOCGIFMTU ioctl operation on fd to get the MTU // of the network device specified by ifname. func IoctlGetIfreqMTU(fd int, ifname string) (*IfreqMTU, error) { var ifreq IfreqMTU copy(ifreq.Name[:], ifname) err := ioctlPtr(fd, SIOCGIFMTU, unsafe.Pointer(&ifreq)) return &ifreq, err } // IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU // of the network device specified by ifreq.Name. func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error { return ioctlPtr(fd, SIOCSIFMTU, unsafe.Pointer(ifreq)) } //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL func Uname(uname *Utsname) error { mib := []_C_int{CTL_KERN, KERN_OSTYPE} n := unsafe.Sizeof(uname.Sysname) if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { return err } mib = []_C_int{CTL_KERN, KERN_HOSTNAME} n = unsafe.Sizeof(uname.Nodename) if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { return err } mib = []_C_int{CTL_KERN, KERN_OSRELEASE} n = unsafe.Sizeof(uname.Release) if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { return err } mib = []_C_int{CTL_KERN, KERN_VERSION} n = unsafe.Sizeof(uname.Version) if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { return err } // The version might have newlines or tabs in it, convert them to // spaces. for i, b := range uname.Version { if b == '\n' || b == '\t' { if i == len(uname.Version)-1 { uname.Version[i] = 0 } else { uname.Version[i] = ' ' } } } mib = []_C_int{CTL_HW, HW_MACHINE} n = unsafe.Sizeof(uname.Machine) if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { return err } return nil } func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) } var length = int64(count) err = sendfile(infd, outfd, *offset, &length, nil, 0) written = int(length) return } func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) { var value IPMreqn vallen := _Socklen(SizeofIPMreqn) errno := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, errno } func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq)) } // GetsockoptXucred is a getsockopt wrapper that returns an Xucred struct. // The usual level and opt are SOL_LOCAL and LOCAL_PEERCRED, respectively. func GetsockoptXucred(fd, level, opt int) (*Xucred, error) { x := new(Xucred) vallen := _Socklen(SizeofXucred) err := getsockopt(fd, level, opt, unsafe.Pointer(x), &vallen) return x, err } func GetsockoptTCPConnectionInfo(fd, level, opt int) (*TCPConnectionInfo, error) { var value TCPConnectionInfo vallen := _Socklen(SizeofTCPConnectionInfo) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func SysctlKinfoProc(name string, args ...int) (*KinfoProc, error) { mib, err := sysctlmib(name, args...) if err != nil { return nil, err } var kinfo KinfoProc n := uintptr(SizeofKinfoProc) if err := sysctl(mib, (*byte)(unsafe.Pointer(&kinfo)), &n, nil, 0); err != nil { return nil, err } if n != SizeofKinfoProc { return nil, EIO } return &kinfo, nil } func SysctlKinfoProcSlice(name string, args ...int) ([]KinfoProc, error) { mib, err := sysctlmib(name, args...) if err != nil { return nil, err } for { // Find size. n := uintptr(0) if err := sysctl(mib, nil, &n, nil, 0); err != nil { return nil, err } if n == 0 { return nil, nil } if n%SizeofKinfoProc != 0 { return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) } // Read into buffer of that size. buf := make([]KinfoProc, n/SizeofKinfoProc) if err := sysctl(mib, (*byte)(unsafe.Pointer(&buf[0])), &n, nil, 0); err != nil { if err == ENOMEM { // Process table grew. Try again. continue } return nil, err } if n%SizeofKinfoProc != 0 { return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) } // The actual call may return less than the original reported required // size so ensure we deal with that. return buf[:n/SizeofKinfoProc], nil } } //sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) //sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error) //sys shmctl(id int, cmd int, buf *SysvShmDesc) (result int, err error) //sys shmdt(addr uintptr) (err error) //sys shmget(key int, size int, flag int) (id int, err error) /* * Exposed directly */ //sys Access(path string, mode uint32) (err error) //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) //sys Chdir(path string) (err error) //sys Chflags(path string, flags int) (err error) //sys Chmod(path string, mode uint32) (err error) //sys Chown(path string, uid int, gid int) (err error) //sys Chroot(path string) (err error) //sys ClockGettime(clockid int32, time *Timespec) (err error) //sys Close(fd int) (err error) //sys Clonefile(src string, dst string, flags int) (err error) //sys Clonefileat(srcDirfd int, src string, dstDirfd int, dst string, flags int) (err error) //sys Dup(fd int) (nfd int, err error) //sys Dup2(from int, to int) (err error) //sys Exchangedata(path1 string, path2 string, options int) (err error) //sys Exit(code int) //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) //sys Fchdir(fd int) (err error) //sys Fchflags(fd int, flags int) (err error) //sys Fchmod(fd int, mode uint32) (err error) //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) //sys Fchown(fd int, uid int, gid int) (err error) //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) //sys Fclonefileat(srcDirfd int, dstDirfd int, dst string, flags int) (err error) //sys Flock(fd int, how int) (err error) //sys Fpathconf(fd int, name int) (val int, err error) //sys Fsync(fd int) (err error) //sys Ftruncate(fd int, length int64) (err error) //sys Getcwd(buf []byte) (n int, err error) //sys Getdtablesize() (size int) //sysnb Getegid() (egid int) //sysnb Geteuid() (uid int) //sysnb Getgid() (gid int) //sysnb Getpgid(pid int) (pgid int, err error) //sysnb Getpgrp() (pgrp int) //sysnb Getpid() (pid int) //sysnb Getppid() (ppid int) //sys Getpriority(which int, who int) (prio int, err error) //sysnb Getrlimit(which int, lim *Rlimit) (err error) //sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Getsid(pid int) (sid int, err error) //sysnb Gettimeofday(tp *Timeval) (err error) //sysnb Getuid() (uid int) //sysnb Issetugid() (tainted bool) //sys Kqueue() (fd int, err error) //sys Lchown(path string, uid int, gid 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 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 Mount(fsType string, dir string, flags int, data unsafe.Pointer) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(dirfd 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 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) //sys Rename(from string, to string) (err error) //sys Renameat(fromfd int, from string, tofd int, to string) (err error) //sys Revoke(path string) (err error) //sys Rmdir(path string) (err error) //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) //sys Setattrlist(path string, attrlist *Attrlist, attrBuf []byte, options int) (err error) //sys Setegid(egid int) (err error) //sysnb Seteuid(euid int) (err error) //sysnb Setgid(gid int) (err error) //sys Setlogin(name string) (err error) //sysnb Setpgid(pid int, pgid int) (err error) //sys Setpriority(which int, who int, prio int) (err error) //sys Setprivexec(flag int) (err error) //sysnb Setregid(rgid int, egid int) (err error) //sysnb Setreuid(ruid int, euid int) (err error) //sysnb Setsid() (pid int, err error) //sysnb Settimeofday(tp *Timeval) (err error) //sysnb Setuid(uid int) (err error) //sys Symlink(path string, link string) (err error) //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) //sys Sync() (err error) //sys Truncate(path string, length int64) (err error) //sys Umask(newmask int) (oldmask int) //sys Undelete(path string) (err error) //sys Unlink(path string) (err error) //sys Unlinkat(dirfd int, path string, flags int) (err error) //sys Unmount(path string, flags int) (err error) //sys write(fd int, p []byte) (n int, err error) //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) //sys munmap(addr uintptr, length uintptr) (err error)
Upload File
Create Folder