Convert remote-syscall code into an RAII helper, AutoRemoteSyscalls.

Also rename restore_mem to AutoRestoreMem.