+ /* Get a block from free list and return it. */
+ b = list_entry (list_pop_front (&d->free_list), struct block, free_elem);
+ a = block_to_arena (b);
+ a->free_cnt--;
+ lock_release (&d->lock);
+ return b;
+}
+
+/* Obtains and returns a new block of at least SIZE bytes.
+ Panics if memory is not available. It is unacceptable for the
+ kernel to panic in normal operation, so this function should
+ only be used during kernel initialization. */
+void *
+xmalloc (size_t size)
+{
+ void *p = malloc (size);
+ if (p == NULL && size > 0)
+ PANIC ("memory exhausted");
+ return p;
+}
+
+/* Allocates and return A times B bytes initialized to zeroes.
+ Returns a null pointer if memory is not available. */
+void *
+calloc (size_t a, size_t b)
+{
+ void *p;
+ size_t size;
+
+ /* Calculate block size and make sure it fits in size_t. */
+ size = a * b;
+ if (size < a || size < b)
+ return NULL;
+
+ /* Allocate and zero memory. */
+ p = malloc (size);
+ if (p != NULL)
+ memset (p, 0, size);
+
+ return p;
+}
+
+/* Allocates and return A times B bytes initialized to zeroes.
+ Panics if memory is not available. It is unacceptable for the
+ kernel to panic in normal operation, so this function should
+ only be used during kernel initialization. */
+void *
+xcalloc (size_t a, size_t b)
+{
+ void *p = calloc (a, b);
+ if (p == NULL && a > 0 && b > 0)
+ PANIC ("memory exhausted");
+ return p;