Blender V5.3
mallocn_inline.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2002-2017 `Jason Evans <jasone@canonware.com>`. All rights reserved.
2 * SPDX-FileCopyrightText: 2007-2012 Mozilla Foundation. All rights reserved.
3 * SPDX-FileCopyrightText: 2009-2017 Facebook, Inc. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause */
6#pragma once
7
11
12#include <cstdlib>
13
14/* BEGIN copied from BLI_asan.hh */
15
16/* Clang defines this. */
17#ifndef __has_feature
18# define __has_feature(x) 0
19#endif
20
21#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && \
22 (!defined(_MSC_VER) || _MSC_VER > 1929) /* MSVC 2019 and below doesn't ship ASAN headers. */
23# include "sanitizer/asan_interface.h"
24# define WITH_ASAN
25#else
26/* Ensure return value is used. Just using UNUSED_VARS results in a warning. */
27# define ASAN_POISON_MEMORY_REGION(addr, size) (void)(0 && ((size) != 0 && (addr) != NULL))
28# define ASAN_UNPOISON_MEMORY_REGION(addr, size) (void)(0 && ((size) != 0 && (addr) != NULL))
29#endif
30
31/* END copied from BLI_asan.hh */
32
39#ifdef WITH_ASAN
40MEM_INLINE void MEM_trigger_error_on_memory_block(const void *address, const size_t size)
41{
42 if (address == nullptr) {
43# ifdef WITH_ASSERT_ABORT
44 abort();
45# endif
46 return;
47 }
48
49 /* Trigger ASAN error by poisoning the memory and accessing it. */
51 char *buffer = const_cast<char *>(static_cast<const char *>(address));
52 const char c = *buffer;
53 *buffer &= 255;
54 *buffer = c;
55
56 /* In case ASAN is set to not terminate on error, but abort on assert is requested. */
57# ifdef WITH_ASSERT_ABORT
58 abort();
59# endif
61}
62#else
63MEM_INLINE void MEM_trigger_error_on_memory_block(const void * /*address*/, const size_t /*size*/)
64{
65# ifdef WITH_ASSERT_ABORT
66 abort();
67# endif
68}
69#endif
#define ASAN_POISON_MEMORY_REGION(addr, size)
Definition BLI_asan.hh:22
#define ASAN_UNPOISON_MEMORY_REGION(addr, size)
Definition BLI_asan.hh:23
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
MEM_INLINE void MEM_trigger_error_on_memory_block(const void *, const size_t)
#define MEM_INLINE