2012-12-25 19:53:51 +08:00
|
|
|
//===-- msan.h --------------------------------------------------*- C++ -*-===//
|
2012-12-11 20:27:27 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of MemorySanitizer.
|
|
|
|
//
|
|
|
|
// Private MSan header.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef MSAN_H
|
|
|
|
#define MSAN_H
|
|
|
|
|
2013-05-06 21:15:14 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
2013-01-29 22:33:29 +08:00
|
|
|
#include "msan_interface_internal.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
#include "msan_flags.h"
|
2015-04-28 08:56:48 +08:00
|
|
|
#include "ubsan/ubsan_platform.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2013-04-05 20:03:47 +08:00
|
|
|
#ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
|
|
|
|
# define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1
|
|
|
|
#endif
|
|
|
|
|
2015-04-28 08:56:48 +08:00
|
|
|
#ifndef MSAN_CONTAINS_UBSAN
|
|
|
|
# define MSAN_CONTAINS_UBSAN CAN_SANITIZE_UB
|
|
|
|
#endif
|
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
struct MappingDesc {
|
|
|
|
uptr start;
|
|
|
|
uptr end;
|
|
|
|
enum Type {
|
|
|
|
INVALID, APP, SHADOW, ORIGIN
|
|
|
|
} type;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
2014-11-28 19:42:55 +08:00
|
|
|
|
|
|
|
#if SANITIZER_LINUX && defined(__mips64)
|
2015-01-27 21:20:34 +08:00
|
|
|
|
2016-08-16 20:49:54 +08:00
|
|
|
// MIPS64 maps:
|
|
|
|
// - 0x0000000000-0x0200000000: Program own segments
|
|
|
|
// - 0xa200000000-0xc000000000: PIE program segments
|
|
|
|
// - 0xe200000000-0xffffffffff: libraries segments.
|
2015-01-27 21:20:34 +08:00
|
|
|
const MappingDesc kMemoryLayout[] = {
|
2016-08-16 20:49:54 +08:00
|
|
|
{0x000000000000ULL, 0x000200000000ULL, MappingDesc::APP, "app-1"},
|
|
|
|
{0x000200000000ULL, 0x002200000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x002200000000ULL, 0x004000000000ULL, MappingDesc::SHADOW, "shadow-2"},
|
|
|
|
{0x004000000000ULL, 0x004200000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x004200000000ULL, 0x006000000000ULL, MappingDesc::ORIGIN, "origin-2"},
|
|
|
|
{0x006000000000ULL, 0x006200000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x006200000000ULL, 0x008000000000ULL, MappingDesc::SHADOW, "shadow-3"},
|
|
|
|
{0x008000000000ULL, 0x008200000000ULL, MappingDesc::SHADOW, "shadow-1"},
|
|
|
|
{0x008200000000ULL, 0x00a000000000ULL, MappingDesc::ORIGIN, "origin-3"},
|
|
|
|
{0x00a000000000ULL, 0x00a200000000ULL, MappingDesc::ORIGIN, "origin-1"},
|
|
|
|
{0x00a200000000ULL, 0x00c000000000ULL, MappingDesc::APP, "app-2"},
|
|
|
|
{0x00c000000000ULL, 0x00e200000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x00e200000000ULL, 0x00ffffffffffULL, MappingDesc::APP, "app-3"}};
|
2015-01-27 21:20:34 +08:00
|
|
|
|
2016-08-16 20:49:54 +08:00
|
|
|
#define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x8000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x2000000000ULL)
|
2015-01-27 21:20:34 +08:00
|
|
|
|
2015-09-16 23:12:25 +08:00
|
|
|
#elif SANITIZER_LINUX && defined(__aarch64__)
|
|
|
|
|
2016-08-26 01:05:56 +08:00
|
|
|
// The mapping describes both 39-bits, 42-bits, and 48-bits VMA. AArch64
|
|
|
|
// maps:
|
|
|
|
// - 0x0000000000000-0x0000010000000: 39/42/48-bits program own segments
|
|
|
|
// - 0x0005500000000-0x0005600000000: 39-bits PIE program segments
|
|
|
|
// - 0x0007f80000000-0x0007fffffffff: 39-bits libraries segments
|
|
|
|
// - 0x002aa00000000-0x002ab00000000: 42-bits PIE program segments
|
|
|
|
// - 0x003ff00000000-0x003ffffffffff: 42-bits libraries segments
|
|
|
|
// - 0x0aaaaa0000000-0x0aaab00000000: 48-bits PIE program segments
|
|
|
|
// - 0xffff000000000-0x1000000000000: 48-bits libraries segments
|
2015-10-29 21:04:19 +08:00
|
|
|
// It is fragmented in multiples segments to increase the memory available
|
|
|
|
// on 42-bits (12.21% of total VMA available for 42-bits and 13.28 for
|
2016-08-26 01:05:56 +08:00
|
|
|
// 39 bits). The 48-bits segments only cover the usual PIE/default segments
|
|
|
|
// plus some more segments (262144GB total, 0.39% total VMA).
|
2015-09-16 23:12:25 +08:00
|
|
|
const MappingDesc kMemoryLayout[] = {
|
2015-10-29 21:04:19 +08:00
|
|
|
{0x00000000000ULL, 0x01000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x01000000000ULL, 0x02000000000ULL, MappingDesc::SHADOW, "shadow-2"},
|
|
|
|
{0x02000000000ULL, 0x03000000000ULL, MappingDesc::ORIGIN, "origin-2"},
|
|
|
|
{0x03000000000ULL, 0x04000000000ULL, MappingDesc::SHADOW, "shadow-1"},
|
|
|
|
{0x04000000000ULL, 0x05000000000ULL, MappingDesc::ORIGIN, "origin-1"},
|
|
|
|
{0x05000000000ULL, 0x06000000000ULL, MappingDesc::APP, "app-1"},
|
|
|
|
{0x06000000000ULL, 0x07000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x07000000000ULL, 0x08000000000ULL, MappingDesc::APP, "app-2"},
|
|
|
|
{0x08000000000ULL, 0x09000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
// The mappings below are used only for 42-bits VMA.
|
|
|
|
{0x09000000000ULL, 0x0A000000000ULL, MappingDesc::SHADOW, "shadow-3"},
|
|
|
|
{0x0A000000000ULL, 0x0B000000000ULL, MappingDesc::ORIGIN, "origin-3"},
|
|
|
|
{0x0B000000000ULL, 0x0F000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0F000000000ULL, 0x10000000000ULL, MappingDesc::APP, "app-3"},
|
|
|
|
{0x10000000000ULL, 0x11000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x11000000000ULL, 0x12000000000ULL, MappingDesc::APP, "app-4"},
|
|
|
|
{0x12000000000ULL, 0x17000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x17000000000ULL, 0x18000000000ULL, MappingDesc::SHADOW, "shadow-4"},
|
|
|
|
{0x18000000000ULL, 0x19000000000ULL, MappingDesc::ORIGIN, "origin-4"},
|
|
|
|
{0x19000000000ULL, 0x20000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x20000000000ULL, 0x21000000000ULL, MappingDesc::APP, "app-5"},
|
|
|
|
{0x21000000000ULL, 0x26000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x26000000000ULL, 0x27000000000ULL, MappingDesc::SHADOW, "shadow-5"},
|
|
|
|
{0x27000000000ULL, 0x28000000000ULL, MappingDesc::ORIGIN, "origin-5"},
|
|
|
|
{0x28000000000ULL, 0x29000000000ULL, MappingDesc::SHADOW, "shadow-7"},
|
|
|
|
{0x29000000000ULL, 0x2A000000000ULL, MappingDesc::ORIGIN, "origin-7"},
|
|
|
|
{0x2A000000000ULL, 0x2B000000000ULL, MappingDesc::APP, "app-6"},
|
|
|
|
{0x2B000000000ULL, 0x2C000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x2C000000000ULL, 0x2D000000000ULL, MappingDesc::SHADOW, "shadow-6"},
|
|
|
|
{0x2D000000000ULL, 0x2E000000000ULL, MappingDesc::ORIGIN, "origin-6"},
|
|
|
|
{0x2E000000000ULL, 0x2F000000000ULL, MappingDesc::APP, "app-7"},
|
|
|
|
{0x2F000000000ULL, 0x39000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x39000000000ULL, 0x3A000000000ULL, MappingDesc::SHADOW, "shadow-9"},
|
|
|
|
{0x3A000000000ULL, 0x3B000000000ULL, MappingDesc::ORIGIN, "origin-9"},
|
|
|
|
{0x3B000000000ULL, 0x3C000000000ULL, MappingDesc::APP, "app-8"},
|
|
|
|
{0x3C000000000ULL, 0x3D000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x3D000000000ULL, 0x3E000000000ULL, MappingDesc::SHADOW, "shadow-8"},
|
|
|
|
{0x3E000000000ULL, 0x3F000000000ULL, MappingDesc::ORIGIN, "origin-8"},
|
|
|
|
{0x3F000000000ULL, 0x40000000000ULL, MappingDesc::APP, "app-9"},
|
2016-08-26 01:05:56 +08:00
|
|
|
// The mappings below are used only for 48-bits VMA.
|
|
|
|
// TODO(unknown): 48-bit mapping ony covers the usual PIE, non-PIE
|
|
|
|
// segments and some more segments totalizing 262144GB of VMA (which cover
|
|
|
|
// only 0.32% of all 48-bit VMA). Memory avaliability can be increase by
|
|
|
|
// adding multiple application segments like 39 and 42 mapping.
|
|
|
|
{0x0040000000000ULL, 0x0041000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0041000000000ULL, 0x0042000000000ULL, MappingDesc::APP, "app-10"},
|
|
|
|
{0x0042000000000ULL, 0x0047000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0047000000000ULL, 0x0048000000000ULL, MappingDesc::SHADOW, "shadow-10"},
|
|
|
|
{0x0048000000000ULL, 0x0049000000000ULL, MappingDesc::ORIGIN, "origin-10"},
|
|
|
|
{0x0049000000000ULL, 0x0050000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0050000000000ULL, 0x0051000000000ULL, MappingDesc::APP, "app-11"},
|
|
|
|
{0x0051000000000ULL, 0x0056000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0056000000000ULL, 0x0057000000000ULL, MappingDesc::SHADOW, "shadow-11"},
|
|
|
|
{0x0057000000000ULL, 0x0058000000000ULL, MappingDesc::ORIGIN, "origin-11"},
|
|
|
|
{0x0058000000000ULL, 0x0059000000000ULL, MappingDesc::APP, "app-12"},
|
|
|
|
{0x0059000000000ULL, 0x005E000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x005E000000000ULL, 0x005F000000000ULL, MappingDesc::SHADOW, "shadow-12"},
|
|
|
|
{0x005F000000000ULL, 0x0060000000000ULL, MappingDesc::ORIGIN, "origin-12"},
|
|
|
|
{0x0060000000000ULL, 0x0061000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0061000000000ULL, 0x0062000000000ULL, MappingDesc::APP, "app-13"},
|
|
|
|
{0x0062000000000ULL, 0x0067000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0067000000000ULL, 0x0068000000000ULL, MappingDesc::SHADOW, "shadow-13"},
|
|
|
|
{0x0068000000000ULL, 0x0069000000000ULL, MappingDesc::ORIGIN, "origin-13"},
|
|
|
|
{0x0069000000000ULL, 0x0AAAAA0000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0AAAAA0000000ULL, 0x0AAAB00000000ULL, MappingDesc::APP, "app-14"},
|
|
|
|
{0x0AAAB00000000ULL, 0x0AACAA0000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0AACAA0000000ULL, 0x0AACB00000000ULL, MappingDesc::SHADOW, "shadow-14"},
|
|
|
|
{0x0AACB00000000ULL, 0x0AADAA0000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0AADAA0000000ULL, 0x0AADB00000000ULL, MappingDesc::ORIGIN, "origin-14"},
|
|
|
|
{0x0AADB00000000ULL, 0x0FF9F00000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0FF9F00000000ULL, 0x0FFA000000000ULL, MappingDesc::SHADOW, "shadow-15"},
|
|
|
|
{0x0FFA000000000ULL, 0x0FFAF00000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0FFAF00000000ULL, 0x0FFB000000000ULL, MappingDesc::ORIGIN, "origin-15"},
|
|
|
|
{0x0FFB000000000ULL, 0x0FFFF00000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x0FFFF00000000ULL, 0x1000000000000ULL, MappingDesc::APP, "app-15"},
|
2015-09-16 23:12:25 +08:00
|
|
|
};
|
2015-10-29 21:04:19 +08:00
|
|
|
# define MEM_TO_SHADOW(mem) ((uptr)mem ^ 0x6000000000ULL)
|
|
|
|
# define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x1000000000ULL)
|
2015-09-16 23:12:25 +08:00
|
|
|
|
2016-04-27 02:44:13 +08:00
|
|
|
#elif SANITIZER_LINUX && SANITIZER_PPC64
|
2015-06-25 14:22:31 +08:00
|
|
|
const MappingDesc kMemoryLayout[] = {
|
2017-11-10 00:14:57 +08:00
|
|
|
{0x000000000000ULL, 0x000200000000ULL, MappingDesc::APP, "low memory"},
|
|
|
|
{0x000200000000ULL, 0x080000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x080000000000ULL, 0x180200000000ULL, MappingDesc::SHADOW, "shadow"},
|
|
|
|
{0x180200000000ULL, 0x1C0000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x1C0000000000ULL, 0x2C0200000000ULL, MappingDesc::ORIGIN, "origin"},
|
|
|
|
{0x2C0200000000ULL, 0x300000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x300000000000ULL, 0x800000000000ULL, MappingDesc::APP, "high memory"}};
|
|
|
|
|
|
|
|
// Various kernels use different low end ranges but we can combine them into one
|
|
|
|
// big range. They also use different high end ranges but we can map them all to
|
|
|
|
// one range.
|
2015-06-25 14:22:31 +08:00
|
|
|
// Maps low and high app ranges to contiguous space with zero base:
|
2017-11-10 00:14:57 +08:00
|
|
|
// Low: 0000 0000 0000 - 0001 ffff ffff -> 1000 0000 0000 - 1001 ffff ffff
|
2015-06-25 14:22:31 +08:00
|
|
|
// High: 3000 0000 0000 - 3fff ffff ffff -> 0000 0000 0000 - 0fff ffff ffff
|
2017-11-10 00:14:57 +08:00
|
|
|
// High: 4000 0000 0000 - 4fff ffff ffff -> 0000 0000 0000 - 0fff ffff ffff
|
|
|
|
// High: 7000 0000 0000 - 7fff ffff ffff -> 0000 0000 0000 - 0fff ffff ffff
|
2015-06-25 14:22:31 +08:00
|
|
|
#define LINEARIZE_MEM(mem) \
|
2017-11-10 00:14:57 +08:00
|
|
|
(((uptr)(mem) & ~0xE00000000000ULL) ^ 0x100000000000ULL)
|
2015-06-25 14:22:31 +08:00
|
|
|
#define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x080000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL)
|
|
|
|
|
2014-11-28 19:42:55 +08:00
|
|
|
#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
|
2015-01-27 21:20:34 +08:00
|
|
|
|
|
|
|
// Low memory: main binary, MAP_32BIT mappings and modules
|
|
|
|
// High memory: heap, modules and main thread stack
|
|
|
|
const MappingDesc kMemoryLayout[] = {
|
|
|
|
{0x000000000000ULL, 0x010000000000ULL, MappingDesc::APP, "low memory"},
|
|
|
|
{0x010000000000ULL, 0x100000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x100000000000ULL, 0x310000000000ULL, MappingDesc::SHADOW, "shadow"},
|
|
|
|
{0x310000000000ULL, 0x380000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x380000000000ULL, 0x590000000000ULL, MappingDesc::ORIGIN, "origin"},
|
|
|
|
{0x590000000000ULL, 0x600000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "high memory"}};
|
|
|
|
|
2014-11-28 19:42:55 +08:00
|
|
|
// Maps low and high app ranges to contiguous space with zero base:
|
|
|
|
// Low: 0000 0000 0000 - 00ff ffff ffff -> 2000 0000 0000 - 20ff ffff ffff
|
|
|
|
// High: 6000 0000 0000 - 7fff ffff ffff -> 0000 0000 0000 - 1fff ffff ffff
|
2015-01-27 21:20:34 +08:00
|
|
|
#define LINEARIZE_MEM(mem) \
|
|
|
|
(((uptr)(mem) & ~0xc00000000000ULL) ^ 0x200000000000ULL)
|
|
|
|
#define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x100000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x280000000000)
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
#elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
|
2014-11-28 19:42:55 +08:00
|
|
|
|
2015-10-09 05:35:34 +08:00
|
|
|
#ifdef MSAN_LINUX_X86_64_OLD_MAPPING
|
2015-01-27 21:20:34 +08:00
|
|
|
// Requries PIE binary and ASLR enabled.
|
|
|
|
// Main thread stack and DSOs at 0x7f0000000000 (sometimes 0x7e0000000000).
|
|
|
|
// Heap at 0x600000000000.
|
|
|
|
const MappingDesc kMemoryLayout[] = {
|
|
|
|
{0x000000000000ULL, 0x200000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x200000000000ULL, 0x400000000000ULL, MappingDesc::SHADOW, "shadow"},
|
|
|
|
{0x400000000000ULL, 0x600000000000ULL, MappingDesc::ORIGIN, "origin"},
|
|
|
|
{0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app"}};
|
2014-11-28 19:42:55 +08:00
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
#define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x400000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x200000000000ULL)
|
2015-10-09 05:35:34 +08:00
|
|
|
#else // MSAN_LINUX_X86_64_OLD_MAPPING
|
|
|
|
// All of the following configurations are supported.
|
|
|
|
// ASLR disabled: main executable and DSOs at 0x555550000000
|
|
|
|
// PIE and ASLR: main executable and DSOs at 0x7f0000000000
|
|
|
|
// non-PIE: main executable below 0x100000000, DSOs at 0x7f0000000000
|
|
|
|
// Heap at 0x700000000000.
|
|
|
|
const MappingDesc kMemoryLayout[] = {
|
|
|
|
{0x000000000000ULL, 0x010000000000ULL, MappingDesc::APP, "app-1"},
|
|
|
|
{0x010000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
|
|
|
|
{0x100000000000ULL, 0x110000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x110000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
|
|
|
|
{0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
|
|
|
|
{0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
|
|
|
|
{0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x500000000000ULL, 0x510000000000ULL, MappingDesc::SHADOW, "shadow-1"},
|
|
|
|
{0x510000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
|
|
|
|
{0x600000000000ULL, 0x610000000000ULL, MappingDesc::ORIGIN, "origin-1"},
|
|
|
|
{0x610000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
|
|
|
|
{0x700000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}};
|
|
|
|
#define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x500000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x100000000000ULL)
|
|
|
|
#endif // MSAN_LINUX_X86_64_OLD_MAPPING
|
2014-11-28 19:42:55 +08:00
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
#else
|
|
|
|
#error "Unsupported platform"
|
|
|
|
#endif
|
2014-11-28 19:42:55 +08:00
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
const uptr kMemoryLayoutSize = sizeof(kMemoryLayout) / sizeof(kMemoryLayout[0]);
|
2014-11-28 19:42:55 +08:00
|
|
|
|
|
|
|
#define MEM_TO_ORIGIN(mem) (SHADOW_TO_ORIGIN(MEM_TO_SHADOW((mem))))
|
|
|
|
|
2015-01-27 21:20:34 +08:00
|
|
|
#ifndef __clang__
|
|
|
|
__attribute__((optimize("unroll-loops")))
|
|
|
|
#endif
|
|
|
|
inline bool addr_is_type(uptr addr, MappingDesc::Type mapping_type) {
|
|
|
|
// It is critical for performance that this loop is unrolled (because then it is
|
|
|
|
// simplified into just a few constant comparisons).
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma unroll
|
|
|
|
#endif
|
|
|
|
for (unsigned i = 0; i < kMemoryLayoutSize; ++i)
|
|
|
|
if (kMemoryLayout[i].type == mapping_type &&
|
|
|
|
addr >= kMemoryLayout[i].start && addr < kMemoryLayout[i].end)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MEM_IS_APP(mem) addr_is_type((uptr)(mem), MappingDesc::APP)
|
|
|
|
#define MEM_IS_SHADOW(mem) addr_is_type((uptr)(mem), MappingDesc::SHADOW)
|
|
|
|
#define MEM_IS_ORIGIN(mem) addr_is_type((uptr)(mem), MappingDesc::ORIGIN)
|
2014-11-28 19:42:55 +08:00
|
|
|
|
2014-10-22 08:12:40 +08:00
|
|
|
// These constants must be kept in sync with the ones in MemorySanitizer.cc.
|
|
|
|
const int kMsanParamTlsSize = 800;
|
|
|
|
const int kMsanRetvalTlsSize = 800;
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
namespace __msan {
|
|
|
|
extern int msan_inited;
|
|
|
|
extern bool msan_init_is_running;
|
2013-01-10 19:17:55 +08:00
|
|
|
extern int msan_report_count;
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
bool ProtectRange(uptr beg, uptr end);
|
2015-05-24 10:47:59 +08:00
|
|
|
bool InitShadow(bool init_origins);
|
2012-12-11 20:27:27 +08:00
|
|
|
char *GetProcSelfMaps();
|
|
|
|
void InitializeInterceptors();
|
|
|
|
|
2015-09-30 05:28:54 +08:00
|
|
|
void MsanAllocatorInit();
|
2013-10-22 22:31:30 +08:00
|
|
|
void MsanAllocatorThreadFinish();
|
2013-09-16 19:03:31 +08:00
|
|
|
void MsanDeallocate(StackTrace *stack, void *ptr);
|
2017-07-19 03:11:04 +08:00
|
|
|
|
|
|
|
void *msan_malloc(uptr size, StackTrace *stack);
|
|
|
|
void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack);
|
|
|
|
void *msan_realloc(void *ptr, uptr size, StackTrace *stack);
|
|
|
|
void *msan_valloc(uptr size, StackTrace *stack);
|
|
|
|
void *msan_pvalloc(uptr size, StackTrace *stack);
|
|
|
|
void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack);
|
|
|
|
void *msan_memalign(uptr alignment, uptr size, StackTrace *stack);
|
|
|
|
int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
|
|
|
|
StackTrace *stack);
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void InstallTrapHandler();
|
2013-01-10 19:17:55 +08:00
|
|
|
void InstallAtExitHandler();
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2014-05-21 17:02:13 +08:00
|
|
|
const char *GetStackOriginDescr(u32 id, uptr *pc);
|
2013-09-13 20:49:13 +08:00
|
|
|
|
2013-02-13 15:19:47 +08:00
|
|
|
void EnterSymbolizer();
|
|
|
|
void ExitSymbolizer();
|
|
|
|
bool IsInSymbolizer();
|
|
|
|
|
2013-03-07 00:11:58 +08:00
|
|
|
struct SymbolizerScope {
|
|
|
|
SymbolizerScope() { EnterSymbolizer(); }
|
|
|
|
~SymbolizerScope() { ExitSymbolizer(); }
|
|
|
|
};
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void PrintWarning(uptr pc, uptr bp);
|
|
|
|
void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);
|
|
|
|
|
2014-10-26 11:35:14 +08:00
|
|
|
void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp,
|
2017-11-09 15:48:53 +08:00
|
|
|
void *context, bool request_fast_unwind);
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2012-12-26 17:32:05 +08:00
|
|
|
void ReportUMR(StackTrace *stack, u32 origin);
|
|
|
|
void ReportExpectedUMRNotFound(StackTrace *stack);
|
2014-05-21 17:56:28 +08:00
|
|
|
void ReportStats();
|
2013-01-10 19:17:55 +08:00
|
|
|
void ReportAtExitStatistics();
|
2014-04-30 17:50:30 +08:00
|
|
|
void DescribeMemoryRange(const void *x, uptr size);
|
2014-05-07 19:50:14 +08:00
|
|
|
void ReportUMRInsideAddressRange(const char *what, const void *start, uptr size,
|
|
|
|
uptr offset);
|
2012-12-26 17:32:05 +08:00
|
|
|
|
2013-06-27 15:50:56 +08:00
|
|
|
// Unpoison first n function arguments.
|
|
|
|
void UnpoisonParam(uptr n);
|
2013-08-27 20:59:39 +08:00
|
|
|
void UnpoisonThreadLocalState();
|
2013-03-12 02:07:42 +08:00
|
|
|
|
2014-03-18 21:45:19 +08:00
|
|
|
// Returns a "chained" origin id, pointing to the given stack trace followed by
|
|
|
|
// the previous origin id.
|
|
|
|
u32 ChainOrigin(u32 id, StackTrace *stack);
|
|
|
|
|
2015-01-22 21:33:16 +08:00
|
|
|
const int STACK_TRACE_TAG_POISON = StackTrace::TAG_CUSTOM + 1;
|
|
|
|
|
2017-11-09 15:48:53 +08:00
|
|
|
#define GET_MALLOC_STACK_TRACE \
|
|
|
|
BufferedStackTrace stack; \
|
|
|
|
if (__msan_get_track_origins() && msan_inited) \
|
|
|
|
GetStackTrace(&stack, common_flags()->malloc_context_size, \
|
|
|
|
StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), nullptr, \
|
2014-06-27 20:48:01 +08:00
|
|
|
common_flags()->fast_unwind_on_malloc)
|
2014-03-31 22:18:55 +08:00
|
|
|
|
2016-12-08 14:30:58 +08:00
|
|
|
// For platforms which support slow unwinder only, we restrict the store context
|
|
|
|
// size to 1, basically only storing the current pc. We do this because the slow
|
|
|
|
// unwinder which is based on libunwind is not async signal safe and causes
|
|
|
|
// random freezes in forking applications as well as in signal handlers.
|
2017-11-09 15:48:53 +08:00
|
|
|
#define GET_STORE_STACK_TRACE_PC_BP(pc, bp) \
|
|
|
|
BufferedStackTrace stack; \
|
|
|
|
if (__msan_get_track_origins() > 1 && msan_inited) { \
|
|
|
|
if (!SANITIZER_CAN_FAST_UNWIND) \
|
|
|
|
GetStackTrace(&stack, Min(1, flags()->store_context_size), pc, bp, \
|
|
|
|
nullptr, false); \
|
|
|
|
else \
|
|
|
|
GetStackTrace(&stack, flags()->store_context_size, pc, bp, nullptr, \
|
|
|
|
common_flags()->fast_unwind_on_malloc); \
|
2016-12-08 14:30:58 +08:00
|
|
|
}
|
2014-10-26 11:35:14 +08:00
|
|
|
|
2017-11-09 15:48:53 +08:00
|
|
|
#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
|
|
|
|
BufferedStackTrace stack; \
|
|
|
|
if (msan_inited) \
|
|
|
|
GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr, \
|
2014-10-26 11:35:14 +08:00
|
|
|
common_flags()->fast_unwind_on_fatal)
|
2014-05-26 21:08:08 +08:00
|
|
|
|
2014-03-31 22:18:55 +08:00
|
|
|
#define GET_STORE_STACK_TRACE \
|
|
|
|
GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
|
2014-03-18 21:45:19 +08:00
|
|
|
|
2013-08-27 22:08:15 +08:00
|
|
|
class ScopedThreadLocalStateBackup {
|
2013-08-28 19:26:09 +08:00
|
|
|
public:
|
2013-08-27 22:08:15 +08:00
|
|
|
ScopedThreadLocalStateBackup() { Backup(); }
|
|
|
|
~ScopedThreadLocalStateBackup() { Restore(); }
|
|
|
|
void Backup();
|
|
|
|
void Restore();
|
2013-08-28 19:26:09 +08:00
|
|
|
private:
|
2013-08-27 22:08:15 +08:00
|
|
|
u64 va_arg_overflow_size_tls;
|
|
|
|
};
|
2014-03-27 22:04:58 +08:00
|
|
|
|
2014-04-04 17:47:41 +08:00
|
|
|
void MsanTSDInit(void (*destructor)(void *tsd));
|
|
|
|
void *MsanTSDGet();
|
|
|
|
void MsanTSDSet(void *tsd);
|
|
|
|
void MsanTSDDtor(void *tsd);
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
} // namespace __msan
|
|
|
|
|
2016-06-17 04:06:06 +08:00
|
|
|
#define MSAN_MALLOC_HOOK(ptr, size) \
|
|
|
|
do { \
|
|
|
|
if (&__sanitizer_malloc_hook) { \
|
|
|
|
UnpoisonParam(2); \
|
|
|
|
__sanitizer_malloc_hook(ptr, size); \
|
|
|
|
} \
|
|
|
|
RunMallocHooks(ptr, size); \
|
|
|
|
} while (false)
|
|
|
|
#define MSAN_FREE_HOOK(ptr) \
|
|
|
|
do { \
|
|
|
|
if (&__sanitizer_free_hook) { \
|
|
|
|
UnpoisonParam(1); \
|
|
|
|
__sanitizer_free_hook(ptr); \
|
|
|
|
} \
|
|
|
|
RunFreeHooks(ptr); \
|
|
|
|
} while (false)
|
2013-08-02 22:26:58 +08:00
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
#endif // MSAN_H
|