<div dir="ltr">Ok, I think I've found the issue.<div>These tests need to be fixed on Apple.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 6, 2016 at 4:59 PM, Manman Ren <span dir="ltr"><<a href="mailto:mren@apple.com" target="_blank">mren@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This seems to trigger <a href="http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/22513/" rel="noreferrer" target="_blank">http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/22513/</a>.<br>
<br>
And it didn’t recover with the follow up commit r r274667 (<a href="http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/22515/" rel="noreferrer" target="_blank">http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/22515/</a>).<br>
<br>
Can you take a look?<br>
<br>
Thanks,<br>
Manman<br>
<div class="HOEnZb"><div class="h5"><br>
> On Jul 6, 2016, at 12:15 PM, Etienne Bergeron via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: etienneb<br>
> Date: Wed Jul 6 14:15:11 2016<br>
> New Revision: 274657<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=274657&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=274657&view=rev</a><br>
> Log:<br>
> [compilter-rt] Add unittests for interception library<br>
><br>
> Summary:<br>
> This patch is adding unittests for the interception library.<br>
><br>
><br>
> Reviewers: rnk<br>
><br>
> Subscribers: majnemer, llvm-commits, wang0109, chrisha, tberghammer, danalbert, srhines<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D21980" rel="noreferrer" target="_blank">http://reviews.llvm.org/D21980</a><br>
><br>
> Added:<br>
> compiler-rt/trunk/lib/interception/tests/<br>
> compiler-rt/trunk/lib/interception/tests/CMakeLists.txt<br>
> compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc<br>
> compiler-rt/trunk/lib/interception/tests/interception_test_main.cc<br>
> compiler-rt/trunk/lib/interception/tests/interception_win_test.cc<br>
> Modified:<br>
> compiler-rt/trunk/lib/interception/CMakeLists.txt<br>
> compiler-rt/trunk/lib/interception/interception_win.cc<br>
><br>
> Modified: compiler-rt/trunk/lib/interception/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=274657&r1=274656&r2=274657&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=274657&r1=274656&r2=274657&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/CMakeLists.txt (original)<br>
> +++ compiler-rt/trunk/lib/interception/CMakeLists.txt Wed Jul 6 14:15:11 2016<br>
> @@ -17,3 +17,7 @@ add_compiler_rt_object_libraries(RTInter<br>
> ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}<br>
> SOURCES ${INTERCEPTION_SOURCES}<br>
> CFLAGS ${INTERCEPTION_CFLAGS})<br>
> +<br>
> +if(COMPILER_RT_INCLUDE_TESTS)<br>
> + add_subdirectory(tests)<br>
> +endif()<br>
><br>
> Modified: compiler-rt/trunk/lib/interception/interception_win.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=274657&r1=274656&r2=274657&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=274657&r1=274656&r2=274657&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/interception_win.cc (original)<br>
> +++ compiler-rt/trunk/lib/interception/interception_win.cc Wed Jul 6 14:15:11 2016<br>
> @@ -201,6 +201,7 @@ static size_t RoundUpToInstrBoundary(siz<br>
> size_t cursor = 0;<br>
> while (cursor < size) {<br>
> switch (code[cursor]) {<br>
> + case '\x50': // push eax<br>
> case '\x51': // push ecx<br>
> case '\x52': // push edx<br>
> case '\x53': // push ebx<br>
> @@ -341,7 +342,7 @@ bool OverrideFunction(uptr old_func, upt<br>
> }<br>
><br>
> static void **InterestingDLLsAvailable() {<br>
> - const char *InterestingDLLs[] = {<br>
> + static const char *InterestingDLLs[] = {<br>
> "kernel32.dll",<br>
> "msvcr110.dll", // VS2012<br>
> "msvcr120.dll", // VS2013<br>
><br>
> Added: compiler-rt/trunk/lib/interception/tests/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/CMakeLists.txt?rev=274657&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/CMakeLists.txt?rev=274657&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/tests/CMakeLists.txt (added)<br>
> +++ compiler-rt/trunk/lib/interception/tests/CMakeLists.txt Wed Jul 6 14:15:11 2016<br>
> @@ -0,0 +1,147 @@<br>
> +include(CompilerRTCompile)<br>
> +<br>
> +clang_compiler_add_cxx_check()<br>
> +<br>
> +filter_available_targets(INTERCEPTION_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)<br>
> +<br>
> +set(INTERCEPTION_UNITTESTS<br>
> + interception_linux_test.cc<br>
> + interception_test_main.cc<br>
> + interception_win_test.cc<br>
> +)<br>
> +<br>
> +set(INTERCEPTION_TEST_HEADERS)<br>
> +<br>
> +set(INTERCEPTION_TEST_CFLAGS_COMMON<br>
> + ${COMPILER_RT_UNITTEST_CFLAGS}<br>
> + ${COMPILER_RT_GTEST_CFLAGS}<br>
> + -I${COMPILER_RT_SOURCE_DIR}/include<br>
> + -I${COMPILER_RT_SOURCE_DIR}/lib<br>
> + -I${COMPILER_RT_SOURCE_DIR}/lib/interception<br>
> + -fno-rtti<br>
> + -O2<br>
> + -Werror=sign-compare<br>
> + -Wno-non-virtual-dtor)<br>
> +<br>
> +# -gline-tables-only must be enough for these tests, so use it if possible.<br>
> +if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")<br>
> + list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gline-tables-only)<br>
> +else()<br>
> + list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -g)<br>
> +endif()<br>
> +if(MSVC)<br>
> + list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gcodeview)<br>
> +endif()<br>
> +list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -g)<br>
> +<br>
> +if(NOT MSVC)<br>
> + list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON --driver-mode=g++)<br>
> +endif()<br>
> +<br>
> +if(ANDROID)<br>
> + list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -pie)<br>
> +endif()<br>
> +<br>
> +set(INTERCEPTION_TEST_LINK_LIBS)<br>
> +append_list_if(COMPILER_RT_HAS_LIBLOG log INTERCEPTION_TEST_LINK_LIBS)<br>
> +# NDK r10 requires -latomic almost always.<br>
> +append_list_if(ANDROID atomic INTERCEPTION_TEST_LINK_LIBS)<br>
> +<br>
> +append_list_if(COMPILER_RT_HAS_LIBDL -ldl INTERCEPTION_TEST_LINK_FLAGS_COMMON)<br>
> +append_list_if(COMPILER_RT_HAS_LIBRT -lrt INTERCEPTION_TEST_LINK_FLAGS_COMMON)<br>
> +append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread INTERCEPTION_TEST_LINK_FLAGS_COMMON)<br>
> +# x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. Also,<br>
> +# 'libm' shall be specified explicitly to build i386 tests.<br>
> +if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE")<br>
> + list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON "-lc++ -lm")<br>
> +endif()<br>
> +<br>
> +include_directories(..)<br>
> +include_directories(../..)<br>
> +<br>
> +# Adds static library which contains interception object file<br>
> +# (universal binary on Mac and arch-specific object files on Linux).<br>
> +macro(add_interceptor_lib library)<br>
> + add_library(${library} STATIC ${ARGN})<br>
> + set_target_properties(${library} PROPERTIES<br>
> + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})<br>
> +endmacro()<br>
> +<br>
> +function(get_interception_lib_for_arch arch lib lib_name)<br>
> + if(APPLE)<br>
> + set(tgt_name "RTInterception.test.osx")<br>
> + else()<br>
> + set(tgt_name "RTInterception.test.${arch}")<br>
> + endif()<br>
> + set(${lib} "${tgt_name}" PARENT_SCOPE)<br>
> + if(CMAKE_CONFIGURATION_TYPES)<br>
> + set(configuration_path "${CMAKE_CFG_INTDIR}/")<br>
> + else()<br>
> + set(configuration_path "")<br>
> + endif()<br>
> + if(NOT MSVC)<br>
> + set(${lib_name} "${configuration_path}lib${tgt_name}.a" PARENT_SCOPE)<br>
> + else()<br>
> + set(${lib_name} "${configuration_path}${tgt_name}.lib" PARENT_SCOPE)<br>
> + endif()<br>
> +endfunction()<br>
> +<br>
> +# Interception unit tests testsuite.<br>
> +add_custom_target(InterceptionUnitTests)<br>
> +set_target_properties(InterceptionUnitTests PROPERTIES<br>
> + FOLDER "Compiler-RT Tests")<br>
> +<br>
> +# Adds interception tests for architecture.<br>
> +macro(add_interception_tests_for_arch arch)<br>
> + get_target_flags_for_arch(${arch} TARGET_FLAGS)<br>
> + set(INTERCEPTION_TEST_SOURCES ${INTERCEPTION_UNITTESTS}<br>
> + ${COMPILER_RT_GTEST_SOURCE})<br>
> + set(INTERCEPTION_TEST_COMPILE_DEPS ${INTERCEPTION_TEST_HEADERS})<br>
> + if(NOT COMPILER_RT_STANDALONE_BUILD)<br>
> + list(APPEND INTERCEPTION_TEST_COMPILE_DEPS gtest)<br>
> + endif()<br>
> + set(INTERCEPTION_TEST_OBJECTS)<br>
> + foreach(source ${INTERCEPTION_TEST_SOURCES})<br>
> + get_filename_component(basename ${source} NAME)<br>
> + if(CMAKE_CONFIGURATION_TYPES)<br>
> + set(output_obj "${CMAKE_CFG_INTDIR}/${basename}.${arch}.o")<br>
> + else()<br>
> + set(output_obj "${basename}.${arch}.o")<br>
> + endif()<br>
> + clang_compile(${output_obj} ${source}<br>
> + CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}<br>
> + DEPS ${INTERCEPTION_TEST_COMPILE_DEPS})<br>
> + list(APPEND INTERCEPTION_TEST_OBJECTS ${output_obj})<br>
> + endforeach()<br>
> + get_interception_lib_for_arch(${arch} INTERCEPTION_COMMON_LIB<br>
> + INTERCEPTION_COMMON_LIB_NAME)<br>
> + # Add unittest target.<br>
> + set(INTERCEPTION_TEST_NAME "Interception-${arch}-Test")<br>
> + add_compiler_rt_test(InterceptionUnitTests ${INTERCEPTION_TEST_NAME}<br>
> + OBJECTS ${INTERCEPTION_TEST_OBJECTS}<br>
> + ${INTERCEPTION_COMMON_LIB_NAME}<br>
> + DEPS ${INTERCEPTION_TEST_OBJECTS} ${INTERCEPTION_COMMON_LIB}<br>
> + LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON}<br>
> + ${TARGET_FLAGS})<br>
> +<br>
> +<br>
> +endmacro()<br>
> +<br>
> +if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)<br>
> + # We use just-built clang to build interception unittests, so we must<br>
> + # be sure that produced binaries would work.<br>
> + if(APPLE)<br>
> + add_interceptor_lib("RTInterception.test.osx"<br>
> + $<TARGET_OBJECTS:RTInterception.osx>)<br>
> + else()<br>
> + foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})<br>
> + add_interceptor_lib("RTInterception.test.${arch}"<br>
> + $<TARGET_OBJECTS:RTInterception.${arch}>)<br>
> + endforeach()<br>
> + endif()<br>
> + foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})<br>
> + add_interception_tests_for_arch(${arch})<br>
> + endforeach()<br>
> +endif()<br>
> +<br>
> +<br>
><br>
> Added: compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc?rev=274657&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc?rev=274657&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc (added)<br>
> +++ compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc Wed Jul 6 14:15:11 2016<br>
> @@ -0,0 +1,65 @@<br>
> +//===-- interception_linux_test.cc ----------------------------------------===//<br>
> +//<br>
> +// The LLVM Compiler Infrastructure<br>
> +//<br>
> +// This file is distributed under the University of Illinois Open Source<br>
> +// License. See LICENSE.TXT for details.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +//<br>
> +// This file is a part of ThreadSanitizer/AddressSanitizer runtime.<br>
> +// Tests for interception_linux.h.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +#include "interception/interception.h"<br>
> +<br>
> +#include "gtest/gtest.h"<br>
> +<br>
> +// Too slow for debug build<br>
> +#if !SANITIZER_DEBUG<br>
> +#if SANITIZER_LINUX<br>
> +<br>
> +static int InterceptorFunctionCalled;<br>
> +<br>
> +DECLARE_REAL(int, isdigit, int);<br>
> +<br>
> +INTERCEPTOR(int, isdigit, int d) {<br>
> + ++InterceptorFunctionCalled;<br>
> + return d >= '0' && d <= '9';<br>
> +}<br>
> +<br>
> +namespace __interception {<br>
> +<br>
> +TEST(Interception, GetRealFunctionAddress) {<br>
> + uptr expected_malloc_address = (uptr)(void*)&malloc;<br>
> + uptr malloc_address = 0;<br>
> + EXPECT_TRUE(GetRealFunctionAddress("malloc", &malloc_address, 0, 0));<br>
> + EXPECT_EQ(expected_malloc_address, malloc_address);<br>
> +<br>
> + uptr dummy_address = 0;<br>
> + EXPECT_TRUE(<br>
> + GetRealFunctionAddress("dummy_doesnt_exist__", &dummy_address, 0, 0));<br>
> + EXPECT_EQ(0U, dummy_address);<br>
> +}<br>
> +<br>
> +TEST(Interception, Basic) {<br>
> + ASSERT_TRUE(INTERCEPT_FUNCTION(isdigit));<br>
> +<br>
> + // After interception, the counter should be incremented.<br>
> + InterceptorFunctionCalled = 0;<br>
> + EXPECT_NE(0, isdigit('1'));<br>
> + EXPECT_EQ(1, InterceptorFunctionCalled);<br>
> + EXPECT_EQ(0, isdigit('a'));<br>
> + EXPECT_EQ(2, InterceptorFunctionCalled);<br>
> +<br>
> + // Calling the REAL function should not affect the counter.<br>
> + InterceptorFunctionCalled = 0;<br>
> + EXPECT_NE(0, REAL(isdigit)('1'));<br>
> + EXPECT_EQ(0, REAL(isdigit)('a'));<br>
> + EXPECT_EQ(0, InterceptorFunctionCalled);<br>
> +}<br>
> +<br>
> +} // namespace __interception<br>
> +<br>
> +#endif // SANITIZER_LINUX<br>
> +#endif // #if !SANITIZER_DEBUG<br>
><br>
> Added: compiler-rt/trunk/lib/interception/tests/interception_test_main.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_test_main.cc?rev=274657&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_test_main.cc?rev=274657&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/tests/interception_test_main.cc (added)<br>
> +++ compiler-rt/trunk/lib/interception/tests/interception_test_main.cc Wed Jul 6 14:15:11 2016<br>
> @@ -0,0 +1,22 @@<br>
> +//===-- interception_test_main.cc------------------------------------------===//<br>
> +//<br>
> +// The LLVM Compiler Infrastructure<br>
> +//<br>
> +// This file is distributed under the University of Illinois Open Source<br>
> +// License. See LICENSE.TXT for details.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +//<br>
> +// This file is a part of AddressSanitizer, an address sanity checker.<br>
> +//<br>
> +// Testing the machinery for providing replacements/wrappers for system<br>
> +// functions.<br>
> +//===----------------------------------------------------------------------===//<br>
> +<br>
> +#include "gtest/gtest.h"<br>
> +<br>
> +int main(int argc, char **argv) {<br>
> + testing::GTEST_FLAG(death_test_style) = "threadsafe";<br>
> + testing::InitGoogleTest(&argc, argv);<br>
> + return RUN_ALL_TESTS();<br>
> +}<br>
><br>
> Added: compiler-rt/trunk/lib/interception/tests/interception_win_test.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_win_test.cc?rev=274657&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_win_test.cc?rev=274657&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/interception/tests/interception_win_test.cc (added)<br>
> +++ compiler-rt/trunk/lib/interception/tests/interception_win_test.cc Wed Jul 6 14:15:11 2016<br>
> @@ -0,0 +1,142 @@<br>
> +//===-- interception_win_test.cc ------------------------------------------===//<br>
> +//<br>
> +// The LLVM Compiler Infrastructure<br>
> +//<br>
> +// This file is distributed under the University of Illinois Open Source<br>
> +// License. See LICENSE.TXT for details.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +//<br>
> +// This file is a part of ThreadSanitizer/AddressSanitizer runtime.<br>
> +// Tests for interception_win.h.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +#include "interception/interception.h"<br>
> +<br>
> +#include "gtest/gtest.h"<br>
> +<br>
> +// Too slow for debug build<br>
> +#if !SANITIZER_DEBUG<br>
> +#if SANITIZER_WINDOWS<br>
> +<br>
> +#define WIN32_LEAN_AND_MEAN<br>
> +#include <windows.h><br>
> +<br>
> +namespace {<br>
> +<br>
> +typedef int (*IdentityFunction)(int);<br>
> +<br>
> +#if !SANITIZER_WINDOWS64<br>
> +u8 kIdentityCodeWithPrologue[] = {<br>
> + 0x55, // push ebp<br>
> + 0x8B, 0xEC, // mov ebp,esp<br>
> + 0x8B, 0x45, 0x08, // mov eax,dword ptr [ebp + 8]<br>
> + 0x5D, // pop ebp<br>
> + 0xC3, // ret<br>
> +};<br>
> +<br>
> +u8 kIdentityCodeWithPushPop[] = {<br>
> + 0x55, // push ebp<br>
> + 0x8B, 0xEC, // mov ebp,esp<br>
> + 0x53, // push ebx<br>
> + 0x50, // push eax<br>
> + 0x58, // pop eax<br>
> + 0x8B, 0x45, 0x08, // mov eax,dword ptr [ebp + 8]<br>
> + 0x5B, // pop ebx<br>
> + 0x5D, // pop ebp<br>
> + 0xC3, // ret<br>
> +};<br>
> +<br>
> +#endif<br>
> +<br>
> +// A buffer holding the dynamically generated code under test.<br>
> +u8* ActiveCode;<br>
> +size_t ActiveCodeLength = 4096;<br>
> +<br>
> +bool LoadActiveCode(u8* Code, size_t CodeLength, uptr* EntryPoint) {<br>
> + if (ActiveCode == nullptr) {<br>
> + ActiveCode =<br>
> + (u8*)::VirtualAlloc(nullptr, ActiveCodeLength, MEM_COMMIT | MEM_RESERVE,<br>
> + PAGE_EXECUTE_READWRITE);<br>
> + if (ActiveCode == nullptr) return false;<br>
> + }<br>
> +<br>
> + size_t Position = 0;<br>
> + *EntryPoint = (uptr)&ActiveCode[0];<br>
> +<br>
> + // Copy the function body.<br>
> + for (size_t i = 0; i < CodeLength; ++i)<br>
> + ActiveCode[Position++] = Code[i];<br>
> +<br>
> + return true;<br>
> +}<br>
> +<br>
> +int InterceptorFunctionCalled;<br>
> +<br>
> +NOINLINE int InterceptorFunction(int x) {<br>
> + ++InterceptorFunctionCalled;<br>
> + return x;<br>
> +}<br>
> +<br>
> +} // namespace<br>
> +<br>
> +namespace __interception {<br>
> +<br>
> +// Tests for interception_win.h<br>
> +TEST(Interception, InternalGetProcAddress) {<br>
> + HMODULE ntdll_handle = ::GetModuleHandle("ntdll");<br>
> + ASSERT_NE(nullptr, ntdll_handle);<br>
> + uptr DbgPrint_expected = (uptr)::GetProcAddress(ntdll_handle, "DbgPrint");<br>
> + uptr isdigit_expected = (uptr)::GetProcAddress(ntdll_handle, "isdigit");<br>
> + uptr DbgPrint_adddress = InternalGetProcAddress(ntdll_handle, "DbgPrint");<br>
> + uptr isdigit_address = InternalGetProcAddress(ntdll_handle, "isdigit");<br>
> +<br>
> + EXPECT_EQ(DbgPrint_expected, DbgPrint_adddress);<br>
> + EXPECT_EQ(isdigit_expected, isdigit_address);<br>
> + EXPECT_NE(DbgPrint_adddress, isdigit_address);<br>
> +}<br>
> +<br>
> +void TestIdentityFunctionPatching(u8* IdentityCode, size_t IdentityCodeLength) {<br>
> + uptr IdentityAddress;<br>
> + ASSERT_TRUE(<br>
> + LoadActiveCode(IdentityCode, IdentityCodeLength, &IdentityAddress));<br>
> + IdentityFunction Identity = (IdentityFunction)IdentityAddress;<br>
> +<br>
> + // Validate behavior before dynamic patching.<br>
> + InterceptorFunctionCalled = 0;<br>
> + EXPECT_EQ(0, Identity(0));<br>
> + EXPECT_EQ(42, Identity(42));<br>
> + EXPECT_EQ(0, InterceptorFunctionCalled);<br>
> +<br>
> + // Patch the function.<br>
> + uptr RealIdentityAddress = 0;<br>
> + EXPECT_TRUE(OverrideFunction(IdentityAddress, (uptr)&InterceptorFunction,<br>
> + &RealIdentityAddress));<br>
> + IdentityFunction RealIdentity = (IdentityFunction)RealIdentityAddress;<br>
> +<br>
> + // Calling the redirected function.<br>
> + InterceptorFunctionCalled = 0;<br>
> + EXPECT_EQ(0, Identity(0));<br>
> + EXPECT_EQ(42, Identity(42));<br>
> + EXPECT_EQ(2, InterceptorFunctionCalled);<br>
> +<br>
> + // Calling the real function.<br>
> + InterceptorFunctionCalled = 0;<br>
> + EXPECT_EQ(0, RealIdentity(0));<br>
> + EXPECT_EQ(42, RealIdentity(42));<br>
> + EXPECT_EQ(0, InterceptorFunctionCalled);<br>
> +}<br>
> +<br>
> +#if !SANITIZER_WINDOWS64<br>
> +TEST(Interception, OverrideFunction) {<br>
> + TestIdentityFunctionPatching(kIdentityCodeWithPrologue,<br>
> + sizeof(kIdentityCodeWithPrologue));<br>
> + TestIdentityFunctionPatching(kIdentityCodeWithPushPop,<br>
> + sizeof(kIdentityCodeWithPushPop));<br>
> +}<br>
> +#endif<br>
> +<br>
> +} // namespace __interception<br>
> +<br>
> +#endif // SANITIZER_WINDOWS<br>
> +#endif // #if !SANITIZER_DEBUG<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Etienne Bergeron<br><div>Chrome</div></div></div></div></div></div></div>
</div>