4 ms·
This is a long essay, and here is my pitch as to why you should read the whole thing if you have any interest in subjects like C programming, binary formats, ke
by spudlyo 2y ago
This is a long essay, and here is my pitch as to why you should read the whole thing if you have any interest in subjects like C programming, binary formats, kernel modules, or assembler.
Breadbox, the author, wants to make smaller binary executables. He explains about ELF binaries, a.out binaries, old MSDOS .COM binaries, and how the later had no metadata, and could be very small. He then explains how you can dynamically load code that deals with new executable binary formats into the Linux kernel, and how this process works. He walks through some sample C for building a "Hello World" kernel module. He then walks you through ~1 page of code for a kernel module that registers a new binary format, sets up some callbacks, and if conditions are right, will vm_mmap() the code into memory and call start_thread() on it.
Yay, it works! He has a tiny binary. This is where most articles would end, but Breadbox goes deeper. What if you want a stack and a heap? What if you want to access argc, argv, and envp? What if you want to append code at the end that automatically calls the exit syscall? All these details are covered, and I think it's glorious.
While this all may seem like pretty dry stuff, there is humor sprinkled throughout, which makes it more fun to read.
- out-of-ideas 2y agoi truly appreciate your tl;dr!
- RaoulP 2y agoAs did I. Would be great if this catches on!
- hoistbypetard 2y agoI really enjoyed reading it, and I hadn't seen it before. Thank you for sharing it here.
- klank 2y agoThanks for sharing, brought back memories of using debug.exe to meticulously type in hex copied from a magazine to generate a .com executable. Ah, the pre-internet was glorious.
- spudlyo 2y agoVery cool! I remember using debug.exe to write directly to 0xB0000 which was mapped my Hercules Monochrome card's video buffer. Rocking dual monitors in the late 80s was pretty cool. Later running the CodeView debugger TUI in your external monochrome monitor was quite a luxury.
- ryao 2y agoI had this itch once in college. I think I got down to a few thousand bytes. He has outdone my college attempt by orders of magnitude.