zcall

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 2 Imported by: 0

README

zcall

Go Reference Go Report Card Codecov

Zero-overhead syscall primitives for Linux, Darwin, and FreeBSD in Go.

Language: English | 简体中文 | Español | 日本語 | Français

Overview

zcall provides raw syscall entry points that bypass Go's runtime syscall machinery (entersyscall/exitsyscall). This eliminates scheduler hook latency, making it ideal for low-latency I/O paths such as io_uring submission.

Key Features
  • Zero Overhead: Direct kernel invocation via raw assembly
  • Multi-Architecture: Supports linux/amd64, linux/arm64, linux/riscv64, linux/loong64, darwin/arm64, freebsd/amd64
  • Raw Semantics: Returns kernel result and errno directly

Installation

go get code.hybscloud.com/zcall

Quick Start

msg := []byte("Hello from zcall!\n")
// Direct kernel write to stdout
zcall.Write(1, msg)

API

Primitive Syscalls
// 4-argument syscall
Syscall4(num, a1, a2, a3, a4 uintptr) (r1, errno uintptr)

// 6-argument syscall
Syscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, errno uintptr)
Convenience Wrappers
Category Functions
Basic I/O Read, Write, Close
Vectored I/O Readv, Writev, Preadv, Pwritev, Preadv2, Pwritev2
Socket Socket, Bind, Listen, Accept, Accept4, Connect, Shutdown
Socket I/O Sendto, Recvfrom, Sendmsg, Recvmsg, Sendmmsg, Recvmmsg
Memory Mmap, Munmap, MemfdCreate
Timers TimerfdCreate, TimerfdSettime, TimerfdGettime
Events Eventfd2, Signalfd4
Zero-copy Splice, Tee, Vmsplice, Pipe2
io_uring IoUringSetup, IoUringEnter, IoUringRegister

Architecture

┌─────────────────────────────────────────────────────────┐
│                    User Application                     │
├─────────────────────────────────────────────────────────┤
│                      zcall API                          │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐  │
│  │  Syscall4   │  │  Syscall6   │  │ Convenience API │  │
│  └──────┬──────┘  └──────┬──────┘  └────────┬────────┘  │
├─────────┴────────────────┴─────────────────┴────────────┤
│                  internal/asm_*.s                       │
│         Raw Assembly (SYSCALL / SVC / ECALL)            │
├─────────────────────────────────────────────────────────┤
│                     Operating System                    │
└─────────────────────────────────────────────────────────┘

Supported Platforms

Architecture Status Instruction
linux/amd64 ✅ Supported SYSCALL
linux/arm64 ✅ Supported SVC #0
linux/riscv64 ✅ Supported ECALL
linux/loong64 ✅ Supported SYSCALL
darwin/arm64 ✅ Supported SVC #0x80
freebsd/amd64 ✅ Supported SYSCALL

Safety Considerations

Since zcall bypasses Go's scheduler hooks:

  1. Non-blocking Calls: Prefer non-blocking syscalls with proper readiness checks
  2. Pointer Validity: Ensure pointers remain valid during syscall execution
  3. Error Handling: Check errno; use zcall.Errno(errno) for error conversion

License

MIT — see LICENSE.

©2025 Hayabusa Cloud Co., Ltd.

Documentation

Overview

Package zcall provides zero-overhead syscall primitives for Linux and Darwin.

Overview

zcall bypasses Go's runtime syscall machinery (entersyscall/exitsyscall) by invoking the kernel directly via raw assembly. This eliminates the latency tax imposed by Go's scheduler hooks, making it suitable for low-latency I/O paths such as io_uring submission and completion.

Design Principles

Zero Overhead: All syscalls are implemented in pure assembly without any Go runtime interaction. The caller is responsible for cooperative scheduling.

Zero Dependencies: This package does not import "syscall" or "golang.org/x/sys/unix". All syscall numbers and constants are defined internally.

Raw Semantics: Functions return the raw kernel result and errno. A negative return value indicates an error, with the absolute value representing the errno. The caller must handle error translation.

Supported Architectures

  • linux/amd64: Uses SYSCALL instruction
  • linux/arm64: Uses SVC #0 instruction
  • linux/riscv64: Uses ECALL instruction
  • linux/loong64: Uses SYSCALL instruction
  • darwin/arm64: Uses SVC #0x80 instruction
  • freebsd/amd64: Uses SYSCALL instruction

Usage

zcall is designed as a building block for high-performance I/O libraries. Direct usage requires understanding of Linux syscall semantics and careful attention to memory safety.

