forked from agl/ctgrind
-
Notifications
You must be signed in to change notification settings - Fork 2
/
valgrind.patch
131 lines (123 loc) · 5 KB
/
valgrind.patch
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
diff -Naur valgrind-3.16.1/coregrind/m_scheduler/scheduler.c valgrind-3.16.1-ctgrind/coregrind/m_scheduler/scheduler.c
--- valgrind-3.16.1/coregrind/m_scheduler/scheduler.c 2020-01-26 16:40:11.000000000 +0100
+++ valgrind-3.16.1-ctgrind/coregrind/m_scheduler/scheduler.c 2020-09-08 14:46:10.129985076 +0200
@@ -1976,6 +1976,16 @@
SET_CLREQ_RETVAL(tid, RUNNING_ON_VALGRIND+1);
break;
+ case VG_USERREQ__GET_POISONFUNCS: {
+ void (**poisonfunc) (void*, SizeT);
+ poisonfunc = (void (**) (void*, SizeT)) arg[1];
+ poisonfunc[0] = VG_(tdict).tool_poison;
+ poisonfunc[1] = VG_(tdict).tool_unpoison;
+ SET_CLREQ_RETVAL( tid, 0 ); /* return value is meaningless */
+
+ break;
+ }
+
case VG_USERREQ__PRINTF: {
const HChar* format = (HChar *)arg[1];
/* JRS 2010-Jan-28: this is DEPRECATED; use the
diff -Naur valgrind-3.16.1/coregrind/m_tooliface.c valgrind-3.16.1-ctgrind/coregrind/m_tooliface.c
--- valgrind-3.16.1/coregrind/m_tooliface.c 2019-12-27 15:51:44.000000000 +0100
+++ valgrind-3.16.1-ctgrind/coregrind/m_tooliface.c 2020-09-08 14:46:10.129985076 +0200
@@ -361,6 +361,15 @@
VG_(tdict).tool_client_redzone_szB = client_malloc_redzone_szB;
}
+void VG_(needs_poison_func)(
+ void (*poison_func) ( void*, SizeT ),
+ void (*unpoison_func) ( void*, SizeT )
+)
+{
+ VG_(tdict).tool_poison = poison_func;
+ VG_(tdict).tool_unpoison = unpoison_func;
+}
+
void VG_(needs_xml_output)( void )
{
VG_(needs).xml_output = True;
diff -Naur valgrind-3.16.1/coregrind/pub_core_tooliface.h valgrind-3.16.1-ctgrind/coregrind/pub_core_tooliface.h
--- valgrind-3.16.1/coregrind/pub_core_tooliface.h 2019-12-27 15:51:44.000000000 +0100
+++ valgrind-3.16.1-ctgrind/coregrind/pub_core_tooliface.h 2020-09-08 14:46:10.133318410 +0200
@@ -169,6 +169,10 @@
SizeT (*tool_malloc_usable_size) (ThreadId, void*);
SizeT tool_client_redzone_szB;
+ // VG_(needs).poison
+ void (*tool_poison) (void*, SizeT);
+ void (*tool_unpoison) (void*, SizeT);
+
// VG_(needs).final_IR_tidy_pass
IRSB* (*tool_final_IR_tidy_pass) (IRSB*);
diff -Naur valgrind-3.16.1/coregrind/vg_preloaded.c valgrind-3.16.1-ctgrind/coregrind/vg_preloaded.c
--- valgrind-3.16.1/coregrind/vg_preloaded.c 2019-12-27 15:51:44.000000000 +0100
+++ valgrind-3.16.1-ctgrind/coregrind/vg_preloaded.c 2020-09-08 14:46:10.133318410 +0200
@@ -372,6 +372,34 @@
# error Unknown OS
#endif
+static int init_done = 0;
+static void (*poison_funcs[2]) (void*, SizeT);
+
+static void init_if_needed() {
+ if (!init_done) {
+ int res;
+ init_done = 1;
+ VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__GET_POISONFUNCS, &poison_funcs,
+ 0, 0, 0, 0);
+ }
+}
+
+void VG_REPLACE_FUNCTION_ZU(libctgrindZdsoZa, ct_poison)(void *ptr, SizeT len);
+void VG_REPLACE_FUNCTION_ZU(libctgrindZdsoZa, ct_poison)(void *ptr, SizeT len) {
+ init_if_needed();
+
+ if (poison_funcs[0])
+ VALGRIND_NON_SIMD_CALL2(poison_funcs[0], ptr, len);
+}
+
+void VG_REPLACE_FUNCTION_ZU(libctgrindZdsoZa, ct_unpoison)(void *ptr, SizeT len);
+void VG_REPLACE_FUNCTION_ZU(libctgrindZdsoZa, ct_unpoison)(void *ptr, SizeT len) {
+ init_if_needed();
+
+ if (poison_funcs[1])
+ VALGRIND_NON_SIMD_CALL2(poison_funcs[1], ptr, len);
+}
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
diff -Naur valgrind-3.16.1/include/valgrind.h valgrind-3.16.1-ctgrind/include/valgrind.h
--- valgrind-3.16.1/include/valgrind.h 2020-06-22 09:41:59.000000000 +0200
+++ valgrind-3.16.1-ctgrind/include/valgrind.h 2020-09-08 14:46:10.136651743 +0200
@@ -6683,6 +6683,9 @@
/* Wine support */
VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
+ /* CTgrind */
+ VG_USERREQ__GET_POISONFUNCS = 0x1602,
+
/* Querying of debug info. */
VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701,
diff -Naur valgrind-3.16.1/memcheck/mc_main.c valgrind-3.16.1-ctgrind/memcheck/mc_main.c
--- valgrind-3.16.1/memcheck/mc_main.c 2019-12-27 15:51:44.000000000 +0100
+++ valgrind-3.16.1-ctgrind/memcheck/mc_main.c 2020-09-08 14:46:10.139985076 +0200
@@ -8085,6 +8085,14 @@
return True;
}
+void MC_(poison) (Word tid, void* addr, SizeT len) {
+ make_mem_undefined((Addr) addr, len);
+}
+
+void MC_(unpoison) (Word tid, void* addr, SizeT len) {
+ MC_(make_mem_defined) ((Addr) addr, len);
+}
+
static void mc_pre_clo_init(void)
{
VG_(details_name) ("Memcheck");
@@ -8125,6 +8133,8 @@
mc_expensive_sanity_check);
VG_(needs_print_stats) (mc_print_stats);
VG_(needs_info_location) (MC_(pp_describe_addr));
+ VG_(needs_poison_func) (MC_(poison),
+ MC_(unpoison));
VG_(needs_malloc_replacement) (MC_(malloc),
MC_(__builtin_new),
MC_(__builtin_vec_new),