How convert address in elf to physical address

孤者浪人 提交于 2020-01-13 11:05:27

问题


I know os will load elf in physical memory. When execute jmp elf-address,system will check tlb and convert the elf-address to physical address. I am confused that elf-address does not have segment num and page num? How os convert elf-address to what MMU need.

I'm really confused that. I know linux will read header of elf and map elf. When page fault happened,kernel will load elf in memory and refresh page table. But you konw elf address is like 0x0804900. If we want to exe jmp elf-address ,how kernel map the elf-address to address which MMU can use. You know MMU address is based on segment num and page num.

Is there a map table which os will look for? And when exec jmp elf-address, will os first map elf-address to MMU address? eg: elf-address <==> MMU-address


回答1:


I don't really think that a Linux kernel, when execve(2) some binary ELF executable, is loading that file into physical RAM.

It is just mapping some ELF segments of the file into the process' address space. You can get an idea of the address space of process 1234 by reading, e.g. with cat command, the pseudo file /proc/1234/maps; Try the command cat /proc/self/maps which shows the memory map of the process running that cat.

So basically what execve(2) does is some sort of memory mapping, like mmap(2) does. It sets the MMU so any initial access to something would fault the memory address, and then the kernel would load (page-in in demand paging) some pages from the file. Read about virtual memory & memory management.

You really should read books like Advanced Linux Programming

As FGE commented, there is the issue of ASLR.



来源:https://stackoverflow.com/questions/14234448/how-convert-address-in-elf-to-physical-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!