Subversion Repositories HelenOS

Rev

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

Rev 4338 Rev 4691
Line 72... Line 72...
72
static int segment_header(elf_ld_t *elf, elf_segment_header_t *entry);
72
static int segment_header(elf_ld_t *elf, elf_segment_header_t *entry);
73
static int section_header(elf_ld_t *elf, elf_section_header_t *entry);
73
static int section_header(elf_ld_t *elf, elf_section_header_t *entry);
74
static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry);
74
static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry);
75
 
75
 
76
/** Read until the buffer is read in its entirety. */
76
/** Read until the buffer is read in its entirety. */
77
static int my_read(int fd, char *buf, size_t len)
77
static int my_read(int fd, void *buf, size_t len)
78
{
78
{
79
    int cnt = 0;
79
    int cnt = 0;
80
    do {
80
    do {
81
        buf += cnt;
81
        buf += cnt;
82
        len -= cnt;
82
        len -= cnt;
Line 327... Line 327...
327
{
327
{
328
    void *a;
328
    void *a;
329
    int flags = 0;
329
    int flags = 0;
330
    uintptr_t bias;
330
    uintptr_t bias;
331
    uintptr_t base;
331
    uintptr_t base;
-
 
332
    void *seg_ptr;
-
 
333
    uintptr_t seg_addr;
332
    size_t mem_sz;
334
    size_t mem_sz;
333
    int rc;
335
    int rc;
334
 
336
 
335
    DPRINTF("Load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,
-
 
336
        entry->p_memsz);
-
 
337
   
-
 
338
    bias = elf->bias;
337
    bias = elf->bias;
339
 
338
 
-
 
339
    seg_addr = entry->p_vaddr + bias;
-
 
340
    seg_ptr = (void *) seg_addr;
-
 
341
 
-
 
342
    DPRINTF("Load segment at addr 0x%x, size 0x%x\n", seg_addr,
-
 
343
        entry->p_memsz);   
-
 
344
 
340
    if (entry->p_align > 1) {
345
    if (entry->p_align > 1) {
341
        if ((entry->p_offset % entry->p_align) !=
346
        if ((entry->p_offset % entry->p_align) !=
342
            (entry->p_vaddr % entry->p_align)) {
347
            (seg_addr % entry->p_align)) {
343
            DPRINTF("Align check 1 failed offset%%align=%d, "
348
            DPRINTF("Align check 1 failed offset%%align=%d, "
344
                "vaddr%%align=%d\n",
349
                "vaddr%%align=%d\n",
345
                entry->p_offset % entry->p_align,
350
                entry->p_offset % entry->p_align,
346
                entry->p_vaddr % entry->p_align
351
                seg_addr % entry->p_align
347
            );
352
            );
348
            return EE_INVALID;
353
            return EE_INVALID;
349
        }
354
        }
350
    }
355
    }
351
 
356
 
Line 360... Line 365...
360
    flags |= AS_AREA_CACHEABLE;
365
    flags |= AS_AREA_CACHEABLE;
361
   
366
   
362
    base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE);
367
    base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE);
363
    mem_sz = entry->p_memsz + (entry->p_vaddr - base);
368
    mem_sz = entry->p_memsz + (entry->p_vaddr - base);
364
 
369
 
365
    DPRINTF("Map to p_vaddr=0x%x-0x%x.\n", entry->p_vaddr + bias,
370
    DPRINTF("Map to seg_addr=0x%x-0x%x.\n", seg_addr,
366
    entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
371
    entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
367
 
372
 
368
    /*
373
    /*
369
     * For the course of loading, the area needs to be readable
374
     * For the course of loading, the area needs to be readable
370
     * and writeable.
375
     * and writeable.
Line 376... Line 381...
376
            base+bias, mem_sz);
381
            base+bias, mem_sz);
377
        return EE_MEMORY;
382
        return EE_MEMORY;
378
    }
383
    }
379
 
384
 
380
    DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
385
    DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
381
        entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a);
386
        base + bias, mem_sz, flags, (uintptr_t)a);
382
 
387
 
383
    /*
388
    /*
384
     * Load segment data
389
     * Load segment data
385
     */
390
     */
386
    rc = lseek(elf->fd, entry->p_offset, SEEK_SET);
391
    rc = lseek(elf->fd, entry->p_offset, SEEK_SET);
Line 396... Line 401...
396
 
401
 
397
    unsigned left, now;
402
    unsigned left, now;
398
    uint8_t *dp;
403
    uint8_t *dp;
399
 
404
 
400
    left = entry->p_filesz;
405
    left = entry->p_filesz;
401
    dp = (uint8_t *)(entry->p_vaddr + bias);
406
    dp = seg_ptr;
402
 
407
 
403
    while (left > 0) {
408
    while (left > 0) {
404
        now = 16384;
409
        now = 16384;
405
        if (now > left) now = left;
410
        if (now > left) now = left;
406
 
411
 
Line 420... Line 425...
420
     * need to set the right access mode and ensure SMC coherence.
425
     * need to set the right access mode and ensure SMC coherence.
421
     */
426
     */
422
    if ((elf->flags & ELDF_RW) != 0) return EE_OK;
427
    if ((elf->flags & ELDF_RW) != 0) return EE_OK;
423
 
428
 
424
//  printf("set area flags to %d\n", flags);
429
//  printf("set area flags to %d\n", flags);
425
    rc = as_area_change_flags((uint8_t *)entry->p_vaddr + bias, flags);
430
    rc = as_area_change_flags(seg_ptr, flags);
426
    if (rc != 0) {
431
    if (rc != 0) {
427
        DPRINTF("Failed to set memory area flags.\n");
432
        DPRINTF("Failed to set memory area flags.\n");
428
        return EE_MEMORY;
433
        return EE_MEMORY;
429
    }
434
    }
430
 
435
 
431
    if (flags & AS_AREA_EXEC) {
436
    if (flags & AS_AREA_EXEC) {
432
        /* Enforce SMC coherence for the segment */
437
        /* Enforce SMC coherence for the segment */
433
        if (smc_coherence(entry->p_vaddr + bias, entry->p_filesz))
438
        if (smc_coherence(seg_ptr, entry->p_filesz))
434
            return EE_MEMORY;
439
            return EE_MEMORY;
435
    }
440
    }
436
 
441
 
437
    return EE_OK;
442
    return EE_OK;
438
}
443
}