From: 张琳 <zhanglin_nk@tom.com>
To: xen-devel@lists.xensource.com
Subject: The address in xen
Date: Mon, 17 Mar 2008 18:35:27 +0800 (CST) [thread overview]
Message-ID: <47DE496F.00014A.10457@bjapp32> (raw)
[-- 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
next reply other threads:[~2008-03-17 10:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-17 10:35 张琳 [this message]
2008-03-17 13:44 ` The address in xen weiming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47DE496F.00014A.10457@bjapp32 \
--to=zhanglin_nk@tom.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.