在内核中的地址 [英] The address in Kernel

查看:137
本文介绍了在内核中的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,当我设在内核中的地址的问题。我插入一个hello模块中的内核,在这个模块中,我把这些东西:

I have a question when I located the address in kernel. I insert a hello module in kernel, in this module, I put these things:

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

我想我可以得到MyString的物理地址,但我发现,在系统日志,它的打印地址是0x38dd0000。然而,我甩存储器,发现真实地址是dcd2a000,这是从前者有很大不同。这怎么解释?我做错了什么?谢谢

I think I can get the physical address of mystring, but what I found is, in syslog, the printed address of it is 0x38dd0000. However, I dumped the memory and found the real address of it is dcd2a000, which is quite different from the former one. How to explain this? I did something wrong? Thanks

PS:我使用的工具来转储整个内存,物理地址

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

推荐答案

按照<一个href=\"http://mirror.linux.org.au/linux.conf.au/2005/cdrom-beta-1/linux-mandocs-2.6.12.6/virt_to_phys.html\">Man VIRT_TO_PHYS 的页

返回的物理地址是对给定的存储器地址的物理(CPU)的映射。 这是唯一有效的使用直接映射或通过kmalloc进行分配的地址本功能。

The returned physical address is the physical (CPU) mapping for the memory address given. It is only valid to use this function on addresses directly mapped or allocated via kmalloc.

这个功能没有给出DMA传输总线的映射。在几乎所有可以想象的情况下,设备驱动程序不应该使用此功能。

This function does not give bus mappings for DMA transfers. In almost all conceivable cases a device driver should not be using this function

尝试使用的myString 分配内存的kmalloc 第一;

Try allocating the memory for mystring using kmalloc first;

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在实施中发现这里

Here is an implementation of strcpy found here:

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

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

这篇关于在内核中的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