1 /******************************************************************************/ 2 #ifdef JEMALLOC_H_TYPES 3 4 /* 5 * Size and alignment of memory chunks that are allocated by the OS's virtual 6 * memory system. 7 */ 8 #ifdef ANDROID_LG_CHUNK_DEFAULT 9 #define LG_CHUNK_DEFAULT ANDROID_LG_CHUNK_DEFAULT 10 #else 11 #define LG_CHUNK_DEFAULT 21 12 #endif 13 14 /* Return the chunk address for allocation address a. */ 15 #define CHUNK_ADDR2BASE(a) \ 16 ((void *)((uintptr_t)(a) & ~chunksize_mask)) 17 18 /* Return the chunk offset of address a. */ 19 #define CHUNK_ADDR2OFFSET(a) \ 20 ((size_t)((uintptr_t)(a) & chunksize_mask)) 21 22 /* Return the smallest chunk multiple that is >= s. */ 23 #define CHUNK_CEILING(s) \ 24 (((s) + chunksize_mask) & ~chunksize_mask) 25 26 #define CHUNK_HOOKS_INITIALIZER { \ 27 NULL, \ 28 NULL, \ 29 NULL, \ 30 NULL, \ 31 NULL, \ 32 NULL, \ 33 NULL \ 34 } 35 36 #endif /* JEMALLOC_H_TYPES */ 37 /******************************************************************************/ 38 #ifdef JEMALLOC_H_STRUCTS 39 40 #endif /* JEMALLOC_H_STRUCTS */ 41 /******************************************************************************/ 42 #ifdef JEMALLOC_H_EXTERNS 43 44 extern size_t opt_lg_chunk; 45 extern const char *opt_dss; 46 47 extern rtree_t chunks_rtree; 48 49 extern size_t chunksize; 50 extern size_t chunksize_mask; /* (chunksize - 1). */ 51 extern size_t chunk_npages; 52 53 extern const chunk_hooks_t chunk_hooks_default; 54 55 chunk_hooks_t chunk_hooks_get(tsdn_t *tsdn, arena_t *arena); 56 chunk_hooks_t chunk_hooks_set(tsdn_t *tsdn, arena_t *arena, 57 const chunk_hooks_t *chunk_hooks); 58 59 bool chunk_register(tsdn_t *tsdn, const void *chunk, 60 const extent_node_t *node); 61 void chunk_deregister(const void *chunk, const extent_node_t *node); 62 void *chunk_alloc_base(size_t size); 63 void *chunk_alloc_cache(tsdn_t *tsdn, arena_t *arena, 64 chunk_hooks_t *chunk_hooks, void *new_addr, size_t size, size_t alignment, 65 size_t *sn, bool *zero, bool *commit, bool dalloc_node); 66 void *chunk_alloc_wrapper(tsdn_t *tsdn, arena_t *arena, 67 chunk_hooks_t *chunk_hooks, void *new_addr, size_t size, size_t alignment, 68 size_t *sn, bool *zero, bool *commit); 69 void chunk_dalloc_cache(tsdn_t *tsdn, arena_t *arena, 70 chunk_hooks_t *chunk_hooks, void *chunk, size_t size, size_t sn, 71 bool committed); 72 void chunk_dalloc_wrapper(tsdn_t *tsdn, arena_t *arena, 73 chunk_hooks_t *chunk_hooks, void *chunk, size_t size, size_t sn, 74 bool zeroed, bool committed); 75 bool chunk_purge_wrapper(tsdn_t *tsdn, arena_t *arena, 76 chunk_hooks_t *chunk_hooks, void *chunk, size_t size, size_t offset, 77 size_t length); 78 bool chunk_boot(void); 79 80 #endif /* JEMALLOC_H_EXTERNS */ 81 /******************************************************************************/ 82 #ifdef JEMALLOC_H_INLINES 83 84 #ifndef JEMALLOC_ENABLE_INLINE 85 extent_node_t *chunk_lookup(const void *chunk, bool dependent); 86 #endif 87 88 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_CHUNK_C_)) 89 JEMALLOC_INLINE extent_node_t * 90 chunk_lookup(const void *ptr, bool dependent) 91 { 92 93 return (rtree_get(&chunks_rtree, (uintptr_t)ptr, dependent)); 94 } 95 #endif 96 97 #endif /* JEMALLOC_H_INLINES */ 98 /******************************************************************************/ 99 100 #include "jemalloc/internal/chunk_dss.h" 101 #include "jemalloc/internal/chunk_mmap.h" 102