Processes (Intro) Yannis Smaragdakis, U. Athens

Similar documents
4. The Abstraction: The Process

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Processes. q Process concept q Process model and implementation q Multiprocessing once again q Next Time: Scheduling

Processes. Today. Next Time. Process concept Process model Implementing processes Multiprocessing once again. Scheduling processes

Processes and Threads

1 Programs and Processes

CS 537 Lecture 2 - Processes

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

CS3210: Isolation Mechanisms

The Abstraction: The Process

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

6. Mechanism: Limited Direct Execution

CS5460/6460: Operating Systems. Lecture 9: First process. Anton Burtsev January, 2014

Changes made in this version not seen in first lecture:

CSC369 Lecture 2. Larry Zhang

CSC369 Lecture 2. Larry Zhang, September 21, 2015

3. Process Management in xv6

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

Assembly Language: Function Calls

CS 318 Principles of Operating Systems

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

CS 318 Principles of Operating Systems

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture)

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

Section 4: Threads and Context Switching

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Register Allocation, iii. Bringing in functions & using spilling & coalescing

6.828: Using Virtual Memory. Adam Belay

COP4610: Operating Systems Project 1

CSE 153 Design of Operating Systems Fall 18

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Processes. Chester Rebeiro IIT Madras

X86 Stack Calling Function POV

x86 assembly CS449 Fall 2017

ASSEMBLY III: PROCEDURES. Jo, Heeseung

W4118: PC Hardware and x86. Junfeng Yang

Assembly III: Procedures. Jo, Heeseung

CS3210: Coordination. Tim Andersen

Stack Discipline Jan. 19, 2018

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-level Programming (3)

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

This is an open book, open notes exam. But no online or in-class chatting.

An Experience Like No Other. Stack Discipline Aug. 30, 2006

Lecture 4 CIS 341: COMPILERS

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

Protection and System Calls. Otto J. Anshus

Processes. Johan Montelius KTH

Changes made in this version not seen in first lecture:

A process. the stack

Function Call Convention

The Kernel Abstraction. Chapter 2 OSPP Part I

Program Exploitation Intro

Misc. Notes. In BVT, switch from i j only if E j E i C/w i. In BVT, Google is example of W better then L. For lab, recall PDE and PTE bits get ANDed

CPEG421/621 Tutorial

University of Washington

CSE 153 Design of Operating Systems

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

CS213. Machine-Level Programming III: Procedures

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

Systems I. Machine-Level Programming V: Procedures

Processes. Dr. Yingwu Zhu

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Machine-Level Programming III: Procedures

Exceptions and Processes

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

The IA-32 Stack and Function Calls. CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

CPS104 Recitation: Assembly Programming

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

Ausgewählte Betriebssysteme. Anatomy of a system call

EEE3052: Introduction to Operating Systems. Fall Project #1

Mechanisms for entering the system

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

x86 Assembly Tutorial COS 318: Fall 2017

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CS 4284 Systems Capstone. Processes and Threads Godmar Back

Problem Set: xv6. Lecture Notes on Operating Systems. 1. Consider the following lines of code in a program running on xv6.

CS153: Process. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

W4118 Operating Systems. Junfeng Yang

Assembly I: Basic Operations. Jo, Heeseung

Multiprocessor Solution

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

U23 - Binary Exploitation

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

Practical Malware Analysis

CS241 Computer Organization Spring 2015 IA

x86 architecture et similia

Buffer Overflow Attack

Computer Systems II. First Two Major Computer System Evolution Steps

CSE 351: Week 4. Tom Bergan, TA

Transcription:

Processes (Intro) Yannis Smaragdakis, U. Athens

Process: CPU Virtualization Process = Program, instantiated has memory, code, current state What kind of memory do we have? registers + address space Let's do a hardware review 2

Process API OSes will typically let you do the following with processes create destroy wait control (e.g., suspend) and notify get status, info Demo process queries 3

Process Creation Load code in memory Allocate stack, set initial args for main Set up heap Set up communication channels (open files) Call main 4

