Subversion Repositories HelenOS

Rev

Rev 3007 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3007 Rev 3222
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 108... Line 109...
108
    for (i = 0; i < header->e_phnum; i++) {
109
    for (i = 0; i < header->e_phnum; i++) {
109
        elf_segment_header_t *seghdr;
110
        elf_segment_header_t *seghdr;
110
 
111
 
111
        seghdr = &((elf_segment_header_t *)(((uint8_t *) header) +
112
        seghdr = &((elf_segment_header_t *)(((uint8_t *) header) +
112
            header->e_phoff))[i];
113
            header->e_phoff))[i];
113
        rc = segment_header(seghdr, header, as);
114
        rc = segment_header(seghdr, header, as, flags);
114
        if (rc != EE_OK)
115
        if (rc != EE_OK)
115
            return rc;
116
            return rc;
116
    }
117
    }
117
 
118
 
118
    /* Inspect all section headers and proccess them. */
119
    /* Inspect all section headers and proccess them. */
Line 149... Line 150...
149
 * @param as Address space into wich the ELF is being loaded.
150
 * @param as Address space into wich the ELF is being loaded.
150
 *
151
 *
151
 * @return EE_OK on success, error code otherwise.
152
 * @return EE_OK on success, error code otherwise.
152
 */
153
 */
153
static int segment_header(elf_segment_header_t *entry, elf_header_t *elf,
154
static int segment_header(elf_segment_header_t *entry, elf_header_t *elf,
154
    as_t *as)
155
    as_t *as, int flags)
155
{
156
{
-
 
157
    char *interp;
-
 
158
 
156
    switch (entry->p_type) {
159
    switch (entry->p_type) {
157
    case PT_NULL:
160
    case PT_NULL:
158
    case PT_PHDR:
161
    case PT_PHDR:
159
        break;
162
        break;
160
    case PT_LOAD:
163
    case PT_LOAD:
161
        return load_segment(entry, elf, as);
164
        return load_segment(entry, elf, as);
162
        break;
165
        break;
163
    case PT_DYNAMIC:
166
    case PT_DYNAMIC:
164
    case PT_INTERP:
167
    case PT_INTERP:
-
 
168
        interp = (char *)elf + entry->p_offset;
-
 
169
        /* FIXME */
-
 
170
        /*if (memcmp((uintptr_t)interp, (uintptr_t)ELF_INTERP_ZSTR,
-
 
171
            ELF_INTERP_ZLEN) != 0) {
-
 
172
            return EE_UNSUPPORTED;
-
 
173
        }*/
-
 
174
        if ((flags & ELD_F_LOADER) == 0) {
-
 
175
            return EE_LOADER;
-
 
176
        }
-
 
177
        break;
165
    case PT_SHLIB:
178
    case PT_SHLIB:
166
    case PT_NOTE:
179
    case PT_NOTE:
167
    case PT_LOPROC:
180
    case PT_LOPROC:
168
    case PT_HIPROC:
181
    case PT_HIPROC:
169
    default:
182
    default: