Mehdi Akiki

Posts tagged "from source to process"

  • Published on

    Investigation · Part 20 of 20 · From source to a running process

    What Happens When a Process Exits

    A line printed twice, output lost with _exit, a Drop that never runs, a zombie without memory. I followed the end of C and Rust processes with strace and /proc: stdio buffers, exit handlers, exit codes, exit_group, and what the kernel cleans up.
  • Published on

    Investigation · Part 19 of 20 · From source to a running process

    How Each Thread Gets Its Own Copy of a Variable: Thread-Local Storage

    One _Thread_local variable, four threads, four copies at four addresses, and one instruction to reach each of them. I followed the fs register, the TLS segment, the access models of the ELF TLS document, their cost, and Rust's thread_local! in the disassembly.
  • Published on

    Investigation · Part 18 of 20 · From source to a running process

    How a Stack Overflow Is Detected: Guard Pages and Signals

    A C program that overflows its stack dies without a word, a Rust program prints a message. I overflowed both on purpose, in the main thread and in a new thread, and followed the limit, the guard page, the SIGSEGV, the alternate signal stack and the abort.
  • Published on

    Investigation · Part 17 of 20 · From source to a running process

    What a System Call Costs, and Why Some Calls Skip the Kernel

    On a performance core of my laptop a function call costs 0.6 ns, getpid as a system call 81 ns, and clock_gettime 14 ns through the vDSO but 108 ns as a real system call. I measured both kinds of cores, counted the calls with strace and dumped the vDSO.
  • Published on

    Investigation · Part 16 of 20 · From source to a running process

    Why Freeing Memory Does Not Shrink Your Process

    I freed 999,000 of one million small blocks and the process did not become one kilobyte smaller. malloc_stats, strace and malloc_trim show why: the heap can only shrink from its top, glibc keeps the free pages, and threads multiply the arenas. Rust behaves the same.