1

I have a question when I located the address in kernel. I insert a hello module in kernel, in this module, I used this solution.

For now I can use kmalloc to achieve the address by virt_to_phys.

char *mystring = kmalloc(19, GFP_KERNEL);
strcpy(mystring, "this is my address"); 
printk("<1>The address of mystring is %p", virt_to_phys(mystring));

But I want to know how to find the address of char mystring[]="this is my address";. This is no heap allocated memory, right? How to find it by some functions?

PS: I used a tool to dump the whole memory, physical addresses.

Community
  • 1
  • 1
Alex
  • 869
  • 3
  • 13
  • 20
  • Stack addresses are still virtual memory addresses. Kernel thread stacks really aren't any different from any other memory, they're allocated form the "heap" (if you can call it that) as well. – pmdj Jun 14 '12 at 20:07
  • Okay, but I cannot use `virt_to_phys` to find the address of mystring, the printed address is not matched. – Alex Jun 14 '12 at 20:16
  • If you've got `char str[]="some string";` in a function, the function will allocate stack memory to hold the string, and then usually copy the string from a data segment. If you're taking a memory image, you're probably detecting the copy of the string in the data segment, not the one on the stack, yet you're looking up the physical address of the stack copy. – pmdj Jun 15 '12 at 12:07

0 Answers0