A collection of small, self-contained C programs. Each file demonstrates a focused systems-programming concept using minimal, technical, production-style code.
The collection is designed as a reference for developers who work with:
- low-level Linux/POSIX APIs
- concurrency primitives
- memory management
- filesystem correctness
- networking and IPC
- kernel interfaces
- secure and defensive programming patterns
- JIT compilation and raw machine-code execution
- futex wait/wake, mutex, latch
- atomics and memory ordering
- seqlock
- sense-reversing barrier, eventfd barrier
- SPSC and MPMC lock-free ring buffers
- reader-writer lock (fair)
- Treiber stack with epoch-based reclamation
- RCU-style linked list
- CRDT PN-counter
- thread pool
- fiber / ucontext cooperative scheduler
- POSIX robust mutex (owner-death recovery)
- POSIX message queues with priority ordering
- mmap arenas with guard pages
- huge pages (
MAP_HUGETLB) - memfd sealing
- sliding-window memory mapping
- reference-counted objects
- LIFO scratch-region allocator
- userfaultfd demand-paging
- buddy system allocator (power-of-2, split/coalesce)
- atomic file replacement (
write+rename) - directory walking via
openat - log-structured record store with compaction
- key-value store with write-ahead journal
- filesystem transactions with rollback
- file-descriptor cache
- ring-buffer logger in shared memory
- pidfd
- userfaultfd
- fanotify
- inotify
- epoll (edge-triggered event loop with timerfd)
- eventfd
- io_uring
- kqueue (BSD/macOS)
- BPF socket counter
- perf event monitoring
- vDSO time
- syscall tracing via ptrace
- edge-triggered TCP server with epoll
- UNIX socket credential passing (
SCM_CREDENTIALS) - file descriptor passing over UNIX sockets (
SCM_RIGHTS) - POSIX shared memory SPSC ring
- zero-copy file serving with
sendfile - zero-copy pipe pumping with
splice - token-bucket rate limiter
- strict seccomp and seccomp-BPF filters
- OpenBSD
pledge/unveil - Landlock LSM filesystem restriction (Linux ≥ 5.13)
- user namespace isolation (
userns_spawn,userns_unshare) O_PATHcapability-style access- cgroup v2 memory limit enforcement
- alternate signal stack for crash handlers
- hierarchical timer wheel
- POSIX AIO
- signalfd / self-pipe fallback
- accurate periodic timer with
timerfdand missed-tick detection
- HKDF key derivation via OpenSSL EVP
- constant-time byte comparison
- cryptographically secure token generation
- runtime machine-code generation:
mmap(RW) → write bytes →mprotect(RX) → call - W^X page discipline
- extracting compiled functions as raw byte blobs (
objcopy,nm,xxd -i) - self-contained syscall-only payload with no libc, no relocations (
sysinfo_jit) - generic JIT host loader (
jit_host)
Build all snippets:
makeBuild a single snippet:
make futex_wait_wakeList all detected targets:
make listClean binaries:
make cleanThe Makefile inspects each source file and links only the libraries it needs:
| Condition | Extra flag |
|---|---|
| Uses pthreads | -pthread |
Uses POSIX AIO or shm_open |
-lrt |
Includes <liburing.h> |
-luring |
Includes <openssl/...> |
-lcrypto |
For snippets in the JIT & Machine Code category, the build flow differs:
# 1. compile to object file — do NOT link
gcc -O2 -fno-stack-protector -std=c11 -c payload.c -o payload.o
# 2. must print nothing — any output means broken relocations
objdump -r payload.o
# 3. extract the raw .text blob
objcopy -O binary --only-section=.text payload.o payload.bin
# 4. find the entry-point offset inside the blob
nm payload.o | grep ' T run'
# 5. generate a C array to embed in the host
xxd -i payload.bin
# standalone test (no host needed)
gcc -O2 -fno-stack-protector -DSTANDALONE -nostartfiles \
-std=c11 payload.c -o payload_test && ./payload_test- Most snippets are Linux-only due to specific kernel syscalls.
kqueue_timerandsandbox_pledge_unveilare BSD/macOS-only.- JIT snippets additionally require x86-64.
- Each file is intentionally isolated: no shared headers, no inter-file dependencies.
- Designed for experimentation, auditing, and reference — every syscall is checked, every resource released.
MIT