[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] The address in xen


  • To: "张琳" <zhanglin_nk@xxxxxxx>
  • From: weiming <zephyr.zhao@xxxxxxxxx>
  • Date: Mon, 17 Mar 2008 09:44:22 -0400
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 17 Mar 2008 06:44:51 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=cH9yJOGbuHiALVM+8TQNC2TcdBn8ewLoJKyYbgAKUq0uCXJ2NwA8k/p15K/iJzfwNP5aUiu8/FlfFmAItXvb1S7DKFzflom5uMI58EGFCfLEhhpNSgBYFZcHQpZEy0lDbvYBsIyRGx1o7SAIeuduDZNUmH6hfs3ewU/Qc9b0NwY=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

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@xxxxxxx>:
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;
}






===============================================
快来和我一起享受TOM免费邮箱吧! 看看除了1.5G,还有什么?

看看女人都在聊什么? 美图尽赏 聊天世界

明星金曲免费送(http://mm.tom.com/ivr/):周杰伦 林俊杰 庞龙 张惠妹

劲爆歌曲尽情点(http://mm.tom.com/ivr/):霍元甲 吉祥三宝 人质 曹操

炫酷彩铃免费送(http://mm.tom.com/cailing/):周杰伦帮你接电话 麻烦女朋友 七里香 小城故事
===============================================

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.