DOC PREVIEW
UNO CSCI 8530 - System Call Implementation

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 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 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11The Tempo/32 Operating SystemPart 6System Call ImplementationProcesses and Timers2newproca – Process Creation• Conceptually simple:– validate parameters– allocate an unused process table entry– fill in the appropriate values– allocate user and kernel stack space– initialize stacks for initial return from kernel• The most complicated part of process creation is getting the initial user and kernel stack contents correct3newproca: pseudocode (1)• Find an unused process table entry; if not found, return error (PROCTBLFULL)• Extract system call arguments• Setup tag, priority, and process ID• Allocate user-mode stack, handle errors• Determine size of string arguments• Set user stack info: #args, ptr to args, return address (processDone)• Copy string arguments and pointers to user-mode stack4newproca: pseudocode (2)• Allocate kernel-mode stack (always 1 page)• Initialize kernel stack: user-mode stack segment and stack pointer, eflags register, code segment and instruction pointer, remaining segment and general-purpose registers• Initialize event queues (empty, unmasked)• Setup file descriptors 0/1 for keyboard, display5newproca: pseudocode (3)• Mark all other file descriptors as available for use.• Mark process as not signaled (see signal discussion for details)• Increase number of processes in the system• Add process to appropriate ready queue by calling addready• If new process has priority greater than current (creating) process, add current process to the appropriate ready queue and set _rs to 1.• Return the ID of the new process.6User Stack at Process StartupString NString 2String 1…Addr Str NAddr Str 2Addr Str 1…Null PtrAddr ArrayNprocessDoneInitial stack pointerBottom of stack27Kernel Stack at Process StartupUser Stack SelUser Stack PtrUser Code SelInstr. PointerOther Segment Registers (4)Gen. Purpose Registers (8)eflags Reg.Initial kernel stack pointerBottom of the kernel stackPopped/restored by the “iret”instruction after “isr30z” in kernel.s8addready• The addready function has a single parameter: a pointer to a process table entry• The statemember of that process table entry is set to PROCESS_READY• The process table entry is linked (using the nextand prev members) onto the appropriate ready queue9getpid: pseudocode• Getpid almost warrants no explanation, since it only extracts and returns the pidmember of the process table entry for the current process.• The only thing worth noting is that it is always assumed that the global variable activeProcesspoints to the process table entry for the running process.10getpstate: pseudocode• Getpstate, like getpid, just returns the contents of a member (in this case, state) of the process table entry.• For this call we must map from the pidto a pointer to the process table entry. This is done by the pid2a function (in sys.c), which just does a linear search of the entire array, returning the appropriate pointer (if the pid was found) or NULL (0) otherwise.• Once the pointer is located (or not), the appropriate value is returned to the caller.11getprio, getquantum, setquantum• Each of these system calls just return a field from the process table for the currently-running process or get/set the value of a global variable.• No further explanation should be necessary to understand their implementation.12setprio: psuedocode• Verify argument is within allowed range for process priorities; if not, return error• If the new priority is the same as the current priority, return without change• Modify the process table entry• If there now exists a ready process with a priority higher than the current process’ priority:– Move the current process to the ready state by calling addready– Set _rs to 1 to force a context switch– Return313yield: pseudocode• Recall that the yield system call causes the running process to voluntarily relinquish the CPU to another process at the same priority. The steps taken are:– add the current process (the one yielding the CPU) to the appropriate ready queue by calling addready– set _rs to 1 to force a context switch– return14exit: pseudocode• Exit does little “direct” work:– The exitstatus member of the process table entry of the terminating process is set to the value of the argument to exit; this value can be retrieved by a waiting process (that called waitproc).– Set _rs to 2 so the process will be terminated (see the code at xterm in kernel.s and xcleanup in sys.c, discussed later).– Return – but since _rs is 2, control never makes it back to the process15Return from a “root” function• If the “root” function of a process should attempt to return, the instruction pointer will be set to the value that was at the top of the stack when the root function began execution.• Since that is processDone, it will be executed.• All processDonedoes is call exit with the value that was returned by the root function (left in the eax register).16waitpid/waitproc: pseudocode(1)• Extract arguments; if the process specified does not currently exist, return NOSUCHPROCESS• If timeout is 0, return TIMEOUT. (why?)• If timeout is INFINITE, set process state to PROCESS_WAIT. Otherwise, set process state to PROCESS_TIMED_WAIT and enqueue on the delta queue (discussed elsewhere).• Invoke _block() – process will awaken when the specified process exits (see xcleanup) or the timeout interval expires.17waitpid/waitproc: pseudocode(2)• When awakened after blocking, check the timedOutmember of the process table entry.– If set, return TIMEOUT– Otherwise, store the exit status from the terminated process in the location specified by the argument and return NOERROR18Aside: Variable Return Reasons• As just seen, a system call may return a variety of different “status” values.• Some of these are obvious, and result from argument errors.• In other cases, the status to be returned depends on why a process is awakened after being blocked.• Since the awakened process may not run immediately after being made ready, the reason for the awakening is stored in its process table entry.• For example, this is the function of of the timedOutmember of the process table entry.419kill: pseudocode (1)• If a process is trying to kill itself, just call exit.• If the process being terminated does not exist, return NOSUCHPROCESS.• Remove the process from any queues on which it may reside; in some cases, a


View Full Document

UNO CSCI 8530 - System Call Implementation

Download System Call Implementation
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 System Call Implementation 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 System Call Implementation 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?