[llvm-commits] [compiler-rt] r158496 - in /compiler-rt/trunk/lib: asan/asan_internal.h asan/asan_posix.cc asan/asan_win.cc sanitizer_common/sanitizer_common.cc sanitizer_common/sanitizer_common.h sanitizer_common/sanitizer_posix.cc sanitizer_common/sanitizer_win.cc
Alexey Samsonov
samsonov at google.com
Fri Jun 15 00:00:31 PDT 2012
Author: samsonov
Date: Fri Jun 15 02:00:31 2012
New Revision: 158496
URL: http://llvm.org/viewvc/llvm-project?rev=158496&view=rev
Log:
[Sanitizer] move atomic ops, min/max and sort to commnon runtime
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_posix.cc
compiler-rt/trunk/lib/asan/asan_win.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Fri Jun 15 02:00:31 2012
@@ -129,9 +129,6 @@
void SetAlternateSignalStack();
void UnsetAlternateSignalStack();
void InstallSignalHandlers();
-int AtomicInc(int *a);
-u16 AtomicExchange(u16 *a, u16 new_val);
-u8 AtomicExchange(u8 *a, u8 new_val);
// Wrapper for TLS/TSD.
void AsanTSDInit(void (*destructor)(void *tsd));
@@ -143,12 +140,6 @@
void AsanPrintf(const char *format, ...);
void AsanReport(const char *format, ...);
-// Don't use std::min and std::max, to minimize dependency on libstdc++.
-template<class T> T Min(T a, T b) { return a < b ? a : b; }
-template<class T> T Max(T a, T b) { return a > b ? a : b; }
-
-void SortArray(uptr *array, uptr size);
-
// asan_poisoning.cc
// Poisons the shadow memory for "size" bytes starting from "addr".
void PoisonShadow(uptr addr, uptr size, u8 value);
Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Fri Jun 15 02:00:31 2012
@@ -28,14 +28,6 @@
#include <sys/resource.h>
#include <unistd.h>
-#ifdef ANDROID
-#include <sys/atomics.h>
-#endif
-
-// Should not add dependency on libstdc++,
-// since most of the stuff here is inlinable.
-#include <algorithm>
-
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
namespace __asan {
@@ -134,26 +126,6 @@
MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV);
}
-int AtomicInc(int *a) {
-#ifdef ANDROID
- return __atomic_inc(a) + 1;
-#else
- return __sync_add_and_fetch(a, 1);
-#endif
-}
-
-u16 AtomicExchange(u16 *a, u16 new_val) {
- return __sync_lock_test_and_set(a, new_val);
-}
-
-u8 AtomicExchange(u8 *a, u8 new_val) {
- return __sync_lock_test_and_set(a, new_val);
-}
-
-void SortArray(uptr *array, uptr size) {
- std::sort(array, array + size);
-}
-
// ---------------------- TSD ---------------- {{{1
static pthread_key_t tsd_key;
Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Fri Jun 15 02:00:31 2012
@@ -24,10 +24,6 @@
#include "asan_lock.h"
#include "asan_thread.h"
-// Should not add dependency on libstdc++,
-// since most of the stuff here is inlinable.
-#include <algorithm>
-
namespace __asan {
// ---------------------- Stacktraces, symbols, etc. ---------------- {{{1
@@ -168,30 +164,6 @@
return true;
}
-int AtomicInc(int *a) {
- return InterlockedExchangeAdd((LONG*)a, 1) + 1;
-}
-
-u16 AtomicExchange(u16 *a, u16 new_val) {
- // InterlockedExchange16 seems unavailable on some MSVS installations.
- // Everybody stand back, I pretend to know inline assembly!
- // FIXME: I assume VC is smart enough to save/restore eax/ecx?
- __asm {
- mov eax, a
- mov cx, new_val
- xchg [eax], cx ; NOLINT
- mov new_val, cx
- }
- return new_val;
-}
-
-u8 AtomicExchange(u8 *a, u8 new_val) {
- // FIXME: can we do this with a proper xchg intrinsic?
- u8 t = *a;
- *a = new_val;
- return t;
-}
-
void SetAlternateSignalStack() {
// FIXME: Decide what to do on Windows.
}
@@ -204,10 +176,6 @@
// FIXME: Decide what to do on Windows.
}
-void SortArray(uptr *array, uptr size) {
- std::sort(array, array + size);
-}
-
} // namespace __asan
#endif // _WIN32
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Jun 15 02:00:31 2012
@@ -14,6 +14,10 @@
#include "sanitizer_common.h"
#include "sanitizer_libc.h"
+// Should not add dependency on libstdc++,
+// since most of the stuff here is inlinable.
+#include <algorithm>
+
namespace __sanitizer {
void RawWrite(const char *buffer) {
@@ -56,4 +60,8 @@
return read_len;
}
+void SortArray(uptr *array, uptr size) {
+ std::sort(array, array + size);
+}
+
} // namespace __sanitizer
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Jun 15 02:00:31 2012
@@ -63,16 +63,24 @@
void NORETURN Exit(int exitcode);
void NORETURN Abort();
int Atexit(void (*function)(void));
+void SortArray(uptr *array, uptr size);
-// Bit twiddling.
+// Atomics
+int AtomicInc(int *a);
+u16 AtomicExchange(u16 *a, u16 new_val);
+u8 AtomicExchange(u8 *a, u8 new_val);
+
+// Math
inline bool IsPowerOfTwo(uptr x) {
return (x & (x - 1)) == 0;
}
inline uptr RoundUpTo(uptr size, uptr boundary) {
- // FIXME: Use CHECK here.
- RAW_CHECK(IsPowerOfTwo(boundary));
+ CHECK(IsPowerOfTwo(boundary));
return (size + boundary - 1) & ~(boundary - 1);
}
+// Don't use std::min and std::max, to minimize dependency on libstdc++.
+template<class T> T Min(T a, T b) { return a < b ? a : b; }
+template<class T> T Max(T a, T b) { return a > b ? a : b; }
#if __WORDSIZE == 64
# define FIRST_32_SECOND_64(a, b) (b)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Fri Jun 15 02:00:31 2012
@@ -27,6 +27,10 @@
#include <sys/types.h>
#include <unistd.h>
+#ifdef ANDROID
+#include <sys/atomics.h>
+#endif
+
namespace __sanitizer {
// ------------- sanitizer_common.h
@@ -112,6 +116,22 @@
return atexit(function);
}
+int AtomicInc(int *a) {
+#ifdef ANDROID
+ return __atomic_inc(a) + 1;
+#else
+ return __sync_add_and_fetch(a, 1);
+#endif
+}
+
+u16 AtomicExchange(u16 *a, u16 new_val) {
+ return __sync_lock_test_and_set(a, new_val);
+}
+
+u8 AtomicExchange(u8 *a, u8 new_val) {
+ return __sync_lock_test_and_set(a, new_val);
+}
+
// -------------- sanitizer_libc.h
int internal_sscanf(const char *str, const char *format, ...) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=158496&r1=158495&r2=158496&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Fri Jun 15 02:00:31 2012
@@ -111,6 +111,30 @@
return atexit(function);
}
+int AtomicInc(int *a) {
+ return InterlockedExchangeAdd((LONG*)a, 1) + 1;
+}
+
+u16 AtomicExchange(u16 *a, u16 new_val) {
+ // InterlockedExchange16 seems unavailable on some MSVS installations.
+ // Everybody stand back, I pretend to know inline assembly!
+ // FIXME: I assume VC is smart enough to save/restore eax/ecx?
+ __asm {
+ mov eax, a
+ mov cx, new_val
+ xchg [eax], cx ; NOLINT
+ mov new_val, cx
+ }
+ return new_val;
+}
+
+u8 AtomicExchange(u8 *a, u8 new_val) {
+ // FIXME: can we do this with a proper xchg intrinsic?
+ u8 t = *a;
+ *a = new_val;
+ return t;
+}
+
// ------------------ sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {
More information about the llvm-commits
mailing list