MCPcopy Create free account
hub / github.com/F-Stack/f-stack / malloc_dbg

Function malloc_dbg

freebsd/kern/kern_malloc.c:500–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498
499#ifdef MALLOC_DEBUG
500static int
501malloc_dbg(caddr_t *vap, size_t *sizep, struct malloc_type *mtp,
502 int flags)
503{
504#ifdef INVARIANTS
505 int indx;
506
507 KASSERT(mtp->ks_version == M_VERSION, ("malloc: bad malloc type version"));
508 /*
509 * Check that exactly one of M_WAITOK or M_NOWAIT is specified.
510 */
511 indx = flags & (M_WAITOK | M_NOWAIT);
512 if (indx != M_NOWAIT && indx != M_WAITOK) {
513 static struct timeval lasterr;
514 static int curerr, once;
515 if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) {
516 printf("Bad malloc flags: %x\n", indx);
517 kdb_backtrace();
518 flags |= M_WAITOK;
519 once++;
520 }
521 }
522#endif
523#ifdef MALLOC_MAKE_FAILURES
524 if ((flags & M_NOWAIT) && (malloc_failure_rate != 0)) {
525 atomic_add_int(&malloc_nowait_count, 1);
526 if ((malloc_nowait_count % malloc_failure_rate) == 0) {
527 atomic_add_int(&malloc_failure_count, 1);
528 *vap = NULL;
529 return (EJUSTRETURN);
530 }
531 }
532#endif
533 if (flags & M_WAITOK) {
534 KASSERT(curthread->td_intr_nesting_level == 0,
535 ("malloc(M_WAITOK) in interrupt context"));
536 if (__predict_false(!THREAD_CAN_SLEEP())) {
537#ifdef EPOCH_TRACE
538 epoch_trace_list(curthread);
539#endif
540 KASSERT(1,
541 ("malloc(M_WAITOK) with sleeping prohibited"));
542 }
543 }
544 KASSERT(curthread->td_critnest == 0 || SCHEDULER_STOPPED(),
545 ("malloc: called with spinlock or critical section held"));
546
547#ifdef DEBUG_MEMGUARD
548 if (memguard_cmp_mtp(mtp, *sizep)) {
549 *vap = memguard_alloc(*sizep, flags);
550 if (*vap != NULL)
551 return (EJUSTRETURN);
552 /* This is unfortunate but should not be fatal. */
553 }
554#endif
555
556#ifdef DEBUG_REDZONE
557 *sizep = redzone_size_ntor(*sizep);

Callers 3

(malloc)Function · 0.85
malloc_domainsetFunction · 0.85
malloc_domainset_execFunction · 0.85

Calls 7

kdb_backtraceFunction · 0.85
epoch_trace_listFunction · 0.85
memguard_cmp_mtpFunction · 0.85
memguard_allocFunction · 0.85
redzone_size_ntorFunction · 0.85
ppsratecheckFunction · 0.70
printfFunction · 0.70

Tested by

no test coverage detected