Mehdi Akiki

Posts tagged "linux"

  • Published on

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

    Reading /proc/self/maps Line by Line

    I printed the memory map of a small C program and of a Rust program and explained every column and every line, then watched the addresses move with ASLR, stop moving with setarch -R, and go back to 0x400000 with -no-pie.
  • Published on

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

    What Is on the Stack When a Process Starts: argv, envp and auxv

    Before the first instruction, the kernel writes argc, argv, envp and 22 pairs of numbers for the loader at the top of the stack. I read them from a C program, compared them with LD_SHOW_AUXV, and saw 4,000 bytes of environment move every local variable of main.
  • Published on

    Investigation · Part 10 of 20 · When the benchmark lies

    Which Clock to Use When You Measure Time

    I measured eight of the clocks that clock_gettime can read, and on my laptop two of them disagreed by 43,257 ns after 20 seconds. I measured their resolution, their cost, which ones enter the kernel, and which clocks Rust and Python use.
  • Published on

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

    The Code That Runs Before main: _start, Constructors and init_array

    With gdb I followed what calls main, where constructors are called from, and in which order init_array and fini_array run. A program without libc starts in 56 microseconds instead of 143, and Rust std has its own function in init_array.
  • Published on

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

    How LD_PRELOAD Replaces a Function Without Recompiling

    I wrote a small library that counts malloc calls and preloaded it into C, Rust and ls. The famous dlsym trap did not appear with glibc 2.43, but ls hid my output in a way I did not expect, and the static binary ignored the library completely.