diff options
author | Mateusz Guzik <mjg@FreeBSD.org> | 2018-06-02 22:20:09 +0000 |
---|---|---|
committer | Mateusz Guzik <mjg@FreeBSD.org> | 2018-06-02 22:20:09 +0000 |
commit | 34c538c3560591a3856e85988b0b5eefdde53b0c (patch) | |
tree | c205e182142b9161c772795861a9c1207447563e | |
parent | c51e28f46fb77c7aec14e2a391137b16d95f060c (diff) |
Notes
-rw-r--r-- | sys/contrib/zstd/lib/freebsd/stdlib.h | 1 | ||||
-rw-r--r-- | sys/kern/kern_malloc.c | 2 | ||||
-rw-r--r-- | sys/netinet/libalias/alias_mod.h | 1 | ||||
-rw-r--r-- | sys/sys/malloc.h | 19 |
4 files changed, 22 insertions, 1 deletions
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 <sys/param.h> +#ifdef _KERNEL +#include <sys/systm.h> +#endif #include <sys/queue.h> #include <sys/_lock.h> #include <sys/_mutex.h> @@ -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, |