Linux Kernel Labs: a System Call, a Module and a /proc Clock

Three operating-systems labs on Linux 4.20.13 in a virtual machine. I added a system call and rebuilt and booted the kernel, wrote a loadable module, and wrote a module that reports the time through a /proc file.

Period
2026
Context
Linux operating systems course labs
Team
Individual project
My role
Sole author of the lab code and report
Status
Labs completed and reported
  • C
  • Linux 4.20 kernel
  • Kernel modules
  • procfs
  • GRUB
  • Ubuntu 18.04
  • VMware

Demo & artifacts

The walkthrough steps through each lab across the line between user space and the kernel, with the terminal and dmesg output the code produces. It is a model: no kernel code runs in your browser.

Walkthrough of the system-call lab with user-space and kernel-space lanes; an arrow crosses from the syscall instruction to entry_SYSCALL_64.
Diagram Step 3 of 7 in the system-call walkthrough. The syscall instruction has just switched to kernel mode, and entry_SYSCALL_64 saves the registers before the table lookup. A step-by-step model in the browser, not a kernel trace.

My contribution

  • Added system call 335, mycall: defined it with SYSCALL_DEFINE1 in kernel/sys.c, declared it, and registered __x64_sys_mycall in syscall_64.tbl. Then configured, compiled (make -j4), installed and booted the 4.20.13 kernel through GRUB, and called it from user space with syscall(335, 666).
  • Wrote a HelloWorld kernel module with module_init, module_exit and a GPL licence, built it with a Makefile that calls the kernel's build system, and loaded, listed and removed it with insmod, lsmod and rmmod.
  • Wrote a clock module that creates /proc/clock/my_clock on load and removes it on unload. Its read handler takes the time with do_gettimeofday and copies seconds and microseconds to user space with copy_to_user.

What the labs cover

The three labs follow one path into the kernel. The first changes the kernel itself: a new entry in the system-call table, a full kernel rebuild and a reboot into it. The second adds code to the running kernel as a module, with no rebuild. The third uses a module to give user programs a new file to read, the usual way for a kernel component to expose data.

The walkthrough follows each lab step by step. For the system call it traces the path from syscall(335, 666) through entry_SYSCALL_64 and the system-call table to the new function and back. For the clock it compares the lab’s test program with cat, with and without the fixed read handler.

Results & validation

  • The rebuilt kernel booted (uname -a showed 4.20.13); testcall printed 666 and dmesg showed the kernel's message.
  • The module and the clock module loaded and unloaded cleanly, with their messages in dmesg, and the clock's test program printed the time read from /proc.

The results come from the lab report and its screenshots. The labs were not re-run for this website.

Limitations & next steps

  • Reading the clock: the handler returns its text on every read, so the test program, which reads one line with fgets, prints the time once, and cat prints a fresh timestamp on each read until it is stopped. Returning end of file after the first read with simple_read_from_buffer, which also respects the reader's buffer size, would make it behave like other /proc files.
  • The new call is defined at the end of kernel/sys.c, next to the 32-bit compatibility calls. It builds because x86-64 configurations enable CONFIG_COMPAT; placing it above that block would make it independent of the option.
  • The echo test suits non-negative numbers: glibc's syscall() wrapper reports return values from −4095 to −1 as errors (−1 with errno set), and the argument is an int.
  • do_gettimeofday and struct timeval were removed from later kernels; on current kernels the handler would use ktime_get_real_ts64.