mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-01 18:39:16 +00:00
fix(kernel/vfs): 🎉 a complete rewrite of the vfs
This is the fourth time re-writing the VFS, hope this will be the last. Tried to make it as modular as possible so this won't be necessary in the future. 🙏
This change required the entire kernel code to be modified.
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
BinaryType GetBinaryType(FileNode *Node)
|
||||
BinaryType GetBinaryType(Node &Node)
|
||||
{
|
||||
debug("Checking binary type of %s", Node->Path.c_str());
|
||||
BinaryType type;
|
||||
@ -34,13 +34,13 @@ namespace Execute
|
||||
ReturnLogError((BinaryType)-ENOENT, "Node is null");
|
||||
|
||||
Elf_Ehdr ehdr;
|
||||
Node->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(Node, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
mach_header mach;
|
||||
Node->Read(&mach, sizeof(mach_header), 0);
|
||||
fs->Read(Node, &mach, sizeof(mach_header), 0);
|
||||
|
||||
IMAGE_DOS_HEADER mz;
|
||||
Node->Read(&mz, sizeof(IMAGE_DOS_HEADER), 0);
|
||||
fs->Read(Node, &mz, sizeof(IMAGE_DOS_HEADER), 0);
|
||||
|
||||
/* Check ELF header. */
|
||||
if (ehdr.e_ident[EI_MAG0] == ELFMAG0 &&
|
||||
@ -64,10 +64,10 @@ namespace Execute
|
||||
else if (mz.e_magic == IMAGE_DOS_SIGNATURE)
|
||||
{
|
||||
IMAGE_NT_HEADERS pe;
|
||||
Node->Read(&pe, sizeof(IMAGE_NT_HEADERS), mz.e_lfanew);
|
||||
fs->Read(Node, &pe, sizeof(IMAGE_NT_HEADERS), mz.e_lfanew);
|
||||
|
||||
IMAGE_OS2_HEADER ne;
|
||||
Node->Read(&ne, sizeof(IMAGE_OS2_HEADER), mz.e_lfanew);
|
||||
fs->Read(Node, &ne, sizeof(IMAGE_OS2_HEADER), mz.e_lfanew);
|
||||
|
||||
/* TODO: LE, EDOS */
|
||||
if (pe.Signature == IMAGE_NT_SIGNATURE)
|
||||
@ -99,14 +99,14 @@ namespace Execute
|
||||
|
||||
BinaryType GetBinaryType(std::string Path)
|
||||
{
|
||||
FileNode *node = fs->GetByPath(Path.c_str(), nullptr);
|
||||
Node node = fs->Lookup(thisProcess->Info.RootNode, Path);
|
||||
if (node->IsSymbolicLink())
|
||||
{
|
||||
char buffer[512];
|
||||
node->ReadLink(buffer, sizeof(buffer));
|
||||
node = fs->GetByPath(buffer, node->Parent);
|
||||
fs->ReadLink(node, buffer, sizeof(buffer));
|
||||
node = fs->Lookup(node->Parent, buffer);
|
||||
}
|
||||
debug("Checking binary type of %s (returning %p)", Path.c_str(), node);
|
||||
debug("Checking binary type of %s (returning %p)", Path.c_str(), node.get());
|
||||
assert(node != nullptr);
|
||||
return GetBinaryType(node);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ using namespace vfs;
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
void ELFObject::GenerateAuxiliaryVector(Memory::VirtualMemoryArea *vma, FileNode *fd, Elf_Ehdr ELFHeader, uintptr_t EntryPoint, uintptr_t BaseAddress)
|
||||
void ELFObject::GenerateAuxiliaryVector(Memory::VirtualMemoryArea *vma, Node &fd, Elf_Ehdr ELFHeader, uintptr_t EntryPoint, uintptr_t BaseAddress)
|
||||
{
|
||||
char *aux_platform = (char *)vma->RequestPages(1, true); /* TODO: 4KiB is too much for this */
|
||||
strcpy(aux_platform, "x86_64");
|
||||
@ -79,7 +79,7 @@ namespace Execute
|
||||
#endif
|
||||
}
|
||||
|
||||
void ELFObject::LoadSegments(FileNode *fd, PCB *TargetProcess, Elf_Ehdr &ELFHeader, uintptr_t &BaseAddress)
|
||||
void ELFObject::LoadSegments(Node &fd, PCB *TargetProcess, Elf_Ehdr &ELFHeader, uintptr_t &BaseAddress)
|
||||
{
|
||||
Memory::Virtual vmm(TargetProcess->PageTable);
|
||||
Memory::VirtualMemoryArea *vma = TargetProcess->vma;
|
||||
@ -91,7 +91,7 @@ namespace Execute
|
||||
size_t SegmentsSize = 0;
|
||||
for (Elf_Half i = 0; i < ELFHeader.e_phnum; i++)
|
||||
{
|
||||
fd->Read(&ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
fs->Read(fd, &ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
|
||||
if (ProgramHeader.p_type == PT_LOAD || ProgramHeader.p_type == PT_DYNAMIC)
|
||||
{
|
||||
@ -113,7 +113,7 @@ namespace Execute
|
||||
|
||||
for (Elf_Half i = 0; i < ELFHeader.e_phnum; i++)
|
||||
{
|
||||
fd->Read(&ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
fs->Read(fd, &ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
|
||||
switch (ProgramHeader.p_type)
|
||||
{
|
||||
@ -132,7 +132,7 @@ namespace Execute
|
||||
|
||||
if (ProgramHeader.p_filesz > 0)
|
||||
{
|
||||
fd->Read(SegmentDestination, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
fs->Read(fd, (void *)SegmentDestination, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
}
|
||||
|
||||
if (ProgramHeader.p_memsz - ProgramHeader.p_filesz > 0)
|
||||
@ -158,7 +158,7 @@ namespace Execute
|
||||
|
||||
if (ProgramHeader.p_filesz > 0)
|
||||
{
|
||||
fd->Read(DynamicSegmentDestination, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
fs->Read(fd, (void *)DynamicSegmentDestination, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
}
|
||||
|
||||
if (ProgramHeader.p_memsz - ProgramHeader.p_filesz > 0)
|
||||
@ -212,7 +212,7 @@ namespace Execute
|
||||
{
|
||||
for (Elf64_Half i = 0; i < ELFHeader.e_phnum; i++)
|
||||
{
|
||||
fd->Read(&ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
fs->Read(fd, &ProgramHeader, sizeof(Elf_Phdr), ELFHeader.e_phoff + (i * sizeof(Elf_Phdr)));
|
||||
switch (ProgramHeader.p_type)
|
||||
{
|
||||
case PT_LOAD:
|
||||
@ -245,7 +245,7 @@ namespace Execute
|
||||
if (ProgramHeader.p_filesz > 0)
|
||||
{
|
||||
debug("%d %#lx %d", ProgramHeader.p_offset, (uint8_t *)pAddr + destOffset, ProgramHeader.p_filesz);
|
||||
fd->Read((uint8_t *)pAddr + destOffset, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
fs->Read(fd, (uint8_t *)pAddr + destOffset, ProgramHeader.p_filesz, ProgramHeader.p_offset);
|
||||
}
|
||||
|
||||
if (ProgramHeader.p_memsz - ProgramHeader.p_filesz > 0)
|
||||
@ -265,35 +265,35 @@ namespace Execute
|
||||
case PT_NOTE:
|
||||
{
|
||||
Elf_Nhdr NoteHeader;
|
||||
fd->Read(&NoteHeader, sizeof(Elf_Nhdr), ProgramHeader.p_offset);
|
||||
fs->Read(fd, &NoteHeader, sizeof(Elf_Nhdr), ProgramHeader.p_offset);
|
||||
|
||||
switch (NoteHeader.n_type)
|
||||
{
|
||||
case NT_PRSTATUS:
|
||||
{
|
||||
Elf_Prstatus prstatus;
|
||||
fd->Read(&prstatus, sizeof(Elf_Prstatus), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
fs->Read(fd, &prstatus, sizeof(Elf_Prstatus), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
debug("PRSTATUS: %#lx", prstatus.pr_reg[0]);
|
||||
break;
|
||||
}
|
||||
case NT_PRPSINFO:
|
||||
{
|
||||
Elf_Prpsinfo prpsinfo;
|
||||
fd->Read(&prpsinfo, sizeof(Elf_Prpsinfo), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
fs->Read(fd, &prpsinfo, sizeof(Elf_Prpsinfo), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
debug("PRPSINFO: %s", prpsinfo.pr_fname);
|
||||
break;
|
||||
}
|
||||
case NT_PLATFORM:
|
||||
{
|
||||
char platform[256];
|
||||
fd->Read(&platform, sizeof(platform), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
fs->Read(fd, &platform, sizeof(platform), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
debug("PLATFORM: %s", platform);
|
||||
break;
|
||||
}
|
||||
case NT_AUXV:
|
||||
{
|
||||
Elf_auxv_t auxv;
|
||||
fd->Read(&auxv, sizeof(Elf_auxv_t), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
fs->Read(fd, &auxv, sizeof(Elf_auxv_t), ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
debug("AUXV: %#lx", auxv.a_un.a_val);
|
||||
break;
|
||||
}
|
||||
@ -311,7 +311,7 @@ namespace Execute
|
||||
debug("TLS Size: %ld (%ld pages)",
|
||||
tlsSize, TO_PAGES(tlsSize));
|
||||
void *tlsMemory = vma->RequestPages(TO_PAGES(tlsSize));
|
||||
fd->Read(tlsMemory, tlsSize, ProgramHeader.p_offset);
|
||||
fs->Read(fd, tlsMemory, tlsSize, ProgramHeader.p_offset);
|
||||
TargetProcess->TLS = {
|
||||
.pBase = uintptr_t(tlsMemory),
|
||||
.vBase = ProgramHeader.p_vaddr,
|
||||
@ -346,12 +346,12 @@ namespace Execute
|
||||
case PT_GNU_PROPERTY:
|
||||
{
|
||||
Elf_Nhdr NoteHeader;
|
||||
fd->Read(&NoteHeader, sizeof(Elf_Nhdr), ProgramHeader.p_offset);
|
||||
fs->Read(fd, &NoteHeader, sizeof(Elf_Nhdr), ProgramHeader.p_offset);
|
||||
|
||||
if (NoteHeader.n_type == NT_GNU_PROPERTY_TYPE_0)
|
||||
{
|
||||
char noteName[0x400];
|
||||
fd->Read(noteName, NoteHeader.n_namesz, ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
fs->Read(fd, noteName, NoteHeader.n_namesz, ProgramHeader.p_offset + sizeof(Elf_Nhdr));
|
||||
noteName[NoteHeader.n_namesz - 1] = '\0';
|
||||
|
||||
if (strcmp(noteName, "GNU") == 0)
|
||||
@ -394,10 +394,10 @@ namespace Execute
|
||||
TargetProcess->ProgramBreak->InitBrk(ProgramBreak);
|
||||
}
|
||||
|
||||
void ELFObject::LoadExec(FileNode *fd, PCB *TargetProcess)
|
||||
void ELFObject::LoadExec(Node &fd, PCB *TargetProcess)
|
||||
{
|
||||
Elf_Ehdr ehdr{};
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
uintptr_t entry = ehdr.e_entry;
|
||||
debug("Entry point is %#lx", entry);
|
||||
|
||||
@ -424,10 +424,10 @@ namespace Execute
|
||||
#endif
|
||||
}
|
||||
|
||||
void ELFObject::LoadDyn(FileNode *fd, PCB *TargetProcess)
|
||||
void ELFObject::LoadDyn(Node &fd, PCB *TargetProcess)
|
||||
{
|
||||
Elf_Ehdr ehdr{};
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
uintptr_t entry = ehdr.e_entry;
|
||||
debug("Entry point is %#lx", entry);
|
||||
|
||||
@ -465,24 +465,25 @@ namespace Execute
|
||||
Elf_Phdr interp = interpVec.front();
|
||||
std::string interpreterPath;
|
||||
interpreterPath.resize(256);
|
||||
fd->Read(interpreterPath.data(), 256, interp.p_offset);
|
||||
fs->Read(fd, interpreterPath.data(), 256, interp.p_offset);
|
||||
debug("Interpreter: %s", interpreterPath.c_str());
|
||||
|
||||
FileNode *ifd = fs->GetByPath(interpreterPath.c_str(), TargetProcess->Info.RootNode);
|
||||
if (ifd == nullptr)
|
||||
eNode ret = fs->Lookup(TargetProcess->Info.RootNode, interpreterPath);
|
||||
if (ret == false)
|
||||
{
|
||||
warn("Failed to open interpreter file: %s", interpreterPath.c_str());
|
||||
warn("Failed to open interpreter file: %s", ret.what());
|
||||
return;
|
||||
}
|
||||
Node ifd = ret;
|
||||
|
||||
if (ifd->IsSymbolicLink())
|
||||
{
|
||||
char buffer[512];
|
||||
ifd->ReadLink(buffer, sizeof(buffer));
|
||||
ifd = fs->GetByPath(buffer, ifd->Parent);
|
||||
fs->ReadLink(ifd, buffer, sizeof(buffer));
|
||||
ifd = fs->Lookup(ifd->Parent, buffer);
|
||||
}
|
||||
|
||||
debug("ifd: %p, interpreter: %s", ifd, interpreterPath.c_str());
|
||||
debug("ifd: %p, interpreter: %s", ifd.get(), interpreterPath.c_str());
|
||||
if (GetBinaryType(interpreterPath) != BinTypeELF)
|
||||
{
|
||||
warn("Interpreter %s is not an ELF file", interpreterPath.c_str());
|
||||
@ -492,10 +493,10 @@ namespace Execute
|
||||
LoadInterpreter(ifd, TargetProcess);
|
||||
}
|
||||
|
||||
bool ELFObject::LoadInterpreter(FileNode *fd, PCB *TargetProcess)
|
||||
bool ELFObject::LoadInterpreter(Node &fd, PCB *TargetProcess)
|
||||
{
|
||||
Elf_Ehdr ehdr;
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
switch (ehdr.e_type)
|
||||
{
|
||||
@ -550,18 +551,19 @@ namespace Execute
|
||||
return;
|
||||
}
|
||||
|
||||
FileNode *fd = fs->GetByPath(AbsolutePath.c_str(), TargetProcess->Info.RootNode);
|
||||
if (fd == nullptr)
|
||||
eNode ret = fs->Lookup(TargetProcess->Info.RootNode, AbsolutePath);
|
||||
if (ret == false)
|
||||
{
|
||||
error("Failed to open %s, errno: %d", AbsolutePath.c_str(), fd);
|
||||
error("Failed to open %s, errno: %s", AbsolutePath.c_str(), ret.what());
|
||||
return;
|
||||
}
|
||||
Node fd = ret;
|
||||
|
||||
if (fd->IsSymbolicLink())
|
||||
{
|
||||
char buffer[512];
|
||||
fd->ReadLink(buffer, sizeof(buffer));
|
||||
fd = fs->GetByPath(buffer, fd->Parent);
|
||||
fs->ReadLink(fd, buffer, sizeof(buffer));
|
||||
fd = fs->Lookup(fd->Parent, buffer);
|
||||
}
|
||||
|
||||
debug("Opened %s", AbsolutePath.c_str());
|
||||
@ -575,7 +577,7 @@ namespace Execute
|
||||
envc++;
|
||||
|
||||
Elf_Ehdr ehdr{};
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
// ELFargv = new const char *[argc + 2];
|
||||
size_t argv_size = argc + 2 * sizeof(char *);
|
||||
|
@ -92,10 +92,10 @@ namespace Execute
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Elf_Sym ELFLookupSymbol(FileNode *fd, std::string Name)
|
||||
Elf_Sym ELFLookupSymbol(Node fd, std::string Name)
|
||||
{
|
||||
Elf_Ehdr ehdr{};
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
Elf_Shdr symTable{};
|
||||
Elf_Shdr stringTable{};
|
||||
@ -103,13 +103,13 @@ namespace Execute
|
||||
for (Elf64_Half i = 0; i < ehdr.e_shnum; i++)
|
||||
{
|
||||
Elf_Shdr shdr;
|
||||
fd->Read(&shdr, sizeof(Elf_Shdr), ehdr.e_shoff + (i * sizeof(Elf_Shdr)));
|
||||
fs->Read(fd, &shdr, sizeof(Elf_Shdr), ehdr.e_shoff + (i * sizeof(Elf_Shdr)));
|
||||
|
||||
switch (shdr.sh_type)
|
||||
{
|
||||
case SHT_SYMTAB:
|
||||
symTable = shdr;
|
||||
fd->Read(&stringTable, sizeof(Elf_Shdr), ehdr.e_shoff + (shdr.sh_link * sizeof(Elf_Shdr)));
|
||||
fs->Read(fd, &stringTable, sizeof(Elf_Shdr), ehdr.e_shoff + (shdr.sh_link * sizeof(Elf_Shdr)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -126,11 +126,11 @@ namespace Execute
|
||||
{
|
||||
// Elf_Sym *sym = (Elf_Sym *)((uintptr_t)Header + symTable->sh_offset + (i * sizeof(Elf_Sym)));
|
||||
Elf_Sym sym;
|
||||
fd->Read(&sym, sizeof(Elf_Sym), symTable.sh_offset + (i * sizeof(Elf_Sym)));
|
||||
fs->Read(fd, &sym, sizeof(Elf_Sym), symTable.sh_offset + (i * sizeof(Elf_Sym)));
|
||||
|
||||
// char *str = (char *)((uintptr_t)Header + stringTable->sh_offset + sym->st_name);
|
||||
char str[256];
|
||||
fd->Read(&str, sizeof(str), stringTable.sh_offset + sym.st_name);
|
||||
fs->Read(fd, &str, sizeof(str), stringTable.sh_offset + sym.st_name);
|
||||
|
||||
if (strcmp(str, Name.c_str()) == 0)
|
||||
return sym;
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
std::vector<Elf_Dyn> ELFGetDynamicTag(FileNode *fd, DynamicArrayTags Tag)
|
||||
std::vector<Elf_Dyn> ELFGetDynamicTag(Node &fd, DynamicArrayTags Tag)
|
||||
{
|
||||
std::vector<Elf_Dyn> ret;
|
||||
std::vector<Elf_Phdr> phdrs = ELFGetSymbolType(fd, PT_DYNAMIC);
|
||||
@ -37,7 +37,7 @@ namespace Execute
|
||||
Elf_Dyn dyn;
|
||||
for (size_t i = 0; i < phdr.p_filesz / sizeof(Elf_Dyn); i++)
|
||||
{
|
||||
fd->Read(&dyn, sizeof(Elf_Dyn), phdr.p_offset + (i * sizeof(Elf_Dyn)));
|
||||
fs->Read(fd, &dyn, sizeof(Elf_Dyn), phdr.p_offset + (i * sizeof(Elf_Dyn)));
|
||||
if (dyn.d_tag != Tag)
|
||||
continue;
|
||||
|
||||
|
@ -21,18 +21,18 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
std::vector<Elf_Shdr> ELFGetSections(FileNode *fd, const char *SectionName)
|
||||
std::vector<Elf_Shdr> ELFGetSections(Node fd, const char *SectionName)
|
||||
{
|
||||
std::vector<Elf_Shdr> ret;
|
||||
|
||||
Elf_Ehdr ehdr;
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
std::unique_ptr<Elf_Shdr[]> sections(new Elf_Shdr[ehdr.e_shnum]);
|
||||
fd->Read(sections.get(), sizeof(Elf_Shdr) * ehdr.e_shnum, ehdr.e_shoff);
|
||||
fs->Read(fd, sections.get(), sizeof(Elf_Shdr) * ehdr.e_shnum, ehdr.e_shoff);
|
||||
|
||||
std::string sectionNames(sections[ehdr.e_shstrndx].sh_size, '\0');
|
||||
fd->Read(sectionNames.data(), sections[ehdr.e_shstrndx].sh_size, sections[ehdr.e_shstrndx].sh_offset);
|
||||
fs->Read(fd, sectionNames.data(), sections[ehdr.e_shstrndx].sh_size, sections[ehdr.e_shstrndx].sh_offset);
|
||||
|
||||
for (Elf_Half i = 0; i < ehdr.e_shnum; ++i)
|
||||
{
|
||||
|
@ -21,15 +21,15 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
std::vector<Elf_Phdr> ELFGetSymbolType(FileNode *fd, SegmentTypes Tag)
|
||||
std::vector<Elf_Phdr> ELFGetSymbolType(Node &fd, SegmentTypes Tag)
|
||||
{
|
||||
std::vector<Elf_Phdr> ret;
|
||||
|
||||
Elf_Ehdr ehdr;
|
||||
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
|
||||
fs->Read(fd, &ehdr, sizeof(Elf_Ehdr), 0);
|
||||
|
||||
Elf_Phdr phdr;
|
||||
fd->Read(&phdr, sizeof(Elf_Phdr), ehdr.e_phoff);
|
||||
fs->Read(fd, &phdr, sizeof(Elf_Phdr), ehdr.e_phoff);
|
||||
|
||||
off_t off = ehdr.e_phoff;
|
||||
for (Elf_Half i = 0; i < ehdr.e_phnum; i++)
|
||||
@ -38,7 +38,7 @@ namespace Execute
|
||||
ret.push_back(phdr);
|
||||
|
||||
off += sizeof(Elf_Phdr);
|
||||
fd->Read(&phdr, sizeof(Elf_Phdr), off);
|
||||
fs->Read(fd, &phdr, sizeof(Elf_Phdr), off);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -35,7 +35,13 @@ namespace Execute
|
||||
Tasking::TaskCompatibility Compatibility,
|
||||
bool Critical)
|
||||
{
|
||||
FileNode *fd = fs->GetByPath(Path, nullptr);
|
||||
if (Parent == nullptr)
|
||||
{
|
||||
debug("no parent specified, using current process");
|
||||
Parent = thisProcess;
|
||||
}
|
||||
|
||||
Node fd = fs->Lookup(Parent->Info.RootNode, Path);
|
||||
if (fd == nullptr)
|
||||
return -ENOENT;
|
||||
|
||||
@ -44,8 +50,8 @@ namespace Execute
|
||||
if (fd->IsSymbolicLink())
|
||||
{
|
||||
char buffer[512];
|
||||
fd->ReadLink(buffer, sizeof(buffer));
|
||||
fd = fs->GetByPath(buffer, fd->Parent);
|
||||
fs->ReadLink(fd, buffer, sizeof(buffer));
|
||||
fd = fs->Lookup(fd->Parent, buffer);
|
||||
if (fd == nullptr)
|
||||
return -ENOENT;
|
||||
}
|
||||
@ -61,7 +67,7 @@ namespace Execute
|
||||
const char *BaseName;
|
||||
cwk_path_get_basename(Path, &BaseName, nullptr);
|
||||
Elf32_Ehdr ELFHeader;
|
||||
fd->Read(&ELFHeader, sizeof(Elf32_Ehdr), 0);
|
||||
fs->Read(fd, &ELFHeader, sizeof(Elf32_Ehdr), 0);
|
||||
|
||||
switch (ELFHeader.e_machine)
|
||||
{
|
||||
@ -108,7 +114,6 @@ namespace Execute
|
||||
PCB *Process;
|
||||
if (Fork)
|
||||
{
|
||||
assert(Parent != nullptr);
|
||||
CriticalSection cs;
|
||||
|
||||
Process = Parent;
|
||||
@ -124,17 +129,13 @@ namespace Execute
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Parent == nullptr)
|
||||
Parent = thisProcess;
|
||||
|
||||
Process = TaskManager->CreateProcess(Parent, BaseName,
|
||||
TaskExecutionMode::User,
|
||||
false, 0, 0);
|
||||
Process = TaskManager->CreateProcess(Parent, BaseName, User, false, 0, 0);
|
||||
Process->Info.Compatibility = Compatibility;
|
||||
Process->Info.Architecture = Arch;
|
||||
}
|
||||
|
||||
Process->SetWorkingDirectory(fs->GetByPath(Path, nullptr)->Parent);
|
||||
Node cwdNode = fs->Lookup(Parent->Info.RootNode, Path);
|
||||
Process->SetWorkingDirectory(fs->Convert(cwdNode->Parent));
|
||||
Process->SetExe(Path);
|
||||
|
||||
ELFObject *obj = new ELFObject(Path, Process, argv, envp);
|
||||
@ -148,9 +149,9 @@ namespace Execute
|
||||
vfs::FileDescriptorTable *pfdt = Parent->FileDescriptors;
|
||||
vfs::FileDescriptorTable *fdt = Process->FileDescriptors;
|
||||
|
||||
auto ForkStdio = [pfdt, fdt](FileNode *SearchNode)
|
||||
auto ForkStdio = [pfdt, fdt](Node SearchNode)
|
||||
{
|
||||
if (unlikely(SearchNode == nullptr))
|
||||
if (unlikely(SearchNode.get() == nullptr))
|
||||
return false;
|
||||
|
||||
for (const auto &ffd : pfdt->FileMap)
|
||||
@ -158,12 +159,11 @@ namespace Execute
|
||||
if (ffd.second.Flags & O_CLOEXEC)
|
||||
continue;
|
||||
|
||||
if (ffd.second.Node == SearchNode)
|
||||
{
|
||||
fdt->usr_open(ffd.second.Node->Path.c_str(),
|
||||
ffd.second.Flags, ffd.second.Mode);
|
||||
return true;
|
||||
}
|
||||
if (ffd.second.node.get() != SearchNode.get())
|
||||
continue;
|
||||
|
||||
fdt->usr_open(ffd.second.node->Path.c_str(), ffd.second.Flags, ffd.second.Mode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
Reference in New Issue
Block a user