LibraryLoader.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #include "il2cpp-pinvoke-support.h"
  4. #include "utils/StringView.h"
  5. #include <string>
  6. #include "Baselib.h"
  7. #include "Cpp/Baselib_DynamicLibrary.h"
  8. #if !RUNTIME_TINY
  9. #include "Cpp/ReentrantLock.h"
  10. #include <vector>
  11. #include <string>
  12. #endif
  13. namespace il2cpp
  14. {
  15. namespace os
  16. {
  17. struct HardcodedPInvokeDependencyFunction
  18. {
  19. const char* functionName;
  20. Il2CppMethodPointer functionPointer;
  21. };
  22. struct HardcodedPInvokeDependencyLibrary
  23. {
  24. const Il2CppNativeChar* libraryName;
  25. size_t functionCount;
  26. const HardcodedPInvokeDependencyFunction* functions;
  27. };
  28. #define HARDCODED_DEPENDENCY_LIBRARY(libraryName, libraryFunctions) { libraryName, sizeof(libraryFunctions) / sizeof(HardcodedPInvokeDependencyFunction), libraryFunctions }
  29. #define HARDCODED_DEPENDENCY_FUNCTION(function) { #function, reinterpret_cast<Il2CppMethodPointer>(function) }
  30. class LibraryLoader
  31. {
  32. public:
  33. static Il2CppMethodPointer GetHardcodedPInvokeDependencyFunctionPointer(const il2cpp::utils::StringView<Il2CppNativeChar>& nativeDynamicLibrary, const il2cpp::utils::StringView<char>& entryPoint);
  34. static Baselib_DynamicLibrary_Handle LoadDynamicLibrary(const utils::StringView<Il2CppNativeChar> nativeDynamicLibrary, std::string& detailedError);
  35. static Il2CppMethodPointer GetFunctionPointer(Baselib_DynamicLibrary_Handle handle, const PInvokeArguments& pinvokeArgs, std::string& detailedError);
  36. static Il2CppMethodPointer GetFunctionPointer(Baselib_DynamicLibrary_Handle handle, const char* functionName, std::string& detailedError);
  37. static void CleanupLoadedLibraries();
  38. static bool CloseLoadedLibrary(Baselib_DynamicLibrary_Handle handle);
  39. static void SetFindPluginCallback(Il2CppSetFindPlugInCallback method);
  40. static Baselib_DynamicLibrary_Handle TryOpeningLibrary(const Il2CppNativeChar* libraryName, std::string& detailedError);
  41. private:
  42. static Baselib_DynamicLibrary_Handle ProbeForLibrary(const Il2CppNativeChar* libraryName, const size_t libraryNameLength, std::string& detailedError);
  43. // needsClosing defaults to true, only set it to false when needed
  44. static Baselib_DynamicLibrary_Handle OpenProgramHandle(Baselib_ErrorState& errorState, bool& needsClosing);
  45. static const HardcodedPInvokeDependencyLibrary* HardcodedPInvokeDependencies;
  46. static const size_t HardcodedPInvokeDependenciesCount;
  47. };
  48. } /* namespace os */
  49. } /* namespace il2cpp*/