mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-09-19 00:53:14 +00:00
.devcontainer
.github
.vscode
Bootloader
Drivers
Kernel
.vscode
arch
core
driver
memory
heap_allocators
brk.cpp
find_bitmap_region.cpp
kstack.cpp
memory.cpp
page_table.cpp
pmi.cpp
pmm.cpp
reserve_essentials.cpp
stack_guard.cpp
va.cpp
vma.cpp
vmm.cpp
panic
time
video
acpi.cpp
console.cpp
cpu.cpp
debugger.cpp
disk.cpp
dsdt.cpp
interrupts_manager.cpp
lock.cpp
pci.cpp
power.cpp
random.cpp
smbios.cpp
smbios.hpp
stack_check.cpp
symbols.cpp
syscalls.cpp
ubsan.c
ubsan.h
drivers
exec
files
include
include_std
kshell
library
network
profiling
storage
subsystem
syscalls
tasking
tests
tty
virtualization
.editorconfig
.gdbinit
.gitignore
ISSUES.md
Makefile
README.md
TODO.md
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_thread.cpp
kernel_vfs.cpp
Userspace
initrd
tools
.editorconfig
.gitignore
.gitlab-ci.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
CREDITS.md
Doxyfile
Fennix Bootloader.code-workspace
Fennix Drivers.code-workspace
Fennix Kernel.code-workspace
Fennix Userspace.code-workspace
Fennix Website.code-workspace
Fennix.code-workspace
LICENSE.md
LICENSES.md
Makefile
README.md
SECURITY.md
STYLE_GUIDE.md
cliff.toml
config.mk
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
/*
|
|
This file is part of Fennix Kernel.
|
|
|
|
Fennix Kernel is free software: you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation, either version 3 of
|
|
the License, or (at your option) any later version.
|
|
|
|
Fennix Kernel is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <memory.hpp>
|
|
|
|
#include "../../kernel.h"
|
|
|
|
namespace Memory
|
|
{
|
|
KernelStackManager::StackAllocation KernelStackManager::DetailedAllocate(size_t Size)
|
|
{
|
|
SmartLock(StackLock);
|
|
Size += 0x10;
|
|
|
|
size_t pagesNeeded = TO_PAGES(Size);
|
|
size_t stackSize = pagesNeeded * PAGE_SIZE;
|
|
|
|
assert((CurrentStackTop - stackSize) > KERNEL_STACK_BASE);
|
|
|
|
void *physicalMemory = KernelAllocator.RequestPages(pagesNeeded);
|
|
void *virtualAddress = (void *)(CurrentStackTop - stackSize);
|
|
|
|
Memory::Virtual vmm(KernelPageTable);
|
|
vmm.Map(virtualAddress, physicalMemory, stackSize, Memory::RW | Memory::G);
|
|
|
|
AllocatedStacks.push_back({physicalMemory, virtualAddress, stackSize});
|
|
CurrentStackTop -= stackSize;
|
|
TotalSize += stackSize;
|
|
return {physicalMemory, virtualAddress, stackSize};
|
|
}
|
|
|
|
void *KernelStackManager::Allocate(size_t Size)
|
|
{
|
|
return this->DetailedAllocate(Size).VirtualAddress;
|
|
}
|
|
|
|
void KernelStackManager::Free(void *Address)
|
|
{
|
|
SmartLock(StackLock);
|
|
|
|
auto it = std::find_if(AllocatedStacks.begin(), AllocatedStacks.end(),
|
|
[Address](const StackAllocation &stack)
|
|
{
|
|
return stack.VirtualAddress == Address;
|
|
});
|
|
|
|
if (it == AllocatedStacks.end())
|
|
return;
|
|
|
|
size_t pagesToFree = TO_PAGES(it->Size);
|
|
Memory::Virtual vmm(KernelPageTable);
|
|
vmm.Unmap(Address, it->Size);
|
|
KernelAllocator.FreePages(it->PhysicalAddress, pagesToFree);
|
|
|
|
TotalSize -= it->Size;
|
|
AllocatedStacks.erase(it);
|
|
}
|
|
|
|
KernelStackManager::KernelStackManager() {}
|
|
KernelStackManager::~KernelStackManager() {}
|
|
}
|