gc_boehm.c raw

   1  //go:build none
   2  
   3  // This file is included in the build on systems that support the Boehm GC,
   4  // despite the //go:build line above.
   5  
   6  #include <stdint.h>
   7  
   8  typedef void (* GC_push_other_roots_proc)(void);
   9  void GC_set_push_other_roots(GC_push_other_roots_proc);
  10  
  11  typedef void(* GC_warn_proc)(const char *msg, uintptr_t arg);
  12  void GC_set_warn_proc(GC_warn_proc p);
  13  
  14  void moxie_runtime_bdwgc_callback(void);
  15  
  16  static void callback(void) {
  17      moxie_runtime_bdwgc_callback();
  18  }
  19  
  20  static void warn_proc(const char *msg, uintptr_t arg) {
  21  }
  22  
  23  void moxie_runtime_bdwgc_init(void) {
  24      GC_set_push_other_roots(callback);
  25  #if defined(__wasm__)
  26      // There are a lot of warnings on WebAssembly in the form:
  27      //
  28      //     GC Warning: Repeated allocation of very large block (appr. size 68 KiB):
  29      //         May lead to memory leak and poor performance
  30      //
  31      // The usual advice is to use something like GC_malloc_ignore_off_page but
  32      // unfortunately for most allocations that's not allowed: Go allocations can
  33      // legitimately hold pointers further than one page in the allocation. So
  34      // instead we just disable the warning.
  35      GC_set_warn_proc(warn_proc);
  36  #endif
  37  }
  38