blob: a7bd478c749a6f1e00af3a73824028ec7c6f2f7d [file] [log] [blame]
Evgeniy Stepanov97edeb32012-12-25 11:53:51 +00001//===-- msan.h --------------------------------------------------*- C++ -*-===//
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of MemorySanitizer.
11//
12// Private MSan header.
13//===----------------------------------------------------------------------===//
14
15#ifndef MSAN_H
16#define MSAN_H
17
Sergey Matveev0b4bf4d2013-05-06 13:15:14 +000018#include "sanitizer_common/sanitizer_flags.h"
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000019#include "sanitizer_common/sanitizer_internal_defs.h"
20#include "sanitizer_common/sanitizer_stacktrace.h"
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000021#include "msan_interface_internal.h"
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000022#include "msan_flags.h"
23
Evgeniy Stepanova8974002013-04-05 12:03:47 +000024#ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
25# define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1
26#endif
27
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000028#define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x400000000000ULL)
29#define MEM_TO_ORIGIN(mem) (MEM_TO_SHADOW(mem) + 0x200000000000ULL)
30#define MEM_IS_APP(mem) ((uptr)mem >= 0x600000000000ULL)
31#define MEM_IS_SHADOW(mem) ((uptr)mem >= 0x200000000000ULL && \
32 (uptr)mem <= 0x400000000000ULL)
33
Reid Kleckner0f92deb2013-03-11 18:07:42 +000034struct link_map; // Opaque type returned by dlopen().
35
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000036const int kMsanParamTlsSizeInWords = 100;
37const int kMsanRetvalTlsSizeInWords = 100;
38
39namespace __msan {
40extern int msan_inited;
41extern bool msan_init_is_running;
Evgeniy Stepanov99bf1d72013-01-10 11:17:55 +000042extern int msan_report_count;
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000043
44bool ProtectRange(uptr beg, uptr end);
45bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins);
46char *GetProcSelfMaps();
47void InitializeInterceptors();
48
49void *MsanReallocate(StackTrace *stack, void *oldp, uptr size,
50 uptr alignment, bool zeroise);
51void MsanDeallocate(void *ptr);
52void InstallTrapHandler();
Evgeniy Stepanov99bf1d72013-01-10 11:17:55 +000053void InstallAtExitHandler();
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000054void ReplaceOperatorsNewAndDelete();
55
Kostya Serebryany70c6e3f2013-02-13 07:19:47 +000056void EnterSymbolizer();
57void ExitSymbolizer();
58bool IsInSymbolizer();
59
Reid Kleckner93c26022013-03-06 16:11:58 +000060struct SymbolizerScope {
61 SymbolizerScope() { EnterSymbolizer(); }
62 ~SymbolizerScope() { ExitSymbolizer(); }
63};
64
Reid Kleckner0f92deb2013-03-11 18:07:42 +000065void EnterLoader();
66void ExitLoader();
67
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000068void MsanDie();
69void PrintWarning(uptr pc, uptr bp);
70void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);
71
Evgeniy Stepanovefbc4352013-02-19 12:43:18 +000072void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
73 bool fast);
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000074
Evgeniy Stepanovdb010da2012-12-26 09:32:05 +000075void ReportUMR(StackTrace *stack, u32 origin);
76void ReportExpectedUMRNotFound(StackTrace *stack);
Evgeniy Stepanov99bf1d72013-01-10 11:17:55 +000077void ReportAtExitStatistics();
Evgeniy Stepanovdb010da2012-12-26 09:32:05 +000078
Reid Kleckner0f92deb2013-03-11 18:07:42 +000079void UnpoisonMappedDSO(struct link_map *map);
Alexey Samsonovc2918bf2013-06-27 07:50:56 +000080// Unpoison first n function arguments.
81void UnpoisonParam(uptr n);
Reid Kleckner0f92deb2013-03-11 18:07:42 +000082
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000083#define GET_MALLOC_STACK_TRACE \
84 StackTrace stack; \
85 stack.size = 0; \
86 if (__msan_get_track_origins() && msan_inited) \
Sergey Matveev0b4bf4d2013-05-06 13:15:14 +000087 GetStackTrace(&stack, common_flags()->malloc_context_size, \
Evgeniy Stepanovefbc4352013-02-19 12:43:18 +000088 StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \
Sergey Matveev0b4bf4d2013-05-06 13:15:14 +000089 common_flags()->fast_unwind_on_malloc)
Evgeniy Stepanov78c56c32012-12-11 12:27:27 +000090
91} // namespace __msan
92
93#endif // MSAN_H