Skip to content
0:00 / 0:00

#assembly#syscalls#libc

Rewriting "sleep" from scratch - no libraries, not even libc - only syscalls and some assembly magic

Valigo

12K subscribers • 1 video on Hallway

YouTube

Advanced. Deep dive for people who know the field.

166K views10 months ago2 recommendations

Systems programmingProgramming languagesCOperating systemsConcurrency and parallelism

How to implement the sleep utility in C from scratch using raw Linux system calls and inline assembly.

Let's rewrite "sleep" program absolutely from scrath - not even with libc. Only the compiler, the kernel, and a magic of inline assembly! Let me know if this kind of long-form video is something you like. Sources: the code: github.com/valignatev/sleep-from-scratch That tweet: x.com/valigo_gg/status/1994169596929024103 GCC inline assembly howto: ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#toc6 System V Application Binary Interface: raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/x86-64-ps… GCC Manual: gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html

Why it's here

2 people recommend this

What people say. Recommended for learning how to write C code without standard libraries by interacting directly with the kernel.

u/Ancient_Telephone_50in r/C_Programming • Recommends

On “What functionality is available in C without including any headers?”

link to this video There is this video where he writes the function sleep() without any libraries, its a bit long but you learn interesting things

u/gogok10in r/C_Programming • Recommends

On “correct me if im wrong but C is "memory safe" if you ensure to handle...stuff that takes up memeory...in a safe manner, right?”

You can write C code without libc, it's just a big headache managing the stack. Here's a cool link to this video of a guy writing sleep() from scratch