diff --git a/Core/CPU.cpp b/Core/CPU.cpp index 6037014..d0923d0 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -102,23 +102,21 @@ namespace CPU { case Check: { + uintptr_t Flags; #if defined(__amd64__) - uint64_t rflags; asmv("pushfq"); asmv("popq %0" - : "=r"(rflags)); - return rflags & (1 << 9); + : "=r"(Flags)); + return Flags & (1 << 9); #elif defined(__i386__) - uint32_t rflags; asmv("pushfl"); asmv("popl %0" - : "=r"(rflags)); - return rflags & (1 << 9); + : "=r"(Flags)); + return Flags & (1 << 9); #elif defined(__aarch64__) - uint64_t daif; asmv("mrs %0, daif" - : "=r"(daif)); - return !(daif & (1 << 2)); + : "=r"(Flags)); + return !(Flags & (1 << 2)); #endif } case Enable: @@ -254,21 +252,20 @@ namespace CPU #endif } - uint64_t Counter() + uintptr_t Counter() { // TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs) + uintptr_t Counter; #if defined(__amd64__) - uint64_t counter; asmv("rdtsc" - : "=A"(counter)); - return counter; + : "=A"(Counter)); #elif defined(__i386__) - return 0; + asmv("rdtsc" + : "=A"(Counter)); #elif defined(__aarch64__) - uint64_t counter; asmv("mrs %0, cntvct_el0" - : "=r"(counter)); - return counter; + : "=r"(Counter)); #endif + return Counter; } } diff --git a/Core/Crash/CrashDetails.cpp b/Core/Crash/CrashDetails.cpp index 338cb12..e3517b8 100644 --- a/Core/Crash/CrashDetails.cpp +++ b/Core/Crash/CrashDetails.cpp @@ -121,7 +121,7 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame) CrashHandler::EHPrint(PageFaultDescriptions[Frame->ErrorCode & 0b111]); #ifdef DEBUG - uint64_t CheckPageFaultAddress = 0; + uintptr_t CheckPageFaultAddress = 0; CheckPageFaultAddress = CPU::x64::readcr2().PFLA; if (CheckPageFaultAddress == 0) CheckPageFaultAddress = Frame->rip; @@ -155,11 +155,11 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame) if (Present) { - uint64_t CheckPageFaultLinearAddress = (uint64_t)CheckPageFaultAddress; + uintptr_t CheckPageFaultLinearAddress = (uintptr_t)CheckPageFaultAddress; CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000; debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress); - Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uint64_t)CheckPageFaultLinearAddress); + Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uintptr_t)CheckPageFaultLinearAddress); debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d", CheckPageFaultLinearAddress, Index.PMLIndex, @@ -168,9 +168,9 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame) Index.PTEIndex); Memory::PageMapLevel4 PML4 = ((Memory::PageTable4 *)CPU::x64::readcr3().raw)->Entries[Index.PMLIndex]; - Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12); - Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); - Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); + Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12); + Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); + Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx", Index.PMLIndex, 0, 0, 0, diff --git a/Core/Crash/CrashHandler.cpp b/Core/Crash/CrashHandler.cpp index 1b13f73..057442f 100644 --- a/Core/Crash/CrashHandler.cpp +++ b/Core/Crash/CrashHandler.cpp @@ -294,8 +294,8 @@ namespace CrashHandler else if (strncmp(Input, "ifr", 3) == 0) { char *arg = TrimWhiteSpace(Input + 3); - uint64_t CountI = atoi(arg); - uint64_t TotalCount = sizeof(EHIntFrames) / sizeof(EHIntFrames[0]); + int CountI = atoi(arg); + int TotalCount = sizeof(EHIntFrames) / sizeof(EHIntFrames[0]); debug("Printing %ld interrupt frames.", CountI); @@ -306,7 +306,7 @@ namespace CrashHandler } else { - for (uint64_t i = 0; i < CountI; i++) + for (int i = 0; i < CountI; i++) { if (EHIntFrames[i]) { @@ -315,12 +315,12 @@ namespace CrashHandler EHPrint("\n\e2565CC%p", EHIntFrames[i]); EHPrint("\e7925CC-"); #if defined(__amd64__) - if ((uint64_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end) + if ((uintptr_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end) #elif defined(__i386__) - if ((uint64_t)EHIntFrames[i] >= 0xC0000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end) + if ((uintptr_t)EHIntFrames[i] >= 0xC0000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end) #elif defined(__aarch64__) #endif - EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uint64_t)EHIntFrames[i])); + EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uintptr_t)EHIntFrames[i])); else EHPrint("\eFF4CA9Outside Kernel"); for (int i = 0; i < 20000; i++) @@ -333,7 +333,7 @@ namespace CrashHandler else if (strncmp(Input, "tlb", 3) == 0) { char *arg = TrimWhiteSpace(Input + 3); - uint64_t Address = NULL; + uintptr_t Address = NULL; Address = strtol(arg, NULL, 16); debug("Converted %s to %#lx", arg, Address); Memory::PageTable4 *BasePageTable = (Memory::PageTable4 *)Address; @@ -355,7 +355,7 @@ namespace CrashHandler Display->SetBuffer(SBIdx); if (PML4.Present) { - Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12); + Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12); if (PDPTE) { for (int PDPTEIndex = 0; PDPTEIndex < 512; PDPTEIndex++) @@ -373,7 +373,7 @@ namespace CrashHandler Display->SetBuffer(SBIdx); if ((PDPTE->Entries[PDPTEIndex].Present)) { - Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[PDPTEIndex].GetAddress() << 12); + Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[PDPTEIndex].GetAddress() << 12); if (PDE) { for (int PDEIndex = 0; PDEIndex < 512; PDEIndex++) @@ -391,7 +391,7 @@ namespace CrashHandler Display->SetBuffer(SBIdx); if ((PDE->Entries[PDEIndex].Present)) { - Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[PDEIndex].GetAddress() << 12); + Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[PDEIndex].GetAddress() << 12); if (PTE) { for (int PTEIndex = 0; PTEIndex < 512; PTEIndex++) @@ -428,7 +428,7 @@ namespace CrashHandler Bitmap bm = KernelAllocator.GetPageBitmap(); EHPrint("\n\eFAFAFA[0%%] %08ld: ", 0); - for (uint64_t i = 0; i < bm.Size; i++) + for (size_t i = 0; i < bm.Size; i++) { if (bm.Get(i)) EHPrint("\eFF00001"); @@ -436,7 +436,7 @@ namespace CrashHandler EHPrint("\e00FF000"); if (i % 128 == 127) { - uint64_t Percentage = (i * 100) / bm.Size; + short Percentage = (i * 100) / bm.Size; EHPrint("\n\eFAFAFA[%03ld%%] %08ld: ", Percentage, i); Display->SetBuffer(SBIdx); } @@ -642,7 +642,7 @@ namespace CrashHandler CPU::x64::CR8 cr8 = CPU::x64::readcr8(); CPU::x64::EFER efer; efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER); - uint64_t ds; + uintptr_t ds; asmv("mov %%ds, %0" : "=r"(ds)); @@ -703,7 +703,7 @@ namespace CrashHandler crashdata.cr4 = CPU::x64::readcr4(); crashdata.cr8 = CPU::x64::readcr8(); crashdata.efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER); - uint64_t ds; + uintptr_t ds; asmv("mov %%ds, %0" : "=r"(ds)); diff --git a/Core/Crash/SFrame.cpp b/Core/Crash/SFrame.cpp index 9317eeb..da9d8c9 100644 --- a/Core/Crash/SFrame.cpp +++ b/Core/Crash/SFrame.cpp @@ -20,7 +20,7 @@ namespace CrashHandler struct StackFrame { struct StackFrame *rbp; - uint64_t rip; + uintptr_t rip; }; SafeFunction void TraceFrames(CHArchTrapFrame *Frame, int Count, SymbolResolver::Symbols *SymHandle, bool Kernel) @@ -75,14 +75,14 @@ namespace CrashHandler #if defined(__amd64__) EHPrint("\e2565CC%p", (void *)Frame->rip); EHPrint("\e7925CC-"); - if ((Frame->rip >= 0xFFFFFFFF80000000 && Frame->rip <= (uint64_t)&_kernel_end) || !Kernel) + if ((Frame->rip >= 0xFFFFFFFF80000000 && Frame->rip <= (uintptr_t)&_kernel_end) || !Kernel) EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->rip)); else EHPrint("Outside Kernel"); #elif defined(__i386__) EHPrint("\e2565CC%p", (void *)Frame->eip); EHPrint("\e7925CC-"); - if ((Frame->eip >= 0xC0000000 && Frame->eip <= (uint64_t)&_kernel_end) || !Kernel) + if ((Frame->eip >= 0xC0000000 && Frame->eip <= (uintptr_t)&_kernel_end) || !Kernel) EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->eip)); else EHPrint("Outside Kernel"); @@ -96,9 +96,9 @@ namespace CrashHandler EHPrint("\n\e2565CC%p", (void *)frames->rip); EHPrint("\e7925CC-"); #if defined(__amd64__) - if ((frames->rip >= 0xFFFFFFFF80000000 && frames->rip <= (uint64_t)&_kernel_end) || !Kernel) + if ((frames->rip >= 0xFFFFFFFF80000000 && frames->rip <= (uintptr_t)&_kernel_end) || !Kernel) #elif defined(__i386__) - if ((frames->rip >= 0xC0000000 && frames->rip <= (uint64_t)&_kernel_end) || !Kernel) + if ((frames->rip >= 0xC0000000 && frames->rip <= (uintptr_t)&_kernel_end) || !Kernel) #elif defined(__aarch64__) #endif EHPrint("\e25CCC9%s", SymHandle->GetSymbolFromAddress(frames->rip)); diff --git a/Core/Crash/Screens/Details.cpp b/Core/Crash/Screens/Details.cpp index 20b4a74..277207e 100644 --- a/Core/Crash/Screens/Details.cpp +++ b/Core/Crash/Screens/Details.cpp @@ -28,6 +28,7 @@ namespace CrashHandler data.Thread->Name, data.Thread->ID); EHPrint("\e7981FCTechnical Informations on CPU %lld:\n", data.ID); + uintptr_t ds; #if defined(__amd64__) CPUData *cpu = (CPUData *)data.CPUData; @@ -46,11 +47,9 @@ namespace CrashHandler EHPrint("Checksum: 0x%X\n", cpu->Checksum); } - uint64_t ds; asmv("mov %%ds, %0" : "=r"(ds)); #elif defined(__i386__) - uint32_t ds; asmv("mov %%ds, %0" : "=r"(ds)); #elif defined(__aarch64__) diff --git a/Core/Crash/Screens/StackFrame.cpp b/Core/Crash/Screens/StackFrame.cpp index ac38961..c95528e 100644 --- a/Core/Crash/Screens/StackFrame.cpp +++ b/Core/Crash/Screens/StackFrame.cpp @@ -32,7 +32,7 @@ namespace CrashHandler TraceFrames(data.Frame, 40, sh, false); } EHPrint("\n\eFAFAFATracing interrupt frames..."); - for (uint64_t i = 0; i < 8; i++) + for (short i = 0; i < 8; i++) { if (EHIntFrames[i]) { @@ -41,12 +41,12 @@ namespace CrashHandler EHPrint("\n\e2565CC%p", EHIntFrames[i]); EHPrint("\e7925CC-"); #if defined(__amd64__) - if ((uint64_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end) + if ((uintptr_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end) #elif defined(__i386__) - if ((uint64_t)EHIntFrames[i] >= 0xC0000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end) + if ((uintptr_t)EHIntFrames[i] >= 0xC0000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end) #elif defined(__aarch64__) #endif - EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uint64_t)EHIntFrames[i])); + EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uintptr_t)EHIntFrames[i])); else EHPrint("\eFF4CA9Outside Kernel"); } @@ -58,7 +58,7 @@ namespace CrashHandler if (!sh) EHPrint("\n\eFFA500Warning: No symbol table available."); int SameItr = 0; - uint64_t LastRIP = 0; + uintptr_t LastRIP = 0; for (int i = 0; i < 128; i++) { if (data.Thread->RIPHistory[i] == 0) @@ -75,7 +75,7 @@ namespace CrashHandler if (!sh) EHPrint("\n\e2565CC%p", data.Thread->RIPHistory[i]); else - EHPrint("\n\e2565CC%p\e7925CC-\e25CCC9%s", data.Thread->RIPHistory[i], sh->GetSymbolFromAddress((uint64_t)data.Thread->RIPHistory[i])); + EHPrint("\n\e2565CC%p\e7925CC-\e25CCC9%s", data.Thread->RIPHistory[i], sh->GetSymbolFromAddress(data.Thread->RIPHistory[i])); } EHPrint("\n\e7925CCNote: \e2565CCSame RIPs are not shown more than 3 times.\n"); } diff --git a/Core/Crash/UserHandler.cpp b/Core/Crash/UserHandler.cpp index 6054cb9..e1e21b2 100644 --- a/Core/Crash/UserHandler.cpp +++ b/Core/Crash/UserHandler.cpp @@ -43,12 +43,11 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER); error("Technical Informations on CPU %lld:", CurCPU->ID); + uintptr_t ds; #if defined(__amd64__) - uint64_t ds; asmv("mov %%ds, %0" : "=r"(ds)); #elif defined(__i386__) - uint32_t ds; asmv("mov %%ds, %0" : "=r"(ds)); #elif defined(__aarch64__) @@ -177,7 +176,7 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) } case CPU::x64::PageFault: { - uint64_t CheckPageFaultAddress = 0; + uintptr_t CheckPageFaultAddress = 0; CPU::x64::PageFaultErrorCode params = {.raw = (uint32_t)Frame->ErrorCode}; #if defined(__amd64__) CheckPageFaultAddress = CPU::x64::readcr2().PFLA; @@ -234,11 +233,11 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) if (Present) { - uint64_t CheckPageFaultLinearAddress = (uint64_t)CheckPageFaultAddress; + uintptr_t CheckPageFaultLinearAddress = (uintptr_t)CheckPageFaultAddress; CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000; debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress); - Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uint64_t)CheckPageFaultLinearAddress); + Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uintptr_t)CheckPageFaultLinearAddress); debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d", CheckPageFaultLinearAddress, Index.PMLIndex, @@ -247,9 +246,9 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) Index.PTEIndex); Memory::PageMapLevel4 PML4 = CurCPU->CurrentProcess->PageTable->Entries[Index.PMLIndex]; - Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12); - Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); - Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); + Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12); + Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); + Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx", Index.PMLIndex, 0, 0, 0, diff --git a/Core/Crash/chfcts.hpp b/Core/Crash/chfcts.hpp index 20efb55..02d014d 100644 --- a/Core/Crash/chfcts.hpp +++ b/Core/Crash/chfcts.hpp @@ -20,7 +20,7 @@ struct CRData CPU::x64::CR4 cr4; CPU::x64::CR8 cr8; CPU::x64::EFER efer; - uint64_t dr0, dr1, dr2, dr3, dr6; + uintptr_t dr0, dr1, dr2, dr3, dr6; CPU::x64::DR7 dr7; long ID; @@ -42,7 +42,7 @@ struct CRData CPU::x32::CR4 cr4; CPU::x32::CR8 cr8; CPU::x32::EFER efer; - uint64_t dr0, dr1, dr2, dr3, dr6; + uintptr_t dr0, dr1, dr2, dr3, dr6; CPU::x32::DR7 dr7; long ID; diff --git a/Core/Driver/Driver.cpp b/Core/Driver/Driver.cpp index 8d1efb7..41971d5 100644 --- a/Core/Driver/Driver.cpp +++ b/Core/Driver/Driver.cpp @@ -77,8 +77,8 @@ namespace Driver foreach (auto var in Drivers) if (var->DriverUID == DUID) { - FexExtended *DrvExtHdr = (FexExtended *)((uint64_t)var->Address + EXTENDED_SECTION_ADDRESS); - return ((int (*)(void *))((uint64_t)DrvExtHdr->Driver.Callback + (uint64_t)var->Address))(KCB); + FexExtended *DrvExtHdr = (FexExtended *)((uintptr_t)var->Address + EXTENDED_SECTION_ADDRESS); + return ((int (*)(void *))((uintptr_t)DrvExtHdr->Driver.Callback + (uintptr_t)var->Address))(KCB); } return -1; } @@ -91,14 +91,14 @@ namespace Driver ((KernelAPI *)KAPIAddress)->Info.DriverUID = DriverUIDs++; debug("Calling driver entry point ( %#lx %ld )", (unsigned long)fex, ((KernelAPI *)KAPIAddress)->Info.DriverUID); - int ret = ((int (*)(KernelAPI *))((uint64_t)((Fex *)fex)->EntryPoint + (uint64_t)fex))(((KernelAPI *)KAPIAddress)); + int ret = ((int (*)(KernelAPI *))((uintptr_t)((Fex *)fex)->EntryPoint + (uintptr_t)fex))(((KernelAPI *)KAPIAddress)); if (DriverReturnCode::OK != ret) return DriverCode::DRIVER_RETURNED_ERROR; return DriverCode::OK; } - DriverCode Driver::LoadDriver(uint64_t DriverAddress, uint64_t Size) + DriverCode Driver::LoadDriver(uintptr_t DriverAddress, uintptr_t Size) { Fex *DrvHdr = (Fex *)DriverAddress; if (DrvHdr->Magic[0] != 'F' || DrvHdr->Magic[1] != 'E' || DrvHdr->Magic[2] != 'X' || DrvHdr->Magic[3] != '\0') @@ -114,7 +114,7 @@ namespace Driver if (ElfDrvHdr->Type == FexFormatType::FexFormatType_Driver) { - FexExtended *ElfDrvExtHdr = (FexExtended *)((uint64_t)ElfDrvHdr + EXTENDED_SECTION_ADDRESS); + FexExtended *ElfDrvExtHdr = (FexExtended *)((uintptr_t)ElfDrvHdr + EXTENDED_SECTION_ADDRESS); debug("Name: \"%s\"; Type: %d; Callback: %#lx", ElfDrvExtHdr->Driver.Name, ElfDrvExtHdr->Driver.Type, ElfDrvExtHdr->Driver.Callback); if (ElfDrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI) @@ -139,7 +139,7 @@ namespace Driver if (DrvHdr->Type == FexFormatType::FexFormatType_Driver) { - FexExtended *DrvExtHdr = (FexExtended *)((uint64_t)DrvHdr + EXTENDED_SECTION_ADDRESS); + FexExtended *DrvExtHdr = (FexExtended *)((uintptr_t)DrvHdr + EXTENDED_SECTION_ADDRESS); debug("Name: \"%s\"; Type: %d; Callback: %#lx", DrvExtHdr->Driver.Name, DrvExtHdr->Driver.Type, DrvExtHdr->Driver.Callback); if (DrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI) @@ -171,7 +171,7 @@ namespace Driver cwk_path_get_extension(driver->Name, &extension, nullptr); if (!strcmp(extension, ".fex") || !strcmp(extension, ".elf")) { - uint64_t ret = this->LoadDriver(driver->Address, driver->Length); + uintptr_t ret = this->LoadDriver(driver->Address, driver->Length); char RetString[128]; if (ret == DriverCode::OK) strncpy(RetString, "\e058C19OK", 64); diff --git a/Core/Driver/DriverLoading/BindInput.cpp b/Core/Driver/DriverLoading/BindInput.cpp index fc9905a..fc43eb2 100644 --- a/Core/Driver/DriverLoading/BindInput.cpp +++ b/Core/Driver/DriverLoading/BindInput.cpp @@ -14,13 +14,13 @@ namespace Driver { - DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf) + DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf) { Memory::Tracker *Tracker = new Memory::Tracker; Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size)); memcpy(fex, (void *)DriverAddress, Size); - FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS); - debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size); + FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS); + debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size); #ifdef DEBUG uint8_t *result = md5File((uint8_t *)fex, Size); debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -47,7 +47,7 @@ namespace Driver KCallback->RawPtr = nullptr; break; KCallback->Reason = CallbackReason::ConfigurationReason; - int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback); + int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback); if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED) { delete Tracker; diff --git a/Core/Driver/DriverLoading/BindInterrupt.cpp b/Core/Driver/DriverLoading/BindInterrupt.cpp index 0316cde..a498c91 100644 --- a/Core/Driver/DriverLoading/BindInterrupt.cpp +++ b/Core/Driver/DriverLoading/BindInterrupt.cpp @@ -14,13 +14,13 @@ namespace Driver { - DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf) + DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf) { Memory::Tracker *Tracker = new Memory::Tracker; Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size)); memcpy(fex, (void *)DriverAddress, Size); - FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS); - debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size); + FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS); + debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size); #ifdef DEBUG uint8_t *result = md5File((uint8_t *)fex, Size); debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -79,7 +79,7 @@ namespace Driver KCallback->RawPtr = nullptr; KCallback->Reason = CallbackReason::ConfigurationReason; - int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback); + int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback); if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED) { error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name); @@ -111,7 +111,7 @@ namespace Driver DriverInterruptHook *InterruptHook = nullptr; if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] != 0) InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] + 32, // x86 - (void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex), + (void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex), KCallback); for (unsigned long i = 0; i < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0]); i++) @@ -119,14 +119,14 @@ namespace Driver if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] == 0) break; // InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] + 32, // x86 - // (void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex), + // (void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex), // KCallback); fixme("TODO: MULTIPLE BIND INTERRUPT VECTORS %d", ((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i]); } KCallback->RawPtr = nullptr; KCallback->Reason = CallbackReason::ConfigurationReason; - int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback); + int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback); if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED) { error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name); diff --git a/Core/Driver/DriverLoading/BindPCI.cpp b/Core/Driver/DriverLoading/BindPCI.cpp index 8672bbf..5deba70 100644 --- a/Core/Driver/DriverLoading/BindPCI.cpp +++ b/Core/Driver/DriverLoading/BindPCI.cpp @@ -14,7 +14,7 @@ namespace Driver { - DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf) + DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf) { for (unsigned long Vidx = 0; Vidx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[0]); Vidx++) for (unsigned long Didx = 0; Didx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[0]); Didx++) @@ -34,8 +34,8 @@ namespace Driver Memory::Tracker *Tracker = new Memory::Tracker(); Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size)); memcpy(fex, (void *)DriverAddress, Size); - FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS); - debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size); + FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS); + debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size); #ifdef DEBUG uint8_t *result = md5File((uint8_t *)fex, Size); debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -60,21 +60,21 @@ namespace Driver ((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)); if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) != 0) - if (!Memory::Virtual().Check((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)))) + if (!Memory::Virtual().Check((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)))) { debug("IO base (BAR1 & ~3) is not mapped"); - Memory::Virtual().Map((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), (void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), Memory::PTFlag::RW); + Memory::Virtual().Map((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), (void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), Memory::PTFlag::RW); } if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) == 0) - if (!Memory::Virtual().Check((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)))) + if (!Memory::Virtual().Check((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)))) { debug("Memory base (BAR0 & ~15) is not mapped"); - Memory::Virtual().Map((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), (void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), Memory::PTFlag::RW); + Memory::Virtual().Map((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), (void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), Memory::PTFlag::RW); - uint64_t original = ((PCI::PCIHeader0 *)PCIDevice)->BAR0; + uintptr_t original = ((PCI::PCIHeader0 *)PCIDevice)->BAR0; ((PCI::PCIHeader0 *)PCIDevice)->BAR0 = 0xFFFFFFFF; - uint64_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 0xFFFFFFF0; + uintptr_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 0xFFFFFFF0; ((PCI::PCIHeader0 *)PCIDevice)->BAR0 = original; debug("Size: %#lx (%ld pages)", size, TO_PAGES(size)); fixme("TODO: [BUG] Mapping is broken!!!!!!"); @@ -97,12 +97,12 @@ namespace Driver case FexDriverType::FexDriverType_Network: { DriverInterruptHook *InterruptHook = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)devices[0])->InterruptLine) + 32, // x86 - (void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex), + (void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex), KCallback); KCallback->RawPtr = PCIDevice; KCallback->Reason = CallbackReason::ConfigurationReason; - int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback); + int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback); if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED) { error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name); @@ -134,7 +134,7 @@ namespace Driver { KCallback->RawPtr = PCIDevice; KCallback->Reason = CallbackReason::ConfigurationReason; - int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback); + int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback); if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED) { error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name); diff --git a/Core/Driver/DriverLoading/BindProcess.cpp b/Core/Driver/DriverLoading/BindProcess.cpp index 9d72d84..f4b61c3 100644 --- a/Core/Driver/DriverLoading/BindProcess.cpp +++ b/Core/Driver/DriverLoading/BindProcess.cpp @@ -14,7 +14,7 @@ namespace Driver { - DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf) + DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf) { fixme("Process driver: %s", ((FexExtended *)DrvExtHdr)->Driver.Name); return DriverCode::NOT_IMPLEMENTED; diff --git a/Core/Interrupts/IntManager.cpp b/Core/Interrupts/IntManager.cpp index abb2b58..e31e371 100644 --- a/Core/Interrupts/IntManager.cpp +++ b/Core/Interrupts/IntManager.cpp @@ -49,8 +49,8 @@ namespace Interrupts CPU::x64::wrmsr(CPU::x64::MSR_SHADOW_GS_BASE, (uint64_t)CoreData); CoreData->ID = Core; CoreData->IsActive = true; - CoreData->SystemCallStack = (uint8_t *)((uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE); - CoreData->Stack = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; + CoreData->SystemCallStack = (uint8_t *)((uintptr_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE); + CoreData->Stack = (uintptr_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; if (CoreData->Checksum != CPU_DATA_CHECKSUM) { KPrint("CPU %d checksum mismatch! %x != %x", Core, CoreData->Checksum, CPU_DATA_CHECKSUM); diff --git a/Core/Memory/HeapAllocators/Xalloc.cpp b/Core/Memory/HeapAllocators/Xalloc.cpp index 5fa169f..29eb0a2 100644 --- a/Core/Memory/HeapAllocators/Xalloc.cpp +++ b/Core/Memory/HeapAllocators/Xalloc.cpp @@ -6,10 +6,10 @@ namespace Xalloc { struct SpinLockData { - uint64_t LockData = 0x0; + uintptr_t LockData = 0x0; const char *CurrentHolder = "(null)"; const char *AttemptingToGet = "(null)"; - uint64_t Count = 0; + size_t Count = 0; }; void DeadLock(SpinLockData Lock) diff --git a/Core/Memory/Memory.cpp b/Core/Memory/Memory.cpp index 4265c09..fd1dc24 100644 --- a/Core/Memory/Memory.cpp +++ b/Core/Memory/Memory.cpp @@ -45,9 +45,9 @@ __no_instrument_function void MapFromZero(PageTable4 *PT, BootInfo *Info) void *NullAddress = KernelAllocator.RequestPage(); memset(NullAddress, 0, PAGE_SIZE); // TODO: If the CPU instruction pointer hits this page, there should be function to handle it. (memcpy assembly code?) va.Map((void *)0, (void *)NullAddress, PTFlag::RW | PTFlag::US); - uint64_t VirtualOffsetNormalVMA = NORMAL_VMA_OFFSET; - uint64_t MemSize = Info->Memory.Size; - for (uint64_t t = 0; t < MemSize; t += PAGE_SIZE) + uintptr_t VirtualOffsetNormalVMA = NORMAL_VMA_OFFSET; + size_t MemSize = Info->Memory.Size; + for (size_t t = 0; t < MemSize; t += PAGE_SIZE) { va.Map((void *)t, (void *)t, PTFlag::RW /* | PTFlag::US */); va.Map((void *)VirtualOffsetNormalVMA, (void *)t, PTFlag::RW /* | PTFlag::US */); @@ -70,8 +70,8 @@ __no_instrument_function void MapFramebuffer(PageTable4 *PT, BootInfo *Info) if (!Info->Framebuffer[itrfb].BaseAddress) break; - for (uint64_t fb_base = (uint64_t)Info->Framebuffer[itrfb].BaseAddress; - fb_base < ((uint64_t)Info->Framebuffer[itrfb].BaseAddress + ((Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height) + PAGE_SIZE)); + for (uintptr_t fb_base = (uintptr_t)Info->Framebuffer[itrfb].BaseAddress; + fb_base < ((uintptr_t)Info->Framebuffer[itrfb].BaseAddress + ((Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height) + PAGE_SIZE)); fb_base += PAGE_SIZE) va.Map((void *)fb_base, (void *)fb_base, PTFlag::RW | PTFlag::US | PTFlag::G); itrfb++; @@ -84,14 +84,14 @@ __no_instrument_function void MapKernel(PageTable4 *PT, BootInfo *Info) Kernel Start & Text Start ------ Text End ------ Kernel Rodata End ------ Kernel Data End & Kernel End */ Virtual va = Virtual(PT); - uint64_t KernelStart = (uint64_t)&_kernel_start; - uint64_t KernelTextEnd = (uint64_t)&_kernel_text_end; - uint64_t KernelDataEnd = (uint64_t)&_kernel_data_end; - uint64_t KernelRoDataEnd = (uint64_t)&_kernel_rodata_end; - uint64_t KernelEnd = (uint64_t)&_kernel_end; + uintptr_t KernelStart = (uintptr_t)&_kernel_start; + uintptr_t KernelTextEnd = (uintptr_t)&_kernel_text_end; + uintptr_t KernelDataEnd = (uintptr_t)&_kernel_data_end; + uintptr_t KernelRoDataEnd = (uintptr_t)&_kernel_rodata_end; + uintptr_t KernelEnd = (uintptr_t)&_kernel_end; - uint64_t BaseKernelMapAddress = (uint64_t)Info->Kernel.PhysicalBase; - uint64_t k; + uintptr_t BaseKernelMapAddress = (uintptr_t)Info->Kernel.PhysicalBase; + uintptr_t k; for (k = KernelStart; k < KernelTextEnd; k += PAGE_SIZE) { @@ -130,9 +130,9 @@ __no_instrument_function void InitializeMemoryManagement(BootInfo *Info) #ifdef DEBUG for (uint64_t i = 0; i < Info->Memory.Entries; i++) { - uint64_t Base = reinterpret_cast(Info->Memory.Entry[i].BaseAddress); - uint64_t Length = Info->Memory.Entry[i].Length; - uint64_t End = Base + Length; + uintptr_t Base = reinterpret_cast(Info->Memory.Entry[i].BaseAddress); + uintptr_t Length = Info->Memory.Entry[i].Length; + uintptr_t End = Base + Length; const char *Type = "Unknown"; switch (Info->Memory.Entry[i].Type) @@ -233,7 +233,7 @@ __no_instrument_function void InitializeMemoryManagement(BootInfo *Info) } } -void *HeapMalloc(uint64_t Size) +void *HeapMalloc(size_t Size) { switch (AllocatorType) { @@ -256,7 +256,7 @@ void *HeapMalloc(uint64_t Size) } } -void *HeapCalloc(uint64_t n, uint64_t Size) +void *HeapCalloc(size_t n, size_t Size) { switch (AllocatorType) { @@ -279,7 +279,7 @@ void *HeapCalloc(uint64_t n, uint64_t Size) } } -void *HeapRealloc(void *Address, uint64_t Size) +void *HeapRealloc(void *Address, size_t Size) { switch (AllocatorType) { diff --git a/Core/Memory/PageMapIndexer.cpp b/Core/Memory/PageMapIndexer.cpp index 3b87ad7..2f07232 100644 --- a/Core/Memory/PageMapIndexer.cpp +++ b/Core/Memory/PageMapIndexer.cpp @@ -2,10 +2,10 @@ namespace Memory { - Virtual::PageMapIndexer::PageMapIndexer(uint64_t VirtualAddress) + Virtual::PageMapIndexer::PageMapIndexer(uintptr_t VirtualAddress) { #if defined(__amd64__) - uint64_t Address = VirtualAddress; + uintptr_t Address = VirtualAddress; Address >>= 12; this->PTEIndex = Address & 0x1FF; Address >>= 9; @@ -15,7 +15,7 @@ namespace Memory Address >>= 9; this->PMLIndex = Address & 0x1FF; #elif defined(__i386__) - uint64_t Address = VirtualAddress; + uintptr_t Address = VirtualAddress; Address >>= 12; this->PTEIndex = Address & 0x3FF; Address >>= 10; diff --git a/Core/Memory/PhysicalMemoryManager.cpp b/Core/Memory/PhysicalMemoryManager.cpp index bc5ea49..acfbc16 100644 --- a/Core/Memory/PhysicalMemoryManager.cpp +++ b/Core/Memory/PhysicalMemoryManager.cpp @@ -34,10 +34,10 @@ namespace Memory return false; } - bool Physical::SwapPages(void *Address, uint64_t PageCount) + bool Physical::SwapPages(void *Address, size_t PageCount) { - for (uint64_t i = 0; i < PageCount; i++) - if (!this->SwapPage((void *)((uint64_t)Address + (i * PAGE_SIZE)))) + for (size_t i = 0; i < PageCount; i++) + if (!this->SwapPage((void *)((uintptr_t)Address + (i * PAGE_SIZE)))) return false; return false; } @@ -48,10 +48,10 @@ namespace Memory return false; } - bool Physical::UnswapPages(void *Address, uint64_t PageCount) + bool Physical::UnswapPages(void *Address, size_t PageCount) { - for (uint64_t i = 0; i < PageCount; i++) - if (!this->UnswapPage((void *)((uint64_t)Address + (i * PAGE_SIZE)))) + for (size_t i = 0; i < PageCount; i++) + if (!this->UnswapPage((void *)((uintptr_t)Address + (i * PAGE_SIZE)))) return false; return false; } @@ -78,7 +78,7 @@ namespace Memory return nullptr; } - void *Physical::RequestPages(uint64_t Count) + void *Physical::RequestPages(size_t Count) { SmartLock(this->MemoryLock); for (; PageBitmapIndex < PageBitmap.Size * 8; PageBitmapIndex++) @@ -91,7 +91,7 @@ namespace Memory if (PageBitmap[Index] == true) continue; - for (uint64_t i = 0; i < Count; i++) + for (size_t i = 0; i < Count; i++) if (PageBitmap[Index + i] == true) goto NextPage; @@ -123,7 +123,7 @@ namespace Memory warn("Null pointer passed to FreePage."); return; } - uint64_t Index = (uint64_t)Address / PAGE_SIZE; + size_t Index = (size_t)Address / PAGE_SIZE; if (unlikely(PageBitmap[Index] == false)) return; @@ -136,7 +136,7 @@ namespace Memory } } - void Physical::FreePages(void *Address, uint64_t Count) + void Physical::FreePages(void *Address, size_t Count) { if (unlikely(Address == nullptr || Count == 0)) { @@ -144,8 +144,8 @@ namespace Memory return; } - for (uint64_t t = 0; t < Count; t++) - this->FreePage((void *)((uint64_t)Address + (t * PAGE_SIZE))); + for (size_t t = 0; t < Count; t++) + this->FreePage((void *)((uintptr_t)Address + (t * PAGE_SIZE))); } void Physical::LockPage(void *Address) @@ -153,7 +153,7 @@ namespace Memory if (unlikely(Address == nullptr)) warn("Trying to lock null address."); - uint64_t Index = (uint64_t)Address / PAGE_SIZE; + uintptr_t Index = (uintptr_t)Address / PAGE_SIZE; if (unlikely(PageBitmap[Index] == true)) return; if (PageBitmap.Set(Index, true)) @@ -163,13 +163,13 @@ namespace Memory } } - void Physical::LockPages(void *Address, uint64_t PageCount) + void Physical::LockPages(void *Address, size_t PageCount) { if (unlikely(Address == nullptr || PageCount == 0)) warn("Trying to lock %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : ""); - for (uint64_t i = 0; i < PageCount; i++) - this->LockPage((void *)((uint64_t)Address + (i * PAGE_SIZE))); + for (size_t i = 0; i < PageCount; i++) + this->LockPage((void *)((uintptr_t)Address + (i * PAGE_SIZE))); } void Physical::ReservePage(void *Address) @@ -177,7 +177,7 @@ namespace Memory if (unlikely(Address == nullptr)) warn("Trying to reserve null address."); - uint64_t Index = (uint64_t)Address / PAGE_SIZE; + uintptr_t Index = (uintptr_t)Address / PAGE_SIZE; if (unlikely(PageBitmap[Index] == true)) return; @@ -188,13 +188,13 @@ namespace Memory } } - void Physical::ReservePages(void *Address, uint64_t PageCount) + void Physical::ReservePages(void *Address, size_t PageCount) { if (unlikely(Address == nullptr || PageCount == 0)) warn("Trying to reserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : ""); - for (uint64_t t = 0; t < PageCount; t++) - this->ReservePage((void *)((uint64_t)Address + (t * PAGE_SIZE))); + for (size_t t = 0; t < PageCount; t++) + this->ReservePage((void *)((uintptr_t)Address + (t * PAGE_SIZE))); } void Physical::UnreservePage(void *Address) @@ -202,7 +202,7 @@ namespace Memory if (unlikely(Address == nullptr)) warn("Trying to unreserve null address."); - uint64_t Index = (uint64_t)Address / PAGE_SIZE; + uintptr_t Index = (uintptr_t)Address / PAGE_SIZE; if (unlikely(PageBitmap[Index] == false)) return; @@ -215,13 +215,13 @@ namespace Memory } } - void Physical::UnreservePages(void *Address, uint64_t PageCount) + void Physical::UnreservePages(void *Address, size_t PageCount) { if (unlikely(Address == nullptr || PageCount == 0)) warn("Trying to unreserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : ""); - for (uint64_t t = 0; t < PageCount; t++) - this->UnreservePage((void *)((uint64_t)Address + (t * PAGE_SIZE))); + for (size_t t = 0; t < PageCount; t++) + this->UnreservePage((void *)((uintptr_t)Address + (t * PAGE_SIZE))); } void Physical::Init(BootInfo *Info) @@ -253,14 +253,14 @@ namespace Memory CPU::Stop(); } - uint64_t BitmapSize = (MemorySize / PAGE_SIZE) / 8 + 1; + size_t BitmapSize = (MemorySize / PAGE_SIZE) / 8 + 1; trace("Initializing Bitmap at %llp-%llp (%lld Bytes)", LargestFreeMemorySegment, - (void *)((uint64_t)LargestFreeMemorySegment + BitmapSize), + (void *)((uintptr_t)LargestFreeMemorySegment + BitmapSize), BitmapSize); PageBitmap.Size = BitmapSize; PageBitmap.Buffer = (uint8_t *)LargestFreeMemorySegment; - for (uint64_t i = 0; i < BitmapSize; i++) + for (size_t i = 0; i < BitmapSize; i++) *(uint8_t *)(PageBitmap.Buffer + i) = 0; trace("Reserving pages..."); diff --git a/Core/Memory/StackGuard.cpp b/Core/Memory/StackGuard.cpp index 8319575..507aada 100644 --- a/Core/Memory/StackGuard.cpp +++ b/Core/Memory/StackGuard.cpp @@ -13,18 +13,18 @@ namespace Memory void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE)); debug("AllocatedStack: %p", AllocatedStack); memset(AllocatedStack, 0, USER_STACK_SIZE); - for (uint64_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++) + for (size_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++) { Virtual(Table).Map((void *)(USER_STACK_BASE + (i * PAGE_SIZE)), - (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)), + (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)), PTFlag::RW | PTFlag::US); debug("Mapped %p to %p", (void *)(USER_STACK_BASE + (i * PAGE_SIZE)), - (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE))); + (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE))); } this->StackBottom = (void *)USER_STACK_BASE; this->StackTop = (void *)(USER_STACK_BASE + USER_STACK_SIZE); this->StackPhyiscalBottom = AllocatedStack; - this->StackPhyiscalTop = (void *)((uint64_t)AllocatedStack + USER_STACK_SIZE); + this->StackPhyiscalTop = (void *)((uintptr_t)AllocatedStack + USER_STACK_SIZE); this->Size = USER_STACK_SIZE; } else @@ -33,7 +33,7 @@ namespace Memory this->StackPhyiscalBottom = this->StackBottom; debug("StackBottom: %p", this->StackBottom); memset(this->StackBottom, 0, STACK_SIZE); - this->StackTop = (void *)((uint64_t)this->StackBottom + STACK_SIZE); + this->StackTop = (void *)((uintptr_t)this->StackBottom + STACK_SIZE); this->StackPhyiscalTop = this->StackTop; this->Size = STACK_SIZE; } @@ -47,12 +47,12 @@ namespace Memory // debug("Freed stack at %p", this->StackBottom); } - bool StackGuard::Expand(uint64_t FaultAddress) + bool StackGuard::Expand(uintptr_t FaultAddress) { if (this->UserMode) { - if (FaultAddress < (uint64_t)this->StackBottom - USER_STACK_SIZE || - FaultAddress > (uint64_t)this->StackTop) + if (FaultAddress < (uintptr_t)this->StackBottom - USER_STACK_SIZE || + FaultAddress > (uintptr_t)this->StackTop) { return false; // It's not about the stack. } @@ -61,12 +61,12 @@ namespace Memory void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE)); debug("AllocatedStack: %p", AllocatedStack); memset(AllocatedStack, 0, USER_STACK_SIZE); - for (uint64_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++) + for (uintptr_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++) { - Virtual(this->Table).Map((void *)((uint64_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)), PTFlag::RW | PTFlag::US); - debug("Mapped %p to %p", (void *)((uint64_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE))); + Virtual(this->Table).Map((void *)((uintptr_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)), PTFlag::RW | PTFlag::US); + debug("Mapped %p to %p", (void *)((uintptr_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE))); } - this->StackBottom = (void *)((uint64_t)this->StackBottom - USER_STACK_SIZE); + this->StackBottom = (void *)((uintptr_t)this->StackBottom - USER_STACK_SIZE); this->Size += USER_STACK_SIZE; info("Stack expanded to %p", this->StackBottom); return true; diff --git a/Core/Memory/Tracker.cpp b/Core/Memory/Tracker.cpp index 6ab6740..ed18eff 100644 --- a/Core/Memory/Tracker.cpp +++ b/Core/Memory/Tracker.cpp @@ -11,22 +11,22 @@ namespace Memory return FROM_PAGES(Size); } - void *Tracker::RequestPages(uint64_t Count) + void *Tracker::RequestPages(size_t Count) { void *Address = KernelAllocator.RequestPages(Count); - for (uint64_t i = 0; i < Count; i++) - Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + for (size_t i = 0; i < Count; i++) + Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); AllocatedPagesList.push_back({Address, Count}); return Address; } - void Tracker::FreePages(void *Address, uint64_t Count) + void Tracker::FreePages(void *Address, size_t Count) { KernelAllocator.FreePages(Address, Count); - for (uint64_t i = 0; i < Count; i++) - Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW); + for (size_t i = 0; i < Count; i++) + Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW); - for (uint64_t i = 0; i < AllocatedPagesList.size(); i++) + for (uintptr_t i = 0; i < AllocatedPagesList.size(); i++) if (AllocatedPagesList[i].Address == Address) { AllocatedPagesList.remove(i); @@ -48,8 +48,8 @@ namespace Memory foreach (auto var in AllocatedPagesList) { KernelAllocator.FreePages(var.Address, var.PageCount); - for (uint64_t i = 0; i < var.PageCount; i++) - Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)var.Address + (i * PAGE_SIZE)), (void *)((uint64_t)var.Address + (i * PAGE_SIZE)), Memory::PTFlag::RW); + for (size_t i = 0; i < var.PageCount; i++) + Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)var.Address + (i * PAGE_SIZE)), (void *)((uintptr_t)var.Address + (i * PAGE_SIZE)), Memory::PTFlag::RW); } debug("Tracker destroyed."); } diff --git a/Core/Memory/VirtualMemoryManager.cpp b/Core/Memory/VirtualMemoryManager.cpp index 379dd2d..3db7f78 100644 --- a/Core/Memory/VirtualMemoryManager.cpp +++ b/Core/Memory/VirtualMemoryManager.cpp @@ -8,10 +8,10 @@ namespace Memory bool Virtual::Check(void *VirtualAddress, PTFlag Flag) { // 0x1000 aligned - uint64_t Address = (uint64_t)VirtualAddress; + uintptr_t Address = (uintptr_t)VirtualAddress; Address &= 0xFFFFFFFFFFFFF000; - PageMapIndexer Index = PageMapIndexer((uint64_t)Address); + PageMapIndexer Index = PageMapIndexer(Address); PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex]; PageDirectoryPointerTableEntryPtr *PDPTE = nullptr; @@ -20,15 +20,15 @@ namespace Memory if ((PML4.raw & Flag) > 0) { - PDPTE = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12); + PDPTE = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12); if (PDPTE) if ((PDPTE->Entries[Index.PDPTEIndex].Present)) { - PDE = (PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); + PDE = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12); if (PDE) if ((PDE->Entries[Index.PDEIndex].Present)) { - PTE = (PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); + PTE = (PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12); if (PTE) if ((PTE->Entries[Index.PTEIndex].Present)) { @@ -49,7 +49,7 @@ namespace Memory return; } - PageMapIndexer Index = PageMapIndexer((uint64_t)VirtualAddress); + PageMapIndexer Index = PageMapIndexer((uintptr_t)VirtualAddress); // Clear any flags that are not 1 << 0 (Present) - 1 << 5 (Accessed) because rest are for page table entries only uint64_t DirectoryFlags = Flags & 0x3F; @@ -60,10 +60,10 @@ namespace Memory PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)KernelAllocator.RequestPage(); memset(PDPTEPtr, 0, PAGE_SIZE); PML4.Present = true; - PML4.SetAddress((uint64_t)PDPTEPtr >> 12); + PML4.SetAddress((uintptr_t)PDPTEPtr >> 12); } else - PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12); + PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12); PML4.raw |= DirectoryFlags; this->Table->Entries[Index.PMLIndex] = PML4; @@ -74,10 +74,10 @@ namespace Memory PDEPtr = (PageDirectoryEntryPtr *)KernelAllocator.RequestPage(); memset(PDEPtr, 0, PAGE_SIZE); PDPTE.Present = true; - PDPTE.SetAddress((uint64_t)PDEPtr >> 12); + PDPTE.SetAddress((uintptr_t)PDEPtr >> 12); } else - PDEPtr = (PageDirectoryEntryPtr *)((uint64_t)PDPTE.GetAddress() << 12); + PDEPtr = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE.GetAddress() << 12); PDPTE.raw |= DirectoryFlags; PDPTEPtr->Entries[Index.PDPTEIndex] = PDPTE; @@ -88,17 +88,17 @@ namespace Memory PTEPtr = (PageTableEntryPtr *)KernelAllocator.RequestPage(); memset(PTEPtr, 0, PAGE_SIZE); PDE.Present = true; - PDE.SetAddress((uint64_t)PTEPtr >> 12); + PDE.SetAddress((uintptr_t)PTEPtr >> 12); } else - PTEPtr = (PageTableEntryPtr *)((uint64_t)PDE.GetAddress() << 12); + PTEPtr = (PageTableEntryPtr *)((uintptr_t)PDE.GetAddress() << 12); PDE.raw |= DirectoryFlags; PDEPtr->Entries[Index.PDEIndex] = PDE; PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex]; PTE.Present = true; PTE.raw |= Flags; - PTE.SetAddress((uint64_t)PhysicalAddress >> 12); + PTE.SetAddress((uintptr_t)PhysicalAddress >> 12); PTEPtr->Entries[Index.PTEIndex] = PTE; #if defined(__amd64__) @@ -133,10 +133,10 @@ namespace Memory #endif } - void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags) + void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, size_t PageCount, uint64_t Flags) { - for (uint64_t i = 0; i < PageCount; i++) - this->Map((void *)((uint64_t)VirtualAddress + (i * PAGE_SIZE)), (void *)((uint64_t)PhysicalAddress + (i * PAGE_SIZE)), Flags); + for (size_t i = 0; i < PageCount; i++) + this->Map((void *)((uintptr_t)VirtualAddress + (i * PAGE_SIZE)), (void *)((uintptr_t)PhysicalAddress + (i * PAGE_SIZE)), Flags); } void Virtual::Unmap(void *VirtualAddress) @@ -148,28 +148,28 @@ namespace Memory return; } - PageMapIndexer Index = PageMapIndexer((uint64_t)VirtualAddress); + PageMapIndexer Index = PageMapIndexer((uintptr_t)VirtualAddress); PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex]; if (!PML4.Present) { error("Page not present"); return; } - PageDirectoryPointerTableEntryPtr *PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.Address << 12); + PageDirectoryPointerTableEntryPtr *PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.Address << 12); PageDirectoryPointerTableEntry PDPTE = PDPTEPtr->Entries[Index.PDPTEIndex]; if (!PDPTE.Present) { error("Page not present"); return; } - PageDirectoryEntryPtr *PDEPtr = (PageDirectoryEntryPtr *)((uint64_t)PDPTE.Address << 12); + PageDirectoryEntryPtr *PDEPtr = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE.Address << 12); PageDirectoryEntry PDE = PDEPtr->Entries[Index.PDEIndex]; if (!PDE.Present) { error("Page not present"); return; } - PageTableEntryPtr *PTEPtr = (PageTableEntryPtr *)((uint64_t)PDE.Address << 12); + PageTableEntryPtr *PTEPtr = (PageTableEntryPtr *)((uintptr_t)PDE.Address << 12); PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex]; if (!PTE.Present) { @@ -195,10 +195,10 @@ namespace Memory #endif } - void Virtual::Unmap(void *VirtualAddress, uint64_t PageCount) + void Virtual::Unmap(void *VirtualAddress, size_t PageCount) { - for (uint64_t i = 0; i < PageCount; i++) - this->Unmap((void *)((uint64_t)VirtualAddress + (i * PAGE_SIZE))); + for (size_t i = 0; i < PageCount; i++) + this->Unmap((void *)((uintptr_t)VirtualAddress + (i * PAGE_SIZE))); } void Virtual::Remap(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags) diff --git a/Core/PeripheralComponentInterconnect.cpp b/Core/PeripheralComponentInterconnect.cpp index 8fb445e..b0bf025 100644 --- a/Core/PeripheralComponentInterconnect.cpp +++ b/Core/PeripheralComponentInterconnect.cpp @@ -772,10 +772,10 @@ namespace PCI } #endif - void PCI::EnumerateFunction(uint64_t DeviceAddress, uint64_t Function) + void PCI::EnumerateFunction(uintptr_t DeviceAddress, uintptr_t Function) { - uint64_t Offset = Function << 12; - uint64_t FunctionAddress = DeviceAddress + Offset; + uintptr_t Offset = Function << 12; + uintptr_t FunctionAddress = DeviceAddress + Offset; Memory::Virtual().Map((void *)FunctionAddress, (void *)FunctionAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)FunctionAddress; if (PCIDeviceHdr->DeviceID == 0) @@ -788,24 +788,24 @@ namespace PCI #endif } - void PCI::EnumerateDevice(uint64_t BusAddress, uint64_t Device) + void PCI::EnumerateDevice(uintptr_t BusAddress, uintptr_t Device) { - uint64_t Offset = Device << 15; - uint64_t DeviceAddress = BusAddress + Offset; + uintptr_t Offset = Device << 15; + uintptr_t DeviceAddress = BusAddress + Offset; Memory::Virtual().Map((void *)DeviceAddress, (void *)DeviceAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)DeviceAddress; if (PCIDeviceHdr->DeviceID == 0) return; if (PCIDeviceHdr->DeviceID == 0xFFFF) return; - for (uint64_t Function = 0; Function < 8; Function++) + for (uintptr_t Function = 0; Function < 8; Function++) EnumerateFunction(DeviceAddress, Function); } - void PCI::EnumerateBus(uint64_t BaseAddress, uint64_t Bus) + void PCI::EnumerateBus(uintptr_t BaseAddress, uintptr_t Bus) { - uint64_t Offset = Bus << 20; - uint64_t BusAddress = BaseAddress + Offset; + uintptr_t Offset = Bus << 20; + uintptr_t BusAddress = BaseAddress + Offset; Memory::Virtual().Map((void *)BusAddress, (void *)BusAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)BusAddress; if (Bus != 0) // TODO: VirtualBox workaround (UNTESTED ON REAL HARDWARE!) @@ -820,7 +820,7 @@ namespace PCI PCIDeviceHdr->CacheLineSize, PCIDeviceHdr->Class, PCIDeviceHdr->Command, PCIDeviceHdr->HeaderType, PCIDeviceHdr->LatencyTimer, PCIDeviceHdr->ProgIF, PCIDeviceHdr->RevisionID, PCIDeviceHdr->Status, PCIDeviceHdr->Subclass); - for (uint64_t Device = 0; Device < 32; Device++) + for (uintptr_t Device = 0; Device < 32; Device++) EnumerateDevice(BusAddress, Device); } @@ -848,11 +848,11 @@ namespace PCI int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig); for (int t = 0; t < Entries; t++) { - DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uint64_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t)); + DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uintptr_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t)); Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW); trace("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress, NewDeviceConfig->StartBus, NewDeviceConfig->EndBus); - for (uint64_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++) + for (uintptr_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++) EnumerateBus(NewDeviceConfig->BaseAddress, Bus); } #elif defined(__i386__) diff --git a/Core/Symbols.cpp b/Core/Symbols.cpp index 4f581df..5a9a845 100644 --- a/Core/Symbols.cpp +++ b/Core/Symbols.cpp @@ -52,7 +52,7 @@ typedef struct namespace SymbolResolver { - Symbols::Symbols(uint64_t ImageAddress) + Symbols::Symbols(uintptr_t ImageAddress) { debug("Solving symbols for address: %#llx", ImageAddress); Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress; @@ -68,7 +68,7 @@ namespace SymbolResolver Elf64_Sym *ElfSymbols = nullptr; char *strtab = nullptr; - for (uint64_t i = 0; i < Header->e_shnum; i++) + for (uint16_t i = 0; i < Header->e_shnum; i++) switch (ElfSections[i].sh_type) { case SHT_SYMTAB: @@ -83,7 +83,7 @@ namespace SymbolResolver } else { - strtab = (char *)(uint64_t)ImageAddress + ElfSections[i].sh_offset; + strtab = (char *)(ImageAddress + ElfSections[i].sh_offset); debug("String table found, %d entries", ElfSections[i].sh_size); } break; @@ -91,8 +91,8 @@ namespace SymbolResolver if (ElfSymbols != nullptr && strtab != nullptr) { - size_t Index, MinimumIndex; - for (size_t i = 0; i < this->TotalEntries - 1; i++) + uintptr_t Index, MinimumIndex; + for (uintptr_t i = 0; i < this->TotalEntries - 1; i++) { MinimumIndex = i; for (Index = i + 1; Index < this->TotalEntries; Index++) @@ -114,7 +114,7 @@ namespace SymbolResolver #endif trace("Symbol table loaded, %d entries (%ldKB)", this->TotalEntries, TO_KB(this->TotalEntries * sizeof(SymbolTable))); - for (size_t i = 0, g = this->TotalEntries; i < g; i++) + for (uintptr_t i = 0, g = this->TotalEntries; i < g; i++) { this->SymTable[i].Address = ElfSymbols[i].st_value; this->SymTable[i].FunctionName = &strtab[ElfSymbols[i].st_name]; @@ -133,10 +133,10 @@ namespace SymbolResolver Symbols::~Symbols() {} - const __no_instrument_function char *Symbols::GetSymbolFromAddress(uint64_t Address) + const __no_instrument_function char *Symbols::GetSymbolFromAddress(uintptr_t Address) { Symbols::SymbolTable Result{0, (char *)""}; - for (size_t i = 0; i < this->TotalEntries; i++) + for (uintptr_t i = 0; i < this->TotalEntries; i++) if (this->SymTable[i].Address <= Address && this->SymTable[i].Address > Result.Address) Result = this->SymTable[i]; return Result.FunctionName; diff --git a/Core/SystemManagementBIOS.cpp b/Core/SystemManagementBIOS.cpp index a6715eb..2c747d5 100644 --- a/Core/SystemManagementBIOS.cpp +++ b/Core/SystemManagementBIOS.cpp @@ -38,16 +38,16 @@ namespace SMBIOS SMBIOSEntryPoint *Header = (SMBIOSEntryPoint *)bInfo->SMBIOSPtr; debug("Getting SMBIOS header for type %d", Type); - struct SMBIOSHeader *hdr = (SMBIOSHeader *)(uint64_t)Header->TableAddress; + struct SMBIOSHeader *hdr = (SMBIOSHeader *)(uintptr_t)Header->TableAddress; for (int i = 0; i <= 11; i++) { - if (hdr < (void *)(uint64_t)(Header->TableAddress + Header->TableLength)) + if (hdr < (void *)(uintptr_t)(Header->TableAddress + Header->TableLength)) if (hdr->Type == Type) { debug("Found SMBIOS header for type %d at %#lx", Type, hdr); return hdr; } - hdr = (struct SMBIOSHeader *)((uint64_t)hdr + SMBIOSTableLength(hdr)); + hdr = (struct SMBIOSHeader *)((uintptr_t)hdr + SMBIOSTableLength(hdr)); } return nullptr; } diff --git a/Core/Timer.cpp b/Core/Timer.cpp index 3aee1ff..ff95c01 100644 --- a/Core/Timer.cpp +++ b/Core/Timer.cpp @@ -12,10 +12,10 @@ namespace Time { - void time::Sleep(uint64_t Milliseconds) + void time::Sleep(uintptr_t Milliseconds) { #if defined(__amd64__) || defined(__i386__) - uint64_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000) / clk; + uintptr_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000) / clk; while (mminq(&((HPET *)hpet)->MainCounterValue) < Target) CPU::Pause(); #elif defined(__aarch64__) diff --git a/Core/UniversalAsynchronousReceiverTransmitter.cpp b/Core/UniversalAsynchronousReceiverTransmitter.cpp index 88cdb2b..81ae47e 100644 --- a/Core/UniversalAsynchronousReceiverTransmitter.cpp +++ b/Core/UniversalAsynchronousReceiverTransmitter.cpp @@ -138,7 +138,7 @@ namespace UniversalAsynchronousReceiverTransmitter SafeFunction __no_instrument_function Events::~Events() { - for (uint64_t i = 0; i < RegisteredEvents.size(); i++) + for (uintptr_t i = 0; i < RegisteredEvents.size(); i++) if (RegisteredEvents[i] == this) { RegisteredEvents.remove(i); diff --git a/Core/Video/Display.cpp b/Core/Video/Display.cpp index 51946f4..20c0fbb 100644 --- a/Core/Video/Display.cpp +++ b/Core/Video/Display.cpp @@ -3,9 +3,9 @@ #include #include -extern uint64_t _binary_Files_ter_powerline_v12n_psf_start; -extern uint64_t _binary_Files_ter_powerline_v12n_psf_end; -extern uint64_t _binary_Files_ter_powerline_v12n_psf_size; +extern uintptr_t _binary_Files_ter_powerline_v12n_psf_start; +extern uintptr_t _binary_Files_ter_powerline_v12n_psf_end; +extern uintptr_t _binary_Files_ter_powerline_v12n_psf_size; NewLock(PrintLock); @@ -67,7 +67,7 @@ namespace Video for (unsigned long Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + fonthdrHeight; Y++) for (unsigned long X = this->Buffers[Index]->CursorX - fonthdrWidth; X < this->Buffers[Index]->CursorX; X++) - *(uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + + *(uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = 0; break; } @@ -145,7 +145,7 @@ namespace Video { for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + fonthdrWidth; X++) if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0) - *(uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + + *(uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = this->Buffers[Index]->Color; FontPtr += BytesPerLine; diff --git a/Core/Video/Font.cpp b/Core/Video/Font.cpp index dd0f1f3..2097fae 100644 --- a/Core/Video/Font.cpp +++ b/Core/Video/Font.cpp @@ -4,7 +4,7 @@ namespace Video { - Font::Font(uint64_t *Start, uint64_t *End, FontType Type) + Font::Font(uintptr_t *Start, uintptr_t *End, FontType Type) { trace("Initializing font with start %#llx and end %#llx Type: %d", Start, End, Type); this->Info.StartAddress = Start; @@ -14,9 +14,9 @@ namespace Video { this->Info.PSF2Font = new PSF2_FONT; - uint64_t FontDataLength = End - Start; + uintptr_t FontDataLength = End - Start; PSF2_HEADER *font2 = (PSF2_HEADER *)KernelAllocator.RequestPages(FontDataLength / PAGE_SIZE + 1); - for (uint64_t i = 0; i < FontDataLength / PAGE_SIZE + 1; i++) + for (uintptr_t i = 0; i < FontDataLength / PAGE_SIZE + 1; i++) Memory::Virtual().Map((void *)(font2 + (i * PAGE_SIZE)), (void *)(font2 + (i * PAGE_SIZE)), Memory::PTFlag::RW); memcpy((void *)font2, Start, FontDataLength); @@ -26,7 +26,7 @@ namespace Video error("Font2 magic mismatch."); this->Info.PSF2Font->Header = font2; - this->Info.PSF2Font->GlyphBuffer = reinterpret_cast(reinterpret_cast(Start) + sizeof(PSF2_HEADER)); + this->Info.PSF2Font->GlyphBuffer = reinterpret_cast(reinterpret_cast(Start) + sizeof(PSF2_HEADER)); } else if (Type == FontType::PCScreenFont1) { @@ -37,7 +37,7 @@ namespace Video uint32_t glyphBufferSize = font1->charsize * 256; if (font1->mode == 1) // 512 glyph mode glyphBufferSize = font1->charsize * 512; - void *glyphBuffer = reinterpret_cast(reinterpret_cast(Start) + sizeof(PSF1_HEADER)); + void *glyphBuffer = reinterpret_cast(reinterpret_cast(Start) + sizeof(PSF1_HEADER)); this->Info.PSF1Font->Header = font1; this->Info.PSF1Font->GlyphBuffer = glyphBuffer; UNUSED(glyphBufferSize); // TODO: Use this in the future? diff --git a/Execute/Parse.cpp b/Execute/Parse.cpp index 9a74d9a..eea3186 100644 --- a/Execute/Parse.cpp +++ b/Execute/Parse.cpp @@ -71,7 +71,7 @@ namespace Execute /* Originally from https://wiki.osdev.org/ELF_Tutorial */ - static inline Elf64_Shdr *GetElfSheader(Elf64_Ehdr *Header) { return (Elf64_Shdr *)((uint64_t)Header + Header->e_shoff); } + static inline Elf64_Shdr *GetElfSheader(Elf64_Ehdr *Header) { return (Elf64_Shdr *)((uintptr_t)Header + Header->e_shoff); } static inline Elf64_Shdr *GetElfSection(Elf64_Ehdr *Header, uint64_t Index) { return &GetElfSheader(Header)[Index]; } static inline char *GetElfStringTable(Elf64_Ehdr *Header) @@ -81,7 +81,7 @@ namespace Execute return (char *)Header + GetElfSection(Header, Header->e_shstrndx)->sh_offset; } - static inline char *elf_lookup_string(Elf64_Ehdr *Header, uint64_t Offset) + static inline char *elf_lookup_string(Elf64_Ehdr *Header, uintptr_t Offset) { char *StringTable = GetElfStringTable(Header); if (StringTable == nullptr) @@ -111,17 +111,17 @@ namespace Execute if (SymbolTable == nullptr || StringTable == nullptr) return nullptr; - for (uint64_t i = 0; i < (SymbolTable->sh_size / sizeof(Elf64_Sym)); i++) + for (size_t i = 0; i < (SymbolTable->sh_size / sizeof(Elf64_Sym)); i++) { - Symbol = (Elf64_Sym *)((uint64_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym))); - String = (char *)((uint64_t)Header + StringTable->sh_offset + Symbol->st_name); + Symbol = (Elf64_Sym *)((uintptr_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym))); + String = (char *)((uintptr_t)Header + StringTable->sh_offset + Symbol->st_name); if (strcmp(String, Name) == 0) return (void *)Symbol->st_value; } return nullptr; } - static uint64_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint32_t Index) + static uintptr_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint32_t Index) { if (Table == SHN_UNDEF || Index == SHN_UNDEF) return 0; @@ -154,14 +154,14 @@ namespace Execute } } else - return (uint64_t)Target; + return (uintptr_t)Target; } else if (Symbol->st_shndx == SHN_ABS) return Symbol->st_value; else { Elf64_Shdr *Target = GetElfSection(Header, Symbol->st_shndx); - return (uint64_t)Header + Symbol->st_value + Target->sh_offset; + return (uintptr_t)Header + Symbol->st_value + Target->sh_offset; } } @@ -181,8 +181,8 @@ namespace Execute memset(Buffer, 0, Section->sh_size); Memory::Virtual pva = Memory::Virtual(/* TODO TODO TODO TODO TODO TODO */); - for (uint64_t i = 0; i < TO_PAGES(Section->sh_size); i++) - pva.Map((void *)((uint64_t)Buffer + (i * PAGE_SIZE)), (void *)((uint64_t)Buffer + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + for (size_t i = 0; i < TO_PAGES(Section->sh_size); i++) + pva.Map((void *)((uintptr_t)Buffer + (i * PAGE_SIZE)), (void *)((uintptr_t)Buffer + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); Section->sh_offset = (uint64_t)Buffer - (uint64_t)Header; debug("Section %ld", Section->sh_size); @@ -190,17 +190,17 @@ namespace Execute } } - for (uint64_t i = 0; i < Header->e_shnum; i++) + for (size_t i = 0; i < Header->e_shnum; i++) { Elf64_Shdr *Section = &shdr[i]; if (Section->sh_type == SHT_REL) { - for (uint64_t Index = 0; Index < Section->sh_size / Section->sh_entsize; Index++) + for (size_t Index = 0; Index < Section->sh_size / Section->sh_entsize; Index++) { - Elf64_Rel *RelTable = &((Elf64_Rel *)((uint64_t)Header + Section->sh_offset))[Index]; + Elf64_Rel *RelTable = &((Elf64_Rel *)((uintptr_t)Header + Section->sh_offset))[Index]; Elf64_Shdr *Target = GetElfSection(Header, Section->sh_info); - uint64_t *RelAddress = (uint64_t *)(((uint64_t)Header + Target->sh_offset) + RelTable->r_offset); + uintptr_t *RelAddress = (uintptr_t *)(((uintptr_t)Header + Target->sh_offset) + RelTable->r_offset); uint64_t SymbolValue = 0; if (ELF64_R_SYM(RelTable->r_info) != SHN_UNDEF) @@ -218,7 +218,7 @@ namespace Execute *RelAddress = DO_64_64(SymbolValue, *RelAddress); break; case R_386_PC32: - *RelAddress = DO_64_PC32(SymbolValue, *RelAddress, (uint64_t)RelAddress); + *RelAddress = DO_64_PC32(SymbolValue, *RelAddress, (uintptr_t)RelAddress); break; default: error("Unsupported relocation type: %d", ELF64_R_TYPE(RelTable->r_info)); diff --git a/Execute/Spawn.cpp b/Execute/Spawn.cpp index 1c1a705..caea58d 100644 --- a/Execute/Spawn.cpp +++ b/Execute/Spawn.cpp @@ -43,7 +43,7 @@ namespace Execute Memory::Virtual pva = Memory::Virtual(Process->PageTable); for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++) - pva.Map((void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), (void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + pva.Map((void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), (void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); Vector auxv; // TODO! @@ -76,13 +76,13 @@ namespace Execute void *BaseImage = KernelAllocator.RequestPages(TO_PAGES(ExFile->Node->Length)); memcpy(BaseImage, (void *)ExFile->Node->Address, ExFile->Node->Length); - debug("Image Size: %#lx - %#lx (length: %ld)", BaseImage, (uint64_t)BaseImage + ExFile->Node->Length, ExFile->Node->Length); + debug("Image Size: %#lx - %#lx (length: %ld)", BaseImage, (uintptr_t)BaseImage + ExFile->Node->Length, ExFile->Node->Length); PCB *Process = TaskManager->CreateProcess(TaskManager->GetCurrentProcess(), BaseName, TaskTrustLevel::User, BaseImage); Memory::Virtual pva = Memory::Virtual(Process->PageTable); for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++) - pva.Remap((void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), (void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + pva.Remap((void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), (void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)BaseImage; @@ -158,8 +158,8 @@ namespace Execute memset(MemoryImage, 0, ElfAppSize); for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++) { - pva.Remap((void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), (void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); - debug("Mapping: %#lx -> %#lx", (uint64_t)MemoryImage + (i * PAGE_SIZE), (uint64_t)MemoryImage + (i * PAGE_SIZE)); + pva.Remap((void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), (void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + debug("Mapping: %#lx -> %#lx", (uintptr_t)MemoryImage + (i * PAGE_SIZE), (uintptr_t)MemoryImage + (i * PAGE_SIZE)); } break; } @@ -172,10 +172,10 @@ namespace Execute memset(MemoryImage, 0, ElfAppSize); for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++) { - uint64_t Address = (uint64_t)ProgramHeader->p_vaddr; + uintptr_t Address = (uintptr_t)ProgramHeader->p_vaddr; Address &= 0xFFFFFFFFFFFFF000; - pva.Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); - debug("Mapping: %#lx -> %#lx", (uint64_t)Address + (i * PAGE_SIZE), (uint64_t)MemoryImage + (i * PAGE_SIZE)); + pva.Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + debug("Mapping: %#lx -> %#lx", (uintptr_t)Address + (i * PAGE_SIZE), (uintptr_t)MemoryImage + (i * PAGE_SIZE)); } } diff --git a/FileSystem/FS/ustar.cpp b/FileSystem/FS/ustar.cpp index 9e3f081..6d56724 100644 --- a/FileSystem/FS/ustar.cpp +++ b/FileSystem/FS/ustar.cpp @@ -24,11 +24,11 @@ namespace FileSystem .Read = USTAR_Read, }; - USTAR::USTAR(uint64_t Address, Virtual *vfs) + USTAR::USTAR(uintptr_t Address, Virtual *vfs) { trace("Initializing USTAR with address %#llx", Address); - if (memcmp(((FileHeader *)Address)->signature, "ustar", 5) != 0) + if (memcmp(((FileHeader *)(uintptr_t)Address)->signature, "ustar", 5) != 0) { error("ustar signature invalid!"); return; @@ -41,9 +41,9 @@ namespace FileSystem vfs->CreateRoot(&ustar, "/"); - uint64_t errorsallowed = 20; + int ErrorsAllowed = 20; - for (uint64_t i = 0;; i++) + for (size_t i = 0;; i++) { FileHeader *header = (FileHeader *)Address; if (memcmp(((FileHeader *)Address)->signature, "ustar", 5) != 0) @@ -51,7 +51,7 @@ namespace FileSystem memmove(header->name, header->name + 1, strlen(header->name)); if (header->name[strlen(header->name) - 1] == '/') header->name[strlen(header->name) - 1] = 0; - uint64_t size = getsize(header->size); + size_t size = getsize(header->size); FileSystemNode *node = nullptr; if (!isempty((char *)header->name)) @@ -63,9 +63,9 @@ namespace FileSystem debug("Added node: %s", node->Name); if (node == nullptr) { - if (errorsallowed > 0) + if (ErrorsAllowed > 0) { - errorsallowed--; + ErrorsAllowed--; goto NextFileAddress; } else diff --git a/FileSystem/Filesystem.cpp b/FileSystem/Filesystem.cpp index aff318a..40b131b 100644 --- a/FileSystem/Filesystem.cpp +++ b/FileSystem/Filesystem.cpp @@ -133,7 +133,7 @@ namespace FileSystem FileStatus RemoveChild(FileSystemNode *Parent, const char *Name) { vfsdbg("RemoveChild( Parent: \"%s\" Name: \"%s\" )", Parent->Name, Name); - for (uint64_t i = 0; i < Parent->Children.size(); i++) + for (uintptr_t i = 0; i < Parent->Children.size(); i++) if (strcmp(Parent->Children[i]->Name, Name) == 0) { Parent->Children.remove(i); @@ -414,7 +414,7 @@ namespace FileSystem return file; } - uint64_t Virtual::Read(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size) + size_t Virtual::Read(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size) { SmartLock(VFSLock); if (unlikely(!File)) @@ -437,7 +437,7 @@ namespace FileSystem return File->Node->Operator->Read(File->Node, Offset, Size, Buffer); } - uint64_t Virtual::Write(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size) + size_t Virtual::Write(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size) { SmartLock(VFSLock); if (unlikely(!File)) diff --git a/KThread.cpp b/KThread.cpp index d03f48b..1626693 100644 --- a/KThread.cpp +++ b/KThread.cpp @@ -25,7 +25,7 @@ void KernelMainThread() KPrint("Initializing Filesystem..."); vfs = new FileSystem::Virtual; - new FileSystem::USTAR((uint64_t)bInfo->Modules[0].Address, vfs); // TODO: Detect initrd + new FileSystem::USTAR((uintptr_t)bInfo->Modules[0].Address, vfs); // TODO: Detect initrd KPrint("Initializing Disk Manager..."); DiskManager = new Disk::Manager; @@ -36,7 +36,7 @@ void KernelMainThread() if (DriverManager->GetDrivers().size() > 0) { foreach (auto Driver in DriverManager->GetDrivers()) - if (((FexExtended *)((uint64_t)Driver->Address + EXTENDED_SECTION_ADDRESS))->Driver.Type == FexDriverType::FexDriverType_Storage) + if (((FexExtended *)((uintptr_t)Driver->Address + EXTENDED_SECTION_ADDRESS))->Driver.Type == FexDriverType::FexDriverType_Storage) DiskManager->FetchDisks(Driver->DriverUID); } else @@ -49,7 +49,7 @@ void KernelMainThread() "TERM=tty", "HOME=/", "USER=root", - "SHELL=/system/bin/sh", + "SHELL=/system/sh", "PWD=/", "LANG=en_US.UTF-8", "TZ=UTC", diff --git a/Kernel.cpp b/Kernel.cpp index e2091b7..ff47eb3 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -13,6 +13,24 @@ #include "Core/smbios.hpp" +#ifdef __amd64__ +#if UINTPTR_MAX != UINT64_MAX +#error "uintptr_t is not 64-bit!" +#endif // UINTPTR_MAX != UINT64_MAX +#endif // __amd64__ + +#ifdef __i386__ +#if UINTPTR_MAX != UINT32_MAX +#error "uintptr_t is not 32-bit!" +#endif // UINTPTR_MAX != UINT32_MAX +#endif // __i386__ + +#ifdef __aarch64__ +#if UINTPTR_MAX != UINT64_MAX +#error "uintptr_t is not 64-bit!" +#endif // UINTPTR_MAX != UINT64_MAX +#endif // __aarch64__ + NewLock(KernelLock); BootInfo *bInfo = nullptr; @@ -45,7 +63,7 @@ EXTERNC void KPrint(const char *Format, ...) Display->SetBuffer(0); } -EXTERNC __no_instrument_function void PostEntry(BootInfo *Info) +EXTERNC __no_instrument_function void AfterEntry(BootInfo *Info) { BootClock = Time::ReadClock(); bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo))); @@ -63,7 +81,7 @@ EXTERNC __no_instrument_function void PostEntry(BootInfo *Info) KPrint("Initializing CPU Features"); CPU::InitializeFeatures(); KPrint("Loading Kernel Symbols"); - KernelSymbolTable = new SymbolResolver::Symbols((uint64_t)Info->Kernel.FileBase); + KernelSymbolTable = new SymbolResolver::Symbols((uintptr_t)Info->Kernel.FileBase); KPrint("Reading Kernel Parameters"); Config = ParseConfig((char *)bInfo->Kernel.CommandLine); KPrint("Initializing Power Manager"); @@ -181,7 +199,7 @@ EXTERNC __no_stack_protector __no_instrument_function void Entry(BootInfo *Info) InitializeMemoryManagement(Info); EnableProfiler = true; - PostEntry(Info); + AfterEntry(Info); } EXTERNC __no_stack_protector __no_instrument_function void BeforeShutdown() diff --git a/Library/cargs.c b/Library/cargs.c index ef43ed8..6865771 100644 --- a/Library/cargs.c +++ b/Library/cargs.c @@ -404,7 +404,7 @@ static int cag_option_find_next(cag_option_context *context) // Grab a pointer to the string and verify that it is not the end. If it is // the end, we have to return false to indicate that we finished. c = context->argv[next_option_index]; - if (context->forced_end || c == NULL || (uint64_t)c == (uint64_t)0xfffffffffffff000 /* TODO: workaround */) + if (context->forced_end || c == NULL || (uintptr_t)c == (uintptr_t)0xfffffffffffff000 /* TODO: workaround */) { return -1; } diff --git a/Profiling/cyg.cpp b/Profiling/cyg.cpp index 87577e3..6814edc 100644 --- a/Profiling/cyg.cpp +++ b/Profiling/cyg.cpp @@ -48,8 +48,8 @@ EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_enter(void Level - 1, Level, ' ', - KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function), - KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite)); + KernelSymbolTable->GetSymbolFromAddress((uintptr_t)Function), + KernelSymbolTable->GetSymbolFromAddress((uintptr_t)CallSite)); Wait = false; } @@ -81,7 +81,7 @@ EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_exit(void Level - 1, Level, ' ', - KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function), - KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite)); + KernelSymbolTable->GetSymbolFromAddress((uintptr_t)Function), + KernelSymbolTable->GetSymbolFromAddress((uintptr_t)CallSite)); Wait = false; } diff --git a/SystemCalls/Linux.cpp b/SystemCalls/Linux.cpp index 72fbf83..607db0d 100644 --- a/SystemCalls/Linux.cpp +++ b/SystemCalls/Linux.cpp @@ -5,6 +5,8 @@ #include "../kernel.h" +typedef __INT32_TYPE__ mode_t; + #define internal_unimpl(a, b, c, d, e, f, g) \ { \ fixme("Unimplemented Syscall: %lld %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f, g); \ @@ -15,31 +17,31 @@ fixme("( %lld %lld %lld %lld %lld %lld %lld ) stub", a, b, c, d, e, f, g); \ } -static uint64_t sys_read(unsigned int fd, char *buf, size_t count) +static ssize_t sys_read(int fd, void *buf, size_t count) { fixme("read( %p %p %ld )", fd, buf, count); return -1; } -static uint64_t sys_write(unsigned int fd, const char *buf, size_t count) +static ssize_t sys_write(int fd, const char *buf, size_t count) { fixme("write( %p %p %ld )", fd, buf, count); return -1; } -static uint64_t sys_open(const char *filename, int flags, unsigned short mode) +static ssize_t sys_open(const char *filename, int flags, mode_t mode) { fixme("open( %s %d %d )", filename, flags, mode); return -1; } -static uint64_t sys_close(unsigned int fd) +static ssize_t sys_close(int fd) { fixme("close( %d )", fd); return -1; } -static uint64_t sys_stat(const char *filename, void *statbuf) +static ssize_t sys_stat(const char *filename, void *statbuf) { fixme("stat( %s %p )", filename, statbuf); return -1; diff --git a/SystemCalls/Native.cpp b/SystemCalls/Native.cpp index f1c8a5d..abcc4a6 100644 --- a/SystemCalls/Native.cpp +++ b/SystemCalls/Native.cpp @@ -6,7 +6,7 @@ #include "../syscalls.h" #include "../kernel.h" -static uint64_t sys_exit(SyscallsFrame *Frame, uint64_t code) +static int sys_exit(SyscallsFrame *Frame, int code) { trace("Userspace thread %s(%lld) exited with code %#llx", TaskManager->GetCurrentThread()->Name, TaskManager->GetCurrentThread()->ID, code); TaskManager->GetCurrentThread()->ExitCode = code; @@ -23,18 +23,18 @@ static int sys_print(SyscallsFrame *Frame, char Char, int Index) return ret; } -static uint64_t sys_request_pages(SyscallsFrame *Frame, uint64_t Count) +static uintptr_t sys_request_pages(SyscallsFrame *Frame, size_t Count) { - return (uint64_t)TaskManager->GetCurrentThread()->Memory->RequestPages(Count); + return (uintptr_t)TaskManager->GetCurrentThread()->Memory->RequestPages(Count); } -static uint64_t sys_free_pages(SyscallsFrame *Frame, uint64_t Address, uint64_t Count) +static int sys_free_pages(SyscallsFrame *Frame, uintptr_t Address, size_t Count) { TaskManager->GetCurrentThread()->Memory->FreePages((void *)Address, Count); return 0; } -static uint64_t sys_kernelctl(SyscallsFrame *Frame, uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4) +static int sys_kernelctl(SyscallsFrame *Frame, int Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4) { fixme("KernelCTL: %lld", Command); return 0; @@ -50,7 +50,7 @@ static void *NativeSyscallsTable[] = { [_KernelCTL] = (void *)sys_kernelctl, }; -uint64_t HandleNativeSyscalls(SyscallsFrame *Frame) +uintptr_t HandleNativeSyscalls(SyscallsFrame *Frame) { #if defined(__amd64__) // debug("rax: %#llx, rbx: %#llx, rcx: %#llx, rdx: %#llx, rsi: %#llx, rdi: %#llx, rbp: %#llx, r8: %#llx, r9: %#llx, r10: %#llx, r11: %#llx, r12: %#llx, r13: %#llx, r14: %#llx, r15: %#llx", Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi, Frame->rbp, Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13, Frame->r14, Frame->r15); @@ -60,14 +60,14 @@ uint64_t HandleNativeSyscalls(SyscallsFrame *Frame) return -1; } - uint64_t (*call)(uint64_t, ...) = reinterpret_cast(NativeSyscallsTable[Frame->rax]); + uintptr_t (*call)(uintptr_t, ...) = reinterpret_cast(NativeSyscallsTable[Frame->rax]); if (!call) { error("Syscall %#llx failed.", Frame->rax); return -1; } debug("[%#lx]->( %#lx %#lx %#lx %#lx %#lx %#lx )", Frame->rax, Frame->rdi, Frame->rsi, Frame->rdx, Frame->rcx, Frame->r8, Frame->r9); - uint64_t ret = call((uint64_t)Frame, Frame->rdi, Frame->rsi, Frame->rdx, Frame->r10, Frame->r8, Frame->r9); + uintptr_t ret = call((uintptr_t)Frame, Frame->rdi, Frame->rsi, Frame->rdx, Frame->r10, Frame->r8, Frame->r9); Frame->rax = ret; return ret; #elif defined(__i386__) diff --git a/SystemCalls/Syscalls.cpp b/SystemCalls/Syscalls.cpp index bec512d..87be5eb 100644 --- a/SystemCalls/Syscalls.cpp +++ b/SystemCalls/Syscalls.cpp @@ -4,7 +4,7 @@ #include "../kernel.h" -extern "C" uint64_t SystemCallsHandler(SyscallsFrame *Frame) +extern "C" uintptr_t SystemCallsHandler(SyscallsFrame *Frame) { #if defined(__amd64__) switch (TaskManager->GetCurrentThread()->Info.Compatibility) diff --git a/Tasking/InterProcessCommunication.cpp b/Tasking/InterProcessCommunication.cpp index 4fef971..4ea3c37 100644 --- a/Tasking/InterProcessCommunication.cpp +++ b/Tasking/InterProcessCommunication.cpp @@ -29,7 +29,7 @@ namespace InterProcessCommunication handle->Operation = IPCOperationNone; handle->Listening = 0; handle->Error = IPCUnknown; - pcb->IPCHandles->AddNode(Port, (uint64_t)handle); + pcb->IPCHandles->AddNode(Port, (uintptr_t)handle); return handle; } @@ -101,7 +101,7 @@ namespace InterProcessCommunication Vector Processes = TaskManager->GetProcessList(); - for (uint64_t i = 0; i < Processes.size(); i++) + for (size_t i = 0; i < Processes.size(); i++) { Tasking::PCB *pcb = Processes[i]; diff --git a/Tasking/Security.cpp b/Tasking/Security.cpp index 4f5a1c6..e121329 100644 --- a/Tasking/Security.cpp +++ b/Tasking/Security.cpp @@ -62,7 +62,7 @@ namespace Tasking Security::~Security() { trace("Destroying Tasking Security"); - for (uint64_t i = 0; i < Tokens.size(); i++) + for (size_t i = 0; i < Tokens.size(); i++) Tokens.remove(i); } } diff --git a/Tasking/Task.cpp b/Tasking/Task.cpp index e142d40..900a531 100644 --- a/Tasking/Task.cpp +++ b/Tasking/Task.cpp @@ -87,7 +87,7 @@ namespace Tasking SafeFunction __no_instrument_function void Task::RemoveThread(TCB *Thread) { - for (uint64_t i = 0; i < Thread->Parent->Threads.size(); i++) + for (size_t i = 0; i < Thread->Parent->Threads.size(); i++) if (Thread->Parent->Threads[i] == Thread) { trace("Thread \"%s\"(%d) removed from process \"%s\"(%d)", @@ -116,7 +116,7 @@ namespace Tasking foreach (PCB *process in Process->Children) RemoveProcess(process); - for (uint64_t i = 0; i < ListProcess.size(); i++) + for (size_t i = 0; i < ListProcess.size(); i++) { if (ListProcess[i] == Process) { @@ -232,20 +232,20 @@ namespace Tasking { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; - for (uint64_t i = 0; i < CurrentCPU->CurrentProcess->Threads.size(); i++) + for (size_t i = 0; i < CurrentCPU->CurrentProcess->Threads.size(); i++) { // Loop until we find the current thread from the process thread list. if (CurrentCPU->CurrentProcess->Threads[i] == CurrentCPU->CurrentThread) { // Check if the next thread is valid. If not, we search until we find, but if we reach the end of the list, we go to the next process. - uint64_t tmpidx = i; + size_t TempIndex = i; RetryAnotherThread: - TCB *thread = CurrentCPU->CurrentProcess->Threads[tmpidx + 1]; + TCB *thread = CurrentCPU->CurrentProcess->Threads[TempIndex + 1]; if (InvalidTCB(thread)) { - if (tmpidx > CurrentCPU->CurrentProcess->Threads.size()) + if (TempIndex > CurrentCPU->CurrentProcess->Threads.size()) break; - tmpidx++; + TempIndex++; goto RetryAnotherThread; } @@ -272,20 +272,20 @@ namespace Tasking { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; - for (uint64_t i = 0; i < ListProcess.size(); i++) + for (size_t i = 0; i < ListProcess.size(); i++) { // Loop until we find the current process from the process list. if (ListProcess[i] == CurrentCPU->CurrentProcess) { // Check if the next process is valid. If not, we search until we find. - uint64_t tmpidx = i; + size_t TempIndex = i; RetryAnotherProcess: - PCB *pcb = ListProcess[tmpidx + 1]; + PCB *pcb = ListProcess[TempIndex + 1]; if (InvalidPCB(pcb)) { - if (tmpidx > ListProcess.size()) + if (TempIndex > ListProcess.size()) break; - tmpidx++; + TempIndex++; goto RetryAnotherProcess; } @@ -293,7 +293,7 @@ namespace Tasking goto RetryAnotherProcess; // Everything good, now search for a thread. - for (uint64_t j = 0; j < pcb->Threads.size(); j++) + for (size_t j = 0; j < pcb->Threads.size(); j++) { TCB *tcb = pcb->Threads[j]; if (InvalidTCB(tcb)) @@ -368,7 +368,7 @@ namespace Tasking schedbg("================================================================"); schedbg("Status: 0-ukn | 1-rdy | 2-run | 3-wait | 4-term"); schedbg("Technical Informations on regs %#lx", Frame->InterruptNumber); - uint64_t ds; + size_t ds; asmv("mov %%ds, %0" : "=r"(ds)); schedbg("FS=%#lx GS=%#lx SS=%#lx CS=%#lx DS=%#lx", @@ -506,7 +506,7 @@ namespace Tasking CurrentCPU->CurrentThread->RIPHistory[127] = Frame->rip; } } - GlobalDescriptorTable::SetKernelStack((void *)((uint64_t)CurrentCPU->CurrentThread->Stack->GetStackTop())); + GlobalDescriptorTable::SetKernelStack((void *)((uintptr_t)CurrentCPU->CurrentThread->Stack->GetStackTop())); CPU::x64::writecr3({.raw = (uint64_t)CurrentCPU->CurrentProcess->PageTable}); // Not sure if this is needed, but it's better to be safe than sorry. asmv("movq %cr3, %rax"); @@ -752,8 +752,8 @@ namespace Tasking Thread->Registers.rflags.AlwaysOne = 1; Thread->Registers.rflags.IF = 1; Thread->Registers.rflags.ID = 1; - Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop()); - POKE(uint64_t, Thread->Registers.rsp) = (uint64_t)ThreadDoExit; + Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop()); + POKE(uintptr_t, Thread->Registers.rsp) = (uintptr_t)ThreadDoExit; #elif defined(__i386__) #elif defined(__aarch64__) #endif @@ -775,14 +775,14 @@ namespace Tasking // Thread->Registers.rflags.IOPL = 3; Thread->Registers.rflags.IF = 1; Thread->Registers.rflags.ID = 1; - Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop()); + Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop()); - uint64_t ArgvSize = 0; + size_t ArgvSize = 0; if (argv) while (argv[ArgvSize] != nullptr) ArgvSize++; - uint64_t EnvpSize = 0; + size_t EnvpSize = 0; if (envp) while (envp[EnvpSize] != nullptr) EnvpSize++; @@ -799,40 +799,40 @@ namespace Tasking char *StackStringsVirtual = (char *)Thread->Stack->GetStackTop(); // Store string pointers for later - uint64_t ArgvStrings[ArgvSize]; - uint64_t EnvpStrings[EnvpSize]; + uintptr_t ArgvStrings[ArgvSize]; + uintptr_t EnvpStrings[EnvpSize]; - for (uint64_t i = 0; i < ArgvSize; i++) + for (size_t i = 0; i < ArgvSize; i++) { // Subtract the length of the string and the null terminator StackStrings -= strlen(argv[i]) + 1; StackStringsVirtual -= strlen(argv[i]) + 1; // Store the pointer to the string - ArgvStrings[i] = (uint64_t)StackStringsVirtual; + ArgvStrings[i] = (uintptr_t)StackStringsVirtual; // Copy the string to the stack strcpy(StackStrings, argv[i]); } - for (uint64_t i = 0; i < EnvpSize; i++) + for (size_t i = 0; i < EnvpSize; i++) { // Subtract the length of the string and the null terminator StackStrings -= strlen(envp[i]) + 1; StackStringsVirtual -= strlen(envp[i]) + 1; // Store the pointer to the string - EnvpStrings[i] = (uint64_t)StackStringsVirtual; + EnvpStrings[i] = (uintptr_t)StackStringsVirtual; // Copy the string to the stack strcpy(StackStrings, envp[i]); } // Align the stack to 16 bytes - StackStrings -= (uint64_t)StackStrings & 0xF; + StackStrings -= (uintptr_t)StackStrings & 0xF; // Set "Stack" to the new stack pointer Stack = (char *)StackStrings; // If argv and envp sizes are odd then we need to align the stack Stack -= (ArgvSize + EnvpSize) % 2; // We need 8 bit pointers for the stack from here - uint64_t *Stack64 = (uint64_t *)Stack; + uintptr_t *Stack64 = (uintptr_t *)Stack; // Store the null terminator Stack64--; @@ -842,7 +842,7 @@ namespace Tasking foreach (AuxiliaryVector var in auxv) { // Subtract the size of the auxillary vector - Stack64 -= sizeof(Elf64_auxv_t) / sizeof(uint64_t); + Stack64 -= sizeof(Elf64_auxv_t) / sizeof(uintptr_t); // Store the auxillary vector POKE(Elf64_auxv_t, Stack64) = var.archaux; // TODO: Store strings to the stack @@ -854,9 +854,9 @@ namespace Tasking // Store EnvpStrings[] to the stack Stack64 -= EnvpSize; // (1 Stack64 = 8 bits; Stack64 = 8 * EnvpSize) - for (uint64_t i = 0; i < EnvpSize; i++) + for (size_t i = 0; i < EnvpSize; i++) { - *(Stack64 + i) = (uint64_t)EnvpStrings[i]; + *(Stack64 + i) = (uintptr_t)EnvpStrings[i]; debug("EnvpStrings[%d]: %#lx", i, EnvpStrings[i]); } @@ -866,9 +866,9 @@ namespace Tasking // Store ArgvStrings[] to the stack Stack64 -= ArgvSize; // (1 Stack64 = 8 bits; Stack64 = 8 * ArgvSize) - for (uint64_t i = 0; i < ArgvSize; i++) + for (size_t i = 0; i < ArgvSize; i++) { - *(Stack64 + i) = (uint64_t)ArgvStrings[i]; + *(Stack64 + i) = (uintptr_t)ArgvStrings[i]; debug("ArgvStrings[%d]: %#lx", i, ArgvStrings[i]); } @@ -881,20 +881,20 @@ namespace Tasking /* We need the virtual address but because we are in the kernel we can't use the process page table. So we modify the physical address and store how much we need to subtract to get the virtual address for RSP. */ - uint64_t SubtractStack = (uint64_t)Thread->Stack->GetStackPhysicalTop() - (uint64_t)Stack; + uintptr_t SubtractStack = (uintptr_t)Thread->Stack->GetStackPhysicalTop() - (uintptr_t)Stack; debug("SubtractStack: %#lx", SubtractStack); // Set the stack pointer to the new stack - Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop() - SubtractStack); + Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop() - SubtractStack); #ifdef DEBUG - DumpData("Stack Data", (void *)((uint64_t)Thread->Stack->GetStackPhysicalTop() - (uint64_t)SubtractStack), SubtractStack); + DumpData("Stack Data", (void *)((uintptr_t)Thread->Stack->GetStackPhysicalTop() - (uintptr_t)SubtractStack), SubtractStack); #endif - Thread->Registers.rdi = (uint64_t)ArgvSize; // argc - Thread->Registers.rsi = (uint64_t)(Thread->Registers.rsp + 8); // argv - Thread->Registers.rcx = (uint64_t)EnvpSize; // envc - Thread->Registers.rdx = (uint64_t)(Thread->Registers.rsp + 8 + (8 * ArgvSize) + 8); // envp + Thread->Registers.rdi = (uintptr_t)ArgvSize; // argc + Thread->Registers.rsi = (uintptr_t)(Thread->Registers.rsp + 8); // argv + Thread->Registers.rcx = (uintptr_t)EnvpSize; // envc + Thread->Registers.rdx = (uintptr_t)(Thread->Registers.rsp + 8 + (8 * ArgvSize) + 8); // envp /* We need to leave the libc's crt to make a syscall when the Thread is exited or we are going to get GPF or PF exception. */ @@ -973,7 +973,7 @@ namespace Tasking Process->Security.TrustLevel = TrustLevel; // Process->Security.UniqueToken = SecurityManager.CreateToken(); - Process->IPCHandles = new HashMap; + Process->IPCHandles = new HashMap; switch (TrustLevel) { @@ -997,7 +997,7 @@ namespace Tasking #if defined(__amd64__) Process->PageTable = (Memory::PageTable4 *)KernelAllocator.RequestPages(TO_PAGES(PAGE_SIZE)); memcpy(Process->PageTable, (void *)UserspaceKernelOnlyPageTable, PAGE_SIZE); - for (uint64_t i = 0; i < TO_PAGES(PAGE_SIZE); i++) + for (size_t i = 0; i < TO_PAGES(PAGE_SIZE); i++) Memory::Virtual(Process->PageTable).Map((void *)Process->PageTable, (void *)Process->PageTable, Memory::PTFlag::RW); // Make sure the page table is mapped. #elif defined(__i386__) #elif defined(__aarch64__) @@ -1037,7 +1037,7 @@ namespace Tasking if (Image) { // TODO: Check if it's ELF - Process->ELFSymbolTable = new SymbolResolver::Symbols((uint64_t)Image); + Process->ELFSymbolTable = new SymbolResolver::Symbols((uintptr_t)Image); } else debug("No image provided for process \"%s\"(%d)", Process->Name, Process->ID); @@ -1093,7 +1093,7 @@ namespace Tasking for (int i = 0; i < SMP::CPUCores; i++) { Vector auxv; - IdleThread = CreateThread(IdleProcess, reinterpret_cast(IdleProcessLoop), nullptr, nullptr, auxv); + IdleThread = CreateThread(IdleProcess, reinterpret_cast(IdleProcessLoop), nullptr, nullptr, auxv); char IdleName[16]; sprintf_(IdleName, "Idle Thread %d", i); IdleThread->Rename(IdleName); diff --git a/Tests/RandomNumberGenerator.cpp b/Tests/RandomNumberGenerator.cpp index f1bcd10..418ff30 100644 --- a/Tests/RandomNumberGenerator.cpp +++ b/Tests/RandomNumberGenerator.cpp @@ -53,7 +53,7 @@ __constructor void TestRandom() uint16_t Seeds16[16]; uint32_t Seeds32[16]; uint64_t Seeds64[16]; - for (uint64_t i = 0; i < 16; i++) + for (short i = 0; i < 16; i++) { Seeds16[i] = Random::rand16(); Seeds32[i] = Random::rand32(); diff --git a/include/bitmap.hpp b/include/bitmap.hpp index b34d5be..a64611c 100644 --- a/include/bitmap.hpp +++ b/include/bitmap.hpp @@ -6,7 +6,7 @@ class Bitmap public: size_t Size; uint8_t *Buffer; - bool operator[](uint64_t index); - bool Set(uint64_t index, bool value); - bool Get(uint64_t index); + bool operator[](uintptr_t index); + bool Set(uintptr_t index, bool value); + bool Get(uintptr_t index); }; diff --git a/include/disk.hpp b/include/disk.hpp index 3939b0d..d1b6e64 100644 --- a/include/disk.hpp +++ b/include/disk.hpp @@ -86,16 +86,16 @@ namespace Disk { public: char Label[72] = "Unidentified Partition"; - uint64_t StartLBA = 0xdeadbeef; - uint64_t EndLBA = 0xdeadbeef; - uint64_t Sectors = 0xdeadbeef; - uint64_t Flags = 0xdeadbeef; + size_t StartLBA = 0xdeadbeef; + size_t EndLBA = 0xdeadbeef; + size_t Sectors = 0xdeadbeef; + size_t Flags = 0xdeadbeef; unsigned char Port = 0; PartitionStyle Style = PartitionStyle::Unknown; size_t Index = 0; - uint64_t Read(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; } - uint64_t Write(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; } + size_t Read(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; } + size_t Write(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; } Partition() {} ~Partition() {} }; @@ -109,10 +109,10 @@ namespace Disk PartitionStyle Style = PartitionStyle::Unknown; Vector Partitions; bool MechanicalDisk = false; - uint64_t UniqueIdentifier = 0xdeadbeef; + size_t UniqueIdentifier = 0xdeadbeef; - uint64_t Read(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; } - uint64_t Write(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; } + size_t Read(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; } + size_t Write(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; } Drive() { // TODO: Allocate buffer } diff --git a/include/display.hpp b/include/display.hpp index 191e7a7..eeed7aa 100644 --- a/include/display.hpp +++ b/include/display.hpp @@ -57,8 +57,8 @@ namespace Video struct FontInfo { - uint64_t *StartAddress; - uint64_t *EndAddress; + uintptr_t *StartAddress; + uintptr_t *EndAddress; PSF1_FONT *PSF1Font; PSF2_FONT *PSF2Font; uint32_t Width, Height; @@ -72,7 +72,7 @@ namespace Video public: FontInfo GetInfo() { return Info; } - Font(uint64_t *Start, uint64_t *End, FontType Type); + Font(uintptr_t *Start, uintptr_t *End, FontType Type); ~Font(); }; @@ -80,7 +80,7 @@ namespace Video { void *Buffer = nullptr; uint32_t Width, Height; - uint64_t Size; + size_t Size; uint32_t Color; uint32_t CursorX, CursorY; long Checksum; @@ -107,7 +107,7 @@ namespace Video debug("No width and height specified, using %ldx%lld", Width, Height); } - uint64_t Size = this->framebuffer.Pitch * Height; + size_t Size = this->framebuffer.Pitch * Height; if (!this->Buffers[Index]) { if (this->Buffers[Index]->Checksum != 0xDEAD5C9EE7) @@ -160,7 +160,7 @@ namespace Video X = this->Buffers[Index]->Width - 1; if (Y >= this->Buffers[Index]->Height) Y = this->Buffers[Index]->Height - 1; - uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)); + uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)); *Pixel = Color; } @@ -168,7 +168,7 @@ namespace Video { if (X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height) return 0; - uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)); + uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)); return *Pixel; } diff --git a/include/driver.hpp b/include/driver.hpp index 7349ea5..8f26644 100644 --- a/include/driver.hpp +++ b/include/driver.hpp @@ -58,17 +58,17 @@ namespace Driver unsigned long DriverUIDs = 0; DriverCode CallDriverEntryPoint(void *fex, void *KAPIAddress); - DriverCode DriverLoadBindPCI(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false); - DriverCode DriverLoadBindInterrupt(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false); - DriverCode DriverLoadBindInput(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false); - DriverCode DriverLoadBindProcess(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false); + DriverCode DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false); + DriverCode DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false); + DriverCode DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false); + DriverCode DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false); public: Vector GetDrivers() { return Drivers; } void UnloadAllDrivers(); bool UnloadDriver(unsigned long DUID); int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB); - DriverCode LoadDriver(uint64_t DriverAddress, uint64_t Size); + DriverCode LoadDriver(uintptr_t DriverAddress, size_t Size); DriverCode StartDrivers(); Driver(); ~Driver(); diff --git a/include/filesystem.hpp b/include/filesystem.hpp index 3b29398..27226e5 100644 --- a/include/filesystem.hpp +++ b/include/filesystem.hpp @@ -20,24 +20,24 @@ namespace FileSystem struct FileSystemNode; - typedef uint64_t (*OperationMount)(const char *, unsigned long, const void *); - typedef uint64_t (*OperationUmount)(int); - typedef uint64_t (*OperationRead)(FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer); - typedef uint64_t (*OperationWrite)(FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer); + typedef size_t (*OperationMount)(const char *, unsigned long, const void *); + typedef size_t (*OperationUmount)(int); + typedef size_t (*OperationRead)(FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer); + typedef size_t (*OperationWrite)(FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer); typedef void (*OperationOpen)(FileSystemNode *Node, uint8_t Mode, uint8_t Flags); typedef void (*OperationClose)(FileSystemNode *Node); - typedef uint64_t (*OperationSync)(void); + typedef size_t (*OperationSync)(void); typedef void (*OperationCreate)(FileSystemNode *Node, char *Name, uint16_t NameLength); typedef void (*OperationMkdir)(FileSystemNode *Node, char *Name, uint16_t NameLength); -#define MountFSFunction(name) uint64_t name(const char *unknown0, unsigned long unknown1, const uint8_t *unknown2) -#define UMountFSFunction(name) uint64_t name(int unknown0) +#define MountFSFunction(name) size_t name(const char *unknown0, unsigned long unknown1, const uint8_t *unknown2) +#define UMountFSFunction(name) size_t name(int unknown0) -#define ReadFSFunction(name) uint64_t name(FileSystem::FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer) -#define WriteFSFunction(name) uint64_t name(FileSystem::FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer) +#define ReadFSFunction(name) size_t name(FileSystem::FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer) +#define WriteFSFunction(name) size_t name(FileSystem::FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer) #define OpenFSFunction(name) void name(FileSystem::FileSystemNode *Node, uint8_t Mode, uint8_t Flags) #define CloseFSFunction(name) void name(FileSystem::FileSystemNode *Node) -#define SyncFSFunction(name) uint64_t name(void) +#define SyncFSFunction(name) size_t name(void) #define CreateFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength) #define MkdirFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength) @@ -108,10 +108,10 @@ namespace FileSystem uint64_t IndexNode = 0; uint64_t Mask = 0; uint64_t Mode = 0; - uint64_t Flags = NodeFlags::FS_ERROR; + int Flags = NodeFlags::FS_ERROR; uint64_t UserIdentifier = 0, GroupIdentifier = 0; - uint64_t Address = 0; - uint64_t Length = 0; + uintptr_t Address = 0; + size_t Length = 0; FileSystemNode *Parent = nullptr; FileSystemOperations *Operator = nullptr; /* For root node: @@ -153,8 +153,8 @@ namespace FileSystem FILE *Mount(FileSystemOperations *Operator, const char *Path); FileStatus Unmount(FILE *File); FILE *Open(const char *Path, FileSystemNode *Parent = nullptr); - uint64_t Read(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size); - uint64_t Write(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size); + size_t Read(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size); + size_t Write(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size); FileStatus Close(FILE *File); FileSystemNode *CreateRoot(FileSystemOperations *Operator, const char *RootName); FileSystemNode *Create(FileSystemNode *Parent, const char *Path); diff --git a/include/filesystem/initrd.hpp b/include/filesystem/initrd.hpp index 6be3f2d..911ad25 100644 --- a/include/filesystem/initrd.hpp +++ b/include/filesystem/initrd.hpp @@ -23,7 +23,7 @@ namespace FileSystem uint32_t length; }; - Initrd(uint64_t Address); + Initrd(uintptr_t Address); ~Initrd(); }; } diff --git a/include/filesystem/mounts.hpp b/include/filesystem/mounts.hpp index 6bc9935..7b75a1f 100644 --- a/include/filesystem/mounts.hpp +++ b/include/filesystem/mounts.hpp @@ -88,7 +88,7 @@ namespace FileSystem class FB { public: - void SetFrameBufferData(uint64_t Address, uint64_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine); + void SetFrameBufferData(uintptr_t Address, size_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine); FB(); ~FB(); }; diff --git a/include/filesystem/ustar.hpp b/include/filesystem/ustar.hpp index b56e0fd..31900ff 100644 --- a/include/filesystem/ustar.hpp +++ b/include/filesystem/ustar.hpp @@ -44,7 +44,7 @@ namespace FileSystem private: uint32_t getsize(const char *s) { - uint64_t ret = 0; + uint32_t ret = 0; while (*s) { ret *= 8; @@ -63,7 +63,7 @@ namespace FileSystem } public: - USTAR(uint64_t Address, Virtual *vfs); + USTAR(uintptr_t Address, Virtual *vfs); ~USTAR(); }; } diff --git a/include/io.h b/include/io.h index 9089e84..ccbabd9 100644 --- a/include/io.h +++ b/include/io.h @@ -61,7 +61,7 @@ extern "C" { asmv("" :: : "memory"); - uint8_t Result = *(volatile uint8_t *)Address; + uint8_t Result = *(volatile uint8_t *)(uintptr_t)Address; asmv("" :: : "memory"); return Result; @@ -71,7 +71,7 @@ extern "C" { asmv("" :: : "memory"); - uint16_t Result = *(volatile uint16_t *)Address; + uint16_t Result = *(volatile uint16_t *)(uintptr_t)Address; asmv("" :: : "memory"); return Result; @@ -81,7 +81,7 @@ extern "C" { asmv("" :: : "memory"); - uint32_t Result = *(volatile uint32_t *)Address; + uint32_t Result = *(volatile uint32_t *)(uintptr_t)Address; asmv("" :: : "memory"); return Result; @@ -91,7 +91,7 @@ extern "C" { asmv("" :: : "memory"); - uint64_t Result = *(volatile uint64_t *)Address; + uint64_t Result = *(volatile uint64_t *)(uintptr_t)Address; asmv("" :: : "memory"); return Result; diff --git a/include/lock.hpp b/include/lock.hpp index afa411b..aadd805 100644 --- a/include/lock.hpp +++ b/include/lock.hpp @@ -13,7 +13,7 @@ class LockClass uint64_t LockData = 0x0; const char *CurrentHolder = "(nul)"; const char *AttemptingToGet = "(nul)"; - uint64_t Count = 0; + size_t Count = 0; long Core = 0; }; void DeadLock(SpinLockData Lock); diff --git a/include/md5.h b/include/md5.h index ecf5962..b544e5b 100644 --- a/include/md5.h +++ b/include/md5.h @@ -11,7 +11,7 @@ START_EXTERNC typedef struct { - uint64_t size; // Size of input in bytes + size_t size; // Size of input in bytes uint32_t buffer[4]; // Current accumulation of hash uint8_t input[64]; // Input to be used in the next step uint8_t digest[16]; // Result of algorithm diff --git a/include/memory.hpp b/include/memory.hpp index 469dc71..ee8a43f 100644 --- a/include/memory.hpp +++ b/include/memory.hpp @@ -11,8 +11,8 @@ #ifdef __cplusplus -extern uint64_t _kernel_start, _kernel_end; -extern uint64_t _kernel_text_end, _kernel_data_end, _kernel_rodata_end; +extern uintptr_t _kernel_start, _kernel_end; +extern uintptr_t _kernel_text_end, _kernel_data_end, _kernel_rodata_end; // kilobyte #define TO_KB(d) (d / 1024) @@ -177,7 +177,7 @@ namespace Memory uint64_t raw; /** @brief Set Address */ - void SetAddress(uint64_t _Address) + void SetAddress(uintptr_t _Address) { #if defined(__amd64__) _Address &= 0x000000FFFFFFFFFF; @@ -195,7 +195,7 @@ namespace Memory } /** @brief Get Address */ - uint64_t GetAddress() + uintptr_t GetAddress() { #if defined(__amd64__) return (this->raw & 0x000FFFFFFFFFF000) >> 12; @@ -232,7 +232,7 @@ namespace Memory uint64_t raw; /** @brief Set PageTableEntryPtr address */ - void SetAddress(uint64_t _Address) + void SetAddress(uintptr_t _Address) { #if defined(__amd64__) _Address &= 0x000000FFFFFFFFFF; @@ -250,7 +250,7 @@ namespace Memory } /** @brief Get PageTableEntryPtr address */ - uint64_t GetAddress() + uintptr_t GetAddress() { #if defined(__amd64__) return (this->raw & 0x000FFFFFFFFFF000) >> 12; @@ -287,7 +287,7 @@ namespace Memory uint64_t raw; /** @brief Set PageDirectoryEntryPtr address */ - void SetAddress(uint64_t _Address) + void SetAddress(uintptr_t _Address) { #if defined(__amd64__) _Address &= 0x000000FFFFFFFFFF; @@ -305,7 +305,7 @@ namespace Memory } /** @brief Get PageDirectoryEntryPtr address */ - uint64_t GetAddress() + uintptr_t GetAddress() { #if defined(__amd64__) return (this->raw & 0x000FFFFFFFFFF000) >> 12; @@ -342,7 +342,7 @@ namespace Memory uint64_t raw; /** @brief Set PageDirectoryPointerTableEntryPtr address */ - void SetAddress(uint64_t _Address) + void SetAddress(uintptr_t _Address) { #if defined(__amd64__) _Address &= 0x000000FFFFFFFFFF; @@ -360,7 +360,7 @@ namespace Memory } /** @brief Get PageDirectoryPointerTableEntryPtr address */ - uint64_t GetAddress() + uintptr_t GetAddress() { #if defined(__amd64__) return (this->raw & 0x000FFFFFFFFFF000) >> 12; @@ -400,9 +400,9 @@ namespace Memory Bitmap PageBitmap; void ReservePage(void *Address); - void ReservePages(void *Address, uint64_t PageCount); + void ReservePages(void *Address, size_t PageCount); void UnreservePage(void *Address); - void UnreservePages(void *Address, uint64_t PageCount); + void UnreservePages(void *Address, size_t PageCount); public: Bitmap GetPageBitmap() { return PageBitmap; } @@ -447,7 +447,7 @@ namespace Memory * @return true if swap was successful * @return false if swap was unsuccessful */ - bool SwapPages(void *Address, uint64_t PageCount); + bool SwapPages(void *Address, size_t PageCount); /** * @brief Unswap page * @@ -464,7 +464,7 @@ namespace Memory * @return true if unswap was successful * @return false if unswap was unsuccessful */ - bool UnswapPages(void *Address, uint64_t PageCount); + bool UnswapPages(void *Address, size_t PageCount); /** * @brief Lock page @@ -478,7 +478,7 @@ namespace Memory * @param Address Address of the pages * @param PageCount Number of pages */ - void LockPages(void *Address, uint64_t PageCount); + void LockPages(void *Address, size_t PageCount); /** * @brief Request page @@ -492,7 +492,7 @@ namespace Memory * @param PageCount Number of pages * @return void* Allocated pages address */ - void *RequestPages(uint64_t Count); + void *RequestPages(size_t Count); /** * @brief Free page * @@ -505,7 +505,7 @@ namespace Memory * @param Address Address of the pages * @param PageCount Number of pages */ - void FreePages(void *Address, uint64_t Count); + void FreePages(void *Address, size_t Count); /** @brief Do not use. */ void Init(BootInfo *Info); /** @brief Do not use. */ @@ -524,11 +524,11 @@ namespace Memory class PageMapIndexer { public: - uint64_t PMLIndex = 0; - uint64_t PDPTEIndex = 0; - uint64_t PDEIndex = 0; - uint64_t PTEIndex = 0; - PageMapIndexer(uint64_t VirtualAddress); + uintptr_t PMLIndex = 0; + uintptr_t PDPTEIndex = 0; + uintptr_t PDEIndex = 0; + uintptr_t PTEIndex = 0; + PageMapIndexer(uintptr_t VirtualAddress); }; /** @@ -558,7 +558,7 @@ namespace Memory * @param PageCount Number of pages. * @param Flags Flags of the page. Check PTFlag enum. */ - void Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags); + void Map(void *VirtualAddress, void *PhysicalAddress, size_t PageCount, uint64_t Flags); /** * @brief Unmap page. @@ -573,7 +573,7 @@ namespace Memory * @param VirtualAddress First virtual address of the page. * @param PageCount Number of pages. */ - void Unmap(void *VirtualAddress, uint64_t PageCount); + void Unmap(void *VirtualAddress, size_t PageCount); /** * @brief Remap page. @@ -619,7 +619,7 @@ namespace Memory /** @brief For general info */ void *GetStackPhysicalTop() { return StackPhyiscalTop; } /** @brief Called by exception handler */ - bool Expand(uint64_t FaultAddress); + bool Expand(uintptr_t FaultAddress); /** * @brief Construct a new Stack Guard object * @param User Stack for user mode? @@ -640,7 +640,7 @@ namespace Memory struct AllocatedPages { void *Address; - uint64_t PageCount; + size_t PageCount; }; Vector AllocatedPagesList; @@ -648,8 +648,8 @@ namespace Memory public: uint64_t GetAllocatedMemorySize(); - void *RequestPages(uint64_t Count); - void FreePages(void *Address, uint64_t Count); + void *RequestPages(size_t Count); + void FreePages(void *Address, size_t Count); Tracker(PageTable4 *PageTable = nullptr); ~Tracker(); @@ -686,9 +686,9 @@ extern Memory::PageTable4 *UserspaceKernelOnlyPageTable; extern void *KPT; -EXTERNC void *HeapMalloc(uint64_t Size); -EXTERNC void *HeapCalloc(uint64_t n, uint64_t Size); -EXTERNC void *HeapRealloc(void *Address, uint64_t Size); +EXTERNC void *HeapMalloc(size_t Size); +EXTERNC void *HeapCalloc(size_t n, size_t Size); +EXTERNC void *HeapRealloc(void *Address, size_t Size); EXTERNC void HeapFree(void *Address); #define kmalloc(Size) HeapMalloc(Size) diff --git a/include/pci.hpp b/include/pci.hpp index b6ccbdb..19b0cc6 100644 --- a/include/pci.hpp +++ b/include/pci.hpp @@ -129,7 +129,7 @@ namespace PCI struct DeviceConfig { - uint64_t BaseAddress; + uintptr_t BaseAddress; uint16_t PCISegGroup; uint8_t StartBus; uint8_t EndBus; @@ -143,9 +143,9 @@ namespace PCI public: Vector &GetDevices() { return Devices; } - void EnumerateFunction(uint64_t DeviceAddress, uint64_t Function); - void EnumerateDevice(uint64_t BusAddress, uint64_t Device); - void EnumerateBus(uint64_t BaseAddress, uint64_t Bus); + void EnumerateFunction(uintptr_t DeviceAddress, uint64_t Function); + void EnumerateDevice(uintptr_t BusAddress, uint64_t Device); + void EnumerateBus(uintptr_t BaseAddress, uint64_t Bus); Vector FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF); Vector FindPCIDevice(int VendorID, int DeviceID); diff --git a/include/smp.hpp b/include/smp.hpp index d83fb3e..1dec7a8 100644 --- a/include/smp.hpp +++ b/include/smp.hpp @@ -23,9 +23,9 @@ struct CPUData /** @brief Used by syscall handler */ uint8_t *SystemCallStack; /* gs+0x0 */ /** @brief Used by syscall handler */ - uint64_t TempStack; /* gs+0x8 */ + uintptr_t TempStack; /* gs+0x8 */ /** @brief Used by CPU */ - uint64_t Stack; + uintptr_t Stack; /** @brief CPU ID. */ long ID; /** @brief Local CPU error code. */ diff --git a/include/symbols.hpp b/include/symbols.hpp index a11f81e..3b20707 100644 --- a/include/symbols.hpp +++ b/include/symbols.hpp @@ -8,17 +8,17 @@ namespace SymbolResolver private: struct SymbolTable { - uint64_t Address; + uintptr_t Address; char *FunctionName; }; SymbolTable SymTable[0x10000]; - uint64_t TotalEntries = 0; + uintptr_t TotalEntries = 0; public: - Symbols(uint64_t ImageAddress); + Symbols(uintptr_t ImageAddress); ~Symbols(); - const char *GetSymbolFromAddress(uint64_t Address); + const char *GetSymbolFromAddress(uintptr_t Address); }; } diff --git a/include/syscalls.hpp b/include/syscalls.hpp index 6949faa..6dbd6b3 100644 --- a/include/syscalls.hpp +++ b/include/syscalls.hpp @@ -10,14 +10,14 @@ typedef struct SyscallsFrame uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax; uint64_t InterruptNumber, ErrorCode, rip, cs, rflags, rsp, ss; #elif defined(__i386__) - uint64_t ebp, edi, esi, edx, ecx, ebx, eax; - uint64_t InterruptNumber, ErrorCode, eip, cs, eflags, esp, ss; + uint32_t ebp, edi, esi, edx, ecx, ebx, eax; + uint32_t InterruptNumber, ErrorCode, eip, cs, eflags, esp, ss; #elif defined(__aarch64__) #endif } SyscallsFrame; -uint64_t HandleNativeSyscalls(SyscallsFrame *Frame); -uint64_t HandleLinuxSyscalls(SyscallsFrame *Frame); +uintptr_t HandleNativeSyscalls(SyscallsFrame *Frame); +uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame); /** * @brief Initialize syscalls for the current CPU. (Function is available on x32, x64 & aarch64) diff --git a/include/task.hpp b/include/task.hpp index cdd565f..bc396c7 100644 --- a/include/task.hpp +++ b/include/task.hpp @@ -15,10 +15,10 @@ namespace Tasking { typedef unsigned long IP; - typedef unsigned long IPOffset; + typedef __UINTPTR_TYPE__ IPOffset; typedef unsigned long UPID; typedef unsigned long UTID; - typedef unsigned long Token; + typedef __UINTPTR_TYPE__ Token; enum TaskArchitecture { @@ -165,7 +165,7 @@ namespace Tasking TaskInfo Info; Vector Threads; Vector Children; - HashMap *IPCHandles; + HashMap *IPCHandles; Memory::PageTable4 *PageTable; SymbolResolver::Symbols *ELFSymbolTable; }; diff --git a/include/types.h b/include/types.h index 019cda2..28bd77e 100644 --- a/include/types.h +++ b/include/types.h @@ -46,7 +46,7 @@ typedef __builtin_va_list va_list; #define va_end(v) __builtin_va_end(v) #define va_arg(v, l) __builtin_va_arg(v, l) -#define ALIGN_UP(x, align) ((__typeof__(x))(((uint64_t)(x) + ((align)-1)) & (~((align)-1)))) +#define ALIGN_UP(x, align) ((__typeof__(x))(((uintptr_t)(x) + ((align)-1)) & (~((align)-1)))) #define ALIGN_DOWN(x, align) ((__typeof__(x))((x) & (~((align)-1)))) #define offsetof(type, member) __builtin_offsetof(type, member) @@ -107,6 +107,7 @@ typedef __INT8_TYPE__ int8_t; typedef __INT16_TYPE__ int16_t; typedef __INT32_TYPE__ int32_t; typedef __INT64_TYPE__ int64_t; + typedef __UINT8_TYPE__ uint8_t; typedef __UINT16_TYPE__ uint16_t; typedef __UINT32_TYPE__ uint32_t; @@ -116,6 +117,7 @@ typedef __INT_LEAST8_TYPE__ int_least8_t; typedef __INT_LEAST16_TYPE__ int_least16_t; typedef __INT_LEAST32_TYPE__ int_least32_t; typedef __INT_LEAST64_TYPE__ int_least64_t; + typedef __UINT_LEAST8_TYPE__ uint_least8_t; typedef __UINT_LEAST16_TYPE__ uint_least16_t; typedef __UINT_LEAST32_TYPE__ uint_least32_t; @@ -125,6 +127,7 @@ typedef __INT_FAST8_TYPE__ int_fast8_t; typedef __INT_FAST16_TYPE__ int_fast16_t; typedef __INT_FAST32_TYPE__ int_fast32_t; typedef __INT_FAST64_TYPE__ int_fast64_t; + typedef __UINT_FAST8_TYPE__ uint_fast8_t; typedef __UINT_FAST16_TYPE__ uint_fast16_t; typedef __UINT_FAST32_TYPE__ uint_fast32_t; @@ -138,6 +141,11 @@ typedef __UINTMAX_TYPE__ uintmax_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; typedef __SIZE_TYPE__ size_t; +// typedef __WCHAR_TYPE__ wchar_t; +typedef __WINT_TYPE__ wint_t; +typedef __SIG_ATOMIC_TYPE__ sig_atomic_t; +// TODO: ssize_t +typedef intptr_t ssize_t; #define INT8_MAX __INT8_MAX__ #define INT8_MIN (-INT8_MAX - 1) diff --git a/include/vector.hpp b/include/vector.hpp index 1fbcd55..8e7db0d 100644 --- a/include/vector.hpp +++ b/include/vector.hpp @@ -6,8 +6,8 @@ template class Vector { private: - uint64_t VectorSize = 0; - uint64_t VectorCapacity = 0; + size_t VectorSize = 0; + size_t VectorCapacity = 0; T *VectorBuffer = nullptr; public: @@ -23,7 +23,7 @@ public: VectorBuffer = 0; } - __no_instrument_function Vector(uint64_t Size) + __no_instrument_function Vector(size_t Size) { VectorCapacity = Size; VectorSize = Size; @@ -33,7 +33,7 @@ public: VectorBuffer = new T[Size]; } - __no_instrument_function Vector(uint64_t Size, const T &Initial) + __no_instrument_function Vector(size_t Size, const T &Initial) { VectorSize = Size; VectorCapacity = Size; @@ -41,7 +41,7 @@ public: debug("VECTOR INIT: Vector( %lld %llx )", Size, Initial); #endif VectorBuffer = new T[Size]; - for (uint64_t i = 0; i < Size; i++) + for (size_t i = 0; i < Size; i++) VectorBuffer[i] = Initial; } @@ -53,7 +53,7 @@ public: debug("VECTOR INIT: Vector( )->Size: %lld", VectorSize); #endif VectorBuffer = new T[VectorSize]; - for (uint64_t i = 0; i < VectorSize; i++) + for (size_t i = 0; i < VectorSize; i++) VectorBuffer[i] = Vector.VectorBuffer[i]; } @@ -65,21 +65,21 @@ public: delete[] VectorBuffer; } - __no_instrument_function void remove(uint64_t Position) + __no_instrument_function void remove(size_t Position) { if (Position >= VectorSize) return; memset(&*(VectorBuffer + Position), 0, sizeof(T)); - for (uint64_t i = 0; i < VectorSize - 1; i++) + for (size_t i = 0; i < VectorSize - 1; i++) { *(VectorBuffer + Position + i) = *(VectorBuffer + Position + i + 1); } VectorSize--; } - __no_instrument_function uint64_t capacity() const { return VectorCapacity; } + __no_instrument_function size_t capacity() const { return VectorCapacity; } - __no_instrument_function uint64_t size() const { return VectorSize; } + __no_instrument_function size_t size() const { return VectorSize; } __no_instrument_function bool empty() const; @@ -104,7 +104,7 @@ public: { if (VectorSize <= 1) return; - for (uint64_t i = 0, j = VectorSize - 1; i < j; i++, j--) + for (size_t i = 0, j = VectorSize - 1; i < j; i++, j--) { T c = *(VectorBuffer + i); *(VectorBuffer + i) = *(VectorBuffer + j); @@ -112,7 +112,7 @@ public: } } - __no_instrument_function void reserve(uint64_t Capacity) + __no_instrument_function void reserve(size_t Capacity) { if (VectorBuffer == 0) { @@ -122,25 +122,25 @@ public: #ifdef DEBUG_MEM_ALLOCATION debug("VECTOR ALLOCATION: reverse( %lld )", Capacity); #endif - T *Newbuffer = new T[Capacity]; - uint64_t _Size = Capacity < VectorSize ? Capacity : VectorSize; - for (uint64_t i = 0; i < _Size; i++) - Newbuffer[i] = VectorBuffer[i]; + T *NewBuffer = new T[Capacity]; + size_t _Size = Capacity < VectorSize ? Capacity : VectorSize; + for (size_t i = 0; i < _Size; i++) + NewBuffer[i] = VectorBuffer[i]; VectorCapacity = Capacity; #ifdef DEBUG_MEM_ALLOCATION debug("VECTOR ALLOCATION: reverse( )->Buffer:~%lld", VectorBuffer); #endif delete[] VectorBuffer; - VectorBuffer = Newbuffer; + VectorBuffer = NewBuffer; } - __no_instrument_function void resize(uint64_t Size) + __no_instrument_function void resize(size_t Size) { reserve(Size); VectorSize = Size; } - __no_instrument_function T &operator[](uint64_t Index) { return VectorBuffer[Index]; } + __no_instrument_function T &operator[](size_t Index) { return VectorBuffer[Index]; } __no_instrument_function Vector &operator=(const Vector &Vector) { @@ -151,7 +151,7 @@ public: debug("VECTOR ALLOCATION: operator=( )->Size:%lld", VectorSize); #endif VectorBuffer = new T[VectorSize]; - for (uint64_t i = 0; i < VectorSize; i++) + for (size_t i = 0; i < VectorSize; i++) VectorBuffer[i] = Vector.VectorBuffer[i]; return *this; }