Weenix Operating System

A complete Unix-like operating system kernel for the x86_64 architecture, built as part of Brown's Operating Systems course (CSCI 1670/1690).

C x86 Assembly Systems Programming Kernel Development File Systems Virtual Memory

Note: Due to academic integrity policies, source code for this project cannot be publicly shared.

Overview

Weenix is a semester-long project that involves building a fully functional Unix-like operating system kernel from the ground up. Originally developed in 1998 and based on early Unix versions, Weenix has evolved to run on QEMU and supports the x86_64 architecture, incorporating modern OS concepts. This intensive project is renowned for its depth and is a cornerstone of Brown's Computer Science curriculum.

The kernel implements all the fundamental components of a modern operating system, providing hands-on experience with low-level systems programming and fostering a deep understanding of OS internals.

Implementation Phases

The project was completed in five major phases, each building upon the previous:

1. Processes & Threads (Procs)

Implemented the kernel's core concurrency mechanisms. Weenix processes have a single kernel thread, and there's no kernel-mode preemption; threads run until they explicitly yield.

  • Kernel thread creation, scheduling (FIFO run queue), and synchronization primitives (mutexes).
  • Process management including `fork()`, `exec()`-like behavior (`kernel_execve`), and `waitpid()` for process lifecycle control.
  • Context switching logic (core_switch provided, sched_switch implemented).

2. Device Drivers

Created drivers for hardware interaction, terminal I/O, disk access, and memory devices.

  • TTY (terminal) driver, including line discipline for input buffering and "cooking".
  • Keyboard and screen drivers.
  • SATA disk driver for block read/write operations.
  • Memory devices `/dev/null` (data sink) and `/dev/zero` (zero-byte source).

3. Virtual File System (VFS)

Built an abstraction layer to support multiple concrete file systems with a unified interface.

  • Implemented `vnode_t` (virtual inode) and `file_t` structures and their management, including reference counting.
  • Pathname-to-vnode resolution (e.g., `namev.c` functions).
  • Initial file system interaction using `ramfs` (an in-memory file system).
  • Generic system call interface for file operations (e.g., `do_open`, `do_read`).

4. System V File System (S5FS)

Developed a concrete on-disk file system based on the traditional System V layout.

  • Managed on-disk structures: superblock, inodes, data blocks.
  • Inode implementation including direct and a single indirect block pointer, supporting sparse files.
  • Directory file structure and operations.
  • Block allocation and free block list management.
  • Interfaced with the VFS layer and utilized kernel caching mechanisms (`mobj_t`, `pframe_t`) for disk I/O.

5. Virtual Memory (VM)

Implemented a complete virtual memory management system.

  • Page fault handling and demand paging.
  • Management of virtual memory areas (vmareas) within a process's memory map.
  • Anonymous memory objects (for stack, heap) and shadow objects (for copy-on-write).
  • Implementation of `fork()` with copy-on-write semantics.
  • System calls such as `mmap()`, `munmap()`, and `brk()`.

Technical Achievements

>5,000

Lines of C code written

100%

Test suite pass rate

4 months

Development timeline

POSIX-like

Implementation of key system calls

Key Challenges & Learning

Building an OS presented unique challenges that deepened my systems programming expertise:

  • Debugging at the kernel level: Developed skills in using GDB for kernel debugging without standard debugging tools.
  • Race conditions & Synchronization: Mastered synchronization primitives and lock ordering to prevent deadlocks in a non-preemptive kernel.
  • Memory management: Gained deep understanding of virtual memory, page tables, TLB management, and copy-on-write mechanisms.
  • File System Internals: Learned intricate details of on-disk file system structures (S5FS) and VFS abstractions.
  • System architecture: Learned to design clean interfaces between kernel subsystems.

Skills Developed

This project provided invaluable experience in:

  • Low-level C programming and x86 assembly
  • Concurrent programming and synchronization in a kernel context
  • Memory management: virtual memory systems, paging, anonymous/shadow objects
  • File system design: VFS principles and on-disk S5FS implementation
  • Hardware/software interface and interrupt handling
  • Debugging complex systems-level code with tools like GDB
  • Reading and understanding large C codebases

Impact

Completing Weenix gave me a comprehensive understanding of operating system internals that has proven invaluable in my career. The project's emphasis on building robust, efficient systems code has influenced my approach to software engineering, particularly in performance-critical applications and when working close to the hardware.

Previous Project

Deepfake Detection CNN