r1, errno := zcall.Syscall6(zcall.SYS_IO_URING_ENTER, fd, toSubmit, minComplete, flags, sigset, sigsetSize)
if errno != 0 {
    // handle error
}

Safety

This package uses unsafe operations for pointer-to-uintptr conversion. Callers must ensure that:

  • Pointers passed to syscalls remain valid for the duration of the call
  • Memory referenced by pointers is not garbage collected during the call
  • Proper synchronization is used for concurrent access

Manual Cooperation

Since zcall bypasses the Go scheduler's syscall hooks, long-running syscalls may starve other goroutines. Callers should:

  • Use non-blocking syscalls where possible
  • Call spin.Yield() periodically in tight loops
  • Consider using GOMAXPROCS > 1 for concurrent workloads

Index

Constants

View Source
const (
	AF_UNIX   = 1
	AF_LOCAL  = AF_UNIX
	AF_INET   = 2
	AF_INET6  = 10
	AF_PACKET = 17
)

Socket address families.

View Source
const (
	SOCK_STREAM    = 1
	SOCK_DGRAM     = 2
	SOCK_RAW       = 3
	SOCK_RDM       = 4
	SOCK_SEQPACKET = 5
	SOCK_NONBLOCK  = 0x800
	SOCK_CLOEXEC   = 0x80000
)

Socket types.

View Source
const (
	IPPROTO_IP   = 0
	IPPROTO_ICMP = 1
	IPPROTO_TCP  = 6
	IPPROTO_UDP  = 17
	IPPROTO_IPV6 = 41
	IPPROTO_SCTP = 132
	IPPROTO_RAW  = 255
)

IP protocols.

View Source
const (
	SOL_SOCKET = 1
	SOL_IP     = 0
	SOL_TCP    = 6
	SOL_UDP    = 17
	SOL_IPV6   = 41
	SOL_SCTP   = 132
)

Socket options levels.

View Source
const (
	SO_DEBUG        = 1
	SO_REUSEADDR    = 2
	SO_TYPE         = 3
	SO_ERROR        = 4
	SO_DONTROUTE    = 5
	SO_BROADCAST    = 6
	SO_SNDBUF       = 7
	SO_RCVBUF       = 8
	SO_KEEPALIVE    = 9
	SO_OOBINLINE    = 10
	SO_NO_CHECK     = 11
	SO_PRIORITY     = 12
	SO_LINGER       = 13
	SO_BSDCOMPAT    = 14
	SO_REUSEPORT    = 15
	SO_RCVLOWAT     = 18
	SO_SNDLOWAT     = 19
	SO_RCVTIMEO     = 20
	SO_SNDTIMEO     = 21
	SO_ACCEPTCONN   = 30
	SO_SNDBUFFORCE  = 32
	SO_RCVBUFFORCE  = 33
	SO_PROTOCOL     = 38
	SO_DOMAIN       = 39
	SO_ZEROCOPY     = 60
	SO_INCOMING_CPU = 49
	SO_BUSY_POLL    = 46
)

Socket options (SOL_SOCKET level).

View Source
const (
	TCP_NODELAY       = 1
	TCP_MAXSEG        = 2
	TCP_CORK          = 3
	TCP_KEEPIDLE      = 4
	TCP_KEEPINTVL     = 5
	TCP_KEEPCNT       = 6
	TCP_SYNCNT        = 7
	TCP_LINGER2       = 8
	TCP_DEFER_ACCEPT  = 9
	TCP_WINDOW_CLAMP  = 10
	TCP_INFO          = 11
	TCP_QUICKACK      = 12
	TCP_CONGESTION    = 13
	TCP_FASTOPEN      = 23
	TCP_NOTSENT_LOWAT = 25
)

TCP options.

View Source
const (
	UDP_CORK    = 1
	UDP_ENCAP   = 100
	UDP_SEGMENT = 103
	UDP_GRO     = 104
)

UDP options.

View Source
const (
	IPV6_V6ONLY       = 26
	IPV6_RECVPKTINFO  = 49
	IPV6_PKTINFO      = 50
	IPV6_RECVHOPLIMIT = 51
	IPV6_HOPLIMIT     = 52
)

IPv6 options.

View Source
const (
	O_RDONLY   = 0x0
	O_WRONLY   = 0x1
	O_RDWR     = 0x2
	O_CREAT    = 0x40
	O_EXCL     = 0x80
	O_NOCTTY   = 0x100
	O_TRUNC    = 0x200
	O_APPEND   = 0x400
	O_NONBLOCK = 0x800
	O_SYNC     = 0x101000
	O_CLOEXEC  = 0x80000
	O_DIRECT   = 0x4000
)

File descriptor flags.

