Articles on C

Last updated: 2022/09/26

Top deep-dives on C

Stop checking for NULL pointers!

When working with a lower level language like C, it is easy to cause problems that might make your whole program or system crash. So intuitively, you'd think we'd want checks to make sure these problems don't occur in the code we right. However,  in this article, Elad Lahav discusses how checking for one of such cases is actually detrimental in that it might lead to a false sense of security.

Build Your Own Text Editor

"This booklet walks you through building the editor in 184 steps" in C.

Defensive Programming - Friend or Foe?

Bugs are the bane of most software. It's especially bad when they cause the software to go into some unexpected or undefined state. In this article, Tyler Hoffman describes a more proactive and aggressive approach to catching and reporting bugs in embedded systems, compared to merely making sure bugs don't cause complete crashes.

malloc as a service

Linear Algebra Shenanigans: Gizmo Repair

Spotting problems and debugging them is as important in programming (if not more) as is writing the code in the first place. Obviously it would be better to not write buggy code in the first place, but sometimes that's out of your control. Fortunately Karl Zylinski has written an article about spotting an issue, narrowing down the problem space, adding visuals to help debug, and the ultimate solution, all for a game engine written in C.

Making Mass Effect not require administrator rights, or maybe how to not write a boolean check

Unfortunately I never got into modding video games (I wish I had, would've been fun), but that doesn't make me appreciate any less what what those devs do. Especially when you see some of the stuff they have to root around in. In this lengthy article, the author takes us along on a quest to discover the source of a register value issue triggering an unwanted action in a PC port of Mass Effect.

Writing a "bare metal" operating system for Raspberry Pi 4

Have you ever wanted to build an OS from scratch? No? Well that doesn't matter, because you can just read this series of interactive articles by Adam Greenwood-Byrne. Although shrouded in the guise of a tutorial, it's by no means a how-to, and Adam covers everything from bootstrapping to WordUp Graphics, all the while littering gems of knowledge along the way.

Writing a simple 16 bit VM in less than 125 lines of C

Title really says it all. Andrei Ciobanu starts with the basics of what a virtual machine is covers every step in the journey of implementing one.

Implementing Hash Tables in C

Really, the title says it all. Is this extensive article by Andrei Ciobanu something your college professor would recommend? Probably. Does that make it any worse? Not really. Andre briefly covers hash functions, then begins taking apart the implementation of the hash table, starting with separate chaining. The article is still in draft form, but has good info, and gives you an opportunity to make comments on improvements/additions!

Let's write a compiler, part 1: Introduction, selecting a language, and doing some planning

Want to write your own compiler? Well I bet Brian Robert Callahan's seroes can help. In this first part, Brian sets out the specifications for what the compiler is going to be able to do, what language to implement it in, and lays out a couple of diagrams for the overall process flow for the compiler.

On finding the average of two unsigned integers without overflow

Raymond Chen demonstrates how to average big numbers without breaking everything.

Program in Arm6 assembly language on a Raspberry Pi

"Assembly language is the symbolic language immediately above machine code and thereby offers special insights into how machines work and how they can be programmed efficiently". You also need to be a very special kind of person to want to program in it. If you are, Marty Kalin has written an article on load-store machines, writing the hstone program in C, assembly language basics, writing the hstone program again but in Arm6 assembly, and basically getting it all to run.

Code memory safety and efficiency by example

Memory leaks lead to a death by a thousand cuts for a program. The topic also always brings me back my first C++ course in college (shudder). But it's about time we stop letting amazing hardware make up for our poor programming! In this extensive article, Marty Kalin gives an overview of memory for executing C programs, nested heap allocation, memory leakage and heap fragmentation, and static area storage.

Chain loading, not preloading: the dynamic linker as a virtualization vector

Executable and Linkable Format (ELF), is a common standard file format for executable files, object code, shared libraries, and core dumps. In this technical article, Dr Stephen Kell shows how to "run a pre-existing binary program but in some kind of instrumented or modified form" using "ELF-level trickery", which essentially means writing a dynamic linker rather than using LD_PRELOAD.

Introduction to ARM Semihosting

It's been a while since I've gotten down and dirty with microcontrollers, but I remember many a long hour debugging errors with terrible logs and information, because it wasn't trivial to determine what the microcontroller was actually doing. Fortunately it looks like with ARM microcontrollers, you can run some additional C code with the help of a built in feature. Amine El Messaoudi's article introduces this feature, and demonstrates how you can get it running.

Untangling Lifetimes: The Arena Allocator

Ryan Fleury illuminates his dislike of how it's the norm for everyone to be taught to stay away from manual memory management in C. Ryan argues that this way of thinking is nonsensical and that it's not necessary to introduce "automatic reference counting, RAII, and/or garbage collectors" as alternatives when there are simpler solutions, like the arena allocator. <br>Some highlights: <ul> <li>Malloc and free should rarely become the defacto memory management interfaces for a codebase</li> <li>Memory leaks are "erased" when the program that created them errors or crashes</li> <li>No easy way to mass free all mallocs relating to something</li> <li>The general gist of the arena allocator is to use independent stacks to bucket memory allocations together</li> </ul>

Leveraging LD_AUDIT to Beat the Traditional Linux Library Preloading Technique

Windows gets a lot of crap (*cough* neckbeards *cough*) for being a breeding cesspool of vulnerabilities and their respective viruses, but Linux has its own vulnerabilities too. What are these you ask? Well Lior Ribak has written an interesting article that explores on such vulnerability. Lior discusses how using an uncommon 'feature of the dynamic linker/loader' to force all ' dynamic executables in [the] environment' to load a shared library can be defended against by another similar feature, that can be forced to load even earlier. Lior also goes into the offensive uses.

Finding Number Related Memory Corruption Vulns

"The root cause of many vulnerabilities are from the mishandling of numbers". Understandably so; how many of you actively think about the vulnerabilities of your code as you write it (excluding the high level topics like user sessions, etc)? Maxwell Dulin's article explores the different issues that might arise from using numbers in C, how you can spot them before they become truly costly.

The wild west of Windows command line parsing

Chris Wellons illuminates the weirdness (read outdatedness) of the Windows runtime's command line argument passing.

My Own Private Binary

How far would you go to make the smallest executable possible? Would you write your own kernel module? No? Well that's what Brian Raiter did, and now has written an article about it. In it, Brian demonstrates all of the necessary steps to get your kernel accepting a nonstandard Linux binary format.

C Structure Padding Initialization

Noah Pendleton dives into C structure padding, explaining what it is, the current state of it, best practices, and the future.

Page Fault Injection in Virtual Machines: Accessing Swapped-Out Pages from HVMI

Andrei Lutas discusses how page fault injection allows Hyper Memory Introspection to analyze normally unreachable guest memory that has been swapped-out of physical memory.

That is not a number, that is a freed object

Siddhesh Poyarekar explains how a common approach to pointer reallocation incorrectly breaks function fortification.

Fast CSV processing with SIMD

If you’re working with csv data using standard UNIX tools like awk, sed, sort, etc. then you might run into issues with embedded commas and newlines being incorrectly interpreted as separators. In this concise article, Chris Wellons demonstrates his own optimized implementation of a library that helps you handle these issues and explains how he went about optimizing it.

Racing the Hardware: 8-bit Division

Nima Badizadegan shows how division on the CPU can be accelerated using software to almost match hardware acceleration components.

My take on "where's all the code"

Chris Wellons discusses some of the design choices and interesting aspects of implementing his own program in C that counts the lines of code in each part of a source tree.

Porting Doom to Helios

Drew DeVault ports DOOM to the Helios microkernel.

Luhn algorithm using SWAR and SIMD

Chris Wellons implements the algorithm for checking credit card numbers in parallel using "SIMD within a register".

What's the Most Portable Way to Include Binary Blobs in an Executable?

Laurence Tratt elaborates on the nuances of having blobs in cross platform executables.

Linux in a Pixel Shader - A RISC-V Emulator for VRChat

This has been around for a bit, but thought it was still worth putting in here. You ever wanted to run Linux in VR chat? Like have it running right there in front of your eyes in your GPU? No? We'll you're clearly not a dreamer like Stefan. In this informative article, Stefan goes through the ins and outs of what it took to get CPU emulator with Linux running in VR chat.

Je Ne Sais Quoi - Falcons over the Horizon

"Falcon stands for FAst Logic CONtroller and is a proprietary microprocessor developed by Nvidia". Its first use was in GPUs from the G98 series, but has since been repurposed and reused for other series too. Mike Heskin and Michael have written a super in-depth article on hacking the Falcon. It really has everything you'd want to know, so check it out.

Want to see more in-depth content?

subscribe to my newsletter!

Other Articles