Tasks
The same steps as the lab slide. Do them on a Linux PC with the files from the zip; the tools below help you check your thinking first.
Lab 9 · System Calls
- TODO 1 in nolibc_starter.c: write my_syscall3 with inline assembly (syscall; rax, rdi, rsi, rdx; rcx and r11 change)
- TODO 2: the numbers of write, getpid, exit from unistd_64.h
- TODO 3: put_num: print a number without printf. TODO 4: argc and argv from the stack
- Run strace ./nolibc hello; compare with the libsys quiz: why so many writes?
- Run ./syscost on the lab PC; fill the table; explain the vDSO line
the finished nolibc (real)
$ ./nolibc hello world; echo $?
my PID is 417
argc = 3
argv: hello
argv: world
write(42, ...) returned -9 (the
kernel returns -errno; 9 = EBADF)
3
$ strace ./nolibc hello
execve("./nolibc", …) = 0
write(1, "my PID is ", 10) = 10
getpid() = 390
write(1, "390", 3) = 3 …
write(42, "x", 1) = -1 EBADF
exit(2) = ?
Before TODO 1: the starter prints nothing and dies with "Illegal instruction" (exit status 132 = 128 + 4, SIGILL): exit never reached the kernel. strace shows every call as syscall_0x3e8 … = -1 ENOSYS.
Try it here
These run in your browser, with no server and no internet. They are built from the same reference programs as the lab, so their output matches what your finished C program should print. They do not replace the real lab: the kernel, gcc and your own code are the point.
Read the files
Every text file from lab09_files.zip. Read here, then download the zip to work on them.