Core address

I have a question when I found the address in the kernel. I insert the hello module into the kernel, in this module I add the following things:

char mystring[]="this is my address"; printk("<1>The address of mystring is %p",virt_to_phys(mystring)); 

I think I can get the physical address of mystring, but I found that in syslog its printed address is 0x38dd0000. However, I dumped the memory and found that the real address is dcd2a000, which is very different from the previous one. How to explain this? Did I do something wrong? Thanks

PS: I used a tool to reset all memory, physical addresses.

+7
source share
1 answer

According to user page VIRT_TO_PHYS

The returned physical address is the physical (CPU) mapping for the specified memory address. Valid only for using this function on addresses directly mapped or distributed via kmalloc.

This function does not provide bus mappings for DMA transmission. In almost all possible cases, the device driver should not use this function.

Try allocating memory for mystring with kmalloc ;

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

Here is the strcpy implementation found here :

 char *strcpy(char *dest, const char *src) { char *tmp = dest; while ((*dest++ = *src++) != '\0') /* nothing */; return tmp; } 
+7
source

All Articles