mirror of
https://github.com/python/cpython.git
synced 2026-04-22 03:41:08 +00:00
[3.7] bpo-35214: Initial clang MemorySanitizer support (GH-10479) (GH-10492)
Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.
Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that. This lets our build succeed under the memory sanitizer. not all tests
pass without sanitizer failures yet but we're in pretty good shape after this.
(cherry picked from commit 1584a00815)
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
This commit is contained in:
parent
f3b0b91674
commit
5f4d05d83f
9 changed files with 115 additions and 4 deletions
|
|
@ -20,6 +20,10 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef MEMORY_SANITIZER
|
||||
# include <sanitizer/msan_interface.h>
|
||||
#endif
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
int _Py_HashSecret_Initialized = 0;
|
||||
#else
|
||||
|
|
@ -143,6 +147,11 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
|
|||
else {
|
||||
n = syscall(SYS_getrandom, dest, n, flags);
|
||||
}
|
||||
# ifdef MEMORY_SANITIZER
|
||||
if (n > 0) {
|
||||
__msan_unpoison(dest, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (n < 0) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ double _Py_force_double(double x)
|
|||
|
||||
/* inline assembly for getting and setting the 387 FPU control word on
|
||||
gcc/x86 */
|
||||
|
||||
#ifdef MEMORY_SANITIZER
|
||||
__attribute__((no_sanitize_memory))
|
||||
#endif
|
||||
unsigned short _Py_get_387controlword(void) {
|
||||
unsigned short cw;
|
||||
__asm__ __volatile__ ("fnstcw %0" : "=m" (cw));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue