On Fri, Aug 24, 2012 at 3:14 AM, 陳韋任 (Wei-Ren Chen)
<che...@iis.sinica.edu.tw> wrote:
> Hi all,
>
>   I would like to know if there is a function in QEMU which converts
> a guest physical address into corresponding host virtual address. I
> guess cpu_physical_memory_map (exec.c) can do the job, but I have a
> few questions.
>
>   1. I am running x86 guest on a x86_64 host and using the cod below
>      to get the host virtual address, I am not sure what value of len
>      should be.
>
>         static inline void *gpa2hva(target_phys_addr_t addr)
>         {
>             target_phys_addr_t len = 4;
>             return cpu_physical_memory_map(addr, &len, 0);
>         }
>
>   2. There is a function "cpu_physical_memory_unmap", the comment
>      of it says,
>
>        Unmaps a memory region previously mapped by cpu_physical_memory_map().
>
>      That makes me not sure if I use cpu_physical_memory_map correctly,
>      does it do what I want to do?

I'd suppose the functions should be used like this:

ptr = cpu_physical_memory_map(addr, &len, 0);
/* code that uses ptr */
...
/* no need to use ptr anymore */
cpu_physical_memory_unmap(ptr, len, 0, len);
/* ptr may no longer be assumed to be valid */

>
> Regards,
> chenwj
>
> --
> Wei-Ren Chen (陳韋任)
> Computer Systems Lab, Institute of Information Science,
> Academia Sinica, Taiwan (R.O.C.)
> Tel:886-2-2788-3799 #1667
> Homepage: http://people.cs.nctu.edu.tw/~chenwj
>

Reply via email to