|
CCTLib
Calling-context and data-object attribution library for Intel Pin
|
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <atomic>#include <malloc.h>#include <iostream>#include <unistd.h>#include <assert.h>#include <string.h>#include <sys/mman.h>#include <sstream>#include <functional>#include <unordered_set>#include <vector>#include <unordered_map>#include <algorithm>#include <list>#include "pin.H"#include "pin_isa_compat.H"#include "cctlib.H"#include "shadow_memory.H"#include <xmmintrin.h>#include <immintrin.h>#include "xed-interface.h"#include "xed-common-hdrs.h"#include <google/sparse_hash_map>#include <google/dense_hash_map>
Include dependency graph for zerospy_client.cpp:Go to the source code of this file.
Classes | |
| struct | RedSpyThreadData |
| struct | RedLogs |
| struct | ApproxRedLogs |
| struct | UnrolledConjunction< start, end, incr > |
| struct | UnrolledConjunction< end, end, incr > |
| struct | UnrolledCount< start, end, step > |
| struct | UnrolledCount< end, end, step > |
| union | float_cast |
| union | double_cast |
| struct | UnrolledCountApprox< start, end, step > |
| struct | UnrolledCountApprox< end, end, step > |
| struct | UnrolledConjunctionApprox< start, end, incr > |
| struct | UnrolledConjunctionApprox< end, end, incr > |
| struct | ZeroSpyAnalysis< T, AccessLen, isApprox > |
| struct | LoadSpyInstrument |
| struct | RedundacyData |
| struct | ApproxRedundacyData |
Macros | |
| #define | READ_ACTION (0) |
| #define | WRITE_ACTION (0xff) |
| #define | ONE_BYTE_READ_ACTION (0) |
| #define | TWO_BYTE_READ_ACTION (0) |
| #define | FOUR_BYTE_READ_ACTION (0) |
| #define | EIGHT_BYTE_READ_ACTION (0) |
| #define | ONE_BYTE_WRITE_ACTION (0xff) |
| #define | TWO_BYTE_WRITE_ACTION (0xffff) |
| #define | FOUR_BYTE_WRITE_ACTION (0xffffffff) |
| #define | EIGHT_BYTE_WRITE_ACTION (0xffffffffffffffff) |
| #define | IS_ACCESS_WITHIN_PAGE_BOUNDARY(accessAddr, accessLen) (PAGE_OFFSET((accessAddr)) <= (PAGE_OFFSET_MASK - (accessLen))) |
| #define | MAX_REDUNDANT_CONTEXTS_TO_LOG (1000) |
| #define | THREAD_MAX (1024) |
| #define | ENCODE_ADDRESS_AND_ACCESS_LEN(addr, len) ((addr) | (((uint64_t)(len)) << 48)) |
| #define | DECODE_ADDRESS(addrAndLen) ((addrAndLen) & ((1L << 48) - 1)) |
| #define | DECODE_ACCESS_LEN(addrAndLen) ((addrAndLen) >> 48) |
| #define | MAX_WRITE_OP_LENGTH (512) |
| #define | MAX_WRITE_OPS_IN_INS (8) |
| #define | MAX_REG_LENGTH (64) |
| #define | MAX_SIMD_LENGTH (64) |
| #define | MAX_SIMD_REGS (32) |
| #define | PAGE_MASK (~0xfff) |
| #define | GET_PAGE_INDEX(x) ((x)&PAGE_MASK) |
| #define | CACHELINE_MASK (~63) |
| #define | GET_CACHELINE_INDEX(x) ((x)&CACHELINE_MASK) |
| #define | DECODE_DEAD(data) static_cast<uint8_t>(((data)&0xffffffffffffffff) >> 32) |
| #define | DECODE_KILL(data) (static_cast<ContextHandle_t>((data)&0x00000000ffffffff)) |
| #define | MAKE_CONTEXT_PAIR(a, b) (((uint64_t)(a) << 32) | ((uint64_t)(b))) |
| #define | delta 0.01 |
| #define | HANDLE_CASE(T, ACCESS_LEN, IS_APPROX) INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)ZeroSpyAnalysis<T, (ACCESS_LEN), (IS_APPROX)>::CheckNByteValueAfterRead, IARG_MEMORYOP_EA, memOp, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_INST_PTR, IARG_END) |
| #define | HANDLE_LARGE() INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)CheckAfterLargeRead, IARG_MEMORYOP_EA, memOp, IARG_MEMORYREAD_SIZE, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_END) |
Functions | |
| RedSpyThreadData * | ClientGetTLS (const THREADID threadId) |
| static INT32 | Usage () |
| static void | ClientInit (int argc, char *argv[]) |
| static void | AddToRedTable (uint64_t key, uint16_t value, uint32_t byteMap, uint16_t total, THREADID threadId) __attribute__((always_inline |
| static void | AddToApproximateRedTable (uint64_t key, uint32_t byteMapMan, uint32_t byteMapExp, uint32_t byteMapSign, uint16_t total, uint16_t zeros, uint16_t nums, uint8_t size, THREADID threadId) __attribute__((always_inline |
| static bool | IsOkToApproximate (xed_decoded_inst_t &xedd) |
| static bool | IsFloatInstructionAndOkToApproximate (ADDRINT ip) |
| static bool | IsFloatInstructionOld (ADDRINT ip) |
| static uint16_t | FloatOperandSize (ADDRINT ip, uint32_t oper) |
| static VOID | CheckAfterLargeRead (void *addr, UINT32 accessLen, uint32_t opaqueHandle, THREADID threadId) |
| static int | GetNumReadOperandsInIns (INS ins, UINT32 &whichOp) |
| static bool | INS_IsIgnorable (INS ins) |
| static VOID | InstrumentInsCallback (INS ins, VOID *v, const uint32_t opaqueHandle) |
| VOID | Update (uint32_t bytes, THREADID threadId) |
| static void | InstrumentTrace (TRACE trace, void *f) |
| static bool | RedundacyCompare (const struct RedundacyData &first, const struct RedundacyData &second) |
| static bool | ApproxRedundacyCompare (const struct ApproxRedundacyData &first, const struct ApproxRedundacyData &second) |
| static void | PrintRedundancyPairs (THREADID threadId) |
| static void | PrintApproximationRedundancyPairs (THREADID threadId) |
| static VOID | ImageUnload (IMG img, VOID *v) |
| static VOID | ThreadFiniFunc (THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v) |
| static VOID | FiniFunc (INT32 code, VOID *v) |
| static void | InitThreadData (RedSpyThreadData *tdata) |
| static VOID | ThreadStart (THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v) |
| uint64_t | computeMetricVal (void *metric) |
| int | main (int argc, char *argv[]) |
Variables | |
| struct { | |
| char dummy1 [128] | |
| xed_state_t xedState | |
| char dummy2 [128] | |
| } | LoadSpyGlobals |
| int | redload_metric_id = 0 |
| int | redload_approx_metric_id = 0 |
| uint64_t | grandTotBytesLoad |
| uint64_t | grandTotBytesRedLoad |
| uint64_t | grandTotBytesApproxRedLoad |
| static TLS_KEY | client_tls_key |
| static RedSpyThreadData * | gSingleThreadedTData |
| static FILE * | gTraceFile |
| static const uint64_t | READ_ACCESS_STATES [] = { 0, ONE_BYTE_READ_ACTION, TWO_BYTE_READ_ACTION, 0, FOUR_BYTE_READ_ACTION, 0, 0, 0, EIGHT_BYTE_READ_ACTION} |
| static const uint64_t | WRITE_ACCESS_STATES [] = { 0, ONE_BYTE_WRITE_ACTION, TWO_BYTE_WRITE_ACTION, 0, FOUR_BYTE_WRITE_ACTION, 0, 0, 0, EIGHT_BYTE_WRITE_ACTION} |
| static const uint8_t | OVERFLOW_CHECK [] = { 0, 0, 0, 1, 2, 3, 4, 5, 6} |
| static unordered_map< uint64_t, RedLogs > | RedMap [THREAD_MAX] |
| static unordered_map< uint64_t, ApproxRedLogs > | ApproxRedMap [THREAD_MAX] |
| static void | flatten |
| #define CACHELINE_MASK (~63) |
Definition at line 76 of file zerospy_client.cpp.
| #define DECODE_ACCESS_LEN | ( | addrAndLen | ) | ((addrAndLen) >> 48) |
Definition at line 63 of file zerospy_client.cpp.
| #define DECODE_ADDRESS | ( | addrAndLen | ) | ((addrAndLen) & ((1L << 48) - 1)) |
Definition at line 62 of file zerospy_client.cpp.
Definition at line 90 of file zerospy_client.cpp.
| #define DECODE_KILL | ( | data | ) | (static_cast<ContextHandle_t>((data)&0x00000000ffffffff)) |
Definition at line 91 of file zerospy_client.cpp.
| #define delta 0.01 |
Definition at line 96 of file zerospy_client.cpp.
| #define EIGHT_BYTE_READ_ACTION (0) |
Definition at line 48 of file zerospy_client.cpp.
| #define EIGHT_BYTE_WRITE_ACTION (0xffffffffffffffff) |
Definition at line 53 of file zerospy_client.cpp.
| #define ENCODE_ADDRESS_AND_ACCESS_LEN | ( | addr, | |
| len | |||
| ) | ((addr) | (((uint64_t)(len)) << 48)) |
Definition at line 61 of file zerospy_client.cpp.
| #define FOUR_BYTE_READ_ACTION (0) |
Definition at line 47 of file zerospy_client.cpp.
| #define FOUR_BYTE_WRITE_ACTION (0xffffffff) |
Definition at line 52 of file zerospy_client.cpp.
| #define GET_CACHELINE_INDEX | ( | x | ) | ((x)&CACHELINE_MASK) |
Definition at line 77 of file zerospy_client.cpp.
| #define GET_PAGE_INDEX | ( | x | ) | ((x)&PAGE_MASK) |
Definition at line 74 of file zerospy_client.cpp.
| #define HANDLE_CASE | ( | T, | |
| ACCESS_LEN, | |||
| IS_APPROX | |||
| ) | INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)ZeroSpyAnalysis<T, (ACCESS_LEN), (IS_APPROX)>::CheckNByteValueAfterRead, IARG_MEMORYOP_EA, memOp, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_INST_PTR, IARG_END) |
Definition at line 1094 of file zerospy_client.cpp.
| #define HANDLE_LARGE | ( | ) | INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)CheckAfterLargeRead, IARG_MEMORYOP_EA, memOp, IARG_MEMORYREAD_SIZE, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_END) |
Definition at line 1100 of file zerospy_client.cpp.
| #define IS_ACCESS_WITHIN_PAGE_BOUNDARY | ( | accessAddr, | |
| accessLen | |||
| ) | (PAGE_OFFSET((accessAddr)) <= (PAGE_OFFSET_MASK - (accessLen))) |
Definition at line 55 of file zerospy_client.cpp.
Definition at line 94 of file zerospy_client.cpp.
| #define MAX_REDUNDANT_CONTEXTS_TO_LOG (1000) |
Definition at line 58 of file zerospy_client.cpp.
| #define MAX_REG_LENGTH (64) |
Definition at line 68 of file zerospy_client.cpp.
| #define MAX_SIMD_LENGTH (64) |
Definition at line 70 of file zerospy_client.cpp.
| #define MAX_SIMD_REGS (32) |
Definition at line 71 of file zerospy_client.cpp.
| #define MAX_WRITE_OP_LENGTH (512) |
Definition at line 66 of file zerospy_client.cpp.
| #define MAX_WRITE_OPS_IN_INS (8) |
Definition at line 67 of file zerospy_client.cpp.
| #define ONE_BYTE_READ_ACTION (0) |
Definition at line 45 of file zerospy_client.cpp.
| #define ONE_BYTE_WRITE_ACTION (0xff) |
Definition at line 50 of file zerospy_client.cpp.
| #define PAGE_MASK (~0xfff) |
Definition at line 73 of file zerospy_client.cpp.
| #define READ_ACTION (0) |
Definition at line 42 of file zerospy_client.cpp.
| #define THREAD_MAX (1024) |
Definition at line 59 of file zerospy_client.cpp.
| #define TWO_BYTE_READ_ACTION (0) |
Definition at line 46 of file zerospy_client.cpp.
| #define TWO_BYTE_WRITE_ACTION (0xffff) |
Definition at line 51 of file zerospy_client.cpp.
| #define WRITE_ACTION (0xff) |
Definition at line 43 of file zerospy_client.cpp.
|
inlinestatic |
Definition at line 310 of file zerospy_client.cpp.
References ApproxRedLogs::AccessLen, ApproxRedMap, ApproxRedLogs::fred, ApproxRedLogs::ftot, ApproxRedLogs::redByteMapExp, ApproxRedLogs::redByteMapMan, ApproxRedLogs::redByteMapSign, and ApproxRedLogs::size.
Referenced by ZeroSpyAnalysis< T, AccessLen, isApprox >::if().
|
inlinestatic |
Definition at line 280 of file zerospy_client.cpp.
References RedLogs::fred, RedLogs::red, RedLogs::redByteMap, RedMap, RedLogs::tot, and value.
Referenced by CheckAfterLargeRead(), and ZeroSpyAnalysis< T, AccessLen, isApprox >::if().
|
inlinestatic |
Definition at line 1546 of file zerospy_client.cpp.
References ApproxRedundacyData::all0freq.
Referenced by PrintApproximationRedundancyPairs().
|
inlinestatic |
Definition at line 1026 of file zerospy_client.cpp.
References AddToRedTable(), PinCCTLib::GetContextHandle(), and MAKE_CONTEXT_PAIR.
|
inline |
Definition at line 156 of file zerospy_client.cpp.
References client_tls_key, and gSingleThreadedTData.
Referenced by PrintApproximationRedundancyPairs(), PrintRedundancyPairs(), ThreadFiniFunc(), and Update().
|
static |
Definition at line 175 of file zerospy_client.cpp.
References gTraceFile, LoadSpyGlobals, and MAX_FILE_PATH.
Referenced by main().
| uint64_t computeMetricVal | ( | void * | metric | ) |
Definition at line 1991 of file zerospy_client.cpp.
References PinCCTLib::metric.
|
static |
Definition at line 1938 of file zerospy_client.cpp.
References ApproxRedMap, grandTotBytesApproxRedLoad, grandTotBytesLoad, grandTotBytesRedLoad, gTraceFile, RedMap, and THREAD_MAX.
Referenced by main().
|
inlinestatic |
Definition at line 655 of file zerospy_client.cpp.
References ip, and LoadSpyGlobals.
Referenced by LoadSpyInstrument::if().
|
static |
Definition at line 1105 of file zerospy_client.cpp.
Referenced by InstrumentInsCallback().
|
static |
Definition at line 1895 of file zerospy_client.cpp.
References ApproxRedMap, gTraceFile, PrintApproximationRedundancyPairs(), PrintCacheRedundancy(), PrintPageRedundancy(), PrintRedundancyPairs(), and RedMap.
Referenced by main().
|
static |
Definition at line 1965 of file zerospy_client.cpp.
References RedSpyThreadData::bytesLoad, RedSpyThreadData::numIns, and RedSpyThreadData::sampleFlag.
Referenced by ThreadStart().
|
inlinestatic |
Definition at line 1209 of file zerospy_client.cpp.
References INS_IsMaskedJump().
Referenced by InstrumentInsCallback(), and InstrumentTrace().
|
static |
Definition at line 1233 of file zerospy_client.cpp.
References GetNumReadOperandsInIns(), and INS_IsIgnorable().
Referenced by main().
|
static |
Definition at line 1358 of file zerospy_client.cpp.
References INS_IsIgnorable(), INS_MemoryReadSize(), and Update().
Referenced by main().
|
inlinestatic |
Definition at line 376 of file zerospy_client.cpp.
References ip, IsOkToApproximate(), and LoadSpyGlobals.
|
inlinestatic |
Definition at line 440 of file zerospy_client.cpp.
References ip, and LoadSpyGlobals.
|
inlinestatic |
Definition at line 358 of file zerospy_client.cpp.
Referenced by IsFloatInstructionAndOkToApproximate().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 1997 of file zerospy_client.cpp.
References client_tls_key, ClientInit(), FiniFunc(), gTraceFile, ImageUnload(), InstrumentInsCallback(), InstrumentTrace(), INTERESTING_INS_ALL, PinCCTLib::PinCCTLibInit(), ThreadFiniFunc(), ThreadStart(), and Usage().
|
static |
Definition at line 1663 of file zerospy_client.cpp.
References ApproxRedMap, ApproxRedundacyCompare(), ClientGetTLS(), delta, grandTotBytesApproxRedLoad, gTraceFile, PinCCTLib::HaveSameCallerPrefix(), PinCCTLib::IsSameSourceLine(), MAX_REDUNDANT_CONTEXTS_TO_LOG, and PinCCTLib::PrintFullCallingContext().
Referenced by ImageUnload().
|
static |
Definition at line 1553 of file zerospy_client.cpp.
References ClientGetTLS(), DECODE_DEAD, DECODE_KILL, RedundacyData::frequency, grandTotBytesRedLoad, gTraceFile, PinCCTLib::HaveSameCallerPrefix(), PinCCTLib::IsSameSourceLine(), MAX_REDUNDANT_CONTEXTS_TO_LOG, PinCCTLib::PrintFullCallingContext(), RedMap, and RedundacyCompare().
Referenced by ImageUnload().
|
inlinestatic |
Definition at line 1543 of file zerospy_client.cpp.
References RedundacyData::frequency.
Referenced by PrintRedundancyPairs().
|
static |
Definition at line 1929 of file zerospy_client.cpp.
References ClientGetTLS(), and grandTotBytesLoad.
Referenced by main().
|
static |
Definition at line 1976 of file zerospy_client.cpp.
References ApproxRedMap, client_tls_key, gSingleThreadedTData, InitThreadData(), and RedMap.
Referenced by main().
|
inline |
Definition at line 1346 of file zerospy_client.cpp.
References RedSpyThreadData::bytesLoad, and ClientGetTLS().
Referenced by InstrumentTrace().
|
static |
Definition at line 166 of file zerospy_client.cpp.
Referenced by main().
|
static |
Definition at line 230 of file zerospy_client.cpp.
Referenced by AddToApproximateRedTable(), FiniFunc(), ImageUnload(), PrintApproximationRedundancyPairs(), and ThreadStart().
|
static |
Definition at line 152 of file zerospy_client.cpp.
Referenced by ClientGetTLS(), main(), and ThreadStart().
| char dummy1[128] |
Definition at line 105 of file zerospy_client.cpp.
| char dummy2[128] |
Definition at line 107 of file zerospy_client.cpp.
| void flatten |
Definition at line 279 of file zerospy_client.cpp.
| uint64_t grandTotBytesApproxRedLoad |
Definition at line 147 of file zerospy_client.cpp.
Referenced by FiniFunc(), and PrintApproximationRedundancyPairs().
| uint64_t grandTotBytesLoad |
Definition at line 145 of file zerospy_client.cpp.
Referenced by FiniFunc(), and ThreadFiniFunc().
| uint64_t grandTotBytesRedLoad |
Definition at line 146 of file zerospy_client.cpp.
Referenced by FiniFunc(), and PrintRedundancyPairs().
|
static |
Definition at line 153 of file zerospy_client.cpp.
Referenced by ClientGetTLS(), and ThreadStart().
|
static |
Definition at line 172 of file zerospy_client.cpp.
Referenced by ClientInit(), FiniFunc(), ImageUnload(), main(), PrintApproximationRedundancyPairs(), and PrintRedundancyPairs().
| struct { ... } LoadSpyGlobals |
Referenced by ClientInit(), FloatOperandSize(), IsFloatInstructionAndOkToApproximate(), and IsFloatInstructionOld().
|
static |
Definition at line 207 of file zerospy_client.cpp.
|
static |
Definition at line 205 of file zerospy_client.cpp.
| int redload_approx_metric_id = 0 |
Definition at line 142 of file zerospy_client.cpp.
| int redload_metric_id = 0 |
Definition at line 141 of file zerospy_client.cpp.
|
static |
Definition at line 229 of file zerospy_client.cpp.
Referenced by AddToRedTable(), FiniFunc(), ImageUnload(), PrintRedundancyPairs(), and ThreadStart().
|
static |
Definition at line 206 of file zerospy_client.cpp.
| xed_state_t xedState |
Definition at line 106 of file zerospy_client.cpp.