簡體   English   中英

內核中的地址

[英]The address in Kernel

當我在內核中找到地址時,我有一個問題。 我在內核中插入了一個hello模塊,在這個模塊中,我把這些東西:

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

我想我可以得到mystring的物理地址,但我發現,在syslog中,它的打印地址是0x38dd0000。 但是,我傾倒了內存並發現它的真實地址是dcd2a000,這與前一個完全不同。 怎么解釋這個? 我做錯事情了? 謝謝

PS:我用一個工具來轉儲整個內存,物理地址。

根據VIRT_TO_PHYSMan頁面

返回的物理地址是給定內存地址的物理(CPU)映射。 僅在通過kmalloc直接映射或分配的地址上使用此功能才有效。

此函數不提供DMA傳輸的總線映射。 在幾乎所有可能的情況下,設備驅動程序都不應該使用此功能

首先嘗試使用kmallocmystring分配內存;

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);

這是strcpy的一個實現,在這里找到:

char *strcpy(char *dest, const char *src)
{
    char *tmp = dest;

    while ((*dest++ = *src++) != '\0')
            /* nothing */;
    return tmp;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM