Make better use of paging::pages

This commit is contained in:
Baptiste Wicht 2016-08-15 17:15:34 +02:00
parent 7b6eb8c049
commit 625f062f22
5 changed files with 7 additions and 18 deletions

View File

@ -15,7 +15,7 @@ void* mmap_phys(size_t phys, size_t size){
auto aligned_phys = phys - offset;
auto real_length = offset + size;
auto pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0) ? 0 : 1;
auto pages = paging::pages(real_length);
// Allocate pages of virtual memory
@ -43,7 +43,7 @@ bool munmap_phys(void* virt_ptr, size_t size){
auto aligned_virt = virt - offset;
auto real_length = offset + size;
auto pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0) ? 0 : 1;
auto pages = paging::pages(real_length);
// Release the virtual memory

View File

@ -40,7 +40,7 @@ size_t array_size(size_t managed_space, size_t block){
uint64_t* create_array(size_t managed_space, size_t block){
auto size = array_size(managed_space, block) * sizeof(uint64_t);
auto pages = size % paging::PAGE_SIZE == 0 ? size / paging::PAGE_SIZE : size / paging::PAGE_SIZE + 1;
auto pages = paging::pages(size);
auto physical_address = current_mmap_entry_position;

View File

@ -361,13 +361,7 @@ bool allocate_user_memory(scheduler::process_t& process, size_t address, size_t
auto left_padding = address - first_page;
auto bytes = left_padding + size;
//Make sure only complete pages are allocated
if(bytes % paging::PAGE_SIZE != 0){
bytes += paging::PAGE_SIZE - (bytes % paging::PAGE_SIZE);
}
auto pages = bytes / paging::PAGE_SIZE;
auto pages = paging::pages(bytes);
//2. Get enough physical memory
auto physical_memory = physical_allocator::allocate(pages);

View File

@ -239,7 +239,7 @@ void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS phys, ACPI_SIZE length){
auto offset = phys % paging::PAGE_SIZE;
auto real_length = offset + length;
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
auto pages = paging::pages(real_length);
auto virt_aligned = virtual_allocator::allocate(pages);
@ -266,7 +266,7 @@ void AcpiOsUnmapMemory(void* virt_raw, ACPI_SIZE length){
auto offset = virt % paging::PAGE_SIZE;
auto real_length = offset + length;
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
auto pages = paging::pages(real_length);
auto virt_aligned = virt - offset;

View File

@ -59,12 +59,7 @@ bool vesa::init(){
auto left_padding = static_cast<uintptr_t>(physical) - first_page;
auto bytes = left_padding + total_size;
//Make sure only complete pages are allocated
if(bytes % paging::PAGE_SIZE != 0){
bytes += paging::PAGE_SIZE - (bytes % paging::PAGE_SIZE); }
auto pages = bytes / paging::PAGE_SIZE;
auto pages = paging::pages(bytes);
auto virt = virtual_allocator::allocate(pages);