[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT PATCH] lib/ukalloc: per-library stats: Return ENOMEM
The per-library wrapper returns ENOMEM instead of failing in an assertions when the default allocator is not yet initialized. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- This patch depends on patch series: 1574 https://patchwork.unikraft.org/project/unikraft/list/?series=1574 --- lib/ukalloc/libstats.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/ukalloc/libstats.c b/lib/ukalloc/libstats.c index d49d9dcc..b2831ba2 100644 --- a/lib/ukalloc/libstats.c +++ b/lib/ukalloc/libstats.c @@ -45,6 +45,7 @@ #include <uk/print.h> #include <uk/alloc_impl.h> +#include <uk/essentials.h> #include <uk/preempt.h> static inline struct uk_alloc *_uk_alloc_get_actual_default(void) @@ -114,7 +115,11 @@ static void *wrapper_malloc(struct uk_alloc *a, __sz size) __sz alloc_size; void *ret; - UK_ASSERT(p); + if (unlikely(!p)) { + update_stats(&a->_stats, 0, 1, 0, 0); + errno = ENOMEM; + return NULL; + } WATCH_STATS_START(p); ret = uk_do_malloc(p, size); @@ -132,7 +137,11 @@ static void *wrapper_calloc(struct uk_alloc *a, __sz nmemb, __sz size) __sz alloc_size; void *ret; - UK_ASSERT(p); + if (unlikely(!p)) { + update_stats(&a->_stats, 0, 1, 0, 0); + errno = ENOMEM; + return NULL; + } WATCH_STATS_START(p); ret = uk_do_calloc(p, nmemb, size); @@ -151,7 +160,10 @@ static int wrapper_posix_memalign(struct uk_alloc *a, void **memptr, __sz alloc_size; int ret; - UK_ASSERT(p); + if (unlikely(!p)) { + update_stats(&a->_stats, 0, 1, 0, 0); + return ENOMEM; + } WATCH_STATS_START(p); ret = uk_do_posix_memalign(p, memptr, align, size); @@ -168,7 +180,11 @@ static void *wrapper_memalign(struct uk_alloc *a, __sz align, __sz size) __sz alloc_size; void *ret; - UK_ASSERT(p); + if (unlikely(!p)) { + update_stats(&a->_stats, 0, 1, 0, 0); + errno = ENOMEM; + return NULL; + } WATCH_STATS_START(p); ret = uk_do_memalign(p, align, size); @@ -185,7 +201,11 @@ static void *wrapper_realloc(struct uk_alloc *a, void *ptr, __sz size) __sz alloc_size; void *ret; - UK_ASSERT(p); + if (unlikely(!p)) { + update_stats(&a->_stats, 0, 1, 0, 0); + errno = ENOMEM; + return NULL; + } WATCH_STATS_START(p); ret = uk_do_realloc(p, ptr, size); -- 2.20.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |