Skip to content

hayabusa-cloud/zcall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zcall

Go Reference Go Report Card Codecov License: MIT

Low-level syscall primitives for Go on Linux, Darwin, and experimental FreeBSD.

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

Overview

zcall provides low-level syscall entry points that bypass Go's runtime syscall machinery (entersyscall/exitsyscall). It targets code paths that need direct control over syscall boundaries, such as io_uring submission.

Properties

  • Direct syscall entry points, provided through assembly stubs for each platform.
  • Kernel-style return values, with wrappers returning the raw result alongside errno.
  • Syscall numbers and related constants defined internally, without depending on syscall or x/sys/unix.
  • Platform-specific implementations selected through build tags.

Operations

  • Primitive entry points for 4-argument and 6-argument syscalls.
  • Wrappers for common I/O, socket, memory, and socket-option operations.
  • Linux-specific helpers for network link queries, special file descriptors, zero-copy operations, and io_uring.

Installation

go get code.hybscloud.com/zcall

Usage

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

Examples

Check errno directly

msg := []byte("hello\n")
n, errno := zcall.Write(1, msg)
if errno != 0 {
	return zcall.Errno(errno)
}

Create a nonblocking socket

fd, errno := zcall.Socket(zcall.AF_INET, zcall.SOCK_STREAM|zcall.SOCK_NONBLOCK|zcall.SOCK_CLOEXEC, 0)
if errno != 0 {
	return zcall.Errno(errno)
}
defer zcall.Close(fd)

Linux: list network links

links, err := zcall.Links()
if err != nil {
	return err
}

Types/Operations

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)

Wrapper availability

Available on Linux and Darwin

Category Functions
Basic I/O Read, Write, Close, Ioctl
Vectored I/O Readv, Writev, Preadv, Pwritev
Socket Socket, Bind, Listen, Accept, Connect, Shutdown, Socketpair
Socket Options Setsockopt, Getsockopt, Getsockname, Getpeername
Socket I/O Sendto, Recvfrom, Sendmsg, Recvmsg
Memory Mmap, Munmap, Pipe2

Linux-only wrappers

Category Functions
Vectored I/O Preadv2, Pwritev2
Socket Accept4
Socket I/O Sendmmsg, Recvmmsg
Network Links, LinkByName, LinkByIndex
Memory MemfdCreate
Timers TimerfdCreate, TimerfdSettime, TimerfdGettime
Events Eventfd2, Signalfd4
Process PidfdOpen, PidfdGetfd, PidfdSendSignal
Zero-copy Splice, Tee, Vmsplice
io_uring IoUringSetup, IoUringEnter, IoUringRegister

Architecture

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

Platform Support

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 ⚠ Experimental, untested SYSCALL

License

MIT — see LICENSE.

©2025 Hayabusa Cloud Co., Ltd.

About

Zero-overhead syscall primitives for Go

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors