* The address in xen
@ 2008-03-17 10:35 张琳
2008-03-17 13:44 ` weiming
0 siblings, 1 reply; 2+ messages in thread
From: 张琳 @ 2008-03-17 10:35 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 3229 bytes --]
It seems that the address in xen has three layer: the virtual address , the pesurdo-physical address and the machine address.
I obtained some addresses of kernel symbols by parsing the system.map file.
I think this address is virtual address.Is it correct?
Then I want to calculate the hash value of memory area start from those addresses. So I have to access the corresponding machine address.
Then problem came.
How to translate the virtual address to machine address?
First, I want to translate the virtual address to pesurdo-physical address by traversing page table tree. But segmentation fault always occurs.
I put my code in the following~~~
Can anyone tell me that what is wrong?
unsigned long VAtoPA(unsigned long VirtualAddress)
{
/*This variable is used for storing the address of
the Page Directory.*/
unsigned long PDAddress;
/*This variable is a pointer pointing to the entry
in the page directory which contains the address
of the Page Table.*/
unsigned long* pPTAddress;
/*This variable is used for storing the address of
the Page Table.*/
unsigned long PTAddress;
/*This variable is a pointer pointing to the entry
in the page table which contains the address of
the physical page.*/
unsigned long* pPPAddress;
/*This variable is used for storing the address of
the physical page.*/
unsigned long PPAddress;
/*This is physical address for the corresponding
virtual address.*/
unsigned long PhysicalAddress;
/*Get the address of the Page Directory from CR3*/
int xc_handle = xc_interface_open();
if(xc_handle == -1)
{
printf("Sorry! Cannot open an interface on xen
hypervisor, please check that whether
the xen is running or not!\n");
exit(1);
}
vcpu_guest_context_t context;
int result = xc_vcpu_getcontext(xc_handle,
1, 0, &context);
if(result == -1)
{
printf("Sorry! Cannot get the context of the
virtual CPU-1 in domain-1, please check
that whether the domain-1 is running or
not!\n");
exit(1);
}
PDAddress = context.ctrlreg[3] & 0xFFFFF000;
int index;
/*Get the index number in Page Directory.*/
index = VirtualAddress >> 22;
/*Get the address of the entry which contains the
address of the Page Table.*/
pPTAddress = PDAddress + (index << 2);
/*Get the address of the Page Table*/
PTAddress = (*pPTAddress) & 0xFFFFF000;
/*Get the index number in Page Table.*/
index = (VirtualAddress >> 12) & 0x000003FF;
/*Get the address of the entry which contains the
address of the physical page.*/
pPPAddress = PTAddress + (index << 2);
/*Get the address of the physical page.*/
PPAddress = (*pPPAddress) & 0xFFFFF000;
PhysicalAddress = PPAddress + (VirtualAddress & 0x00000FFF);
result = xc_interface_close(xc_handle);
if(result == -1)
{
printf("Sorry! Cannot close the special
interface on xen hypervisor!\n");
exit(1);
}
return PhysicalAddress;
}
[-- Attachment #1.2: Type: text/html, Size: 6648 bytes --]
[-- Attachment #2: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: The address in xen
2008-03-17 10:35 The address in xen 张琳
@ 2008-03-17 13:44 ` weiming
0 siblings, 0 replies; 2+ messages in thread
From: weiming @ 2008-03-17 13:44 UTC (permalink / raw)
To: 张琳; +Cc: xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 5318 bytes --]
In the xen kernel, there's existing functions/macros to convert between
these addresses.
Your calculation may be not correct. Every address stored in the page
table/directory is machine address. But your pointer should use virtual
address to access them.
weiming
2008/3/17 张琳 <zhanglin_nk@tom.com>:
> It seems that the address in xen has three layer: the virtual address ,
> the pesurdo-physical address and the machine address.
>
> I obtained some addresses of kernel symbols by parsing the system.mapfile.
> I think this address is virtual address.Is it correct?
> Then I want to calculate the hash value of memory area start from those
> addresses. So I have to access the corresponding machine address.
>
> Then problem came.
> How to translate the virtual address to machine address?
>
> First, I want to translate the virtual address to pesurdo-physical address
> by traversing page table tree. But segmentation fault always occurs.
>
> I put my code in the following~~~
> Can anyone tell me that what is wrong?
>
> unsigned long VAtoPA(unsigned long VirtualAddress)
> {
> /*This variable is used for storing the address of
> the Page Directory.*/
> unsigned long PDAddress;
>
> /*This variable is a pointer pointing to the entry
> in the page directory which contains the address
> of the Page Table.*/
> unsigned long* pPTAddress;
>
> /*This variable is used for storing the address of
> the Page Table.*/
> unsigned long PTAddress;
>
> /*This variable is a pointer pointing to the entry
> in the page table which contains the address of
> the physical page.*/
> unsigned long* pPPAddress;
>
> /*This variable is used for storing the address of
> the physical page.*/
> unsigned long PPAddress;
>
> /*This is physical address for the corresponding
> virtual address.*/
> unsigned long PhysicalAddress;
>
> /*Get the address of the Page Directory from CR3*/
> int xc_handle = xc_interface_open();
> if(xc_handle == -1)
> {
> printf("Sorry! Cannot open an interface on xen
> hypervisor, please check that whether
> the xen is running or not!\n");
> exit(1);
> }
>
> vcpu_guest_context_t context;
> int result = xc_vcpu_getcontext(xc_handle,
> 1, 0, &context);
> if(result == -1)
> {
> printf("Sorry! Cannot get the context of the
> virtual CPU-1 in domain-1, please check
> that whether the domain-1 is running or
> not!\n");
> exit(1);
> }
> PDAddress = context.ctrlreg[3] & 0xFFFFF000;
>
> int index;
> /*Get the index number in Page Directory.*/
> index = VirtualAddress >> 22;
> /*Get the address of the entry which contains the
> address of the Page Table.*/
> pPTAddress = PDAddress + (index << 2);
> /*Get the address of the Page Table*/
> PTAddress = (*pPTAddress) & 0xFFFFF000;
> /*Get the index number in Page Table.*/
> index = (VirtualAddress >> 12) & 0x000003FF;
> /*Get the address of the entry which contains the
> address of the physical page.*/
> pPPAddress = PTAddress + (index << 2);
> /*Get the address of the physical page.*/
> PPAddress = (*pPPAddress) & 0xFFFFF000;
>
> PhysicalAddress = PPAddress + (VirtualAddress & 0x00000FFF);
>
>
> result = xc_interface_close(xc_handle);
> if(result == -1)
> {
> printf("Sorry! Cannot close the special
> interface on xen hypervisor!\n");
> exit(1);
> }
>
> return PhysicalAddress;
> }
>
>
>
>
>
>
> ===============================================
> 快来和我一起享受TOM免费邮箱吧! 看看除了1.5G,还有什么?<http://bjcgi.163.net/cgi-bin/newreg.cgi?%0Arf=050602>
>
> <http://vip.tom.com/info/ggd_060301/index_tmail.html> 看看女人都在聊什么?<http://bbs.lady.tom.com/bbs.php?forumid=703>
> 美图尽赏 <http://pic.tom.com/> 聊天世界<http://bbs.news.tom.com/bbs.php?forumid=697>
>
> 明星金曲免费送(http://mm.tom.com/ivr/):周杰伦<http://fs.tom.com/ivr/search_ivrring.php?SingerName=%E5%91%A8%E6%9D%B0%E4%BC%A6&user_id=3&code_id=000000>
> 林俊杰<http://fs.tom.com/ivr/search_ivrring.php?SingerName=%E6%9E%97%E4%BF%8A%E6%9D%B0&user_id=3&code_id=000000>
> 庞龙<http://fs.tom.com/ivr/search_ivrring.php?SingerName=%E5%BA%9E%E9%BE%99&user_id=3&code_id=000000>
> 张惠妹<http://fs.tom.com/ivr/search_ivrring.php?SingerName=%E5%BC%A0%E6%83%A0%E5%A6%B9&user_id=3&code_id=000000>
>
> 劲爆歌曲尽情点(http://mm.tom.com/ivr/):霍元甲<http://fs.tom.com/ivr/send_step1.php?Id=39244&user_id=3&code_id=w555>
> 吉祥三宝<http://fs.tom.com/ivr/send_step1.php?Id=38397&user_id=3&code_id=w555>
> 人质 <http://fs.tom.com/ivr/send_step1.php?Id=39335&user_id=3&code_id=w555>
> 曹操 <http://fs.tom.com/ivr/send_step1.php?Id=39325&user_id=3&code_id=w555>
>
> 炫酷彩铃免费送(http://mm.tom.com/cailing/):周杰伦帮你接电话<http://fs.tom.com/cailing/search.php?CurPage=1&user_id=3&Catalog=&phone_num=&SearchBy=ring&Keyword=%D6%DC%BD%DC%C2%D7%B0%EF%C4%E3%BD%D3%B5%E7%BB%B0>
> 麻烦女朋友<http://fs.tom.com/cailing/search.php?CurPage=1&user_id=3&Catalog=&phone_num=&SearchBy=ring&Keyword=%C2%E9%B7%B3%C5%AE%C5%F3%D3%D1>
> 七里香<http://fs.tom.com/cailing/search.php?CurPage=1&user_id=3&Catalog=&phone_num=&SearchBy=ring&Keyword=%C6%DF%C0%EF%CF%E3>
> 小城故事<http://fs.tom.com/cailing/search.php?CurPage=1&user_id=3&Catalog=&phone_num=&SearchBy=ring&Keyword=%D0%A1%B3%C7%B9%CA%CA%C2>
> ===============================================
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
>
[-- Attachment #1.2: Type: text/html, Size: 7366 bytes --]
[-- Attachment #2: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-03-17 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-17 10:35 The address in xen 张琳
2008-03-17 13:44 ` weiming
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.