"Fossies" - the Fresh Open Source Software Archive

Member "darktable-3.6.1/src/external/rawspeed/src/external/AddressSanitizer.h" (9 Sep 2021, 3265 Bytes) of package /linux/misc/darktable-3.6.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddressSanitizer.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2     RawSpeed - RAW file decoder.
    3 
    4     Copyright (C) 2018 Roman Lebedev
    5 
    6     This library is free software; you can redistribute it and/or
    7     modify it under the terms of the GNU Lesser General Public
    8     License as published by the Free Software Foundation; either
    9     version 2 of the License, or (at your option) any later version.
   10 
   11     This library is distributed in the hope that it will be useful,
   12     but WITHOUT ANY WARRANTY; without even the implied warranty of
   13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14     Lesser General Public License for more details.
   15 
   16     You should have received a copy of the GNU Lesser General Public
   17     License along with this library; if not, write to the Free Software
   18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   19 */
   20 
   21 #pragma once
   22 
   23 #include <cstddef> // for size_t
   24 
   25 // see http://clang.llvm.org/docs/LanguageExtensions.html
   26 #ifndef __has_feature      // Optional of course.
   27 #define __has_feature(x) 0 // Compatibility with non-clang compilers.
   28 #endif
   29 #ifndef __has_extension
   30 #define __has_extension __has_feature // Compatibility with pre-3.0 compilers.
   31 #endif
   32 
   33 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
   34 #include <sanitizer/asan_interface.h>
   35 #endif
   36 
   37 namespace rawspeed {
   38 
   39 struct ASan final {
   40   // Do not instantiate.
   41   ASan() = delete;
   42   ASan(const ASan&) = delete;
   43   ASan(ASan&&) = delete;
   44   ASan& operator=(const ASan&) = delete;
   45   ASan& operator=(ASan&&) = delete;
   46   ~ASan() = delete;
   47 
   48   // Marks memory region [addr, addr+size) as unaddressable.
   49   static void PoisonMemoryRegion(void const volatile* addr, size_t size);
   50   // Marks memory region [addr, addr+size) as addressable.
   51   static void UnPoisonMemoryRegion(void const volatile* addr, size_t size);
   52 
   53   // If at least one byte in [beg, beg+size) is poisoned, return true
   54   // Otherwise return 0.
   55   static bool RegionIsPoisoned(void const volatile* addr, size_t size);
   56 };
   57 
   58 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
   59 inline void ASan::PoisonMemoryRegion(void const volatile* addr, size_t size) {
   60   __asan_poison_memory_region(addr, size);
   61 }
   62 inline void ASan::UnPoisonMemoryRegion(void const volatile* addr, size_t size) {
   63   __asan_unpoison_memory_region(addr, size);
   64 }
   65 inline bool ASan::RegionIsPoisoned(void const volatile* addr, size_t size) {
   66   auto* beg = const_cast<void*>(addr); // NOLINT
   67   return nullptr != __asan_region_is_poisoned(beg, size);
   68 }
   69 #else
   70 inline void ASan::PoisonMemoryRegion(void const volatile* addr, size_t size) {
   71   // If we are building without ASan, then there is no way to have a non-empty
   72   // body of this function. It's better than to have a macros, or to use
   73   // preprocessor in every place it is called.
   74 }
   75 inline void ASan::UnPoisonMemoryRegion(void const volatile* addr, size_t size) {
   76   // If we are building without ASan, then there is no way to have a non-empty
   77   // body of this function. It's better than to have a macros, or to use
   78   // preprocessor in every place it is called.
   79 }
   80 inline bool ASan::RegionIsPoisoned(void const volatile* addr, size_t size) {
   81   // If we are building without ASan, then there is no way to have a poisoned
   82   // memory region.
   83   return false;
   84 }
   85 #endif
   86 
   87 } // namespace rawspeed