127
127
#include " interception.h"
128
128
129
129
#if SANITIZER_WINDOWS
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>
130
+ #include " sanitizer_common/sanitizer_platform.h"
131
+ #define WIN32_LEAN_AND_MEAN
132
+ #include < windows.h>
135
133
136
134
namespace __interception {
137
135
@@ -188,6 +186,40 @@ static uptr GetMmapGranularity() {
188
186
return si.dwAllocationGranularity ;
189
187
}
190
188
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
+
191
223
static bool ChangeMemoryProtection (
192
224
uptr address, uptr size, DWORD *old_protection) {
193
225
return ::VirtualProtect ((void *)address, size,
@@ -234,7 +266,7 @@ static bool FunctionHasPadding(uptr address, uptr size) {
234
266
}
235
267
236
268
static void WritePadding (uptr from, uptr size) {
237
- internal_memset ((void *)from, 0xCC , (size_t )size);
269
+ _memset ((void *)from, 0xCC , (size_t )size);
238
270
}
239
271
240
272
static void WriteJumpInstruction (uptr from, uptr target) {
@@ -705,8 +737,8 @@ static bool CopyInstructions(uptr to, uptr from, size_t size) {
705
737
size_t instruction_size = GetInstructionSize (from + cursor, &rel_offset);
706
738
if (!instruction_size)
707
739
return false ;
708
- internal_memcpy ((void *)(to + cursor), (void *)(from + cursor),
709
- (size_t )instruction_size);
740
+ _memcpy ((void *)(to + cursor), (void *)(from + cursor),
741
+ (size_t )instruction_size);
710
742
if (rel_offset) {
711
743
# if SANITIZER_WINDOWS64
712
744
// we want to make sure that the new relative offset still fits in 32-bits
@@ -995,7 +1027,7 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
995
1027
996
1028
for (DWORD i = 0 ; i < exports->NumberOfNames ; i++) {
997
1029
RVAPtr<char > name (module , names[i]);
998
- if (!internal_strcmp (func_name, name)) {
1030
+ if (!strcmp (func_name, name)) {
999
1031
DWORD index = ordinals[i];
1000
1032
RVAPtr<char > func (module , functions[index]);
1001
1033
@@ -1007,13 +1039,13 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
1007
1039
// format: "<module> . <function_name>" that is stored into the
1008
1040
// exported directory.
1009
1041
char function_name[256 ];
1010
- size_t funtion_name_length = internal_strlen (func);
1042
+ size_t funtion_name_length = _strlen (func);
1011
1043
if (funtion_name_length >= sizeof (function_name) - 1 )
1012
1044
InterceptionFailed ();
1013
1045
1014
- internal_memcpy (function_name, func, funtion_name_length);
1046
+ _memcpy (function_name, func, funtion_name_length);
1015
1047
function_name[funtion_name_length] = ' \0 ' ;
1016
- char * separator = internal_strchr (function_name, ' .' );
1048
+ char * separator = _strchr (function_name, ' .' );
1017
1049
if (!separator)
1018
1050
InterceptionFailed ();
1019
1051
*separator = ' \0 ' ;
0 commit comments