Changeset 874a0e8 in mainline


Ignore:
Timestamp:
2008-08-14T20:09:11Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cebab351
Parents:
6808614
Message:

Make sure that the loader keeps on read()ing until it read()s all it wanted to
read().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loader/elf_load.c

    r6808614 r874a0e8  
    7272static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry);
    7373
     74/** Read until the buffer is read in its entirety. */
     75static int my_read(int fd, char *buf, size_t len)
     76{
     77        int cnt = 0;
     78        do {
     79                buf += cnt;
     80                len -= cnt;
     81                cnt = read(fd, buf, len);
     82        } while ((cnt > 0) && ((len - cnt) > 0));
     83
     84        return cnt;
     85}
     86
    7487/** Load ELF binary from a file.
    7588 *
     
    157170        int i, rc;
    158171
    159         rc = read(elf->fd, header, sizeof(elf_header_t));
     172        rc = my_read(elf->fd, header, sizeof(elf_header_t));
    160173        if (rc < 0) {
    161174                printf("read error\n");
     
    224237                        + i * sizeof(elf_segment_header_t), SEEK_SET);
    225238
    226                 rc = read(elf->fd, &segment_hdr, sizeof(elf_segment_header_t));
     239                rc = my_read(elf->fd, &segment_hdr,
     240                    sizeof(elf_segment_header_t));
    227241                if (rc < 0) {
    228242                        printf("read error\n");
     
    245259                    + i * sizeof(elf_section_header_t), SEEK_SET);
    246260
    247                 rc = read(elf->fd, &section_hdr, sizeof(elf_section_header_t));
     261                rc = my_read(elf->fd, &section_hdr,
     262                    sizeof(elf_section_header_t));
    248263                if (rc < 0) {
    249264                        printf("read error\n");
     
    362377         * and writeable.
    363378         */
    364         a = as_area_create((uint8_t *)base + bias,
    365                 mem_sz, AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
     379        a = as_area_create((uint8_t *)base + bias, mem_sz,
     380            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    366381        if (a == (void *)(-1)) {
    367382                printf("memory mapping failed\n");
     
    399414
    400415//              printf("read %d...", now);
    401                 rc = read(elf->fd, dp, now);
     416                rc = my_read(elf->fd, dp, now);
    402417//              printf("->%d\n", rc);
    403418
Note: See TracChangeset for help on using the changeset viewer.