Christo Wilson Project 2: User Programs in Pintos

Slides:



Advertisements
Similar presentations
Process Management.
Advertisements

Project 5: Virtual Memory
CS 140 Project 3 Virtual Memory
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Operating Systems Lecture 7.
Project 1 – My Shell Let’s get started… Alex Milenkovich.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CSCC69: Operating Systems
1 Pintos Project #3 Virtual Memory The following slides were created by Xiaomo Liu and others for CS 3204 Fall And Modified by Nick Ryan for Spring.
Chapter 6 Limited Direct Execution
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Jaishankar Sundararaman
CS 4284 Systems Capstone Project 2 Hints Slides created by Jaishankar Sundararaman.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CSE 451 Section 4 Project 2 Design Considerations.
Christo Wilson Project 3: Virtual Memory in Pintos
Christo Wilson Project 4: File System in Pintos
1 User-Level Processes Needed to test the system call you implement The “Noff” format file required –Look at the Makefile in test MIPS “syscall” instruction.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Creating and Executing Processes
Project 2: User Programs
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Project 2: Initial Implementation Notes Tao Yang.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
Process Management Azzam Mourad COEN 346.
Functions/Methods in Assembly
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation.
Project 2: User Programs Presented by Min Li 26 Feb 2009.
Lecture 5 Page 1 CS 111 Online Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command.
CSE120 Discussion 5 Xinxin Jin. Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level.
Introduction to Operating Systems
Jaishankar Sundararaman
Protection of System Resources
Linux Processes & Threads
Unix Process Management
Processes in Unix, Linux, and Windows
Introduction to Operating Systems
Processes in Unix, Linux, and Windows
System Structure and Process Model
Discussions on HW2 Objectives
Operation System Program 1
Discussions on HW2 Objectives
Virtual Memory: Systems CSCI 380: Operating Systems
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Presentation transcript:

Christo Wilson Project 2: User Programs in Pintos 8/22/2012 CS 5600 Computer Systems Project 2: User Programs in Pintos Defense

User Programs in Pintos Pintos already implements a basic program loader Can parse ELF executables and start them as a process with one thread Loaded programs can be executed But this system has problems: User processes crash immediately :( System calls have not been implemented

Your Goals Implement argument passing Implement the Pintos system APIs Example: “ls” sort of works … but “ls –l –a” doesn’t work You must pass argv and argc to user programs Implement the Pintos system APIs Process management: exec(), wait(), exit() OS shutdown: halt() File I/O: open(), read(), write(), close() Can be used for writing to the screen (write stdout) … and reading from the keyboard (read stdin)

Formatting the File System In this project, you will be running user programs within Pintos Thus, you must format a file system to store these user programs on $ pintos-mkdisk filesys.dsk --filesys-size=2 $ pintos -p ../../examples/echo -a echo -- -f -q run 'echo x' Total size of the file system, in MB Copy the ‘echo’ program to the Pintos file system Format the file system

Program Loading userprog/process.c contains the code for loading ELF files /* Executable header. This appears at the very beginning of an ELF binary. */ struct Elf32_Ehdr { … } /* Program header. There are e_phnum of these, starting at file offset e_phoff. */ struct Elf32_Phdr { … } /* Loads an ELF executable from FILE_NAME into the current thread. Stores the executable's entry point into *EIP and its initial stack pointer into *ESP. Returns true if successful, false otherwise. */ bool load (const char *file_name, void (**eip) (void), void **esp) { … }

Setting Up The Stack userprog/process.c /* Create a minimal stack by mapping a zeroed page at the top of user virtual memory. */ static bool setup_stack (void **esp) { uint8_t *kpage; bool success = false; kpage = palloc_get_page (PAL_USER | PAL_ZERO); if (kpage != NULL) { success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true); if (success) *esp = PHYS_BASE; else palloc_free_page (kpage); } return success; At a minimum, you will need to place argc and *argv on the initial stack, since they are parameters to main()

Program Loading Flowchart Parse cmd line args, pass to load() (2) process_execute() thread_create() start_process() (1) Start the new process load() (2) (1) file_read() setup_stack() Pass the cmd line args to the new process on the stack load_segment() install_page() validate_segment() install_page()

Syscalls in Pintos Pintos uses int 0x30 for system calls Pintos has code for dispatching syscalls from user programs i.e. user processes will push parameters onto the stack and execute int 0x30 In the kernel, Pintos will handles int 0x30 by calling syscall_handler() in userprog/syscall.c static void syscall_handler (struct intr_frame *f) { printf ("system call!\n"); thread_exit (); }

Syscalls from the user process lib/user/syscall.h Defines all the syscalls that user programs can use lib/user/syscall.c void halt (void) { syscall0 (SYS_HALT); } void exit (int status) { syscall1 (SYS_EXIT, status); pid_t exec (const char *file) { return (pid_t) syscall1 (SYS_EXEC, file); } These are syscalls. They are implemented in the kernel, not in userland.

Using int 0x30 to Enter the Kernel lib/user/syscall.c /* Invokes syscall NUMBER, passing argument ARG0, and returns the return value as an `int'. */ #define syscall1(NUMBER, ARG0) \ ({ \ int retval; \ asm volatile \ ("pushl %[arg0]; pushl %[number]; int $0x30; addl $8, %%esp" \ : "=a" (retval) \ : [number] "i" (NUMBER), \ [arg0] "g" (ARG0) \ : "memory"); \ retval; \ })

On the Kernel Side… userprog/syscall.c void syscall_init (void) { intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); } static void syscall_handler (struct intr_frame *f) { printf ("system call!\n"); thread_exit (); Called during main(), sets syscall_handler() to be run whenever int 0x30 is received

Example Syscall Flowchart (exit) Christo Wilson Example Syscall Flowchart (exit) 8/22/2012 User Space Kernel Space Your changes will almost all be in here /userprog/syscall.c User Program syscall_handler() exit() exit() intr_handler() syscall1() /threads/interrupt.c /lib/user/syscall.c intr_entry() intr_exit() intr30_stub() /threads/intr-stubs.S Defense

Other Things Pintos Gives You Basic virtual memory management User processes live in virtual memory, cannot access the kernel directly Kernel may access all memory You will enhance this in Project 3 Trivial filesystem implementation Can store user programs You will enhance this in Project 4

Key Challenges Having the kernel read/write memory in user processes Necessary for reading API parameters from the user stack E.g. a string passed via a pointer Need to understand the virtual memory system Handling concurrent processes Remember, processes can call exec() Handling file descriptors and standard I/O

Modified Files threads/thread.c 13 threads/thread.h 26 userprog/exception.c 8 userprog/process.c 247 userprog/syscall.c 468 userprog/syscall.h 1 6 files changed, 725 insertions(+), 38 deletions(-) Setting up argv and argc Implementing syscalls

Grading 15 points total To receive full credit: Turn in working, well documented code that compiles successfully and completes all tests (50%) Turn in a complete, well thought our design document (50%) If your code doesn’t compile or doesn’t run, you get zero credit Must run on the CCIS Linux machines! All code will be scanned by plagiarism detection software

Turning In Your Project Register yourself for the grading system $ /course/cs5600f14/bin/register-student [NUID] Register your group All group members must run the script! $ /course/cs5600f14/bin/register project2 [team name] Run the turn-in script Two parameters: project name and code directory $ /course/cs5600f14/bin/turnin project2 ~/pintos

DUE: March 3 11:59:59PM EST Questions?