Computer Science 822 Quiz 4 Name_______________________ 1. When a software interrupt occurs on an Intel based Linux system identify whether each of the following functions in performed by the application (A), the hardware (H), or the Linux kernel (K) _H_ a. Save old values of CS, EIP, EFlags on the stack _H_ b. Switch SS and ESP from user level stack to kernel stack _K_ c. Save general registers (EAX, EBX, ECX, ... etc) _H_ d. Load new values CS and EIP from interrupt descriptor _H_ e. Save SS and ESP for the user level stack. 2. The old user level stack values of SS and ESP are saved a. in the IDT b. in the TSS d c. On the user level stack d. On the kernel stack 3. The new kernel level stack values of SS and ESP are loaded from a. the IDT b. the TSS b c. the kernel level stack d. the task struct 4. The application's values of the General Registers are saved during a system call a. On the app stack b. on the kernel stack b c. in the task struct 5. Shown below is the syscall2 macro: #define _syscall2(type,name,type1,arg1,type2,arg2) \ type name(type1 arg1,type2 arg2) \ { \ long __res; \ __asm__ volatile ("int $0x80" \ : "=a" (__res) \ : "" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ __syscall_return(type,__res); \ } Suppose I am going to write a new system call with numeric id 235: unsigned long superkill(int pid, int sigid); How would I define this new call using _syscall2 #define __NR_superkill 235 __syscall2(unsigned long, superkill, int, pid, int, sigid); 5. Suppose I write an application that uses the standard function call len = write(fd, buf, 1024); Describe as precisely and concisely as possible the mechanism by which control is eventually vectored to the sys_write function in the kernel. You may use the fact ( __NR_write = 4) to make your explanation a bit more concrete. __syscall3() generates wrapper which sets EAX = 4, (puts other parms in regs) and issues int 0x80 trap gate at offset 0x80 in the IDT contains CS and Offset pointing the system_call entry kernel entry point. The system_call() function makes an indirect call to the address found in system_call_table[EAX] which better point to sys_write 6. Suppose sys_write returns a value of 512. How does this value get transfered to my "len" variable sys_write returns the 512 in register EAX the system_call function stores EAX in the kernel stack at the location from where EAX will be restored on return. since the value returned in EAX is positive, the wrapper doesn't modify it and the standard C function interface assumes that the return from any function is in EAX.