Handle ERESTART* codes better, and make scratch mem and syscallbuf play better together.

This commit changes the way scratch memory state is saved: instead of
always using |scratch_ptr| as the saved scratch area, another level of
indirection is added.  This enables syscallbuf *or* scratch memory to
be recorded.  This invasive change required touching most of the code
that used scratch, so was a convenient excuse to clean up a bit and
add some consistency checks.

Adds two tests, of blocking syscalls and socket usage.