diff --git a/sys/contrib/zstd/lib/freebsd/stdlib.h b/sys/contrib/zstd/lib/freebsd/stdlib.h index e20bc72089c5..33c17f023fde 100644 --- a/sys/contrib/zstd/lib/freebsd/stdlib.h +++ b/sys/contrib/zstd/lib/freebsd/stdlib.h @@ -35,6 +35,7 @@ MALLOC_DECLARE(M_ZSTD); +#undef malloc #define malloc(x) (malloc)((x), M_ZSTD, M_WAITOK) #define free(x) (free)((x), M_ZSTD) #define calloc(a, b) (mallocarray)((a), (b), M_ZSTD, M_WAITOK | M_ZERO) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 93664e5476bb..50dfe2507b62 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -549,7 +549,7 @@ malloc_dbg(caddr_t *vap, size_t *sizep, struct malloc_type *mtp, * the allocation fails. */ void * -malloc(size_t size, struct malloc_type *mtp, int flags) +(malloc)(size_t size, struct malloc_type *mtp, int flags) { int indx; caddr_t va; diff --git a/sys/netinet/libalias/alias_mod.h b/sys/netinet/libalias/alias_mod.h index ff2322f9324d..781366b14ef6 100644 --- a/sys/netinet/libalias/alias_mod.h +++ b/sys/netinet/libalias/alias_mod.h @@ -41,6 +41,7 @@ MALLOC_DECLARE(M_ALIAS); /* Use kernel allocator. */ #if defined(_SYS_MALLOC_H_) +#undef malloc #define malloc(x) malloc(x, M_ALIAS, M_NOWAIT|M_ZERO) #define calloc(n, x) mallocarray((n), (x), M_ALIAS, M_NOWAIT|M_ZERO) #define free(x) free(x, M_ALIAS) diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index 09c3be644967..62431510947a 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -38,6 +38,9 @@ #define _SYS_MALLOC_H_ #include +#ifdef _KERNEL +#include +#endif #include #include #include @@ -183,6 +186,22 @@ void free(void *addr, struct malloc_type *type); void free_domain(void *addr, struct malloc_type *type); void *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like __result_use_check __alloc_size(1); +#ifdef _KERNEL +#define malloc(size, type, flags) ({ \ + void *_malloc_item; \ + size_t _size = (size); \ + if (__builtin_constant_p(size) && __builtin_constant_p(flags) &&\ + ((flags) & M_ZERO)) { \ + _malloc_item = malloc(_size, type, (flags) &~ M_ZERO); \ + if (((flags) & M_WAITOK) || _malloc_item != NULL) \ + bzero(_malloc_item, _size); \ + } else { \ + _malloc_item = malloc(_size, type, flags); \ + } \ + _malloc_item; \ +}) +#endif + void *malloc_domain(size_t size, struct malloc_type *type, int domain, int flags) __malloc_like __result_use_check __alloc_size(1); void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type,