populate ELF header information on the initial stack so that glibc can set up TLS properly

This commit is contained in:
Balazs Gerofi bgerofi@riken.jp
2012-10-09 00:51:50 +09:00
parent f1da972bb7
commit 9a8449df2b
7 changed files with 67 additions and 8 deletions

View File

@@ -60,6 +60,8 @@ struct program_load_desc *load_elf(FILE *fp)
Elf64_Phdr phdr;
int i, j, nhdrs = 0;
struct program_load_desc *desc;
unsigned long load_addr = 0;
int load_addr_set = 0;
if (fread(&hdr, sizeof(hdr), 1, fp) < 1) {
__eprint("Cannot read Ehdr.\n");
@@ -103,11 +105,20 @@ struct program_load_desc *load_elf(FILE *fp)
desc->sections[j].offset,
desc->sections[j].len);
j++;
if (!load_addr_set) {
load_addr_set = 1;
load_addr = phdr.p_vaddr - phdr.p_offset;
}
}
}
desc->pid = getpid();
desc->entry = hdr.e_entry;
desc->at_phdr = load_addr + hdr.e_phoff;
desc->at_phent = sizeof(phdr);
desc->at_phnum = hdr.e_phnum;
return desc;
}

View File

@@ -31,6 +31,9 @@ struct program_load_desc {
int pid;
unsigned long entry;
unsigned long rprocess;
unsigned long at_phdr;
unsigned long at_phent;
unsigned long at_phnum;
char *args;
unsigned long args_len;
char *envs;