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_PROG        = linux.BPF_F_RDONLY_PROG
30	BPF_F_WRONLY_PROG        = linux.BPF_F_WRONLY_PROG
31	BPF_OBJ_NAME_LEN         = linux.BPF_OBJ_NAME_LEN
32	BPF_TAG_SIZE             = linux.BPF_TAG_SIZE
33	SYS_BPF                  = linux.SYS_BPF
34	F_DUPFD_CLOEXEC          = linux.F_DUPFD_CLOEXEC
35	EPOLL_CTL_ADD            = linux.EPOLL_CTL_ADD
36	EPOLL_CLOEXEC            = linux.EPOLL_CLOEXEC
37	O_CLOEXEC                = linux.O_CLOEXEC
38	O_NONBLOCK               = linux.O_NONBLOCK
39	PROT_READ                = linux.PROT_READ
40	PROT_WRITE               = linux.PROT_WRITE
41	MAP_SHARED               = linux.MAP_SHARED
42	PERF_TYPE_SOFTWARE       = linux.PERF_TYPE_SOFTWARE
43	PERF_COUNT_SW_BPF_OUTPUT = linux.PERF_COUNT_SW_BPF_OUTPUT
44	PerfBitWatermark         = linux.PerfBitWatermark
45	PERF_SAMPLE_RAW          = linux.PERF_SAMPLE_RAW
46	PERF_FLAG_FD_CLOEXEC     = linux.PERF_FLAG_FD_CLOEXEC
47	RLIM_INFINITY            = linux.RLIM_INFINITY
48	RLIMIT_MEMLOCK           = linux.RLIMIT_MEMLOCK
49	BPF_STATS_RUN_TIME       = linux.BPF_STATS_RUN_TIME
50)
51
52// Statfs_t is a wrapper
53type Statfs_t = linux.Statfs_t
54
55// Rlimit is a wrapper
56type Rlimit = linux.Rlimit
57
58// Setrlimit is a wrapper
59func Setrlimit(resource int, rlim *Rlimit) (err error) {
60	return linux.Setrlimit(resource, rlim)
61}
62
63// Syscall is a wrapper
64func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
65	return linux.Syscall(trap, a1, a2, a3)
66}
67
68// FcntlInt is a wrapper
69func FcntlInt(fd uintptr, cmd, arg int) (int, error) {
70	return linux.FcntlInt(fd, cmd, arg)
71}
72
73// Statfs is a wrapper
74func Statfs(path string, buf *Statfs_t) (err error) {
75	return linux.Statfs(path, buf)
76}
77
78// Close is a wrapper
79func Close(fd int) (err error) {
80	return linux.Close(fd)
81}
82
83// EpollEvent is a wrapper
84type EpollEvent = linux.EpollEvent
85
86// EpollWait is a wrapper
87func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
88	return linux.EpollWait(epfd, events, msec)
89}
90
91// EpollCtl is a wrapper
92func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) {
93	return linux.EpollCtl(epfd, op, fd, event)
94}
95
96// Eventfd is a wrapper
97func Eventfd(initval uint, flags int) (fd int, err error) {
98	return linux.Eventfd(initval, flags)
99}
100
101// Write is a wrapper
102func Write(fd int, p []byte) (n int, err error) {
103	return linux.Write(fd, p)
104}
105
106// EpollCreate1 is a wrapper
107func EpollCreate1(flag int) (fd int, err error) {
108	return linux.EpollCreate1(flag)
109}
110
111// PerfEventMmapPage is a wrapper
112type PerfEventMmapPage linux.PerfEventMmapPage
113
114// SetNonblock is a wrapper
115func SetNonblock(fd int, nonblocking bool) (err error) {
116	return linux.SetNonblock(fd, nonblocking)
117}
118
119// Mmap is a wrapper
120func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
121	return linux.Mmap(fd, offset, length, prot, flags)
122}
123
124// Munmap is a wrapper
125func Munmap(b []byte) (err error) {
126	return linux.Munmap(b)
127}
128
129// PerfEventAttr is a wrapper
130type PerfEventAttr = linux.PerfEventAttr
131
132// PerfEventOpen is a wrapper
133func PerfEventOpen(attr *PerfEventAttr, pid int, cpu int, groupFd int, flags int) (fd int, err error) {
134	return linux.PerfEventOpen(attr, pid, cpu, groupFd, flags)
135}
136
137// Utsname is a wrapper
138type Utsname = linux.Utsname
139
140// Uname is a wrapper
141func Uname(buf *Utsname) (err error) {
142	return linux.Uname(buf)
143}
144
145// Getpid is a wrapper
146func Getpid() int {
147	return linux.Getpid()
148}
149
150// Gettid is a wrapper
151func Gettid() int {
152	return linux.Gettid()
153}
154
155// Tgkill is a wrapper
156func Tgkill(tgid int, tid int, sig syscall.Signal) (err error) {
157	return linux.Tgkill(tgid, tid, sig)
158}
159
160func KernelRelease() (string, error) {
161	var uname Utsname
162	err := Uname(&uname)
163	if err != nil {
164		return "", err
165	}
166
167	end := bytes.IndexByte(uname.Release[:], 0)
168	release := string(uname.Release[:end])
169	return release, nil
170}
171