* The definitions of the macros have been pulled directly from jemalloc.h
* and checked for consistency in mem.c.
*
- *\li ISC_MEM_ALIGN(alignment) - use when you need aligned allocation,
- *
- * NOTE: Set the matching flag, when freeing aligned memory allocation.
- *
*\li ISC_MEM_ZERO - fill the memory with zeroes before returning
*/
-#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
-#if __SIZEOF_POINTER__ == 4
-#define ISC_MEM_ALIGN(a) ((int)(ffs((int)(a)) - 1))
-#else
-#define ISC_MEM_ALIGN(a) \
- ((int)(((size_t)(a) < (size_t)INT_MAX) \
- ? ffs((int)(a)) - 1 \
- : ffs((int)(((size_t)(a)) >> 32)) + 31))
-#endif
-#else
-#define ISC_MEM_ALIGN(a) (a & 0)
-#endif
#define ISC_MEM_ZERO ((int)0x40)
#define isc_mem_get(c, s) isc__mem_get((c), (s), 0 _ISC_MEM_FILELINE)
*/
#ifdef JEMALLOC_API_SUPPORTED
RUNTIME_CHECK(ISC_MEM_ZERO == MALLOCX_ZERO);
- RUNTIME_CHECK(ISC_MEM_ALIGN(0) == MALLOCX_ALIGN(0));
- RUNTIME_CHECK(ISC_MEM_ALIGN(sizeof(void *)) ==
- MALLOCX_ALIGN(sizeof(void *)));
#endif /* JEMALLOC_API_SUPPORTED */
isc_mutex_init(&contextslock);
REQUIRE(ctxp != NULL && *ctxp == NULL);
- ctx = mallocx(sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline()));
+ ctx = malloc(sizeof(*ctx));
INSIST(ctx != NULL);
*ctx = (isc_mem_t){
if (ctx->checkfree) {
INSIST(atomic_load(&ctx->inuse) == 0);
}
- sdallocx(ctx, sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline()));
+ free(ctx);
}
void
isc_mempool_destroy(&mp1);
}
-#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
-/* aligned memory system tests */
-ISC_RUN_TEST_IMPL(isc_mem_get_align) {
- isc_mem_t *mctx2 = NULL;
- void *ptr;
- size_t alignment;
- uintptr_t aligned;
-
- /* Check different alignment sizes up to the page size */
- for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) {
- size_t size = alignment / 2 - 1;
- ptr = isc_mem_getx(mctx, size, ISC_MEM_ALIGN(alignment));
-
- /* Check if the pointer is properly aligned */
- aligned = (((uintptr_t)ptr / alignment) * alignment);
- assert_ptr_equal(aligned, (uintptr_t)ptr);
-
- /* Check if we can resize to <alignment, 2*alignment> range */
- ptr = isc_mem_regetx(mctx, ptr, size, size * 2 + alignment,
- ISC_MEM_ALIGN(alignment));
-
- /* Check if the pointer is still properly aligned */
- aligned = (((uintptr_t)ptr / alignment) * alignment);
- assert_ptr_equal(aligned, (uintptr_t)ptr);
-
- isc_mem_putx(mctx, ptr, size * 2 + alignment,
- ISC_MEM_ALIGN(alignment));
-
- /* Check whether isc_mem_putanddetach_detach() also works */
- isc_mem_create(&mctx2);
- ptr = isc_mem_getx(mctx2, size, ISC_MEM_ALIGN(alignment));
- isc_mem_putanddetachx(&mctx2, ptr, size,
- ISC_MEM_ALIGN(alignment));
- }
-}
-
-/* aligned memory system tests */
-ISC_RUN_TEST_IMPL(isc_mem_allocate_align) {
- void *ptr;
- size_t alignment;
- uintptr_t aligned;
-
- /* Check different alignment sizes up to the page size */
- for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) {
- size_t size = alignment / 2 - 1;
- ptr = isc_mem_allocatex(mctx, size, ISC_MEM_ALIGN(alignment));
-
- /* Check if the pointer is properly aligned */
- aligned = (((uintptr_t)ptr / alignment) * alignment);
- assert_ptr_equal(aligned, (uintptr_t)ptr);
-
- /* Check if we can resize to <alignment, 2*alignment> range */
- ptr = isc_mem_reallocatex(mctx, ptr, size * 2 + alignment,
- ISC_MEM_ALIGN(alignment));
-
- /* Check if the pointer is still properly aligned */
- aligned = (((uintptr_t)ptr / alignment) * alignment);
- assert_ptr_equal(aligned, (uintptr_t)ptr);
-
- isc_mem_freex(mctx, ptr, ISC_MEM_ALIGN(alignment));
- }
-}
-#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
-
/* zeroed memory system tests */
ISC_RUN_TEST_IMPL(isc_mem_get_zero) {
uint8_t *ptr;
ISC_TEST_LIST_START
ISC_TEST_ENTRY(isc_mem_get)
-#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
-ISC_TEST_ENTRY(isc_mem_get_align)
-ISC_TEST_ENTRY(isc_mem_allocate_align)
-#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
ISC_TEST_ENTRY(isc_mem_get_zero)
ISC_TEST_ENTRY(isc_mem_allocate_zero)
ISC_TEST_ENTRY(isc_mem_inuse)