+void
+gc_heap_exhausted_error_or_lose (long available, long requested)
+{
+ /* Write basic information before doing anything else: if we don't
+ * call to lisp this is a must, and even if we do there is always the
+ * danger that we bounce back here before the error has been handled,
+ * or indeed even printed.
+ */
+ fprintf(stderr, "Heap exhausted during %s: %ld bytes available, %ld requested.\n",
+ gc_active_p ? "garbage collection" : "allocation", available, requested);
+ if (gc_active_p || (available == 0)) {
+ /* If we are in GC, or totally out of memory there is no way
+ * to sanely transfer control to the lisp-side of things.
+ */
+ print_generation_stats(1);
+ lose("Heap exhausted, game over.");
+ }
+ else {
+ /* FIXME: assert free_pages_lock held */
+ thread_mutex_unlock(&free_pages_lock);
+ funcall2(SymbolFunction(HEAP_EXHAUSTED_ERROR),
+ make_fixnum(available), make_fixnum(requested));
+ lose("HEAP-EXHAUSTED-ERROR fell through");
+ }
+}
+