127127#include " interception.h"
128128
129129#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>
133135
134136namespace __interception {
135137
@@ -186,40 +188,6 @@ static uptr GetMmapGranularity() {
186188 return si.dwAllocationGranularity ;
187189}
188190
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-
223191static bool ChangeMemoryProtection (
224192 uptr address, uptr size, DWORD *old_protection) {
225193 return ::VirtualProtect ((void *)address, size,
@@ -266,7 +234,7 @@ static bool FunctionHasPadding(uptr address, uptr size) {
266234}
267235
268236static void WritePadding (uptr from, uptr size) {
269- _memset ((void *)from, 0xCC , (size_t )size);
237+ internal_memset ((void *)from, 0xCC , (size_t )size);
270238}
271239
272240static void WriteJumpInstruction (uptr from, uptr target) {
@@ -737,8 +705,8 @@ static bool CopyInstructions(uptr to, uptr from, size_t size) {
737705 size_t instruction_size = GetInstructionSize (from + cursor, &rel_offset);
738706 if (!instruction_size)
739707 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);
742710 if (rel_offset) {
743711# if SANITIZER_WINDOWS64
744712 // 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) {
1027995
1028996 for (DWORD i = 0 ; i < exports->NumberOfNames ; i++) {
1029997 RVAPtr<char > name (module , names[i]);
1030- if (!strcmp (func_name, name)) {
998+ if (!internal_strcmp (func_name, name)) {
1031999 DWORD index = ordinals[i];
10321000 RVAPtr<char > func (module , functions[index]);
10331001
@@ -1039,13 +1007,13 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
10391007 // format: "<module> . <function_name>" that is stored into the
10401008 // exported directory.
10411009 char function_name[256 ];
1042- size_t funtion_name_length = _strlen (func);
1010+ size_t funtion_name_length = internal_strlen (func);
10431011 if (funtion_name_length >= sizeof (function_name) - 1 )
10441012 InterceptionFailed ();
10451013
1046- _memcpy (function_name, func, funtion_name_length);
1014+ internal_memcpy (function_name, func, funtion_name_length);
10471015 function_name[funtion_name_length] = ' \0 ' ;
1048- char * separator = _strchr (function_name, ' .' );
1016+ char * separator = internal_strchr (function_name, ' .' );
10491017 if (!separator)
10501018 InterceptionFailed ();
10511019 *separator = ' \0 ' ;
0 commit comments