Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CSE 421/521 – Operating Systems
1. Preparation
Before beginning your work, please read the following carefully:
● Chapters 8-9 from Silberschatz (9
th edition)
● Lecture slides on Memory and Virtual Memory
● Pintos Introduction
● Pintos Reference Guide
● Complete Pintos Documentation (PDF file) -- for reference only
2. Task: Implement the User Programs of Pintos OS
In this project, you are asked to perform “kernel” level programming of the “User
Programs” component in the Pintos operating system. The base code already supports loading
and running user programs, but no I/O or interactivity is possible. In this project, you will enable
programs to interact with the OS via system calls.
Before beginning this assignment, make sure you read these sections from Pintos
Reference Guide: section A.1 Pintos Loading, A.2 Threads, A.3 Synchronization, A.4 Interrupt
Handling, A.5 Memory Allocation, A.6 Virtual Addresses, and Appendix E (Debugging Tools).
Page: 1/19
3. Setting Up The Pintos Environment
Project-2 does not depend on project-1. No code from project-1 is required for this
assignment. So, we suggest that you fetch a clean copy of the Pintos source code.
We have prepared a Virtual Machine image of Pintos which will make the
installation/configuration process much simpler for you. This will enable you to develop your
pintos project on any Linux, Windows, or Mac system (i.e. your own machine) without much
hassle. You can also download the VM image from:
https://buffalo.box.com/s/erdn4wnde8fmyzk3y36lln4cxot4y649
http://ftp.cse.buffalo.edu/CSE421/UB-pintos.ova
After downloading the file, verify the integrity of the file by comparing the md5 hash of the
downloaded file with:
ecf501c3494f741f6d56f7ebe6064beb
You will need VirtualBox software for your host OS to run this VM. You can download
VirtualBox at the following link:
https://www.virtualbox.org/wiki/Downloads
For the detailed instruction on how to setup this VM on your host OS, please see the
"Environment Setup" on Piazza:
http://www.piazza.com/class_profile/get_resource/jqh89ng55by1rd/jrr0l4wxmog6h5
In VirtualBox software, from the File menu, choose "Import Appliance" and point to the
downloaded "UB-pintos.ova". You do not need to change any other settings for this procedure.
Choose UB-Pintos from the left pane, and click on "Start", your virtual machine should now
boot. Here is the login information if needed:
Username: os-class
Password: os-class
To learn how to run, debug and test Pintos code, please read the Pintos Introduction.
Page: 2/19
4. Implementation of the Project
You will be working primarily in the “userprog” directory of the source tree for this
assignment. Compilation should be done in the “userprog” directory.
4.1 Background
Up to now, all of the code you have run under Pintos has been part of the operating
system kernel. This means, for example, that all the test code from the last assignment ran as part
of the kernel, with full access to privileged parts of the system. Once we start running user
programs on top of the operating system, this is no longer true. This project deals with the
consequences.
We allow more than one process to run at a time. Each process has one thread
(multi-threaded processes are not supported). User programs are written under the illusion that
they have the entire machine. This means that when you load and run multiple processes at a
time, you must manage memory, scheduling, and other state correctly to maintain this illusion.
In the previous project, we compiled our test code directly into your kernel, so we had to
require specific function interfaces within the kernel. From now on, we will test your operating
system by running user programs. This gives you much greater freedom. You must make sure that
the user program interface meets the specifications described here, but given that constraint you
are free to restructure or rewrite kernel code however you wish.
4.2 Source Files
The easiest way to get an overview of the programming you will be doing is to simply go
over each part you'll be working with. In `userprog', you'll find a small number of files, but here is
where the bulk of your work will be:
`process.c'
`process.h'
Loads ELF binaries and starts processes.
`pagedir.c'
`pagedir.h'
A simple manager for 80x86 hardware page tables. Although you probably won't want to
modify this code for this project, you may want to call some of its functions. See Section 4.1.2.3
[Page Tables] from Pintos Manual, for more information.
`syscall.c'
`syscall.h'
Whenever a user process wants to access some kernel functionality, it invokes a system
call. This is a skeleton system call handler. Currently, it just prints a message and terminates the
user process. In part 2 of this project you will add code to do everything else needed by system
calls.
`exception.c'
Page: 3/19
`exception.h'
When a user process performs a privileged or prohibited operation, it traps into the kernel
as an “exception" or “fault." These files handle exceptions. Currently all exceptions simply print
1
a message and terminate the process. Some, but not all, solutions to project 2 require modifying
page_fault() in this file.
`gdt.c'
`gdt.h'
The 80x86 is a segmented architecture. The Global Descriptor Table (GDT) is a table that
describes the segments in use. These files set up the GDT. You should not need to modify these
files for any of the projects. You can read the code if you're interested in how the GDT works.
`tss.c'
`tss.h'
The Task-State Segment (TSS) is used for 80x86 architectural task switching. Pintos uses
the TSS only for switching stacks when a user process enters an interrupt handler, as does Linux.
You should not need to modify these files for any of the projects. You can read the code if you're
interested in how the TSS works.
4.3 Using the File System
You will need to interface to the file system code for this project, because user programs
are loaded from the file system and many of the system calls you must implement deal with the
file system. However, the focus of this project is not the file system, so we have provided a
simple but complete file system in the `filesys' directory. You will want to look over the
`filesys.h' and `file.h' interfaces to understand how to use the file system, and especially its many
limitations.
There is no need to modify the file system code for this project, and so we recommend
that you do not. Working on the file system is likely to distract you from this project's focus.
You will have to tolerate the following limitations of the file system:
● No internal synchronization. Concurrent accesses will interfere with one another. You
should use synchronization to ensure that only one process at a time is executing file
system code.
● File size is fixed at creation time. The root directory is represented as a file, so the
number of files that may be created is also limited.
● File data is allocated as a single extent, that is, data in a single file must occupy a
contiguous range of sectors on disk. External fragmentation can therefore become a
serious problem as a file system is used over time.
● No subdirectories.
● File names are limited to 14 characters.
● A system crash mid-operation may corrupt the disk in a way that cannot be repaired
1 We will treat these terms as synonyms. There is no standard distinction between them, although Intel processor
manuals make a minor distinction between them on 80x86.
Page: 4/19
automatically. There is no file system repair tool anyway.
One important feature is included:
● Unix-like semantics for filesys_remove() are implemented. That is, if a file is open when
it is removed, its blocks are not deallocated and it may still be accessed by any threads
that have it open, until the last one closes it. See Section 3.4.2 FAQ [Removing an Open
File] from Pintos Manual for more information.
You need to be able to create a simulated disk with a file system partition. The
pintos-mkdisk program provides this functionality. From the `userprog/build' directory, execute
pintos-mkdisk filesys.dsk --filesys-size=2. This command creates a simulated disk named
`filesys.dsk' that contains a 2 MB Pintos file system partition. Then format the file system
partition by passing `-f -q' on the kernel's command line: pintos -f -q. The `-f' option causes the
file system to be formatted, and `-q' causes Pintos to exit as soon as the format is done.
You'll need a way to copy files in and out of the simulated file system. The pintos `-p'
(“put") and `-g' (“get") options do this. To copy `file' into the Pintos file system, use the command
`pintos -p file -- -q'. (The `--' is needed because `-p' is for the pintos script, not for the simulated
kernel.) To copy it to the Pintos file system under the name `newname', add `-a newname': `pintos
-p file -a newname -- -q'. The commands for copying files out of a VM are similar, but substitute
`-g' for `-p'.
Incidentally, these commands work by passing special commands extract and append on
the kernel's command line and copying to and from a special simulated “scratch" partition. If
you're very curious, you can look at the pintos script as well as `filesys/fsutil.c' to learn the
implementation details.
Here's a summary of how to create a disk with a file system partition, format the file
system, copy the echo program into the new disk, and then run echo, passing argument x.
(Argument passing won't work until you implemented it.) It assumes that you've already built the
examples in `examples' and that the current directory is `userprog/build':
pintos-mkdisk filesys.dsk --filesys-size=2
pintos -f -q
pintos -p ../../examples/echo -a echo -- -q
pintos -q run 'echo x'
The three final steps can actually be combined into a single command:
pintos-mkdisk filesys.dsk --filesys-size=2
pintos -p ../../examples/echo -a echo -- -f -q run 'echo x'
If you don't want to keep the file system disk around for later use or inspection, you can
even combine all four steps into a single command. The --filesys-size=n option creates a
temporary file system partition approximately n megabytes in size just for the duration of the
pintos run. The Pintos automatic test suite makes extensive use of this syntax:
pintos --filesys-size=2 -p ../../examples/echo -a echo -- -f -q run 'echo x'
You can delete a file from the Pintos file system using the rm file kernel action, e.g.
pintos -q rm file. Also, ls lists the files in the file system and cat file prints a file's contents to the
display.