mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
Don't leak page frames
This commit is contained in:
@@ -11,8 +11,10 @@
|
||||
#include "FDT.hpp"
|
||||
|
||||
// Returns a free page frame in HHDM
|
||||
static uint64_t *get_free_frame() {
|
||||
uint64_t *AddressSpace::get_free_frame() {
|
||||
uint64_t *res = static_cast<uint64_t *>(get4k());
|
||||
if (_taken_pages.get())
|
||||
_taken_pages->push_back(res);
|
||||
assert(res != nullptr);
|
||||
for (int j = 0; j < 512; j++)
|
||||
res[j] = 0;
|
||||
@@ -29,6 +31,9 @@ static inline void invlpg(void *m) {
|
||||
|
||||
AddressSpace::AddressSpace() {
|
||||
PML4 = static_cast<uint64_t *>(get4k());
|
||||
assert(_taken_pages.get() == nullptr);
|
||||
_taken_pages = UniquePtr(new cgistd::vector<uint64_t *>());
|
||||
_taken_pages->push_back(PML4);
|
||||
for (int j = 0; j < 512; j++)
|
||||
PML4[j] = 0;
|
||||
}
|
||||
@@ -36,8 +41,9 @@ AddressSpace::AddressSpace() {
|
||||
AddressSpace::AddressSpace(uint64_t *PML4) : PML4(PML4) {}
|
||||
|
||||
AddressSpace::~AddressSpace() {
|
||||
// TODO:
|
||||
free4k(PML4);
|
||||
if (_taken_pages.get()) {
|
||||
for (const auto &p: *_taken_pages) free4k(p);
|
||||
}
|
||||
}
|
||||
|
||||
void *AddressSpace::virt2real(void *virt) {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "PointersCollection.hpp"
|
||||
#include "mutex.hpp"
|
||||
|
||||
#include <stl/vector>
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#define KERN_V2P(a) ((((uintptr_t) (a) - (uintptr_t) kernel_virt_base) + (uintptr_t) kernel_phys_base))
|
||||
@@ -44,11 +46,15 @@ public:
|
||||
FDT *getFdt();
|
||||
|
||||
private:
|
||||
// Pointer to PML4 in HHDM
|
||||
uint64_t *PML4;
|
||||
uint64_t *get_free_frame();
|
||||
|
||||
UniquePtr<FDT> _fdt;
|
||||
Mutex _fdtLock;
|
||||
// Pointer to PML4 in HHDM
|
||||
uint64_t *PML4;
|
||||
|
||||
UniquePtr<FDT> _fdt;
|
||||
Mutex _fdtLock;
|
||||
|
||||
UniquePtr<cgistd::vector<uint64_t *>> _taken_pages;
|
||||
};
|
||||
|
||||
extern AddressSpace *KERN_AddressSpace;
|
||||
|
||||
Reference in New Issue
Block a user