View Source
const (
	EFD_SEMAPHORE = 0x1
	EFD_CLOEXEC   = 0x80000
	EFD_NONBLOCK  = 0x800
)

eventfd flags.

View Source
const (
	TFD_CLOEXEC       = 0x80000
	TFD_NONBLOCK      = 0x800
	TFD_TIMER_ABSTIME = 0x1
)

timerfd flags.

View Source
const (
	SFD_CLOEXEC  = 0x80000
	SFD_NONBLOCK = 0x800
)

signalfd flags.

View Source
const (
	MFD_CLOEXEC       = 0x1
	MFD_ALLOW_SEALING = 0x2
	MFD_HUGETLB       = 0x4
	MFD_NOEXEC_SEAL   = 0x8
	MFD_EXEC          = 0x10
)

memfd flags.

View Source
const (
	CLOCK_REALTIME  = 0
	CLOCK_MONOTONIC = 1
)

Clock IDs for timerfd.

View Source
const (
	IORING_SETUP_IOPOLL        = 1 << 0
	IORING_SETUP_SQPOLL        = 1 << 1
	IORING_SETUP_SQ_AFF        = 1 << 2
	IORING_SETUP_CQSIZE        = 1 << 3
	IORING_SETUP_CLAMP         = 1 << 4
	IORING_SETUP_ATTACH_WQ     = 1 << 5
	IORING_SETUP_R_DISABLED    = 1 << 6
	IORING_SETUP_SUBMIT_ALL    = 1 << 7
	IORING_SETUP_COOP_TASKRUN  = 1 << 8
	IORING_SETUP_TASKRUN_FLAG  = 1 << 9
	IORING_SETUP_SQE128        = 1 << 10
	IORING_SETUP_CQE32         = 1 << 11
	IORING_SETUP_SINGLE_ISSUER = 1 << 12
	IORING_SETUP_DEFER_TASKRUN = 1 << 13
)

io_uring setup flags.

View Source
const (
	IORING_ENTER_GETEVENTS       = 1 << 0
	IORING_ENTER_SQ_WAKEUP       = 1 << 1
	IORING_ENTER_SQ_WAIT         = 1 << 2
	IORING_ENTER_EXT_ARG         = 1 << 3
	IORING_ENTER_REGISTERED_RING = 1 << 4
)

io_uring enter flags.

View Source
const (
	IORING_OP_NOP             = 0
	IORING_OP_READV           = 1
	IORING_OP_WRITEV          = 2
	IORING_OP_FSYNC           = 3
	IORING_OP_READ_FIXED      = 4
	IORING_OP_WRITE_FIXED     = 5
	IORING_OP_POLL_ADD        = 6
	IORING_OP_POLL_REMOVE     = 7
	IORING_OP_SYNC_FILE_RANGE = 8
	IORING_OP_SENDMSG         = 9
	IORING_OP_RECVMSG         = 10
	IORING_OP_TIMEOUT         = 11
	IORING_OP_TIMEOUT_REMOVE  = 12
	IORING_OP_ACCEPT          = 13
	IORING_OP_ASYNC_CANCEL    = 14
	IORING_OP_LINK_TIMEOUT    = 15
	IORING_OP_CONNECT         = 16
	IORING_OP_FALLOCATE       = 17
	IORING_OP_OPENAT          = 18
	IORING_OP_CLOSE           = 19
	IORING_OP_FILES_UPDATE    = 20
	IORING_OP_STATX           = 21
	IORING_OP_READ            = 22
	IORING_OP_WRITE           = 23
	IORING_OP_FADVISE         = 24
	IORING_OP_MADVISE         = 25
	IORING_OP_SEND            = 26
	IORING_OP_RECV            = 27
	IORING_OP_OPENAT2         = 28
	IORING_OP_EPOLL_CTL       = 29
	IORING_OP_SPLICE          = 30
	IORING_OP_PROVIDE_BUFFERS = 31
	IORING_OP_REMOVE_BUFFERS  = 32
	IORING_OP_TEE             = 33
	IORING_OP_SHUTDOWN        = 34
	IORING_OP_RENAMEAT        = 35
	IORING_OP_UNLINKAT        = 36
	IORING_OP_MKDIRAT         = 37
	IORING_OP_SYMLINKAT       = 38
	IORING_OP_LINKAT          = 39
	IORING_OP_MSG_RING        = 40
	IORING_OP_FSETXATTR       = 41
	IORING_OP_SETXATTR        = 42
	IORING_OP_FGETXATTR       = 43
	IORING_OP_GETXATTR        = 44
	IORING_OP_SOCKET          = 45
	IORING_OP_URING_CMD       = 46
	IORING_OP_SEND_ZC         = 47
	IORING_OP_SENDMSG_ZC      = 48
)

