20
Pintos Project 2 User Programs September 28, 2016

Pintos Project 2 - USC Bitsbits.usc.edu/cs350/assignments/project2.pdfProject 2 must be put in a directory named “proj2” in your repository Implementation Project 2 will be done

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Pintos Project 2User Programs

September 28, 2016

Overview

What are user programs?

Anything you run on the command line:

~$ls~$git push~$./my_project arg1 arg2

User Kernel

Hey I wanna run this thing:~$/bin/ls -l foo bar

K cool. Imma setup the stack for you:

bfffffd0 00 00 00 00 | ....|bfffffd0 04 00 00 00 d8 ff ff bf-ed ff ff bf f5 ff ff bf |................|bfffffe0 f8 ff ff bf fc ff ff bf-00 00 00 00 00 00 62 69 |............./bi|bffffff0 6e 2f 6c 73 00 2d 6c 00-66 6f 6f 00 62 61 72 00 |n/ls.-l.foo.bar.|

Overview of Part 1: Setup Stack

User Kernel

Hey I wanna run this thing:<insert syscall here>I dun have the authority, so can you plz do it?

K. Let me try

Overview of Part 2: Syscalls

Dude you messed up, Imma give you a -1 so you know.

Ok cool, I can do this.Imma go do the thing.

Requirements

DirectoryProject 2 must be put in a directory named “proj2” in your repository

ImplementationProject 2 will be done in src/userprog/

This means you will run make in src/userprogThis means you will run tests in src/userprog/build

DesignDocProject 2 design document can be found in doc/userprog.tmplRename the design document as “DESIGNDOC” and place in src/userprog.

Failure to follow the naming & organization convention will result in deductions!!!

Due Dates

Project 2 Check (October 6th, no late days allowed)We will only check the argument tests (tests that begin with “args-”), which are the first 5 tests

Project 2 due date is October 23rd Both implementation and design document are due.

Overview

This project aims for you to implement the necessary features for user programs (the test programs) to request kernel functionality.

Part 1: Setup StackIn src/userprog/process.c, support the feature of parsing the user program’s filename and setup the stack correctly.

Part 2: System CallsImplement the required functions in src/userprog/syscall.h/c

Prerequisites

Setup proj2 DirectoryRe-copy & paste the pintos-base repository contents into a new directory named proj2

OR copy / paste your proj1 directory and rename it proj2

Keep Alarm ImplementationGo back to your project 1 and add in all the alarm code. You do NOT need priority donation implementation, just the alarm. You should pass all the alarm tests in src/threads except alarm-priority

Modify the Make.varsIn src/userprog/Make.vars, comment out:SIMULATOR=--qemu

Part 1Setup Stack

Setup Stack

Remember:

~$/bin/ls -l foo bar

argc = 4argv[0] = /bin/lsargv[1] = -largv[2] = fooargv[3] = bar

Your job is to setup the stack for the Pintos

Setup Stack~$/bin/ls -l foo barWill result in the following stack setup:

Address Name Data Type

0xbffffffc argv[3][…] “bar\0” char[4]

0xbffffff8 argv[2][…] “foo\0” char[4]

0xbffffff5 argv[1][…] “-l\0” char[3]

0xbfffffed argv[0][…] “/bin/ls\0” char[8]

0xbfffffec word-align 0 uint8_t

0xbfffffe8 argv[4] 0 char*

0xbfffffe4 argv[3] 0xbffffffc char*

0xbfffffe0 argv[2] 0xbffffff8 char*

0xbfffffdc argv[1] 0xbffffff5 char*

0xbfffffd8 argv[0] 0xbfffffed char*

0xbfffffd4 argv 0xbfffffd8 char**

0xbfffffd0 argc 4 int

0xbfffffcc return address 0 void(*)()

Address Name Data Type

0xbffffffc argv[3][…] “bar\0” char[4]

0xbffffff8 argv[2][…] “foo\0” char[4]

0xbffffff5 argv[1][…] “-l\0” char[3]

0xbfffffed argv[0][…] “/bin/ls\0” char[8]

0xbfffffec word-align 0 uint8_t

0xbfffffe8 argv[4] 0 char*

0xbfffffe4 argv[3] 0xbffffffc char*

0xbfffffe0 argv[2] 0xbffffff8 char*

0xbfffffdc argv[1] 0xbffffff5 char*

0xbfffffd8 argv[0] 0xbfffffed char*

0xbfffffd4 argv 0xbfffffd8 char**

0xbfffffd0 argc 4 int

0xbfffffcc return address 0 void(*)()

bfffffd0 00 00 00 00 | ....|bfffffd0 04 00 00 00 d8 ff ff bf-ed ff ff bf f5 ff ff bf |................|bfffffe0 f8 ff ff bf fc ff ff bf-00 00 00 00 00 00 62 69 |............./bi|bffffff0 6e 2f 6c 73 00 2d 6c 00-66 6f 6f 00 62 61 72 00 |n/ls.-l.foo.bar.|

Setup Stack

General steps should be:

1. Parse the argument by white spaces2. Write each argument (including \0) in reverse3. Word align to 4 bytes, write the word align4. Write four 0’s as last argument5. Write the addresses of each argument6. Write the address of argv7. Write argc8. Write a 0 for the return address

You’ll need to use a lot of memset and sizeof

Double check your setup stack is correct with hex_dump

Part 2System Calls

System Calls

When a user program wants to execute a command that only the kernel can do (eg. Write to a file), the following steps will occur:

• User program makes a request to the kernel• Kernel recieves a syscall interrupt• Kernel handles this interrupt

• If it’s valid, completes the request• If invalid, exit and return -1

System Calls

System calls are interrupts in Pintos, this is handled in src/userprog/syscall.h syscall_handler.

static void syscall_handler(struct intr_frame* f);

Using the intr_frame f, you’ll want to:1. Extract the program inputs from the pointer (f->esp)2. Validate the inputs

1. Cannot be NULL2. Cannot be kernel memory3. Cannot be unmapped memory4. Cannot be a bad pointer

3. Run the appropriate system call4. If there is a return value, store it in f->eax

System Calls

You have 13 system calls to implement: Halt, exit, exec, wait, create, remove, open, filesize, read, write, seek, tell, close

There are two types of syscalls you need to worry about:• Process Management

• Halt, exit, exec, wait• File System

• Create, remove, open, filesize, read, write, seek, tell, close

Make sure your syscall_handler can be extended to run more commands (project 3)

System Calls

File System are messy, but you have the libraries filesys/file.h and filesys/filesys.h to use for all your file system functions.

Each file has a file descriptor, an integer ID. File descriptor 0 and 1 are reserved for STDIN and STDOUT

Questions & Concerns?