1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package syscall provides the syscall primitives required for the runtime.
6package syscall
7
8import (
9	"unsafe"
10)
11
12// TODO(https://go.dev/issue/51087): This package is incomplete and currently
13// only contains very minimal support for Linux.
14
15// Syscall6 calls system call number 'num' with arguments a1-6.
16func Syscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr)
17
18func EpollCreate1(flags int32) (fd int32, errno uintptr) {
19	r1, _, e := Syscall6(SYS_EPOLL_CREATE1, uintptr(flags), 0, 0, 0, 0, 0)
20	return int32(r1), e
21}
22
23var _zero uintptr
24
25func EpollWait(epfd int32, events []EpollEvent, maxev, waitms int32) (n int32, errno uintptr) {
26	var ev unsafe.Pointer
27	if len(events) > 0 {
28		ev = unsafe.Pointer(&events[0])
29	} else {
30		ev = unsafe.Pointer(&_zero)
31	}
32	r1, _, e := Syscall6(SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(ev), uintptr(maxev), uintptr(waitms), 0, 0)
33	return int32(r1), e
34}
35
36func EpollCtl(epfd, op, fd int32, event *EpollEvent) (errno uintptr) {
37	_, _, e := Syscall6(SYS_EPOLL_CTL, uintptr(epfd), uintptr(op), uintptr(fd), uintptr(unsafe.Pointer(event)), 0, 0)
38	return e
39}
40
41func Eventfd(initval, flags int32) (fd int32, errno uintptr) {
42	r1, _, e := Syscall6(SYS_EVENTFD2, uintptr(initval), uintptr(flags), 0, 0, 0, 0)
43	return int32(r1), e
44}
45