1 #ifndef JEMALLOC_INTERNAL_PAGES_EXTERNS_H
2 #define JEMALLOC_INTERNAL_PAGES_EXTERNS_H
3 
4 /* Page size.  LG_PAGE is determined by the configure script. */
5 #ifdef PAGE_MASK
6 #  undef PAGE_MASK
7 #endif
8 #define PAGE		((size_t)(1U << LG_PAGE))
9 #define PAGE_MASK	((size_t)(PAGE - 1))
10 /* Return the page base address for the page containing address a. */
11 #define PAGE_ADDR2BASE(a)						\
12 	((void *)((uintptr_t)(a) & ~PAGE_MASK))
13 /* Return the smallest pagesize multiple that is >= s. */
14 #define PAGE_CEILING(s)							\
15 	(((s) + PAGE_MASK) & ~PAGE_MASK)
16 
17 /* Huge page size.  LG_HUGEPAGE is determined by the configure script. */
18 #define HUGEPAGE	((size_t)(1U << LG_HUGEPAGE))
19 #define HUGEPAGE_MASK	((size_t)(HUGEPAGE - 1))
20 /* Return the huge page base address for the huge page containing address a. */
21 #define HUGEPAGE_ADDR2BASE(a)						\
22 	((void *)((uintptr_t)(a) & ~HUGEPAGE_MASK))
23 /* Return the smallest pagesize multiple that is >= s. */
24 #define HUGEPAGE_CEILING(s)						\
25 	(((s) + HUGEPAGE_MASK) & ~HUGEPAGE_MASK)
26 
27 /* PAGES_CAN_PURGE_LAZY is defined if lazy purging is supported. */
28 #if defined(_WIN32) || defined(JEMALLOC_PURGE_MADVISE_FREE)
29 #  define PAGES_CAN_PURGE_LAZY
30 #endif
31 /*
32  * PAGES_CAN_PURGE_FORCED is defined if forced purging is supported.
33  *
34  * The only supported way to hard-purge on Windows is to decommit and then
35  * re-commit, but doing so is racy, and if re-commit fails it's a pain to
36  * propagate the "poisoned" memory state.  Since we typically decommit as the
37  * next step after purging on Windows anyway, there's no point in adding such
38  * complexity.
39  */
40 #if !defined(_WIN32) && ((defined(JEMALLOC_PURGE_MADVISE_DONTNEED) && \
41     defined(JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS)) || \
42     defined(JEMALLOC_MAPS_COALESCE))
43 #  define PAGES_CAN_PURGE_FORCED
44 #endif
45 
46 static const bool pages_can_purge_lazy =
47 #ifdef PAGES_CAN_PURGE_LAZY
48     true
49 #else
50     false
51 #endif
52     ;
53 static const bool pages_can_purge_forced =
54 #ifdef PAGES_CAN_PURGE_FORCED
55     true
56 #else
57     false
58 #endif
59     ;
60 
61 void *pages_map(void *addr, size_t size, size_t alignment, bool *commit);
62 void pages_unmap(void *addr, size_t size);
63 bool pages_commit(void *addr, size_t size);
64 bool pages_decommit(void *addr, size_t size);
65 bool pages_purge_lazy(void *addr, size_t size);
66 bool pages_purge_forced(void *addr, size_t size);
67 bool pages_huge(void *addr, size_t size);
68 bool pages_nohuge(void *addr, size_t size);
69 bool pages_boot(void);
70 
71 #endif /* JEMALLOC_INTERNAL_PAGES_EXTERNS_H */
72