Skip to contentSkip to conversation

system calls-(query)

DISCUSSION Susheel Raj 3 participants 3 messages Jul 6, 2004

lore
Share & tools
lore
#0 lore raw

i have been trying to understand how the system calls are being made by applications and how the kernel reacts to them...this is what i got into my brain.... when an application makes a system call ( for i386) %eax register is filled with the system call number and some other registers are to be given some appropriate values..for example ..if i amke an exit () system call.. then its system call number "1" is filled in %eax and the status code is filled in %ebx...

so i want to know what are the requirements for other systems calls to execute ...what all registers they access..any documentation would be a great help....

________________________________________________________________________
Yahoo! India Careers: Over 50,000 jobs online Go to: http://yahoo.naukri.com/

#1 lore raw

On Tue, 2004-07-06 09:00:30 +0100, Susheel Raj <[email protected]> wrote in message <[email protected]>:

Quoted 11 lines

i have been trying to understand how the system calls are being made by applications and how the kernel reacts to them...this is what i got into my brain.... when an application makes a system call ( for i386) %eax register is filled with the system call number and some other registers are to be given some appropriate values..for example ..if i amke an exit () system call.. then its system call number "1" is filled in %eax and the status code is filled in %ebx...

Quoted 3 lines

so i want to know what are the requirements for other systems calls to execute ...what all registers they access..any documentation would be a great help....

Userland has to place arguments where the kernel expects them. Have a look at ./linux/asm-$ARCH/unistd.h to see how syscalls can be made. You can think of the _syscallX() macros as the lowest-level "function" to get access to a system call slot. From there, the syscall is usually dispatched from entry.S.

Syscalls trigger some kind of interrupt or exception; an exception handler then gets the system call number and dispatches it through the syscall function pointer's addresses in sys_call_table (in entry.S).

MfG, JBG

Signature · 4 lines
   Jan-Benedict Glaw       [email protected]    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#2 lore raw
In reply to Susheel Raj
Quoted 11 lines · Susheel Raj

i have been trying to understand how the system calls are being made by applications and how the kernel reacts to them...this is what i got into my brain.... when an application makes a system call ( for i386) %eax register is filled with the system call number and some other registers are to be given some appropriate values..for example ..if i amke an exit () system call.. then its system call number "1" is filled in %eax and the status code is filled in %ebx...

Quoted 3 lines

so i want to know what are the requirements for other systems calls to execute ...what all registers they access..any documentation would be a great help....

You missed the main point here.It does software interrupt using eax, ebx, ecx, edx, esi, edi in that order.

C program:
syscall (100, 0, 1, 2, 3, 4, 5, 6);

Function call :

 8048200:       6a 06                   push   $0x6
 8048202:       6a 05                   push   $0x5
 8048204:       6a 04                   push   $0x4
 8048206:       6a 03                   push   $0x3
 8048208:       6a 02                   push   $0x2
 804820a:       6a 01                   push   $0x1
 804820c:       6a 00                   push   $0x0
 804820e:       6a 64                   push   $0x64
 8048210:       e8 1b 5d 00 00          call   804df30 <syscall>

Syscall release :

 804df33:       8b 7c 24 24             mov    0x24(%esp),%edi
 804df37:       8b 74 24 20             mov    0x20(%esp),%esi
 804df3b:       8b 54 24 1c             mov    0x1c(%esp),%edx
 804df3f:       8b 4c 24 18             mov    0x18(%esp),%ecx
 804df43:       8b 5c 24 14             mov    0x14(%esp),%ebx
 804df47:       8b 44 24 10             mov    0x10(%esp),%eax
 804df4b:       cd 80                   int    $0x80

(further args works with struct passing)

Best regards,
FabF