summaryrefslogtreecommitdiff
path: root/lib/asan/asan_win.cc
AgeCommit message (Collapse)Author
2017-09-14[compiler-rt] Cleanup SignalContext initializationVitaly Buka
Reviewers: eugenis, alekseyshl Subscribers: kubamracek, dberris Differential Revision: https://reviews.llvm.org/D37827 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313223 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-13[asan] Fix Windows buildVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313177 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-12[asan] For iOS/AArch64, if the dynamic shadow doesn't fit, restrict the VM spaceKuba Mracek
On iOS/AArch64, the address space is very limited and has a dynamic maximum address based on the configuration of the device. We're already using a dynamic shadow, and we find a large-enough "gap" in the VM where we place the shadow memory. In some cases and some device configuration, we might not be able to find a large-enough gap: E.g. if the main executable is linked against a large number of libraries that are not part of the system, these libraries can fragment the address space, and this happens before ASan starts initializing. This patch has a solution, where we have a "backup plan" when we cannot find a large-enough gap: We will restrict the address space (via MmapFixedNoAccess) to a limit, for which the shadow limit will fit. Differential Revision: https://reviews.llvm.org/D35098 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307865 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24[asan] Remove allow_user_segv_handler on Windows.Vitaly Buka
Summary: This flags is not covered by tests on Windows and looks like it's implemented incorrectly. Switching its default breaks some tests. Taking into account that related handle_segv flag is not supported on Windows it's safer to remove it until we commit to support it. Reviewers: eugenis, zturner, rnk Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D33471 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303728 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21[compiler-rt][asan] Add support for desallocation of unhandled pointersEtienne Bergeron
Summary: On windows 10, the ucrt DLL is performing allocations before the function hooking and there are multiple allocations not handled by Asan. When a free occur at the end of the process, asan is reporting desallocations not malloc-ed. Reviewers: rnk, kcc Reviewed By: rnk, kcc Subscribers: kcc, llvm-commits, kubamracek, chrisha, dberris Differential Revision: https://reviews.llvm.org/D25946 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295730 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[asan] Intercept SetUnhandledExceptionFilter.Marcos Pividori
In this diff I update the code for asan on Windows, so we can intercept SetUnhandledExceptionFilter and catch some exceptions depending on the result of IsHandledDeadlyException() (which depends on asan flags). This way we have the same behavior on Windows and Posix systems. On Posix, we intercept signal and sigaction, so user's code can only register signal handlers for signals that are not handled by asan. After this diff, the same happens on Windows, user's code can only register exception handlers for exceptions that are not handled by asan. Differential Revision: https://reviews.llvm.org/D29463 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293957 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[sanitizer] Move DescribeSignalOrException to sanitizer_common.Marcos Pividori
Differential Revision: https://reviews.llvm.org/D29459 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293956 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[sanitizer] Move exception code to sanitizer_common.Marcos Pividori
Differential Revision: https://reviews.llvm.org/D29458 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293955 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[asan] Properly handle exceptions.Marcos Pividori
Differential Revision: https://reviews.llvm.org/D29457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293954 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-29General definition for weak functionsMarcos Pividori
In this diff, I define a general macro for defining weak functions with a default implementation: "SANITIZER_INTERFACE_WEAK_DEF()". This way, we simplify the implementation for different platforms. For example, we cannot define weak functions on Windows, but we can use linker pragmas to create an alias to a default implementation. All of these implementation details are hidden in the new macro. Also, as I modify the name for exported weak symbols on Windows, I needed to temporarily disable "dll_host" test for asan, which checks the list of functions included in asan_win_dll_thunk. Differential Revision: https://reviews.llvm.org/D28596 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293419 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20[sanitizer] [asan] Use macros to simplify weak aliases on Windows.Marcos Pividori
This patch adds some useful macros for dealing with pragma directives on Windows. Also, I add appropriate documentation for future users. Differential Revision: https://reviews.llvm.org/D28525 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@292650 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05[sancov] force default flags for windowsMike Aizatsky
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291089 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05fixing build, accidentally deleted two linesMike Aizatsky
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291077 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05[sancov] workaround for absence of weak symbols on winMike Aizatsky
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291076 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05[sancov] workaround for absence of weak symbols on winMike Aizatsky
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291071 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-17[asan] Create a .ASAN$G(A-Z) section for global registrationReid Kleckner
Summary: The expectation is that new instrumented code will add global variable metadata to the .ASAN$GL section, and we will use this new code to iterate over it. This technique seems to break when using incremental linking, which seems to align every global to a 256 byte boundary. Presumably this is so that it can incrementally cope with global changing size. Clang already passes -incremental:no as a linker flag when you invoke it to do the link step. The two tests added for this feature will fail until the LLVM instrumentation change in D26770 lands, so they are marked XFAIL for now. Reviewers: pcc, kcc, mehdi_amini, kubabrecka Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D26771 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287246 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15Allow users to call ASan's deadly exception report mechanismReid Kleckner
Users often have their own unhandled exception filters installed. ASan already goes to great lengths to install its own filter, but our core wars with Chrome crashpad have escalated to the point that its time to declare a truce. By exposing this hook, they can call us directly when they want ASan crash reporting without worrying about who initializes when. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287040 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09Pacify lint checkJonas Hahnfeld
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286346 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08[asan/win] Add init hooks to .CRT$XLABReid Kleckner
Summary: User applications may register hooks in the .CRT$XL* callback list, which is called very early by the loader. This is very common in Chromium: https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs This has flown under the radar for a long time because the loader appears to catch exceptions originating from these callbacks. It's a real problem when you're debugging an asan application, though, since it makes the program crash early. The solution is to add our own callback to this list, and sort it very early in the list like we do elsewhere. Also add a test with such an instrumented callback, and test that it gets called with asan. Reviewers: etienneb Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D26404 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286290 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30[compiler-rt] Add support for the dynamic shadow allocationEtienne Bergeron
Summary: This patch is adding support for dynamic shadow allocation. This is a merge and re-commit of the following patches. ``` [compiler-rt] Fix Asan build on Android https://reviews.llvm.org/D24768 [compiler-rt] Add support for the dynamic shadow allocation https://reviews.llvm.org/D23363 ``` This patch needed to re-land at the same time: ``` [asan] Support dynamic shadow address instrumentation https://reviews.llvm.org/D23354 ``` Reviewers: rnk, zaks.anna Subscribers: tberghammer, danalbert, kubabrecka, dberris, chrisha, llvm-commits Differential Revision: https://reviews.llvm.org/D25104 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282882 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15Really fix the Windows sanitizer buildReid Kleckner
Don't list __sanitizer_print_memory profile as an INTERFACE_FUNCTION. It is not exported by ASan; it is exported by user code. Move the weak definition from asan_win.cc to sanitizer_win.cc to fix the ubsan tests. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281619 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-14Fix the Windows build after r281546Reid Kleckner
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281558 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-08[asan] Reify ErrorDeadlySignalFilipe Cabecinhas
Summary: Keep reifying other errors. Reviewers: kcc, samsonov Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23873 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280930 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-29[asan] Remove runtime flag detect_stack_use_after_scopeVitaly Buka
Summary: We are going to use store instructions to poison some allocas. Runtime flag will require branching in instrumented code on every lifetime intrinsic. We'd like to avoid that. Reviewers: eugenis Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23967 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279981 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-05Fix two tests in Win64 ASanReid Kleckner
Go back to intercepting kernel32!RaiseException, and only go for ntdll!RtlRaiseException if that fails. Fixes throw_and_catch.cc test. Work around an issue in LLVM's win64 epilogues. We end up with an epilogue that looks like this, and it drives the Win64 unwinder crazy until stack overflow: call ill_cc!__asan_handle_no_return xor eax,eax add rsp,40h // epilogue starts pop rbp // CSR ud2 // Trap here ret // Ret? nop word ptr [rax+rax] sub rsp,28h // Next function Will file a PR soon. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277874 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-04Avoid re-entrancy between __sanitizer::Report, OutputDebugString, and ↵Reid Kleckner
RtlRaiseException Our Report implementation calls OutputDebugString, which calls RtlRaiseException, which can re-enter back into the ASan runtime and cause a hang. Don't treat this special debugger-only exception code as a noreturn event, since the stack won't really unwind all the way. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277763 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03[ASan] Report illegal instruction exceptions in ASanReid Kleckner
Summary: Respect the handle_sigill common flag and handle_segv flags while we're at it. We still handle signals/exceptions differently on Unix and Windows. The installation process is tricky on Windows, and difficult to push down into sanitizer_common without concerning it with the different static/dynamic CRT models on Windows. Reviewers: kcc, etienneb Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23098 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277621 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02[asan] Intercept RtlRaiseException instead of kernel32!RaiseExceptionReid Kleckner
Summary: On my install of Windows 10, RaiseException is a tail call to kernelbase!RaiseException. Obviously, we fail to intercept that. Instead, try hooking at the ntdll!RtlRaiseException layer. It is unlikely that this layer will contain control flow. Intercepting at this level requires adding a decoding for 'LEA ESP, [ESP + 0xXXXXXXXX]', which is a really obscure way to write 'SUB ESP, 0xXXXXXXXX' that avoids clobbering EFLAGS. Reviewers: etienneb Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23046 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277518 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02[asan] Remove NtWaitForWorkViaWorkerFactory interceptorReid Kleckner
Summary: On Windows 10, this gets called after TLS has been torn down from NTDLL, and we crash attempting to return fake_tsd. This interceptor isn't needed after r242948 anyway, so let's remove it. The ASan runtime can now tolerate unregistered threads calling __asan_handle_no_return. Reviewers: vitalybuka, etienneb Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D23044 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277478 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-01[compiler-rt] Fix various typos in asan dll [NFC]Etienne Bergeron
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277345 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-21Disable thread safe statics in clang-cl, they call the CRTReid Kleckner
Also remove the needless static that was using them. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276327 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-21Fix clang-cl warning and crash in sanitizersReid Kleckner
Make kStderrFd a macro to avoid dynamic initialization of the report_file global. This actually causes a crash at runtime, because ASan initializes before static initializers run. Remove an unused variable in asan_win.cc. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276314 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19Add detect_stack_use_after_scope runtime flagVitaly Buka
Summary: This flag could be used to disable check in runtime. Subscribers: kubabrecka Differential Revision: https://reviews.llvm.org/D22495 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276004 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15[compiler-rt] Fix 64-bits exception handlers in ASAN 64-bits runtimeEtienne Bergeron
Summary: This is adding the appropriate suport for exception handling for 64-bits ASAN on windows. Reviewers: rnk Subscribers: kubabrecka, llvm-commits, wang0109, chrisha Differential Revision: https://reviews.llvm.org/D22395 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275585 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11[asan] Add exception handler to map memory on demand on Win64.Etienne Bergeron
Memory will be committed on demand when exception happens while accessing shadow memeory region. Patch by: Wei Wang Differential Revision: http://reviews.llvm.org/D21942 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275107 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27This patch is activating the build of Asan on Windows 64-bits.Etienne Bergeron
It's fixing compilation errors. The runtime is not yet working. Missing features: OverrideFunction for x64 an equiv function for inline asm (atomic_compare_exchange_strong) shadow memory offset needs to be adjusted RoundUpToInstrBoundary for x64 They will be implemented by subsequent patches. Patch by Wei Wang. Differential revision: http://reviews.llvm.org/D20455 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-28[asan] Add runtime support for __asan_(un)register_image_globalsRyan Govostes
This change introduces routines that register and unregister all instrumented globals in a loaded executable image. These routines are only implemented on Darwin, where globals metadata is expected to be placed in the __DATA,__asan_globals section. Review: http://reviews.llvm.org/D16841 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@264644 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-21[asan] Set the unhandled exception filter slightly later during startupReid Kleckner
VS 2015 moved the priority of their exception filter initializer from XIY to XCAA. We now set ours to XCAB, which makes it run after both CRT versions but before user constructors, as it should. Fixes null_deref.cc and a variety of related tests with VS 2015. Only 4 failures remain. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@264006 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-03[tsan] Use re-exec method to enable interceptors on older versions of OS XKuba Brecka
In AddressSanitizer, we have the MaybeReexec method to detect when we're running without DYLD_INSERT_LIBRARIES (in which case interceptors don't work) and re-execute with the environment variable set. On OS X 10.11+, this is no longer necessary, but to have ThreadSanitizer supported on older versions of OS X, let's use the same method as well. This patch moves the implementation from `asan/` into `sanitizer_common/`. Differential Revision: http://reviews.llvm.org/D15123 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254600 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-29Sanitizer: define WIN32_LEAN_AND_MEANSaleem Abdulrasool
Define WIN32_LEAN_AND_MEAN before including Windows.h. This is already being done in some places. This does it more broadly. This permits building ASAN on Linux for Winndows, as well as reduces the amount of included declarations. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@251649 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-13Fix installation of the unhandled exception filter with r244767Reid Kleckner
Apparently /Zc:inline causes static globals in custom sections to be discarded if they are unreferenced. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@244908 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-06[sanitizer] 2-nd attempt. Add the flag handle_sigfpe that is default true to ↵Kostya Serebryany
handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski. This time the test is enabled only on x86-64 (it broke on ARM) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@244234 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-06Revert "[sanitizer] Add the flag handle_sigfpe that is default true to ↵Renato Golin
handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski" This reverts commit r244136, it was breaking the ARM bots for too long. We should investigate it offline. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@244210 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-05[sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE ↵Kostya Serebryany
crashes same as SIGSEV crashes, patch by Karl Skomski git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@244136 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-29Delete unused <dbghelp.h> includeReid Kleckner
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@243529 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-21[asan] Remove AsanPlatformThreadInitReid Kleckner
Since the CoreFoundation allocator replacement was moved in r173134, all implementations of this function have been empty. Reviewers: samsonov Differential Revision: http://reviews.llvm.org/D11375 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@242811 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-17[ASan/Win] Fix a CHECK failure when an exception is thrown from a callback ↵Timur Iskhodzhanov
passed to BindIoCompletionCallback This also simplifies how we handle QueueUserWorkItem git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232499 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-16[ASan] NFC: Factor out platform-specific interceptorsTimur Iskhodzhanov
Reviewed at http://reviews.llvm.org/D8321 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232377 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-02asan: fix windows build after commit 230978Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230980 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-25Reland r230419 - add __asan_default_suppressions() hook with a fix for WindowsTimur Iskhodzhanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230501 91177308-0d34-0410-b5e6-96231b3b80d8