previous | start | next

The sendrec function

This function is in assembly code, not C:

__sendrec:
        push  %ebp
        mov   %esp, %ebp
        push  %ebx
        mov   SRC_DST(%ebp), %eax    ! eax = dest-src
        mov   MESSAGE(%ebp), %ebx    ! ebx = message pointer
        mov   SENDREC, %ecx        ! _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