2022-03-14 08:28:55 +01:00
|
|
|
/* Copyright (C) 2010, 2022, MariaDB Corporation.
|
2011-07-10 19:55:54 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
Update FSF address
This commit is based on the work of Michal Schorm, rebased on the
earliest MariaDB version.
Th command line used to generate this diff was:
find ./ -type f \
-exec sed -i -e 's/Foundation, Inc., 59 Temple Place, Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/Foundation, Inc. 59 Temple Place.* Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/MA.*.....-1307.*USA/MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/Foundation, Inc., 59 Temple/Foundation, Inc., 51 Franklin/g' {} \; \
-exec sed -i -e 's/Place, Suite 330, Boston, MA.*02111-1307.*USA/Street, Fifth Floor, Boston, MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/MA.*.....-1307/MA 02110-1335/g' {} \;
2019-05-10 19:49:46 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2011-07-10 19:55:54 +02:00
|
|
|
|
2019-05-20 18:23:10 +02:00
|
|
|
#ifndef MY_VALGRIND_INCLUDED
|
|
|
|
#define MY_VALGRIND_INCLUDED
|
2018-11-28 11:25:43 +01:00
|
|
|
|
2018-01-22 13:39:59 +01:00
|
|
|
/* clang -> gcc */
|
|
|
|
#ifndef __has_feature
|
|
|
|
# define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
# define __SANITIZE_ADDRESS__ 1
|
|
|
|
#endif
|
|
|
|
|
2020-06-28 19:07:32 +02:00
|
|
|
#if __has_feature(memory_sanitizer)
|
|
|
|
# include <sanitizer/msan_interface.h>
|
|
|
|
# define HAVE_valgrind
|
2021-03-23 08:16:20 +01:00
|
|
|
# define HAVE_MEM_CHECK
|
2020-06-28 19:07:32 +02:00
|
|
|
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
|
2020-07-02 15:52:13 +02:00
|
|
|
# define MEM_MAKE_ADDRESSABLE(a,len) MEM_UNDEFINED(a,len)
|
2020-06-28 19:07:32 +02:00
|
|
|
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
|
|
|
|
# define MEM_NOACCESS(a,len) ((void) 0)
|
|
|
|
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
|
|
|
|
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
|
|
|
|
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
|
|
|
|
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
|
|
|
|
# define REDZONE_SIZE 8
|
2022-03-14 08:28:55 +01:00
|
|
|
# ifdef __linux__
|
|
|
|
# define MSAN_STAT_WORKAROUND(st) MEM_MAKE_DEFINED(st, sizeof(*st))
|
|
|
|
# else
|
|
|
|
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
|
|
|
|
# endif
|
2020-06-28 19:07:32 +02:00
|
|
|
#elif defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
|
2011-07-10 19:55:54 +02:00
|
|
|
# include <valgrind/memcheck.h>
|
2021-03-23 08:16:20 +01:00
|
|
|
# define HAVE_MEM_CHECK
|
2011-07-10 19:55:54 +02:00
|
|
|
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
|
2020-07-02 15:52:13 +02:00
|
|
|
# define MEM_MAKE_ADDRESSABLE(a,len) MEM_UNDEFINED(a,len)
|
2020-05-15 13:20:43 +02:00
|
|
|
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
|
2011-07-10 19:55:54 +02:00
|
|
|
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
|
|
|
|
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
|
|
|
|
# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
|
MDEV-20377: Make WITH_MSAN more usable
MemorySanitizer (clang -fsanitize=memory) requires that all code
be compiled with instrumentation enabled. The only exception is the
C runtime library. Failure to use instrumented libraries will cause
bogus messages about memory being uninitialized.
In WITH_MSAN builds, we must avoid calling getservbyname(),
because even though it is a standard library function, it is
not instrumented, not even in clang 10.
Note: Before MariaDB Server 10.5, ./mtr will typically fail
due to the old PCRE library, which was updated in MDEV-14024.
The following cmake options were tested on 10.5
in commit 94d0bb4dbeb28a94d1f87fdd55f4297ff3df0157:
cmake \
-DCMAKE_C_FLAGS='-march=native -O2' \
-DCMAKE_CXX_FLAGS='-stdlib=libc++ -march=native -O2' \
-DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug \
-DWITH_INNODB_{BZIP2,LZ4,LZMA,LZO,SNAPPY}=OFF \
-DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO \
-DWITH_SAFEMALLOC=OFF \
-DWITH_{ZLIB,SSL,PCRE}=bundled \
-DHAVE_LIBAIO_H=0 \
-DWITH_MSAN=ON
MEM_MAKE_DEFINED(): An alias for VALGRIND_MAKE_MEM_DEFINED()
and __msan_unpoison().
MEM_GET_VBITS(), MEM_SET_VBITS(): Aliases for
VALGRIND_GET_VBITS(), VALGRIND_SET_VBITS(), __msan_copy_shadow().
InnoDB: Replace the UNIV_MEM_ macros with corresponding MEM_ macros.
ut_crc32_8_hw(), ut_crc32_64_low_hw(): Use the compiler built-in
functions instead of inline assembler when building WITH_MSAN.
This will require at least -msse4.2 when building for IA-32 or AMD64.
The inline assembler would not be instrumented, and would thus cause
bogus failures.
2020-07-01 16:23:00 +02:00
|
|
|
# define MEM_GET_VBITS(a,b,len) VALGRIND_GET_VBITS(a,b,len)
|
|
|
|
# define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len)
|
2019-05-20 18:23:10 +02:00
|
|
|
# define REDZONE_SIZE 8
|
2022-03-14 08:28:55 +01:00
|
|
|
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
|
2021-03-12 08:43:37 +01:00
|
|
|
#elif defined(__SANITIZE_ADDRESS__) && (!defined(_MSC_VER) || defined (__clang__))
|
2018-01-16 22:57:28 +01:00
|
|
|
# include <sanitizer/asan_interface.h>
|
2018-03-20 08:46:57 +01:00
|
|
|
/* How to do manual poisoning:
|
|
|
|
https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */
|
2020-07-02 15:52:13 +02:00
|
|
|
# define MEM_UNDEFINED(a,len) ((void) 0)
|
|
|
|
# define MEM_MAKE_ADDRESSABLE(a,len) ASAN_UNPOISON_MEMORY_REGION(a,len)
|
2020-05-15 13:20:43 +02:00
|
|
|
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
|
2018-01-16 22:57:28 +01:00
|
|
|
# define MEM_NOACCESS(a,len) ASAN_POISON_MEMORY_REGION(a,len)
|
2020-07-02 15:52:13 +02:00
|
|
|
# define MEM_CHECK_ADDRESSABLE(a,len) \
|
|
|
|
assert(!__asan_region_is_poisoned((void*) a,len))
|
2018-01-16 22:57:28 +01:00
|
|
|
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
|
MDEV-20377: Make WITH_MSAN more usable
MemorySanitizer (clang -fsanitize=memory) requires that all code
be compiled with instrumentation enabled. The only exception is the
C runtime library. Failure to use instrumented libraries will cause
bogus messages about memory being uninitialized.
In WITH_MSAN builds, we must avoid calling getservbyname(),
because even though it is a standard library function, it is
not instrumented, not even in clang 10.
Note: Before MariaDB Server 10.5, ./mtr will typically fail
due to the old PCRE library, which was updated in MDEV-14024.
The following cmake options were tested on 10.5
in commit 94d0bb4dbeb28a94d1f87fdd55f4297ff3df0157:
cmake \
-DCMAKE_C_FLAGS='-march=native -O2' \
-DCMAKE_CXX_FLAGS='-stdlib=libc++ -march=native -O2' \
-DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug \
-DWITH_INNODB_{BZIP2,LZ4,LZMA,LZO,SNAPPY}=OFF \
-DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO \
-DWITH_SAFEMALLOC=OFF \
-DWITH_{ZLIB,SSL,PCRE}=bundled \
-DHAVE_LIBAIO_H=0 \
-DWITH_MSAN=ON
MEM_MAKE_DEFINED(): An alias for VALGRIND_MAKE_MEM_DEFINED()
and __msan_unpoison().
MEM_GET_VBITS(), MEM_SET_VBITS(): Aliases for
VALGRIND_GET_VBITS(), VALGRIND_SET_VBITS(), __msan_copy_shadow().
InnoDB: Replace the UNIV_MEM_ macros with corresponding MEM_ macros.
ut_crc32_8_hw(), ut_crc32_64_low_hw(): Use the compiler built-in
functions instead of inline assembler when building WITH_MSAN.
This will require at least -msse4.2 when building for IA-32 or AMD64.
The inline assembler would not be instrumented, and would thus cause
bogus failures.
2020-07-01 16:23:00 +02:00
|
|
|
# define MEM_GET_VBITS(a,b,len) ((void) 0)
|
|
|
|
# define MEM_SET_VBITS(a,b,len) ((void) 0)
|
2022-03-14 08:28:55 +01:00
|
|
|
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
|
2019-05-20 18:23:10 +02:00
|
|
|
# define REDZONE_SIZE 8
|
2018-01-16 22:57:28 +01:00
|
|
|
#else
|
2020-07-02 15:52:13 +02:00
|
|
|
# define MEM_UNDEFINED(a,len) ((void) 0)
|
|
|
|
# define MEM_MAKE_ADDRESSABLE(a,len) ((void) 0)
|
2020-05-15 13:20:43 +02:00
|
|
|
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
|
2011-07-10 19:55:54 +02:00
|
|
|
# define MEM_NOACCESS(a,len) ((void) 0)
|
|
|
|
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
|
|
|
|
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
|
MDEV-20377: Make WITH_MSAN more usable
MemorySanitizer (clang -fsanitize=memory) requires that all code
be compiled with instrumentation enabled. The only exception is the
C runtime library. Failure to use instrumented libraries will cause
bogus messages about memory being uninitialized.
In WITH_MSAN builds, we must avoid calling getservbyname(),
because even though it is a standard library function, it is
not instrumented, not even in clang 10.
Note: Before MariaDB Server 10.5, ./mtr will typically fail
due to the old PCRE library, which was updated in MDEV-14024.
The following cmake options were tested on 10.5
in commit 94d0bb4dbeb28a94d1f87fdd55f4297ff3df0157:
cmake \
-DCMAKE_C_FLAGS='-march=native -O2' \
-DCMAKE_CXX_FLAGS='-stdlib=libc++ -march=native -O2' \
-DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug \
-DWITH_INNODB_{BZIP2,LZ4,LZMA,LZO,SNAPPY}=OFF \
-DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO \
-DWITH_SAFEMALLOC=OFF \
-DWITH_{ZLIB,SSL,PCRE}=bundled \
-DHAVE_LIBAIO_H=0 \
-DWITH_MSAN=ON
MEM_MAKE_DEFINED(): An alias for VALGRIND_MAKE_MEM_DEFINED()
and __msan_unpoison().
MEM_GET_VBITS(), MEM_SET_VBITS(): Aliases for
VALGRIND_GET_VBITS(), VALGRIND_SET_VBITS(), __msan_copy_shadow().
InnoDB: Replace the UNIV_MEM_ macros with corresponding MEM_ macros.
ut_crc32_8_hw(), ut_crc32_64_low_hw(): Use the compiler built-in
functions instead of inline assembler when building WITH_MSAN.
This will require at least -msse4.2 when building for IA-32 or AMD64.
The inline assembler would not be instrumented, and would thus cause
bogus failures.
2020-07-01 16:23:00 +02:00
|
|
|
# define MEM_GET_VBITS(a,b,len) ((void) 0)
|
|
|
|
# define MEM_SET_VBITS(a,b,len) ((void) 0)
|
2019-05-20 18:23:10 +02:00
|
|
|
# define REDZONE_SIZE 0
|
2022-03-14 08:28:55 +01:00
|
|
|
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
|
2020-06-28 19:07:32 +02:00
|
|
|
#endif /* __has_feature(memory_sanitizer) */
|
|
|
|
|
2020-05-15 16:55:01 +02:00
|
|
|
#ifdef TRASH_FREED_MEMORY
|
2020-05-15 13:20:43 +02:00
|
|
|
/*
|
2020-07-02 15:52:13 +02:00
|
|
|
_TRASH_FILL() has to call MEM_MAKE_ADDRESSABLE() to cancel any effect of
|
|
|
|
TRASH_FREE().
|
2020-05-15 13:20:43 +02:00
|
|
|
This can happen in the case one does
|
|
|
|
TRASH_ALLOC(A,B) ; TRASH_FREE(A,B) ; TRASH_ALLOC(A,B)
|
|
|
|
to reuse the same memory in an internal memory allocator like MEM_ROOT.
|
2020-07-02 15:52:13 +02:00
|
|
|
_TRASH_FILL() is an internal function and should not be used externally.
|
2020-05-15 13:20:43 +02:00
|
|
|
*/
|
2020-07-02 15:52:13 +02:00
|
|
|
#define _TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_MAKE_ADDRESSABLE(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
|
2011-07-10 19:55:54 +02:00
|
|
|
#else
|
2020-07-02 15:52:13 +02:00
|
|
|
#define _TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
|
2011-07-10 19:55:54 +02:00
|
|
|
#endif
|
2020-07-02 15:52:13 +02:00
|
|
|
/** Note that some memory became allocated and/or uninitialized. */
|
|
|
|
#define TRASH_ALLOC(A,B) do { _TRASH_FILL(A,B,0xA5); MEM_MAKE_ADDRESSABLE(A,B); } while(0)
|
2019-08-12 13:05:26 +02:00
|
|
|
/** Note that some memory became freed. (Prohibit further access to it.) */
|
2020-07-02 15:52:13 +02:00
|
|
|
#define TRASH_FREE(A,B) do { _TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)
|
2018-11-28 11:25:43 +01:00
|
|
|
|
2019-05-20 18:23:10 +02:00
|
|
|
#endif /* MY_VALGRIND_INCLUDED */
|