dart_api_dl.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "dart_api_dl.h" /* NOLINT */
  7. #include "dart_version.h" /* NOLINT */
  8. #include "internal/dart_api_dl_impl.h" /* NOLINT */
  9. #include <string.h>
  10. #define DART_API_DL_DEFINITIONS(name, R, A) name##_Type name##_DL = NULL;
  11. DART_API_ALL_DL_SYMBOLS(DART_API_DL_DEFINITIONS)
  12. #undef DART_API_DL_DEFINITIONS
  13. typedef void* DartApiEntry_function;
  14. DartApiEntry_function FindFunctionPointer(const DartApiEntry* entries,
  15. const char* name) {
  16. while (entries->name != NULL) {
  17. if (strcmp(entries->name, name) == 0) return entries->function;
  18. entries++;
  19. }
  20. return NULL;
  21. }
  22. intptr_t Dart_InitializeApiDL(void* data) {
  23. DartApi* dart_api_data = (DartApi*)data;
  24. if (dart_api_data->major != DART_API_DL_MAJOR_VERSION) {
  25. // If the DartVM we're running on does not have the same version as this
  26. // file was compiled against, refuse to initialize. The symbols are not
  27. // compatible.
  28. return -1;
  29. }
  30. // Minor versions are allowed to be different.
  31. // If the DartVM has a higher minor version, it will provide more symbols
  32. // than we initialize here.
  33. // If the DartVM has a lower minor version, it will not provide all symbols.
  34. // In that case, we leave the missing symbols un-initialized. Those symbols
  35. // should not be used by the Dart and native code. The client is responsible
  36. // for checking the minor version number himself based on which symbols it
  37. // is using.
  38. // (If we would error out on this case, recompiling native code against a
  39. // newer SDK would break all uses on older SDKs, which is too strict.)
  40. const DartApiEntry* dart_api_function_pointers = dart_api_data->functions;
  41. #define DART_API_DL_INIT(name, R, A) \
  42. name##_DL = \
  43. (name##_Type)(FindFunctionPointer(dart_api_function_pointers, #name));
  44. DART_API_ALL_DL_SYMBOLS(DART_API_DL_INIT)
  45. #undef DART_API_DL_INIT
  46. return 0;
  47. }