1/*
2 * FatELF; support multiple ELF binaries in one file.
3 *
4 * This file written by Ryan C. Gordon as part of the FatELF project,
5 * released under the public domain.
6 *
7 * Copyright 2012 Haiku, Inc. All rights reserved.
8 * Distributed under the terms of the MIT License.
9 */
10
11#ifndef _FATELF_H
12#define _FATELF_H
13
14#include <stdint.h>
15
16/* This is little endian on disk, and looks like "FA700E1F" in a hex editor. */
17#define FATELF_MAGIC (0x1F0E70FA)
18#define FATELF_FORMAT_VERSION (1)
19
20/* This does not count padding for page alignment at the end. */
21#define FATELF_DISK_FORMAT_SIZE(bins) (8 + (24 * (bins)))
22
23/* Valid FATELF_record::word_size values. Maps to EI_CLASS. */
24#define FATELF_32BITS (1)
25#define FATELF_64BITS (2)
26
27/* Valid FATELF_record::byte_order values. Maps to EI_DATA */
28#define FATELF_LITTLEENDIAN (1)
29#define FATELF_BIGENDIAN	(2)
30
31/* Values on disk are always littleendian, and align like Elf64. */
32typedef struct FATELF_record
33{
34	uint16_t machine;		/* maps to e_machine. */
35	uint8_t osabi;			/* maps to e_ident[EI_OSABI]. */
36	uint8_t osabi_version;	/* maps to e_ident[EI_ABIVERSION]. */
37	uint8_t word_size;		/* maps to e_ident[EI_CLASS]. */
38	uint8_t byte_order;		/* maps to e_ident[EI_DATA]. */
39	uint8_t reserved0;
40	uint8_t reserved1;
41	uint64_t offset;
42	uint64_t size;
43} FATELF_record;
44
45/* Values on disk are always littleendian, and align like Elf64. */
46typedef struct FATELF_header
47{
48	uint32_t magic; 		/* always FATELF_MAGIC */
49	uint16_t version;		/* latest is always FATELF_FORMAT_VERSION */
50	uint8_t num_records;
51	uint8_t reserved0;
52#if __GNUC__ <= 2
53	FATELF_record records[0];
54#else
55	FATELF_record records[];
56#endif /* __GNUC__ <= 2 */
57} FATELF_header;
58
59#endif /* _FATELF_H */
60