mirror of https://github.com/tailix/libkernaux.git
Print Multiboot 2 ELF section headers (#154)
This commit is contained in:
parent
6ec080ddfa
commit
e829231328
|
@ -1,3 +1,7 @@
|
||||||
|
2022-12-19 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
|
* src/multiboot2/*_print.c: Print Multiboot 2 ELF section headers
|
||||||
|
|
||||||
2022-12-17 Alex Kotov <kotovalexarian@gmail.com>
|
2022-12-17 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
* configure.ac: Feature "--(enable|disable)-fixtures" has been added
|
* configure.ac: Feature "--(enable|disable)-fixtures" has been added
|
||||||
|
|
|
@ -50,37 +50,37 @@ Multiboot 2 info tag {
|
||||||
u32 entry_size: 24
|
u32 entry_size: 24
|
||||||
u32 entry_version: 0
|
u32 entry_version: 0
|
||||||
varies(entry_size) entries[]: [
|
varies(entry_size) entries[]: [
|
||||||
[0] entry: {
|
[0]: {
|
||||||
u64 base_addr: 0x0
|
u64 base_addr: 0x0
|
||||||
u64 length: 654336
|
u64 length: 654336
|
||||||
u32 type: 1
|
u32 type: 1
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[1] entry: {
|
[1]: {
|
||||||
u64 base_addr: 0x9fc00
|
u64 base_addr: 0x9fc00
|
||||||
u64 length: 1024
|
u64 length: 1024
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[2] entry: {
|
[2]: {
|
||||||
u64 base_addr: 0xf0000
|
u64 base_addr: 0xf0000
|
||||||
u64 length: 65536
|
u64 length: 65536
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[3] entry: {
|
[3]: {
|
||||||
u64 base_addr: 0x100000
|
u64 base_addr: 0x100000
|
||||||
u64 length: 133038080
|
u64 length: 133038080
|
||||||
u32 type: 1
|
u32 type: 1
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[4] entry: {
|
[4]: {
|
||||||
u64 base_addr: 0x7fe0000
|
u64 base_addr: 0x7fe0000
|
||||||
u64 length: 131072
|
u64 length: 131072
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[5] entry: {
|
[5]: {
|
||||||
u64 base_addr: 0xfffc0000
|
u64 base_addr: 0xfffc0000
|
||||||
u64 length: 262144
|
u64 length: 262144
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
|
@ -94,6 +94,141 @@ Multiboot 2 info tag {
|
||||||
u32 num: 10
|
u32 num: 10
|
||||||
u32 entsize: 40
|
u32 entsize: 40
|
||||||
u32 shndx: 9
|
u32 shndx: 9
|
||||||
|
varies(entsize) section_headers[]: [
|
||||||
|
[0]: {
|
||||||
|
name: 0
|
||||||
|
type: 0 (NULL)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x0
|
||||||
|
offset: 0x0
|
||||||
|
size: 0
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 0
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[1]: {
|
||||||
|
name: 27
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x6 (
|
||||||
|
ALLOC |
|
||||||
|
EXECINSTR
|
||||||
|
)
|
||||||
|
addr: 0x400000
|
||||||
|
offset: 0x1000
|
||||||
|
size: 13718
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[2]: {
|
||||||
|
name: 33
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x2 (
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x404000
|
||||||
|
offset: 0x5000
|
||||||
|
size: 2824
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[3]: {
|
||||||
|
name: 41
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x2 (
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x404b08
|
||||||
|
offset: 0x5b08
|
||||||
|
size: 2692
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[4]: {
|
||||||
|
name: 51
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x3 (
|
||||||
|
WRITE |
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x406000
|
||||||
|
offset: 0x7000
|
||||||
|
size: 1
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[5]: {
|
||||||
|
name: 57
|
||||||
|
type: 8 (NOBITS)
|
||||||
|
flags: 0x3 (
|
||||||
|
WRITE |
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x407000
|
||||||
|
offset: 0x7001
|
||||||
|
size: 43328
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[6]: {
|
||||||
|
name: 62
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x30 ()
|
||||||
|
addr: 0x100000
|
||||||
|
offset: 0x7001
|
||||||
|
size: 17
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 1
|
||||||
|
}
|
||||||
|
[7]: {
|
||||||
|
name: 1
|
||||||
|
type: 2 (SYMTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x100014
|
||||||
|
offset: 0x7014
|
||||||
|
size: 3248
|
||||||
|
link: 8
|
||||||
|
info: 72
|
||||||
|
addralign: 4
|
||||||
|
entsize: 16
|
||||||
|
}
|
||||||
|
[8]: {
|
||||||
|
name: 9
|
||||||
|
type: 3 (STRTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x100cc4
|
||||||
|
offset: 0x7cc4
|
||||||
|
size: 3536
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[9]: {
|
||||||
|
name: 17
|
||||||
|
type: 3 (STRTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x101a94
|
||||||
|
offset: 0x8a94
|
||||||
|
size: 71
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Multiboot 2 info tag {
|
Multiboot 2 info tag {
|
||||||
u32 type: 4 (basic memory info)
|
u32 type: 4 (basic memory info)
|
||||||
|
|
|
@ -45,37 +45,37 @@ Multiboot 2 info tag {
|
||||||
u32 entry_size: 24
|
u32 entry_size: 24
|
||||||
u32 entry_version: 0
|
u32 entry_version: 0
|
||||||
varies(entry_size) entries[]: [
|
varies(entry_size) entries[]: [
|
||||||
[0] entry: {
|
[0]: {
|
||||||
u64 base_addr: 0x0
|
u64 base_addr: 0x0
|
||||||
u64 length: 654336
|
u64 length: 654336
|
||||||
u32 type: 1
|
u32 type: 1
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[1] entry: {
|
[1]: {
|
||||||
u64 base_addr: 0x9fc00
|
u64 base_addr: 0x9fc00
|
||||||
u64 length: 1024
|
u64 length: 1024
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[2] entry: {
|
[2]: {
|
||||||
u64 base_addr: 0xf0000
|
u64 base_addr: 0xf0000
|
||||||
u64 length: 65536
|
u64 length: 65536
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[3] entry: {
|
[3]: {
|
||||||
u64 base_addr: 0x100000
|
u64 base_addr: 0x100000
|
||||||
u64 length: 133038080
|
u64 length: 133038080
|
||||||
u32 type: 1
|
u32 type: 1
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[4] entry: {
|
[4]: {
|
||||||
u64 base_addr: 0x7fe0000
|
u64 base_addr: 0x7fe0000
|
||||||
u64 length: 131072
|
u64 length: 131072
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
u32 reserved: 0x0
|
u32 reserved: 0x0
|
||||||
}
|
}
|
||||||
[5] entry: {
|
[5]: {
|
||||||
u64 base_addr: 0xfffc0000
|
u64 base_addr: 0xfffc0000
|
||||||
u64 length: 262144
|
u64 length: 262144
|
||||||
u32 type: 2
|
u32 type: 2
|
||||||
|
@ -160,6 +160,141 @@ Multiboot 2 info tag {
|
||||||
u32 num: 10
|
u32 num: 10
|
||||||
u32 entsize: 40
|
u32 entsize: 40
|
||||||
u32 shndx: 9
|
u32 shndx: 9
|
||||||
|
varies(entsize) section_headers[]: [
|
||||||
|
[0]: {
|
||||||
|
name: 0
|
||||||
|
type: 0 (NULL)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x0
|
||||||
|
offset: 0x0
|
||||||
|
size: 0
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 0
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[1]: {
|
||||||
|
name: 27
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x6 (
|
||||||
|
ALLOC |
|
||||||
|
EXECINSTR
|
||||||
|
)
|
||||||
|
addr: 0x400000
|
||||||
|
offset: 0x1000
|
||||||
|
size: 13718
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[2]: {
|
||||||
|
name: 33
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x2 (
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x404000
|
||||||
|
offset: 0x5000
|
||||||
|
size: 2824
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[3]: {
|
||||||
|
name: 41
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x2 (
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x404b08
|
||||||
|
offset: 0x5b08
|
||||||
|
size: 2692
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[4]: {
|
||||||
|
name: 51
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x3 (
|
||||||
|
WRITE |
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x406000
|
||||||
|
offset: 0x7000
|
||||||
|
size: 1
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[5]: {
|
||||||
|
name: 57
|
||||||
|
type: 8 (NOBITS)
|
||||||
|
flags: 0x3 (
|
||||||
|
WRITE |
|
||||||
|
ALLOC
|
||||||
|
)
|
||||||
|
addr: 0x407000
|
||||||
|
offset: 0x7001
|
||||||
|
size: 43328
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 4096
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[6]: {
|
||||||
|
name: 62
|
||||||
|
type: 1 (PROGBITS)
|
||||||
|
flags: 0x30 ()
|
||||||
|
addr: 0x100000
|
||||||
|
offset: 0x7001
|
||||||
|
size: 17
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 1
|
||||||
|
}
|
||||||
|
[7]: {
|
||||||
|
name: 1
|
||||||
|
type: 2 (SYMTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x100014
|
||||||
|
offset: 0x7014
|
||||||
|
size: 3248
|
||||||
|
link: 8
|
||||||
|
info: 72
|
||||||
|
addralign: 4
|
||||||
|
entsize: 16
|
||||||
|
}
|
||||||
|
[8]: {
|
||||||
|
name: 9
|
||||||
|
type: 3 (STRTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x100cc4
|
||||||
|
offset: 0x7cc4
|
||||||
|
size: 3536
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
[9]: {
|
||||||
|
name: 17
|
||||||
|
type: 3 (STRTAB)
|
||||||
|
flags: 0x0 ()
|
||||||
|
addr: 0x101a94
|
||||||
|
offset: 0x8a94
|
||||||
|
size: 71
|
||||||
|
link: 0
|
||||||
|
info: 0
|
||||||
|
addralign: 1
|
||||||
|
entsize: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Multiboot 2 info tag {
|
Multiboot 2 info tag {
|
||||||
u32 type: 10 (APM table)
|
u32 type: 10 (APM table)
|
||||||
|
|
|
@ -7,87 +7,173 @@ extern "C" {
|
||||||
|
|
||||||
#include <kernaux/macro.h>
|
#include <kernaux/macro.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <kernaux/macro/packing_start.run>
|
#include <kernaux/macro/packing_start.run>
|
||||||
|
|
||||||
|
struct KernAux_ELF_Ident {
|
||||||
|
uint8_t magic_0x7f;
|
||||||
|
uint8_t magic_E;
|
||||||
|
uint8_t magic_L;
|
||||||
|
uint8_t magic_F;
|
||||||
|
uint8_t class_;
|
||||||
|
uint8_t data;
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t unused[9];
|
||||||
|
}
|
||||||
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Ident, 16);
|
||||||
|
|
||||||
|
// KernAux_ELF_Ident.class_
|
||||||
|
#define KERNAUX_ELF_CLASS_NONE 0 // Invalid class
|
||||||
|
#define KERNAUX_ELF_CLASS_32 1 // 32-bit objects
|
||||||
|
#define KERNAUX_ELF_CLASS_64 2 // 64-bit objects
|
||||||
|
|
||||||
|
// KernAux_ELF_Ident.data
|
||||||
|
#define KERNAUX_ELF_DATA_NONE 0 // Invalid data encoding
|
||||||
|
#define KERNAUX_ELF_DATA_2LSB 1 // 0x01020304 == [0x04, 0x03, 0x02, 0x01]
|
||||||
|
#define KERNAUX_ELF_DATA_2MSB 2 // 0x01020304 == [0x01, 0x02, 0x03, 0x04]
|
||||||
|
|
||||||
struct KernAux_ELF_Header {
|
struct KernAux_ELF_Header {
|
||||||
unsigned magic_0x7f : 8;
|
struct KernAux_ELF_Ident ident;
|
||||||
unsigned magic_E : 8;
|
uint16_t type;
|
||||||
unsigned magic_L : 8;
|
uint16_t machine;
|
||||||
unsigned magic_F : 8;
|
uint32_t version;
|
||||||
unsigned bitness : 8;
|
uint32_t entry;
|
||||||
unsigned endianness : 8;
|
uint32_t phoff;
|
||||||
unsigned header_version : 8;
|
uint32_t shoff;
|
||||||
unsigned os_abi : 8;
|
uint32_t flags;
|
||||||
unsigned unused1 : 32;
|
uint16_t ehsize;
|
||||||
unsigned unused2 : 32;
|
uint16_t phentsize;
|
||||||
unsigned obj_type : 16;
|
uint16_t phnum;
|
||||||
unsigned isa : 16;
|
uint16_t shentsize;
|
||||||
unsigned elf_version : 32;
|
uint16_t shnum;
|
||||||
unsigned entrypoint : 32;
|
uint16_t shstrndx;
|
||||||
unsigned prog_table_pos : 32;
|
|
||||||
unsigned sect_table_pos : 32;
|
|
||||||
unsigned arch_flags : 32;
|
|
||||||
unsigned header_size : 16;
|
|
||||||
unsigned prog_entr_size : 16;
|
|
||||||
unsigned prog_entr_num : 16;
|
|
||||||
unsigned sect_entr_size : 16;
|
|
||||||
unsigned sect_entr_num : 16;
|
|
||||||
unsigned sect_names_idx : 16;
|
|
||||||
}
|
}
|
||||||
KERNAUX_PACKED;
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Header, 52);
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Header, 52);
|
||||||
|
|
||||||
struct KernAux_ELF_ProgramEntry {
|
// KernAux_ELF_Header.type
|
||||||
unsigned type : 32;
|
#define KERNAUX_ELF_TYPE_NONE 0 // No file type
|
||||||
unsigned offset : 32;
|
#define KERNAUX_ELF_TYPE_REL 1 // Relocatable file
|
||||||
unsigned virt_addr : 32;
|
#define KERNAUX_ELF_TYPE_EXEC 2 // Executable file
|
||||||
unsigned phys_addr : 32;
|
#define KERNAUX_ELF_TYPE_DYN 3 // Shared object file
|
||||||
unsigned file_size : 32;
|
#define KERNAUX_ELF_TYPE_CORE 4 // Core file
|
||||||
unsigned mem_size : 32;
|
#define KERNAUX_ELF_TYPE_LOPROC 0xff00 // Processor-specific
|
||||||
unsigned flags : 32;
|
#define KERNAUX_ELF_TYPE_HIPROC 0xffff // Processor-specific
|
||||||
unsigned align : 32;
|
|
||||||
|
// KernAux_ELF_Header.machine
|
||||||
|
#define KERNAUX_ELF_MACHINE_NONE 0 // No machine
|
||||||
|
#define KERNAUX_ELF_MACHINE_M32 1 // AT&T WE 32100
|
||||||
|
#define KERNAUX_ELF_MACHINE_SPARC 2 // SPARC
|
||||||
|
#define KERNAUX_ELF_MACHINE_386 3 // Intel 80386
|
||||||
|
#define KERNAUX_ELF_MACHINE_68K 4 // Motorola 68000
|
||||||
|
#define KERNAUX_ELF_MACHINE_88K 5 // Motorola 88000
|
||||||
|
#define KERNAUX_ELF_MACHINE_860 7 // Intel 80860
|
||||||
|
#define KERNAUX_ELF_MACHINE_MIPS 8 // MIPS RS3000
|
||||||
|
|
||||||
|
// KernAux_ELF_Header.version
|
||||||
|
#define KERNAUX_ELF_VERSION_NONE 0 // Invalid version
|
||||||
|
#define KERNAUX_ELF_VERSION_CURRENT 1 // Current version
|
||||||
|
|
||||||
|
struct KernAux_ELF_Section {
|
||||||
|
uint32_t name;
|
||||||
|
uint32_t type;
|
||||||
|
uint32_t flags;
|
||||||
|
uint32_t addr;
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t link;
|
||||||
|
uint32_t info;
|
||||||
|
uint32_t addralign;
|
||||||
|
uint32_t entsize;
|
||||||
}
|
}
|
||||||
KERNAUX_PACKED;
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_ProgramEntry, 32);
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Section, 40);
|
||||||
|
|
||||||
struct KernAux_ELF_SectionEntry {
|
#define KERNAUX_ELF_SECT_TYPE_NULL 0
|
||||||
unsigned name : 32;
|
#define KERNAUX_ELF_SECT_TYPE_PROGBITS 1
|
||||||
unsigned type : 32;
|
#define KERNAUX_ELF_SECT_TYPE_SYMTAB 2
|
||||||
unsigned flags : 32;
|
#define KERNAUX_ELF_SECT_TYPE_STRTAB 3
|
||||||
unsigned vaddr : 32;
|
#define KERNAUX_ELF_SECT_TYPE_RELA 4
|
||||||
unsigned file_offset : 32;
|
#define KERNAUX_ELF_SECT_TYPE_HASH 5
|
||||||
unsigned file_size : 32;
|
#define KERNAUX_ELF_SECT_TYPE_DYNAMIC 6
|
||||||
unsigned link : 32;
|
#define KERNAUX_ELF_SECT_TYPE_NOTE 7
|
||||||
unsigned info : 32;
|
#define KERNAUX_ELF_SECT_TYPE_NOBITS 8
|
||||||
unsigned alignment : 32;
|
#define KERNAUX_ELF_SECT_TYPE_REL 9
|
||||||
unsigned ent_size : 32;
|
#define KERNAUX_ELF_SECT_TYPE_SHLIB 10
|
||||||
|
#define KERNAUX_ELF_SECT_TYPE_DYNSYM 11
|
||||||
|
#define KERNAUX_ELF_SECT_TYPE_LOPROC 0x70000000
|
||||||
|
#define KERNAUX_ELF_SECT_TYPE_HIPROC 0x7fffffff
|
||||||
|
#define KERNAUX_ELF_SECT_TYPE_LOUSER 0x80000000
|
||||||
|
#define KERNAUX_ELF_SECT_TYPE_HIUSER 0xffffffff
|
||||||
|
|
||||||
|
#define KERNAUX_ELF_SECT_FLAGS_WRITE 0x1
|
||||||
|
#define KERNAUX_ELF_SECT_FLAGS_ALLOC 0x2
|
||||||
|
#define KERNAUX_ELF_SECT_FLAGS_EXECINSTR 0x4
|
||||||
|
#define KERNAUX_ELF_SECT_FLAGS_MASKPROC 0xf0000000
|
||||||
|
|
||||||
|
const char *KernAux_ELF_Section_Type_to_str(uint32_t type);
|
||||||
|
|
||||||
|
struct KernAux_ELF_Symbol {
|
||||||
|
uint32_t name;
|
||||||
|
uint32_t value;
|
||||||
|
uint32_t size;
|
||||||
|
uint8_t info;
|
||||||
|
uint8_t other;
|
||||||
|
uint16_t shndx;
|
||||||
}
|
}
|
||||||
KERNAUX_PACKED;
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_SectionEntry, 40);
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Symbol, 16);
|
||||||
|
|
||||||
struct KernAux_ELF_RelocationEntry {
|
#define KERNAUX_ELF_SYM_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
||||||
unsigned virt_addr : 32;
|
#define KERNAUX_ELF_SYM_BIND(info) ((info) >> 4)
|
||||||
unsigned info : 32;
|
#define KERNAUX_ELF_SYM_TYPE(info) ((into) & 0xf)
|
||||||
|
|
||||||
|
#define KERNAUX_ELF_SYM_BIND_LOCAL 0
|
||||||
|
#define KERNAUX_ELF_SYM_BIND_GLOBAL 1
|
||||||
|
#define KERNAUX_ELF_SYM_BIND_WEAK 2
|
||||||
|
#define KERNAUX_ELF_SYM_BIND_LOPROC 13
|
||||||
|
#define KERNAUX_ELF_SYM_BIND_HIPROC 15
|
||||||
|
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_NOTYPE 0
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_OBJECT 1
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_FUNC 2
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_SECTION 3
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_FILE 4
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_LOPROC 13
|
||||||
|
#define KERNAUX_ELF_SYM_TYPE_HIPROC 15
|
||||||
|
|
||||||
|
struct KernAux_ELF_Program {
|
||||||
|
uint32_t type;
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t vaddr;
|
||||||
|
uint32_t paddr;
|
||||||
|
uint32_t filesz;
|
||||||
|
uint32_t memsz;
|
||||||
|
uint32_t flags;
|
||||||
|
uint32_t align;
|
||||||
}
|
}
|
||||||
KERNAUX_PACKED;
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_RelocationEntry, 8);
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Program, 32);
|
||||||
|
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_NULL 0
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_LOAD 1
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_DYNAMIC 2
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_INTERP 3
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_NOTE 4
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_SHLIB 5
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_PHDR 6
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_LOPROC 0x70000000
|
||||||
|
#define KERNAUX_ELF_PROG_TYPE_HIPROC 0x7fffffff
|
||||||
|
|
||||||
#include <kernaux/macro/packing_end.run>
|
#include <kernaux/macro/packing_end.run>
|
||||||
|
|
||||||
typedef struct KernAux_ELF_ProgramEntry KernAux_ELF_ProgramTable[];
|
|
||||||
|
|
||||||
typedef struct KernAux_ELF_SectionEntry KernAux_ELF_SectionTable[];
|
|
||||||
|
|
||||||
typedef struct KernAux_ELF_RelocationEntry KernAux_ELF_RelocationTable[];
|
|
||||||
|
|
||||||
bool KernAux_ELF_Header_is_valid(const struct KernAux_ELF_Header *header);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -366,7 +366,7 @@ struct KernAux_Multiboot2_ITag_ELFSymbols {
|
||||||
uint32_t entsize;
|
uint32_t entsize;
|
||||||
uint32_t shndx;
|
uint32_t shndx;
|
||||||
|
|
||||||
// DATA: varies section_headers[]
|
// DATA: varies(entsize) section_headers[]
|
||||||
}
|
}
|
||||||
KERNAUX_PACKED;
|
KERNAUX_PACKED;
|
||||||
|
|
||||||
|
|
87
src/elf.c
87
src/elf.c
|
@ -2,56 +2,47 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <kernaux/assert.h>
|
|
||||||
#include <kernaux/elf.h>
|
#include <kernaux/elf.h>
|
||||||
|
#include <kernaux/macro.h>
|
||||||
|
|
||||||
bool KernAux_ELF_Header_is_valid(
|
#include <stddef.h>
|
||||||
const struct KernAux_ELF_Header *const header
|
|
||||||
) {
|
|
||||||
KERNAUX_ASSERT(header);
|
|
||||||
|
|
||||||
if (!(
|
const char *KernAux_ELF_Section_Type_to_str(const uint32_t type)
|
||||||
header->magic_0x7f == 0x7f &&
|
{
|
||||||
header->magic_E == 'E' &&
|
switch (type) {
|
||||||
header->magic_L == 'L' &&
|
case KERNAUX_ELF_SECT_TYPE_NULL:
|
||||||
header->magic_F == 'F' &&
|
return "NULL";
|
||||||
header->header_version == 1 &&
|
case KERNAUX_ELF_SECT_TYPE_PROGBITS:
|
||||||
header->elf_version == 1
|
return "PROGBITS";
|
||||||
)) {
|
case KERNAUX_ELF_SECT_TYPE_SYMTAB:
|
||||||
return false;
|
return "SYMTAB";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_STRTAB:
|
||||||
|
return "STRTAB";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_RELA:
|
||||||
|
return "RELA";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_HASH:
|
||||||
|
return "HASH";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_DYNAMIC:
|
||||||
|
return "DYNAMIC";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_NOTE:
|
||||||
|
return "NOTE";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_NOBITS:
|
||||||
|
return "NOBITS";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_REL:
|
||||||
|
return "REL";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_SHLIB:
|
||||||
|
return "SHLIB";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_DYNSYM:
|
||||||
|
return "DYNSYM";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_LOPROC:
|
||||||
|
return "LOPROC";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_HIPROC:
|
||||||
|
return "HIPROC";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_LOUSER:
|
||||||
|
return "LOUSER";
|
||||||
|
case KERNAUX_ELF_SECT_TYPE_HIUSER:
|
||||||
|
return "HIUSER";
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(
|
|
||||||
header->bitness == 1 || // 32 bit
|
|
||||||
header->bitness == 2 // 64 bit
|
|
||||||
)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(
|
|
||||||
header->endianness == 1 || // Little endian
|
|
||||||
header->endianness == 2 // Big endian
|
|
||||||
)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(header->os_abi <= 0x12 && header->os_abi != 0x05)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(
|
|
||||||
header->obj_type == 0x00 || // NONE
|
|
||||||
header->obj_type == 0x01 || // REL
|
|
||||||
header->obj_type == 0x02 || // EXEC
|
|
||||||
header->obj_type == 0x03 || // DYN
|
|
||||||
header->obj_type == 0x04 || // CORE
|
|
||||||
header->obj_type == 0xfe00 || // LOOS
|
|
||||||
header->obj_type == 0xfeff || // HIOS
|
|
||||||
header->obj_type == 0xff00 || // LOPROC
|
|
||||||
header->obj_type == 0xffff // HIPROC
|
|
||||||
)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,26 +225,30 @@ void KernAux_Multiboot2_HTag_InfoReq_print(
|
||||||
|
|
||||||
// Print data:
|
// Print data:
|
||||||
|
|
||||||
PRINTLN(" u32 mbi_tag_types[]: [");
|
if ((tag->base.size - sizeof(*tag)) / sizeof(uint32_t) == 0) {
|
||||||
|
PRINTLN(" u32 mbi_tag_types[]: []");
|
||||||
|
} else {
|
||||||
|
PRINTLN(" u32 mbi_tag_types[]: [");
|
||||||
|
|
||||||
const uint32_t *const mbi_tag_types =
|
const uint32_t *const mbi_tag_types =
|
||||||
(const uint32_t*)KERNAUX_MULTIBOOT2_DATA(tag);
|
(const uint32_t*)KERNAUX_MULTIBOOT2_DATA(tag);
|
||||||
|
|
||||||
for (
|
for (
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
index < (tag->base.size - sizeof(*tag)) / sizeof(uint32_t);
|
index < (tag->base.size - sizeof(*tag)) / sizeof(uint32_t);
|
||||||
++index
|
++index
|
||||||
) {
|
) {
|
||||||
KERNAUX_CAST_CONST(unsigned long, type, mbi_tag_types[index]);
|
KERNAUX_CAST_CONST(unsigned long, type, mbi_tag_types[index]);
|
||||||
|
|
||||||
PRINTLNF(" %lu (%s)",
|
PRINTLNF(" %lu (%s)",
|
||||||
type,
|
type,
|
||||||
KernAux_Multiboot2_ITag_to_str(type)
|
KernAux_Multiboot2_ITag_to_str(type)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTLN(" ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTLN(" ]");
|
|
||||||
|
|
||||||
FOOTER;
|
FOOTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <kernaux/assert.h>
|
#include <kernaux/assert.h>
|
||||||
|
#include <kernaux/elf.h>
|
||||||
#include <kernaux/generic/display.h>
|
#include <kernaux/generic/display.h>
|
||||||
#include <kernaux/macro.h>
|
#include <kernaux/macro.h>
|
||||||
#include <kernaux/multiboot2.h>
|
#include <kernaux/multiboot2.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -39,6 +41,44 @@
|
||||||
|
|
||||||
#define FOOTER do { PRINTLN("}"); } while (0)
|
#define FOOTER do { PRINTLN("}"); } while (0)
|
||||||
|
|
||||||
|
#define INDENT do { \
|
||||||
|
for (unsigned index = 0; index < basic_indentation; ++index) PRINT(" "); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define INDENT_MORE do { \
|
||||||
|
for (unsigned index = 0; index < indentation_delta; ++index) PRINT(" "); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
uint32_t number;
|
||||||
|
const char *name;
|
||||||
|
} section_flag_names[] = {
|
||||||
|
{
|
||||||
|
.number = KERNAUX_ELF_SECT_FLAGS_WRITE,
|
||||||
|
.name = "WRITE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.number = KERNAUX_ELF_SECT_FLAGS_ALLOC,
|
||||||
|
.name = "ALLOC",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.number = KERNAUX_ELF_SECT_FLAGS_EXECINSTR,
|
||||||
|
.name = "EXECINSTR",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.number = KERNAUX_ELF_SECT_FLAGS_MASKPROC,
|
||||||
|
.name = "MASKPROC",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void KernAux_ELF_Section_Flags_print(
|
||||||
|
uint16_t flags,
|
||||||
|
KernAux_Display display,
|
||||||
|
unsigned basic_indentation,
|
||||||
|
unsigned indentation_delta,
|
||||||
|
bool indent_first
|
||||||
|
);
|
||||||
|
|
||||||
void KernAux_Multiboot2_Info_print(
|
void KernAux_Multiboot2_Info_print(
|
||||||
const struct KernAux_Multiboot2_Info *const multiboot2_info,
|
const struct KernAux_Multiboot2_Info *const multiboot2_info,
|
||||||
const KernAux_Display display
|
const KernAux_Display display
|
||||||
|
@ -308,31 +348,43 @@ void KernAux_Multiboot2_ITag_MemoryMap_print(
|
||||||
|
|
||||||
// Print data:
|
// Print data:
|
||||||
|
|
||||||
PRINTLN (" varies(entry_size) entries[]: [");
|
if (tag->entry_size == 0 ||
|
||||||
|
(tag->base.size - sizeof(*tag)) / tag->entry_size == 0)
|
||||||
|
{
|
||||||
|
PRINTLN (" varies(entry_size) entries[]: []");
|
||||||
|
} else {
|
||||||
|
PRINTLN (" varies(entry_size) entries[]: [");
|
||||||
|
|
||||||
const struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase *const entries =
|
const struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*
|
||||||
(struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*)
|
const entries =
|
||||||
KERNAUX_MULTIBOOT2_DATA((struct KernAux_Multiboot2_ITag_MemoryMap*)tag);
|
(struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*)
|
||||||
|
KERNAUX_MULTIBOOT2_DATA(tag);
|
||||||
|
|
||||||
for (
|
for (
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
index < (tag->base.size - sizeof(*tag)) / tag->entry_size;
|
index < (tag->base.size - sizeof(*tag)) / tag->entry_size;
|
||||||
++index
|
++index
|
||||||
) {
|
) {
|
||||||
KERNAUX_CAST_CONST(unsigned long long, base_addr, entries[index].base_addr);
|
KERNAUX_CAST_CONST(unsigned long long, base_addr,
|
||||||
KERNAUX_CAST_CONST(unsigned long long, length, entries[index].length);
|
entries[index].base_addr);
|
||||||
KERNAUX_CAST_CONST(unsigned long, type, entries[index].type);
|
KERNAUX_CAST_CONST(unsigned long long, length,
|
||||||
KERNAUX_CAST_CONST(unsigned long, reserved, entries[index].reserved);
|
entries[index].length);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, type,
|
||||||
|
entries[index].type);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, reserved,
|
||||||
|
entries[index].reserved);
|
||||||
|
|
||||||
PRINTLNF(" [%zu] entry: {", index);
|
PRINTLNF(" [%zu]: {", index);
|
||||||
PRINTLNF(" u64 base_addr: 0x%llx", base_addr);
|
PRINTLNF(" u64 base_addr: 0x%llx", base_addr);
|
||||||
PRINTLNF(" u64 length: %llu", length);
|
PRINTLNF(" u64 length: %llu", length);
|
||||||
PRINTLNF(" u32 type: %lu", type);
|
PRINTLNF(" u32 type: %lu", type);
|
||||||
PRINTLNF(" u32 reserved: 0x%lx", reserved);
|
PRINTLNF(" u32 reserved: 0x%lx", reserved);
|
||||||
PRINTLN (" }");
|
PRINTLN (" }");
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTLN(" ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTLN(" ]");
|
|
||||||
FOOTER;
|
FOOTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +478,62 @@ void KernAux_Multiboot2_ITag_ELFSymbols_print(
|
||||||
PRINTLNF(" u32 entsize: %lu", entsize);
|
PRINTLNF(" u32 entsize: %lu", entsize);
|
||||||
PRINTLNF(" u32 shndx: %lu", shndx);
|
PRINTLNF(" u32 shndx: %lu", shndx);
|
||||||
|
|
||||||
// TODO: Print data?
|
// Print data:
|
||||||
|
|
||||||
|
if (tag->num == 0) {
|
||||||
|
PRINTLN(" varies(entsize) section_headers[]: []");
|
||||||
|
} else {
|
||||||
|
PRINTLN(" varies(entsize) section_headers[]: [");
|
||||||
|
|
||||||
|
const struct KernAux_ELF_Section *section =
|
||||||
|
(const struct KernAux_ELF_Section*)
|
||||||
|
KERNAUX_MULTIBOOT2_DATA(tag);
|
||||||
|
|
||||||
|
for (size_t index = 0; index < tag->num; ++index) {
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, name, section->name);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, type, section->type);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, addr, section->addr);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, offset, section->offset);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, size, section->size);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, link, section->link);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, info, section->info);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, addralign, section->addralign);
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, s_entsize, section->entsize);
|
||||||
|
|
||||||
|
const char *const type_name =
|
||||||
|
#ifdef WITH_ELF
|
||||||
|
KernAux_ELF_Section_Type_to_str(section->type);
|
||||||
|
#else
|
||||||
|
"?";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PRINTLNF(" [%zu]: {", index);
|
||||||
|
PRINTLNF(" name: %lu", name);
|
||||||
|
PRINTLNF(" type: %lu (%s)", type, type_name);
|
||||||
|
PRINT (" flags: ");
|
||||||
|
KernAux_ELF_Section_Flags_print(
|
||||||
|
section->flags,
|
||||||
|
display,
|
||||||
|
6,
|
||||||
|
2,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
PRINTLNF(" addr: 0x%lx", addr);
|
||||||
|
PRINTLNF(" offset: 0x%lx", offset);
|
||||||
|
PRINTLNF(" size: %lu", size);
|
||||||
|
PRINTLNF(" link: %lu", link);
|
||||||
|
PRINTLNF(" info: %lu", info);
|
||||||
|
PRINTLNF(" addralign: %lu", addralign);
|
||||||
|
PRINTLNF(" entsize: %lu", s_entsize);
|
||||||
|
PRINTLN (" }");
|
||||||
|
|
||||||
|
section =
|
||||||
|
(const struct KernAux_ELF_Section*)
|
||||||
|
(((const uint8_t*)section) + tag->entsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTLN(" ]");
|
||||||
|
}
|
||||||
|
|
||||||
FOOTER;
|
FOOTER;
|
||||||
}
|
}
|
||||||
|
@ -610,3 +717,45 @@ void KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr_print(
|
||||||
|
|
||||||
FOOTER;
|
FOOTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KernAux_ELF_Section_Flags_print(
|
||||||
|
const uint16_t flags,
|
||||||
|
const KernAux_Display display,
|
||||||
|
const unsigned basic_indentation,
|
||||||
|
const unsigned indentation_delta,
|
||||||
|
const bool indent_first
|
||||||
|
) {
|
||||||
|
KERNAUX_CAST_CONST(unsigned long, flags_ul, flags);
|
||||||
|
|
||||||
|
if (indent_first) INDENT;
|
||||||
|
PRINTF("0x%lx (", flags_ul);
|
||||||
|
|
||||||
|
bool is_first = true;
|
||||||
|
|
||||||
|
for (
|
||||||
|
size_t index = 0;
|
||||||
|
index < sizeof(section_flag_names) / sizeof(section_flag_names[0]);
|
||||||
|
++index
|
||||||
|
) {
|
||||||
|
if (flags & section_flag_names[index].number) {
|
||||||
|
if (is_first) {
|
||||||
|
PRINTLN("");
|
||||||
|
} else {
|
||||||
|
PRINTLN(" |");
|
||||||
|
}
|
||||||
|
|
||||||
|
INDENT;
|
||||||
|
INDENT_MORE;
|
||||||
|
PRINTF("%s", section_flag_names[index].name);
|
||||||
|
is_first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_first) {
|
||||||
|
PRINTLN(")");
|
||||||
|
} else {
|
||||||
|
PRINTLN("");
|
||||||
|
INDENT;
|
||||||
|
PRINTLN(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,25 +4,4 @@
|
||||||
|
|
||||||
#include <kernaux/elf.h>
|
#include <kernaux/elf.h>
|
||||||
|
|
||||||
#include <assert.h>
|
void test_main() {}
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define BUFFER_SIZE (1024 * 1024)
|
|
||||||
|
|
||||||
void test_main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
assert(argc >= 1);
|
|
||||||
|
|
||||||
FILE *const fd = fopen(argv[0], "r");
|
|
||||||
assert(fd);
|
|
||||||
|
|
||||||
uint8_t buffer[BUFFER_SIZE];
|
|
||||||
const size_t size = fread(buffer, sizeof(uint8_t), BUFFER_SIZE, fd);
|
|
||||||
assert(size > 0);
|
|
||||||
|
|
||||||
assert(KernAux_ELF_Header_is_valid((struct KernAux_ELF_Header*)buffer));
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue