mirror of
https://github.com/facebook/zstd.git
synced 2025-10-18 00:03:50 -04:00
Move ASAN/MSAN support declarations to compiler.h
This commit is contained in:
parent
b09ec5c2b9
commit
4d63ee57f5
@ -196,4 +196,80 @@
|
|||||||
#define STATIC_BMI2 0
|
#define STATIC_BMI2 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* detects whether we are being compiled under msan */
|
||||||
|
#if defined (__has_feature)
|
||||||
|
# if __has_feature(memory_sanitizer)
|
||||||
|
# define MEMORY_SANITIZER 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (MEMORY_SANITIZER)
|
||||||
|
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
||||||
|
* We therefore declare the functions we need ourselves, rather than trying to
|
||||||
|
* include the header file... */
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
#define ZS_DEPS_NEED_STDINT
|
||||||
|
#include "zstd_deps.h" /* intptr_t */
|
||||||
|
|
||||||
|
/* Make memory region fully initialized (without changing its contents). */
|
||||||
|
void __msan_unpoison(const volatile void *a, size_t size);
|
||||||
|
|
||||||
|
/* Make memory region fully uninitialized (without changing its contents).
|
||||||
|
This is a legacy interface that does not update origin information. Use
|
||||||
|
__msan_allocated_memory() instead. */
|
||||||
|
void __msan_poison(const volatile void *a, size_t size);
|
||||||
|
|
||||||
|
/* Returns the offset of the first (at least partially) poisoned byte in the
|
||||||
|
memory range, or -1 if the whole range is good. */
|
||||||
|
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* detects whether we are being compiled under asan */
|
||||||
|
#if defined (__has_feature)
|
||||||
|
# if __has_feature(address_sanitizer)
|
||||||
|
# define ADDRESS_SANITIZER 1
|
||||||
|
# endif
|
||||||
|
#elif defined(__SANITIZE_ADDRESS__)
|
||||||
|
# define ADDRESS_SANITIZER 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (ADDRESS_SANITIZER)
|
||||||
|
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
||||||
|
* We therefore declare the functions we need ourselves, rather than trying to
|
||||||
|
* include the header file... */
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
|
||||||
|
*
|
||||||
|
* This memory must be previously allocated by your program. Instrumented
|
||||||
|
* code is forbidden from accessing addresses in this region until it is
|
||||||
|
* unpoisoned. This function is not guaranteed to poison the entire region -
|
||||||
|
* it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
|
||||||
|
* alignment restrictions.
|
||||||
|
*
|
||||||
|
* \note This function is not thread-safe because no two threads can poison or
|
||||||
|
* unpoison memory in the same memory region simultaneously.
|
||||||
|
*
|
||||||
|
* \param addr Start of memory region.
|
||||||
|
* \param size Size of memory region. */
|
||||||
|
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
|
||||||
|
*
|
||||||
|
* This memory must be previously allocated by your program. Accessing
|
||||||
|
* addresses in this region is allowed until this region is poisoned again.
|
||||||
|
* This function could unpoison a super-region of <c>[addr, addr+size)</c> due
|
||||||
|
* to ASan alignment restrictions.
|
||||||
|
*
|
||||||
|
* \note This function is not thread-safe because no two threads can
|
||||||
|
* poison or unpoison memory in the same memory region simultaneously.
|
||||||
|
*
|
||||||
|
* \param addr Start of memory region.
|
||||||
|
* \param size Size of memory region. */
|
||||||
|
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_COMPILER_H */
|
#endif /* ZSTD_COMPILER_H */
|
||||||
|
@ -46,80 +46,6 @@ extern "C" {
|
|||||||
/* code only tested on 32 and 64 bits systems */
|
/* code only tested on 32 and 64 bits systems */
|
||||||
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
||||||
|
|
||||||
/* detects whether we are being compiled under msan */
|
|
||||||
#if defined (__has_feature)
|
|
||||||
# if __has_feature(memory_sanitizer)
|
|
||||||
# define MEMORY_SANITIZER 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (MEMORY_SANITIZER)
|
|
||||||
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
|
||||||
* We therefore declare the functions we need ourselves, rather than trying to
|
|
||||||
* include the header file... */
|
|
||||||
|
|
||||||
#define ZS_DEPS_NEED_STDINT
|
|
||||||
#include "zstd_deps.h"
|
|
||||||
|
|
||||||
/* Make memory region fully initialized (without changing its contents). */
|
|
||||||
void __msan_unpoison(const volatile void *a, size_t size);
|
|
||||||
|
|
||||||
/* Make memory region fully uninitialized (without changing its contents).
|
|
||||||
This is a legacy interface that does not update origin information. Use
|
|
||||||
__msan_allocated_memory() instead. */
|
|
||||||
void __msan_poison(const volatile void *a, size_t size);
|
|
||||||
|
|
||||||
/* Returns the offset of the first (at least partially) poisoned byte in the
|
|
||||||
memory range, or -1 if the whole range is good. */
|
|
||||||
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* detects whether we are being compiled under asan */
|
|
||||||
#if defined (__has_feature)
|
|
||||||
# if __has_feature(address_sanitizer)
|
|
||||||
# define ADDRESS_SANITIZER 1
|
|
||||||
# endif
|
|
||||||
#elif defined(__SANITIZE_ADDRESS__)
|
|
||||||
# define ADDRESS_SANITIZER 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER)
|
|
||||||
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
|
||||||
* We therefore declare the functions we need ourselves, rather than trying to
|
|
||||||
* include the header file... */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
|
|
||||||
*
|
|
||||||
* This memory must be previously allocated by your program. Instrumented
|
|
||||||
* code is forbidden from accessing addresses in this region until it is
|
|
||||||
* unpoisoned. This function is not guaranteed to poison the entire region -
|
|
||||||
* it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
|
|
||||||
* alignment restrictions.
|
|
||||||
*
|
|
||||||
* \note This function is not thread-safe because no two threads can poison or
|
|
||||||
* unpoison memory in the same memory region simultaneously.
|
|
||||||
*
|
|
||||||
* \param addr Start of memory region.
|
|
||||||
* \param size Size of memory region. */
|
|
||||||
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
|
|
||||||
*
|
|
||||||
* This memory must be previously allocated by your program. Accessing
|
|
||||||
* addresses in this region is allowed until this region is poisoned again.
|
|
||||||
* This function could unpoison a super-region of <c>[addr, addr+size)</c> due
|
|
||||||
* to ASan alignment restrictions.
|
|
||||||
*
|
|
||||||
* \note This function is not thread-safe because no two threads can
|
|
||||||
* poison or unpoison memory in the same memory region simultaneously.
|
|
||||||
*
|
|
||||||
* \param addr Start of memory region.
|
|
||||||
* \param size Size of memory region. */
|
|
||||||
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
|
Loading…
x
Reference in New Issue
Block a user