2010-02-02 69 views
1

我急於尋找一個或多或少的詳細描述,說明如何將應用程序加載到內存中,然後在Linux中執行。基本上,我想知道從ELF文件中讀取哪些信息,執行哪些系統調用,例如exec() ,直到此信息存儲在進程描述符中。在Linux中啓動應用程序

有沒有人知道一個很好的描述。谷歌博士就沒有那麼有用到目前爲止

感謝

回答

2

strace的會幫助你的系統調用,這裏就是你對自己在後臺運行strace:

 
[[email protected] httpd]# strace strace 
execve("/usr/bin/strace", ["strace"], [/* 27 vars */]) = 0 
brk(0)         = 0x9aa3000 
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7873000 
access("/etc/ld.so.preload", R_OK)  = -1 ENOENT (No such file or directory) 
open("/etc/ld.so.cache", O_RDONLY)  = 3 
fstat64(3, {st_mode=S_IFREG|0644, st_size=90632, ...}) = 0 
mmap2(NULL, 90632, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb785c000 
close(3)        = 0 
open("/lib/libc.so.6", O_RDONLY)  = 3 
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20-\\\0004\0\0\0"..., 512) = 512 
fstat64(3, {st_mode=S_IFREG|0755, st_size=2403884, ...}) = 0 
mmap2(0x5ac000, 1526120, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x5ac000 
mmap2(0x71b000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16e) = 0x71b000 
mmap2(0x71e000, 10600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x71e000 
close(3)        = 0 
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb785b000 
set_thread_area({entry_number:-1 -> 6, base_addr:0xb785b6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0 
mprotect(0x71b000, 8192, PROT_READ)  = 0 
mprotect(0x5a8000, 4096, PROT_READ)  = 0 
munmap(0xb785c000, 90632)    = 0 
brk(0)         = 0x9aa3000 
brk(0x9ac4000)       = 0x9ac4000 
write(2, "usage: strace [-dffhiqrtttTvVxx]"..., 1655usage: strace [-dffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file] 

0

你可以在開始內核源碼樹位於文件fs/binfmt_elf.c中,並從那裏開始工作(可能是up)。 它包含SVR4 ELF加載程序。

如果這是另一個加載器,我想它應該在同一個區域。

0

不實用作爲第一篇文章,但我發現下面的文章是偉大的,當我需要獲得大畫面:

http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html

http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory

http://duartes.org/gustavo/blog/post/how-the-kernel-manages-your-memory

寫過最後兩篇文章的人Gustavo Duarte的博客也充滿了關於操作系統的大量一般信息。我強烈建議閱讀它。