[compiler-rt] r200700 - [ASan] Move GetMacosVersion() to sanitizer_common.
Alexey Samsonov
samsonov at google.com
Mon Feb 3 07:45:45 PST 2014
On Mon, Feb 3, 2014 at 7:32 PM, Alexander Potapenko <glider at google.com>wrote:
> Author: glider
> Date: Mon Feb 3 09:32:19 2014
> New Revision: 200700
>
> URL: http://llvm.org/viewvc/llvm-project?rev=200700&view=rev
> Log:
> [ASan] Move GetMacosVersion() to sanitizer_common.
>
> Added:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h (with props)
> Modified:
> compiler-rt/trunk/lib/asan/asan_mac.cc
> compiler-rt/trunk/lib/asan/asan_mac.h
> compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
>
> Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=200700&r1=200699&r2=200700&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_mac.cc Mon Feb 3 09:32:19 2014
> @@ -23,6 +23,7 @@
> #include "asan_thread.h"
> #include "sanitizer_common/sanitizer_atomic.h"
> #include "sanitizer_common/sanitizer_libc.h"
> +#include "sanitizer_common/sanitizer_mac.h"
>
> #include <crt_externs.h> // for _NSGetArgv
> #include <dlfcn.h> // for dladdr()
> @@ -53,43 +54,6 @@ void GetPcSpBp(void *context, uptr *pc,
> # endif // SANITIZER_WORDSIZE
> }
>
> -MacosVersion cached_macos_version = MACOS_VERSION_UNINITIALIZED;
> -
> -MacosVersion GetMacosVersionInternal() {
> - int mib[2] = { CTL_KERN, KERN_OSRELEASE };
> - char version[100];
> - uptr len = 0, maxlen = sizeof(version) / sizeof(version[0]);
> - for (uptr i = 0; i < maxlen; i++) version[i] = '\0';
> - // Get the version length.
> - CHECK_NE(sysctl(mib, 2, 0, &len, 0, 0), -1);
> - CHECK_LT(len, maxlen);
> - CHECK_NE(sysctl(mib, 2, version, &len, 0, 0), -1);
> - switch (version[0]) {
> - case '9': return MACOS_VERSION_LEOPARD;
> - case '1': {
> - switch (version[1]) {
> - case '0': return MACOS_VERSION_SNOW_LEOPARD;
> - case '1': return MACOS_VERSION_LION;
> - case '2': return MACOS_VERSION_MOUNTAIN_LION;
> - case '3': return MACOS_VERSION_MAVERICKS;
> - default: return MACOS_VERSION_UNKNOWN;
> - }
> - }
> - default: return MACOS_VERSION_UNKNOWN;
> - }
> -}
> -
> -MacosVersion GetMacosVersion() {
> - atomic_uint32_t *cache =
> - reinterpret_cast<atomic_uint32_t*>(&cached_macos_version);
> - MacosVersion result =
> - static_cast<MacosVersion>(atomic_load(cache, memory_order_acquire));
> - if (result == MACOS_VERSION_UNINITIALIZED) {
> - result = GetMacosVersionInternal();
> - atomic_store(cache, result, memory_order_release);
> - }
> - return result;
> -}
>
> bool PlatformHasDifferentMemcpyAndMemmove() {
> // On OS X 10.7 memcpy() and memmove() are both resolved
>
> Modified: compiler-rt/trunk/lib/asan/asan_mac.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.h?rev=200700&r1=200699&r2=200700&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_mac.h (original)
> +++ compiler-rt/trunk/lib/asan/asan_mac.h Mon Feb 3 09:32:19 2014
> @@ -36,22 +36,12 @@ typedef struct __CFRuntimeBase {
> #endif
> } CFRuntimeBase;
>
> -enum MacosVersion {
> - MACOS_VERSION_UNINITIALIZED = 0,
> - MACOS_VERSION_UNKNOWN,
> - MACOS_VERSION_LEOPARD,
> - MACOS_VERSION_SNOW_LEOPARD,
> - MACOS_VERSION_LION,
> - MACOS_VERSION_MOUNTAIN_LION,
> - MACOS_VERSION_MAVERICKS
> -};
>
> // Used by asan_malloc_mac.cc and asan_mac.cc
> extern "C" void __CFInitialize();
>
> namespace __asan {
>
> -MacosVersion GetMacosVersion();
> void MaybeReplaceCFAllocator();
>
> } // namespace __asan
>
> Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=200700&r1=200699&r2=200700&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Mon Feb 3 09:32:19 2014
> @@ -28,6 +28,7 @@
> #include "asan_report.h"
> #include "asan_stack.h"
> #include "asan_stats.h"
> +#include "sanitizer_common/sanitizer_mac.h"
>
> // Similar code is used in Google Perftools,
> // http://code.google.com/p/google-perftools.
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=200700&r1=200699&r2=200700&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Feb 3
> 09:32:19 2014
> @@ -7,9 +7,8 @@
> //
>
> //===----------------------------------------------------------------------===//
> //
> -// This file is shared between AddressSanitizer and ThreadSanitizer
> -// run-time libraries and implements mac-specific functions from
> -// sanitizer_libc.h.
> +// This file is shared between various sanitizers' runtime libraries and
> +// implements OSX-specific functions.
>
> //===----------------------------------------------------------------------===//
>
> #include "sanitizer_platform.h"
> @@ -26,6 +25,7 @@
> #include "sanitizer_flags.h"
> #include "sanitizer_internal_defs.h"
> #include "sanitizer_libc.h"
> +#include "sanitizer_mac.h"
> #include "sanitizer_placement_new.h"
> #include "sanitizer_procmaps.h"
>
> @@ -37,6 +37,7 @@
> #include <sys/mman.h>
> #include <sys/resource.h>
> #include <sys/stat.h>
> +#include <sys/sysctl.h>
> #include <sys/types.h>
> #include <unistd.h>
> #include <libkern/OSAtomic.h>
> @@ -249,6 +250,44 @@ bool IsDeadlySignal(int signum) {
> return (signum == SIGSEGV || signum == SIGBUS) &&
> common_flags()->handle_segv;
> }
>
> +MacosVersion cached_macos_version = MACOS_VERSION_UNINITIALIZED;
> +
> +MacosVersion GetMacosVersionInternal() {
> + int mib[2] = { CTL_KERN, KERN_OSRELEASE };
> + char version[100];
> + uptr len = 0, maxlen = sizeof(version) / sizeof(version[0]);
> + for (uptr i = 0; i < maxlen; i++) version[i] = '\0';
> + // Get the version length.
> + CHECK_NE(sysctl(mib, 2, 0, &len, 0, 0), -1);
> + CHECK_LT(len, maxlen);
> + CHECK_NE(sysctl(mib, 2, version, &len, 0, 0), -1);
> + switch (version[0]) {
> + case '9': return MACOS_VERSION_LEOPARD;
> + case '1': {
> + switch (version[1]) {
> + case '0': return MACOS_VERSION_SNOW_LEOPARD;
> + case '1': return MACOS_VERSION_LION;
> + case '2': return MACOS_VERSION_MOUNTAIN_LION;
> + case '3': return MACOS_VERSION_MAVERICKS;
> + default: return MACOS_VERSION_UNKNOWN;
> + }
> + }
> + default: return MACOS_VERSION_UNKNOWN;
> + }
> +}
> +
> +MacosVersion GetMacosVersion() {
> + atomic_uint32_t *cache =
> + reinterpret_cast<atomic_uint32_t*>(&cached_macos_version);
> + MacosVersion result =
> + static_cast<MacosVersion>(atomic_load(cache, memory_order_acquire));
> + if (result == MACOS_VERSION_UNINITIALIZED) {
> + result = GetMacosVersionInternal();
> + atomic_store(cache, result, memory_order_release);
> + }
> + return result;
> +}
> +
> } // namespace __sanitizer
>
> #endif // SANITIZER_MAC
>
> Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h?rev=200700&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h (added)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h Mon Feb 3
> 09:32:19 2014
> @@ -0,0 +1,32 @@
> +//===-- sanitizer_mac.h -----------------------------------------*- C++
> -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +//
> +// This file is shared between various sanitizers' runtime libraries and
> +// provides definitions for OSX-specific functions.
>
> +//===----------------------------------------------------------------------===//
> +#ifndef SANITIZER_MAC_H
> +#define SANITIZER_MAC_H
>
Make this file empty on non-Mac platforms.
Add it to the list in compiler-rt/lib/sanitizer_common/CMakeLists.txt
> +
> +namespace __sanitizer {
> +
> +enum MacosVersion {
> + MACOS_VERSION_UNINITIALIZED = 0,
> + MACOS_VERSION_UNKNOWN,
> + MACOS_VERSION_LEOPARD,
> + MACOS_VERSION_SNOW_LEOPARD,
> + MACOS_VERSION_LION,
> + MACOS_VERSION_MOUNTAIN_LION,
> + MACOS_VERSION_MAVERICKS
> +};
> +
> +MacosVersion GetMacosVersion();
> +
> +} // namespace __sanitizer
> +
> +#endif // SANITIZER_MAC_H
>
> Propchange: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
>
> ------------------------------------------------------------------------------
> svn:eol-style = LF
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140203/f902a739/attachment.html>
More information about the llvm-commits
mailing list