c - The address in Kernel -
i have question when located address in kernel. insert hello module in kernel, in module, put these things:
char mystring[]="this address"; printk("<1>the address of mystring %p",virt_to_phys(mystring));
i think can physical address of mystring, found is, in syslog, printed address of 0x38dd0000. however, dumped memory , found real address of dcd2a000, quite different former one. how explain this? did wrong? thanks
ps: used tool dump whole memory, physical addresses.
according man page of virt_to_phys
the returned physical address physical (cpu) mapping memory address given. it valid use function on addresses directly mapped or allocated via kmalloc.
this function not give bus mappings dma transfers. in conceivable cases device driver should not using function
try allocating memory mystring
using kmalloc
first;
char *mystring = kmalloc(19, gfp_kernel); strcpy(mystring, "this address"); //use kernel implementation of strcpy printk("<1>the address of mystring %p", virt_to_phys(mystring)); kfree(mystring);
here implementation of strcpy found here:
char *strcpy(char *dest, const char *src) { char *tmp = dest; while ((*dest++ = *src++) != '\0') /* nothing */; return tmp; }
Comments
Post a Comment