Rev 2927 | Rev 3009 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2927 | Rev 3001 | ||
|---|---|---|---|
| Line 55... | Line 55... | ||
| 55 | "unsupported image type", |
55 | "unsupported image type", |
| 56 | "irrecoverable error" |
56 | "irrecoverable error" |
| 57 | }; |
57 | }; |
| 58 | 58 | ||
| 59 | static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, |
59 | static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, |
| 60 | as_t *as); |
60 | as_t *as, int flags); |
| 61 | static int section_header(elf_section_header_t *entry, elf_header_t *elf, |
61 | static int section_header(elf_section_header_t *entry, elf_header_t *elf, |
| 62 | as_t *as); |
62 | as_t *as); |
| 63 | static int load_segment(elf_segment_header_t *entry, elf_header_t *elf, |
63 | static int load_segment(elf_segment_header_t *entry, elf_header_t *elf, |
| 64 | as_t *as); |
64 | as_t *as); |
| 65 | 65 | ||
| 66 | /** ELF loader |
66 | /** ELF loader |
| 67 | * |
67 | * |
| 68 | * @param header Pointer to ELF header in memory |
68 | * @param header Pointer to ELF header in memory |
| 69 | * @param as Created and properly mapped address space |
69 | * @param as Created and properly mapped address space |
| - | 70 | * @param flags A combination of ELD_F_* |
|
| 70 | * @return EE_OK on success |
71 | * @return EE_OK on success |
| 71 | */ |
72 | */ |
| 72 | unsigned int elf_load(elf_header_t *header, as_t * as) |
73 | unsigned int elf_load(elf_header_t *header, as_t * as, int flags) |
| 73 | { |
74 | { |
| 74 | int i, rc; |
75 | int i, rc; |
| 75 | 76 | ||
| 76 | /* Identify ELF */ |
77 | /* Identify ELF */ |
| 77 | if (header->e_ident[EI_MAG0] != ELFMAG0 || |
78 | if (header->e_ident[EI_MAG0] != ELFMAG0 || |
| Line 104... | Line 105... | ||
| 104 | for (i = 0; i < header->e_phnum; i++) { |
105 | for (i = 0; i < header->e_phnum; i++) { |
| 105 | elf_segment_header_t *seghdr; |
106 | elf_segment_header_t *seghdr; |
| 106 | 107 | ||
| 107 | seghdr = &((elf_segment_header_t *)(((uint8_t *) header) + |
108 | seghdr = &((elf_segment_header_t *)(((uint8_t *) header) + |
| 108 | header->e_phoff))[i]; |
109 | header->e_phoff))[i]; |
| 109 | rc = segment_header(seghdr, header, as); |
110 | rc = segment_header(seghdr, header, as, flags); |
| 110 | if (rc != EE_OK) |
111 | if (rc != EE_OK) |
| 111 | return rc; |
112 | return rc; |
| 112 | } |
113 | } |
| 113 | 114 | ||
| 114 | /* Inspect all section headers and proccess them. */ |
115 | /* Inspect all section headers and proccess them. */ |
| Line 145... | Line 146... | ||
| 145 | * @param as Address space into wich the ELF is being loaded. |
146 | * @param as Address space into wich the ELF is being loaded. |
| 146 | * |
147 | * |
| 147 | * @return EE_OK on success, error code otherwise. |
148 | * @return EE_OK on success, error code otherwise. |
| 148 | */ |
149 | */ |
| 149 | static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, |
150 | static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, |
| 150 | as_t *as) |
151 | as_t *as, int flags) |
| 151 | { |
152 | { |
| - | 153 | char *interp; |
|
| - | 154 | ||
| 152 | switch (entry->p_type) { |
155 | switch (entry->p_type) { |
| 153 | case PT_NULL: |
156 | case PT_NULL: |
| 154 | case PT_PHDR: |
157 | case PT_PHDR: |
| 155 | break; |
158 | break; |
| 156 | case PT_LOAD: |
159 | case PT_LOAD: |
| 157 | return load_segment(entry, elf, as); |
160 | return load_segment(entry, elf, as); |
| 158 | break; |
161 | break; |
| 159 | case PT_DYNAMIC: |
162 | case PT_DYNAMIC: |
| 160 | case PT_INTERP: |
163 | case PT_INTERP: |
| - | 164 | interp = (char *)elf + entry->p_offset; |
|
| - | 165 | if (memcmp(interp, ELF_INTERP_ZSTR, ELF_INTERP_ZLEN) != 0) { |
|
| - | 166 | return EE_UNSUPPORTED; |
|
| - | 167 | } |
|
| - | 168 | if ((flags & ELD_F_LOADER) == 0) { |
|
| - | 169 | return EE_LOADER; |
|
| - | 170 | } |
|
| - | 171 | break; |
|
| 161 | case PT_SHLIB: |
172 | case PT_SHLIB: |
| 162 | case PT_NOTE: |
173 | case PT_NOTE: |
| 163 | case PT_LOPROC: |
174 | case PT_LOPROC: |
| 164 | case PT_HIPROC: |
175 | case PT_HIPROC: |
| 165 | default: |
176 | default: |