feat(syscall): add madvise, epollctl

Signed-off-by: Nugraha <26342994+ii64@users.noreply.github.com>
This commit is contained in:
Nugraha 2022-02-10 02:16:53 +07:00
parent c232c10e24
commit 50fd85fabc
Signed by untrusted user who does not match committer: Xeffy
GPG key ID: E41C08AD390E7C49
3 changed files with 33 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package syscall
import (
"syscall"
"unsafe"
"github.com/ii64/gouring"
)
@ -9,7 +10,10 @@ import (
var _ = syscall.EpollCtl
// EpollCtl
func EpollCtl(sqe *gouring.SQEntry, epfd int, op int, fd int, event *syscall.EpollEvent) (err error) {
func EpollCtl(sqe *gouring.SQEntry, epfd int, op int, fd int, event *syscall.EpollEvent) {
sqe.Opcode = gouring.IORING_OP_EPOLL_CTL
return nil
sqe.Fd = int32(epfd)
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(event)))
sqe.Len = uint32(op)
*sqe.Offset() = uint64(fd)
}

View file

@ -5,5 +5,7 @@ import (
_ "unsafe"
)
var _zero uintptr
//go:linkname anyToSockaddr syscall.anyToSockaddr
func anyToSockaddr(rsa *syscall.RawSockaddrAny) (syscall.Sockaddr, error)

25
syscall/mem.go Normal file
View file

@ -0,0 +1,25 @@
package syscall
import (
"syscall"
"unsafe"
"github.com/ii64/gouring"
)
var _ = syscall.Madvise
// Madvise
func Madvise(sqe *gouring.SQEntry, b []byte, advice int) {
var ptr unsafe.Pointer
if len(b) > 0 {
ptr = unsafe.Pointer(&b[0])
} else {
ptr = unsafe.Pointer(&_zero)
}
sqe.Opcode = gouring.IORING_OP_MADVISE
sqe.Fd = -1
*sqe.Addr() = uint64(uintptr(ptr))
sqe.Len = uint32(len(b))
*sqe.Offset() = 0
}