refactor(kernel): remove 'foreach' macro

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-03-29 22:43:07 +00:00
parent 93d897e95c
commit 8d71ed0ad5
42 changed files with 112 additions and 119 deletions

View File

@ -571,7 +571,7 @@ namespace v0
__PCIArray *head = nullptr;
__PCIArray *array = nullptr;
foreach (auto &dev in Devices)
for (auto &dev : Devices)
{
/* TODO: optimize memory allocation */
PCI::PCIDevice *dptr = (PCI::PCIDevice *)vma->RequestPages(TO_PAGES(sizeof(PCI::PCIDevice)));

View File

@ -110,7 +110,7 @@ namespace Driver
return;
}
foreach (const auto &drvNode in drvDirNode->Children)
for (const auto &drvNode : drvDirNode->Children)
{
debug("Checking driver %s", drvNode->Path.c_str());
if (!drvNode->IsRegularFile())
@ -169,7 +169,7 @@ namespace Driver
return;
}
foreach (auto &var in Drivers)
for (auto &var : Drivers)
{
DriverObject &Drv = var.second;
@ -224,7 +224,7 @@ namespace Driver
void Manager::UnloadAllDrivers()
{
foreach (auto &var in Drivers)
for (auto &var : Drivers)
{
DriverObject *Drv = &var.second;
if (!Drv->Initialized)
@ -240,7 +240,7 @@ namespace Driver
if (!Drv->InterruptHandlers->empty())
{
foreach (auto &rInt in * Drv->InterruptHandlers)
for (auto &rInt : *Drv->InterruptHandlers)
{
Interrupts::RemoveHandler((void (*)(CPU::TrapFrame *))rInt.second);
}
@ -256,7 +256,7 @@ namespace Driver
if (Drivers.size() == 0)
return;
foreach (auto Driver in Drivers)
for (auto Driver : Drivers)
{
if (!Driver.second.Initialized)
continue;

View File

@ -191,7 +191,7 @@ namespace Interrupts
void *ctx, bool Critical)
{
/* Just log a warning if the interrupt is already registered. */
foreach (auto ev in RegisteredEvents)
for (auto ev : RegisteredEvents)
{
if (ev.IRQ == InterruptNumber &&
ev.Callback == Callback)
@ -279,7 +279,7 @@ namespace Interrupts
{ return a.Priority < b.Priority; });
#ifdef DEBUG
foreach (auto ev in RegisteredEvents)
for (auto ev : RegisteredEvents)
{
void *fct = ev.IsHandler
? ev.Data
@ -421,7 +421,7 @@ namespace Interrupts
Handler::Handler(int InterruptNumber, bool Critical)
{
foreach (auto ev in RegisteredEvents)
for (auto ev : RegisteredEvents)
{
if (ev.IRQ == InterruptNumber)
{

View File

@ -79,7 +79,7 @@ namespace Memory
this->Expanded = Parent->Expanded;
std::list<AllocatedPages> ParentAllocatedPages = Parent->GetAllocatedPages();
foreach (auto Page in ParentAllocatedPages)
for (auto Page : ParentAllocatedPages)
{
void *NewPhysical = vma->RequestPages(1);
debug("Forking address %#lx to %#lx", Page.PhysicalAddress, NewPhysical);

View File

@ -82,7 +82,7 @@ namespace Memory
func("%#lx, %lld", Address, Count);
SmartLock(MgrLock);
foreach (auto &apl in AllocatedPagesList)
for (auto &apl : AllocatedPagesList)
{
if (apl.VirtualAddress != Address)
continue;
@ -128,7 +128,7 @@ namespace Memory
/* No need to remap pages, the page table will be destroyed */
Virtual vmm(this->Table);
foreach (auto ap in AllocatedPagesList)
for (auto ap : AllocatedPagesList)
{
KernelAllocator.FreePages(ap.PhysicalAddress, ap.PageCount);

View File

@ -29,7 +29,7 @@ namespace Memory
{
SmartLock(MgrLock);
uint64_t Size = 0;
foreach (auto ap in AllocatedPagesList)
for (auto ap : AllocatedPagesList)
Size += ap.PageCount;
return FROM_PAGES(Size);
}
@ -214,7 +214,7 @@ namespace Memory
return false;
}
foreach (auto sr in SharedRegions)
for (auto sr : SharedRegions)
{
uintptr_t Start = (uintptr_t)sr.Address;
uintptr_t End = (uintptr_t)sr.Address + sr.Length;
@ -263,7 +263,7 @@ namespace Memory
void VirtualMemoryArea::FreeAllPages()
{
SmartLock(MgrLock);
foreach (auto ap in AllocatedPagesList)
for (auto ap : AllocatedPagesList)
{
KernelAllocator.FreePages(ap.Address, ap.PageCount);
Virtual vmm(this->Table);
@ -287,7 +287,7 @@ namespace Memory
Virtual vmm(this->Table);
SmartLock(MgrLock);
foreach (auto &ap in Parent->AllocatedPagesList)
for (auto &ap : Parent->AllocatedPagesList)
{
if (ap.Protected)
{
@ -339,7 +339,7 @@ namespace Memory
(uintptr_t)ap.Address + (ap.PageCount * PAGE_SIZE));
}
foreach (auto &sr in Parent->SharedRegions)
for (auto &sr : Parent->SharedRegions)
{
MgrLock.Unlock();
void *Address = this->CreateCoWRegion(sr.Address, sr.Length,
@ -496,7 +496,7 @@ namespace Memory
/* No need to remap pages, the page table will be destroyed */
SmartLock(MgrLock);
foreach (auto ap in AllocatedPagesList)
for (auto ap : AllocatedPagesList)
KernelAllocator.FreePages(ap.Address, ap.PageCount);
}
}

View File

@ -489,12 +489,12 @@ nsa void DisplayProcessScreen(CPU::ExceptionFrame *Frame, bool IgnoreReady = tru
bool pRdy = false;
bool showNote = false;
/* FIXME: This is slow */
foreach (auto Process in Plist)
for (auto Process : Plist)
{
bool ignore = true;
if (Process->State == Tasking::Ready && IgnoreReady)
{
foreach (auto Thread in Process->Threads)
for (auto Thread : Process->Threads)
{
if (Thread->State == Tasking::Ready)
continue;
@ -522,7 +522,7 @@ nsa void DisplayProcessScreen(CPU::ExceptionFrame *Frame, bool IgnoreReady = tru
: "none");
bool tRdy = false;
foreach (auto Thread in Process->Threads)
for (auto Thread : Process->Threads)
{
if (Thread->State == Tasking::Ready && IgnoreReady)
{

View File

@ -1079,7 +1079,7 @@ namespace PCI
std::list<PCIDevice> Manager::FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF)
{
std::list<PCIDevice> DeviceFound;
foreach (auto dev in Devices)
for (auto dev : Devices)
{
if (dev.Header->Class == Class &&
dev.Header->Subclass == Subclass &&
@ -1094,7 +1094,7 @@ namespace PCI
std::list<PCIDevice> Manager::FindPCIDevice(uint16_t VendorID, uint16_t DeviceID)
{
std::list<PCIDevice> DeviceFound;
foreach (auto dev in Devices)
for (auto dev : Devices)
{
if (dev.Header->VendorID == VendorID &&
dev.Header->DeviceID == DeviceID)
@ -1109,11 +1109,11 @@ namespace PCI
std::list<uint16_t> DeviceIDs)
{
std::list<PCIDevice> DeviceFound;
foreach (auto dev in Devices)
for (auto dev : Devices)
{
foreach (auto VendorID in VendorIDs)
for (auto VendorID : VendorIDs)
{
foreach (auto DeviceID in DeviceIDs)
for (auto DeviceID : DeviceIDs)
{
if (dev.Header->VendorID == VendorID &&
dev.Header->DeviceID == DeviceID)

View File

@ -25,14 +25,14 @@ namespace Random
__constructor void InitRandomSeed()
{
if (std::strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0)
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0)
{
if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
CPU::x86::AMD::CPUID0x00000007_ECX_0 cpuid;
RDSEEDFlag = cpuid.EBX.RDSEED;
}
else if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
{
CPU::x86::Intel::CPUID0x00000007_0 cpuid;
RDSEEDFlag = cpuid.EBX.RDSEED;
@ -41,14 +41,14 @@ namespace Random
else
RDSEEDFlag = false;
if (std::strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0)
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0)
{
if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
CPU::x86::AMD::CPUID0x00000001 cpuid;
RDRANDFlag = cpuid.ECX.RDRAND;
}
else if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
{
CPU::x86::Intel::CPUID0x00000001 cpuid;
RDRANDFlag = cpuid.ECX.RDRAND;

View File

@ -324,7 +324,7 @@ namespace SymbolResolver
debug("- %#lx", this);
debug("Freeing %d symbols",
this->SymTable.size());
foreach (auto tbl in this->SymTable)
for (auto tbl : this->SymTable)
delete[] tbl.FunctionName;
}
}