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_unpoison(const void *a, uptr size);
     42 SANITIZER_INTERFACE_ATTRIBUTE
     43 void __msan_clear_and_unpoison(void *a, uptr size);
     44 SANITIZER_INTERFACE_ATTRIBUTE
     45 void* __msan_memcpy(void *dst, const void *src, uptr size);
     46 SANITIZER_INTERFACE_ATTRIBUTE
     47 void* __msan_memset(void *s, int c, uptr n);
     48 SANITIZER_INTERFACE_ATTRIBUTE
     49 void* __msan_memmove(void* dest, const void* src, uptr n);
     50 SANITIZER_INTERFACE_ATTRIBUTE
     51 void __msan_copy_poison(void *dst, const void *src, uptr size);
     52 SANITIZER_INTERFACE_ATTRIBUTE
     53 void __msan_copy_origin(void *dst, const void *src, uptr size);
     54 SANITIZER_INTERFACE_ATTRIBUTE
     55 void __msan_move_poison(void *dst, const void *src, uptr size);
     56 SANITIZER_INTERFACE_ATTRIBUTE
     57 void __msan_poison(const void *a, uptr size);
     58 SANITIZER_INTERFACE_ATTRIBUTE
     59 void __msan_poison_stack(void *a, uptr size);
     60 
     61 // Copy size bytes from src to dst and unpoison the result.
     62 // Useful to implement unsafe loads.
     63 SANITIZER_INTERFACE_ATTRIBUTE
     64 void __msan_load_unpoisoned(void *src, uptr size, void *dst);
     65 
     66 // Returns the offset of the first (at least partially) poisoned byte,
     67 // or -1 if the whole range is good.
     68 SANITIZER_INTERFACE_ATTRIBUTE
     69 sptr __msan_test_shadow(const void *x, uptr size);
     70 
     71 SANITIZER_INTERFACE_ATTRIBUTE
     72 void __msan_set_origin(const void *a, uptr size, u32 origin);
     73 SANITIZER_INTERFACE_ATTRIBUTE
     74 void __msan_set_alloca_origin(void *a, uptr size, const char *descr);
     75 SANITIZER_INTERFACE_ATTRIBUTE
     76 u32 __msan_get_origin(const void *a);
     77 
     78 SANITIZER_INTERFACE_ATTRIBUTE
     79 void __msan_clear_on_return();
     80 
     81 // Default: -1 (don't exit on error).
     82 SANITIZER_INTERFACE_ATTRIBUTE
     83 void __msan_set_exit_code(int exit_code);
     84 
     85 SANITIZER_INTERFACE_ATTRIBUTE
     86 void __msan_set_keep_going(int keep_going);
     87 
     88 SANITIZER_INTERFACE_ATTRIBUTE
     89 int __msan_set_poison_in_malloc(int do_poison);
     90 
     91 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
     92 /* OPTIONAL */ const char* __msan_default_options();
     93 
     94 // For testing.
     95 SANITIZER_INTERFACE_ATTRIBUTE
     96 void __msan_set_expect_umr(int expect_umr);
     97 SANITIZER_INTERFACE_ATTRIBUTE
     98 void __msan_print_shadow(const void *x, uptr size);
     99 SANITIZER_INTERFACE_ATTRIBUTE
    100 void __msan_print_param_shadow();
    101 SANITIZER_INTERFACE_ATTRIBUTE
    102 int  __msan_has_dynamic_component();
    103 
    104 // Returns x such that %fs:x is the first byte of __msan_retval_tls.
    105 SANITIZER_INTERFACE_ATTRIBUTE
    106 int __msan_get_retval_tls_offset();
    107 SANITIZER_INTERFACE_ATTRIBUTE
    108 int __msan_get_param_tls_offset();
    109 
    110 // For intercepting mmap from ld.so in msandr.
    111 SANITIZER_INTERFACE_ATTRIBUTE
    112 bool __msan_is_in_loader();
    113 
    114 // For testing.
    115 SANITIZER_INTERFACE_ATTRIBUTE
    116 u32 __msan_get_umr_origin();
    117 SANITIZER_INTERFACE_ATTRIBUTE
    118 const char *__msan_get_origin_descr_if_stack(u32 id);
    119 SANITIZER_INTERFACE_ATTRIBUTE
    120 void __msan_partial_poison(const void* data, void* shadow, uptr size);
    121 
    122 // Tell MSan about newly allocated memory (ex.: custom allocator).
    123 // Memory will be marked uninitialized, with origin at the call site.
    124 SANITIZER_INTERFACE_ATTRIBUTE
    125 void __msan_allocated_memory(const void* data, uptr size);
    126 
    127 SANITIZER_INTERFACE_ATTRIBUTE
    128 u16 __sanitizer_unaligned_load16(const uu16 *p);
    129 
    130 SANITIZER_INTERFACE_ATTRIBUTE
    131 u32 __sanitizer_unaligned_load32(const uu32 *p);
    132 
    133 SANITIZER_INTERFACE_ATTRIBUTE
    134 u64 __sanitizer_unaligned_load64(const uu64 *p);
    135 
    136 SANITIZER_INTERFACE_ATTRIBUTE
    137 void __sanitizer_unaligned_store16(uu16 *p, u16 x);
    138 
    139 SANITIZER_INTERFACE_ATTRIBUTE
    140 void __sanitizer_unaligned_store32(uu32 *p, u32 x);
    141 
    142 SANITIZER_INTERFACE_ATTRIBUTE
    143 void __sanitizer_unaligned_store64(uu64 *p, u64 x);
    144 
    145 SANITIZER_INTERFACE_ATTRIBUTE
    146 uptr __msan_get_estimated_allocated_size(uptr size);
    147 
    148 SANITIZER_INTERFACE_ATTRIBUTE
    149 bool __msan_get_ownership(const void *p);
    150 
    151 SANITIZER_INTERFACE_ATTRIBUTE
    152 uptr __msan_get_allocated_size(const void *p);
    153 
    154 SANITIZER_INTERFACE_ATTRIBUTE
    155 uptr __msan_get_current_allocated_bytes();
    156 
    157 SANITIZER_INTERFACE_ATTRIBUTE
    158 uptr __msan_get_heap_size();
    159 
    160 SANITIZER_INTERFACE_ATTRIBUTE
    161 uptr __msan_get_free_bytes();
    162 
    163 SANITIZER_INTERFACE_ATTRIBUTE
    164 uptr __msan_get_unmapped_bytes();
    165 
    166 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
    167 /* OPTIONAL */ void __msan_malloc_hook(void *ptr, uptr size);
    168 
    169 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
    170 /* OPTIONAL */ void __msan_free_hook(void *ptr);
    171 }  // extern "C"
    172 
    173 #endif  // MSAN_INTERFACE_INTERNAL_H
    174