2022-11-21 02:22:26 +08:00
|
|
|
package system
|
2014-11-08 08:56:13 +08:00
|
|
|
|
|
|
|
import (
|
2022-10-27 00:21:34 +08:00
|
|
|
"unsafe"
|
2023-06-19 22:06:44 +08:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SyscallErrno wraps the "unix.Errno"
|
|
|
|
type SyscallErrno unix.Errno
|
|
|
|
|
|
|
|
// wrapping for used constants of unix package
|
|
|
|
const (
|
|
|
|
Syscall_SYS_IOCTL = unix.SYS_IOCTL
|
|
|
|
Syscall_EINVAL = unix.EINVAL
|
|
|
|
Syscall_EBUSY = unix.EBUSY
|
|
|
|
Syscall_EFAULT = unix.EFAULT
|
2014-11-08 08:56:13 +08:00
|
|
|
)
|
|
|
|
|
2022-11-05 14:42:28 +08:00
|
|
|
// nativeSyscall represents the native Syscall
|
|
|
|
type nativeSyscall struct{}
|
2014-11-08 08:56:13 +08:00
|
|
|
|
2023-06-19 22:06:44 +08:00
|
|
|
// Syscall calls the native unix.Syscall, implements the SystemCaller interface
|
|
|
|
func (sys *nativeSyscall) syscall(trap uintptr, f File, signal uintptr, payload unsafe.Pointer) (r1, r2 uintptr, err SyscallErrno) {
|
|
|
|
r1, r2, errNo := unix.Syscall(trap, f.Fd(), signal, uintptr(payload))
|
|
|
|
return r1, r2, SyscallErrno(errNo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error implements the error interface. It wraps the "unix.Errno.Error()".
|
|
|
|
func (e SyscallErrno) Error() string {
|
|
|
|
return unix.Errno(e).Error()
|
2014-11-08 08:56:13 +08:00
|
|
|
}
|