/*BEGIN_LEGAL Intel Open Source License Copyright (c) 2002-2005 Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_LEGAL */ /* * This file contains an ISA-portable PIN tool for tracing system calls */ #include #if defined(TARGET_MAC) #include #else #include #endif #include "pin.H" FILE * trace; // Print syscall number and arguments VOID SysBefore(VOID * ip, INT32 num, VOID * arg0, VOID * arg1, VOID * arg2, VOID * arg3, VOID * arg4, VOID * arg5) { #if defined(TARGET_IA32) // On ia32, there are only 5 registers for passing system call arguments, // but mmap needs 6. For mmap on ia32, the first argument to the system call // is a pointer to an array of the 6 arguments if (num == SYS_mmap) { VOID ** mmapArgs = static_cast(arg0); arg0 = mmapArgs[0]; arg1 = mmapArgs[1]; arg2 = mmapArgs[2]; arg3 = mmapArgs[3]; arg4 = mmapArgs[4]; arg5 = mmapArgs[5]; } #endif fprintf(trace,"%p: %d(%p, %p, %p, %p, %p, %p)", ip, num, arg0, arg1, arg2, arg3, arg4, arg5); } // Print the return value of the system call VOID SysAfter(VOID * ret) { fprintf(trace,"returns: %p\n", ret); fflush(trace); } // Is called for every instruction and instruments syscalls VOID Instruction(INS ins, VOID *v) { if (INS_IsSyscall(ins)) { // Arguments and syscall number is only available before INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(SysBefore), IARG_INST_PTR, IARG_SYSCALL_NUMBER, IARG_SYSARG_VALUE, 0, IARG_SYSARG_VALUE, 1, IARG_SYSARG_VALUE, 2, IARG_SYSARG_VALUE, 3, IARG_SYSARG_VALUE, 4, IARG_SYSARG_VALUE, 5, IARG_END); // return value only available after INS_InsertCall(ins, IPOINT_AFTER, AFUNPTR(SysAfter), IARG_SYSRET_VALUE, IARG_END); } } VOID Fini(INT32 code, VOID *v) { fprintf(trace,"#eof\n"); fclose(trace); } int main(int argc, char *argv[]) { PIN_Init(argc, argv); trace = fopen("strace.out", "w"); INS_AddInstrumentFunction(Instruction, 0); PIN_AddFiniFunction(Fini, 0); // Never returns PIN_StartProgram(); return 0; }