Master the fundamental concepts of system calls & kernel interface through this focused micro-challenge.
Custom syscalls start in kernel space: assign a syscall number, implement SYSCALL_DEFINE handler, and expose via the syscall table. Userspace needs a wrapper or raw syscall() with the new NR.
Steps on x86_64:
syscalls.h / arch tablecopy_from_userFor example, a sys_hello returning a constant might use NR 467 on a teaching kernel while mainline Linux reserves official numbers centrally.
The SYSCALL_DEFINEx macro and syscall table registration you're documenting here is the real onboarding path the Linux kernel requires for every new syscall (io_uring and pidfd_open both went through this exact process), and it's also why kernel CVEs so often trace back to a missing copy_from_user bounds check on a new syscall's arguments. Once assigned, a syscall number is effectively permanent ABI , removing io_uring's early numbers would break every binary that already calls them.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will add a minimal syscall returning data to userspace and call it from a test program. This exercise requires discussing why unvalidated pointers from user mode are security bugs.
Document custom system call implementation.
Requirements:
Deliverable:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github