io_uring opcodes.

View Source
const (
	IOSQE_FIXED_FILE       = 1 << 0
	IOSQE_IO_DRAIN         = 1 << 1
	IOSQE_IO_LINK          = 1 << 2
	IOSQE_IO_HARDLINK      = 1 << 3
	IOSQE_ASYNC            = 1 << 4
	IOSQE_BUFFER_SELECT    = 1 << 5
	IOSQE_CQE_SKIP_SUCCESS = 1 << 6
)

io_uring SQE flags.

View Source
const (
	IORING_REGISTER_BUFFERS          = 0
	IORING_UNREGISTER_BUFFERS        = 1
	IORING_REGISTER_FILES            = 2
	IORING_UNREGISTER_FILES          = 3
	IORING_REGISTER_EVENTFD          = 4
	IORING_UNREGISTER_EVENTFD        = 5
	IORING_REGISTER_FILES_UPDATE     = 6
	IORING_REGISTER_EVENTFD_ASYNC    = 7
	IORING_REGISTER_PROBE            = 8
	IORING_REGISTER_PERSONALITY      = 9
	IORING_UNREGISTER_PERSONALITY    = 10
	IORING_REGISTER_RESTRICTIONS     = 11
	IORING_REGISTER_ENABLE_RINGS     = 12
	IORING_REGISTER_FILES2           = 13
	IORING_REGISTER_FILES_UPDATE2    = 14
	IORING_REGISTER_BUFFERS2         = 15
	IORING_REGISTER_BUFFERS_UPDATE   = 16
	IORING_REGISTER_IOWQ_AFF         = 17
	IORING_UNREGISTER_IOWQ_AFF       = 18
	IORING_REGISTER_IOWQ_MAX_WORKERS = 19
	IORING_REGISTER_RING_FDS         = 20
	IORING_UNREGISTER_RING_FDS       = 21
	IORING_REGISTER_PBUF_RING        = 22
	IORING_UNREGISTER_PBUF_RING      = 23
	IORING_REGISTER_SYNC_CANCEL      = 24
	IORING_REGISTER_FILE_ALLOC_RANGE = 25
)

io_uring register opcodes.

View Source
const (
	PROT_NONE  = 0x0
	PROT_READ  = 0x1
	PROT_WRITE = 0x2
	PROT_EXEC  = 0x4
)

mmap protection flags.

View Source
const (
	MAP_SHARED    = 0x1
	MAP_PRIVATE   = 0x2
	MAP_FIXED     = 0x10
	MAP_ANONYMOUS = 0x20
	MAP_POPULATE  = 0x8000
)

mmap flags.

View Source
const (
	POLLIN    = 0x1
	POLLPRI   = 0x2
	POLLOUT   = 0x4
	POLLERR   = 0x8
	POLLHUP   = 0x10
	POLLNVAL  = 0x20
	POLLRDHUP = 0x2000
)

Poll events.

View Source
const (
	SHUT_RD   = 0
	SHUT_WR   = 1
	SHUT_RDWR = 2
)

Shutdown how.

View Source
const (
	MSG_OOB          = 0x1
	MSG_PEEK         = 0x2
	MSG_DONTROUTE    = 0x4
	MSG_CTRUNC       = 0x8
	MSG_PROXY        = 0x10
	MSG_TRUNC        = 0x20
	MSG_DONTWAIT     = 0x40
	MSG_EOR          = 0x80
	MSG_WAITALL      = 0x100
	MSG_FIN          = 0x200
	MSG_SYN          = 0x400
	MSG_CONFIRM      = 0x800
	MSG_RST          = 0x1000
	MSG_ERRQUEUE     = 0x2000
	MSG_NOSIGNAL     = 0x4000
	MSG_MORE         = 0x8000
	MSG_WAITFORONE   = 0x10000
	MSG_BATCH        = 0x40000
	MSG_ZEROCOPY     = 0x4000000
	MSG_FASTOPEN     = 0x20000000
	MSG_CMSG_CLOEXEC = 0x40000000
)

MSG flags for send/recv.

View Source
const (
	SPLICE_F_MOVE     = 0x1
	SPLICE_F_NONBLOCK = 0x2
	SPLICE_F_MORE     = 0x4
	SPLICE_F_GIFT     = 0x8
)

Splice flags.

View Source
const (
	RWF_HIPRI  = 0x1
	RWF_DSYNC  = 0x2
	RWF_SYNC   = 0x4
	RWF_NOWAIT = 0x8
	RWF_APPEND = 0x10
)

