core: Replace PA_PAGE_SIZE with pa_page_size()

PA_PAGE_SIZE using sysconf() may return a negative number

CID 1137925, CID 1137926, CID 1138485

instead of calling sysconf() directly, add function pa_page_size()
which uses the guestimate 4096 in case sysconf(_SC_PAGE_SIZE) fails

using PA_ONCE to only evaluate sysconf() once
This commit is contained in:
Peter Meerwald-Stadler 2016-08-18 01:06:47 +02:00
parent c99efbffd6
commit 45d9030638
10 changed files with 55 additions and 38 deletions

View file

@ -302,4 +302,17 @@ bool pa_running_in_vm(void);
char *pa_win32_get_toplevel(HANDLE handle);
#endif
size_t pa_page_size(void);
/* Rounds down */
static inline void* PA_PAGE_ALIGN_PTR(const void *p) {
return (void*) (((size_t) p) & ~(pa_page_size() - 1));
}
/* Rounds up */
static inline size_t PA_PAGE_ALIGN(size_t l) {
size_t page_size = pa_page_size();
return (l + page_size - 1) & ~(page_size - 1);
}
#endif