X7ROOT File Manager
Current Path:
/opt/golang/1.17.2/src/syscall
opt
/
golang
/
1.17.2
/
src
/
syscall
/
📁
..
📄
asm9_unix1_amd64.s
(1.01 KB)
📄
asm9_unix2_amd64.s
(1.23 KB)
📄
asm_aix_ppc64.s
(540 B)
📄
asm_darwin_amd64.s
(2.82 KB)
📄
asm_darwin_arm64.s
(2.71 KB)
📄
asm_freebsd_arm.s
(2.96 KB)
📄
asm_freebsd_arm64.s
(2.68 KB)
📄
asm_linux_386.s
(5.05 KB)
📄
asm_linux_amd64.s
(3.34 KB)
📄
asm_linux_arm.s
(4 KB)
📄
asm_linux_arm64.s
(2.73 KB)
📄
asm_linux_mips64x.s
(2.71 KB)
📄
asm_linux_mipsx.s
(3.66 KB)
📄
asm_linux_ppc64x.s
(2.69 KB)
📄
asm_linux_riscv64.s
(2.88 KB)
📄
asm_linux_s390x.s
(4.19 KB)
📄
asm_netbsd_arm.s
(2.85 KB)
📄
asm_netbsd_arm64.s
(2.77 KB)
📄
asm_openbsd_386.s
(1.04 KB)
📄
asm_openbsd_amd64.s
(1.04 KB)
📄
asm_openbsd_arm.s
(1.04 KB)
📄
asm_openbsd_arm64.s
(1.04 KB)
📄
asm_openbsd_mips64.s
(2.85 KB)
📄
asm_plan9_386.s
(3.14 KB)
📄
asm_plan9_amd64.s
(3.06 KB)
📄
asm_plan9_arm.s
(3.25 KB)
📄
asm_solaris_amd64.s
(1.79 KB)
📄
asm_unix_386.s
(2.76 KB)
📄
asm_unix_amd64.s
(2.11 KB)
📄
bpf_bsd.go
(4.67 KB)
📄
bpf_darwin.go
(3.97 KB)
📄
const_plan9.go
(1.2 KB)
📄
creds_test.go
(3.34 KB)
📄
dir_plan9.go
(5.62 KB)
📄
dirent.go
(3.1 KB)
📄
dirent_test.go
(3.15 KB)
📄
dll_windows.go
(10.19 KB)
📄
endian_big.go
(283 B)
📄
endian_little.go
(365 B)
📄
env_unix.go
(3 KB)
📄
env_windows.go
(1.75 KB)
📄
errors_plan9.go
(1.61 KB)
📄
exec_aix_test.go
(831 B)
📄
exec_bsd.go
(6.98 KB)
📄
exec_libc.go
(7.44 KB)
📄
exec_libc2.go
(7.48 KB)
📄
exec_linux.go
(18.98 KB)
📄
exec_linux_test.go
(19.07 KB)
📄
exec_plan9.go
(13.23 KB)
📄
exec_solaris_test.go
(827 B)
📄
exec_unix.go
(8.93 KB)
📄
exec_unix_test.go
(7.2 KB)
📄
exec_windows.go
(11.09 KB)
📄
exec_windows_test.go
(3.1 KB)
📄
export_darwin_test.go
(314 B)
📄
export_freebsd_test.go
(304 B)
📄
export_linux_test.go
(252 B)
📄
export_unix_test.go
(396 B)
📄
export_windows_test.go
(439 B)
📄
flock.go
(753 B)
📄
flock_aix.go
(564 B)
📄
flock_darwin.go
(405 B)
📄
flock_linux_32bit.go
(565 B)
📄
forkpipe.go
(527 B)
📄
forkpipe2.go
(339 B)
📄
fs_js.go
(10.56 KB)
📄
getdirentries_test.go
(2.11 KB)
📁
js
📄
lsf_linux.go
(2.12 KB)
📄
mkall.sh
(12.79 KB)
📄
mkasm.go
(1.76 KB)
📄
mkerrors.sh
(10.65 KB)
📄
mkpost.go
(1.99 KB)
📄
mksyscall.pl
(9.95 KB)
📄
mksyscall_libc.pl
(7.98 KB)
📄
mksyscall_windows.go
(2 KB)
📄
mksysctl_openbsd.pl
(5.04 KB)
📄
mksysnum_dragonfly.pl
(866 B)
📄
mksysnum_freebsd.pl
(1.35 KB)
📄
mksysnum_linux.pl
(1.26 KB)
📄
mksysnum_netbsd.pl
(1.01 KB)
📄
mksysnum_openbsd.pl
(872 B)
📄
mksysnum_plan9.sh
(459 B)
📄
mmap_unix_test.go
(623 B)
📄
msan.go
(425 B)
📄
msan0.go
(358 B)
📄
net.go
(1.19 KB)
📄
net_js.go
(2.14 KB)
📄
netlink_linux.go
(4.67 KB)
📄
ptrace_darwin.go
(396 B)
📄
ptrace_ios.go
(382 B)
📄
pwd_plan9.go
(1.55 KB)
📄
route_bsd.go
(9.15 KB)
📄
route_darwin.go
(2.01 KB)
📄
route_dragonfly.go
(2.61 KB)
📄
route_freebsd.go
(2.67 KB)
📄
route_freebsd_32bit.go
(1.33 KB)
📄
route_freebsd_64bit.go
(776 B)
📄
route_netbsd.go
(1.43 KB)
📄
route_openbsd.go
(1.46 KB)
📄
security_windows.go
(10.12 KB)
📄
setuidgid_32_linux.go
(469 B)
📄
setuidgid_linux.go
(447 B)
📄
sock_cloexec_linux.go
(632 B)
📄
sockcmsg_dragonfly.go
(547 B)
📄
sockcmsg_linux.go
(1.12 KB)
📄
sockcmsg_unix.go
(2.65 KB)
📄
sockcmsg_unix_other.go
(1.14 KB)
📄
syscall.go
(3.61 KB)
📄
syscall_aix.go
(18.05 KB)
📄
syscall_aix_ppc64.go
(405 B)
📄
syscall_bsd.go
(14.39 KB)
📄
syscall_bsd_test.go
(1.21 KB)
📄
syscall_darwin.go
(11.93 KB)
📄
syscall_darwin_amd64.go
(1.92 KB)
📄
syscall_darwin_arm64.go
(1.84 KB)
📄
syscall_dragonfly.go
(8.29 KB)
📄
syscall_dragonfly_amd64.go
(1.12 KB)
📄
syscall_dup2_linux.go
(409 B)
📄
syscall_dup3_linux.go
(275 B)
📄
syscall_freebsd.go
(15.82 KB)
📄
syscall_freebsd_386.go
(1.17 KB)
📄
syscall_freebsd_amd64.go
(1.12 KB)
📄
syscall_freebsd_arm.go
(1.16 KB)
📄
syscall_freebsd_arm64.go
(1.12 KB)
📄
syscall_freebsd_test.go
(1.37 KB)
📄
syscall_illumos.go
(1.2 KB)
📄
syscall_js.go
(6.64 KB)
📄
syscall_linux.go
(33.3 KB)
📄
syscall_linux_386.go
(10.63 KB)
📄
syscall_linux_amd64.go
(5.34 KB)
📄
syscall_linux_arm.go
(7.32 KB)
📄
syscall_linux_arm64.go
(6.68 KB)
📄
syscall_linux_mips64x.go
(6.54 KB)
📄
syscall_linux_mipsx.go
(6.98 KB)
📄
syscall_linux_ppc64x.go
(5.19 KB)
📄
syscall_linux_riscv64.go
(6.32 KB)
📄
syscall_linux_s390x.go
(8.59 KB)
📄
syscall_linux_test.go
(20.69 KB)
📄
syscall_netbsd.go
(7.59 KB)
📄
syscall_netbsd_386.go
(716 B)
📄
syscall_netbsd_amd64.go
(709 B)
📄
syscall_netbsd_arm.go
(716 B)
📄
syscall_netbsd_arm64.go
(709 B)
📄
syscall_openbsd.go
(6.67 KB)
📄
syscall_openbsd1.go
(634 B)
📄
syscall_openbsd_386.go
(715 B)
📄
syscall_openbsd_amd64.go
(701 B)
📄
syscall_openbsd_arm.go
(715 B)
📄
syscall_openbsd_arm64.go
(906 B)
📄
syscall_openbsd_libc.go
(3.46 KB)
📄
syscall_openbsd_mips64.go
(906 B)
📄
syscall_plan9.go
(8.94 KB)
📄
syscall_plan9_test.go
(1.15 KB)
📄
syscall_ptrace_test.go
(824 B)
📄
syscall_solaris.go
(15.07 KB)
📄
syscall_solaris_amd64.go
(487 B)
📄
syscall_test.go
(1.44 KB)
📄
syscall_unix.go
(8.46 KB)
📄
syscall_unix_test.go
(10.4 KB)
📄
syscall_windows.go
(46.08 KB)
📄
syscall_windows_test.go
(3.39 KB)
📄
tables_js.go
(19.19 KB)
📄
time_fake.go
(696 B)
📄
time_nofake.go
(371 B)
📄
timestruct.go
(1.07 KB)
📄
types_aix.go
(3.37 KB)
📄
types_darwin.go
(5.05 KB)
📄
types_dragonfly.go
(5.06 KB)
📄
types_freebsd.go
(6.98 KB)
📄
types_illumos_amd64.go
(397 B)
📄
types_linux.go
(10.7 KB)
📄
types_netbsd.go
(4.78 KB)
📄
types_openbsd.go
(5.06 KB)
📄
types_solaris.go
(4.9 KB)
📄
types_windows.go
(27.71 KB)
📄
types_windows_386.go
(477 B)
📄
types_windows_amd64.go
(477 B)
📄
types_windows_arm.go
(477 B)
📄
types_windows_arm64.go
(477 B)
📄
zerrors_aix_ppc64.go
(47.16 KB)
📄
zerrors_darwin_amd64.go
(55.3 KB)
📄
zerrors_darwin_arm64.go
(55.81 KB)
📄
zerrors_dragonfly_amd64.go
(59.65 KB)
📄
zerrors_freebsd_386.go
(67.38 KB)
📄
zerrors_freebsd_amd64.go
(67.42 KB)
📄
zerrors_freebsd_arm.go
(67.37 KB)
📄
zerrors_freebsd_arm64.go
(67.43 KB)
📄
zerrors_linux_386.go
(58.33 KB)
📄
zerrors_linux_amd64.go
(58.37 KB)
📄
zerrors_linux_arm.go
(58.86 KB)
📄
zerrors_linux_arm64.go
(69.54 KB)
📄
zerrors_linux_mips.go
(70.14 KB)
📄
zerrors_linux_mips64.go
(69.46 KB)
📄
zerrors_linux_mips64le.go
(69.46 KB)
📄
zerrors_linux_mipsle.go
(70.14 KB)
📄
zerrors_linux_ppc64.go
(71.86 KB)
📄
zerrors_linux_ppc64le.go
(72.82 KB)
📄
zerrors_linux_riscv64.go
(71.76 KB)
📄
zerrors_linux_s390x.go
(74.28 KB)
📄
zerrors_netbsd_386.go
(67.5 KB)
📄
zerrors_netbsd_amd64.go
(67.09 KB)
📄
zerrors_netbsd_arm.go
(66.51 KB)
📄
zerrors_netbsd_arm64.go
(67.09 KB)
📄
zerrors_openbsd_386.go
(62.54 KB)
📄
zerrors_openbsd_amd64.go
(62.5 KB)
📄
zerrors_openbsd_arm.go
(62.49 KB)
📄
zerrors_openbsd_arm64.go
(66.36 KB)
📄
zerrors_openbsd_mips64.go
(66.66 KB)
📄
zerrors_solaris_amd64.go
(50.74 KB)
📄
zerrors_windows.go
(9.97 KB)
📄
zsyscall_aix_ppc64.go
(40.16 KB)
📄
zsyscall_darwin_amd64.go
(50.65 KB)
📄
zsyscall_darwin_amd64.s
(8.64 KB)
📄
zsyscall_darwin_arm64.go
(50.6 KB)
📄
zsyscall_darwin_arm64.s
(8.61 KB)
📄
zsyscall_dragonfly_amd64.go
(31.21 KB)
📄
zsyscall_freebsd_386.go
(33.58 KB)
📄
zsyscall_freebsd_amd64.go
(33.44 KB)
📄
zsyscall_freebsd_arm.go
(33.6 KB)
📄
zsyscall_freebsd_arm64.go
(33.44 KB)
📄
zsyscall_linux_386.go
(34.35 KB)
📄
zsyscall_linux_amd64.go
(39.48 KB)
📄
zsyscall_linux_arm.go
(38.57 KB)
📄
zsyscall_linux_arm64.go
(37.74 KB)
📄
zsyscall_linux_mips.go
(40.33 KB)
📄
zsyscall_linux_mips64.go
(40.12 KB)
📄
zsyscall_linux_mips64le.go
(40.12 KB)
📄
zsyscall_linux_mipsle.go
(40.34 KB)
📄
zsyscall_linux_ppc64.go
(40.76 KB)
📄
zsyscall_linux_ppc64le.go
(40.76 KB)
📄
zsyscall_linux_riscv64.go
(37.77 KB)
📄
zsyscall_linux_s390x.go
(34.76 KB)
📄
zsyscall_netbsd_386.go
(29.65 KB)
📄
zsyscall_netbsd_amd64.go
(29.51 KB)
📄
zsyscall_netbsd_arm.go
(29.65 KB)
📄
zsyscall_netbsd_arm64.go
(29.51 KB)
📄
zsyscall_openbsd_386.go
(46.85 KB)
📄
zsyscall_openbsd_386.s
(7.89 KB)
📄
zsyscall_openbsd_amd64.go
(46.71 KB)
📄
zsyscall_openbsd_amd64.s
(7.89 KB)
📄
zsyscall_openbsd_arm.go
(46.87 KB)
📄
zsyscall_openbsd_arm.s
(7.89 KB)
📄
zsyscall_openbsd_arm64.go
(46.71 KB)
📄
zsyscall_openbsd_arm64.s
(7.89 KB)
📄
zsyscall_openbsd_mips64.go
(30.35 KB)
📄
zsyscall_plan9_386.go
(6.19 KB)
📄
zsyscall_plan9_amd64.go
(6.2 KB)
📄
zsyscall_plan9_arm.go
(6.19 KB)
📄
zsyscall_solaris_amd64.go
(35.82 KB)
📄
zsyscall_windows.go
(56.68 KB)
📄
zsysctl_openbsd.go
(11.71 KB)
📄
zsysnum_darwin_amd64.go
(14.57 KB)
📄
zsysnum_darwin_arm64.go
(14.41 KB)
📄
zsysnum_dragonfly_amd64.go
(22.97 KB)
📄
zsysnum_freebsd_386.go
(25.67 KB)
📄
zsysnum_freebsd_amd64.go
(25.68 KB)
📄
zsysnum_freebsd_arm.go
(25.67 KB)
📄
zsysnum_freebsd_arm64.go
(36.12 KB)
📄
zsysnum_linux_386.go
(11.29 KB)
📄
zsysnum_linux_amd64.go
(10.13 KB)
📄
zsysnum_linux_arm.go
(11.57 KB)
📄
zsysnum_linux_arm64.go
(8.97 KB)
📄
zsysnum_linux_mips.go
(12.1 KB)
📄
zsysnum_linux_mips64.go
(10.93 KB)
📄
zsysnum_linux_mips64le.go
(10.93 KB)
📄
zsysnum_linux_mipsle.go
(12.1 KB)
📄
zsysnum_linux_ppc64.go
(11.49 KB)
📄
zsysnum_linux_ppc64le.go
(11.51 KB)
📄
zsysnum_linux_riscv64.go
(8.88 KB)
📄
zsysnum_linux_s390x.go
(10.64 KB)
📄
zsysnum_netbsd_386.go
(25.71 KB)
📄
zsysnum_netbsd_amd64.go
(25.71 KB)
📄
zsysnum_netbsd_arm.go
(25.71 KB)
📄
zsysnum_netbsd_arm64.go
(25.71 KB)
📄
zsysnum_openbsd_386.go
(14.18 KB)
📄
zsysnum_openbsd_amd64.go
(14.18 KB)
📄
zsysnum_openbsd_arm.go
(14.48 KB)
📄
zsysnum_openbsd_arm64.go
(14.72 KB)
📄
zsysnum_openbsd_mips64.go
(14.93 KB)
📄
zsysnum_plan9.go
(1.03 KB)
📄
zsysnum_solaris_amd64.go
(317 B)
📄
ztypes_aix_ppc64.go
(4.17 KB)
📄
ztypes_darwin_amd64.go
(6.97 KB)
📄
ztypes_darwin_arm64.go
(6.97 KB)
📄
ztypes_dragonfly_amd64.go
(6.73 KB)
📄
ztypes_freebsd_386.go
(9.03 KB)
📄
ztypes_freebsd_amd64.go
(9.03 KB)
📄
ztypes_freebsd_arm.go
(9.04 KB)
📄
ztypes_freebsd_arm64.go
(9.03 KB)
📄
ztypes_linux_386.go
(11.57 KB)
📄
ztypes_linux_amd64.go
(11.94 KB)
📄
ztypes_linux_arm.go
(11.46 KB)
📄
ztypes_linux_arm64.go
(10.15 KB)
📄
ztypes_linux_mips.go
(9.93 KB)
📄
ztypes_linux_mips64.go
(10.05 KB)
📄
ztypes_linux_mips64le.go
(10.05 KB)
📄
ztypes_linux_mipsle.go
(9.93 KB)
📄
ztypes_linux_ppc64.go
(10.24 KB)
📄
ztypes_linux_ppc64le.go
(10.37 KB)
📄
ztypes_linux_riscv64.go
(10.2 KB)
📄
ztypes_linux_s390x.go
(10.39 KB)
📄
ztypes_netbsd_386.go
(6.01 KB)
📄
ztypes_netbsd_amd64.go
(6.19 KB)
📄
ztypes_netbsd_arm.go
(6.15 KB)
📄
ztypes_netbsd_arm64.go
(6.19 KB)
📄
ztypes_openbsd_386.go
(6.75 KB)
📄
ztypes_openbsd_amd64.go
(6.91 KB)
📄
ztypes_openbsd_arm.go
(6.84 KB)
📄
ztypes_openbsd_arm64.go
(6.66 KB)
📄
ztypes_openbsd_mips64.go
(6.66 KB)
📄
ztypes_solaris_amd64.go
(5.59 KB)
Editing: syscall_linux.go
// Copyright 2009 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. // Linux 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. package syscall import ( "internal/itoa" "unsafe" ) func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr) /* * Wrapped */ func Access(path string, mode uint32) (err error) { return Faccessat(_AT_FDCWD, path, mode, 0) } func Chmod(path string, mode uint32) (err error) { return Fchmodat(_AT_FDCWD, path, mode, 0) } func Chown(path string, uid int, gid int) (err error) { return Fchownat(_AT_FDCWD, path, uid, gid, 0) } func Creat(path string, mode uint32) (fd int, err error) { return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode) } func isGroupMember(gid int) bool { groups, err := Getgroups() if err != nil { return false } for _, g := range groups { if g == gid { return true } } return false } //sys faccessat(dirfd int, path string, mode uint32) (err error) func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { if flags & ^(_AT_SYMLINK_NOFOLLOW|_AT_EACCESS) != 0 { return EINVAL } // The Linux kernel faccessat system call does not take any flags. // The glibc faccessat implements the flags itself; see // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/faccessat.c;hb=HEAD // Because people naturally expect syscall.Faccessat to act // like C faccessat, we do the same. if flags == 0 { return faccessat(dirfd, path, mode) } var st Stat_t if err := fstatat(dirfd, path, &st, flags&_AT_SYMLINK_NOFOLLOW); err != nil { return err } mode &= 7 if mode == 0 { return nil } var uid int if flags&_AT_EACCESS != 0 { uid = Geteuid() } else { uid = Getuid() } if uid == 0 { if mode&1 == 0 { // Root can read and write any file. return nil } if st.Mode&0111 != 0 { // Root can execute any file that anybody can execute. return nil } return EACCES } var fmode uint32 if uint32(uid) == st.Uid { fmode = (st.Mode >> 6) & 7 } else { var gid int if flags&_AT_EACCESS != 0 { gid = Getegid() } else { gid = Getgid() } if uint32(gid) == st.Gid || isGroupMember(gid) { fmode = (st.Mode >> 3) & 7 } else { fmode = st.Mode & 7 } } if fmode&mode == mode { return nil } return EACCES } //sys fchmodat(dirfd int, path string, mode uint32) (err error) func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { // Linux fchmodat doesn't support the flags parameter. Mimick glibc's behavior // and check the flags. Otherwise the mode would be applied to the symlink // destination which is not what the user expects. if flags&^_AT_SYMLINK_NOFOLLOW != 0 { return EINVAL } else if flags&_AT_SYMLINK_NOFOLLOW != 0 { return EOPNOTSUPP } return fchmodat(dirfd, path, mode) } //sys linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) func Link(oldpath string, newpath string) (err error) { return linkat(_AT_FDCWD, oldpath, _AT_FDCWD, newpath, 0) } func Mkdir(path string, mode uint32) (err error) { return Mkdirat(_AT_FDCWD, path, mode) } func Mknod(path string, mode uint32, dev int) (err error) { return Mknodat(_AT_FDCWD, path, mode, dev) } func Open(path string, mode int, perm uint32) (fd int, err error) { return openat(_AT_FDCWD, path, mode|O_LARGEFILE, perm) } //sys openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) { return openat(dirfd, path, flags|O_LARGEFILE, mode) } //sys readlinkat(dirfd int, path string, buf []byte) (n int, err error) func Readlink(path string, buf []byte) (n int, err error) { return readlinkat(_AT_FDCWD, path, buf) } func Rename(oldpath string, newpath string) (err error) { return Renameat(_AT_FDCWD, oldpath, _AT_FDCWD, newpath) } func Rmdir(path string) error { return unlinkat(_AT_FDCWD, path, _AT_REMOVEDIR) } //sys symlinkat(oldpath string, newdirfd int, newpath string) (err error) func Symlink(oldpath string, newpath string) (err error) { return symlinkat(oldpath, _AT_FDCWD, newpath) } func Unlink(path string) error { return unlinkat(_AT_FDCWD, path, 0) } //sys unlinkat(dirfd int, path string, flags int) (err error) func Unlinkat(dirfd int, path string) error { return unlinkat(dirfd, path, 0) } func Utimes(path string, tv []Timeval) (err error) { if len(tv) != 2 { return EINVAL } return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) } //sys utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error) func UtimesNano(path string, ts []Timespec) (err error) { if len(ts) != 2 { return EINVAL } err = utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0) if err != ENOSYS { return err } // If the utimensat syscall isn't available (utimensat was added to Linux // in 2.6.22, Released, 8 July 2007) then fall back to utimes var tv [2]Timeval for i := 0; i < 2; i++ { tv[i].Sec = ts[i].Sec tv[i].Usec = ts[i].Nsec / 1000 } return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) } func Futimesat(dirfd int, path string, tv []Timeval) (err error) { if len(tv) != 2 { return EINVAL } return futimesat(dirfd, path, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) } func Futimes(fd int, tv []Timeval) (err error) { // Believe it or not, this is the best we can do on Linux // (and is what glibc does). return Utimes("/proc/self/fd/"+itoa.Itoa(fd), tv) } const ImplementsGetwd = true //sys Getcwd(buf []byte) (n int, err error) func Getwd() (wd string, err error) { var buf [PathMax]byte n, err := Getcwd(buf[0:]) if err != nil { return "", err } // Getcwd returns the number of bytes written to buf, including the NUL. if n < 1 || n > len(buf) || buf[n-1] != 0 { return "", EINVAL } return string(buf[0 : n-1]), nil } func Getgroups() (gids []int, err error) { n, err := getgroups(0, nil) if err != nil { return nil, err } if n == 0 { return nil, nil } // Sanity check group count. Max is 1<<16 on Linux. if n < 0 || n > 1<<20 { return nil, EINVAL } a := make([]_Gid_t, n) n, err = getgroups(n, &a[0]) if err != nil { return nil, err } gids = make([]int, n) for i, v := range a[0:n] { gids[i] = int(v) } return } var cgo_libc_setgroups unsafe.Pointer // non-nil if cgo linked. func Setgroups(gids []int) (err error) { n := uintptr(len(gids)) if n == 0 { if cgo_libc_setgroups == nil { if _, _, e1 := AllThreadsSyscall(_SYS_setgroups, 0, 0, 0); e1 != 0 { err = errnoErr(e1) } return } if ret := cgocaller(cgo_libc_setgroups, 0, 0); ret != 0 { err = errnoErr(Errno(ret)) } return } a := make([]_Gid_t, len(gids)) for i, v := range gids { a[i] = _Gid_t(v) } if cgo_libc_setgroups == nil { if _, _, e1 := AllThreadsSyscall(_SYS_setgroups, n, uintptr(unsafe.Pointer(&a[0])), 0); e1 != 0 { err = errnoErr(e1) } return } if ret := cgocaller(cgo_libc_setgroups, n, uintptr(unsafe.Pointer(&a[0]))); ret != 0 { err = errnoErr(Errno(ret)) } return } type WaitStatus uint32 // Wait status is 7 bits at bottom, either 0 (exited), // 0x7F (stopped), or a signal number that caused an exit. // The 0x80 bit is whether there was a core dump. // An extra number (exit code, signal causing a stop) // is in the high bits. At least that's the idea. // There are various irregularities. For example, the // "continued" status is 0xFFFF, distinguishing itself // from stopped via the core dump bit. const ( mask = 0x7F core = 0x80 exited = 0x00 stopped = 0x7F shift = 8 ) func (w WaitStatus) Exited() bool { return w&mask == exited } func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != exited } func (w WaitStatus) Stopped() bool { return w&0xFF == stopped } func (w WaitStatus) Continued() bool { return w == 0xFFFF } func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 } func (w WaitStatus) ExitStatus() int { if !w.Exited() { return -1 } return int(w>>shift) & 0xFF } func (w WaitStatus) Signal() Signal { if !w.Signaled() { return -1 } return Signal(w & mask) } func (w WaitStatus) StopSignal() Signal { if !w.Stopped() { return -1 } return Signal(w>>shift) & 0xFF } func (w WaitStatus) TrapCause() int { if w.StopSignal() != SIGTRAP { return -1 } return int(w>>shift) >> 8 } //sys wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) { var status _C_int wpid, err = wait4(pid, &status, options, rusage) if wstatus != nil { *wstatus = WaitStatus(status) } return } func Mkfifo(path string, mode uint32) (err error) { return Mknod(path, mode|S_IFIFO, 0) } func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return nil, 0, EINVAL } sa.raw.Family = AF_INET p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port)) p[0] = byte(sa.Port >> 8) p[1] = byte(sa.Port) for i := 0; i < len(sa.Addr); i++ { sa.raw.Addr[i] = sa.Addr[i] } return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil } func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return nil, 0, EINVAL } sa.raw.Family = AF_INET6 p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port)) p[0] = byte(sa.Port >> 8) p[1] = byte(sa.Port) sa.raw.Scope_id = sa.ZoneId for i := 0; i < len(sa.Addr); i++ { sa.raw.Addr[i] = sa.Addr[i] } return unsafe.Pointer(&sa.raw), SizeofSockaddrInet6, nil } func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) { name := sa.Name n := len(name) if n > len(sa.raw.Path) { return nil, 0, EINVAL } if n == len(sa.raw.Path) && name[0] != '@' { return nil, 0, EINVAL } sa.raw.Family = AF_UNIX for i := 0; i < n; i++ { sa.raw.Path[i] = int8(name[i]) } // length is family (uint16), name, NUL. sl := _Socklen(2) if n > 0 { sl += _Socklen(n) + 1 } if sa.raw.Path[0] == '@' { sa.raw.Path[0] = 0 // Don't count trailing NUL for abstract address. sl-- } return unsafe.Pointer(&sa.raw), sl, nil } type SockaddrLinklayer struct { Protocol uint16 Ifindex int Hatype uint16 Pkttype uint8 Halen uint8 Addr [8]byte raw RawSockaddrLinklayer } func (sa *SockaddrLinklayer) sockaddr() (unsafe.Pointer, _Socklen, error) { if sa.Ifindex < 0 || sa.Ifindex > 0x7fffffff { return nil, 0, EINVAL } sa.raw.Family = AF_PACKET sa.raw.Protocol = sa.Protocol sa.raw.Ifindex = int32(sa.Ifindex) sa.raw.Hatype = sa.Hatype sa.raw.Pkttype = sa.Pkttype sa.raw.Halen = sa.Halen for i := 0; i < len(sa.Addr); i++ { sa.raw.Addr[i] = sa.Addr[i] } return unsafe.Pointer(&sa.raw), SizeofSockaddrLinklayer, nil } type SockaddrNetlink struct { Family uint16 Pad uint16 Pid uint32 Groups uint32 raw RawSockaddrNetlink } func (sa *SockaddrNetlink) sockaddr() (unsafe.Pointer, _Socklen, error) { sa.raw.Family = AF_NETLINK sa.raw.Pad = sa.Pad sa.raw.Pid = sa.Pid sa.raw.Groups = sa.Groups return unsafe.Pointer(&sa.raw), SizeofSockaddrNetlink, nil } func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) { switch rsa.Addr.Family { case AF_NETLINK: pp := (*RawSockaddrNetlink)(unsafe.Pointer(rsa)) sa := new(SockaddrNetlink) sa.Family = pp.Family sa.Pad = pp.Pad sa.Pid = pp.Pid sa.Groups = pp.Groups return sa, nil case AF_PACKET: pp := (*RawSockaddrLinklayer)(unsafe.Pointer(rsa)) sa := new(SockaddrLinklayer) sa.Protocol = pp.Protocol sa.Ifindex = int(pp.Ifindex) sa.Hatype = pp.Hatype sa.Pkttype = pp.Pkttype sa.Halen = pp.Halen for i := 0; i < len(sa.Addr); i++ { sa.Addr[i] = pp.Addr[i] } return sa, nil case AF_UNIX: pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa)) sa := new(SockaddrUnix) if pp.Path[0] == 0 { // "Abstract" Unix domain socket. // Rewrite leading NUL as @ for textual display. // (This is the standard convention.) // Not friendly to overwrite in place, // but the callers below don't care. pp.Path[0] = '@' } // Assume path ends at NUL. // This is not technically the Linux semantics for // abstract Unix domain sockets--they are supposed // to be uninterpreted fixed-size binary blobs--but // everyone uses this convention. n := 0 for n < len(pp.Path) && pp.Path[n] != 0 { n++ } bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n] sa.Name = string(bytes) return sa, nil case AF_INET: pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa)) sa := new(SockaddrInet4) p := (*[2]byte)(unsafe.Pointer(&pp.Port)) sa.Port = int(p[0])<<8 + int(p[1]) for i := 0; i < len(sa.Addr); i++ { sa.Addr[i] = pp.Addr[i] } return sa, nil case AF_INET6: pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa)) sa := new(SockaddrInet6) p := (*[2]byte)(unsafe.Pointer(&pp.Port)) sa.Port = int(p[0])<<8 + int(p[1]) sa.ZoneId = pp.Scope_id for i := 0; i < len(sa.Addr); i++ { sa.Addr[i] = pp.Addr[i] } return sa, nil } return nil, EAFNOSUPPORT } func Accept(fd int) (nfd int, sa Sockaddr, err error) { var rsa RawSockaddrAny var len _Socklen = SizeofSockaddrAny // Try accept4 first for Android, then try accept for kernel older than 2.6.28 nfd, err = accept4(fd, &rsa, &len, 0) if err == ENOSYS { nfd, err = accept(fd, &rsa, &len) } if err != nil { return } sa, err = anyToSockaddr(&rsa) if err != nil { Close(nfd) nfd = 0 } return } func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) { var rsa RawSockaddrAny var len _Socklen = SizeofSockaddrAny nfd, err = accept4(fd, &rsa, &len, flags) if err != nil { return } if len > SizeofSockaddrAny { panic("RawSockaddrAny too small") } sa, err = anyToSockaddr(&rsa) if err != nil { Close(nfd) nfd = 0 } return } func Getsockname(fd int) (sa Sockaddr, err error) { var rsa RawSockaddrAny var len _Socklen = SizeofSockaddrAny if err = getsockname(fd, &rsa, &len); err != nil { return } return anyToSockaddr(&rsa) } func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error) { vallen := _Socklen(4) err = getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen) return value, err } func GetsockoptIPMreq(fd, level, opt int) (*IPMreq, error) { var value IPMreq vallen := _Socklen(SizeofIPMreq) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) { var value IPMreqn vallen := _Socklen(SizeofIPMreqn) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptIPv6Mreq(fd, level, opt int) (*IPv6Mreq, error) { var value IPv6Mreq vallen := _Socklen(SizeofIPv6Mreq) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) { var value IPv6MTUInfo vallen := _Socklen(SizeofIPv6MTUInfo) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptICMPv6Filter(fd, level, opt int) (*ICMPv6Filter, error) { var value ICMPv6Filter vallen := _Socklen(SizeofICMPv6Filter) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptUcred(fd, level, opt int) (*Ucred, error) { var value Ucred vallen := _Socklen(SizeofUcred) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq)) } func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { var msg Msghdr var rsa RawSockaddrAny msg.Name = (*byte)(unsafe.Pointer(&rsa)) msg.Namelen = uint32(SizeofSockaddrAny) var iov Iovec if len(p) > 0 { iov.Base = &p[0] iov.SetLen(len(p)) } var dummy byte if len(oob) > 0 { if len(p) == 0 { var sockType int sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) if err != nil { return } // receive at least one normal byte if sockType != SOCK_DGRAM { iov.Base = &dummy iov.SetLen(1) } } msg.Control = &oob[0] msg.SetControllen(len(oob)) } msg.Iov = &iov msg.Iovlen = 1 if n, err = recvmsg(fd, &msg, flags); err != nil { return } oobn = int(msg.Controllen) recvflags = int(msg.Flags) // source address is only specified if the socket is unconnected if rsa.Addr.Family != AF_UNSPEC { from, err = anyToSockaddr(&rsa) } return } func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { _, err = SendmsgN(fd, p, oob, to, flags) return } func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { var ptr unsafe.Pointer var salen _Socklen if to != nil { var err error ptr, salen, err = to.sockaddr() if err != nil { return 0, err } } var msg Msghdr msg.Name = (*byte)(ptr) msg.Namelen = uint32(salen) var iov Iovec if len(p) > 0 { iov.Base = &p[0] iov.SetLen(len(p)) } var dummy byte if len(oob) > 0 { if len(p) == 0 { var sockType int sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) if err != nil { return 0, err } // send at least one normal byte if sockType != SOCK_DGRAM { iov.Base = &dummy iov.SetLen(1) } } msg.Control = &oob[0] msg.SetControllen(len(oob)) } msg.Iov = &iov msg.Iovlen = 1 if n, err = sendmsg(fd, &msg, flags); err != nil { return 0, err } if len(oob) > 0 && len(p) == 0 { n = 0 } return n, nil } // BindToDevice binds the socket associated with fd to device. func BindToDevice(fd int, device string) (err error) { return SetsockoptString(fd, SOL_SOCKET, SO_BINDTODEVICE, device) } //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error) func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err error) { // The peek requests are machine-size oriented, so we wrap it // to retrieve arbitrary-length data. // The ptrace syscall differs from glibc's ptrace. // Peeks returns the word in *data, not as the return value. var buf [sizeofPtr]byte // Leading edge. PEEKTEXT/PEEKDATA don't require aligned // access (PEEKUSER warns that it might), but if we don't // align our reads, we might straddle an unmapped page // boundary and not get the bytes leading up to the page // boundary. n := 0 if addr%sizeofPtr != 0 { err = ptrace(req, pid, addr-addr%sizeofPtr, uintptr(unsafe.Pointer(&buf[0]))) if err != nil { return 0, err } n += copy(out, buf[addr%sizeofPtr:]) out = out[n:] } // Remainder. for len(out) > 0 { // We use an internal buffer to guarantee alignment. // It's not documented if this is necessary, but we're paranoid. err = ptrace(req, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0]))) if err != nil { return n, err } copied := copy(out, buf[0:]) n += copied out = out[copied:] } return n, nil } func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error) { return ptracePeek(PTRACE_PEEKTEXT, pid, addr, out) } func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) { return ptracePeek(PTRACE_PEEKDATA, pid, addr, out) } func ptracePoke(pokeReq int, peekReq int, pid int, addr uintptr, data []byte) (count int, err error) { // As for ptracePeek, we need to align our accesses to deal // with the possibility of straddling an invalid page. // Leading edge. n := 0 if addr%sizeofPtr != 0 { var buf [sizeofPtr]byte err = ptrace(peekReq, pid, addr-addr%sizeofPtr, uintptr(unsafe.Pointer(&buf[0]))) if err != nil { return 0, err } n += copy(buf[addr%sizeofPtr:], data) word := *((*uintptr)(unsafe.Pointer(&buf[0]))) err = ptrace(pokeReq, pid, addr-addr%sizeofPtr, word) if err != nil { return 0, err } data = data[n:] } // Interior. for len(data) > sizeofPtr { word := *((*uintptr)(unsafe.Pointer(&data[0]))) err = ptrace(pokeReq, pid, addr+uintptr(n), word) if err != nil { return n, err } n += sizeofPtr data = data[sizeofPtr:] } // Trailing edge. if len(data) > 0 { var buf [sizeofPtr]byte err = ptrace(peekReq, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0]))) if err != nil { return n, err } copy(buf[0:], data) word := *((*uintptr)(unsafe.Pointer(&buf[0]))) err = ptrace(pokeReq, pid, addr+uintptr(n), word) if err != nil { return n, err } n += len(data) } return n, nil } func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) { return ptracePoke(PTRACE_POKETEXT, PTRACE_PEEKTEXT, pid, addr, data) } func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) { return ptracePoke(PTRACE_POKEDATA, PTRACE_PEEKDATA, pid, addr, data) } func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) { return ptrace(PTRACE_GETREGS, pid, 0, uintptr(unsafe.Pointer(regsout))) } func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) { return ptrace(PTRACE_SETREGS, pid, 0, uintptr(unsafe.Pointer(regs))) } func PtraceSetOptions(pid int, options int) (err error) { return ptrace(PTRACE_SETOPTIONS, pid, 0, uintptr(options)) } func PtraceGetEventMsg(pid int) (msg uint, err error) { var data _C_long err = ptrace(PTRACE_GETEVENTMSG, pid, 0, uintptr(unsafe.Pointer(&data))) msg = uint(data) return } func PtraceCont(pid int, signal int) (err error) { return ptrace(PTRACE_CONT, pid, 0, uintptr(signal)) } func PtraceSyscall(pid int, signal int) (err error) { return ptrace(PTRACE_SYSCALL, pid, 0, uintptr(signal)) } func PtraceSingleStep(pid int) (err error) { return ptrace(PTRACE_SINGLESTEP, pid, 0, 0) } func PtraceAttach(pid int) (err error) { return ptrace(PTRACE_ATTACH, pid, 0, 0) } func PtraceDetach(pid int) (err error) { return ptrace(PTRACE_DETACH, pid, 0, 0) } //sys reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error) func Reboot(cmd int) (err error) { return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "") } func ReadDirent(fd int, buf []byte) (n int, err error) { return Getdents(fd, buf) } 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) { reclen, ok := direntReclen(buf) if !ok { return 0, false } return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true } //sys mount(source string, target string, fstype string, flags uintptr, data *byte) (err error) func Mount(source string, target string, fstype string, flags uintptr, data string) (err error) { // Certain file systems get rather angry and EINVAL if you give // them an empty string of data, rather than NULL. if data == "" { return mount(source, target, fstype, flags, nil) } datap, err := BytePtrFromString(data) if err != nil { return err } return mount(source, target, fstype, flags, datap) } // Sendto // Recvfrom // Socketpair /* * Direct access */ //sys Acct(path string) (err error) //sys Adjtimex(buf *Timex) (state int, err error) //sys Chdir(path string) (err error) //sys Chroot(path string) (err error) //sys Close(fd int) (err error) //sys Dup(oldfd int) (fd int, err error) //sys Dup3(oldfd int, newfd int, flags int) (err error) //sysnb EpollCreate1(flag int) (fd int, err error) //sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) //sys Fallocate(fd int, mode uint32, off int64, len int64) (err error) //sys Fchdir(fd int) (err error) //sys Fchmod(fd int, mode uint32) (err error) //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) //sys fcntl(fd int, cmd int, arg int) (val int, err error) //sys Fdatasync(fd int) (err error) //sys Flock(fd int, how int) (err error) //sys Fsync(fd int) (err error) //sys Getdents(fd int, buf []byte) (n int, err error) = SYS_GETDENTS64 //sysnb Getpgid(pid int) (pgid int, err error) func Getpgrp() (pid int) { pid, _ = Getpgid(0) return } //sysnb Getpid() (pid int) //sysnb Getppid() (ppid int) //sys Getpriority(which int, who int) (prio int, err error) //sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Gettid() (tid int) //sys Getxattr(path string, attr string, dest []byte) (sz int, err error) //sys InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err error) //sysnb InotifyInit1(flags int) (fd int, err error) //sysnb InotifyRmWatch(fd int, watchdesc uint32) (success int, err error) //sysnb Kill(pid int, sig Signal) (err error) //sys Klogctl(typ int, buf []byte) (n int, err error) = SYS_SYSLOG //sys Listxattr(path string, dest []byte) (sz int, err error) //sys Mkdirat(dirfd int, path string, mode uint32) (err error) //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT //sysnb prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT64 //sys read(fd int, p []byte) (n int, err error) //sys Removexattr(path string, attr string) (err error) //sys Setdomainname(p []byte) (err error) //sys Sethostname(p []byte) (err error) //sysnb Setpgid(pid int, pgid int) (err error) //sysnb Setsid() (pid int, err error) //sysnb Settimeofday(tv *Timeval) (err error) // allThreadsCaller holds the input and output state for performing a // allThreadsSyscall that needs to synchronize all OS thread state. Linux // generally does not always support this natively, so we have to // manipulate the runtime to fix things up. type allThreadsCaller struct { // arguments trap, a1, a2, a3, a4, a5, a6 uintptr // return values (only set by 0th invocation) r1, r2 uintptr // err is the error code err Errno } // doSyscall is a callback for executing a syscall on the current m // (OS thread). //go:nosplit //go:norace func (pc *allThreadsCaller) doSyscall(initial bool) bool { r1, r2, err := RawSyscall(pc.trap, pc.a1, pc.a2, pc.a3) if initial { pc.r1 = r1 pc.r2 = r2 pc.err = err } else if pc.r1 != r1 || (archHonorsR2 && pc.r2 != r2) || pc.err != err { print("trap:", pc.trap, ", a123=[", pc.a1, ",", pc.a2, ",", pc.a3, "]\n") print("results: got {r1=", r1, ",r2=", r2, ",err=", err, "}, want {r1=", pc.r1, ",r2=", pc.r2, ",r3=", pc.err, "}\n") panic("AllThreadsSyscall results differ between threads; runtime corrupted") } return err == 0 } // doSyscall6 is a callback for executing a syscall6 on the current m // (OS thread). //go:nosplit //go:norace func (pc *allThreadsCaller) doSyscall6(initial bool) bool { r1, r2, err := RawSyscall6(pc.trap, pc.a1, pc.a2, pc.a3, pc.a4, pc.a5, pc.a6) if initial { pc.r1 = r1 pc.r2 = r2 pc.err = err } else if pc.r1 != r1 || (archHonorsR2 && pc.r2 != r2) || pc.err != err { print("trap:", pc.trap, ", a123456=[", pc.a1, ",", pc.a2, ",", pc.a3, ",", pc.a4, ",", pc.a5, ",", pc.a6, "]\n") print("results: got {r1=", r1, ",r2=", r2, ",err=", err, "}, want {r1=", pc.r1, ",r2=", pc.r2, ",r3=", pc.err, "}\n") panic("AllThreadsSyscall6 results differ between threads; runtime corrupted") } return err == 0 } // Provided by runtime.syscall_runtime_doAllThreadsSyscall which // serializes the world and invokes the fn on each OS thread (what the // runtime refers to as m's). Once this function returns, all threads // are in sync. func runtime_doAllThreadsSyscall(fn func(bool) bool) // AllThreadsSyscall performs a syscall on each OS thread of the Go // runtime. It first invokes the syscall on one thread. Should that // invocation fail, it returns immediately with the error status. // Otherwise, it invokes the syscall on all of the remaining threads // in parallel. It will terminate the program if it observes any // invoked syscall's return value differs from that of the first // invocation. // // AllThreadsSyscall is intended for emulating simultaneous // process-wide state changes that require consistently modifying // per-thread state of the Go runtime. // // AllThreadsSyscall is unaware of any threads that are launched // explicitly by cgo linked code, so the function always returns // ENOTSUP in binaries that use cgo. //go:uintptrescapes func AllThreadsSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { if cgo_libc_setegid != nil { return minus1, minus1, ENOTSUP } pc := &allThreadsCaller{ trap: trap, a1: a1, a2: a2, a3: a3, } runtime_doAllThreadsSyscall(pc.doSyscall) r1 = pc.r1 r2 = pc.r2 err = pc.err return } // AllThreadsSyscall6 is like AllThreadsSyscall, but extended to six // arguments. //go:uintptrescapes func AllThreadsSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { if cgo_libc_setegid != nil { return minus1, minus1, ENOTSUP } pc := &allThreadsCaller{ trap: trap, a1: a1, a2: a2, a3: a3, a4: a4, a5: a5, a6: a6, } runtime_doAllThreadsSyscall(pc.doSyscall6) r1 = pc.r1 r2 = pc.r2 err = pc.err return } // linked by runtime.cgocall.go //go:uintptrescapes func cgocaller(unsafe.Pointer, ...uintptr) uintptr var cgo_libc_setegid unsafe.Pointer // non-nil if cgo linked. const minus1 = ^uintptr(0) func Setegid(egid int) (err error) { if cgo_libc_setegid == nil { if _, _, e1 := AllThreadsSyscall(SYS_SETRESGID, minus1, uintptr(egid), minus1); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setegid, uintptr(egid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_seteuid unsafe.Pointer // non-nil if cgo linked. func Seteuid(euid int) (err error) { if cgo_libc_seteuid == nil { if _, _, e1 := AllThreadsSyscall(SYS_SETRESUID, minus1, uintptr(euid), minus1); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_seteuid, uintptr(euid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setgid unsafe.Pointer // non-nil if cgo linked. func Setgid(gid int) (err error) { if cgo_libc_setgid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETGID, uintptr(gid), 0, 0); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setgid, uintptr(gid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setregid unsafe.Pointer // non-nil if cgo linked. func Setregid(rgid, egid int) (err error) { if cgo_libc_setregid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETREGID, uintptr(rgid), uintptr(egid), 0); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setregid, uintptr(rgid), uintptr(egid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setresgid unsafe.Pointer // non-nil if cgo linked. func Setresgid(rgid, egid, sgid int) (err error) { if cgo_libc_setresgid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setresgid, uintptr(rgid), uintptr(egid), uintptr(sgid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setresuid unsafe.Pointer // non-nil if cgo linked. func Setresuid(ruid, euid, suid int) (err error) { if cgo_libc_setresuid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setresuid, uintptr(ruid), uintptr(euid), uintptr(suid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setreuid unsafe.Pointer // non-nil if cgo linked. func Setreuid(ruid, euid int) (err error) { if cgo_libc_setreuid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETREUID, uintptr(ruid), uintptr(euid), 0); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setreuid, uintptr(ruid), uintptr(euid)); ret != 0 { err = errnoErr(Errno(ret)) } return } var cgo_libc_setuid unsafe.Pointer // non-nil if cgo linked. func Setuid(uid int) (err error) { if cgo_libc_setuid == nil { if _, _, e1 := AllThreadsSyscall(sys_SETUID, uintptr(uid), 0, 0); e1 != 0 { err = errnoErr(e1) } } else if ret := cgocaller(cgo_libc_setuid, uintptr(uid)); ret != 0 { err = errnoErr(Errno(ret)) } return } //sys Setpriority(which int, who int, prio int) (err error) //sys Setxattr(path string, attr string, data []byte, flags int) (err error) //sys Sync() //sysnb Sysinfo(info *Sysinfo_t) (err error) //sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error) //sysnb Tgkill(tgid int, tid int, sig Signal) (err error) //sysnb Times(tms *Tms) (ticks uintptr, err error) //sysnb Umask(mask int) (oldmask int) //sysnb Uname(buf *Utsname) (err error) //sys Unmount(target string, flags int) (err error) = SYS_UMOUNT2 //sys Unshare(flags int) (err error) //sys write(fd int, p []byte) (n int, err error) //sys exitThread(code int) (err error) = SYS_EXIT //sys readlen(fd int, p *byte, np int) (n int, err error) = SYS_READ //sys writelen(fd int, p *byte, np int) (n int, err error) = SYS_WRITE // mmap varies by architecture; see syscall_linux_*.go. //sys munmap(addr uintptr, length uintptr) (err error) var mapper = &mmapper{ active: make(map[*byte][]byte), mmap: mmap, munmap: munmap, } func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { return mapper.Mmap(fd, offset, length, prot, flags) } func Munmap(b []byte) (err error) { return mapper.Munmap(b) } //sys Madvise(b []byte, advice int) (err error) //sys Mprotect(b []byte, prot int) (err error) //sys Mlock(b []byte) (err error) //sys Munlock(b []byte) (err error) //sys Mlockall(flags int) (err error) //sys Munlockall() (err error)
Upload File
Create Folder