Jae badgetuser 2 movzwl 1eax edx xorl eax eax ret

This preview shows page 16 - 18 out of 22 pages.

jae bad_get_user 2: movzwl -1(%eax), %edx xorl %eax, %eax ret bad_get_user: xorl %edx, %edx movl $-EFAULT, %eax ret The eax register contains the address ptr of the first byte to be read. The first six instructions essentially perform the same checks as the access_ok( ) macro: they ensure that the 2 bytes to be read have addresses less than 4 GB as well as less than the addr_limit.seg field of the current process. (This field is stored at offset 24 in the thread_info structure of current , which appears in the first operand of the cmpl instruction.) If the addresses are valid, the function executes the movzwl instruction to store the data to be read in the two least significant bytes of edx register while setting the high-order bytes of edx to 0; then it sets a 0 return code in eax and terminates. If the addresses are not valid, the function clears edx , sets the -EFAULT value into eax , and terminates. The put_user(x,ptr) macro is similar to the one discussed before, except it writes the value x into the process address space starting from address ptr . Depending on the size of x , it invokes either the _ _put_user_asm( ) macro (size of 1, 2, or 4 bytes) or the _ _put_user_u64( ) macro (size of 8 bytes). Both macros return the value 0 in the eax register if they succeed in writing the value, and -EFAULT otherwise.
Image of page 16

Subscribe to view the full document.

Several other functions and macros are available to access the process address space in Kernel Mode; they are listed in Table 10-1 . Notice that many of them also have a variant prefixed by two underscores (_ _). The ones without initial underscores take extra time to check the validity of the linear address interval requested, while the ones with the underscores bypass that check. Whenever the kernel must repeatedly access the same memory area in the process address space, it is more efficient to check the address once at the start and then access the process area without making any further checks. Table 10-1. Functions and macros that access the process address space Function Action get_user _ _get_user Reads an integer value from user space (1, 2, or 4 bytes) put_user _ _put_user Writes an integer value to user space (1, 2, or 4 bytes) copy_from_user _ _copy_from_user Copies a block of arbitrary size from user space copy_to_user _ _copy_to_user Copies a block of arbitrary size to user space strncpy_from_user _ _strncpy_from_user Copies a null-terminated string from user space strlen_user strnlen_user Returns the length of a null-terminated string in user space clear_user _ _clear_user Fills a memory area in user space with zeros 10.4.3. Dynamic Address Checking: The Fix-up Code As seen previously, access_ok( ) makes a coarse check on the validity of linear addresses passed as parameters of a system call. This check only ensures that the User Mode process is not attempting to fiddle with the kernel address space; however, the linear addresses passed as parameters still might not belong to the process address space. In this case, a Page Fault exception will occur when the kernel tries to use any of such bad addresses.
Image of page 17
Image of page 18
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