From 2a962bfa1ce404726f0037d41098d2a9286f31ae Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 28 Jun 2020 03:51:09 +0200 Subject: Base: PhysM formatting --- src/pOS/arch/x86/kernel/physm.cpp | 12 +++++++++--- src/pOS/include/kernel/physm.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pOS/arch/x86/kernel/physm.cpp b/src/pOS/arch/x86/kernel/physm.cpp index e76116f..b2786bb 100644 --- a/src/pOS/arch/x86/kernel/physm.cpp +++ b/src/pOS/arch/x86/kernel/physm.cpp @@ -25,12 +25,12 @@ int PhysM::print_debug(void) int PhysM::init(void) { total_blocks = MEM_SIZE / BLOCK_SIZE; - memory = memset((void*)(&end), 0, total_blocks * BLOCK_SIZE); + memory = memset(static_cast(&end), 0, total_blocks * BLOCK_SIZE); /* Init memory in blocks */ for(size_t i = 0; i < total_blocks; i++) { - blocks[i].memory = (char*)memory + (i * BLOCK_SIZE); + blocks[i].memory = static_cast(memory) + (i * BLOCK_SIZE); } return 0; @@ -41,6 +41,8 @@ void* PhysM::malloc(size_t size, bool calloc) if(!size) return NULL; + usleep(1); //so id is diff + uint32_t num = size / BLOCK_SIZE; if(num * BLOCK_SIZE < size) num++; @@ -49,6 +51,9 @@ void* PhysM::malloc(size_t size, bool calloc) void* PhysM::realloc(void* oldmem, size_t size) { + if(!oldmem || !size) + return NULL; + void* newmem = malloc(size, false); size_t oldsize = get_blocks_num(oldmem) * BLOCK_SIZE; @@ -102,8 +107,9 @@ int PhysM::free_all_blocks_from(Block& block) Block& PhysM::find_block_from_memory(void* memory_from_block) { - int index = ((char*)memory_from_block - (char*)memory) / BLOCK_SIZE;//calculate block num from addr + uint32_t index = (static_cast(memory_from_block) - static_cast(memory)) / BLOCK_SIZE;//calculate block num from addr //printf("freeing block %d\n", index); + ASSERT(index < total_blocks); return blocks[index]; } diff --git a/src/pOS/include/kernel/physm.h b/src/pOS/include/kernel/physm.h index a833a29..b260172 100644 --- a/src/pOS/include/kernel/physm.h +++ b/src/pOS/include/kernel/physm.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #define BLOCK_SIZE 20 -- cgit 1.4.1