Articles tagged #rust

In the bowels of glibc

Good morning, and welcome back to "how many executables can we run with our custom dynamic loader before things get really out of control".

In Part 13, we "implemented" thread-local storage. I'm using scare quotes because, well, we spent most of the article blabbering about Addressing Memory Through The Ages, And Other Fun Tidbits.

we
Making our own executable packer

In this series, we'll attempt to understand how Linux executables are organized, how they are executed, and how to make a program that takes an executable fresh off the linker and compresses it - just because we can.

Running glibc applications

In the last article, we implemented thread-local storage.

Well, some of it. We didn't actually bother supporting any kind of threading, so, if we try to load and execute a multithreaded program

Shell session
$ cargo b -q && gdb --args ./target/debug/elk run /bin/ls
(gdb) break jmp
Breakpoint 1 at 0x47e02: file src/process.rs, line 819.
(gdb) r
Starting program: /home/amos/ftl/elk/target/debug/elk run /bin/ls
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Loading "/usr/bin/ls"
Loading "/usr/lib/libcap.so.2.33"
Loading "/usr/lib/libc-2.31.so"
Loading "/usr/lib/ld-2.31.so"

Breakpoint 1, elk::process::jmp (
    entry_point=0x7ffff7faab20 "\363\017\036\372\061\355I\211\321^H\211\342H\203\344\360PTL\215\005f\030\001\000",
    stack_contents=0x5555557150a0, qword_count=94) at src/process.rs:819
819         asm!(
(gdb) autosym
add symbol table from file "/home/amos/ftl/elk/target/debug/elk" at
        .text_addr = 0x555555565160
add symbol table from file "/usr/lib/ld-2.31.so" at
        .text_addr = 0x7ffff7a94100
add symbol table from file "/usr/lib/libc-2.31.so" at
        .text_addr = 0x7ffff7ba6630
add symbol table from file "/usr/lib/libgcc_s.so.1" at
        .text_addr = 0x7ffff7d8d020
add symbol table from file "/usr/lib/libpthread-2.31.so" at
        .text_addr = 0x7ffff7dabad0
add symbol table from file "/usr/lib/libdl-2.31.so" at
        .text_addr = 0x7ffff7dc7210
add symbol table from file "/usr/lib/libc-2.31.so" at
        .text_addr = 0x7ffff7df0630
add symbol table from file "/usr/lib/libcap.so.2.33" at
        .text_addr = 0x7ffff7f9e020
add symbol table from file "/usr/bin/ls" at
        .text_addr = 0x7ffff7fa9040
add symbol table from file "/usr/lib/ld-2.31.so" at
        .text_addr = 0x7ffff7fd3100
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
Day 14 (Advent of Code 2020)

It's time for the Day 14 problem!

After the hassle that was Day 13, I hope this time we'll have a relatively chill time. And, at least for Part 1, that is true.

Our input looks something like this:

mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0

mem is our memory. Our addresses are 36-bit wide, but as you'll see, that doesn't matter much.

Day 13 (Advent of Code 2020)

In the Day 13 problem, we're trying to take the bus.

Our input looks like this:

939
7,13,x,x,59,x,31,19

The first line indicates the earliest minute we can leave from the bus terminal, and the second line indicates the "identifier" of the buses that are active.

Each bus departs every "bus ID" minutes - bus 7 leaves at minute 0, minute 7, minute 14, minute 21, etc. The question is: which bus can we take first (apparently they either all go to the same destination, or we don't really care where we're going), and how long do we have to wait for it?

Day 12 (Advent of Code 2020)

Time for the Day 12 problem!

In this problem, we have a ship. And we have navigation instructions:

  • Action N means to move north by the given value.
  • Action S means to move south by the given value.
  • Action E means to move east by the given value.
  • Action W means to move west by the given value.
  • Action L means to turn left the given number of degrees.
  • Action means to turn the given number of degrees.
Day 11 (Advent of Code 2020)

Another day, another problem.

This time the problem looks suspiciously like Conway's Game of Life, or, I guess, any old Cellular automaton.

We have a map like so:

L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL

And for each iteration:

  • L symbols turn into # if there's no # in any of the 8 adjacent cells
Day 10 (Advent of Code 2020)
Bear

Day, 10! Day, 10!

Okay, Day 10.

Again, the problem statement is very confusing - but what it all boils down to is this. We have a list of numbers:

16
10
15
5
1
11
7
19
6
12
4

To which we need to add 0 and whatever the maximum was, plus three:

16
10
15
5
1
11
7
19
6
12
4
0
22

From there on, if we take them in order, we'll have gaps of 1 and gaps of 3:

Go back to the homepage.