Changeset 1afa94d in mainline


Ignore:
Timestamp:
2017-12-10T21:08:11Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dd8ab1c
Parents:
c81132d
Message:

Fix error handling in elf code.

Location:
uspace/lib/c
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/elf/elf_load.c

    rc81132d r1afa94d  
    5353 * @param file File handle
    5454 * @param info Place to store ELF program information
    55  * @return EOK on success or an error code
     55 * @return EE_OK on success or an EE_x error code
    5656 */
    5757int elf_load(int file, elf_info_t *info)
  • uspace/lib/c/generic/elf/elf_mod.c

    rc81132d r1afa94d  
    6969        "incompatible image",
    7070        "unsupported image type",
    71         "irrecoverable error"
     71        "irrecoverable error",
     72        "file io error"
    7273};
    7374
     
    9091 *                  extracted from the binary.
    9192 *
    92  * @return EOK on success or negative error code.
     93 * @return EE_OK on success or EE_xx error code.
    9394 *
    9495 */
     
    103104        }
    104105        if (rc != EOK) {
    105                 return rc;
     106                return EE_IO;
    106107        }
    107108
     
    110111        elf.flags = flags;
    111112
    112         rc = elf_load_module(&elf, so_bias);
     113        int ret = elf_load_module(&elf, so_bias);
    113114
    114115        vfs_put(ofile);
    115         return rc;
     116        return ret;
    116117}
    117118
     
    122123        int rc = vfs_lookup(path, 0, &file);
    123124        if (rc == EOK) {
    124                 rc = elf_load_file(file, so_bias, flags, info);
     125                int ret = elf_load_file(file, so_bias, flags, info);
    125126                vfs_put(file);
    126         }
    127         return rc;
     127                return ret;
     128        } else {
     129                return EE_IO;
     130        }
    128131}
    129132
     
    144147        aoff64_t pos = 0;
    145148        size_t nr;
    146         int i, rc;
     149        int i, ret;
     150        int rc;
    147151
    148152        rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t), &nr);
    149153        if (rc != EOK || nr != sizeof(elf_header_t)) {
    150154                DPRINTF("Read error.\n");
    151                 return EE_INVALID;
     155                return EE_IO;
    152156        }
    153157
     
    209213                if (rc != EOK || nr != sizeof(elf_segment_header_t)) {
    210214                        DPRINTF("Read error.\n");
    211                         return EE_INVALID;
     215                        return EE_IO;
    212216                }
    213217
    214                 rc = segment_header(elf, &segment_hdr);
    215                 if (rc != EE_OK)
    216                         return rc;
     218                ret = segment_header(elf, &segment_hdr);
     219                if (ret != EE_OK)
     220                        return ret;
    217221        }
    218222
     
    228232                if (rc != EOK || nr != sizeof(elf_section_header_t)) {
    229233                        DPRINTF("Read error.\n");
    230                         return EE_INVALID;
     234                        return EE_IO;
    231235                }
    232236
    233                 rc = section_header(elf, &section_hdr);
    234                 if (rc != EE_OK)
    235                         return rc;
     237                ret = section_header(elf, &section_hdr);
     238                if (ret != EE_OK)
     239                        return ret;
    236240        }
    237241
     
    399403        if (rc != EOK || nr != entry->p_filesz) {
    400404                DPRINTF("read error\n");
    401                 return EE_INVALID;
     405                return EE_IO;
    402406        }
    403407
  • uspace/lib/c/include/elf/elf_mod.h

    rc81132d r1afa94d  
    5353#define EE_LOADER               5       /* The image is actually a program loader. */
    5454#define EE_IRRECOVERABLE        6
     55#define EE_IO                   7       /* Could not read file. */
    5556
    5657typedef enum {
Note: See TracChangeset for help on using the changeset viewer.