InternalCalls.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "il2cpp-config.h"
  2. #include "vm/InternalCalls.h"
  3. #include "vm/Runtime.h"
  4. #include <map>
  5. #include <string>
  6. typedef std::map<std::string, Il2CppMethodPointer> ICallMap;
  7. static ICallMap s_InternalCalls;
  8. namespace il2cpp
  9. {
  10. namespace vm
  11. {
  12. void InternalCalls::Add(const char* name, Il2CppMethodPointer method)
  13. {
  14. //ICallMap::iterator res = s_InternalCalls.find(name);
  15. // TODO: Don't assert right now because Unity adds some icalls multiple times.
  16. //if (res != icalls.end())
  17. // IL2CPP_ASSERT(0 && "Adding internal call twice!");
  18. IL2CPP_ASSERT(method);
  19. s_InternalCalls[name] = method;
  20. #if IL2CPP_ENABLE_MEM_STATS
  21. il2cpp_mem_stats.interal_calls_total = s_InternalCalls.size();
  22. #endif
  23. }
  24. Il2CppMethodPointer InternalCalls::Resolve(const char* name)
  25. {
  26. // Try to find the whole name first, then search using just type::method
  27. // if parameters were passed
  28. // ex: First, System.Foo::Bar(System.Int32)
  29. // Then, System.Foo::Bar
  30. ICallMap::iterator res = s_InternalCalls.find(name);
  31. if (res != s_InternalCalls.end())
  32. {
  33. #if IL2CPP_ENABLE_MEM_STATS
  34. ++il2cpp_mem_stats.interal_calls_resolved;
  35. #endif
  36. return res->second;
  37. }
  38. std::string shortName(name);
  39. size_t index = shortName.find('(');
  40. if (index != std::string::npos)
  41. {
  42. shortName = shortName.substr(0, index);
  43. res = s_InternalCalls.find(shortName);
  44. if (res != s_InternalCalls.end())
  45. {
  46. #if IL2CPP_ENABLE_MEM_STATS
  47. ++il2cpp_mem_stats.interal_calls_resolved;
  48. #endif
  49. return res->second;
  50. }
  51. }
  52. return NULL;
  53. }
  54. #if IL2CPP_ENABLE_MEM_STATS
  55. size_t InternalCalls::GetInternalCallsCount() {
  56. return s_InternalCalls.size();
  57. }
  58. #endif //#if IL2CPP_ENABLE_MEM_STATS
  59. } /* namespace vm */
  60. } /* namespace il2cpp */