Points from Jan 07 lecture. Recap of UNIX systems calls and userland--kernel separation. 1. System calls as the centerpiece of a UNIX kernel. All privileged operations in UNIX are performed on behalf of user processes by "system call" code located in the kernel. The data that this code operates on is also located in the kernel and can only be directly accessed when the CPU is in "kernel mode". This ensures that user processes get to use this code only as a "package deal", with the up-front permission and sanity checks being a part of the package. This mechanism is the basis of the OS stability and security. 2. Some Linux/x86 details: User-level code accesses syscall code through the so-called "call gate" mechanism: it sets the number of the desired call in a register (EAX on Linux/x86), sets arguments or pointers to arguments in other registers (EBX, ECX, EDX, ... on Linux) and executes the "int 0x80" instruction. Note that the system call function is accessed only by it number, not by its address, which user-level code cannot "jump" or "call" to (if it tries, a segfault will occur). The "int 0x80" instruction simultaneously puts the CPU into the kernel mode and transfers control to the address stored in the 0x80-th slot of the x86 CPU's Interrupt Descriptor Table (which is pointed to by the CPU's special IDTR register). That address is *the single entry point* for all system calls. Look at the nice Fig. 1 in this IBM developer article on syscalls: http://www.ibm.com/developerworks/linux/library/l-system-calls/ Look at ENTRY(system_call) in: http://lxr.linux.no/linux+v2.6.24/arch/x86/kernel/entry_32.S Observe the sys_call_table: http://lxr.linux.no/linux+v2.6.24/arch/x86/kernel/syscall_table_32.S Details on Linux system calls: http://www.ibm.com/developerworks/linux/library/l-system-calls/ 3. Some OpenSolaris details: Syscall numbers exposed in Solaris in: /etc/name_to_sysnum Syscall numbers defined in: /usr/src/uts/common/sys/syscall.h (http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/sys/syscall.h) Syscalls dispatched in: /usr/src/uts/intel/ia32/os/syscall.c http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/intel/ia32/os/syscall.c Observe: dosyscall() gets the address of the requested syscall function by "code" in syscall_entry() then executes it by function pointer (lines 920--925). System call table: usr/src/uts/common/os/sysent.c http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/sysent.c Observe: Line 430, struct sysent sysent[NSYSCALL] = ... 4. A simple syscall: getpid() http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/syscall/getpid.c#44 Looks up the PID via the pointer to the current thread descriptor curthread (follows the pointer to the process structure of type proc_t, then locates the integer PID value through that). Kernel struct that keeps process data (alongside with some others, explained briefly on pp. 44--48 of the textbook, details in Section 2.4): http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/sys/proc.h#127 Suggestion: explore proc_t for the linking between process structs. How many other proc_t's are linked to it and why? (Many...) Similar structure for Linux is task_struct: http://lxr.linux.no/linux+v2.6.24/include/linux/sched.h#L917 --------------------------------------------------------------------- Installing your own copy of OpenSolaris in a virtual machine: I installed OpenSolaris version 2009.06 in a VirtualBox environment (free, recently bought by Sun and tested with OpenSolaris) on MacOS 10.5: http://www.virtualbox.org/wiki/Downloads Sun's directions on installing OpenSolaris in a VirtualBox: http://dlc.sun.com/osol/docs/content/dev/getstart/virtualbox.html NOTE: Use at least 640M RAM in the virtual machine. With 512M, the LiveCD installer refused to run. These nice step-by-step instructions with screenshots http://www.javapassion.com/handsonlabs/opensolarisvirtual/ will lead you to the point where you need to double-click "Install OpenSolaris", which will install it onto your virtual disk. Then follow OpenSolaris installer instructions (in particular, accept the default partitioning scheme). Once everything has been installed, reboot the VirtualBox and choose "Boot from Hard Drive" in the Grub menu (or else you will boot from the installation CD ISO image again; or "detach" this ISO image before "booting" the VirtualBox).