RWF flags for preadv2/pwritev2.

View Source
const (
	// Basic I/O
	SYS_READ      = 0
	SYS_WRITE     = 1
	SYS_CLOSE     = 3
	SYS_FSTAT     = 5
	SYS_MMAP      = 9
	SYS_MUNMAP    = 11
	SYS_FTRUNCATE = 77

	// Vectored I/O
	SYS_READV    = 19
	SYS_WRITEV   = 20
	SYS_PREADV   = 295
	SYS_PWRITEV  = 296
	SYS_PREADV2  = 327
	SYS_PWRITEV2 = 328

	// Networking - basic
	SYS_SOCKET      = 41
	SYS_CONNECT     = 42
	SYS_ACCEPT      = 43
	SYS_SENDTO      = 44
	SYS_RECVFROM    = 45
	SYS_SENDMSG     = 46
	SYS_RECVMSG     = 47
	SYS_SHUTDOWN    = 48
	SYS_BIND        = 49
	SYS_LISTEN      = 50
	SYS_GETSOCKNAME = 51
	SYS_GETPEERNAME = 52
	SYS_SOCKETPAIR  = 53
	SYS_SETSOCKOPT  = 54
	SYS_GETSOCKOPT  = 55

	// Zero-copy and pipe
	SYS_SPLICE   = 275
	SYS_TEE      = 276
	SYS_VMSPLICE = 278
	SYS_PIPE2    = 293

	// Timers and events
	SYS_TIMERFD_CREATE  = 283
	SYS_TIMERFD_SETTIME = 286
	SYS_TIMERFD_GETTIME = 287
	SYS_ACCEPT4         = 288
	SYS_EVENTFD2        = 290

	// Multi-message
	SYS_RECVMMSG = 299
	SYS_SENDMMSG = 307

	// io_uring
	SYS_IO_URING_SETUP    = 425
	SYS_IO_URING_ENTER    = 426
	SYS_IO_URING_REGISTER = 427

	// signalfd, pidfd, memfd
	SYS_SIGNALFD4         = 289
	SYS_MEMFD_CREATE      = 319
	SYS_PIDFD_SEND_SIGNAL = 424
	SYS_PIDFD_OPEN        = 434
	SYS_PIDFD_GETFD       = 438
)

Syscall numbers for Linux on amd64. Reference: arch/x86/entry/syscalls/syscall_64.tbl

View Source
const (
	PIDFD_NONBLOCK = 0x800
)

pidfd flags.

Variables

This section is empty.

Functions

func Accept

func Accept(fd uintptr, addr unsafe.Pointer, addrlen unsafe.Pointer) (nfd uintptr, errno uintptr)

Accept accepts a connection on a socket.

func Accept4

func Accept4(fd uintptr, addr unsafe.Pointer, addrlen unsafe.Pointer, flags uintptr) (nfd uintptr, errno uintptr)

Accept4 accepts a connection on a socket with flags.

func Bind

func Bind(fd uintptr, addr unsafe.Pointer, addrlen uintptr) (errno uintptr)

Bind binds a socket to an address.

func Close

func Close(fd uintptr) (errno uintptr)

Close closes a file descriptor.

func Connect

func Connect(fd uintptr, addr unsafe.Pointer, addrlen uintptr) (errno uintptr)

Connect connects a socket to an address.

func Eventfd2

func Eventfd2(initval, flags uintptr) (fd uintptr, errno uintptr)

Eventfd2 creates an eventfd.

func Getpeername

func Getpeername(fd uintptr, addr unsafe.Pointer, addrlen unsafe.Pointer) (errno uintptr)

Getpeername gets the remote address of a socket.

func Getsockname

func Getsockname(fd uintptr, addr unsafe.Pointer, addrlen unsafe.Pointer) (errno uintptr)

Getsockname gets the local address of a socket.

func Getsockopt

func Getsockopt(fd, level, optname uintptr, optval unsafe.Pointer, optlen unsafe.Pointer) (errno uintptr)

Getsockopt gets a socket option.

func IoUringEnter

func IoUringEnter(fd, toSubmit, minComplete, flags uintptr, sig unsafe.Pointer, sigsetSize uintptr) (r1 uintptr, errno uintptr)

IoUringEnter submits I/O requests and/or waits for completions.

func IoUringRegister

func IoUringRegister(fd, opcode uintptr, arg unsafe.Pointer, nrArgs uintptr) (r1 uintptr, errno uintptr)

IoUringRegister registers resources with an io_uring instance.

func IoUringSetup

func IoUringSetup(entries uintptr, params unsafe.Pointer) (fd uintptr, errno uintptr)

