Skip to content

Commit

Permalink
Start to use an unrecognised syscall to trigger snapshotting
Browse files Browse the repository at this point in the history
This replaces use of SIGUSR1 in some cases.
  • Loading branch information
Mark Seaborn committed Jul 9, 2015
1 parent 0a3aed2 commit 2400191
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ptracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ int main(int argc, char **argv) {
regs.orig_rax = -1;
rc = ptrace(PTRACE_SETREGS, pid, 0, &regs);
assert(rc == 0);
} else if (regs.orig_rax == (uintptr_t) -1) {
// Unrecognised syscall: trigger snapshotting.
// TODO: Whitelist syscalls instead of blacklisting this one.
ptracer.Dump();
ptracer.TerminateSubprocess();
break;
}
} else {
ptracer.HandleSyscall(&regs);
Expand Down
9 changes: 2 additions & 7 deletions tests/example_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ static int my_errno;
extern char code_start[], code_end[];
asm("code_start:\n"

// Call getpid()
"movl $39, %eax\n"
"syscall\n"
// Call kill(getpid(), SIGUSR1)
"movl %eax, %edi\n" // arg1: result of getpid()
"movl $10, %esi\n" // arg2: SIGUSR1
"movl $62, %eax\n" // __NR_kill
// Do unhandled syscall -1 to trigger snapshotting
"movq $-1, %rax\n"
"syscall\n"

// Call write()
Expand Down
9 changes: 7 additions & 2 deletions tests/example_prog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <signal.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>


int main(void) {
raise(SIGUSR1);
// Do unhandled syscall -1 to trigger snapshotting.
int rc = syscall(-1);
assert(rc == -1);
assert(errno == ENOSYS);

printf("In example_prog2.c!\n");
return 0;
Expand Down
6 changes: 4 additions & 2 deletions tests/save_restore_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <assert.h>
#include <elf.h>
#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -19,7 +18,10 @@
namespace {

void do_snapshot() {
raise(SIGUSR1);
// Do unhandled syscall -1 to trigger snapshotting.
int rc = syscall(-1);
assert(rc == -1);
assert(errno == ENOSYS);
}

void test_munmap_whole_mapping() {
Expand Down

0 comments on commit 2400191

Please sign in to comment.