Skip to content

Commit 46fe36a

Browse files
committed
Revert "[compiler-rt] Remove duplicates of sanitizer_common functions"
This works for MinGW, but the MSVC linker apparently doens't pull in those symbols. Reverting for now since I won't be able to reproduce it today. https://lab.llvm.org/buildbot/#/builders/107/builds/2337 This reverts commit 9df92cb.
1 parent 034f2b3 commit 46fe36a

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

compiler-rt/lib/interception/interception_win.cpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,9 @@
127127
#include "interception.h"
128128

129129
#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>
135133

136134
namespace __interception {
137135

@@ -188,6 +186,40 @@ static uptr GetMmapGranularity() {
188186
return si.dwAllocationGranularity;
189187
}
190188

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+
191223
static bool ChangeMemoryProtection(
192224
uptr address, uptr size, DWORD *old_protection) {
193225
return ::VirtualProtect((void*)address, size,
@@ -234,7 +266,7 @@ static bool FunctionHasPadding(uptr address, uptr size) {
234266
}
235267

236268
static void WritePadding(uptr from, uptr size) {
237-
internal_memset((void *)from, 0xCC, (size_t)size);
269+
_memset((void*)from, 0xCC, (size_t)size);
238270
}
239271

240272
static void WriteJumpInstruction(uptr from, uptr target) {
@@ -705,8 +737,8 @@ static bool CopyInstructions(uptr to, uptr from, size_t size) {
705737
size_t instruction_size = GetInstructionSize(from + cursor, &rel_offset);
706738
if (!instruction_size)
707739
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);
710742
if (rel_offset) {
711743
# if SANITIZER_WINDOWS64
712744
// 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) {
9951027

9961028
for (DWORD i = 0; i < exports->NumberOfNames; i++) {
9971029
RVAPtr<char> name(module, names[i]);
998-
if (!internal_strcmp(func_name, name)) {
1030+
if (!strcmp(func_name, name)) {
9991031
DWORD index = ordinals[i];
10001032
RVAPtr<char> func(module, functions[index]);
10011033

@@ -1007,13 +1039,13 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
10071039
// format: "<module> . <function_name>" that is stored into the
10081040
// exported directory.
10091041
char function_name[256];
1010-
size_t funtion_name_length = internal_strlen(func);
1042+
size_t funtion_name_length = _strlen(func);
10111043
if (funtion_name_length >= sizeof(function_name) - 1)
10121044
InterceptionFailed();
10131045

1014-
internal_memcpy(function_name, func, funtion_name_length);
1046+
_memcpy(function_name, func, funtion_name_length);
10151047
function_name[funtion_name_length] = '\0';
1016-
char *separator = internal_strchr(function_name, '.');
1048+
char* separator = _strchr(function_name, '.');
10171049
if (!separator)
10181050
InterceptionFailed();
10191051
*separator = '\0';

0 commit comments

Comments
 (0)