127
127
#include " interception.h"
128
128
129
129
#if SANITIZER_WINDOWS
130
- #include " sanitizer_common/sanitizer_platform.h"
131
- #define WIN32_LEAN_AND_MEAN
132
- #include < windows.h>
130
+ # include " sanitizer_common/sanitizer_common.h"
131
+ # include " sanitizer_common/sanitizer_libc.h"
132
+ # include " sanitizer_common/sanitizer_platform.h"
133
+ # define WIN32_LEAN_AND_MEAN
134
+ # include < windows.h>
133
135
134
136
namespace __interception {
135
137
@@ -186,40 +188,6 @@ static uptr GetMmapGranularity() {
186
188
return si.dwAllocationGranularity ;
187
189
}
188
190
189
- UNUSED static uptr RoundUpTo (uptr size, uptr boundary) {
190
- return (size + boundary - 1 ) & ~(boundary - 1 );
191
- }
192
-
193
- // FIXME: internal_str* and internal_mem* functions should be moved from the
194
- // ASan sources into interception/.
195
-
196
- static size_t _strlen (const char *str) {
197
- const char * p = str;
198
- while (*p != ' \0 ' ) ++p;
199
- return p - str;
200
- }
201
-
202
- static char * _strchr (char * str, char c) {
203
- while (*str) {
204
- if (*str == c)
205
- return str;
206
- ++str;
207
- }
208
- return nullptr ;
209
- }
210
-
211
- static void _memset (void *p, int value, size_t sz) {
212
- for (size_t i = 0 ; i < sz; ++i)
213
- ((char *)p)[i] = (char )value;
214
- }
215
-
216
- static void _memcpy (void *dst, void *src, size_t sz) {
217
- char *dst_c = (char *)dst,
218
- *src_c = (char *)src;
219
- for (size_t i = 0 ; i < sz; ++i)
220
- dst_c[i] = src_c[i];
221
- }
222
-
223
191
static bool ChangeMemoryProtection (
224
192
uptr address, uptr size, DWORD *old_protection) {
225
193
return ::VirtualProtect ((void *)address, size,
@@ -266,7 +234,7 @@ static bool FunctionHasPadding(uptr address, uptr size) {
266
234
}
267
235
268
236
static void WritePadding (uptr from, uptr size) {
269
- _memset ((void *)from, 0xCC , (size_t )size);
237
+ internal_memset ((void *)from, 0xCC , (size_t )size);
270
238
}
271
239
272
240
static void WriteJumpInstruction (uptr from, uptr target) {
@@ -737,8 +705,8 @@ static bool CopyInstructions(uptr to, uptr from, size_t size) {
737
705
size_t instruction_size = GetInstructionSize (from + cursor, &rel_offset);
738
706
if (!instruction_size)
739
707
return false ;
740
- _memcpy ((void *)(to + cursor), (void *)(from + cursor),
741
- (size_t )instruction_size);
708
+ internal_memcpy ((void *)(to + cursor), (void *)(from + cursor),
709
+ (size_t )instruction_size);
742
710
if (rel_offset) {
743
711
# if SANITIZER_WINDOWS64
744
712
// we want to make sure that the new relative offset still fits in 32-bits
@@ -1027,7 +995,7 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
1027
995
1028
996
for (DWORD i = 0 ; i < exports->NumberOfNames ; i++) {
1029
997
RVAPtr<char > name (module , names[i]);
1030
- if (!strcmp (func_name, name)) {
998
+ if (!internal_strcmp (func_name, name)) {
1031
999
DWORD index = ordinals[i];
1032
1000
RVAPtr<char > func (module , functions[index]);
1033
1001
@@ -1039,13 +1007,13 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
1039
1007
// format: "<module> . <function_name>" that is stored into the
1040
1008
// exported directory.
1041
1009
char function_name[256 ];
1042
- size_t funtion_name_length = _strlen (func);
1010
+ size_t funtion_name_length = internal_strlen (func);
1043
1011
if (funtion_name_length >= sizeof (function_name) - 1 )
1044
1012
InterceptionFailed ();
1045
1013
1046
- _memcpy (function_name, func, funtion_name_length);
1014
+ internal_memcpy (function_name, func, funtion_name_length);
1047
1015
function_name[funtion_name_length] = ' \0 ' ;
1048
- char * separator = _strchr (function_name, ' .' );
1016
+ char * separator = internal_strchr (function_name, ' .' );
1049
1017
if (!separator)
1050
1018
InterceptionFailed ();
1051
1019
*separator = ' \0 ' ;
0 commit comments