Lecture 3 --------- Questions? - where's good assembly documentation? - local variables? environment variables? - gcc arguments What is a function call? - save arguments (to registers or the stack) - call function - saves (pushes) current instruction pointer onto call stack - changes instruction pointer to location of start of function - ...function runs... - on function return, pops instruction pointer from stack, restoring old function pointer - everything is based on pointers to code Pointers in a process are *local* - addresses only have meaning in the context of the process address space - name space for pointers System calls are invocations of kernel code - calling code that isn't necessarily in your address space - calling code with higher privileges - running in supervisor mode, not user mode How can I (user space process) call privileged code safely? (code that runs in supervisor mode) - restrict entry points to privileged code - can't call arbitrary routines - entry point should check whether operation is allowed In the kernel, this is what the system call dispatcher does System call dispatcher - process requests system call (write) - CPU switches to supervisor mode, runs system call dispatcher - dispatcher decides if system call is allowed - system call code (write) is invoked CPU switches into supervisor mode using special instructions - "software interrupts" - "upcall"