Kernel: Optimize processes' memory management

Memory regions are now stored in a sorted array. This allows O(nlogn)
lookup for address validation instead of the old linear lookup.

Now inserting new regions is also O(nlogn) instead of the old constant
time, but lookups are **much** more frequent
This commit is contained in:
2025-11-12 04:57:44 +02:00
parent c700d9f714
commit dc2a455395
2 changed files with 102 additions and 47 deletions

View File

@@ -270,6 +270,12 @@ namespace Kernel
BAN::StringView file_name;
};
// Adds new region to the sorted array of mapped regions
BAN::ErrorOr<void> add_mapped_region(BAN::UniqPtr<MemoryRegion>&&);
// If address is contained by a region, returns the index of that.
// Otherwise returns the address of the first region after this address.
size_t find_mapped_region(vaddr_t) const;
BAN::ErrorOr<VirtualFileSystem::File> find_file(int fd, const char* path, int flags) const;
BAN::ErrorOr<FileParent> find_parent_file(int fd, const char* path, int flags) const;
BAN::ErrorOr<VirtualFileSystem::File> find_relative_parent(int fd, const char* path) const;