Augment macros that manipulate td_no_sleeping with assertions to check

underleak and overflow of the counter.

Reviewed by:	kib
This commit is contained in:
Gleb Smirnoff 2019-10-29 17:19:36 +00:00
parent f1eeb689ab
commit 46e6447470

View File

@ -246,8 +246,7 @@ struct thread {
u_char td_lend_user_pri; /* (t) Lend user pri. */
/* Cleared during fork1() */
#define td_startzero td_epochnest
u_char td_epochnest; /* (k) Epoch nest counter. */
#define td_startzero td_flags
int td_flags; /* (t) TDF_* flags. */
int td_inhibitors; /* (t) Why can not run. */
int td_pflags; /* (k) Private thread (TDP_*) flags. */
@ -299,7 +298,7 @@ struct thread {
struct vm_map_entry *td_map_def_user; /* (k) Deferred entries. */
pid_t td_dbg_forked; /* (c) Child pid for debugger. */
u_int td_vp_reserv; /* (k) Count of reserved vnodes. */
int td_no_sleeping; /* (k) Sleeping disabled count. */
u_int td_no_sleeping; /* (k) Sleeping disabled count. */
void *td_su; /* (k) FFS SU private */
sbintime_t td_sleeptimo; /* (t) Sleep timeout. */
int td_rtcgen; /* (s) rtc_generation of abs. sleep */
@ -948,9 +947,15 @@ extern pid_t pid_max;
#define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP)
/* Control whether or not it is safe for curthread to sleep. */
#define THREAD_NO_SLEEPING() ((curthread)->td_no_sleeping++)
#define THREAD_NO_SLEEPING() do { \
curthread->td_no_sleeping++; \
MPASS(curthread->td_no_sleeping > 0); \
} while (0)
#define THREAD_SLEEPING_OK() ((curthread)->td_no_sleeping--)
#define THREAD_SLEEPING_OK() do { \
MPASS(curthread->td_no_sleeping > 0); \
curthread->td_no_sleeping--; \
} while (0)
#define THREAD_CAN_SLEEP() ((curthread)->td_no_sleeping == 0)