Gets the address of the sysenterreturn label while

This preview shows page 11 - 14 out of 22 pages.

gets the address of the SYSENTER_RETURN label, while ecx gets the current user data stack pointer. 10.3.2.5. The sysexit instruction The sysexit assembly language instruction is the companion of sysenter : it allows a fast switch from Kernel Mode to User Mode. When the instruction is executed, the CPU control unit performs the following steps:
Image of page 11

Subscribe to view the full document.

1. Adds 16 to the value in the SYSENTER_CS_MSR register, and loads the result in the cs register. 2. Copies the content of the edx register into the eip register. 3. Adds 24 to the value in the SYSENTER_CS_MSR register, and loads the result in the ss register. 4. Copies the content of the ecx register into the esp register. Because the SYSENTER_CS_MSR register is loaded with the Segment Selector of the kernel code, the cs register is loaded with the Segment Selector of the user code, while the ss register is loaded with the Segment Selector of the user data segment (see the section " The Linux GDT " in Chapter 2 ). As a result, the CPU switches from Kernel Mode to User Mode and starts executing the instruction whose address is stored in the edx register. 10.3.2.6. The SYSENTER_RETURN code The code at the SYSENTER_RETURN label is stored in the vsyscall page, and it is executed when a system call entered via sysenter is being terminated, either by the iret instruction or the sysexit instruction. The code simply restores the original contents of the ebp , edx , and ecx registers saved in the User Mode stack, and returns the control to the wrapper routine in the standard library: SYSENTER_RETURN: popl %ebp popl %edx popl %ecx ret 10.4. Parameter Passing Like ordinary functions, system calls often require some input/output parameters, which may consist of actual values (i.e., numbers), addresses of variables in the address space of the User Mode process, or even addresses of data structures including pointers to User Mode functions (see the section " System Calls Related to Signal Handling " in Chapter 11 ). Because the system_call( ) and the sysenter_entry( ) functions are the common entry points for all system calls in Linux, each of them has at least one parameter: the system call number passed in the eax register. For instance, if an application program invokes the fork( ) wrapper routine, the eax register is set to 2 (i.e., _ _NR_fork ) before executing the int $0x80 or sysenter assembly language instruction. Because the register is set by the wrapper routines included in the libc library, programmers do not usually care about the system call number. The fork( ) system call does not require other parameters. However, many system calls do require additional parameters, which must be explicitly passed by the
Image of page 12
application program. For instance, the mmap( ) system call may require up to six additional parameters (besides the system call number). The parameters of ordinary C functions are usually passed by writing their values in the active program stack (either the User Mode stack or the Kernel Mode stack).
Image of page 13

Subscribe to view the full document.

Image of page 14
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung
  • Assembly Language, Virtual memory, Subroutine, Control flow

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern