-/* $OpenBSD: kern_malloc.c,v 1.146 2021/05/16 15:10:20 deraadt Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.147 2022/05/04 21:24:33 bluhm Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
if (size > 65535 * PAGE_SIZE) {
if (flags & M_CANFAIL) {
#ifndef SMALL_KERNEL
- /* XXX lock */
if (ratecheck(&malloc_lasterr, &malloc_errintvl))
printf("malloc(): allocation too large, "
"type = %d, size = %lu\n", type, size);
-/* $OpenBSD: kern_time.c,v 1.154 2021/06/18 15:59:14 cheloha Exp $ */
+/* $OpenBSD: kern_time.c,v 1.155 2022/05/04 21:24:33 bluhm Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
int
ratecheck(struct timeval *lasttime, const struct timeval *mininterval)
{
+ static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH);
struct timeval tv, delta;
int rv = 0;
getmicrouptime(&tv);
+ mtx_enter(&mtx);
timersub(&tv, lasttime, &delta);
/*
*lasttime = tv;
rv = 1;
}
+ mtx_leave(&mtx);
return (rv);
}
int
ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
{
+ static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH);
struct timeval tv, delta;
int rv;
microuptime(&tv);
+ mtx_enter(&mtx);
timersub(&tv, lasttime, &delta);
/*
else
rv = 0;
-#if 1 /*DIAGNOSTIC?*/
/* be careful about wrap-around */
if (*curpps + 1 > *curpps)
*curpps = *curpps + 1;
-#else
- /*
- * assume that there's not too many calls to this function.
- * not sure if the assumption holds, as it depends on *caller's*
- * behavior, not the behavior of this function.
- * IMHO it is wrong to make assumption on the caller's behavior,
- * so the above #if is #if 1, not #ifdef DIAGNOSTIC.
- */
- *curpps = *curpps + 1;
-#endif
+
+ mtx_leave(&mtx);
return (rv);
}