docs: documented ELF parser

This commit is contained in:
antifallobst 2023-03-01 21:03:33 +01:00
parent 1f448a7b76
commit 17156ab824
1 changed files with 141 additions and 1 deletions

View File

@ -256,7 +256,9 @@ This is not a really a placeholder, but you can use this to mask the % sign,
so it will be interpreted as just a `%` instead of a placeholder.
##
## Executables
NoxOS uses the **ELF** executable format, which is the linux/unix standard.
Further information can be found in the `Syscalls` and `drivers/elf/elf.h` documentation.
---
@ -284,6 +286,144 @@ More information can be found on the limine project's [GitHub](https://github.co
## drivers
### elf/elf.h
#### `elf_executable_T` - struct
This struct holds the parsed data of an ELF executable.
| Name | Type | Description |
|--------------|--------------|----------------------------------------------------------------------------------------------------------------------------------|
| header | elf_header_T | The header of the elf file |
| num_symbols | uint64_t | The size of _symbols_ |
| symbols | symbol_T* | An array containing all symbols of the elf file |
| string_table | void* | A copy of the elf files `.strtab` section, all strings are referenced here to have them available even if the elf file is closed |
#### `elf_executable_temp_T` - struct
This struct is used while generating an `elf_executable_T`.
It holds parse-time information about the elf file.
| Name | Type | Description |
|-----------------------------|-------------------|------------------------------------------------|
| executable | elf_executable_T* | A pointer to the final `elf_executable_T` |
| symbol_table | elf_section_T* | A pointer to `.symtab` in _buffer_ |
| section_header_string_table | elf_section_T* | A pointer to `.shstrtab` in _buffer_ |
| buffer | uint8_t* | The buffer where the executable is loaded from |
#### `elf_executable_create(buffer)` - function (elf_executable_T*)
Generates an `elf_executable_T` from an elf file loaded to **_buffer_** and returns a pointer to it.
#### `elf_executable_destruct(executable)` - function (void)
Frees all memory allocated for **_executable_**.
### elf/header.h
The enums in this header describe the possible values that a field of the elf header can have.
#### `elf_target_architecture_E` - enum
Field in header: **identity[4]**
#### `elf_endianness_E` - enum
Field in header: **identity[5]**
#### `elf_sysabi_E` - enum
Field in header: **identity[7]**
#### `elf_object_type_E` - enum
Field in header: **type**
#### `elf_instruction_set_E` - enum
Field in header: **isa**
#### `elf_header_T` - struct
| Name | Type | Description |
|----------------------------|-------------|-------------------------------------------------------------------|
| identity | uint8_t[16] | Information like the used endian and the SysABI is stored in here |
| type | uint16_t | The type of the elf file -> `elf_object_type_E` |
| isa | uint16_t | The used instruction set -> `elf_instruction_set_E` |
| version | uint32_t | ELF version |
| address_entry_point | uint64_t | The start point for program execution |
| offset_program_header | uint64_t | The position of the program header array in the file |
| offset_section_header | uint64_t | The position of the section header array in the file |
| flags | uint32_t | Architecture dependent, can be ignored |
| len_header | uint16_t | The size of this header |
| len_program_header_entry | uint16_t | The size of one program header |
| num_program_header_entries | uint16_t | The amount of program headers |
| len_section_header_entry | uint16_t | The size of one section header |
| num_section_header_entries | uint16_t | The amount of section headers |
| string_section_index | uint16_t | The section header index of the `.shstrtab` section |
#### `g_elf_target_architecture_strings` - global variable
An array of strings matching `elf_target_architecture_E`.
#### `g_elf_endianness_strings` - global variable
An array of strings matching `elf_endianess_E`.
#### `g_elf_sysabi_strings` - global variable
An array of strings matching `elf_sysabi_E`.
#### `g_elf_object_type_strings` - global variable
An array of strings matching `elf_object_type_E`.
#### `g_elf_instruction_set_strings` - global variable
An array of strings matching `elf_instruction_set_E`.
### elf/section.h
#### `elf_section_type_E` - enum
- **Null** - These sections can be ignored
- **Program Data** - These link to segments, if I remember right
- **Symbol Table** - Here are all the executables' symbols stored
- **String Table** - Here are all strings stored
- **RelocationA** - Contains relocation information
- **Hash** - Symbol Table hash table
- **Dynamic Link** - This provides information for the dynamic linker
- **Note** - notes that were created by the compiler / toolchain
- **Nobits** - Nulled data like `.bss`
#### `elf_section_T` - struct
| Name | Type | Description |
|-----------------|----------|-------------------------------------------------------------------|
| name_offset | uint32_t | The offset of the sections name in `.shstrtab` |
| type | uint32_t | The type of the section -> `elf_section_type_E` |
| flags | uint64_t | Sections attribute flags |
| virtual_address | uint64_t | The address where the section should be mapped to (if it's not 0) |
| offset | uint64_t | The sections offset in the file |
| length | uint64_t | The size of the section |
| link | uint32_t | Type specific link to another section |
| info | uint32_t | Type specific information |
| alignment | uint64_t | If the section is aligned, this value specifies the alignment |
| entry_size | uint64_t | The size of the sections entries |
#### `g_elf_section_type_strings` - global variable
An array of strings matching `elf_section_type_E`.
### elf/symbol.h
#### `ELF_SYMBOL_TYPE(info)` - macro
Extracts the `elf_symbol_type_E` from the symbols info value.
#### `elf_symbol_type_E` - enum
- **None** - Unspecified type
- **Object** - Data objects like variables, arrays, etc.
- **Func** - Function
- **Section** - Associated section
- **File** - The path to the source file associated with the object
- **Common** - Uninitialized common blocks
- **TLS** - Thread Local Storage
#### `elf_symbol_T` - struct
| Name | Type | Description |
|-----------------------|-------------------------------------------------------------------|-------------|
| name_offset | The offset of the symbols name in `.strtab` | |
| info | Information about the symbol (type, bind) | |
| other | Information about the symbol (visibility) | |
| related_section_index | The index of the symbols related section | |
| value | Value, in most cases this is an address | |
| length | The size of the symbol (e.g. num bytes if the symbol is an array) | |
### fs/ramfs.h
**Warning:** This is a filesystem specific driver, by this it should only be accessed by the vfs.