Understanding Forward Declarations in C

One of the best ways to learn systems programming is by reading real-world code. Recently, while reading the Linux kernel source, I noticed something interesting inside drivers/pinctrl/core.h: #include <linux/kref.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/radix-tree.h> #include <linux/types.h> #include <linux/pinctrl/machine.h> struct dentry; struct device; struct device_node; struct module; At first glance, these lines seem incomplete. We see declarations like struct device; but no actual definition. Where is the complete structure with all its members? Why didn’t file defining this structure isn’t included? ...

May 17, 2026 · 6 min · Ankit

C Memory Layout: Structs, Unions, and a Linux Kernel Patch

Overview C memory layout looks simple in isolation: structs store fields sequentially, unions overlap memory, and flexible array members allow variable-sized trailing storage. But combining these features can create subtle layout issues. While working on a Linux kernel selftest, I encountered a case where a union contained multiple structures, each ending with a flexible array member at different offsets. Although the code was functionally correct, this confused the compiler into treating the union as effectively variable-sized, triggering a layout warning. ...

May 4, 2026 · 11 min · Ankit

Build and Install Linux Kernel For Beaglebone Black

Overview The BeagleBone Black (BBB) uses an ARM Cortex-A8 32 bit processor, so the kernel must be cross-compiled on an x86 machine and then deployed to the board. This blog will assume that you already have a os[debian/ubuntu] installed on your sd card. We’ll: set up toolchain fetch kernel source configure for BBB build kernel + modules deploy to SD card / board 1. Prerequisites Make sure you have: Ubuntu (or any Linux host) Cross compiler for ARM (arm) Install required tools: ...

April 8, 2026 · 3 min · Ankit

Basics of debugging slab memory corruption via SLUB debug

Introduction Memory corruption can occur due to various bugs or defects: Uninitialized Memory Reads (UMR), Use After Free (UAF), Use After Return (UAR), double-free, memory leakage, or illegal Out Of Bounds (OOB) accesses that attempt to work upon (read/write/ execute) illegal memory regions. Since memory is dynamically allocated and freed via the kernel’s engine – the page allocator. This can lead to serious wastage (internal fragmentation) of memory. To mitigate this, the slab allocator (or slab cache) is layered upon it, serving two primary tasks – providing fragments of pages efficiently (within the kernel, allocation requests for small pieces of memory, from a few bytes to a couple of kilobytes), and serving as a cache for commonly used data structures. ...

February 4, 2026 · 7 min · Ankit

Linux Kernel Mentorship Program

Introduction I have been using Linux for the last two years and gradually developed an interest in systems programming and C. The mentorship prerequisites includes tasks like building and booting the Linux kernel, writing a basic kernel module, decoding stack traces, and modifying and booting a custom kernel build. Somehow, my application was accepted ;-). At first, the Linux Kernel seemed quite difficult to understand what was going on. We were initially told to choose two subsystems to work on. ...

December 8, 2025 · 3 min · Ankit