dart_api_dl.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
  3. * for details. All rights reserved. Use of this source code is governed by a
  4. * BSD-style license that can be found in the LICENSE file.
  5. */
  6. #ifndef RUNTIME_INCLUDE_DART_API_DL_H_
  7. #define RUNTIME_INCLUDE_DART_API_DL_H_
  8. #include "dart_api.h" /* NOLINT */
  9. #include "dart_native_api.h" /* NOLINT */
  10. /** \mainpage Dynamically Linked Dart API
  11. *
  12. * This exposes a subset of symbols from dart_api.h and dart_native_api.h
  13. * available in every Dart embedder through dynamic linking.
  14. *
  15. * All symbols are postfixed with _DL to indicate that they are dynamically
  16. * linked and to prevent conflicts with the original symbol.
  17. *
  18. * Link `dart_api_dl.c` file into your library and invoke
  19. * `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`.
  20. */
  21. DART_EXPORT intptr_t Dart_InitializeApiDL(void* data);
  22. // ============================================================================
  23. // IMPORTANT! Never update these signatures without properly updating
  24. // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
  25. //
  26. // Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types
  27. // to trigger compile-time errors if the symbols in those files are updated
  28. // without updating these.
  29. //
  30. // Function return and argument types, and typedefs are carbon copied. Structs
  31. // are typechecked nominally in C/C++, so they are not copied, instead a
  32. // comment is added to their definition.
  33. typedef int64_t Dart_Port_DL;
  34. typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id,
  35. Dart_CObject* message);
  36. // dart_native_api.h symbols can be called on any thread.
  37. #define DART_NATIVE_API_DL_SYMBOLS(F) \
  38. /***** dart_native_api.h *****/ \
  39. /* Dart_Port */ \
  40. F(Dart_PostCObject, bool, (Dart_Port_DL port_id, Dart_CObject * message)) \
  41. F(Dart_PostInteger, bool, (Dart_Port_DL port_id, int64_t message)) \
  42. F(Dart_NewNativePort, Dart_Port_DL, \
  43. (const char* name, Dart_NativeMessageHandler_DL handler, \
  44. bool handle_concurrently)) \
  45. F(Dart_CloseNativePort, bool, (Dart_Port_DL native_port_id))
  46. // dart_api.h symbols can only be called on Dart threads.
  47. #define DART_API_DL_SYMBOLS(F) \
  48. /***** dart_api.h *****/ \
  49. /* Errors */ \
  50. F(Dart_IsError, bool, (Dart_Handle handle)) \
  51. F(Dart_IsApiError, bool, (Dart_Handle handle)) \
  52. F(Dart_IsUnhandledExceptionError, bool, (Dart_Handle handle)) \
  53. F(Dart_IsCompilationError, bool, (Dart_Handle handle)) \
  54. F(Dart_IsFatalError, bool, (Dart_Handle handle)) \
  55. F(Dart_GetError, const char*, (Dart_Handle handle)) \
  56. F(Dart_ErrorHasException, bool, (Dart_Handle handle)) \
  57. F(Dart_ErrorGetException, Dart_Handle, (Dart_Handle handle)) \
  58. F(Dart_ErrorGetStackTrace, Dart_Handle, (Dart_Handle handle)) \
  59. F(Dart_NewApiError, Dart_Handle, (const char* error)) \
  60. F(Dart_NewCompilationError, Dart_Handle, (const char* error)) \
  61. F(Dart_NewUnhandledExceptionError, Dart_Handle, (Dart_Handle exception)) \
  62. F(Dart_PropagateError, void, (Dart_Handle handle)) \
  63. /* Dart_Handle, Dart_PersistentHandle, Dart_WeakPersistentHandle */ \
  64. F(Dart_HandleFromPersistent, Dart_Handle, (Dart_PersistentHandle object)) \
  65. F(Dart_HandleFromWeakPersistent, Dart_Handle, \
  66. (Dart_WeakPersistentHandle object)) \
  67. F(Dart_NewPersistentHandle, Dart_PersistentHandle, (Dart_Handle object)) \
  68. F(Dart_SetPersistentHandle, void, \
  69. (Dart_PersistentHandle obj1, Dart_Handle obj2)) \
  70. F(Dart_DeletePersistentHandle, void, (Dart_PersistentHandle object)) \
  71. F(Dart_NewWeakPersistentHandle, Dart_WeakPersistentHandle, \
  72. (Dart_Handle object, void* peer, intptr_t external_allocation_size, \
  73. Dart_HandleFinalizer callback)) \
  74. F(Dart_DeleteWeakPersistentHandle, void, (Dart_WeakPersistentHandle object)) \
  75. F(Dart_UpdateExternalSize, void, \
  76. (Dart_WeakPersistentHandle object, intptr_t external_allocation_size)) \
  77. F(Dart_NewFinalizableHandle, Dart_FinalizableHandle, \
  78. (Dart_Handle object, void* peer, intptr_t external_allocation_size, \
  79. Dart_HandleFinalizer callback)) \
  80. F(Dart_DeleteFinalizableHandle, void, \
  81. (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object)) \
  82. F(Dart_UpdateFinalizableExternalSize, void, \
  83. (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \
  84. intptr_t external_allocation_size)) \
  85. /* Isolates */ \
  86. F(Dart_CurrentIsolate, Dart_Isolate, (void)) \
  87. F(Dart_ExitIsolate, void, (void)) \
  88. F(Dart_EnterIsolate, void, (Dart_Isolate)) \
  89. /* Dart_Port */ \
  90. F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \
  91. F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \
  92. F(Dart_SendPortGetId, Dart_Handle, \
  93. (Dart_Handle port, Dart_Port_DL * port_id)) \
  94. /* Scopes */ \
  95. F(Dart_EnterScope, void, (void)) \
  96. F(Dart_ExitScope, void, (void)) \
  97. /* Objects */ \
  98. F(Dart_IsNull, bool, (Dart_Handle))
  99. #define DART_API_ALL_DL_SYMBOLS(F) \
  100. DART_NATIVE_API_DL_SYMBOLS(F) \
  101. DART_API_DL_SYMBOLS(F)
  102. // IMPORTANT! Never update these signatures without properly updating
  103. // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
  104. //
  105. // End of verbatim copy.
  106. // ============================================================================
  107. // Copy of definition of DART_EXPORT without 'used' attribute.
  108. //
  109. // The 'used' attribute cannot be used with DART_API_ALL_DL_SYMBOLS because
  110. // they are not function declarations, but variable declarations with a
  111. // function pointer type.
  112. //
  113. // The function pointer variables are initialized with the addresses of the
  114. // functions in the VM. If we were to use function declarations instead, we
  115. // would need to forward the call to the VM adding indirection.
  116. #if defined(__CYGWIN__)
  117. #error Tool chain and platform not supported.
  118. #elif defined(_WIN32)
  119. #if defined(DART_SHARED_LIB)
  120. #define DART_EXPORT_DL DART_EXTERN_C __declspec(dllexport)
  121. #else
  122. #define DART_EXPORT_DL DART_EXTERN_C
  123. #endif
  124. #else
  125. #if __GNUC__ >= 4
  126. #if defined(DART_SHARED_LIB)
  127. #define DART_EXPORT_DL DART_EXTERN_C __attribute__((visibility("default")))
  128. #else
  129. #define DART_EXPORT_DL DART_EXTERN_C
  130. #endif
  131. #else
  132. #error Tool chain not supported.
  133. #endif
  134. #endif
  135. #define DART_API_DL_DECLARATIONS(name, R, A) \
  136. typedef R(*name##_Type) A; \
  137. DART_EXPORT_DL name##_Type name##_DL;
  138. DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS)
  139. #undef DART_API_DL_DECLARATIONS
  140. #undef DART_EXPORT_DL
  141. #endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */