+
+ if (mem == NULL) {
+
+ /*
+ * We get here when the caller told us to block waiting for memory, but
+ * kalloc said there's no memory left to get. Generally, this means there's a
+ * leak or the caller asked for an impossibly large amount of memory. Since there's
+ * nothing left to wait for and the caller isn't expecting a NULL return code, we
+ * just panic. This is less than ideal, but returning NULL doesn't help since the
+ * majority of callers don't check the return value and will just dereference the pointer and
+ * trap anyway. We may as well get a more descriptive message out while we can.
+ */
+
+ panic("_MALLOC: kalloc returned NULL (potential leak), size %llu", (uint64_t) size);
+ }