previous | start | next

The sendrec function

This function is in assembly code, not C:

__sendrec:
        push  ebp
        mov   ebp, esp
        push  ebx
        mov   eax, SRC_DST(ebp)   ! eax = dest-src
        mov   ebx, MESSAGE(ebp)   ! ebx = message pointer
        mov   ecx, SENDREC        ! _sendrec(srcdest, ptr)
        int   SYSVEC              ! trap to the kernel
        pop   ebx
        pop   ebp
        ret

     

The routine pushes arguments on the stack and then executes the int machine instruction with operand SYSVEC, which is just an integer identifying an entry in the interrupt vector table.

This instruction int is an instruction (software), but has the effect of a hardware interrupt.

In particular it saves part of the state of the current process and loads the program counter (register eip) and the flags register for a kernel routine that handles all system calls.

Important! This switches from user mode to kernel mode, but also from user code to kernel code.

The int instruction can't be used to somehow magically switch to kernel mode but to user written code.



previous | start | next