int main() { char *p1; char *p2; int i; p1 = Allocate(SIZE, ALIGN); p2 = Allocate(SIZE, ALIGN); printf("p1 = %p, p2 = %p\n", p1, p2); for (i = 0; i < SIZE; i++) p1[i] = "abcdefghijklmnopqrstuvwxyz"[i%26]; memcpy(p2, p1, SIZE); CheckBuf(p2, SIZE); memset(p2, 0, SIZE); CheckZeroBuf(p2, SIZE); /* * Do a memory copy using XMM registers. Verifies that Pin properly * saves and restores XMM registers when the SEGV is intercepted. */ CopyWithXmm(p2, p1, SIZE); CheckBuf(p2, SIZE); return 0; }
static void Handle1(int sig) { SigCount++; CopyWithXmm(SigBuf2, SigBuf1, SIZESMALL); /* * After a while, switch to using a "siginfo" handler. This exercises different * signal emulation paths within Pin. */ if (SigCount > SIGCOUNT/2) { struct sigaction sigact; sigact.sa_sigaction = Handle2; sigact.sa_flags = SA_SIGINFO; sigemptyset(&sigact.sa_mask); if (sigaction(SIGVTALRM, &sigact, 0) == -1) { fprintf(stderr, "Unable to reset handler\n"); exit(1); } } }
static void Handle(int sig, siginfo_t *i, void *vctxt) { ucontext_t *ctxt = vctxt; /* Fix the illegal memory address access */ #if defined(TARGET_IA32) #if defined(TARGET_MAC) ctxt->uc_mcontext->__ss.__eax = (unsigned long)&Glob; #else ctxt->uc_mcontext.gregs[REG_EAX] = (unsigned long)&Glob; #endif #elif defined(TARGET_IA32E) #if defined(TARGET_BSD) ctxt->uc_mcontext.mc_rax = (unsigned long)&Glob; #elif defined(TARGET_MAC) ctxt->uc_mcontext->__ss.__rax = (unsigned long)&Glob; #else ctxt->uc_mcontext.gregs[REG_RAX] = (unsigned long)&Glob; #endif #endif /* This changes the values of the XMM registers */ CopyWithXmm(SigBuf2, SigBuf1, SIZE); }
static void Handle2(int sig, siginfo_t *i, void *v) { SigCount++; CopyWithXmm(SigBuf2, SigBuf1, SIZESMALL); }