Home | History | Annotate | Download | only in msan
      1 //===-- msan_interface_internal.h -------------------------------*- C++ -*-===//
      2 //
      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 interface header.
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef MSAN_INTERFACE_INTERNAL_H
     16 #define MSAN_INTERFACE_INTERNAL_H
     17 
     18 #include "sanitizer_common/sanitizer_internal_defs.h"
     19 
     20 extern "C" {
     21 // FIXME: document all interface functions.
     22 
     23 SANITIZER_INTERFACE_ATTRIBUTE
     24 int __msan_get_track_origins();
     25 
     26 SANITIZER_INTERFACE_ATTRIBUTE
     27 void __msan_init();
     28 
     29 // Print a warning and maybe return.
     30 // This function can die based on flags()->exit_code.
     31 SANITIZER_INTERFACE_ATTRIBUTE
     32 void __msan_warning();
     33 
     34 // Print a warning and die.
     35 // Intrumentation inserts calls to this function when building in "fast" mode
     36 // (i.e. -mllvm -msan-keep-going)
     37 SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))
     38 void __msan_warning_noreturn();
     39 
     40 SANITIZER_INTERFACE_ATTRIBUTE
     41 void __msan_maybe_warning_1(u8 s, u32 o);
     42 SANITIZER_INTERFACE_ATTRIBUTE
     43 void __msan_maybe_warning_2(u16 s, u32 o);
     44 SANITIZER_INTERFACE_ATTRIBUTE
     45 void __msan_maybe_warning_4(u32 s, u32 o);
     46 SANITIZER_INTERFACE_ATTRIBUTE
     47 void __msan_maybe_warning_8(u64 s, u32 o);
     48 
     49 SANITIZER_INTERFACE_ATTRIBUTE
     50 void __msan_maybe_store_origin_1(u8 s, void *p, u32 o);
     51 SANITIZER_INTERFACE_ATTRIBUTE
     52 void __msan_maybe_store_origin_2(u16 s, void *p, u32 o);
     53 SANITIZER_INTERFACE_ATTRIBUTE
     54 void __msan_maybe_store_origin_4(u32 s, void *p, u32 o);
     55 SANITIZER_INTERFACE_ATTRIBUTE
     56 void __msan_maybe_store_origin_8(u64 s, void *p, u32 o);
     57 
     58 SANITIZER_INTERFACE_ATTRIBUTE
     59 void __msan_unpoison(const void *a, uptr size);
     60 SANITIZER_INTERFACE_ATTRIBUTE
     61 void __msan_unpoison_string(const char *s);
     62 SANITIZER_INTERFACE_ATTRIBUTE
     63 void __msan_clear_and_unpoison(void *a, uptr size);
     64 SANITIZER_INTERFACE_ATTRIBUTE
     65 void* __msan_memcpy(void *dst, const void *src, uptr size);
     66 SANITIZER_INTERFACE_ATTRIBUTE
     67 void* __msan_memset(void *s, int c, uptr n);
     68 SANITIZER_INTERFACE_ATTRIBUTE
     69 void* __msan_memmove(void* dest, const void* src, uptr n);
     70 SANITIZER_INTERFACE_ATTRIBUTE
     71 void __msan_poison(const void *a, uptr size);
     72 SANITIZER_INTERFACE_ATTRIBUTE
     73 void __msan_poison_stack(void *a, uptr size);
     74 
     75 // Copy size bytes from src to dst and unpoison the result.
     76 // Useful to implement unsafe loads.
     77 SANITIZER_INTERFACE_ATTRIBUTE
     78 void __msan_load_unpoisoned(void *src, uptr size, void *dst);
     79 
     80 // Returns the offset of the first (at least partially) poisoned byte,
     81 // or -1 if the whole range is good.
     82 SANITIZER_INTERFACE_ATTRIBUTE
     83 sptr __msan_test_shadow(const void *x, uptr size);
     84 
     85 SANITIZER_INTERFACE_ATTRIBUTE
     86 void __msan_check_mem_is_initialized(const void *x, uptr size);
     87 
     88 SANITIZER_INTERFACE_ATTRIBUTE
     89 void __msan_set_origin(const void *a, uptr size, u32 origin);
     90 SANITIZER_INTERFACE_ATTRIBUTE
     91 void __msan_set_alloca_origin(void *a, uptr size, const char *descr);
     92 SANITIZER_INTERFACE_ATTRIBUTE
     93 void __msan_set_alloca_origin4(void *a, uptr size, const char *descr, uptr pc);
     94 SANITIZER_INTERFACE_ATTRIBUTE
     95 u32 __msan_chain_origin(u32 id);
     96 SANITIZER_INTERFACE_ATTRIBUTE
     97 u32 __msan_get_origin(const void *a);
     98 
     99 SANITIZER_INTERFACE_ATTRIBUTE
    100 void __msan_clear_on_return();
    101 
    102 // Default: -1 (don't exit on error).
    103 SANITIZER_INTERFACE_ATTRIBUTE
    104 void __msan_set_exit_code(int exit_code);
    105 
    106 SANITIZER_INTERFACE_ATTRIBUTE
    107 void __msan_set_keep_going(int keep_going);
    108 
    109 SANITIZER_INTERFACE_ATTRIBUTE
    110 int __msan_set_poison_in_malloc(int do_poison);
    111 
    112 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
    113 /* OPTIONAL */ const char* __msan_default_options();
    114 
    115 // For testing.
    116 SANITIZER_INTERFACE_ATTRIBUTE
    117 void __msan_set_expect_umr(int expect_umr);
    118 SANITIZER_INTERFACE_ATTRIBUTE
    119 void __msan_print_shadow(const void *x, uptr size);
    120 SANITIZER_INTERFACE_ATTRIBUTE
    121 void __msan_dump_shadow(const void *x, uptr size);
    122 SANITIZER_INTERFACE_ATTRIBUTE
    123 int  __msan_has_dynamic_component();
    124 
    125 // Returns x such that %fs:x is the first byte of __msan_retval_tls.
    126 SANITIZER_INTERFACE_ATTRIBUTE
    127 int __msan_get_retval_tls_offset();
    128 SANITIZER_INTERFACE_ATTRIBUTE
    129 int __msan_get_param_tls_offset();
    130 
    131 // For intercepting mmap from ld.so in msandr.
    132 SANITIZER_INTERFACE_ATTRIBUTE
    133 bool __msan_is_in_loader();
    134 
    135 // For testing.
    136 SANITIZER_INTERFACE_ATTRIBUTE
    137 u32 __msan_get_umr_origin();
    138 SANITIZER_INTERFACE_ATTRIBUTE
    139 void __msan_partial_poison(const void* data, void* shadow, uptr size);
    140 
    141 // Tell MSan about newly allocated memory (ex.: custom allocator).
    142 // Memory will be marked uninitialized, with origin at the call site.
    143 SANITIZER_INTERFACE_ATTRIBUTE
    144 void __msan_allocated_memory(const void* data, uptr size);
    145 
    146 SANITIZER_INTERFACE_ATTRIBUTE
    147 u16 __sanitizer_unaligned_load16(const uu16 *p);
    148 
    149 SANITIZER_INTERFACE_ATTRIBUTE
    150 u32 __sanitizer_unaligned_load32(const uu32 *p);
    151 
    152 SANITIZER_INTERFACE_ATTRIBUTE
    153 u64 __sanitizer_unaligned_load64(const uu64 *p);
    154 
    155 SANITIZER_INTERFACE_ATTRIBUTE
    156 void __sanitizer_unaligned_store16(uu16 *p, u16 x);
    157 
    158 SANITIZER_INTERFACE_ATTRIBUTE
    159 void __sanitizer_unaligned_store32(uu32 *p, u32 x);
    160 
    161 SANITIZER_INTERFACE_ATTRIBUTE
    162 void __sanitizer_unaligned_store64(uu64 *p, u64 x);
    163 
    164 // ---------------------------
    165 // FIXME: Replace these functions with __sanitizer equivalent.
    166 SANITIZER_INTERFACE_ATTRIBUTE
    167 uptr __msan_get_estimated_allocated_size(uptr size);
    168 SANITIZER_INTERFACE_ATTRIBUTE
    169 int __msan_get_ownership(const void *p);
    170 SANITIZER_INTERFACE_ATTRIBUTE
    171 uptr __msan_get_allocated_size(const void *p);
    172 SANITIZER_INTERFACE_ATTRIBUTE
    173 uptr __msan_get_current_allocated_bytes();
    174 SANITIZER_INTERFACE_ATTRIBUTE
    175 uptr __msan_get_heap_size();
    176 SANITIZER_INTERFACE_ATTRIBUTE
    177 uptr __msan_get_free_bytes();
    178 SANITIZER_INTERFACE_ATTRIBUTE
    179 uptr __msan_get_unmapped_bytes();
    180 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
    181 /* OPTIONAL */ void __msan_malloc_hook(void *ptr, uptr size);
    182 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
    183 /* OPTIONAL */ void __msan_free_hook(void *ptr);
    184 // ---------------------------
    185 
    186 SANITIZER_INTERFACE_ATTRIBUTE
    187 void __msan_dr_is_initialized();
    188 
    189 SANITIZER_INTERFACE_ATTRIBUTE
    190 void *__msan_wrap_indirect_call(void *target);
    191 
    192 SANITIZER_INTERFACE_ATTRIBUTE
    193 void __msan_set_indirect_call_wrapper(uptr wrapper);
    194 
    195 SANITIZER_INTERFACE_ATTRIBUTE
    196 void __msan_set_death_callback(void (*callback)(void));
    197 }  // extern "C"
    198 
    199 #endif  // MSAN_INTERFACE_INTERNAL_H
    200