Example Modern Address Space (64-bit Linux) location of code : 0x40057d location of heap : 0xcf2010 location of stack : 0x7fff9ca45fcc 0x400000 0x401000 0xcf2000 0xd13000 Address Space Code (Text) Data Heap heap (free) stack 0x7fffca28000 0x7fffca4f000 Stack 5

Loading code static data heap stack Process code static data heap Program Disk Loading: Takes on-disk program and reads it into the address space of process 6

Simplified Process States Running Descheduled Scheduled Ready I/O: initiate I/O: done Blocked 7

OS Structures Structure holding all processes, per state how do you think this looks? PCB (Process Control Block) per process 8

xv6 Kernel Structures // the registers xv6 will save and restore // to stop and subsequently restart a process struct context { int eip; // Index pointer register int esp; // Stack pointer register int ebx; // Called the base register int ecx; // Called the counter register int edx; // Called the data register int esi; // Source index register int edi; // Destination index register int ebp; // Stack base pointer register }; // the different states a process can be in enum proc_state { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; 9

xv6 Kernel Structures // the information xv6 tracks about each process // including its register context and state struct proc { char *mem; // Start of process memory uint sz; // Size of process memory char *kstack; // Bottom of kernel stack // for this process enum proc_state state; // Process state int pid; // Process ID struct proc *parent; // Parent process void *chan; // If non-zero, sleeping on chan int killed; // If non-zero, have been killed struct file *ofile[nofile]; // Open files struct inode *cwd; // Current directory struct context context; // Switch here to run process struct trapframe *tf; // Trap frame for the // current interrupt }; 10

How Is Kernel and User Code Execution Interleaved? Principle of OSes: the same physical core runs both kernel and user (process) code User code runs at full CPU speed But kernel maintains control How??? 11

Example Execution OS 1. Create entry for process list 2. Allocate memory for program 3. Load program into memory 4. Set up stack with argc / argv 5. Clear registers 6. Execute call main() f. Free memory of process 10. Remove from process list Program 7. Run main() 8. Execute return from main() But the OS is the boss of all resources, not just a library, so how does it take back control? 12

System Calls, Interrupts User vs. Kernel CPU mode not all programs can do everything System calls for all resource access trap, return-from-trap instructions trap = synchronous, user-initiated interrupt 13

OS @ run (kernel mode) Hardware Program (user mode) initialize trap table remember address of syscall handler... Create process structs Load program into memory Setup user stack with argv Fill kernel stack with reg/pc return-from -trap Handle trap Do work of syscall return-from-trap restore regs move to user mode jump to main save regs to kernel stack move to kernel mode jump to trap handler restore regs move to user mode jump to PC after trap Run main() Call system trap into OS 14

Is This Enough? What if a process is stuck in infinite loop? historical note: cooperative multiprocessing Hardware again to the rescue! OS has set a timer interrupt a process only runs for a time slice scheduling decision afterwards context switch if needed 15

xv6 (old) Context Switch Code 1 # void swtch(struct context *old, struct context *new); 2 # 3 # Save current register context in old 4 # and then load register context from new. 5.globl swtch 6 swtch: 7 # Save old registers 8 movl 4(%esp), %eax # put old ptr into eax 9 popl 0(%eax) # save the old IP, stack contents: return,old,new 10 movl %esp, 4(%eax) # and stack 11 movl %ebx, 8(%eax) # and other registers 12 movl %ecx, 12(%eax) 13 movl %edx, 16(%eax) 14 movl %esi, 20(%eax) 15 movl %edi, 24(%eax) 16 movl %ebp, 28(%eax) 17 18 # Load new registers 19 movl 4(%esp), %eax # put new ptr into eax, was 8(%esp) but popped return 20 movl 28(%eax), %ebp # restore other registers 21 movl 24(%eax), %edi 22 movl 20(%eax), %esi 23 movl 16(%eax), %edx 24 movl 12(%eax), %ecx 25 movl 8(%eax), %ebx 26 movl 4(%eax), %esp # stack is switched here 27 pushl 0(%eax) # return addr put in place 28 ret # finally return into new ctxt 16

What If Interrupted During Interrupt Handling? OS can briefly disable interrupts... or ensures safe access to data structures through concurrency control mechanisms (e.g., locking) 17