IoUringSetup sets up an io_uring instance.

func Listen

func Listen(fd, backlog uintptr) (errno uintptr)

Listen marks a socket as listening.

func MemfdCreate

func MemfdCreate(name unsafe.Pointer, flags uintptr) (fd uintptr, errno uintptr)

MemfdCreate creates an anonymous, memory-backed file descriptor. The name is a null-terminated string used for debugging (visible in /proc/self/fd/). Flags may include MFD_CLOEXEC, MFD_ALLOW_SEALING, and MFD_HUGETLB. Returns the file descriptor and errno.

func Mmap

func Mmap(addr unsafe.Pointer, length, prot, flags, fd, offset uintptr) (ptr unsafe.Pointer, errno uintptr)

Mmap maps files or devices into memory. Returns unsafe.Pointer to enable vet-clean pointer arithmetic with unsafe.Add.

func Munmap

func Munmap(addr unsafe.Pointer, length uintptr) (errno uintptr)

Munmap unmaps files or devices from memory.

func PidfdGetfd

func PidfdGetfd(pidfd, targetfd, flags uintptr) (fd uintptr, errno uintptr)

PidfdGetfd duplicates a file descriptor from another process.

func PidfdOpen

func PidfdOpen(pid, flags uintptr) (fd uintptr, errno uintptr)

PidfdOpen refers to a process.

func PidfdSendSignal

func PidfdSendSignal(pidfd, sig uintptr, info unsafe.Pointer, flags uintptr) (errno uintptr)

PidfdSendSignal sends a signal to a process.

func Pipe2

func Pipe2(fds *[2]int32, flags uintptr) (errno uintptr)

Pipe2 creates a pipe with flags.

func Preadv

func Preadv(fd uintptr, iov unsafe.Pointer, iovcnt uintptr, offset int64) (n uintptr, errno uintptr)

Preadv reads into multiple buffers at a given offset.

func Preadv2

func Preadv2(fd uintptr, iov unsafe.Pointer, iovcnt uintptr, offset int64, flags uintptr) (n uintptr, errno uintptr)

Preadv2 reads into multiple buffers at a given offset with flags.

func Pwritev

func Pwritev(fd uintptr, iov unsafe.Pointer, iovcnt uintptr, offset int64) (n uintptr, errno uintptr)

Pwritev writes from multiple buffers at a given offset.

func Pwritev2

func Pwritev2(fd uintptr, iov unsafe.Pointer, iovcnt uintptr, offset int64, flags uintptr) (n uintptr, errno uintptr)

Pwritev2 writes from multiple buffers at a given offset with flags.

func Read

func Read(fd uintptr, buf []byte) (n uintptr, errno uintptr)

Read reads from a file descriptor into buf.

func Readv

func Readv(fd uintptr, iov unsafe.Pointer, iovcnt uintptr) (n uintptr, errno uintptr)

Readv reads into multiple buffers.

func Recvfrom

func Recvfrom(fd uintptr, buf []byte, flags uintptr, addr unsafe.Pointer, addrlen unsafe.Pointer) (n uintptr, errno uintptr)

Recvfrom receives a message from a socket.

func Recvmmsg

func Recvmmsg(fd uintptr, msgvec unsafe.Pointer, vlen, flags uintptr, timeout unsafe.Pointer) (n uintptr, errno uintptr)

Recvmmsg receives multiple messages from a socket.

func Recvmsg

func Recvmsg(fd uintptr, msg unsafe.Pointer, flags uintptr) (n uintptr, errno uintptr)

Recvmsg receives a message from a socket using a msghdr.

func Sendmmsg

func Sendmmsg(fd uintptr, msgvec unsafe.Pointer, vlen, flags uintptr) (n uintptr, errno uintptr)

Sendmmsg sends multiple messages on a socket.

func Sendmsg

func Sendmsg(fd uintptr, msg unsafe.Pointer, flags uintptr) (n uintptr, errno uintptr)

Sendmsg sends a message on a socket using a msghdr.

func Sendto

func Sendto(fd uintptr, buf []byte, flags uintptr, addr unsafe.Pointer, addrlen uintptr) (n uintptr, errno uintptr)

Sendto sends a message on a socket.

func Setsockopt

func Setsockopt(fd, level, optname uintptr, optval unsafe.Pointer, optlen uintptr) (errno uintptr)

Setsockopt sets a socket option.

func Shutdown

func Shutdown(fd, how uintptr) (errno uintptr)

Shutdown shuts down part of a full-duplex connection.

func Signalfd4

func Signalfd4(fd uintptr, mask unsafe.Pointer, maskSize, flags uintptr) (newfd uintptr, errno uintptr)

