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.
This commit is contained in:
Augustin Cavalier 2018-06-29 23:11:14 -04:00
parent da166fc646
commit 595605d86f

View File

@ -13,6 +13,7 @@
#include <KernelExport.h>
#include <image.h>
#include <kernel/heap.h>
#include <util/BitUtils.h>
@ -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;