Alexander Potapenko
e8ba1c851a
[ASan] Refactoring: nuke the redundant function declarations in asan_intercepted_functions.h
...
that had been used on OS X only.
The INTERCEPTOR() macro on OS X is now responsible for declaring the wrapped function, the wrapper and the
pair of pointers to them in __DATA,__interposition section. Thus adding an interceptor requires editing a single file now.
llvm-svn: 175740
2013-02-21 14:41:16 +00:00
Kostya Serebryany
9f298da9bd
[asan] instrument memory accesses with unusual sizes
...
This patch makes asan instrument memory accesses with unusual sizes (e.g. 5 bytes or 10 bytes), e.g. long double or
packed structures.
Instrumentation is done with two 1-byte checks
(first and last bytes) and if the error is found
__asan_report_load_n(addr, real_size) or
__asan_report_store_n(addr, real_size)
is called.
asan-rt part
Also fix lint.
llvm-svn: 175508
2013-02-19 11:30:25 +00:00
Alexey Samsonov
4544d1fa3d
[ASan] make variables unsigned to silence warnings - attempt 2
...
llvm-svn: 175285
2013-02-15 19:22:49 +00:00
Alexey Samsonov
f6d7379def
[ASan] make variable unsigned to silence the warning
...
llvm-svn: 175284
2013-02-15 19:02:32 +00:00
Alexander Potapenko
3182c3e441
[ASan] Fix https://code.google.com/p/address-sanitizer/issues/detail?id=159
...
MaybeReexec() does now a tricky job to manage DYLD_INSERT_LIBRARIES in a safe way.
Because we're using library interposition, it's critical for an instrumented app
to be executed with the runtime library present in DYLD_INSERT_LIBRARIES list.
Therefore if it's initially missing in that list, we append the runtime library name
to the value of DYLD_INSERT_LIBRARIES and then exec() ourselves.
On the other hand, some of the apps exec()ed by our program may not want to have
ASan runtime library preloaded, so we remove the runtime library from the
DYLD_INSERT_LIBRARIES if it's already there.
Users may want to preload other libraries using DYLD_INSERT_LIBRARIES, so we preserve those.
llvm-svn: 175276
2013-02-15 16:10:49 +00:00
Kostya Serebryany
aa7f2b5aa6
[tsan] disable a failing test until it gets fixed. fix lint
...
llvm-svn: 175137
2013-02-14 06:54:51 +00:00
Alexander Potapenko
c5ba5ef3c5
[ASan] When re-executing the process on OS X, make sure we update the existing DYLD_INSERT_LIBRARIES correctly.
...
Previously ASan used to hang in an exec loop, because it failed to overwrite the env var value
(see https://code.google.com/p/address-sanitizer/issues/detail?id=159 ).
llvm-svn: 175059
2013-02-13 17:52:55 +00:00
Alexander Potapenko
34157fc33f
[ASan] Delete the code related to static runtime on OS X.
...
Nuke lib/interception/mach_override.
llvm-svn: 174383
2013-02-05 15:57:12 +00:00
Alexander Potapenko
dc00c44d46
[ASan] Remove the declarations of pthread_workqueue_t and pthread_workitem_handle_t, which are used no more.
...
Kudos to Jeremy Huddleston Sequoia <jeremyhu@apple.com>
llvm-svn: 173143
2013-01-22 10:32:06 +00:00
Alexander Potapenko
cae42d23a6
[ASan] Use dylib interposition to hook memory allocation in the dynamic runtime.
...
This CL drastically simplifies the way we're hooking the memory allocation routines in ASan on Mac by using dylib interposition to replace the main malloc_zone_* functions. This allows us to avoid replacing the default CFAllocator and drop the CF dependency at all.
Committing this patch will result in the static runtime being broken. A follow-up CL will switch ASan to use the dynamic runtime library.
llvm-svn: 173134
2013-01-22 09:14:54 +00:00
Alexander Potapenko
51794a390f
Remove references to pthread_workqueue_additem_np(), which isn't in the official libdispatch API.
...
llvm-svn: 172802
2013-01-18 10:27:31 +00:00
Alexey Samsonov
4f1885a109
[ASan] minor changes to swapcontext handling: don't clear shadow memory if context stack is too large
...
llvm-svn: 172727
2013-01-17 15:45:28 +00:00
Dmitry Vyukov
f22982bf0a
asan/tsan: move blocking mutex from asan to sanitizer_common
...
llvm-svn: 172380
2013-01-14 07:51:39 +00:00
Kostya Serebryany
3674c6b13b
[asan] add a flag alloc_dealloc_mismatch (off by default for now) which finds malloc/delete, new/free, new/delete[], etc mismatches
...
llvm-svn: 170869
2012-12-21 08:53:59 +00:00
Kostya Serebryany
060bfab568
[asan] fix win build
...
llvm-svn: 170119
2012-12-13 10:03:50 +00:00
Kostya Serebryany
baf583c443
[asan] add two asan flags: fast_unwind_on_fatal and fast_unwind_on_malloc to allow using the slow CFI-based unwinder
...
llvm-svn: 170117
2012-12-13 09:34:23 +00:00
Alexander Potapenko
0dcd6d9468
[ASan] Do not build the interceptors that use ObjC blocks if the compiler does not support blocks.
...
Need to define MISSING_BLOCKS_SUPPORT in this case at buildtime.
Patch by Jack Howarth <howarth@bromo.med.uc.edu>
llvm-svn: 169206
2012-12-04 02:41:47 +00:00
Kostya Serebryany
df198db1aa
[asan/tsan] get rid of kPageSize completely in favor of GetPageSizeCached(). This makes the code friendly to more platforms
...
llvm-svn: 168537
2012-11-24 05:03:11 +00:00
Alexey Samsonov
aac36b345a
[ASan] intercept swapcontext on Linux only
...
llvm-svn: 168509
2012-11-23 10:14:44 +00:00
Kostya Serebryany
734f1eb5f4
[asan/tsan] do not use __WORDSIZE macro, as it is glibc-private thing. Instead, define our own SANITIZER_WORDSIZE
...
llvm-svn: 168424
2012-11-21 12:38:58 +00:00
Alexander Potapenko
1eef2b813c
[ASan] Rename ReplaceCFAllocator to MaybeReplaceCFAllocator.
...
Replace the allocator only if the replace_cfallocator flag is set (in some cases it wasn't checked)
llvm-svn: 166550
2012-10-24 09:35:23 +00:00
Alexander Potapenko
e3e80d607f
Do not call ReplaceCFAllocator() before __CFInitialize(), otherwise crashes are possible on 10.8.
...
Fixes http://code.google.com/p/address-sanitizer/issues/detail?id=122
llvm-svn: 166029
2012-10-16 16:58:10 +00:00
Alexander Potapenko
4a78e1002d
Add MACOS_VERSION_MOUNTAIN_LION.
...
llvm-svn: 166026
2012-10-16 16:24:49 +00:00
Alexey Samsonov
4787d0fbef
[ASan] more macro/casting magic to suppress warnings
...
llvm-svn: 163706
2012-09-12 14:10:14 +00:00
Alexander Potapenko
3ecf916c33
Use the return value of dladdr() to avoid Clang warning.
...
llvm-svn: 163311
2012-09-06 12:18:45 +00:00
Kostya Serebryany
ee92877f17
[asan] more refactoring to move StackTrace to sanitizer_common
...
llvm-svn: 162752
2012-08-28 13:25:55 +00:00
Kostya Serebryany
6b0d775229
[asan] some renaming before we move StackTrace into sanitizer_common
...
llvm-svn: 162747
2012-08-28 11:54:30 +00:00
Alexander Potapenko
fefc1e989c
If the program is linked to a dynamic ASan runtime which is not present in DYLD_INSERT_LIBRARIES
...
(which, in turn, is required for our interceptors to take effect), re-exec the program with
DYLD_INSERT_LIBRARIES set.
llvm-svn: 162547
2012-08-24 09:22:05 +00:00
Alexander Potapenko
2ebe619340
Re-implement the wrappers for libdispatch functions using blocks where appropriate
...
(kudos to Anna Zaks for a good example).
This simplifies the code much and lets us not implement internal parts of libdispatch.
All ASan tests from t32 and t64 should pass with the dylib runtime now.
llvm-svn: 162439
2012-08-23 09:34:40 +00:00
Kostya Serebryany
6b745b5281
[asan] fix lint
...
llvm-svn: 162258
2012-08-21 06:43:44 +00:00
Alexander Potapenko
02e6f03236
Dynamic interceptors for dispatch_async and dispatch_after.
...
llvm-svn: 162202
2012-08-20 11:59:26 +00:00
Alexander Potapenko
1233d558dc
Minor refactoring: reduce code duplication by introducing a macro for dispatch_sync_f, dispatch_async_f, dispatch_barrier_async_f bodies.
...
llvm-svn: 162199
2012-08-20 09:25:10 +00:00
Alexander Potapenko
20f9fcc285
Move the prototype of __CFInitialize to asan_mac.h so that asan_malloc_mac.cc may use it in the dynamic library mode.
...
llvm-svn: 161945
2012-08-15 12:23:36 +00:00
Alexey Samsonov
36d2dff143
[ASan] fix cmake build warning
...
llvm-svn: 160957
2012-07-30 10:18:31 +00:00
Alexander Potapenko
51e6488b31
Intercept CFAllocator for each thread in the program.
...
Test that child threads use the ASan allocator, that allocated memory can be passed to another thread and deallocated on it.
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=81
llvm-svn: 160630
2012-07-23 14:07:58 +00:00
Alexey Samsonov
34efb8e9b9
[ASan] Use common flags parsing machinery.
...
llvm-svn: 159933
2012-07-09 14:36:04 +00:00
Alexander Potapenko
89f9270366
A portable way to check whether __CFInitialize has been called: compare kCFAllocatorSystemDefault._base._cfisa to 0.
...
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=87 on both Lion and Snow Leopard.
llvm-svn: 159821
2012-07-06 13:04:12 +00:00
Alexander Potapenko
d2ff0b087a
Do not check for __CFRuntimeClassTableSize on non-10.6 systems, where this symbol is private.
...
This change may cause http://code.google.com/p/address-sanitizer/issues/detail?id=87 to re-appear on Lion.
llvm-svn: 159819
2012-07-06 11:58:54 +00:00
Alexander Potapenko
25b567dd0d
Fix http://code.google.com/p/address-sanitizer/issues/detail?id=87 by making sure we replace the default CFAllocator only after __CFInitialize has been called.
...
llvm-svn: 159749
2012-07-05 14:46:56 +00:00
Alexey Samsonov
70386aaffa
[ASan] cleanup: trailing semicolons, trailing colons in enums
...
llvm-svn: 159338
2012-06-28 08:27:24 +00:00
Alexander Potapenko
f9f2fbacb3
Actually intercept free() to ensure that the deallocations caused by other functions directly calling it are routed to our allocator.
...
For the allocations that do not belong to any malloc zone check whether they're padded with a pointer to ASan's CFAllocator. If so, free the original (unpadded) pointer.
This should fix AddressSanitizerMac.NSURLDeallocation and issue 70.
llvm-svn: 158863
2012-06-20 22:29:09 +00:00
Alexey Samsonov
c70d1086f6
[Sanitizer] move rest of mmap routines to common sanitizer runtime
...
llvm-svn: 158452
2012-06-14 14:42:58 +00:00
Alexey Samsonov
0c53a38abb
[Sanitizer] move portable GetEnv to common sanitizer runtime
...
llvm-svn: 158451
2012-06-14 14:07:21 +00:00
Alexey Samsonov
52f946611f
[ASan] don't include deleted header
...
llvm-svn: 158448
2012-06-14 13:15:45 +00:00
Alexey Samsonov
4b1f1031e6
[Sanitizer] factor out GetThreadStackTopAndBottom from ASan runtime to common.
...
llvm-svn: 158140
2012-06-07 07:13:46 +00:00
Alexey Samsonov
28a9895ee0
[Sanitizer] __asan::AsanProcMaps -> __sanitizer::ProcessMaps.
...
llvm-svn: 158139
2012-06-07 06:15:12 +00:00
Alexey Samsonov
40d5b772e5
[Sanitizer] Switch to common mmap/munmap routines in ASan run-time.
...
llvm-svn: 158078
2012-06-06 16:15:07 +00:00
Kostya Serebryany
79437fe376
[asan] make tid u32 instead of int
...
llvm-svn: 158074
2012-06-06 15:06:58 +00:00
Alexey Samsonov
d44cb4cb8a
[ASan] match type of arguments to format string on Mac.
...
llvm-svn: 158068
2012-06-06 13:44:19 +00:00
Alexey Samsonov
c4b201308b
[ASan] Use __sanitizer::Die() in ASan runtime.
...
llvm-svn: 158051
2012-06-06 07:02:44 +00:00
Alexey Samsonov
8602c65719
[Sanitizer] remove using namespace __sanitizer lines
...
llvm-svn: 157999
2012-06-05 14:05:09 +00:00
Alexey Samsonov
7ac77d6b29
[Sanitizer] add sanitizer_posix.cc. Move more various functions into sanitizer_libc: sscanf, munmap, memchr
...
llvm-svn: 157994
2012-06-05 09:49:25 +00:00
Alexey Samsonov
9354688dc5
[ASan] s/size_t/uptr in asan_mac.cc
...
llvm-svn: 157993
2012-06-05 09:13:33 +00:00
Alexey Samsonov
1b12eda7ec
[ASan] use internal_{close,read,write} in ASan runtime.
...
llvm-svn: 157991
2012-06-05 08:48:10 +00:00
Alexey Samsonov
f5e2dc3c3d
[ASan] use internal_open from sanitizer_libc in ASan runtime
...
llvm-svn: 157986
2012-06-05 07:25:47 +00:00
Alexey Samsonov
2c5fc3bb11
Created files sanitizer_linux.cc and sanitizer_mac.cc for platform-specific implementations of common functions. Turned asan_mmap into __sanitizer::internal_mmap.
...
llvm-svn: 157930
2012-06-04 14:27:50 +00:00
Kostya Serebryany
1d35d155fd
[asan] more renaming
...
llvm-svn: 157747
2012-05-31 15:02:07 +00:00
Kostya Serebryany
8d03204204
[asan] more renaming
...
llvm-svn: 157746
2012-05-31 14:35:53 +00:00
Evgeniy Stepanov
8152e22073
Move AsanShadowRangeIsAvailable() from mac to posix.
...
llvm-svn: 157326
2012-05-23 15:21:50 +00:00
Alexey Samsonov
7ec936a4f4
[ASan] remove dispatch.h header once again - it's not present on Leopard, and we don't want to break the build of compiler-rt there. See https://trac.macports.org/ticket/33362
...
llvm-svn: 154326
2012-04-09 16:45:18 +00:00
Alexander Potapenko
c6eb6a8287
Add internal_memset and replace the uses of REAL(memset) with it where the performance allows.
...
llvm-svn: 153641
2012-03-29 12:20:47 +00:00
Alexey Samsonov
8ada45553d
[asan]: substitute extern decls with system header in asan_mac.cc
...
llvm-svn: 153182
2012-03-21 13:00:04 +00:00
Alexey Samsonov
9ce04b0c36
[asan] merge mac-specific interceptors into one function
...
llvm-svn: 153180
2012-03-21 12:42:00 +00:00
Alexey Samsonov
5f7048b396
[asan]: remove asan_mac.h
...
llvm-svn: 153179
2012-03-21 12:29:54 +00:00
Alexey Samsonov
1d4145380e
[asan]: start removing os-specific asan_mac.h - move inclusion of mac system header to asan_mac.cc
...
llvm-svn: 153178
2012-03-21 12:03:44 +00:00
Alexey Samsonov
c298b3674f
[ASan]: remove GetMacosVersion from asan_mac.h header
...
llvm-svn: 153084
2012-03-20 10:54:40 +00:00
Kostya Serebryany
e059c124a8
[asan] one more -Wnull-conversion fix
...
llvm-svn: 152773
2012-03-15 04:26:00 +00:00
Alexey Samsonov
278c25f241
AddressSanitizer: simplify IntervalsAreSeparate function
...
llvm-svn: 150569
2012-02-15 08:27:34 +00:00
Alexander Potapenko
438447a7f3
Fix compilation on Mac.
...
llvm-svn: 150400
2012-02-13 17:14:31 +00:00
Alexander Potapenko
720aaefb8d
Move the non-trivial implementation of AsanShadowRangeIsAvailable to asan_mac.cc
...
to avoid crashes on Linux and Win.
llvm-svn: 150398
2012-02-13 17:09:40 +00:00
Alexey Samsonov
8489f2a564
AddressSanitizer: start factoring out interception machinery
...
llvm-svn: 150083
2012-02-08 19:52:01 +00:00
Alexey Samsonov
e725478e2f
AddressSanitizer: replace all "real_X" calls with "REAL(X)"
...
llvm-svn: 150073
2012-02-08 13:45:31 +00:00
Alexey Samsonov
15965f9c3d
AddressSanitizer: Add macro for definition/declaration of interceptors
...
llvm-svn: 149602
2012-02-02 10:39:40 +00:00
Kostya Serebryany
7e7d0ca1a2
[asan] remove dead code
...
llvm-svn: 149392
2012-01-31 17:29:02 +00:00
Alexander Potapenko
81203bdb33
Implement GetMacosVersion() to obtain the OS X version at runtime.
...
llvm-svn: 149382
2012-01-31 13:19:18 +00:00
Kostya Serebryany
fed83c5755
[asan] ifdef/include cleanup
...
llvm-svn: 149281
2012-01-30 22:11:04 +00:00
Alexander Potapenko
98f0c713d9
Fix a bug in AsanProcMaps on Mac: on 64 bits the program was trying to read twice as many segment load commands as the binary actually contained.
...
llvm-svn: 149063
2012-01-26 17:01:20 +00:00
Alexander Potapenko
046ecc06be
Wrap CFStringCreateCopy to prevent copying constant CF strings.
...
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=10
llvm-svn: 148696
2012-01-23 10:09:54 +00:00
Alexander Potapenko
3825e9770b
Minor fixes of the AsanProcMaps code on Mac:
...
-- make the load command scan linear (instead of quadratic)
-- do not create a nested AsanProcMaps instance for each address lookup
-- more comments
llvm-svn: 148472
2012-01-19 12:44:06 +00:00
Evgeniy Stepanov
84c44a8b8b
EHABI-based stack trace on ARM.
...
The change removes the unused FLAG_fast_unwind, and forces EHABI-based unwind
on ARM, and fast (FP-based) unwind everywhere else.
llvm-svn: 148468
2012-01-19 11:34:18 +00:00
Alexander Potapenko
4257386879
Implement AsanProcMaps for Mac OS. The code from sysinfo/ is not needed anymore and should be cleaned up.
...
llvm-svn: 148385
2012-01-18 11:16:05 +00:00
Alexander Potapenko
2b2e0721d7
Define the bounds of the branch allocator memory space for 32-bit apps.
...
llvm-svn: 148303
2012-01-17 09:38:54 +00:00
Alexey Samsonov
2d3a67b73b
AddressSanitizer: create AsanThreadSummary together with AsanThread (in parent thread)
...
llvm-svn: 148286
2012-01-17 06:35:31 +00:00
Alexey Samsonov
50bf956f29
AddressSanitizer: fix recently introduced lint errors and broken test on Mac.
...
llvm-svn: 148235
2012-01-16 12:38:09 +00:00
Alexander Potapenko
bd53f597de
This patch adds two methods, __asan_allocate_island and __asan_deallocate_island
...
and switches our interceptors to using them instead of the default
vm_allocate-based approach used by mach_override_ptr.
To simplify the code, a fixed memory mapping is used for the allocation pool --
note that we can't mmap an arbitrary chunk of memory, because the shadow memory hasn't been mapped yet
(for the reasons discussed in http://code.google.com/p/address-sanitizer/issues/detail?id=24 , we cannot map the shadow earlier)
The patch drops the program startup time from several second to half a second,
which speeds up the execution of ASan tests noticeably.
Because of the virtual memory size occupied by the programs it's hard
to speed up the shutdown time, which would've also helped the tests.
llvm-svn: 148116
2012-01-13 16:13:58 +00:00
Alexander Potapenko
553c208d22
This patch moves the code reading /proc/self/environ into AsanGetEnv
...
in asan_linux.cc, because /proc is unavailable on Mac.
Instead the Mac version of AsanGetEnv iterates over the array of
environment variables obtained from _NSGetEnviron()
llvm-svn: 148114
2012-01-13 12:59:48 +00:00
Kostya Serebryany
332923be32
[asan] get rid of the scary TSD destructor code. Now, we store the leaky AsanThreadSummary in TSD and never remove it from there.
...
llvm-svn: 147910
2012-01-11 02:03:16 +00:00
Kostya Serebryany
a82f0d4950
[asan] move OS-dependent code away from asan_lock.h
...
llvm-svn: 147878
2012-01-10 21:24:40 +00:00
Kostya Serebryany
edb4a8a128
[asan] don't include unistd.h in the headers
...
llvm-svn: 147811
2012-01-09 23:11:26 +00:00
Kostya Serebryany
5be458ccfd
[asan] refactoring: move some common linux/mac code to asan_posix.cc
...
llvm-svn: 147788
2012-01-09 19:18:27 +00:00
Kostya Serebryany
9fd01e5ea5
[asan] refactoring: move all interceptors to a single file
...
llvm-svn: 147784
2012-01-09 18:53:15 +00:00
Kostya Serebryany
3f4b9bb4a0
[asan] do not use new/delete for the internal thread structure
...
llvm-svn: 147674
2012-01-06 19:44:11 +00:00
Kostya Serebryany
25d6c1b3c3
[asan] move more code into OS-specific files
...
llvm-svn: 147671
2012-01-06 19:11:09 +00:00
Kostya Serebryany
2b08718bba
[asan] move more stuff to OS-specific files
...
llvm-svn: 147647
2012-01-06 02:12:25 +00:00
Kostya Serebryany
78d87d3b4b
[asan] move {linux,mac}-specific code from asan_thread.cc to asan_{linux,mac}.cc; also add asan_procmaps.h which I forgot to add on previous commit.
...
llvm-svn: 147586
2012-01-05 01:07:27 +00:00
Kostya Serebryany
a772096156
[asan] refactoring: don't #include <sys/mman.h> in non-os-specific files
...
llvm-svn: 147328
2011-12-28 23:28:54 +00:00
Kostya Serebryany
6c4bd806fa
[asan] use custom libc-free getenv; a bit of refactoring around mmap calls
...
llvm-svn: 147326
2011-12-28 22:58:01 +00:00
Kostya Serebryany
6bb2f1d5b5
Recently the GCD tests started failing because of the invalid size of
...
FakeStack on the worker threads.
This patch moves the AsanThread initialization into a separate
procedure that's called when AsanThread objects are called for worker
threads.
Patch by glider@google.com
llvm-svn: 146752
2011-12-16 19:13:35 +00:00
Kostya Serebryany
c5be44aaa2
[asan] quick fix for mac build, second attempt. Sorry for spam.
...
llvm-svn: 145694
2011-12-02 18:52:35 +00:00
Kostya Serebryany
196cd6af90
[asan] quick fix for mac build
...
llvm-svn: 145692
2011-12-02 18:48:20 +00:00