Re: [XenAccess-devel] How to get the code section of a process
Status: Beta
Brought to you by:
bdpayne
From: Bryan D. P. <br...@th...> - 2006-07-20 17:16:16
|
> Is it possible to print a whole section of a process > from a domain (for example the code section)? Yes... see more details below. > ----------------------------------------- > unsigned long vaddr; > ..... > > for(vaddr = taskaddr.start_code; vaddr <= > taskaddr.start_end; vaddr++) > { > memory = xa_access_user_virtual_address(&xai, > vaddr, &offset, pid); > if (NULL == memory){ > perror("failed to map memory"); > goto error_exit; > } > print_hex(memory, XA_PAGE_SIZE); > } > .... > ----------------------------------------- This is close. The problem here is that you are incrementing vaddr one byte at a time, but printing out an entire page of memory at a time. So you'll get the same page many times in a row. The xa_access_user_virtual_address function will return a pointer to the *start* of the page in memory that contains the vaddr in question. The value of <offset> will be the offset into that page where you will find vaddr. > I'm not sure if the addresses found in > "xa_linux_taskaddr_t" are page-frame identifiers or > virtual addresses. They are virtual addresses. These values are identical to what you would find in the kernel's mm_struct structure. In fact, I populate those values by copying directly from the mm_struct structure. > I've looked through the code, and I see that the > virtual address (vaddr) is first mapped to the > physical address and then to the physical frame and > then "xc_map_foreign_range" is called with the > parameter size=XC_PAGE_SIZE, and it returns a void * > (through mmap) that points to a frame. Is that true? Yes. > Or should the previous code be something like: > vaddr = taskaddr.start_code; vaddr <= > taskaddr.start_end; vaddr+=XC_PAGE_SIZE) This is closer to what you want, but not quite right. Imagine the case where the code spans multiple pages of memory. The code above will iterate through each page that holds the code, except for the last page (unless the code completely filled that page). To fix this, you need your loop termination condition to account for the fact that you'd want to print any page that has at least one byte of the relavent code on it. Ideally, I'd like for XenAccess to provide some capability for doing this. I'm thinking of a function that takes a start and end vaddr and returns the memory. Or perhaps a start vaddr and a length. Something along these lines. Until that's added to the API, you'll want to continue down the path that you're discussing. Or, if you'd like to add it to the API, I'd be happy to accept the patch :-) Cheers, bryan |