elf_map: why offset of vma need to subtract eppnt->p_vaddr ?

Prabhu nath gprabhunath at gmail.com
Fri Mar 29 05:42:25 EDT 2013


On Fri, Mar 29, 2013 at 3:03 PM, Jacky <jackyclivia at 163.com> wrote:

>
> Great ! Thanks Prabhunath.
>
> Let me make sure I understand you correctly:
>
> Substracting  ELF_PAGEOFFSET(eppnt->p_vaddr) from variable off makes vma
> map the page-aligned file contents, right ?
>

Small change : Substracting  ELF_PAGEOFFSET(eppnt->p_vaddr) from variable
eppnt->p_offset makes vma map the page-aligned file contents

>
> 在 2013-03-29 16:56:29,"Prabhu nath" <gprabhunath at gmail.com> 写道:
>
>
>
> On Fri, Mar 29, 2013 at 12:45 PM, Jacky <jackyclivia at 163.com> wrote:
>
>>  Hi All,
>>
>> When mmaping elf image into memory, why offset vma need to subtract
>> eppnt->p_vaddr as the following code ?
>>
>> static unsigned long elf_map()
>> {
>>     ...
>>     unsigned long off = eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr);
>>     ...
>> }
>>
>       Assume you have logically divided the contents of the ELF file into
> chunks of PAGE_SIZE (Typically 4K on x86). Let us name each chunk as *file
> page*-synonym to *page frame* in the physical address space and *page* in
> the virtual address space respectively.
> Here variable *off* is the *file page* base offset - synonym to page base
> address or page frame base address which are typically multiple of
> PAGE_SIZE.
>
>       off >> PAGE_SHIFT is the value stored in *vm_pgoff* in struct
> vm_area_struct
> In a nutshell vm_pgoff is the page number (*file page *number) in the ELF
> file where the corresponding PT_LOAD segment starts.
>
> Suppose if a file offset (eppnt->p_offset) of a PT_LOAD segment is 9560
> (0x2558) bytes into the file and eppnt->p_vaddr is 0x08048558. Then the
> file page number base address *off* is calculated as
>
>                off = 0x2558 - 0x558; // ELF_PAGEOFFSET(eppnt->p_vaddr)
> will expand to 0x558.
> Then off is 0x2000 and vm_pgoff is (off >> PAGE_SHIFT) = 2. This means
> that the PT_LOAD segment starts at 2nd page or 2nd file page in the ELF
> file.
>
>
> Thanks in advance.
>>
>> Jacky
>>
>
> --
> Regards,
> Prabhunath G
> Linux Trainer
> Bangalore
>
>
>
>


-- 
Regards,
Prabhunath G
Linux Trainer
Bangalore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130329/1af758a5/attachment.html 


More information about the Kernelnewbies mailing list