Kernel: All process' memory areas can report their virtual mem usage

This commit is contained in:
Bananymous 2023-09-30 21:15:46 +03:00
parent 38320018dc
commit f88ad7efcd
4 changed files with 9 additions and 0 deletions

View File

@ -124,6 +124,8 @@ namespace LibELF
dprintln("Invalid program header");
return BAN::Error::from_errno(EINVAL);
}
m_virtual_page_count += BAN::Math::div_round_up<size_t>((pheader.p_vaddr % PAGE_SIZE) + pheader.p_memsz, PAGE_SIZE);
}
return {};

View File

@ -33,6 +33,8 @@ namespace LibELF
BAN::ErrorOr<BAN::UniqPtr<LoadableELF>> clone(Kernel::PageTable&);
size_t virtual_page_count() const { return m_virtual_page_count; }
private:
LoadableELF(Kernel::PageTable&, BAN::RefPtr<Kernel::Inode>);
BAN::ErrorOr<void> initialize();
@ -42,6 +44,7 @@ namespace LibELF
Kernel::PageTable& m_page_table;
ElfNativeFileHeader m_file_header;
BAN::Vector<ElfNativeProgramHeader> m_program_headers;
size_t m_virtual_page_count = 0;
};
}

View File

@ -37,6 +37,8 @@ namespace Kernel
size_t size() const { return m_size; }
vaddr_t vaddr() const { return m_vaddr; }
size_t virtual_page_count() const { return BAN::Math::div_round_up<size_t>(m_size, PAGE_SIZE); }
// Returns error if no memory was available
// Returns true if page was succesfully allocated
// Returns false if page was already allocated

View File

@ -83,6 +83,8 @@ namespace Kernel
bool is_userspace() const { return m_is_userspace; }
size_t virtual_page_count() const { return m_stack->size() / PAGE_SIZE; }
#if __enable_sse
void save_sse() { asm volatile("fxsave %0" :: "m"(m_sse_storage)); }
void load_sse() { asm volatile("fxrstor %0" :: "m"(m_sse_storage)); }