DOC PREVIEW
UMD CMSC 412 - Project 2

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Project 2Zen and the art of sending signalsBackground – Context SwitchingOne processor and multiple threads running concurrently – How?Give each thread a small time quantum to run.When this quantum expires, or the thread blocks, context-switch to a different thread.1. Where should I save the thread context during a context-switch?2. What should this context consist of?Background – Kernel Stack•User process i s a kernel t h read with USER_CONTEXT structure.•Store the current context (state) before context switching.•Where is the kernel stack?struct Kernel_Thread {unsigned long esp; // Stack pointer (absolute)void* stackPage; //The beginning of the stack.........................}; •esp points at the end of the stack (stack grows down from higher to lower address)Background – User Processes•Two stacks: kernel stack and user stack.•User Stack (stores state in user mode)•Start_User_Thread: set up the kernel stack to look as if the thread had previously been running and then context-switched to the ready queue.User Stack LocationInterrupt_StateBackground – Context Information• The items at the top are pushed first.•Program Counter EIP• User stack pointer points to the end of the DS.• Stack grows down from higher address to lower address.Stack Data Selector (data selector)Stack Pointer (end of data memory)Eflags Text Selector (code selector) Program Counter (entry addr) Error Code (0) Interrupt Number (0) EAX (0) EBX (0) ECX (0) EDX (0) ESI (Argument Block address) EDI (0) EBP (0) DS (data selector) ES (data selector) FS (data selector) GS (data selector)Project 2: SignalsInter-process communicationSignals are to user processes what interrupts are to the kernel .Process temporarily stops what it is doing, and is instead redirected to the signal handler.When the handler completes, the process goes back to what it was doing (unless another signal is pending!)SignalsProcess A CS….Kill(A, SIGUSR1) ……….X = x + 1; OR Get_Key()……1. Process A is executing then either finishes quantum OR blocked2. Process B is now executing and sends a signal to A.Process B CSSIGUSR1 HandlerMemory3. Process A is executing again. However, control is transferred to SIGUSR1 handler.4. SIGUSR1 handler finishes. Then control transfers to Process A again (if no other signal pending).Project Requirements1.Add the code to handle signals.2.System calls. 3.Background processes are NOT detached. (Now they are children)Look for TODO macroSupported Signals•SIGKILL: treated as Sys_Kill of project1.•SIGUSR1 & SIGUSR2•SIGCHLD•Background processes are NOT detached any more (refCount will start as 2).•Sent to a parent when the background child dies.•Default handler - reap the childSystem Calls•Sys_Signal: register a signal handler•Sys_RegDeliver: initialize signal handling for a process •Sys_Kill: send a signal •Sys_ReturnSignal: indicate completion of signal handler •Sys_WaitNoPID: wait for any child process to dieSys_ Signal•Register a signal handler for a process•state->ebx - pointer to handler function•state->ecx - signal number• Returns: 0 on success or error code (< 0) on error•Calling Sys_Signal with a handler to SIGKILL should result in an error.Sys_Signal•Initial handler for SIGCHLD (reaps all zombie) is•Def_Child_Handler•Two predefined handlers:•SIG_IGN, SIG_DFL (check inlcude/libc/signal.h)•Example: Signal(SIGUSR1,SIG_IGN);Sys_ RegDeliver Register three functions:1. Ignore2. Default 3. Return_Signal trampoline (calls Sys_ReturnSignal)Signals cannot be delivered until this is registered.state->ebx - pointer to Return_Signal functionstate->ecx - pointer to the default handlerstate->edx - pointer to the ignore handler Returns: 0 on success or error code (< 0) on errorThese routines are registered automatically.(check src/libc/entry.c)Sys_Kill•Send a signal to a process•state->ebx - pid of process•state->ecx - signal number• Returns: 0 on success or error code (< 0) on errorSys_ReturnSignal •Complete signal handling for this process.•No Parameters•Returns: 0 on success or error code (< 0) on error•Called by a process immediately! after it has handled a signal.Sys_WaitNoPID•Reap a child process that has died•state->ebx - pointer to status of process reaped•Returns: pid of reaped process on success, -1on error.Signals Golden Rules•Any user process stores THREE pointers to handler functions corresponding to (SIGUSR1, SIGUSR2, SIGCHLD).•These pointers could be NULL if there is no registered handler.•Any process also stores THREE pointers to the Ign_Handler, Def_Handler, Signal_Return•If there no handler registered, the default handler will be executed. •Signal handling is non-reentrant.Signals Delivery in Kernel•src/geekos/signal.c•Send_Signal•Check_Pending_Signal•Set_Handler•Setup_Frame•Complete_HandlerCheck_Pending_Signal•A signal is pending for that user process.•The process is about to start executing in user space. •CS register != KERNEL_CS •(see include/geekos/defs.h) •The process is not currently handling another signal.Setup_FrameUser Stack Location (SP)Interrupt_State (Context Information)Kernel StackMemoryLower AddressHigher AddressInterrupt_State (Context Information)1. Push a copy of the context from kernel stack to user stack.3. Advance user stack pointer in kernel stack.2. Push the address of the “signal trampoline”.Signal Trampoline4. Change program counter in kernel stack to point to signal handler.Complete_HandlerUser Stack Location (SP)Interrupt_State (Context Information)Kernel StackMemoryLower AddressHigher AddressInterrupt_State (Context Information)1. Copy of the context from user stack to kernel stack.2. Update user stack pointer in kernel stack.Signal


View Full Document

UMD CMSC 412 - Project 2

Documents in this Course
Security

Security

65 pages

Deadlocks

Deadlocks

22 pages

Set 2

Set 2

70 pages

Load more
Download Project 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Project 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Project 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?