Add alignment/size assertions to pages_*().
These sanity checks prevent what otherwise might result in failed system calls and unintended fallback execution paths.
This commit is contained in:
parent
7cbcd2e2b7
commit
28078274c4
15
src/pages.c
15
src/pages.c
@ -19,6 +19,9 @@ static bool os_overcommits;
|
|||||||
|
|
||||||
void *
|
void *
|
||||||
pages_map(void *addr, size_t size, bool *commit) {
|
pages_map(void *addr, size_t size, bool *commit) {
|
||||||
|
assert(PAGE_ADDR2BASE(addr) == addr);
|
||||||
|
assert(PAGE_CEILING(size) == size);
|
||||||
|
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
assert(size != 0);
|
assert(size != 0);
|
||||||
@ -63,6 +66,9 @@ pages_map(void *addr, size_t size, bool *commit) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
pages_unmap(void *addr, size_t size) {
|
pages_unmap(void *addr, size_t size) {
|
||||||
|
assert(PAGE_ADDR2BASE(addr) == addr);
|
||||||
|
assert(PAGE_CEILING(size) == size);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (VirtualFree(addr, 0, MEM_RELEASE) == 0)
|
if (VirtualFree(addr, 0, MEM_RELEASE) == 0)
|
||||||
#else
|
#else
|
||||||
@ -122,6 +128,9 @@ pages_trim(void *addr, size_t alloc_size, size_t leadsize, size_t size,
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
pages_commit_impl(void *addr, size_t size, bool commit) {
|
pages_commit_impl(void *addr, size_t size, bool commit) {
|
||||||
|
assert(PAGE_ADDR2BASE(addr) == addr);
|
||||||
|
assert(PAGE_CEILING(size) == size);
|
||||||
|
|
||||||
if (os_overcommits) {
|
if (os_overcommits) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -162,6 +171,9 @@ pages_decommit(void *addr, size_t size) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
pages_purge_lazy(void *addr, size_t size) {
|
pages_purge_lazy(void *addr, size_t size) {
|
||||||
|
assert(PAGE_ADDR2BASE(addr) == addr);
|
||||||
|
assert(PAGE_CEILING(size) == size);
|
||||||
|
|
||||||
if (!pages_can_purge_lazy) {
|
if (!pages_can_purge_lazy) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -181,6 +193,9 @@ pages_purge_lazy(void *addr, size_t size) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
pages_purge_forced(void *addr, size_t size) {
|
pages_purge_forced(void *addr, size_t size) {
|
||||||
|
assert(PAGE_ADDR2BASE(addr) == addr);
|
||||||
|
assert(PAGE_CEILING(size) == size);
|
||||||
|
|
||||||
if (!pages_can_purge_forced) {
|
if (!pages_can_purge_forced) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user