Advanced%20Operating%20Systems - PowerPoint PPT Presentation

About This Presentation
Title:

Advanced%20Operating%20Systems

Description:

System calls involve switching from user to supervisor ... ELF Executable and Linkable Format. There are others lots of them! 51. Linux and file formats ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 14
Provided by: craig60
Category:

less

Transcript and Presenter's Notes

Title: Advanced%20Operating%20Systems


1
Advanced Operating Systems
  • Implementing System Calls

2
System Call Implementation
  • Under Linux system calls have 2 separate function
    calls
  • The do_xxx call which does the work
  • The sys_xxx macro which deals with arguments a
    call numbers

3
System Call Implementation
  • System calls involve switching from user to
    supervisor mode through an interrrupt (0x80 on
    PCs)
  • _syscall macro generates the actual system call
    number (unistd.h)
  • Interrupt routine handles the call
    (arch/kernel/entry.s)
  • If legitimate, the routine looked up in
    sys_call_table

4
System Call Implementation
  • Some call may be traced - ie debugged calls
    using the syscall_trace function
  • On return from system call a number of
    administrative tasks must be done
  • Send parent signals
  • Any pending interrupt service routines called
  • Signals handled

5
Implementing fork() clone()
  • Under Linux fork() and clone() are essentially
    the same call with some (important) differences
  • Fork() create a completely new process
  • Clone() creates a new thread within a process

6
Linux fork() versus traditional fork()
  • UNIX fork() creates
  • New process environment
  • Copies data
  • Copies text
  • Copies files, locks and signals
  • Creates new PID
  • Linux fork() creates
  • New process environment
  • Makes data write protected (copies on write)
  • Copies files, locks and signals
  • Creates new PID

Text may be shared
7
Implementing fork() clone()
  • They both call do_fork() however clone() sets up
    some extra parameters beforehand
  • Set up a new set of register and stack pointers
  • do_fork() is called as follows
  • do_fork(SIGCHILD, regs, esp, regs)
  • Or
  • do_fork(clone_flags, newsp, regs)

8
Implementing fork() clone()
  • do_fork()
  • Creates a new stack using kmalloc()
  • Gets a new process table entry
  • The child or thread inherits all of the parents
    task structure but changes some entries
  • Exec flag, time, signal flags

9
Implementing fork() clone()
  • The difference between fork and clone is found at
    the final section of the call when the task
    substructures are copied (or not!)
  • This copies files, file systems, signal handlers,
    memory management
  • The parent gets the child or thread pid

10
Fork and Clone
Process 1
Process 1
Process 1
Process 1
User Space
Thread
Thread
Kernel
Kernel Space
Kernel
11
Executable formats
  • Before looking at exec a word on file formats
    there are a number of different formats
  • a.out the original UNIX format
  • COFF Common Object File Format
  • ELF Executable and Linkable Format
  • There are others lots of them!

12
Linux and file formats
  • Linux supports a large number of file formats
    each ones is tried until one works
  • Done by do_exec
  • Use linux_binfmt
  • Loads binary
  • Loads libs
  • Deals with the core file
  • They can be load as modules

13
ELF
E L F 0x8048090 52 52 2
e_indent e_entry e_phoff e_phentsize e_phnum
PT_LOAD 0 0x804800 68532 68532 PF_R, PF_X
p_type p_offset p_vaddr p_filesz p_memsz p_flags
Physical Header
p_type p_offset p_vaddr p_filesz p_memsz p_flags
PT_LOAD 68536 0x8059BB8 2200 4248 PF_R, PF_W
Physical Header
CODE
DATA
Write a Comment
User Comments (0)
About PowerShow.com