提交 53d7ac6f 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

dl_iterate_phdr

上级 3f3c2501
...@@ -33,7 +33,7 @@ multiboot_header: ...@@ -33,7 +33,7 @@ multiboot_header:
.long flags .long flags
.long (- magic - flags) # checksum .long (- magic - flags) # checksum
.long PADDR(multiboot_header) # header address .long PADDR(multiboot_header) # header address
.long PADDR(multiboot_header) # load address .long PADDR(multiboot_header)-0x1000 # load address, incl elf headers
.long PADDR(edata) # load end address .long PADDR(edata) # load end address
.long PADDR(end) # bss end address .long PADDR(end) # bss end address
.long PADDR(start) # entry address .long PADDR(start) # entry address
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "condvar.h" #include "condvar.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
#include "elf.hh"
void* void*
operator new(unsigned long nbytes) operator new(unsigned long nbytes)
...@@ -159,11 +160,34 @@ free(void* vp) ...@@ -159,11 +160,34 @@ free(void* vp)
kmfree(p-1, p[-1]+8); kmfree(p-1, p[-1]+8);
} }
extern "C" int dl_iterate_phdr(void); struct dl_phdr_info {
Elf64_Addr dlpi_addr;
const char *dlpi_name;
const struct proghdr *dlpi_phdr;
Elf64_Half dlpi_phnum;
unsigned long long int dlpi_adds;
unsigned long long int dlpi_subs;
};
extern "C" int dl_iterate_phdr(int (*cb) (struct dl_phdr_info *info,
size_t size, void *data),
void *data);
int int
dl_iterate_phdr(void) dl_iterate_phdr(int (*cb) (struct dl_phdr_info *info, size_t size, void *data),
{ void *data)
return -1; {
extern char multiboot_header[];
elfhdr *eh = (elfhdr*) &multiboot_header[-0x1000];
assert(eh->magic == ELF_MAGIC);
struct dl_phdr_info info;
info.dlpi_addr = 0;
info.dlpi_name = "kernel";
info.dlpi_phdr = (proghdr*) (((char*) eh) + eh->phoff);
info.dlpi_phnum = eh->phnum;
info.dlpi_adds = 0;
info.dlpi_subs = 0;
return cb(&info, sizeof(struct dl_phdr_info), data);
} }
extern "C" void __stack_chk_fail(void); extern "C" void __stack_chk_fail(void);
......
...@@ -4,9 +4,12 @@ ENTRY(xxx) ...@@ -4,9 +4,12 @@ ENTRY(xxx)
SECTIONS SECTIONS
{ {
. = 0xFFFFFFFFC0100000; /* Skip one page to leave room for ELF headers.
* See multiboot_header and dl_iterate_phdr.
*/
. = 0xFFFFFFFFC0101000;
PROVIDE(text = .); PROVIDE(text = .);
.text : AT(0x100000) { .text : AT(0x101000) {
*(.text .stub .text.* .gnu.linkonce.t.*) *(.text .stub .text.* .gnu.linkonce.t.*)
} }
.rodata : { .rodata : {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论