operating system - Understanding higher level call to systemcalls -


i going through book galvin on os . there section @ end of chapter 2 author writes "adding system call " kernel.

he describes how using asmlinkage can create file containing function , make qualify system call . in next part how call system call writes following :

" unfortunately, these low-level operations cannot performed using c language statements , instead require assembly instructions. fortunately, linux provides macros instantiating wrapper functions contain appropriate assembly instructions. instance, following c program uses _syscallo() macro invoke newly defined system call:

basically , want understand how syscall() function works . , understand macros system text substitution . (please correct me if wrong) how macro call assembly language instruction ? syscallo() when compiled translated address(op code) of instruction execute trap ?(but somehow doesn't fit concept or definition of macros have ) wrapper functions contained inside , written in assembly language ?

suppose , want create function of own performs system call things need . , need compile generate machine code performing trap instructions ?

man, have pay $156 dollars thing, have read it. vms internals , data structures book under $30.

that said, let me try translate gibberish english.

system calls not use same kind of linkage (i.e. method of passing parameters , calling functions) other functions use.

rather executing call instruction of kind, execute system service, trigger exception (which in intel bizarrely called interrupt).

the cpu expects operating system create dispatch table , store location , size in special hardware register(s). dispatch table array of pointers handlers exceptions , interrupts.

exceptions , interrupts have numbers so, when exception or interrupt number #1 occurs, cpu invokes 2d exception handler (not #0, #1) in dispatch table in kernel mode.

what wrapper functions contained inside , written in assembly language ?

the operating system devotes 1 (but more) exceptions system services. need thing in assembly language invoke system service:

int $80 ; explicitly trigger exception 80h  

because have execute specific instruction, has 1 in assembly language. maybe c compiler can assembly language in line call system service that. if could, royal pita have each time wanted call system service.

plus have not filled in details here (only actual call system service). normally, when call functions in c (or whatever), arguments pushed on program stack. because stack changes when enter kernel mode, arguments system calls need stored in registers.

plus need identify system service want execute. usually, system services have numbers. number of system service loaded first register (e.g., r0 or ax).

the full process when need invoke system service is:

  1. save registers going overwrite on stack.
  2. load arguments want pass system service hardware registers.
  3. load number of system service lowest register.
  4. trigger exception enter kernel mode.
  5. unload arguments returned system service registers
  6. possibly error checking
  7. restore registers saved before.

instead of doing each time call system service, operating systems provide wrapper functions high level languages use. call wrapper call function. wrapper (in assembly language) steps above you.

because these wrappers pretty same (usually difference result of different numbers of arguments), wrappers can created using macros. assemblers have powerful macro facilities allow single macro define wrappers, different numbers of arguments.

linux provides multiple _syscall c macros create wrappers. there 1 each number of arguments. note these macros operating system developers. once wrapper there, can use it.

how macro call assembly language instruction ?

these _syscall macros have generate in line assembly code.

finally, note these wrappers not define actual system service. has set in dispatch table , system service exception handler.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -