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"
|
|
|
|
|
2013-04-05 20:03:47 +08:00
|
|
|
#ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
|
|
|
|
# define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1
|
|
|
|
#endif
|
|
|
|
|
2013-10-24 19:56:03 +08:00
|
|
|
#define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x400000000000ULL)
|
|
|
|
#define SHADOW_TO_ORIGIN(shadow) (((uptr)shadow) + 0x200000000000ULL)
|
|
|
|
#define MEM_TO_ORIGIN(mem) (SHADOW_TO_ORIGIN(MEM_TO_SHADOW(mem)))
|
|
|
|
#define MEM_IS_APP(mem) ((uptr)mem >= 0x600000000000ULL)
|
|
|
|
#define MEM_IS_SHADOW(mem) \
|
|
|
|
((uptr)mem >= 0x200000000000ULL && (uptr)mem <= 0x400000000000ULL)
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
const int kMsanParamTlsSizeInWords = 100;
|
|
|
|
const int kMsanRetvalTlsSizeInWords = 100;
|
|
|
|
|
|
|
|
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);
|
|
|
|
bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins);
|
|
|
|
char *GetProcSelfMaps();
|
|
|
|
void InitializeInterceptors();
|
|
|
|
|
2013-10-22 22:31:30 +08:00
|
|
|
void MsanAllocatorThreadFinish();
|
2012-12-11 20:27:27 +08:00
|
|
|
void *MsanReallocate(StackTrace *stack, void *oldp, uptr size,
|
|
|
|
uptr alignment, bool zeroise);
|
2013-09-16 19:03:31 +08:00
|
|
|
void MsanDeallocate(StackTrace *stack, void *ptr);
|
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
|
|
|
void ReplaceOperatorsNewAndDelete();
|
|
|
|
|
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(); }
|
|
|
|
};
|
|
|
|
|
2013-03-12 02:07:42 +08:00
|
|
|
void EnterLoader();
|
|
|
|
void ExitLoader();
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void MsanDie();
|
|
|
|
void PrintWarning(uptr pc, uptr bp);
|
|
|
|
void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);
|
|
|
|
|
2013-02-19 20:43:18 +08:00
|
|
|
void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
|
2013-11-07 15:28:33 +08:00
|
|
|
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-04-02 19:06:35 +08:00
|
|
|
u32 GetOriginIfPoisoned(uptr a, uptr size);
|
|
|
|
void SetOriginIfPoisoned(uptr addr, uptr src_shadow, uptr size, u32 src_origin);
|
2014-03-18 21:45:19 +08:00
|
|
|
void CopyOrigin(void *dst, const void *src, uptr size, StackTrace *stack);
|
|
|
|
void MovePoison(void *dst, const void *src, uptr size, StackTrace *stack);
|
|
|
|
void CopyPoison(void *dst, const void *src, uptr size, StackTrace *stack);
|
|
|
|
|
|
|
|
// Returns a "chained" origin id, pointing to the given stack trace followed by
|
|
|
|
// the previous origin id.
|
|
|
|
u32 ChainOrigin(u32 id, StackTrace *stack);
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
#define GET_MALLOC_STACK_TRACE \
|
|
|
|
StackTrace stack; \
|
|
|
|
stack.size = 0; \
|
|
|
|
if (__msan_get_track_origins() && msan_inited) \
|
2013-05-06 21:15:14 +08:00
|
|
|
GetStackTrace(&stack, common_flags()->malloc_context_size, \
|
2013-02-19 20:43:18 +08:00
|
|
|
StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \
|
2013-05-06 21:15:14 +08:00
|
|
|
common_flags()->fast_unwind_on_malloc)
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2014-06-27 20:48:01 +08:00
|
|
|
#define GET_STORE_STACK_TRACE_PC_BP(pc, bp) \
|
|
|
|
StackTrace stack; \
|
|
|
|
stack.size = 0; \
|
|
|
|
if (__msan_get_track_origins() > 1 && msan_inited) \
|
|
|
|
GetStackTrace(&stack, flags()->store_context_size, pc, bp, \
|
|
|
|
common_flags()->fast_unwind_on_malloc)
|
2014-03-31 22:18:55 +08:00
|
|
|
|
2014-05-26 21:08:08 +08:00
|
|
|
#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
|
|
|
|
StackTrace stack; \
|
|
|
|
stack.size = 0; \
|
|
|
|
if (msan_inited) \
|
|
|
|
GetStackTrace(&stack, kStackTraceMax, pc, bp, \
|
|
|
|
common_flags()->fast_unwind_on_fatal)
|
|
|
|
|
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
|
|
|
|
|
|
|
extern void (*death_callback)(void);
|
|
|
|
|
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
|
|
|
|
|
2013-08-02 22:26:58 +08:00
|
|
|
#define MSAN_MALLOC_HOOK(ptr, size) \
|
2014-07-08 01:39:31 +08:00
|
|
|
if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
|
2013-08-02 22:26:58 +08:00
|
|
|
#define MSAN_FREE_HOOK(ptr) \
|
2014-07-08 01:39:31 +08:00
|
|
|
if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
|
2013-08-02 22:26:58 +08:00
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
#endif // MSAN_H
|