2018-09-02 11:33:27 +05:30
|
|
|
#ifndef PAGES_H
|
|
|
|
#define PAGES_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2019-03-26 00:24:22 +05:30
|
|
|
#include <stdint.h>
|
2018-09-02 11:33:27 +05:30
|
|
|
|
2022-01-17 01:11:46 +05:30
|
|
|
#include "util.h"
|
|
|
|
|
2018-09-02 11:33:27 +05:30
|
|
|
#define PAGE_SHIFT 12
|
2018-12-05 12:37:05 +05:30
|
|
|
#ifndef PAGE_SIZE
|
2018-09-02 11:33:27 +05:30
|
|
|
#define PAGE_SIZE ((size_t)1 << PAGE_SHIFT)
|
2018-12-05 12:37:05 +05:30
|
|
|
#endif
|
2022-01-17 01:11:46 +05:30
|
|
|
|
2019-03-23 08:47:26 +05:30
|
|
|
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name);
|
2019-03-24 07:59:04 +05:30
|
|
|
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size, const char *name);
|
2018-09-02 11:33:27 +05:30
|
|
|
void deallocate_pages(void *usable, size_t usable_size, size_t guard_size);
|
|
|
|
|
2022-01-17 03:27:22 +05:30
|
|
|
static inline size_t page_align(size_t size) {
|
|
|
|
return align(size, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:24:22 +05:30
|
|
|
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 11:33:27 +05:30
|
|
|
#endif
|