Signalfd4 creates or modifies a file descriptor for signal handling. If fd is -1 (^uintptr(0)), a new signalfd is created; otherwise, the existing fd is modified. The mask points to a sigset_t specifying which signals to accept. Flags may include SFD_NONBLOCK and SFD_CLOEXEC. Returns the file descriptor and errno.

func Socket

func Socket(domain, typ, protocol uintptr) (fd uintptr, errno uintptr)

Socket creates a socket.

func Socketpair

func Socketpair(domain, typ, protocol uintptr, fds *[2]int32) (errno uintptr)

Socketpair creates a pair of connected sockets.

func Splice

func Splice(fdIn uintptr, offIn *int64, fdOut uintptr, offOut *int64, length, flags uintptr) (n uintptr, errno uintptr)

Splice moves data between two file descriptors.

func Syscall4

func Syscall4(num, a1, a2, a3, a4 uintptr) (r1, errno uintptr)

Syscall4 executes a syscall with up to 4 arguments.

func Syscall6

func Syscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, errno uintptr)

Syscall6 executes a syscall with up to 6 arguments.

func Tee

func Tee(fdIn, fdOut, length, flags uintptr) (n uintptr, errno uintptr)

Tee duplicates data between two pipe file descriptors.

func TimerfdCreate

func TimerfdCreate(clockid, flags uintptr) (fd uintptr, errno uintptr)

TimerfdCreate creates a timerfd.

func TimerfdGettime

func TimerfdGettime(fd uintptr, currValue unsafe.Pointer) (errno uintptr)

TimerfdGettime gets the current setting of a timerfd.

func TimerfdSettime

func TimerfdSettime(fd, flags uintptr, newValue, oldValue unsafe.Pointer) (errno uintptr)

TimerfdSettime arms or disarms a timerfd.

func Vmsplice

func Vmsplice(fd uintptr, iov unsafe.Pointer, nrSegs, flags uintptr) (n uintptr, errno uintptr)

Vmsplice maps user pages into a pipe.

func Write

func Write(fd uintptr, buf []byte) (n uintptr, errno uintptr)

Write writes buf to a file descriptor.

func Writev

func Writev(fd uintptr, iov unsafe.Pointer, iovcnt uintptr) (n uintptr, errno uintptr)

Writev writes from multiple buffers.

Types

type Errno

type Errno uintptr

Errno is a raw system error number. It implements the error interface and provides helper methods for common error patterns.

