Skip to content

Commit

Permalink
Make machine info 16 bits to match ELF spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 7, 2009
1 parent de9b998 commit 81e1642
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/fatelf.h
Expand Up @@ -22,7 +22,8 @@ typedef struct FATELF_binary_info
{
uint16_t abi;
uint16_t abi_version;
uint32_t machine;
uint16_t machine;
uint16_t reserved0;
uint64_t offset;
} FATELF_binary_info;

Expand Down
12 changes: 7 additions & 5 deletions utils/fatelf-utils.c
Expand Up @@ -136,9 +136,9 @@ void xread_elf_header(const char *fname, const int fd, FATELF_binary_info *info)
info->abi = (uint16_t) buf[7];
info->abi_version = (uint16_t) buf[8];
if (buf[5] == 0) // bigendian
info->machine = (((uint32_t)buf[18]) << 8) | (((uint32_t)buf[19]));
info->machine = (((uint16_t)buf[18]) << 8) | (((uint16_t)buf[19]));
else if (buf[5] == 1) // littleendian
info->machine = (((uint32_t)buf[19]) << 8) | (((uint32_t)buf[18]));
info->machine = (((uint16_t)buf[19]) << 8) | (((uint16_t)buf[18]));
else
xfail("Unexpected data encoding in '%s'", fname);
} // xread_elf_header
Expand Down Expand Up @@ -235,7 +235,8 @@ void xwrite_fatelf_header(const char *fname, const int fd,
{
ptr = putui16(ptr, header->binaries[i].abi);
ptr = putui16(ptr, header->binaries[i].abi_version);
ptr = putui32(ptr, header->binaries[i].machine);
ptr = putui16(ptr, header->binaries[i].machine);
ptr = putui16(ptr, header->binaries[i].reserved0);
ptr = putui64(ptr, header->binaries[i].offset);
} // for

Expand Down Expand Up @@ -284,7 +285,8 @@ FATELF_header *xread_fatelf_header(const char *fname, const int fd)
{
ptr = getui16(ptr, &header->binaries[i].abi);
ptr = getui16(ptr, &header->binaries[i].abi_version);
ptr = getui32(ptr, &header->binaries[i].machine);
ptr = getui16(ptr, &header->binaries[i].machine);
ptr = getui16(ptr, &header->binaries[i].reserved0);
ptr = getui64(ptr, &header->binaries[i].offset);
} // for

Expand Down Expand Up @@ -435,7 +437,7 @@ static const fatelf_abi_info abis[] =
};


const fatelf_machine_info *get_machine_by_id(const uint32_t id)
const fatelf_machine_info *get_machine_by_id(const uint16_t id)
{
int i;
for (i = 0; i < (sizeof (machines) / sizeof (machines[0])); i++)
Expand Down
4 changes: 2 additions & 2 deletions utils/fatelf-utils.h
Expand Up @@ -29,7 +29,7 @@ extern const char *unlink_on_xfail;

typedef struct fatelf_machine_info
{
uint32_t id;
uint16_t id;
const char *name;
const char *desc;
} fatelf_machine_info;
Expand Down Expand Up @@ -85,7 +85,7 @@ FATELF_header *xread_fatelf_header(const char *fname, const int fd);
// Align a value to the page size.
uint64_t align_to_page(const uint64_t offset);

const fatelf_machine_info *get_machine_by_id(const uint32_t id);
const fatelf_machine_info *get_machine_by_id(const uint16_t id);
const fatelf_machine_info *get_machine_by_name(const char *name);
const fatelf_abi_info *get_abi_by_id(const uint16_t id);
const fatelf_abi_info *get_abi_by_name(const char *name);
Expand Down

0 comments on commit 81e1642

Please sign in to comment.