mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
139
include/exec.hpp
139
include/exec.hpp
@ -23,12 +23,13 @@
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
#include <std.hpp>
|
||||
#include <errno.h>
|
||||
#include <vector>
|
||||
#include <elf.h>
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
enum BinaryType
|
||||
enum BinaryType : int
|
||||
{
|
||||
BinTypeInvalid,
|
||||
BinTypeFex,
|
||||
@ -39,28 +40,6 @@ namespace Execute
|
||||
BinTypeUnknown
|
||||
};
|
||||
|
||||
enum ExStatus
|
||||
{
|
||||
Unknown,
|
||||
OK,
|
||||
Unsupported,
|
||||
GenericError,
|
||||
LoadingProcedureFailed,
|
||||
InvalidFile,
|
||||
InvalidFileFormat,
|
||||
InvalidFileHeader,
|
||||
InvalidFileData,
|
||||
InvalidFileEntryPoint,
|
||||
InvalidFilePath
|
||||
};
|
||||
|
||||
struct SpawnData
|
||||
{
|
||||
ExStatus Status;
|
||||
Tasking::PCB *Process;
|
||||
Tasking::TCB *Thread;
|
||||
};
|
||||
|
||||
struct SharedLibrary
|
||||
{
|
||||
char Identifier[64];
|
||||
@ -72,25 +51,6 @@ namespace Execute
|
||||
size_t Length;
|
||||
};
|
||||
|
||||
struct ELFBaseLoad
|
||||
{
|
||||
bool Success;
|
||||
bool Interpreter;
|
||||
SpawnData sd;
|
||||
Tasking::IP InstructionPointer;
|
||||
|
||||
std::vector<const char *> NeededLibraries;
|
||||
void *MemoryImage;
|
||||
void *VirtualMemoryImage;
|
||||
|
||||
/* This should be deleted after copying the allocated pages to the thread
|
||||
Intended to be used only inside BaseLoad.cpp */
|
||||
Memory::MemMgr *TmpMem;
|
||||
|
||||
/* Same as above, for BaseLoad.cpp only */
|
||||
std::vector<AuxiliaryVector> auxv;
|
||||
};
|
||||
|
||||
struct MmImage
|
||||
{
|
||||
void *Physical;
|
||||
@ -100,46 +60,46 @@ namespace Execute
|
||||
class ELFObject
|
||||
{
|
||||
private:
|
||||
ELFBaseLoad BaseLoadInfo{};
|
||||
bool IsElfValid;
|
||||
const char **ELFargv;
|
||||
const char **ELFenvp;
|
||||
std::vector<AuxiliaryVector> Elfauxv;
|
||||
Tasking::IP ip;
|
||||
|
||||
ELFBaseLoad LoadExec_x86_32(VirtualFileSystem::File &ElfFile,
|
||||
Tasking::PCB *TargetProcess);
|
||||
void LoadExec_x86_32(int fd,
|
||||
Tasking::PCB *TargetProcess);
|
||||
|
||||
ELFBaseLoad LoadExec_x86_64(VirtualFileSystem::File &ElfFile,
|
||||
Tasking::PCB *TargetProcess);
|
||||
void LoadExec_x86_64(int fd,
|
||||
Tasking::PCB *TargetProcess);
|
||||
|
||||
ELFBaseLoad LoadDyn_x86_32(VirtualFileSystem::File &ElfFile,
|
||||
Tasking::PCB *TargetProcess,
|
||||
bool IsLibrary);
|
||||
void LoadDyn_x86_32(int fd,
|
||||
Tasking::PCB *TargetProcess);
|
||||
|
||||
ELFBaseLoad LoadDyn_x86_64(VirtualFileSystem::File &ElfFile,
|
||||
Tasking::PCB *TargetProcess,
|
||||
bool IsLibrary);
|
||||
void LoadDyn_x86_64(int fd,
|
||||
Tasking::PCB *TargetProcess);
|
||||
|
||||
bool LoadInterpreter(int fd,
|
||||
Tasking::PCB *TargetProcess);
|
||||
|
||||
public:
|
||||
ELFBaseLoad GetBaseLoadInfo() { return BaseLoadInfo; }
|
||||
bool IsValid() { return BaseLoadInfo.Success; }
|
||||
decltype(IsElfValid) &IsValid = IsElfValid;
|
||||
decltype(ip) &InstructionPointer = ip;
|
||||
decltype(ELFargv) &argv = ELFargv;
|
||||
decltype(ELFenvp) &envp = ELFenvp;
|
||||
decltype(Elfauxv) &auxv = Elfauxv;
|
||||
|
||||
ELFObject(char *AbsolutePath,
|
||||
Tasking::PCB *TargetProcess,
|
||||
bool IsLibrary = false);
|
||||
const char **argv,
|
||||
const char **envp);
|
||||
~ELFObject();
|
||||
};
|
||||
|
||||
/* Full binary size. */
|
||||
BinaryType GetBinaryType(void *Image);
|
||||
BinaryType GetBinaryType(const char *Path);
|
||||
|
||||
BinaryType GetBinaryType(char *Path);
|
||||
|
||||
SpawnData Spawn(char *Path, const char **argv, const char **envp);
|
||||
|
||||
ELFBaseLoad ELFLoad(char *Path, const char **argv, const char **envp,
|
||||
Tasking::TaskCompatibility Compatibility = Tasking::TaskCompatibility::Native);
|
||||
|
||||
void ELFInterpreterIPCThread(Tasking::PCB *TargetProcess,
|
||||
std::string *TargetPath,
|
||||
void *MemoryImage,
|
||||
std::vector<const char *> *NeededLibraries);
|
||||
int Spawn(char *Path, const char **argv, const char **envp,
|
||||
Tasking::PCB *Parent = nullptr,
|
||||
Tasking::TaskCompatibility Compatibility = Tasking::TaskCompatibility::Native);
|
||||
|
||||
bool ELFIs64(void *Header);
|
||||
Elf64_Shdr *GetELFSheader(Elf64_Ehdr *Header);
|
||||
@ -147,44 +107,17 @@ namespace Execute
|
||||
char *GetELFStringTable(Elf64_Ehdr *Header);
|
||||
char *ELFLookupString(Elf64_Ehdr *Header, uintptr_t Offset);
|
||||
Elf64_Sym *ELFLookupSymbol(Elf64_Ehdr *Header, const char *Name);
|
||||
Elf64_Sym ELFLookupSymbol(VirtualFileSystem::File &ElfFile, const char *Name);
|
||||
Elf64_Sym ELFLookupSymbol(int fd, const char *Name);
|
||||
uintptr_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint64_t Index);
|
||||
|
||||
std::vector<Elf64_Phdr> ELFGetSymbolType_x86_64(VirtualFileSystem::File &ElfFile, SegmentTypes Tag);
|
||||
std::vector<Elf32_Phdr> ELFGetSymbolType_x86_32(VirtualFileSystem::File &ElfFile, SegmentTypes Tag);
|
||||
std::vector<Elf64_Phdr> ELFGetSymbolType_x86_64(int fd, SegmentTypes Tag);
|
||||
std::vector<Elf32_Phdr> ELFGetSymbolType_x86_32(int fd, SegmentTypes Tag);
|
||||
|
||||
std::vector<Elf64_Shdr> ELFGetSections_x86_64(VirtualFileSystem::File &ElfFile, const char *SectionName);
|
||||
std::vector<Elf32_Shdr> ELFGetSections_x86_32(VirtualFileSystem::File &ElfFile, const char *SectionName);
|
||||
std::vector<Elf64_Shdr> ELFGetSections_x86_64(int fd, const char *SectionName);
|
||||
std::vector<Elf32_Shdr> ELFGetSections_x86_32(int fd, const char *SectionName);
|
||||
|
||||
std::vector<Elf64_Dyn> ELFGetDynamicTag_x86_64(VirtualFileSystem::File &ElfFile, DynamicArrayTags Tag);
|
||||
std::vector<Elf32_Dyn> ELFGetDynamicTag_x86_32(VirtualFileSystem::File &ElfFile, DynamicArrayTags Tag);
|
||||
|
||||
void CopyLOADSegments(VirtualFileSystem::File &ElfFile, uintptr_t HdrsBase, uintptr_t PhysicalBase);
|
||||
void GetBaseAndSize(VirtualFileSystem::File &ElfFile, uintptr_t &Base, size_t &Size);
|
||||
|
||||
/**
|
||||
* @brief Create a ELF Memory Image
|
||||
*
|
||||
* @param mem The memory manager to use
|
||||
* @param vmm Memory::Virtual object to use
|
||||
* @param ElfFile The ELF File
|
||||
* @param Length Length of @p ElfFile
|
||||
* @return The Memory Image (Physical and Virtual)
|
||||
*/
|
||||
MmImage ELFCreateMemoryImage(Memory::MemMgr *mem,
|
||||
Memory::Virtual &vmm,
|
||||
VirtualFileSystem::File &ElfFile,
|
||||
size_t Length);
|
||||
|
||||
uintptr_t LoadELFInterpreter(Memory::MemMgr *mem,
|
||||
Memory::Virtual &vmm,
|
||||
const char *Interpreter);
|
||||
|
||||
void LibraryManagerService();
|
||||
bool AddLibrary(char *Identifier,
|
||||
VirtualFileSystem::File &ExFile,
|
||||
const Memory::Virtual &vmm = Memory::Virtual());
|
||||
SharedLibrary GetLibrary(char *Identifier);
|
||||
std::vector<Elf64_Dyn> ELFGetDynamicTag_x86_64(int fd, DynamicArrayTags Tag);
|
||||
std::vector<Elf32_Dyn> ELFGetDynamicTag_x86_32(int fd, DynamicArrayTags Tag);
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILE_EXECUTE_H__
|
||||
|
Reference in New Issue
Block a user