Mehdi Akiki

Posts tagged "c"

  • Published on

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

    What fork Really Copies: Copy-on-Write Measured

    fork of a process with 2 GiB of touched memory took 16 ms here, because it copies page tables and not memory. I measured the copies that come later when the child writes, what reading costs, what happens to huge pages, and why posix_spawn stays under a millisecond.
  • Published on

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

    Why the First Touch of Memory Is Slow: Demand Paging Measured

    Mapping 1 GiB takes no time, the first write to each page costs about a microsecond, and the second write 16 nanoseconds. I measured faults with and without huge pages, MAP_POPULATE, calloc and Rust vectors, and twice the compiler removed the work I wanted to measure.
  • 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 · 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.