#define MALLOCX_ZERO ((int)0x40)
#define MALLOCX_ZERO_GET(flags) ((bool)(flags & MALLOCX_ZERO))
+#if defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE)
+
+#ifdef HAVE_MALLOC_SIZE
+
+#include <malloc/malloc.h>
+
+static inline size_t
+sallocx(void *ptr, int flags ISC_ATTR_UNUSED) {
+ return malloc_size(ptr);
+}
+
+#elif HAVE_MALLOC_USABLE_SIZE
+
+#ifdef __DragonFly__
+/*
+ * On DragonFly BSD 'man 3 malloc' advises us to include the following
+ * header to have access to malloc_usable_size().
+ */
+#include <malloc_np.h>
+#else
+#include <malloc.h>
+#endif
+
+static inline size_t
+sallocx(void *ptr, int flags ISC_ATTR_UNUSED) {
+ return malloc_usable_size(ptr);
+}
+
+#endif /* HAVE_MALLOC_SIZE */
+
+static inline void *
+mallocx(size_t size, int flags) {
+ void *ptr = malloc(size);
+ INSIST(ptr != NULL);
+
+ if ((flags & MALLOCX_ZERO) != 0) {
+ memset(ptr, 0, size);
+ }
+
+ return ptr;
+}
+
+static inline void
+sdallocx(void *ptr, size_t size ISC_ATTR_UNUSED, int flags ISC_ATTR_UNUSED) {
+ free(ptr);
+}
+
+static inline void *
+rallocx(void *ptr, size_t size, int flags) {
+ REQUIRE(size != 0);
+ REQUIRE((flags & MALLOCX_ZERO) == 0);
+
+ ptr = realloc(ptr, size);
+ INSIST(ptr != NULL);
+
+ return ptr;
+}
+
+#else
+
typedef union {
size_t size;
max_align_t __alignment;
return ptr;
}
+#endif /* defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE) */
+
#endif /* !defined(HAVE_JEMALLOC) */
DELETE_TRACE(ctx, old_ptr, old_size, func, file, line);
mem_putstats(ctx, old_size);
+ ADJUST_ZERO_ALLOCATION_SIZE(new_size);
+
+#ifdef HAVE_JEMALLOC
new_ptr = mem_realloc(ctx, old_ptr, new_size, flags);
+#else
+ new_ptr = mem_realloc(ctx, old_ptr, new_size,
+ flags & ~ISC__MEM_ZERO);
+
+ if ((flags & ISC__MEM_ZERO) != 0) {
+ if (new_size > old_size) {
+ memset((uint8_t *)new_ptr + old_size, 0,
+ new_size - old_size);
+ }
+ }
+#endif
mem_getstats(ctx, new_size);
ADD_TRACE(ctx, new_ptr, new_size, func, file, line);
endif
endif
+foreach fn : [
+ 'malloc_usable_size',
+]
+ if cc.has_function(
+ fn,
+ prefix: '#include <malloc.h>',
+ args: sys_defines,
+ dependencies: thread_dep,
+ )
+ config.set('HAVE_@0@'.format(fn.to_upper()), 1)
+ endif
+endforeach
+
+foreach fn : [
+ 'malloc_size',
+]
+ if cc.has_function(
+ fn,
+ prefix: '#include <malloc/malloc.h>',
+ args: sys_defines,
+ dependencies: thread_dep,
+ )
+ config.set('HAVE_@0@'.format(fn.to_upper()), 1)
+ endif
+endforeach
+
## dnstap
dnstap_dep = null_dep # Will be filled later