Find the answer to your Linux question:
Results 1 to 4 of 4
I would like to have a look at user-mode stack when an application is in kernel mode using kprobes or just some printk statements in the source. The main idea ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    2

    User mode information


    I would like to have a look at user-mode stack when an application is in kernel mode using kprobes or just some printk statements in the source. The main idea is to know what my application was doing when a context switch is about to happen (e.g in schedule() method). Now, I know that in kernel mode stack/address space is switched from the user mode to kernel. So, I tried doing something like this but now sure if it should work or there is any other easy way to do this.

    - user_stack = current->mm->start_task
    - get_user_pages(..., user_stack, ...., pages)
    - unsigned long addr = page_to_phys(page)

    Any help or hint will be greatly appreciated. Thanks

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    The stack pointer(user stack pointer) is saved in the kernel stack during the switch..Check the Intel/AMD manuals for details...G4143

    Note this applies to Intel/AMD 32 bit
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    2
    The hard part seems to be accessing physical memory containing this stack pointer. Any idea?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by phyizal View Post
    The hard part seems to be accessing physical memory containing this stack pointer. Any idea?
    If your operating in kernel mode you literally dereference the stack pointer to the point at which the user stack(user %esp) is saved. Once you have the value for the user %esp you have the the user stack...you shouldn't have to deal with physical memory even if you did the processor couldn't translate it(physical memory) while paging is enabled...G4143
    Make mine Arch Linux

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •