Thread: how would you answer this question?

  1. #1
    Registered User
    Join Date
    Oct 2007

    how would you answer this question?

    Hello Everybody!
    This is not a real programming question, but it's about linux..
    At high level, how would you answer the following question:

    "What does it happen in Linux when a process (running in User Mode) tries to address a byte of memory belonging to the address space reserved to the Kernel?"

    I'd answer like this:
    "The paging circuit will lookup the PAGE DIRECTORY of the process and, not finding the requested address, will raise a PAGE FAULT. The page fault handler will then find out that the address doesn't belong to the process' address space and then terminate the process".

    I don't know if the USER/SUPERVISOR flag plays some role in this case..?

    Thanks for your comments! Bye!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    and then terminate the process
    Actually, it will raise a SIGSEGV. The default action for this signal is to terminate the process, but it can be caught and handled.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    > I don't know if the USER/SUPERVISOR flag plays some role in this case..?
    No, why would it?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Details, assuming x86:
    There are several levels of page-table [x86 has 2, 3 or 4 depending on what the mode of the processor is]. At any of these levels, the processor can determine that the page is not accessible, which is signaled by a PAGE FAULT (PF).

    The PF handler in the kernel will look at the CR2 (virtual address being accessed) as well as the error code [this indicates the type of error/access attempted, e.g. read, write, not present or privilege violation].

    The USER bit in the page-table WILL have an effect here, since the user-mode application attempts to access an address that is [or could be] valid in the kernel-side, so the value value of CS mode bits (lower 2 bits of the CS register) will indicate whether the code is in kernel mode or user-mode. The page-table entry will say if the page is allowed to be accessed in user-mode or only kernel-mode. So if the page is valid, the kernel would have set it as "kernel only".

    As discussed, if the PF handle determines that the page should not be used by user-mode, then it will issue a SEGV signal to the user-app.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some question asking for answer...
    By mat13mat in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2008, 03:40 AM
  2. C++ Question with uncomplete answer..anyone can solve it?
    By jason07 in forum C++ Programming
    Replies: 9
    Last Post: 09-13-2005, 04:56 PM
  3. Please Answer My Question:
    By DeanDemon in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2002, 12:50 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM