Skip to content

Commit

Permalink
goto sleep;
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Dec 16, 2020
1 parent bda7d2b commit 1e1df15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/misc/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ struct memory_pool

bool memory_pool_init(struct memory_pool *pool, uint64_t size)
{
uint64_t pa_size = size + (size % PAGE_SIZE);
uint64_t num_pages = size / PAGE_SIZE;
uint64_t remainder = size % PAGE_SIZE;
if (remainder) num_pages++;

pool->used = 0;
pool->size = pa_size;
pool->memory = mmap(0, pa_size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
pool->size = num_pages * PAGE_SIZE;
pool->memory = mmap(0, pool->size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

bool result = pool->memory != MAP_FAILED;
if (result) mprotect(pool->memory + pa_size, PAGE_SIZE, PROT_NONE);
if (result) mprotect(pool->memory + pool->size, PAGE_SIZE, PROT_NONE);

return result;
}
Expand Down
10 changes: 6 additions & 4 deletions src/misc/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ static struct {

bool ts_init(uint64_t size)
{
uint64_t pa_size = size + (size % PAGE_SIZE);
uint64_t num_pages = size / PAGE_SIZE;
uint64_t remainder = size % PAGE_SIZE;
if (remainder) num_pages++;

g_temp_storage.used = 0;
g_temp_storage.size = pa_size;
g_temp_storage.memory = mmap(0, pa_size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
g_temp_storage.size = num_pages * PAGE_SIZE;
g_temp_storage.memory = mmap(0, g_temp_storage.size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

bool result = g_temp_storage.memory != MAP_FAILED;
if (result) mprotect(g_temp_storage.memory + pa_size, PAGE_SIZE, PROT_NONE);
if (result) mprotect(g_temp_storage.memory + g_temp_storage.size, PAGE_SIZE, PROT_NONE);

return result;
}
Expand Down

0 comments on commit 1e1df15

Please sign in to comment.