Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibAPI added ELF sections, LibTC added Vector constructor, Spawner fixed memory leak #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions Libs/LibApi/Api/ELF32.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ typedef struct {
u16 e_phnum; /* Number of entries in program header table */
u16 e_shentsize; /* Size of one entry in section header table */
u16 e_shnum; /* Number of entries in section header table */
u16 e_shstrndx; /* Section header table index of section name string table */
u16 e_shstrndx; /* Section header string table index */
} A_PACKED Elf32Ehdr;

/**
* @brief ELF program headers
*/
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_TLS 7
#define PT_NULL 0 /* Unused header */
#define PT_LOAD 1 /* Loadable segment */
#define PT_DYNAMIC 2 /* Linking information */
#define PT_INTERP 3 /* Path to the interpreter */
#define PT_NOTE 4 /* Auxiliary information */
#define PT_SHLIB 5 /* Reserved */
#define PT_PHDR 6 /* Program header table */
#define PT_TLS 7 /* Thread local storage */
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7FFFFFFF

/**
* @brief ELF Program header protection flags
* @brief ELF program header protection flags
*/
#define PF_X 1
#define PF_W 2
Expand All @@ -114,13 +114,42 @@ typedef struct {
u32 p_type; /* Type of the segment */
u32 p_offset; /* Offset of the segment in the binary file */
u32 p_vaddr; /* Virtual address */
u32 p_paddr; /* Not relevant for System V */
u32 p_paddr; /* Physical address */
u32 p_filesz; /* Size of the segment in the binary file */
u32 p_memsz; /* Size of the segment in memory */
u32 p_flags; /* Segment flags */
u32 p_align; /* Alignment information */
} A_PACKED Elf32Phdr;

/**
* @brief ELF section header
*/
#define SHT_NULL 0 /* Inactive header */
#define SHT_PROGBITS 1 /* Information defined by the program */
#define SHT_SYMTAB 2 /* Symbol table */
#define SHT_STRTAB 3 /* String table */
#define SHT_RELA 4 /* Relocation entries with explicit addend. Not in x86 ABI */
#define SHT_HASH 5 /* Symbol hash table */
#define SHT_DYNAMIC 6 /* Information for dynamic linking */
#define SHT_NOTE 7 /* Notes */
#define SHT_NOBITS 8 /* Program defined with empty space */
#define SHT_REL 9 /* Relocation entries with implicit addend */
#define SHT_SHLIB 10 /* Reserved */
#define SHT_DYNSYM 11 /* Dynamic symbols */

typedef struct {
u32 sh_name; /* Section name */
u32 sh_type; /* Section type */
u32 sh_flags; /* Section flags */
u32 sh_addr; /* Section virtual address at execution */
u32 sh_offset; /* Section file offset */
u32 sh_size; /* Section size in bytes */
u32 sh_link; /* Link to another section */
u32 sh_info; /* Additional section information */
u32 sh_addralign; /* Section alignment */
u32 sh_entsize; /* Entry size if section holds table */
} A_PACKED Elf32Shdr;

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions Libs/LibTC/Collection/Vector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public:
explicit Vector() = default;
explicit Vector(usize capacity);
explicit Vector(AdoptTag, T* data_storage, usize size);
explicit Vector(AdoptTag, T* data_storage, usize size, usize capacity);

Vector(Vector const& rhs);
Vector(Vector&& rhs) noexcept;
Expand Down
7 changes: 7 additions & 0 deletions Libs/LibTC/Collection/Vector.hhi
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ Vector<T>::Vector(AdoptTag, T* data_storage, usize size)
, m_values_count{ size } {
}

template<typename T>
Vector<T>::Vector(AdoptTag, T* data_storage, usize size, usize capacity)
: m_data_storage{ data_storage }
, m_data_capacity{ size }
, m_values_count{ capacity } {
}

template<typename T>
Vector<T>::Vector(Vector const& rhs)
: m_values_count{ rhs.m_values_count } {
Expand Down
2 changes: 1 addition & 1 deletion Userspace/Servers/Spawner/Elf32Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ LoaderStatus Elf32Loader::loadTlsSegment(Elf32Phdr* phdr) {
}
}

delete tlsContent;
delete[] tlsContent;

return result;
}
Expand Down