From 595605d86ff08a4e9781bc4e097c654b619d8003 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 29 Jun 2018 23:11:14 -0400 Subject: [PATCH] freebsd11_network: Properly handle M_NOWAIT in _kernel_malloc. I'm not sure what the comment was about; HEAP_DONT_WAIT_FOR_MALLOC predates the FreeBSD compatibility layer. Potentially fixes some timing issues. --- src/libs/compat/freebsd11_network/compat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/compat/freebsd11_network/compat.c b/src/libs/compat/freebsd11_network/compat.c index 1f62ea7ca8..d717e59290 100644 --- a/src/libs/compat/freebsd11_network/compat.c +++ b/src/libs/compat/freebsd11_network/compat.c @@ -13,6 +13,7 @@ #include #include +#include #include @@ -619,14 +620,13 @@ resource_int_value(const char *name, int unit, const char *resname, void * _kernel_malloc(size_t size, int flags) { - // our kernel malloc() is insufficient, must handle M_WAIT - // According to the FreeBSD kernel malloc man page the allocator is expected // to return power of two aligned addresses for allocations up to one page // size. While it also states that this shouldn't be relied upon, at least // bus_dmamem_alloc expects it and drivers may depend on it as well. void *ptr - = memalign(size >= PAGESIZE ? PAGESIZE : next_power_of_2(size), size); + = memalign_etc(size >= PAGESIZE ? PAGESIZE : next_power_of_2(size), size, + (flags & M_NOWAIT) ? HEAP_DONT_WAIT_FOR_MEMORY : 0); if (ptr == NULL) return NULL;