
CS485G Spring 2015 41
(d) When the kernel is ready to return from the exception:
i. The CPU changes to its previous mode (typically user mode)
and its previous location.
ii. The saved information is popped from the stack.
45 Example: opening a file in Linux x86
1. Lecture 25, 4/1/2015
2. In C, a program invokes open(filename, options).
3. The C library handles this function by executing an interrupt instruc-
tion: int $0x80.
4. The Linux kernel runs a procedure called sys open(). Any error it
encounters causes it to return a specific negative number indicating
the error, such as EFAULT.
(a) verify that the filename is in a valid location in memory.
(b) verify that the file exists.
(c) verify that the file permissions allow this process to open it in
th manner specified by the options.
(d) build a kernel data structure files struct.
(e) return the index of that structure within the kernel’s per-process
fd array.
5. The C library sees if the return value R is negative. If so, it stores R
in the global variable errno and returns –1. Otherwise, it returns R.
46 Example: Page fault
1. A program tries to access a memory address that is in its virtual
space but which is not currently available.
2. The MMU (memory management unit) notices the problem and gen-
erates a page fault.
3. The Linux kernel executes a procedure called fault(). It takes pos-
sibly complex action to make sure the memory address is available.
4. The kernel then returns to the same instruction that caused the fault.
Comentarios a estos manuales