1 / 19

CMSC421: Principles of Operating Systems

CMSC421: Principles of Operating Systems. Nilanjan Banerjee. Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/. Principles of Operating Systems. Announcements. Project 0 and Homework 1 out

mindy
Download Presentation

CMSC421: Principles of Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC421: Principles of Operating Systems Nilanjan Banerjee Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/ Principles of Operating Systems

  2. Announcements • Project 0 and Homework 1 out • Discussion grades will not be on Blackboard • Readings from Silberchatz • Optional but important

  3. Discussion 1 Sign bit exponent Mantissa 1000 *(int *)&a 1000 1000 Integer/2s compliment

  4. Kernel-userspace interaction software interrupts system calls Hardware interrupts timers Application kernel exceptions Timers/return from sys call A closer look at system calls

  5. Lets take an example main: OS _start libc linker assembler .s file .o file Exec. .c file libraries

  6. X86 assembly for system calls (older mechanism) mov $1, %eax mov $25, %ebx int $0x80 Execute interrupt # 128 In the interrupt vector table Software interrupt Jump to an address in the kernel where the syscall table is stored And execute syscall # stored in %eax args for syscall in registers [ebx, ecx, edx, esi, edi]

  7. Primer into virtual memory management Virtual addresses unallocated Physical addresses

  8. Primer into kernel and user space memory Acknowledgement: http://duarts.org/gustavo/blog/category/internals

  9. Primer into how context switching happens Acknowledgement: http://duarts.org/gustavo/blog/category/internals

  10. Flow of control during a system call invocation library (libc) Return value Error = -1 Errorcode = errorno your application system call invocation User space int 0x80 Kernel space syscall_table.S iret entry_32.S Saves registers on stack Save return address of user process (thread_info) restore registers system call execution return value stored in the stack location corresponding to %eax table of function pointers

  11. Kernel dive.

  12. Important kernel files/ data structures for system calls • implementation file for the sys call • kernel/sys.c (most of the system calls are implemented) • You can implement a system call anywhere • include/asm-i386/unistd.h • Defines the *number* of a system call • Defined the total number of system calls. • arch/i386/kernel/syscall_table.S • Stores the system call table • Stores the function pointers to system call definition

  13. Using sysenter/sysexit in Linux > 2.5 • Sysenter/sysexit is also called “Fast system Call” • Available in Pentium II + • Sysenter is made of three registers • SYSENTER_CS_MSR -- selecting segment of the kernel code (figuring out which kernel code to run) • SYSENTER_EIP_MSR --- address of the kernel entry • SYSENTER_ESP_MSR --- kernel stack pointer

  14. Simplified view of sysenter/sysexit in Linux > 2.5 library (libc) Return value Error = -1 Errorcode = errorno your application _ _kernel_vsyscall User space sysenter Kernel space syscall_table.S sysexit entry_32.S Saves user mode stack Save return address of user process (thread_info) restore registers system call execution return value stored in the stack location corresponding to %eax table of function pointers

  15. Lets write a system call in the kernel (sys_strcpy) intstrcpy(char *src, char *dest, intlen) can return values of size of at most long? Why? asmlinkage long sys_strcpy(char *src, char *dest, intlen) compiler directive params will be read from stack

  16. Issues to think about when writing system calls • Moving data between the kernel and user process • Concerns: security and protection • Synchronization and concurrency (will revisit) • Several (so called) kernel threads might be accessing the same data structure that you want to read/write • Simple solution (disable interrupts “cli”) • Usually not a good idea • Big problem in preemptive CPU (which is almost every CPU) and multi-processor systems • CONFIG_SMP or CONFIG_PREEMPT

  17. Useful kernel API functions for bidirectional data movement • access_ok (type, addr, size): type (VERIFY_READ, VERIFY_WRITE) • get_user(x, ptr) --- read a char or int from user-space • put_user(x, ptr) --- write variable from kernel to user space • copy_to_user(to, from, n) --- copy data from kernel to userspace • copy_from_user(to, from, n) – copy data to kernel from userspace • strnlen_user(src, n) – checks that the length of a buffer is n • strcpy_from_user(dest, src, n) ---copies from kernel to user space Acknowledgement: http://www.ibm.com/developerworks/linux/library/l-kernel-memory-access/index.html

  18. Next class • Linux Boot process • How the first process gets started • Process management • Process creation and basic IPC: fork(), pipe(), dup2(), wait() • Theory on processes

  19. An in-class discussion (a Microsoft Interview Question)

More Related