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