2018-09-02 02:03:27 -04:00
|
|
|
#ifndef PAGES_H
|
|
|
|
#define PAGES_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2019-03-25 14:54:22 -04:00
|
|
|
#include <stdint.h>
|
2018-09-02 02:03:27 -04:00
|
|
|
|
|
|
|
#define PAGE_SHIFT 12
|
2018-12-05 02:07:05 -05:00
|
|
|
#ifndef PAGE_SIZE
|
2018-09-02 02:03:27 -04:00
|
|
|
#define PAGE_SIZE ((size_t)1 << PAGE_SHIFT)
|
2018-12-05 02:07:05 -05:00
|
|
|
#endif
|
|
|
|
#define PAGE_CEILING(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
|
2018-09-02 02:03:27 -04:00
|
|
|
|
2019-03-22 23:17:26 -04:00
|
|
|
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name);
|
2019-03-23 22:29:04 -04:00
|
|
|
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size, const char *name);
|
2018-09-02 02:03:27 -04:00
|
|
|
void deallocate_pages(void *usable, size_t usable_size, size_t guard_size);
|
|
|
|
|
2019-03-25 14:54:22 -04:00
|
|
|
static inline size_t hash_page(const void *p) {
|
|
|
|
uintptr_t u = (uintptr_t)p >> PAGE_SHIFT;
|
|
|
|
size_t sum = u;
|
|
|
|
sum = (sum << 7) - sum + (u >> 16);
|
|
|
|
sum = (sum << 7) - sum + (u >> 32);
|
|
|
|
sum = (sum << 7) - sum + (u >> 48);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2018-09-02 02:03:27 -04:00
|
|
|
#endif
|