4

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

jianxi sun
  • 340
  • 1
  • 19
  • 1
    Good question, especially in this day and age of ASR... – fge Jan 09 '13 at 11:46
  • Why do you ask? From which point of view: from inside the kernel, or from user-land applications? – Basile Starynkevitch Jan 09 '13 at 12:01
  • I'm really surprised about this question receiving such a big score. I don't feel it shows prior research on the subject.... – Basile Starynkevitch Jan 09 '13 at 14:50
  • 1
    More it's based on a misunderstanding of what happens. The kernel does not convert virtual address for the MMU, rather then MMU converts them for the kernel, user mode programs, etc according to context-specific mappings which the kernel has set up for each case. – Chris Stratton Jan 09 '13 at 18:00

1 Answers1

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Did you mean linux kernel will map the elf segments to virtual address.And the virtual address can be parsed by MMU? – jianxi sun Jan 09 '13 at 14:31
  • Please take time to read the references I gave you. It seems that you have a fuzzy idea of how a processor and an operating system kernel works. Take time to read several books about processor architecture and operating system principles. – Basile Starynkevitch Jan 09 '13 at 14:35
  • 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 – jianxi sun Jan 10 '13 at 02:49
  • 1
    This is not correct. The OS must load the executable into the physical RAM in order for it be available for the CPU to be executed. Paging just creates a virtual->physical mapping in a nutshell. Therefore, the OS reads the ELF structure and the ELF knows where it wants to be, so the OS loads it anywhere in the physical space, but maps it into the correct area of the virtual space. – Levente Kurusa Oct 28 '13 at 06:28