Kernel, libc: Round up to nearest page-aligned size instead of down
This commit is contained in:
parent
a8eb7a6b66
commit
e90b90c556
@ -5,10 +5,9 @@
|
|||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "memory/VMM.h"
|
#include "memory/VMM.h"
|
||||||
|
#include "misc/utils.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
// FIXME: Round size up instead of down. (use get_blocks_from_size)
|
|
||||||
|
|
||||||
#define MAP_FAIL(errno) 0xffffffffffffff00 | (unsigned char)(errno)
|
#define MAP_FAIL(errno) 0xffffffffffffff00 | (unsigned char)(errno)
|
||||||
|
|
||||||
void sys_mmap(Context* context, void* address, size_t size, int flags)
|
void sys_mmap(Context* context, void* address, size_t size, int flags)
|
||||||
@ -32,7 +31,8 @@ void sys_mmap(Context* context, void* address, size_t size, int flags)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
||||||
void* result = MemoryManager::get_pages_at((uint64_t)address - offset, size / PAGE_SIZE, real_flags);
|
void* result = MemoryManager::get_pages_at((uint64_t)address - offset,
|
||||||
|
Utilities::get_blocks_from_size(PAGE_SIZE, size), real_flags);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
kdbgln("mmap succeeded: %p", result);
|
kdbgln("mmap succeeded: %p", result);
|
||||||
@ -46,8 +46,9 @@ void sys_mmap(Context* context, void* address, size_t size, int flags)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kdbgln("sys_mmap: %ld pages at any address, %s", size / PAGE_SIZE, real_flags & MAP_READ_WRITE ? "rw" : "ro");
|
kdbgln("sys_mmap: %ld pages at any address, %s", Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
||||||
void* result = MemoryManager::get_pages(size / PAGE_SIZE, real_flags);
|
real_flags & MAP_READ_WRITE ? "rw" : "ro");
|
||||||
|
void* result = MemoryManager::get_pages(Utilities::get_blocks_from_size(PAGE_SIZE, size), real_flags);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
kdbgln("mmap succeeded: %p", result);
|
kdbgln("mmap succeeded: %p", result);
|
||||||
@ -85,7 +86,7 @@ void sys_munmap(Context* context, void* address, size_t size)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
||||||
MemoryManager::release_pages((void*)((uint64_t)address - offset), size / PAGE_SIZE);
|
MemoryManager::release_pages((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
||||||
kdbgln("munmap succeeded");
|
kdbgln("munmap succeeded");
|
||||||
context->rax = 0;
|
context->rax = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -17,11 +17,11 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maps size bytes of memory (rounded down to the nearest page-aligned size) into the current process's address
|
/* Maps size bytes of memory (rounded up to the nearest page-aligned size) into the current process's address
|
||||||
* space at addr. If addr is null, the kernel will choose an address. */
|
* space at addr. If addr is null, the kernel will choose an address. */
|
||||||
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset);
|
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset);
|
||||||
|
|
||||||
/* Unmaps size bytes of memory (rounded down to the nearest page-aligned size) at addr from the current process's
|
/* Unmaps size bytes of memory (rounded up to the nearest page-aligned size) at addr from the current process's
|
||||||
* address space. */
|
* address space. */
|
||||||
int munmap(void* addr, size_t size);
|
int munmap(void* addr, size_t size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user