-
Notifications
You must be signed in to change notification settings - Fork 47
/
ins_clear_op.cpp
115 lines (100 loc) · 3.54 KB
/
ins_clear_op.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "ins_clear_op.h"
#include "ins_helper.h"
/* threads context */
extern thread_ctx_t *threads_ctx;
static void PIN_FAST_ANALYSIS_CALL r_clrl4(THREADID tid) {
for (size_t i = 0; i < 8; i++) {
RTAG[DFT_REG_RDX][i] = tag_traits<tag_t>::cleared_val;
RTAG[DFT_REG_RCX][i] = tag_traits<tag_t>::cleared_val;
RTAG[DFT_REG_RBX][i] = tag_traits<tag_t>::cleared_val;
RTAG[DFT_REG_RAX][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clrl2(THREADID tid) {
for (size_t i = 0; i < 8; i++) {
RTAG[DFT_REG_RDX][i] = tag_traits<tag_t>::cleared_val;
RTAG[DFT_REG_RAX][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clrb_l(THREADID tid, uint32_t reg) {
RTAG[reg][0] = tag_traits<tag_t>::cleared_val;
}
static void PIN_FAST_ANALYSIS_CALL r_clrb_u(THREADID tid, uint32_t reg) {
RTAG[reg][1] = tag_traits<tag_t>::cleared_val;
}
static void PIN_FAST_ANALYSIS_CALL r_clrw(THREADID tid, uint32_t reg) {
for (size_t i = 0; i < 2; i++) {
RTAG[reg][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clrl(THREADID tid, uint32_t reg) {
for (size_t i = 0; i < 4; i++) {
RTAG[reg][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clrq(THREADID tid, uint32_t reg) {
for (size_t i = 0; i < 8; i++) {
RTAG[reg][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clrx(THREADID tid, uint32_t reg) {
for (size_t i = 0; i < 16; i++) {
RTAG[reg][i] = tag_traits<tag_t>::cleared_val;
}
}
static void PIN_FAST_ANALYSIS_CALL r_clry(THREADID tid, uint32_t reg) {
for (size_t i = 0; i < 32; i++) {
RTAG[reg][i] = tag_traits<tag_t>::cleared_val;
}
}
void ins_clear_op(INS ins) {
if (INS_OperandIsMemory(ins, OP_0)) {
INT32 n = INS_OperandWidth(ins, OP_0) / 8;
M_CLEAR_N(n);
} else {
REG reg_dst = INS_OperandReg(ins, OP_0);
if (REG_is_gr64(reg_dst)) {
R_CALL(r_clrq, reg_dst);
} else if (REG_is_gr32(reg_dst)) {
R_CALL(r_clrl, reg_dst);
} else if (REG_is_gr16(reg_dst)) {
R_CALL(r_clrw, reg_dst);
} else if (REG_is_xmm(reg_dst)) {
R_CALL(r_clrx, reg_dst);
} else if (REG_is_mm(reg_dst)) {
R_CALL(r_clrq, reg_dst);
} else if (REG_is_ymm(reg_dst)) {
R_CALL(r_clry, reg_dst);
} else {
if (REG_is_Upper8(reg_dst))
R_CALL(r_clrb_u, reg_dst);
else
R_CALL(r_clrb_l, reg_dst);
}
}
}
void ins_clear_op_predicated(INS ins) {
// one byte
if (INS_MemoryOperandCount(ins) == 0) {
REG reg_dst = INS_OperandReg(ins, OP_0);
if (REG_is_Upper8(reg_dst))
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)r_clrb_u,
IARG_FAST_ANALYSIS_CALL, IARG_THREAD_ID,
IARG_UINT32, REG_INDX(reg_dst), IARG_END);
else
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)r_clrb_l,
IARG_FAST_ANALYSIS_CALL, IARG_THREAD_ID,
IARG_UINT32, REG_INDX(reg_dst), IARG_END);
} else
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)tagmap_clrn,
IARG_FAST_ANALYSIS_CALL, IARG_MEMORYWRITE_EA,
IARG_UINT32, 1, IARG_END);
}
void ins_clear_op_l2(INS ins) {
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)r_clrl2, IARG_FAST_ANALYSIS_CALL,
IARG_THREAD_ID, IARG_END);
}
void ins_clear_op_l4(INS ins) {
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)r_clrl4, IARG_FAST_ANALYSIS_CALL,
IARG_THREAD_ID, IARG_END);
}