You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.3 KiB

  1. /*
  2. * mono.h -- Definitions for Mono C API functions.
  3. *
  4. * The file contains definitions for some of functions provided by Mono C API.
  5. *
  6. * Note: Since we don't use any mono headers, all pointers to mono-related structs are
  7. * replaced with void *.
  8. */
  9. #pragma once
  10. #pragma warning( disable : 4152 )
  11. #include <windows.h>
  12. // Creates a MonoString based from a C wide string
  13. #define MONO_STRING(str) mono_string_new_utf16(domain, str, wcslen(str))
  14. // Set MonoArray's index to a reference type value (i.e. string)
  15. #define SET_ARRAY_REF(arr, index, refVal) \
  16. { \
  17. void **p = (void**) mono_array_addr_with_size(arr, sizeof(void*), index); \
  18. mono_gc_wbarrier_set_arrayref(arr, p, refVal); \
  19. }
  20. // Here we define the pointers to some functions within mono.dll
  21. // Note to C learners: these are not signature definitions, but rather "variable"
  22. // definitions with the function pointer type.
  23. // Note: we use void* instead of the real intented structs defined in mono API
  24. // This way we don't need to include or define any of Mono's structs, which saves space
  25. // This, obviously, comes with a drawback of not being able to easily access the contents of the structs
  26. typedef enum {
  27. MONO_DEBUG_FORMAT_NONE,
  28. MONO_DEBUG_FORMAT_MONO,
  29. /* Deprecated, the mdb debugger is not longer supported. */
  30. MONO_DEBUG_FORMAT_DEBUGGER
  31. } MonoDebugFormat;
  32. void (*mono_jit_parse_options)(int argc, char * argv[]);
  33. void (*mono_debug_init)(MonoDebugFormat format);
  34. void (*mono_debug_domain_create)(void*);
  35. void *(*mono_jit_init_version)(const char *root_domain_name, const char *runtime_version);
  36. void *(*mono_domain_assembly_open)(void *domain, const char *name);
  37. void *(*mono_assembly_get_image)(void *assembly);
  38. void *(*mono_runtime_invoke)(void *method, void *obj, void **params, void **exc);
  39. void *(*mono_method_desc_new)(const char *name, int include_namespace);
  40. void *(*mono_method_desc_search_in_image)(void *desc, void *image);
  41. void *(*mono_method_signature)(void *method);
  42. UINT32 (*mono_signature_get_param_count)(void *sig);
  43. void *(*mono_array_new)(void *domain, void *eclass, uintptr_t n);
  44. void (*mono_gc_wbarrier_set_arrayref)(void *arr, void *slot_ptr, void *value);
  45. char *(*mono_array_addr_with_size)(void *arr, int size, uintptr_t idx);
  46. void *(*mono_get_string_class)();
  47. void *(*mono_string_new_utf16)(void *domain, const wchar_t *text, INT32 len);
  48. void* (*mono_object_to_string)(void* obj, void** exc);
  49. void (*mono_dllmap_insert)(void* assemblyImage, const char* dll, const char* func, const char* tdll, const char* tfunc);
  50. char* (*mono_string_to_utf8)(void* str);
  51. wchar_t* (*mono_string_to_utf16)(void* str);
  52. void (*mono_free)(void*);
  53. /* Installs a function which is called when the runtime encounters an unhandled exception.
  54. * This hook isn't expected to return.
  55. * If no hook has been installed, the runtime will print a message before aborting.
  56. */
  57. typedef void (*MonoUnhandledExceptionFunc)(void* exc, void* user_data);
  58. void (*mono_install_unhandled_exception_hook)(MonoUnhandledExceptionFunc func, void* user_data);
  59. /**
  60. * \brief Loads Mono C API function pointers so that the above definitions can be called.
  61. * \param monoLib Mono.dll module.
  62. */
  63. inline void loadMonoFunctions(HMODULE monoLib)
  64. {
  65. // Enjoy the fact that C allows such sloppy casting
  66. // In C++ you would have to cast to the precise function pointer type
  67. #define GET_MONO_PROC(name) name = (void*)GetProcAddress(monoLib, #name)
  68. // Find and assign all our functions that we are going to use
  69. GET_MONO_PROC(mono_debug_domain_create);
  70. GET_MONO_PROC(mono_domain_assembly_open);
  71. GET_MONO_PROC(mono_assembly_get_image);
  72. GET_MONO_PROC(mono_runtime_invoke);
  73. GET_MONO_PROC(mono_debug_init);
  74. GET_MONO_PROC(mono_jit_init_version);
  75. GET_MONO_PROC(mono_jit_parse_options);
  76. GET_MONO_PROC(mono_method_desc_new);
  77. GET_MONO_PROC(mono_method_desc_search_in_image);
  78. GET_MONO_PROC(mono_method_signature);
  79. GET_MONO_PROC(mono_signature_get_param_count);
  80. GET_MONO_PROC(mono_array_new);
  81. GET_MONO_PROC(mono_get_string_class);
  82. GET_MONO_PROC(mono_string_new_utf16);
  83. GET_MONO_PROC(mono_gc_wbarrier_set_arrayref);
  84. GET_MONO_PROC(mono_array_addr_with_size);
  85. GET_MONO_PROC(mono_object_to_string);
  86. GET_MONO_PROC(mono_string_to_utf8);
  87. GET_MONO_PROC(mono_string_to_utf16);
  88. GET_MONO_PROC(mono_free);
  89. GET_MONO_PROC(mono_dllmap_insert);
  90. GET_MONO_PROC(mono_install_unhandled_exception_hook);
  91. }