mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Refactor filesystem & stl code
This commit is contained in:
@ -173,7 +173,7 @@ typedef volatile _Atomic(int64_t) atomic64_t;
|
||||
typedef volatile _Atomic(void *) atomicptr_t;
|
||||
|
||||
/* Intellisense errors */
|
||||
#ifndef __debug_vscode__
|
||||
#ifndef __vscode__
|
||||
|
||||
static FORCEINLINE int32_t atomic_load32(atomic32_t *src) { return atomic_load_explicit(src, memory_order_relaxed); }
|
||||
static FORCEINLINE void atomic_store32(atomic32_t *dst, int32_t val) { atomic_store_explicit(dst, val, memory_order_relaxed); }
|
||||
|
@ -86,6 +86,6 @@ EXTERNC int __rpmalloc_munmap(void *addr, size_t length)
|
||||
|
||||
EXTERNC int __rpmalloc_posix_madvise(void *addr, size_t length, int advice)
|
||||
{
|
||||
function("%#lx %d %d", addr, length, advice);
|
||||
func("%#lx %d %d", addr, length, advice);
|
||||
return 0;
|
||||
}
|
||||
|
@ -427,7 +427,11 @@ NIF void InitializeMemoryManagement()
|
||||
|
||||
void *malloc(size_t Size)
|
||||
{
|
||||
assert(Size > 0);
|
||||
if (Size == 0)
|
||||
{
|
||||
warn("Attempt to allocate 0 bytes");
|
||||
Size = 16;
|
||||
}
|
||||
|
||||
memdbg("malloc(%d)->[%s]", Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
@ -474,7 +478,11 @@ void *malloc(size_t Size)
|
||||
|
||||
void *calloc(size_t n, size_t Size)
|
||||
{
|
||||
assert(Size > 0);
|
||||
if (Size == 0)
|
||||
{
|
||||
warn("Attempt to allocate 0 bytes");
|
||||
Size = 16;
|
||||
}
|
||||
|
||||
memdbg("calloc(%d, %d)->[%s]", n, Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
@ -521,7 +529,11 @@ void *calloc(size_t n, size_t Size)
|
||||
|
||||
void *realloc(void *Address, size_t Size)
|
||||
{
|
||||
assert(Size > 0);
|
||||
if (Size == 0)
|
||||
{
|
||||
warn("Attempt to allocate 0 bytes");
|
||||
Size = 16;
|
||||
}
|
||||
|
||||
memdbg("realloc(%#lx, %d)->[%s]", Address, Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
@ -568,7 +580,11 @@ void *realloc(void *Address, size_t Size)
|
||||
|
||||
void free(void *Address)
|
||||
{
|
||||
assert(Address != nullptr);
|
||||
if (Address == nullptr)
|
||||
{
|
||||
warn("Attempt to free a null pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
memdbg("free(%#lx)->[%s]", Address,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
@ -609,105 +625,3 @@ void free(void *Address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *operator new(std::size_t Size)
|
||||
{
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("new(%d)->[%s]", Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
void *ret = malloc(Size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *operator new[](std::size_t Size)
|
||||
{
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("new[](%d)->[%s]", Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
void *ret = malloc(Size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *operator new(std::size_t Size, std::align_val_t Alignment)
|
||||
{
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("new(%d, %d)->[%s]", Size, Alignment,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
fixme("operator new with alignment(%#lx) is not implemented",
|
||||
Alignment);
|
||||
|
||||
void *ret = malloc(Size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void operator delete(void *Pointer)
|
||||
{
|
||||
assert(Pointer != nullptr);
|
||||
|
||||
memdbg("delete(%#lx)->[%s]", Pointer,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
free(Pointer);
|
||||
}
|
||||
|
||||
void operator delete[](void *Pointer)
|
||||
{
|
||||
assert(Pointer != nullptr);
|
||||
|
||||
memdbg("delete[](%#lx)->[%s]", Pointer,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
free(Pointer);
|
||||
}
|
||||
|
||||
void operator delete(void *Pointer, long unsigned int Size)
|
||||
{
|
||||
assert(Pointer != nullptr);
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("delete(%#lx, %d)->[%s]",
|
||||
Pointer, Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
free(Pointer);
|
||||
}
|
||||
|
||||
void operator delete[](void *Pointer, long unsigned int Size)
|
||||
{
|
||||
assert(Pointer != nullptr);
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("delete[](%#lx, %d)->[%s]",
|
||||
Pointer, Size,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
free(Pointer);
|
||||
}
|
||||
|
||||
void operator delete(void *Pointer, unsigned long Size, std::align_val_t Alignment)
|
||||
{
|
||||
assert(Pointer != nullptr);
|
||||
assert(Size > 0);
|
||||
|
||||
memdbg("delete(%#lx, %d, %d)->[%s]",
|
||||
Pointer, Size, Alignment,
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
|
||||
fixme("operator delete with alignment is not implemented");
|
||||
|
||||
free(Pointer);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Memory
|
||||
{
|
||||
VirtualAllocation::AllocatedPages VirtualAllocation::RequestPages(size_t Count)
|
||||
{
|
||||
function("%lld", Count);
|
||||
func("%lld", Count);
|
||||
|
||||
void *pAddress = KernelAllocator.RequestPages(Count);
|
||||
memset(pAddress, 0, FROM_PAGES(Count));
|
||||
@ -79,7 +79,7 @@ namespace Memory
|
||||
|
||||
void VirtualAllocation::FreePages(void *Address, size_t Count)
|
||||
{
|
||||
function("%#lx, %lld", Address, Count);
|
||||
func("%#lx, %lld", Address, Count);
|
||||
|
||||
SmartLock(MgrLock);
|
||||
foreach (auto &apl in AllocatedPagesList)
|
||||
@ -110,7 +110,7 @@ namespace Memory
|
||||
|
||||
void VirtualAllocation::MapTo(AllocatedPages ap, PageTable *TargetTable)
|
||||
{
|
||||
function("%#lx, %#lx", ap.VirtualAddress, TargetTable);
|
||||
func("%#lx, %#lx", ap.VirtualAddress, TargetTable);
|
||||
|
||||
Virtual vmm(TargetTable);
|
||||
vmm.Map(ap.VirtualAddress, ap.PhysicalAddress, FROM_PAGES(ap.PageCount), RW | KRsv | G);
|
||||
@ -120,7 +120,7 @@ namespace Memory
|
||||
: BaseAddress(Base), CurrentBase(Base),
|
||||
Table((PageTable *)CPU::PageTable())
|
||||
{
|
||||
function("%#lx", Base);
|
||||
func("%#lx", Base);
|
||||
}
|
||||
|
||||
VirtualAllocation::~VirtualAllocation()
|
||||
|
@ -36,9 +36,9 @@ namespace Memory
|
||||
|
||||
void *VirtualMemoryArea::RequestPages(size_t Count, bool User, bool Protect)
|
||||
{
|
||||
function("%lld, %s, %s", Count,
|
||||
User ? "true" : "false",
|
||||
Protect ? "true" : "false");
|
||||
func("%lld, %s, %s", Count,
|
||||
User ? "true" : "false",
|
||||
Protect ? "true" : "false");
|
||||
|
||||
void *Address = KernelAllocator.RequestPages(Count);
|
||||
memset(Address, 0, Count * PAGE_SIZE);
|
||||
@ -61,7 +61,7 @@ namespace Memory
|
||||
|
||||
void VirtualMemoryArea::FreePages(void *Address, size_t Count)
|
||||
{
|
||||
function("%#lx, %lld", Address, Count);
|
||||
func("%#lx, %lld", Address, Count);
|
||||
|
||||
SmartLock(MgrLock);
|
||||
forItr(itr, AllocatedPagesList)
|
||||
@ -104,7 +104,7 @@ namespace Memory
|
||||
|
||||
void VirtualMemoryArea::DetachAddress(void *Address)
|
||||
{
|
||||
function("%#lx", Address);
|
||||
func("%#lx", Address);
|
||||
|
||||
SmartLock(MgrLock);
|
||||
forItr(itr, AllocatedPagesList)
|
||||
@ -128,12 +128,12 @@ namespace Memory
|
||||
bool Read, bool Write, bool Exec,
|
||||
bool Fixed, bool Shared)
|
||||
{
|
||||
function("%#lx, %lld, %s, %s, %s, %s, %s", Address, Length,
|
||||
Read ? "true" : "false",
|
||||
Write ? "true" : "false",
|
||||
Exec ? "true" : "false",
|
||||
Fixed ? "true" : "false",
|
||||
Shared ? "true" : "false");
|
||||
func("%#lx, %lld, %s, %s, %s, %s, %s", Address, Length,
|
||||
Read ? "true" : "false",
|
||||
Write ? "true" : "false",
|
||||
Exec ? "true" : "false",
|
||||
Fixed ? "true" : "false",
|
||||
Shared ? "true" : "false");
|
||||
|
||||
Virtual vmm(this->Table);
|
||||
|
||||
@ -191,7 +191,7 @@ namespace Memory
|
||||
|
||||
bool VirtualMemoryArea::HandleCoW(uintptr_t PFA)
|
||||
{
|
||||
function("%#lx", PFA);
|
||||
func("%#lx", PFA);
|
||||
Virtual vmm(this->Table);
|
||||
PageTableEntry *pte = vmm.GetPTE((void *)PFA);
|
||||
|
||||
@ -269,7 +269,7 @@ namespace Memory
|
||||
|
||||
void VirtualMemoryArea::Fork(VirtualMemoryArea *Parent)
|
||||
{
|
||||
function("%#lx", Parent);
|
||||
func("%#lx", Parent);
|
||||
assert(Parent);
|
||||
|
||||
debug("parent apl:%d sr:%d [P:%#lx C:%#lx]",
|
||||
|
Reference in New Issue
Block a user