Skip to content

Commit

Permalink
Switched from mmap to SDL_malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Mar 25, 2024
1 parent 8e0d6a0 commit fe08570
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/binocle/core/binocle_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "binocle_memory.h"
#include "binocle_math.h"
#include <assert.h>
#include <sys/mman.h>
#include "binocle_sdl.h"
//#include <sys/mman.h>

static binocle_memory_state g_memory_state;

Expand Down Expand Up @@ -93,19 +94,18 @@ binocle_memory_block *binocle_memory_allocate(binocle_memory_index size,
protect_offset = page_size + size_rounded_up;
}

binocle_memory_platform_block *block = (binocle_memory_platform_block *)mmap(
0, total_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert(block != MAP_FAILED);
binocle_memory_platform_block *block = (binocle_memory_platform_block *)SDL_malloc(total_size);
assert(block != 0);
block->block.base = (uint8_t *)block + base_offset;
assert(block->block.used == 0);
assert(block->block.prev_arena == 0);

if (flags & (BINOCLE_MEMORY_FLAG_CHECK_UNDERFLOW |
BINOCLE_MEMORY_FLAG_CHECK_OVERFLOW)) {
int Protected =
mprotect((uint8_t *)block + protect_offset, page_size, PROT_NONE);
assert(Protected != -1);
}
// if (flags & (BINOCLE_MEMORY_FLAG_CHECK_UNDERFLOW |
// BINOCLE_MEMORY_FLAG_CHECK_OVERFLOW)) {
// int Protected =
// mprotect((uint8_t *)block + protect_offset, page_size, PROT_NONE);
// assert(Protected != -1);
// }

binocle_memory_platform_block *Sentinel = &g_memory_state.memory_sentinel;
block->next = Sentinel;
Expand Down

0 comments on commit fe08570

Please sign in to comment.