Using unsafe.Pointer to explore Linux system calls
summary
Shows concrete patterns for using unsafe.Pointer with Linux syscalls: uses x/sys/unix and ioctl to fetch a uint32 vmsock context ID, demonstrates reinterpreting memory like convert uint16 to [2]byte via unsafe.Pointer and mapping a 328‑byte taskstats blob directly to a struct, warns that missing size checks to avoid reading arbitrary memory leaks secrets, and emphasizes the rule to convert the pointer to uintptr inside the syscall call to prevent GC-moving and crashes.
AI-written summary · about
chapters (23)
- 0:00Introduction
- 0:50What is package unsafe
- 1:32What is a system call
- 2:37IOCTL system call example
- 3:18Prerequisites for unsafe system calls
- 3:38Go type safety explained
- 4:39Go types memory layout
- 5:40Slices and memory
- 6:21Endianness in Go
- 7:25Diving into package unsafe
- 8:07unsafe.Sizeof function
- 9:11unsafe.Pointer conversions
- 12:40Dangerous unsafe patterns
- 15:07Safe uses of unsafe
- 15:30System calls with syscall
- 16:55IOCTL in Go with syscall
- 17:58Garbage collector and pointers
- 18:40Native endianness detection
- 19:01Linux taskstats interface
- 20:03Performance with unsafe
- 20:45Other uses of unsafe
- 21:06Summary and responsibilities
- 21:52Q&A
related talks
01h 26mLinux User/Kernel ABI: the realities of how C and C++ programs really talk to the OS
25mSyscalls for Rustaceans
39mThe Beginner's Guide to Linux Syscalls
26mDesigning Syscalls for Extensibility
18mExploiting Uses of Uninitialized Stack Variables in Linux Kernels to Leak Kernel Pointers
05mDetecting Programs That Rely on Undefined Behavior
51mIntroduction to Memory Management in Linux
52mWelcome & Opening Remarks & Meaningful Bounds Checking in the Linux Kernel
