mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Updated argv and envp in tasking
This commit is contained in:
parent
eab80c215c
commit
1317dc53fa
@ -62,6 +62,8 @@ void KernelMainThread()
|
|||||||
CPU::Interrupts(CPU::Enable);
|
CPU::Interrupts(CPU::Enable);
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
ret.Thread->SetDebugMode(true);
|
||||||
|
ret.Thread->SetKernelDebugMode(true);
|
||||||
ret.Thread->SetCritical(true);
|
ret.Thread->SetCritical(true);
|
||||||
KPrint("Waiting for \e22AAFF%s\eCCCCCC to start...", Config.InitPath);
|
KPrint("Waiting for \e22AAFF%s\eCCCCCC to start...", Config.InitPath);
|
||||||
CPU::Interrupts(CPU::Enable);
|
CPU::Interrupts(CPU::Enable);
|
||||||
|
@ -535,6 +535,23 @@ namespace Tasking
|
|||||||
UpdateUsage(&CurrentCPU->CurrentThread->Info, CurrentCPU->ID);
|
UpdateUsage(&CurrentCPU->CurrentThread->Info, CurrentCPU->ID);
|
||||||
OneShot(CurrentCPU->CurrentThread->Info.Priority);
|
OneShot(CurrentCPU->CurrentThread->Info.Priority);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
if (CurrentCPU->CurrentThread->Security.IsDebugEnabled && CurrentCPU->CurrentThread->Security.IsKernelDebugEnabled)
|
||||||
|
{
|
||||||
|
schedbg("================================================================");
|
||||||
|
schedbg("%s[%ld]:", CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID);
|
||||||
|
schedbg("R8=%#lx R9=%#lx R10=%#lx R11=%#lx",
|
||||||
|
Frame->r8, Frame->r9, Frame->r10, Frame->r11);
|
||||||
|
schedbg("R12=%#lx R13=%#lx R14=%#lx R15=%#lx",
|
||||||
|
Frame->r12, Frame->r13, Frame->r14, Frame->r15);
|
||||||
|
schedbg("RAX=%#lx RBX=%#lx RCX=%#lx RDX=%#lx",
|
||||||
|
Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx);
|
||||||
|
schedbg("RSI=%#lx RDI=%#lx RBP=%#lx RSP=%#lx",
|
||||||
|
Frame->rsi, Frame->rdi, Frame->rbp, Frame->rsp);
|
||||||
|
schedbg("RIP=%#lx RFL=%#lx INT=%#lx ERR=%#lx",
|
||||||
|
Frame->rip, Frame->rflags, Frame->InterruptNumber, Frame->ErrorCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
schedbg("================================================================");
|
schedbg("================================================================");
|
||||||
schedbg("Technical Informations on Thread %s[%ld]:", CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID);
|
schedbg("Technical Informations on Thread %s[%ld]:", CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID);
|
||||||
@ -749,7 +766,7 @@ namespace Tasking
|
|||||||
Thread->Registers.rflags.ID = 1;
|
Thread->Registers.rflags.ID = 1;
|
||||||
Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop());
|
Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop());
|
||||||
|
|
||||||
if (Compatibility == TaskCompatibility::Linux)
|
if (Compatibility == TaskCompatibility::Linux) // Not tested and probably not working
|
||||||
{
|
{
|
||||||
// https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf#figure.3.9
|
// https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf#figure.3.9
|
||||||
// What is a "eightbyte"? unsigned long? 1 eightbyte = 8 bytes? 2 eightbyte each = 16 bytes?
|
// What is a "eightbyte"? unsigned long? 1 eightbyte = 8 bytes? 2 eightbyte each = 16 bytes?
|
||||||
@ -827,61 +844,49 @@ namespace Tasking
|
|||||||
else // Native
|
else // Native
|
||||||
{
|
{
|
||||||
uint64_t ArgvSize = 0;
|
uint64_t ArgvSize = 0;
|
||||||
uint64_t ArgvStrSize = 0;
|
|
||||||
if (argv)
|
if (argv)
|
||||||
{
|
|
||||||
while (argv[ArgvSize] != nullptr)
|
while (argv[ArgvSize] != nullptr)
|
||||||
{
|
|
||||||
debug("> ArgvSize: %d, ArgvStrSize: %d", ArgvSize, ArgvStrSize);
|
|
||||||
ArgvSize++;
|
ArgvSize++;
|
||||||
ArgvStrSize += strlen(argv[ArgvSize]) + 1;
|
|
||||||
debug("< ArgvSize: %d, ArgvStrSize: %d", ArgvSize, ArgvStrSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t EnvpSize = 0;
|
uint64_t EnvpSize = 0;
|
||||||
uint64_t EnvpStrSize = 0;
|
|
||||||
if (envp)
|
if (envp)
|
||||||
{
|
|
||||||
while (envp[EnvpSize] != nullptr)
|
while (envp[EnvpSize] != nullptr)
|
||||||
{
|
|
||||||
debug("> EnvpSize: %d, EnvpStrSize: %d", EnvpSize, EnvpStrSize);
|
|
||||||
EnvpSize++;
|
EnvpSize++;
|
||||||
EnvpStrSize += strlen(envp[EnvpSize]) + 1;
|
|
||||||
debug("< EnvpSize: %d, EnvpStrSize: %d", EnvpSize, EnvpStrSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *_argv = 0;
|
Memory::Virtual ArgMap = Memory::Virtual(Parent->PageTable);
|
||||||
uint8_t *_envp = 0;
|
|
||||||
|
char **_argv = (char **)KernelAllocator.RequestPages(TO_PAGES(ArgvSize * sizeof(char *)));
|
||||||
|
char **_envp = (char **)KernelAllocator.RequestPages(TO_PAGES(EnvpSize * sizeof(char *)));
|
||||||
|
|
||||||
|
for (uint64_t i = 0; i < TO_PAGES(ArgvSize * sizeof(char *)); i++)
|
||||||
|
ArgMap.Map((void *)_argv[i], (void *)_argv[i], Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
|
|
||||||
|
for (uint64_t i = 0; i < TO_PAGES(EnvpSize * sizeof(char *)); i++)
|
||||||
|
ArgMap.Map((void *)_envp[i], (void *)_envp[i], Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
|
|
||||||
for (uint64_t i = 0; i < ArgvSize; i++)
|
for (uint64_t i = 0; i < ArgvSize; i++)
|
||||||
{
|
{
|
||||||
void *Tmp = KernelAllocator.RequestPages(TO_PAGES(strlen(argv[i]) + 1));
|
_argv[i] = (char *)KernelAllocator.RequestPages(TO_PAGES(strlen(argv[i]) + 1));
|
||||||
debug("argv[%d] ptr %#lx", i, (uint64_t)Tmp);
|
strcpy(_argv[i], argv[i]);
|
||||||
Memory::Virtual().Map(Tmp, Tmp, Memory::PTFlag::RW | Memory::PTFlag::US);
|
for (uint64_t j = 0; j < TO_PAGES(strlen(argv[i]) + 1); j++)
|
||||||
_argv = (uint8_t *)Tmp;
|
ArgMap.Map((void *)_argv[i], (void *)_argv[i], Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
strcpy((char *)_argv, argv[i]);
|
|
||||||
argv[i] = (char *)_argv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("argv done");
|
|
||||||
|
|
||||||
for (uint64_t i = 0; i < EnvpSize; i++)
|
for (uint64_t i = 0; i < EnvpSize; i++)
|
||||||
{
|
{
|
||||||
void *Tmp = KernelAllocator.RequestPages(TO_PAGES(strlen(envp[i]) + 1));
|
_envp[i] = (char *)KernelAllocator.RequestPages(TO_PAGES(strlen(envp[i]) + 1));
|
||||||
debug("envp[%d] ptr %#lx", i, (uint64_t)Tmp);
|
strcpy(_envp[i], envp[i]);
|
||||||
Memory::Virtual().Map(Tmp, Tmp, Memory::PTFlag::RW | Memory::PTFlag::US);
|
for (uint64_t j = 0; j < TO_PAGES(strlen(envp[i]) + 1); j++)
|
||||||
_envp = (uint8_t *)Tmp;
|
ArgMap.Map((void *)_envp[i], (void *)_envp[i], Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
strcpy((char *)_envp, envp[i]);
|
|
||||||
envp[i] = (char *)_envp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("envp done");
|
_argv[ArgvSize] = nullptr;
|
||||||
|
_envp[EnvpSize] = nullptr;
|
||||||
|
|
||||||
Thread->Registers.rdi = ArgvSize;
|
Thread->Registers.rdi = (uint64_t)ArgvSize;
|
||||||
Thread->Registers.rsi = (uint64_t)_argv;
|
Thread->Registers.rsi = (uint64_t)_argv;
|
||||||
Thread->Registers.rdx = (uint64_t)_envp;
|
Thread->Registers.rdx = (uint64_t)EnvpSize;
|
||||||
|
Thread->Registers.rcx = (uint64_t)_envp;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < ArgvSize; i++)
|
for (uint64_t i = 0; i < ArgvSize; i++)
|
||||||
debug("argv[%d]: %s", i, _argv[i]);
|
debug("argv[%d]: %s", i, _argv[i]);
|
||||||
|
@ -61,6 +61,8 @@ namespace Tasking
|
|||||||
TaskTrustLevel TrustLevel;
|
TaskTrustLevel TrustLevel;
|
||||||
Token UniqueToken;
|
Token UniqueToken;
|
||||||
bool IsCritical;
|
bool IsCritical;
|
||||||
|
bool IsDebugEnabled;
|
||||||
|
bool IsKernelDebugEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TaskInfo
|
struct TaskInfo
|
||||||
@ -125,11 +127,25 @@ namespace Tasking
|
|||||||
|
|
||||||
int GetExitCode() { return ExitCode; }
|
int GetExitCode() { return ExitCode; }
|
||||||
|
|
||||||
void SetCritical(bool critical)
|
void SetCritical(bool Critical)
|
||||||
{
|
{
|
||||||
CriticalSection cs;
|
CriticalSection cs;
|
||||||
trace("Setting criticality of thread %s to %s", Name, critical ? "true" : "false");
|
trace("Setting criticality of thread %s to %s", Name, Critical ? "true" : "false");
|
||||||
Security.IsCritical = critical;
|
Security.IsCritical = Critical;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDebugMode(bool Enable)
|
||||||
|
{
|
||||||
|
CriticalSection cs;
|
||||||
|
trace("Setting debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||||
|
Security.IsDebugEnabled = Enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetKernelDebugMode(bool Enable)
|
||||||
|
{
|
||||||
|
CriticalSection cs;
|
||||||
|
trace("Setting kernel debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||||
|
Security.IsKernelDebugEnabled = Enable;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user