mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-28 16:43:09 +00:00
When INVARIANTS is defined make sure that uma_zalloc_arg (and hence
uma_zalloc) is called with exactly one of either M_WAITOK or M_NOWAIT and that it is called with neither M_TRYWAIT or M_DONTWAIT. Print a warning if anything is wrong. Default to M_WAITOK of no flag is given. This is the same test as in malloc(9).
This commit is contained in:
parent
def6489df6
commit
8522511b2a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=117736
@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/proc.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/vmmeter.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_object.h>
|
||||
@ -1320,6 +1321,25 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
|
||||
printf("Allocating one item from %s(%p)\n", zone->uz_name, zone);
|
||||
#endif
|
||||
|
||||
#ifdef INVARIANTS
|
||||
/*
|
||||
* To make sure that WAITOK or NOWAIT is set, but not more than
|
||||
* one, and check against the API botches that are common.
|
||||
* The uma code implies M_WAITOK if M_NOWAIT is not set, so
|
||||
* we default to waiting if none of the flags is set.
|
||||
*/
|
||||
cpu = flags & (M_WAITOK | M_NOWAIT | M_DONTWAIT | M_TRYWAIT);
|
||||
if (cpu != M_NOWAIT && cpu != M_WAITOK) {
|
||||
static struct timeval lasterr;
|
||||
static int curerr, once;
|
||||
if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) {
|
||||
printf("Bad uma_zalloc flags: %x\n", cpu);
|
||||
backtrace();
|
||||
once++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(flags & M_NOWAIT)) {
|
||||
KASSERT(curthread->td_intr_nesting_level == 0,
|
||||
("malloc(M_WAITOK) in interrupt context"));
|
||||
|
Loading…
Reference in New Issue
Block a user