Task: System Calls
Enter the chapters/software-stack/system-calls/drills/tasks/basic-syscall/ folder. Run make and then enter chapters/software-stack/system-calls/drills/tasks/basic-syscall/support/ folder and go through the practice items below.
For debugging, use strace to trace the system calls from your program and make sure the arguments are set right.
-
Update the
hello.asmand / orhello.sfiles to print bothHello, world!andBye, world!. This means adding anotherwrite()system call. -
Update the
hello.asmand / orhello.sfiles to sleep before theexitsystem call.You need to make the
sys_nanosleep()system call, with thetimespecstructure. Find its ID here. -
Update the
hello.asmand / orhello.sfiles to read a message from standard input and print it to standard output.You’ll need to define a buffer in the
dataorbsssection. Use thereadsystem call to read data in the buffer. The return value ofread(placed in theraxregister) is the number of bytes read. Use that value as the 3rd argument orwrite, i.e. the number of bytes printed.Find the ID of the
readsystem call here. To find out more about its arguments, see its man page. Standard input descriptor is0. -
Difficult: Port the initial program to ARM on 64 bits (also called aarch64).
Use the skeleton files in the
arm/folder. Find information about theaarch64system calls here. -
Create your own program, written in assembly, doing some system calls you want to learn more about. Some system calls you could try:
open(),rename(),mkdir(). Create a Makefile for that program. Run the resulting program withstraceto see the actual system calls being made (and their arguments).
If you’re having difficulties solving this exercise, go through this reading material.