mmu: avoid allocation in allocate_intermediate_level()

An allocation causes recursion with the debug allocator.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
x64: switch stacks in general_protection

If we abort() (which is likely), we'll print a backtrace, which will
call safe_load(), which is likely to generate an exception.  Switch stacks
so it generates the exception on a new stack, preserving the old one
for a developer to examine.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Add defer() utility

Following go, add a way to defer a cleanup function until we exit the scope
in any way (return, exceptio, or break):

  FILE* fp = fopen(...);
  auto cleanup = defer([&] { fclose(fp); });

  ...

  // do things with fp in the knowledge that it will be closed when going
  // out of scope.

A deferred operation can be cancelled:

  if (everything_is_good) {
      cleanup.cancel();
      return fp;
  }

Of course, use RAII types where available in preference to defers.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mempool: protect debug allocator against recursion

Sometimes we need to allocate memory during a free (for example when
we clean up page tables, we use rcu_defer(), which allocates memory).

Prevent this recursion with a flag.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>