Skip to content

Commit

Permalink
Made num_binaries 8 bits (seriously, do we need more than 255 binarie…
Browse files Browse the repository at this point in the history
…s?).

Mostly this makes the kernel portions more sane; the FatELF header for 0xFFFF
 binaries would be like 1.5 megabytes!
  • Loading branch information
icculus committed Sep 7, 2009
1 parent 3596b9d commit 9108025
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/fatelf.h
Expand Up @@ -33,7 +33,8 @@ typedef struct FATELF_header
{
uint32_t magic; /* always FATELF_MAGIC */
uint16_t version; /* latest is always FATELF_FORMAT_VERSION */
uint16_t num_binaries;
uint8_t num_binaries;
uint8_t reserved0;
FATELF_binary_info binaries[];
} FATELF_header;

Expand Down
4 changes: 2 additions & 2 deletions utils/fatelf-glue.c
Expand Up @@ -21,8 +21,8 @@ static int fatelf_glue(const char *out, const char **bins, const int bincount)

if (bincount == 0)
xfail("Nothing to do.");
else if (bincount > 0xFFFF)
xfail("Too many binaries (max is %d).", 0xFFFF);
else if (bincount > 0xFF)
xfail("Too many binaries (max is 255).");

header->magic = FATELF_MAGIC;
header->version = FATELF_FORMAT_VERSION;
Expand Down
6 changes: 3 additions & 3 deletions utils/fatelf-info.c
Expand Up @@ -13,10 +13,10 @@ static int fatelf_info(const char *fname)
{
const int fd = xopen(fname, O_RDONLY, 0755);
FATELF_header *header = xread_fatelf_header(fname, fd);
uint16_t i = 0;
unsigned int i = 0;

printf("%s: FatELF format version %d\n", fname, header->version);
printf("%d binaries.\n", header->num_binaries);
printf("%s: FatELF format version %d\n", fname, (int) header->version);
printf("%d binaries.\n", (int) header->num_binaries);

for (i = 0; i < header->num_binaries; i++)
{
Expand Down
26 changes: 23 additions & 3 deletions utils/fatelf-utils.c
Expand Up @@ -150,6 +150,14 @@ size_t fatelf_header_size(const int bincount)
} // fatelf_header_size


// Write a uint8_t to a buffer.
static inline uint8_t *putui8(uint8_t *ptr, const uint8_t val)
{
*(ptr++) = val;
return ptr + 1;
} // putui8


// Write a native uint16_t to a buffer in littleendian format.
static inline uint8_t *putui16(uint8_t *ptr, const uint16_t val)
{
Expand Down Expand Up @@ -185,6 +193,14 @@ static inline uint8_t *putui64(uint8_t *ptr, const uint64_t val)
} // putui64


// Read a uint8_t from a buffer.
static inline uint8_t *getui8(uint8_t *ptr, uint8_t *val)
{
*val = *ptr;
return ptr + sizeof (*val);
} // getui8


// Read a littleendian uint16_t from a buffer in native format.
static inline uint8_t *getui16(uint8_t *ptr, uint16_t *val)
{
Expand Down Expand Up @@ -229,7 +245,8 @@ void xwrite_fatelf_header(const char *fname, const int fd,

ptr = putui32(ptr, header->magic);
ptr = putui16(ptr, header->version);
ptr = putui16(ptr, header->num_binaries);
ptr = putui8(ptr, header->num_binaries);
ptr = putui8(ptr, header->reserved0);

for (i = 0; i < header->num_binaries; i++)
{
Expand Down Expand Up @@ -258,15 +275,17 @@ FATELF_header *xread_fatelf_header(const char *fname, const int fd)
uint8_t *ptr = buf;
uint32_t magic = 0;
uint16_t version = 0;
uint16_t bincount = 0;
uint8_t bincount = 0;
uint8_t reserved0 = 0;
size_t buflen = 0;
int i = 0;

xlseek(fname, fd, 0, SEEK_SET); // just in case.
xread(fname, fd, buf, sizeof (buf), 1);
ptr = getui32(ptr, &magic);
ptr = getui16(ptr, &version);
ptr = getui16(ptr, &bincount);
ptr = getui8(ptr, &bincount);
ptr = getui8(ptr, &reserved0);

if (magic != FATELF_MAGIC)
xfail("'%s' is not a FatELF binary.", fname);
Expand All @@ -281,6 +300,7 @@ FATELF_header *xread_fatelf_header(const char *fname, const int fd)
header->magic = magic;
header->version = version;
header->num_binaries = bincount;
header->reserved0 = reserved0;

for (i = 0; i < bincount; i++)
{
Expand Down

0 comments on commit 9108025

Please sign in to comment.