How to print kernel stack's lower and upper address in linux for process using pid and without using pid

313 Views Asked by At

How to print kernel stack's lower and upper address in linux for each process process

  1. using pid and
  2. without using pid
1

There are 1 best solutions below

0
On

You may want to understand into the current_stack_pointer() code. (for the slightly older kernels, now the stack size has been increased to 16K)

The kernel stack starts on top of the page and increases downwards, %esp on x86 points (or %rsp on x86_64) to the bottom of stack. You can also derive the current macro as follows

current macro == current_thread_info(%esp)->task
current->pid == (current_thread_info(%esp)->task)->pid

As you know the bottom of the stack, you need to add/subtract the number of pages to get the top of the kernel stack (using %esp or %rsp depends on your arch).