1// +build linux 2 3package unix 4 5import ( 6 "bytes" 7 "syscall" 8 9 linux "golang.org/x/sys/unix" 10) 11 12const ( 13 ENOENT = linux.ENOENT 14 EEXIST = linux.EEXIST 15 EAGAIN = linux.EAGAIN 16 ENOSPC = linux.ENOSPC 17 EINVAL = linux.EINVAL 18 EPOLLIN = linux.EPOLLIN 19 EINTR = linux.EINTR 20 EPERM = linux.EPERM 21 ESRCH = linux.ESRCH 22 ENODEV = linux.ENODEV 23 // ENOTSUPP is not the same as ENOTSUP or EOPNOTSUP 24 ENOTSUPP = syscall.Errno(0x20c) 25 26 EBADF = linux.EBADF 27 BPF_F_NO_PREALLOC = linux.BPF_F_NO_PREALLOC 28 BPF_F_NUMA_NODE = linux.BPF_F_NUMA_NODE 29 BPF_F_RDONLY = linux.BPF_F_RDONLY 30 BPF_F_WRONLY = linux.BPF_F_WRONLY 31 BPF_F_RDONLY_PROG = linux.BPF_F_RDONLY_PROG 32 BPF_F_WRONLY_PROG = linux.BPF_F_WRONLY_PROG 33 BPF_F_SLEEPABLE = linux.BPF_F_SLEEPABLE 34 BPF_F_MMAPABLE = linux.BPF_F_MMAPABLE 35 BPF_F_INNER_MAP = linux.BPF_F_INNER_MAP 36 BPF_OBJ_NAME_LEN = linux.BPF_OBJ_NAME_LEN 37 BPF_TAG_SIZE = linux.BPF_TAG_SIZE 38 SYS_BPF = linux.SYS_BPF 39 F_DUPFD_CLOEXEC = linux.F_DUPFD_CLOEXEC 40 EPOLL_CTL_ADD = linux.EPOLL_CTL_ADD 41 EPOLL_CLOEXEC = linux.EPOLL_CLOEXEC 42 O_CLOEXEC = linux.O_CLOEXEC 43 O_NONBLOCK = linux.O_NONBLOCK 44 PROT_READ = linux.PROT_READ 45 PROT_WRITE = linux.PROT_WRITE 46 MAP_SHARED = linux.MAP_SHARED 47 PERF_ATTR_SIZE_VER1 = linux.PERF_ATTR_SIZE_VER1 48 PERF_TYPE_SOFTWARE = linux.PERF_TYPE_SOFTWARE 49 PERF_TYPE_TRACEPOINT = linux.PERF_TYPE_TRACEPOINT 50 PERF_COUNT_SW_BPF_OUTPUT = linux.PERF_COUNT_SW_BPF_OUTPUT 51 PERF_EVENT_IOC_DISABLE = linux.PERF_EVENT_IOC_DISABLE 52 PERF_EVENT_IOC_ENABLE = linux.PERF_EVENT_IOC_ENABLE 53 PERF_EVENT_IOC_SET_BPF = linux.PERF_EVENT_IOC_SET_BPF 54 PerfBitWatermark = linux.PerfBitWatermark 55 PERF_SAMPLE_RAW = linux.PERF_SAMPLE_RAW 56 PERF_FLAG_FD_CLOEXEC = linux.PERF_FLAG_FD_CLOEXEC 57 RLIM_INFINITY = linux.RLIM_INFINITY 58 RLIMIT_MEMLOCK = linux.RLIMIT_MEMLOCK 59 BPF_STATS_RUN_TIME = linux.BPF_STATS_RUN_TIME 60 PERF_RECORD_LOST = linux.PERF_RECORD_LOST 61 PERF_RECORD_SAMPLE = linux.PERF_RECORD_SAMPLE 62 AT_FDCWD = linux.AT_FDCWD 63 RENAME_NOREPLACE = linux.RENAME_NOREPLACE 64) 65 66// Statfs_t is a wrapper 67type Statfs_t = linux.Statfs_t 68 69// Rlimit is a wrapper 70type Rlimit = linux.Rlimit 71 72// Setrlimit is a wrapper 73func Setrlimit(resource int, rlim *Rlimit) (err error) { 74 return linux.Setrlimit(resource, rlim) 75} 76 77// Syscall is a wrapper 78func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { 79 return linux.Syscall(trap, a1, a2, a3) 80} 81 82// FcntlInt is a wrapper 83func FcntlInt(fd uintptr, cmd, arg int) (int, error) { 84 return linux.FcntlInt(fd, cmd, arg) 85} 86 87// IoctlSetInt is a wrapper 88func IoctlSetInt(fd int, req uint, value int) error { 89 return linux.IoctlSetInt(fd, req, value) 90} 91 92// Statfs is a wrapper 93func Statfs(path string, buf *Statfs_t) (err error) { 94 return linux.Statfs(path, buf) 95} 96 97// Close is a wrapper 98func Close(fd int) (err error) { 99 return linux.Close(fd) 100} 101 102// EpollEvent is a wrapper 103type EpollEvent = linux.EpollEvent 104 105// EpollWait is a wrapper 106func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { 107 return linux.EpollWait(epfd, events, msec) 108} 109 110// EpollCtl is a wrapper 111func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { 112 return linux.EpollCtl(epfd, op, fd, event) 113} 114 115// Eventfd is a wrapper 116func Eventfd(initval uint, flags int) (fd int, err error) { 117 return linux.Eventfd(initval, flags) 118} 119 120// Write is a wrapper 121func Write(fd int, p []byte) (n int, err error) { 122 return linux.Write(fd, p) 123} 124 125// EpollCreate1 is a wrapper 126func EpollCreate1(flag int) (fd int, err error) { 127 return linux.EpollCreate1(flag) 128} 129 130// PerfEventMmapPage is a wrapper 131type PerfEventMmapPage linux.PerfEventMmapPage 132 133// SetNonblock is a wrapper 134func SetNonblock(fd int, nonblocking bool) (err error) { 135 return linux.SetNonblock(fd, nonblocking) 136} 137 138// Mmap is a wrapper 139func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { 140 return linux.Mmap(fd, offset, length, prot, flags) 141} 142 143// Munmap is a wrapper 144func Munmap(b []byte) (err error) { 145 return linux.Munmap(b) 146} 147 148// PerfEventAttr is a wrapper 149type PerfEventAttr = linux.PerfEventAttr 150 151// PerfEventOpen is a wrapper 152func PerfEventOpen(attr *PerfEventAttr, pid int, cpu int, groupFd int, flags int) (fd int, err error) { 153 return linux.PerfEventOpen(attr, pid, cpu, groupFd, flags) 154} 155 156// Utsname is a wrapper 157type Utsname = linux.Utsname 158 159// Uname is a wrapper 160func Uname(buf *Utsname) (err error) { 161 return linux.Uname(buf) 162} 163 164// Getpid is a wrapper 165func Getpid() int { 166 return linux.Getpid() 167} 168 169// Gettid is a wrapper 170func Gettid() int { 171 return linux.Gettid() 172} 173 174// Tgkill is a wrapper 175func Tgkill(tgid int, tid int, sig syscall.Signal) (err error) { 176 return linux.Tgkill(tgid, tid, sig) 177} 178 179// BytePtrFromString is a wrapper 180func BytePtrFromString(s string) (*byte, error) { 181 return linux.BytePtrFromString(s) 182} 183 184// ByteSliceToString is a wrapper 185func ByteSliceToString(s []byte) string { 186 return linux.ByteSliceToString(s) 187} 188 189// Renameat2 is a wrapper 190func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) error { 191 return linux.Renameat2(olddirfd, oldpath, newdirfd, newpath, flags) 192} 193 194func KernelRelease() (string, error) { 195 var uname Utsname 196 err := Uname(&uname) 197 if err != nil { 198 return "", err 199 } 200 201 end := bytes.IndexByte(uname.Release[:], 0) 202 release := string(uname.Release[:end]) 203 return release, nil 204} 205