const (
	EPERM           Errno = 1
	ENOENT          Errno = 2
	ESRCH           Errno = 3
	EINTR           Errno = 4
	EIO             Errno = 5
	ENXIO           Errno = 6
	E2BIG           Errno = 7
	ENOEXEC         Errno = 8
	EBADF           Errno = 9
	ECHILD          Errno = 10
	EAGAIN          Errno = 11
	EWOULDBLOCK     Errno = EAGAIN
	ENOMEM          Errno = 12
	EACCES          Errno = 13
	EFAULT          Errno = 14
	ENOTBLK         Errno = 15
	EBUSY           Errno = 16
	EEXIST          Errno = 17
	EXDEV           Errno = 18
	ENODEV          Errno = 19
	ENOTDIR         Errno = 20
	EISDIR          Errno = 21
	EINVAL          Errno = 22
	ENFILE          Errno = 23
	EMFILE          Errno = 24
	ENOTTY          Errno = 25
	ETXTBSY         Errno = 26
	EFBIG           Errno = 27
	ENOSPC          Errno = 28
	ESPIPE          Errno = 29
	EROFS           Errno = 30
	EMLINK          Errno = 31
	EPIPE           Errno = 32
	EDOM            Errno = 33
	ERANGE          Errno = 34
	EDEADLK         Errno = 35
	ENAMETOOLONG    Errno = 36
	ENOLCK          Errno = 37
	ENOSYS          Errno = 38
	ENOTEMPTY       Errno = 39
	ELOOP           Errno = 40
	ENOMSG          Errno = 42
	EIDRM           Errno = 43
	ECHRNG          Errno = 44
	EL2NSYNC        Errno = 45
	EL3HLT          Errno = 46
	EL3RST          Errno = 47
	ELNRNG          Errno = 48
	EUNATCH         Errno = 49
	ENOCSI          Errno = 50
	EL2HLT          Errno = 51
	EBADE           Errno = 52
	EBADR           Errno = 53
	EXFULL          Errno = 54
	ENOANO          Errno = 55
	EBADRQC         Errno = 56
	EBADSLT         Errno = 57
	EBFONT          Errno = 59
	ENOSTR          Errno = 60
	ENODATA         Errno = 61
	ETIME           Errno = 62
	ENOSR           Errno = 63
	ENONET          Errno = 64
	ENOPKG          Errno = 65
	EREMOTE         Errno = 66
	ENOLINK         Errno = 67
	EADV            Errno = 68
	ESRMNT          Errno = 69
	ECOMM           Errno = 70
	EPROTO          Errno = 71
	EMULTIHOP       Errno = 72
	EDOTDOT         Errno = 73
	EBADMSG         Errno = 74
	EOVERFLOW       Errno = 75
	ENOTUNIQ        Errno = 76
	EBADFD          Errno = 77
	EREMCHG         Errno = 78
	ELIBACC         Errno = 79
	ELIBBAD         Errno = 80
	ELIBSCN         Errno = 81
	ELIBMAX         Errno = 82
	ELIBEXEC        Errno = 83
	EILSEQ          Errno = 84
	ERESTART        Errno = 85
	ESTRPIPE        Errno = 86
	EUSERS          Errno = 87
	ENOTSOCK        Errno = 88
	EDESTADDRREQ    Errno = 89
	EMSGSIZE        Errno = 90
	EPROTOTYPE      Errno = 91
	ENOPROTOOPT     Errno = 92
	EPROTONOSUPPORT Errno = 93
	ESOCKTNOSUPPORT Errno = 94
	EOPNOTSUPP      Errno = 95
	ENOTSUP         Errno = EOPNOTSUPP
	EPFNOSUPPORT    Errno = 96
	EAFNOSUPPORT    Errno = 97
	EADDRINUSE      Errno = 98
	EADDRNOTAVAIL   Errno = 99
	ENETDOWN        Errno = 100
	ENETUNREACH     Errno = 101
	ENETRESET       Errno = 102
	ECONNABORTED    Errno = 103
	ECONNRESET      Errno = 104
	ENOBUFS         Errno = 105
	EISCONN         Errno = 106
	ENOTCONN        Errno = 107
	ESHUTDOWN       Errno = 108
	ETOOMANYREFS    Errno = 109
	ETIMEDOUT       Errno = 110
	ECONNREFUSED    Errno = 111
	EHOSTDOWN       Errno = 112
	EHOSTUNREACH    Errno = 113
	EALREADY        Errno = 114
	EINPROGRESS     Errno = 115
	ESTALE          Errno = 116
	EUCLEAN         Errno = 117
	ENOTNAM         Errno = 118
	ENAVAIL         Errno = 119
	EISNAM          Errno = 120
	EREMOTEIO       Errno = 121
	EDQUOT          Errno = 122
	ENOMEDIUM       Errno = 123
	EMEDIUMTYPE     Errno = 124
	ECANCELED       Errno = 125
	ENOKEY          Errno = 126
	EKEYEXPIRED     Errno = 127
	EKEYREVOKED     Errno = 128
	EKEYREJECTED    Errno = 129
	EOWNERDEAD      Errno = 130
	ENOTRECOVERABLE Errno = 131
	ERFKILL         Errno = 132
	EHWPOISON       Errno = 133
)

Common Linux error numbers.

func (Errno) Error

func (e Errno) Error() string

func (Errno) Is

func (e Errno) Is(target error) bool

Is reports whether the error is equal to the target. This enables errors.Is() compatibility.

func (Errno) Temporary

func (e Errno) Temporary() bool

Temporary reports whether the error is temporary. Temporary errors include EAGAIN, EWOULDBLOCK, EINTR, and EINPROGRESS.

func (Errno) Timeout

func (e Errno) Timeout() bool

Timeout reports whether the error represents a timeout.

type Iovec

type Iovec struct {
	Base *byte
	Len  uint64
}

Iovec represents a scatter/gather I/O vector. Used by readv, writev, preadv, pwritev, and related syscalls.

type Itimerspec

type Itimerspec struct {
	Interval Timespec
	Value    Timespec
}

Itimerspec represents an interval timer specification.

type Mmsghdr

type Mmsghdr struct {
	Hdr Msghdr
	Len uint32
	// contains filtered or unexported fields
}

Mmsghdr represents a message header for sendmmsg/recvmmsg.

type Msghdr

type Msghdr struct {
	Name    *byte
	Namelen uint32

	Iov        *Iovec
	Iovlen     uint64
	Control    *byte
	Controllen uint64
	Flags      int32
	// contains filtered or unexported fields
}

Msghdr represents a message header for sendmsg/recvmsg.

type Timespec

type Timespec struct {
	Sec  int64
	Nsec int64
}

Timespec represents a time value with nanosecond precision.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL