Home | History | Annotate | Download | only in tests
      1 //===-- msan_loadable.cc --------------------------------------------------===//
      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 // MemorySanitizer unit tests.
     13 //===----------------------------------------------------------------------===//
     14 
     15 #include "msan/msan_interface_internal.h"
     16 #include <stdlib.h>
     17 
     18 static void *dso_global;
     19 
     20 // No name mangling.
     21 extern "C" {
     22 
     23 __attribute__((constructor))
     24 void loadable_module_init(void) {
     25   if (!__msan_has_dynamic_component())
     26     return;
     27   // The real test is that this compare should not make an uninit.
     28   if (dso_global == NULL)
     29     dso_global = malloc(4);
     30 }
     31 
     32 __attribute__((destructor))
     33 void loadable_module_fini(void) {
     34   if (!__msan_has_dynamic_component())
     35     return;
     36   free(dso_global);
     37   // *Don't* overwrite it with NULL!  That would unpoison it, but our test
     38   // relies on reloading at the same address and keeping the poison.
     39 }
     40 
     41 void **get_dso_global() {
     42   return &dso_global;
     43 }
     44 
     45 }
     46