Ancient CS 61 Content Warning!!!!!1!!!
This is not the current version of the class.
This site was automatically translated from a wiki. The translation may have introduced mistakes (and the content might have been wrong to begin with).

10/27: Weensy Memory-Mapped I/O

This exercise aims to teach you about system call implementation, argument checking, and memory mapping in an operating system kernel.

Check out the kernel3x directory of your cs61-exercises repository (you’ll need to pull first). This directory contains a tiny operating system built around a ramdisk, which is a model of a normal operating system’s buffer cache. The ramdisk is stored in kernel memory in the ramdisk character array. The kernel first fills the initial portion of the ramdisk with some data. Then the p-reader process repeatedly reads from the ramdisk by calling the sys_read system call and prints what it finds.

Enter your answers here

Part 0

Look at the code, particularly p-reader.c, and understand how it works.

Note: This weensy OS has kernel isolation (the kernel’s memory is protected from processes by the page table), but not full process isolation (all processes share the same page table, kernel_pagetable).

Part 1: Write system call

Uncomment the body of p-writer.c. Now your kernel will fail to compile, because the sys_write system call is missing. So add it!

When you’re done, the output of p-reader should eventually become all “61”.

Enter your answers on the survey

Part 2: System call checking

Our implementation of sys_read doesn’t check its arguments. As a result, a process can kill the kernel by calling sys_read (and likely sys_write too).

First, verify this: change either p-reader or p-writer to kill the kernel (the OS should crash in some way).

Second, fix it: change sys_read and sys_write to validate their arguments to provide kernel isolation. A full check will involve some arithmetic and some calls to virtual_memory_lookup.

Enter your answers on the survey

Part 3: Memory mapping

Uncomment the body of p-mapreader.c. Now your kernel will fail to compile, because the sys_mmap system call is missing. So add it!

When you’re done, your output should alternate between read and mapread lines, each printing the same thing (and both gradually becoming all “61”).

Enter your answers on the survey

Part 4: Memory mapping for writes

Uncomment the body of p-mapwriter.c, and re-comment the body of p-writer.c. Then add support for read/write memory mapping!

When you’re done, the read and mapread lines should gradually become all “61”, because p-mapwriter is writing into the ramdisk.

Enter your answers on the survey

Solution video