il2cpp-api.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. #include "il2cpp-api.h"
  2. #include "il2cpp-object-internals.h"
  3. #include "il2cpp-runtime-stats.h"
  4. #include "gc/WriteBarrier.h"
  5. #include "os/StackTrace.h"
  6. #include "os/Image.h"
  7. #include "vm/AndroidRuntime.h"
  8. #include "vm/Array.h"
  9. #include "vm/Assembly.h"
  10. #include "vm/Class.h"
  11. #include "vm/Domain.h"
  12. #include "vm/Exception.h"
  13. #include "vm/Field.h"
  14. #include "vm/Image.h"
  15. #include "vm/InternalCalls.h"
  16. #include "vm/Liveness.h"
  17. #include "vm/MemoryInformation.h"
  18. #include "vm/Method.h"
  19. #include "vm/Monitor.h"
  20. #include "vm/Object.h"
  21. #include "vm/Path.h"
  22. #include "vm/PlatformInvoke.h"
  23. #include "vm/Profiler.h"
  24. #include "vm/Property.h"
  25. #include "vm/Reflection.h"
  26. #include "vm/Runtime.h"
  27. #include "vm/StackTrace.h"
  28. #include "vm/String.h"
  29. #include "vm/Thread.h"
  30. #include "vm/Type.h"
  31. #include "utils/Exception.h"
  32. #include "utils/Logging.h"
  33. #include "utils/Memory.h"
  34. #include "utils/StringUtils.h"
  35. #include "utils/Runtime.h"
  36. #include "utils/Environment.h"
  37. #include "vm-utils/Debugger.h"
  38. #include "vm-utils/NativeSymbol.h"
  39. #include "gc/GarbageCollector.h"
  40. #include "gc/GCHandle.h"
  41. #include "gc/WriteBarrierValidation.h"
  42. #include <locale.h>
  43. #include <fstream>
  44. #include <string>
  45. using namespace il2cpp::vm;
  46. using il2cpp::utils::Memory;
  47. using namespace il2cpp::gc;
  48. #if IL2CPP_API_DYNAMIC_NO_DLSYM
  49. #include <map>
  50. struct SymbolCompare : public std::binary_function<char*, char*, bool>
  51. {
  52. bool operator()(const char* lhs, const char* rhs) const
  53. {
  54. return strcmp(lhs, rhs) < 0;
  55. }
  56. };
  57. typedef std::map<const char*, void*, SymbolCompare> SymbolTable;
  58. static SymbolTable s_SymbolTable;
  59. static void RegisterAPIFunction(const char* name, void* symbol)
  60. {
  61. s_SymbolTable.insert(std::make_pair(name, symbol));
  62. }
  63. void il2cpp_api_register_symbols(void)
  64. {
  65. #define DO_API(r, n, p) RegisterAPIFunction(#n, (void*)n);
  66. #define DO_API_NO_RETURN(r, n, p) DO_API(r, n, p)
  67. #include "il2cpp-api-functions.h"
  68. #undef DO_API
  69. #undef DO_API_NO_RETURN
  70. }
  71. void* il2cpp_api_lookup_symbol(const char* name)
  72. {
  73. SymbolTable::iterator it = s_SymbolTable.find(name);
  74. if (it != s_SymbolTable.end())
  75. {
  76. return it->second;
  77. }
  78. return NULL;
  79. }
  80. #endif // IL2CPP_API_DYNAMIC_NO_DLSYM
  81. int il2cpp_init(const char* domain_name)
  82. {
  83. // Use environment's default locale
  84. setlocale(LC_ALL, "");
  85. return Runtime::Init(domain_name);
  86. }
  87. int il2cpp_init_utf16(const Il2CppChar* domain_name)
  88. {
  89. return il2cpp_init(il2cpp::utils::StringUtils::Utf16ToUtf8(domain_name).c_str());
  90. }
  91. void il2cpp_shutdown()
  92. {
  93. Runtime::Shutdown();
  94. }
  95. void il2cpp_set_config_dir(const char *config_path)
  96. {
  97. il2cpp::vm::Runtime::SetConfigDir(config_path);
  98. }
  99. void il2cpp_set_data_dir(const char *data_path)
  100. {
  101. il2cpp::utils::Runtime::SetDataDir(data_path);
  102. }
  103. void il2cpp_set_temp_dir(const char *temp_dir)
  104. {
  105. il2cpp::vm::Path::SetTempPath(temp_dir);
  106. }
  107. void il2cpp_set_commandline_arguments(int argc, const char* const argv[], const char* basedir)
  108. {
  109. il2cpp::utils::Environment::SetMainArgs(argv, argc);
  110. }
  111. void il2cpp_set_commandline_arguments_utf16(int argc, const Il2CppChar* const argv[], const char* basedir)
  112. {
  113. il2cpp::utils::Environment::SetMainArgs(argv, argc);
  114. }
  115. void il2cpp_set_config_utf16(const Il2CppChar* executablePath)
  116. {
  117. il2cpp::vm::Runtime::SetConfigUtf16(executablePath);
  118. }
  119. void il2cpp_set_config(const char* executablePath)
  120. {
  121. il2cpp::vm::Runtime::SetConfig(executablePath);
  122. }
  123. void il2cpp_set_memory_callbacks(Il2CppMemoryCallbacks* callbacks)
  124. {
  125. Memory::SetMemoryCallbacks(callbacks);
  126. }
  127. const Il2CppImage* il2cpp_get_corlib()
  128. {
  129. return Image::GetCorlib();
  130. }
  131. void il2cpp_add_internal_call(const char* name, Il2CppMethodPointer method)
  132. {
  133. return InternalCalls::Add(name, method);
  134. }
  135. Il2CppMethodPointer il2cpp_resolve_icall(const char* name)
  136. {
  137. return InternalCalls::Resolve(name);
  138. }
  139. void* il2cpp_alloc(size_t size)
  140. {
  141. return IL2CPP_MALLOC(size);
  142. }
  143. void il2cpp_free(void* ptr)
  144. {
  145. IL2CPP_FREE(ptr);
  146. }
  147. // array
  148. Il2CppClass *il2cpp_array_class_get(Il2CppClass *element_class, uint32_t rank)
  149. {
  150. return Class::GetArrayClass(element_class, rank);
  151. }
  152. uint32_t il2cpp_array_length(Il2CppArray* array)
  153. {
  154. return Array::GetLength(array);
  155. }
  156. uint32_t il2cpp_array_get_byte_length(Il2CppArray *array)
  157. {
  158. return Array::GetByteLength(array);
  159. }
  160. Il2CppArray* il2cpp_array_new(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
  161. {
  162. return Array::New(elementTypeInfo, length);
  163. }
  164. Il2CppArray* il2cpp_array_new_specific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length)
  165. {
  166. return Array::NewSpecific(arrayTypeInfo, length);
  167. }
  168. Il2CppArray* il2cpp_array_new_full(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds)
  169. {
  170. return Array::NewFull(array_class, lengths, lower_bounds);
  171. }
  172. Il2CppClass* il2cpp_bounded_array_class_get(Il2CppClass *element_class, uint32_t rank, bool bounded)
  173. {
  174. return Class::GetBoundedArrayClass(element_class, rank, bounded);
  175. }
  176. int il2cpp_array_element_size(const Il2CppClass* klass)
  177. {
  178. return Array::GetElementSize(klass);
  179. }
  180. // assembly
  181. const Il2CppImage* il2cpp_assembly_get_image(const Il2CppAssembly *assembly)
  182. {
  183. return Assembly::GetImage(assembly);
  184. }
  185. // class
  186. const Il2CppType* il2cpp_class_enum_basetype(Il2CppClass *klass)
  187. {
  188. return Class::GetEnumBaseType(klass);
  189. }
  190. Il2CppClass* il2cpp_class_from_system_type(Il2CppReflectionType *type)
  191. {
  192. return Class::FromSystemType(type);
  193. }
  194. bool il2cpp_class_is_generic(const Il2CppClass *klass)
  195. {
  196. return Class::IsGeneric(klass);
  197. }
  198. bool il2cpp_class_is_inflated(const Il2CppClass *klass)
  199. {
  200. return Class::IsInflated(klass);
  201. }
  202. bool il2cpp_class_is_assignable_from(Il2CppClass *klass, Il2CppClass *oklass)
  203. {
  204. return Class::IsAssignableFrom(klass, oklass);
  205. }
  206. bool il2cpp_class_is_subclass_of(Il2CppClass *klass, Il2CppClass *klassc, bool check_interfaces)
  207. {
  208. return Class::IsSubclassOf(klass, klassc, check_interfaces);
  209. }
  210. bool il2cpp_class_has_parent(Il2CppClass *klass, Il2CppClass *klassc)
  211. {
  212. return Class::HasParent(klass, klassc);
  213. }
  214. Il2CppClass* il2cpp_class_from_il2cpp_type(const Il2CppType* type)
  215. {
  216. return Class::FromIl2CppType(type);
  217. }
  218. Il2CppClass* il2cpp_class_from_name(const Il2CppImage* image, const char* namespaze, const char *name)
  219. {
  220. return Class::FromName(image, namespaze, name);
  221. }
  222. Il2CppClass* il2cpp_class_get_element_class(Il2CppClass *klass)
  223. {
  224. return Class::GetElementClass(klass);
  225. }
  226. const EventInfo* il2cpp_class_get_events(Il2CppClass *klass, void* *iter)
  227. {
  228. return Class::GetEvents(klass, iter);
  229. }
  230. FieldInfo* il2cpp_class_get_fields(Il2CppClass *klass, void* *iter)
  231. {
  232. return Class::GetFields(klass, iter);
  233. }
  234. Il2CppClass* il2cpp_class_get_nested_types(Il2CppClass *klass, void* *iter)
  235. {
  236. return Class::GetNestedTypes(klass, iter);
  237. }
  238. Il2CppClass* il2cpp_class_get_interfaces(Il2CppClass *klass, void* *iter)
  239. {
  240. return Class::GetInterfaces(klass, iter);
  241. }
  242. const PropertyInfo* il2cpp_class_get_properties(Il2CppClass *klass, void* *iter)
  243. {
  244. return Class::GetProperties(klass, iter);
  245. }
  246. const PropertyInfo* il2cpp_class_get_property_from_name(Il2CppClass *klass, const char *name)
  247. {
  248. return Class::GetPropertyFromName(klass, name);
  249. }
  250. FieldInfo* il2cpp_class_get_field_from_name(Il2CppClass* klass, const char *name)
  251. {
  252. return Class::GetFieldFromName(klass, name);
  253. }
  254. const MethodInfo* il2cpp_class_get_methods(Il2CppClass *klass, void* *iter)
  255. {
  256. return Class::GetMethods(klass, iter);
  257. }
  258. const MethodInfo* il2cpp_class_get_method_from_name(Il2CppClass *klass, const char* name, int argsCount)
  259. {
  260. return Class::GetMethodFromName(klass, name, argsCount);
  261. }
  262. const char* il2cpp_class_get_name(Il2CppClass *klass)
  263. {
  264. return Class::GetName(klass);
  265. }
  266. const char* il2cpp_class_get_namespace(Il2CppClass *klass)
  267. {
  268. return Class::GetNamespace(klass);
  269. }
  270. Il2CppClass* il2cpp_class_get_parent(Il2CppClass *klass)
  271. {
  272. return Class::GetParent(klass);
  273. }
  274. Il2CppClass* il2cpp_class_get_declaring_type(Il2CppClass* klass)
  275. {
  276. return Class::GetDeclaringType(klass);
  277. }
  278. int32_t il2cpp_class_instance_size(Il2CppClass *klass)
  279. {
  280. return Class::GetInstanceSize(klass);
  281. }
  282. size_t il2cpp_class_num_fields(const Il2CppClass* klass)
  283. {
  284. return Class::GetNumFields(klass);
  285. }
  286. bool il2cpp_class_is_valuetype(const Il2CppClass* klass)
  287. {
  288. return Class::IsValuetype(klass);
  289. }
  290. bool il2cpp_class_is_blittable(const Il2CppClass* klass)
  291. {
  292. return Class::IsBlittable(klass);
  293. }
  294. int32_t il2cpp_class_value_size(Il2CppClass *klass, uint32_t *align)
  295. {
  296. return Class::GetValueSize(klass, align);
  297. }
  298. int il2cpp_class_get_flags(const Il2CppClass *klass)
  299. {
  300. return Class::GetFlags(klass);
  301. }
  302. bool il2cpp_class_is_abstract(const Il2CppClass *klass)
  303. {
  304. return Class::IsAbstract(klass);
  305. }
  306. bool il2cpp_class_is_interface(const Il2CppClass *klass)
  307. {
  308. return Class::IsInterface(klass);
  309. }
  310. int il2cpp_class_array_element_size(const Il2CppClass *klass)
  311. {
  312. return Class::GetArrayElementSize(klass);
  313. }
  314. Il2CppClass* il2cpp_class_from_type(const Il2CppType *type)
  315. {
  316. return Class::FromIl2CppType(type);
  317. }
  318. const Il2CppType* il2cpp_class_get_type(Il2CppClass *klass)
  319. {
  320. return Class::GetType(klass);
  321. }
  322. uint32_t il2cpp_class_get_type_token(Il2CppClass *klass)
  323. {
  324. return klass->token;
  325. }
  326. bool il2cpp_class_has_attribute(Il2CppClass *klass, Il2CppClass *attr_class)
  327. {
  328. return Class::HasAttribute(klass, attr_class);
  329. }
  330. bool il2cpp_class_has_references(Il2CppClass *klass)
  331. {
  332. return Class::HasReferences(klass);
  333. }
  334. bool il2cpp_class_is_enum(const Il2CppClass *klass)
  335. {
  336. return Class::IsEnum(klass);
  337. }
  338. const Il2CppImage* il2cpp_class_get_image(Il2CppClass* klass)
  339. {
  340. return Class::GetImage(klass);
  341. }
  342. const char *il2cpp_class_get_assemblyname(const Il2CppClass *klass)
  343. {
  344. return Class::GetAssemblyNameNoExtension(klass);
  345. }
  346. int il2cpp_class_get_rank(const Il2CppClass *klass)
  347. {
  348. return klass->rank;
  349. }
  350. uint32_t il2cpp_class_get_data_size(const Il2CppClass *klass)
  351. {
  352. return klass->static_fields_size;
  353. }
  354. void* il2cpp_class_get_static_field_data(const Il2CppClass *klass)
  355. {
  356. return klass->static_fields;
  357. }
  358. // testing only
  359. size_t il2cpp_class_get_bitmap_size(const Il2CppClass *klass)
  360. {
  361. return Class::GetBitmapSize(klass);
  362. }
  363. void il2cpp_class_get_bitmap(Il2CppClass *klass, size_t* bitmap)
  364. {
  365. size_t dummy = 0;
  366. Class::GetBitmap(klass, bitmap, dummy);
  367. }
  368. // stats
  369. extern Il2CppRuntimeStats il2cpp_runtime_stats;
  370. bool il2cpp_stats_dump_to_file(const char *path)
  371. {
  372. std::fstream fs;
  373. fs.open(path, std::fstream::out | std::fstream::trunc);
  374. fs << "New object count: " << il2cpp_stats_get_value(IL2CPP_STAT_NEW_OBJECT_COUNT) << "\n";
  375. fs << "Method count: " << il2cpp_stats_get_value(IL2CPP_STAT_METHOD_COUNT) << "\n";
  376. fs << "Class static data size: " << il2cpp_stats_get_value(IL2CPP_STAT_CLASS_STATIC_DATA_SIZE) << "\n";
  377. fs << "Inflated method count: " << il2cpp_stats_get_value(IL2CPP_STAT_INFLATED_METHOD_COUNT) << "\n";
  378. fs << "Inflated type count: " << il2cpp_stats_get_value(IL2CPP_STAT_INFLATED_TYPE_COUNT) << "\n";
  379. fs << "Initialized class count: " << il2cpp_stats_get_value(IL2CPP_STAT_INITIALIZED_CLASS_COUNT) << "\n";
  380. fs << "Generic instance count: " << il2cpp_stats_get_value(IL2CPP_STAT_GENERIC_INSTANCE_COUNT) << "\n";
  381. fs << "Generic class count: " << il2cpp_stats_get_value(IL2CPP_STAT_GENERIC_CLASS_COUNT) << "\n";
  382. fs.close();
  383. return true;
  384. }
  385. uint64_t il2cpp_stats_get_value(Il2CppStat stat)
  386. {
  387. switch (stat)
  388. {
  389. case IL2CPP_STAT_NEW_OBJECT_COUNT:
  390. return il2cpp_runtime_stats.new_object_count;
  391. case IL2CPP_STAT_INITIALIZED_CLASS_COUNT:
  392. return il2cpp_runtime_stats.initialized_class_count;
  393. /*case IL2CPP_STAT_GENERIC_VTABLE_COUNT:
  394. return il2cpp_runtime_stats.generic_vtable_count;
  395. case IL2CPP_STAT_USED_CLASS_COUNT:
  396. return il2cpp_runtime_stats.used_class_count;*/
  397. case IL2CPP_STAT_METHOD_COUNT:
  398. return il2cpp_runtime_stats.method_count;
  399. /*case IL2CPP_STAT_CLASS_VTABLE_SIZE:
  400. return il2cpp_runtime_stats.class_vtable_size;*/
  401. case IL2CPP_STAT_CLASS_STATIC_DATA_SIZE:
  402. return il2cpp_runtime_stats.class_static_data_size;
  403. case IL2CPP_STAT_GENERIC_INSTANCE_COUNT:
  404. return il2cpp_runtime_stats.generic_instance_count;
  405. case IL2CPP_STAT_GENERIC_CLASS_COUNT:
  406. return il2cpp_runtime_stats.generic_class_count;
  407. case IL2CPP_STAT_INFLATED_METHOD_COUNT:
  408. return il2cpp_runtime_stats.inflated_method_count;
  409. case IL2CPP_STAT_INFLATED_TYPE_COUNT:
  410. return il2cpp_runtime_stats.inflated_type_count;
  411. /*case IL2CPP_STAT_DELEGATE_CREATIONS:
  412. return il2cpp_runtime_stats.delegate_creations;
  413. case IL2CPP_STAT_MINOR_GC_COUNT:
  414. return il2cpp_runtime_stats.minor_gc_count;
  415. case IL2CPP_STAT_MAJOR_GC_COUNT:
  416. return il2cpp_runtime_stats.major_gc_count;
  417. case IL2CPP_STAT_MINOR_GC_TIME_USECS:
  418. return il2cpp_runtime_stats.minor_gc_time_usecs;
  419. case IL2CPP_STAT_MAJOR_GC_TIME_USECS:
  420. return il2cpp_runtime_stats.major_gc_time_usecs;*/
  421. }
  422. return 0;
  423. }
  424. // domain
  425. Il2CppDomain* il2cpp_domain_get()
  426. {
  427. return Domain::GetCurrent();
  428. }
  429. const Il2CppAssembly* il2cpp_domain_assembly_open(Il2CppDomain *domain, const char *name)
  430. {
  431. return Assembly::Load(name);
  432. }
  433. const Il2CppAssembly** il2cpp_domain_get_assemblies(const Il2CppDomain* domain, size_t* size)
  434. {
  435. il2cpp::vm::AssemblyVector* assemblies = Assembly::GetAllAssemblies();
  436. *size = assemblies->size();
  437. return &(*assemblies)[0];
  438. }
  439. // exception
  440. void il2cpp_raise_exception(Il2CppException* exc)
  441. {
  442. Exception::Raise(exc);
  443. }
  444. Il2CppException* il2cpp_exception_from_name_msg(const Il2CppImage* image, const char *name_space, const char *name, const char *msg)
  445. {
  446. return Exception::FromNameMsg(image, name_space, name, msg);
  447. }
  448. Il2CppException* il2cpp_get_exception_argument_null(const char *arg)
  449. {
  450. return Exception::GetArgumentNullException(arg);
  451. }
  452. void il2cpp_format_exception(const Il2CppException* ex, char* message, int message_size)
  453. {
  454. strncpy(message, il2cpp::utils::Exception::FormatException(ex).c_str(), message_size);
  455. }
  456. void il2cpp_format_stack_trace(const Il2CppException* ex, char* output, int output_size)
  457. {
  458. strncpy(output, il2cpp::utils::Exception::FormatStackTrace(ex).c_str(), output_size);
  459. }
  460. void il2cpp_unhandled_exception(Il2CppException* exc)
  461. {
  462. Runtime::UnhandledException(exc);
  463. }
  464. void il2cpp_native_stack_trace(const Il2CppException * ex, uintptr_t** addresses, int* numFrames, char** imageUUID, char** imageName)
  465. {
  466. #if IL2CPP_ENABLE_NATIVE_INSTRUCTION_POINTER_EMISSION && !IL2CPP_TINY
  467. if (ex == NULL || ex->native_trace_ips == NULL)
  468. {
  469. *numFrames = 0;
  470. *addresses = NULL;
  471. *imageUUID = NULL;
  472. *imageName = NULL;
  473. return;
  474. }
  475. *numFrames = il2cpp_array_length(ex->native_trace_ips);
  476. if (*numFrames <= 0)
  477. {
  478. *addresses = NULL;
  479. *imageUUID = NULL;
  480. *imageName = NULL;
  481. }
  482. else
  483. {
  484. *addresses = static_cast<uintptr_t*>(il2cpp_alloc((*numFrames) * sizeof(uintptr_t)));
  485. for (int i = 0; i < *numFrames; i++)
  486. {
  487. uintptr_t ptrAddr = il2cpp_array_get(ex->native_trace_ips, uintptr_t, i);
  488. (*addresses)[i] = ptrAddr;
  489. }
  490. *imageUUID = il2cpp::os::Image::GetImageUUID();
  491. *imageName = il2cpp::os::Image::GetImageName();
  492. }
  493. #endif
  494. }
  495. // field
  496. const char* il2cpp_field_get_name(FieldInfo *field)
  497. {
  498. return Field::GetName(field);
  499. }
  500. int il2cpp_field_get_flags(FieldInfo *field)
  501. {
  502. return Field::GetFlags(field);
  503. }
  504. Il2CppClass* il2cpp_field_get_parent(FieldInfo *field)
  505. {
  506. return Field::GetParent(field);
  507. }
  508. size_t il2cpp_field_get_offset(FieldInfo *field)
  509. {
  510. return Field::GetOffset(field);
  511. }
  512. const Il2CppType* il2cpp_field_get_type(FieldInfo *field)
  513. {
  514. return Field::GetType(field);
  515. }
  516. void il2cpp_field_get_value(Il2CppObject *obj, FieldInfo *field, void *value)
  517. {
  518. return Field::GetValue(obj, field, value);
  519. }
  520. Il2CppObject* il2cpp_field_get_value_object(FieldInfo *field, Il2CppObject *obj)
  521. {
  522. return Field::GetValueObject(field, obj);
  523. }
  524. bool il2cpp_field_has_attribute(FieldInfo *field, Il2CppClass *attr_class)
  525. {
  526. return Field::HasAttribute(field, attr_class);
  527. }
  528. void il2cpp_field_set_value(Il2CppObject *obj, FieldInfo *field, void *value)
  529. {
  530. Field::SetValue(obj, field, value);
  531. }
  532. void il2cpp_field_set_value_object(Il2CppObject* objectInstance, FieldInfo* field, Il2CppObject* value)
  533. {
  534. Field::SetInstanceFieldValueObject(objectInstance, field, value);
  535. }
  536. void il2cpp_field_static_get_value(FieldInfo *field, void *value)
  537. {
  538. Field::StaticGetValue(field, value);
  539. }
  540. void il2cpp_field_static_set_value(FieldInfo *field, void *value)
  541. {
  542. Field::StaticSetValue(field, value);
  543. }
  544. bool il2cpp_field_is_literal(FieldInfo *field)
  545. {
  546. return (field->type->attrs & FIELD_ATTRIBUTE_LITERAL) != 0;
  547. }
  548. // gc
  549. void il2cpp_gc_collect(int maxGenerations)
  550. {
  551. GarbageCollector::Collect(maxGenerations);
  552. }
  553. int32_t il2cpp_gc_collect_a_little()
  554. {
  555. return GarbageCollector::CollectALittle();
  556. }
  557. void il2cpp_gc_start_incremental_collection()
  558. {
  559. GarbageCollector::StartIncrementalCollection();
  560. }
  561. void il2cpp_gc_enable()
  562. {
  563. GarbageCollector::Enable();
  564. }
  565. void il2cpp_gc_disable()
  566. {
  567. GarbageCollector::Disable();
  568. }
  569. bool il2cpp_gc_is_disabled()
  570. {
  571. return GarbageCollector::IsDisabled();
  572. }
  573. void il2cpp_gc_set_mode(Il2CppGCMode mode)
  574. {
  575. GarbageCollector::SetMode(mode);
  576. }
  577. bool il2cpp_gc_is_incremental()
  578. {
  579. return GarbageCollector::IsIncremental();
  580. }
  581. int64_t il2cpp_gc_get_max_time_slice_ns()
  582. {
  583. return GarbageCollector::GetMaxTimeSliceNs();
  584. }
  585. void il2cpp_gc_set_max_time_slice_ns(int64_t maxTimeSlice)
  586. {
  587. GarbageCollector::SetMaxTimeSliceNs(maxTimeSlice);
  588. }
  589. int64_t il2cpp_gc_get_used_size()
  590. {
  591. return GarbageCollector::GetUsedHeapSize();
  592. }
  593. int64_t il2cpp_gc_get_heap_size()
  594. {
  595. return GarbageCollector::GetAllocatedHeapSize();
  596. }
  597. void il2cpp_gc_foreach_heap(void(*func)(void* data, void* context), void* userData)
  598. {
  599. MemoryInformation::IterationContext ctx;
  600. ctx.callback = func;
  601. ctx.userData = userData;
  602. il2cpp::gc::GarbageCollector::ForEachHeapSection(&ctx, MemoryInformation::ReportGcHeapSection);
  603. }
  604. void il2cpp_stop_gc_world()
  605. {
  606. il2cpp::gc::GarbageCollector::StopWorld();
  607. }
  608. void il2cpp_start_gc_world()
  609. {
  610. il2cpp::gc::GarbageCollector::StartWorld();
  611. }
  612. void* il2cpp_gc_alloc_fixed(size_t size)
  613. {
  614. return il2cpp::gc::GarbageCollector::AllocateFixed(size, NULL);
  615. }
  616. void il2cpp_gc_free_fixed(void* address)
  617. {
  618. il2cpp::gc::GarbageCollector::FreeFixed(address);
  619. }
  620. // gchandle
  621. uint32_t il2cpp_gchandle_new(Il2CppObject *obj, bool pinned)
  622. {
  623. return GCHandle::New(obj, pinned);
  624. }
  625. uint32_t il2cpp_gchandle_new_weakref(Il2CppObject *obj, bool track_resurrection)
  626. {
  627. // Note that the call to Get will assert if an error occurred.
  628. return GCHandle::NewWeakref(obj, track_resurrection).Get();
  629. }
  630. Il2CppObject* il2cpp_gchandle_get_target(uint32_t gchandle)
  631. {
  632. return GCHandle::GetTarget(gchandle);
  633. }
  634. void il2cpp_gchandle_foreach_get_target(void(*func)(void*, void*), void* userData)
  635. {
  636. MemoryInformation::IterationContext ctx;
  637. ctx.callback = func;
  638. ctx.userData = userData;
  639. il2cpp::gc::GCHandle::WalkStrongGCHandleTargets(MemoryInformation::ReportGcHandleTarget, &ctx);
  640. }
  641. void il2cpp_gc_wbarrier_set_field(Il2CppObject *obj, void **targetAddress, void *object)
  642. {
  643. il2cpp::gc::WriteBarrier::GenericStore(targetAddress, object);
  644. }
  645. bool il2cpp_gc_has_strict_wbarriers()
  646. {
  647. #if IL2CPP_ENABLE_STRICT_WRITE_BARRIERS
  648. return true;
  649. #else
  650. return false;
  651. #endif
  652. }
  653. void il2cpp_gc_set_external_allocation_tracker(void(*func)(void*, size_t, int))
  654. {
  655. #if IL2CPP_ENABLE_WRITE_BARRIER_VALIDATION
  656. il2cpp::gc::WriteBarrierValidation::SetExternalAllocationTracker(func);
  657. #endif
  658. }
  659. void il2cpp_gc_set_external_wbarrier_tracker(void(*func)(void**))
  660. {
  661. #if IL2CPP_ENABLE_WRITE_BARRIER_VALIDATION
  662. il2cpp::gc::WriteBarrierValidation::SetExternalWriteBarrierTracker(func);
  663. #endif
  664. }
  665. void il2cpp_gchandle_free(uint32_t gchandle)
  666. {
  667. GCHandle::Free(gchandle);
  668. }
  669. // vm runtime info
  670. uint32_t il2cpp_object_header_size()
  671. {
  672. return static_cast<uint32_t>(sizeof(Il2CppObject));
  673. }
  674. uint32_t il2cpp_array_object_header_size()
  675. {
  676. return static_cast<uint32_t>(kIl2CppSizeOfArray);
  677. }
  678. uint32_t il2cpp_offset_of_array_length_in_array_object_header()
  679. {
  680. return kIl2CppOffsetOfArrayLength;
  681. }
  682. uint32_t il2cpp_offset_of_array_bounds_in_array_object_header()
  683. {
  684. return kIl2CppOffsetOfArrayBounds;
  685. }
  686. uint32_t il2cpp_allocation_granularity()
  687. {
  688. return static_cast<uint32_t>(2 * sizeof(void*));
  689. }
  690. // liveness
  691. void* il2cpp_unity_liveness_allocate_struct(Il2CppClass* filter, int max_object_count, il2cpp_register_object_callback callback, void* userdata, il2cpp_liveness_reallocate_callback reallocate)
  692. {
  693. return Liveness::AllocateStruct(filter, max_object_count, callback, userdata, reallocate);
  694. }
  695. void il2cpp_unity_liveness_calculation_from_root(Il2CppObject* root, void* state)
  696. {
  697. Liveness::FromRoot(root, state);
  698. }
  699. void il2cpp_unity_liveness_calculation_from_statics(void* state)
  700. {
  701. Liveness::FromStatics(state);
  702. }
  703. void il2cpp_unity_liveness_finalize(void* state)
  704. {
  705. Liveness::Finalize(state);
  706. }
  707. void il2cpp_unity_liveness_free_struct(void* state)
  708. {
  709. Liveness::FreeStruct(state);
  710. }
  711. // method
  712. const Il2CppType* il2cpp_method_get_return_type(const MethodInfo* method)
  713. {
  714. return Method::GetReturnType(method);
  715. }
  716. const MethodInfo* il2cpp_method_get_from_reflection(const Il2CppReflectionMethod *method)
  717. {
  718. return Reflection::GetMethod(method);
  719. }
  720. Il2CppReflectionMethod* il2cpp_method_get_object(const MethodInfo *method, Il2CppClass *refclass)
  721. {
  722. return Reflection::GetMethodObject(method, refclass);
  723. }
  724. const char* il2cpp_method_get_name(const MethodInfo *method)
  725. {
  726. return Method::GetName(method);
  727. }
  728. bool il2cpp_method_is_generic(const MethodInfo *method)
  729. {
  730. return Method::IsGeneric(method);
  731. }
  732. bool il2cpp_method_is_inflated(const MethodInfo *method)
  733. {
  734. return Method::IsInflated(method);
  735. }
  736. bool il2cpp_method_is_instance(const MethodInfo *method)
  737. {
  738. return Method::IsInstance(method);
  739. }
  740. uint32_t il2cpp_method_get_param_count(const MethodInfo *method)
  741. {
  742. return Method::GetParamCount(method);
  743. }
  744. const Il2CppType* il2cpp_method_get_param(const MethodInfo *method, uint32_t index)
  745. {
  746. return Method::GetParam(method, index);
  747. }
  748. Il2CppClass* il2cpp_method_get_class(const MethodInfo *method)
  749. {
  750. return Method::GetClass(method);
  751. }
  752. bool il2cpp_method_has_attribute(const MethodInfo *method, Il2CppClass *attr_class)
  753. {
  754. return Method::HasAttribute(method, attr_class);
  755. }
  756. Il2CppClass* il2cpp_method_get_declaring_type(const MethodInfo* method)
  757. {
  758. return Method::GetDeclaringType(method);
  759. }
  760. uint32_t il2cpp_method_get_flags(const MethodInfo *method, uint32_t *iflags)
  761. {
  762. if (iflags != 0)
  763. *iflags = Method::GetImplementationFlags(method);
  764. return Method::GetFlags(method);
  765. }
  766. uint32_t il2cpp_method_get_token(const MethodInfo *method)
  767. {
  768. return Method::GetToken(method);
  769. }
  770. const char *il2cpp_method_get_param_name(const MethodInfo *method, uint32_t index)
  771. {
  772. return Method::GetParamName(method, index);
  773. }
  774. // profiler
  775. #if IL2CPP_ENABLE_PROFILER
  776. void il2cpp_profiler_install(Il2CppProfiler *prof, Il2CppProfileFunc shutdown_callback)
  777. {
  778. Profiler::Install(prof, shutdown_callback);
  779. }
  780. void il2cpp_profiler_set_events(Il2CppProfileFlags events)
  781. {
  782. Profiler::SetEvents(events);
  783. }
  784. void il2cpp_profiler_install_enter_leave(Il2CppProfileMethodFunc enter, Il2CppProfileMethodFunc fleave)
  785. {
  786. Profiler::InstallEnterLeave(enter, fleave);
  787. }
  788. void il2cpp_profiler_install_allocation(Il2CppProfileAllocFunc callback)
  789. {
  790. Profiler::InstallAllocation(callback);
  791. }
  792. void il2cpp_profiler_install_gc(Il2CppProfileGCFunc callback, Il2CppProfileGCResizeFunc heap_resize_callback)
  793. {
  794. Profiler::InstallGC(callback, heap_resize_callback);
  795. }
  796. void il2cpp_profiler_install_fileio(Il2CppProfileFileIOFunc callback)
  797. {
  798. Profiler::InstallFileIO(callback);
  799. }
  800. void il2cpp_profiler_install_thread(Il2CppProfileThreadFunc start, Il2CppProfileThreadFunc end)
  801. {
  802. Profiler::InstallThread(start, end);
  803. }
  804. #endif
  805. // property
  806. const char* il2cpp_property_get_name(PropertyInfo *prop)
  807. {
  808. return Property::GetName(prop);
  809. }
  810. const MethodInfo* il2cpp_property_get_get_method(PropertyInfo *prop)
  811. {
  812. return Property::GetGetMethod(prop);
  813. }
  814. const MethodInfo* il2cpp_property_get_set_method(PropertyInfo *prop)
  815. {
  816. return Property::GetSetMethod(prop);
  817. }
  818. Il2CppClass* il2cpp_property_get_parent(PropertyInfo *prop)
  819. {
  820. return Property::GetParent(prop);
  821. }
  822. uint32_t il2cpp_property_get_flags(PropertyInfo *prop)
  823. {
  824. return Property::GetFlags(prop);
  825. }
  826. // object
  827. Il2CppClass* il2cpp_object_get_class(Il2CppObject* obj)
  828. {
  829. return Object::GetClass(obj);
  830. }
  831. uint32_t il2cpp_object_get_size(Il2CppObject* obj)
  832. {
  833. return Object::GetSize(obj);
  834. }
  835. const MethodInfo* il2cpp_object_get_virtual_method(Il2CppObject *obj, const MethodInfo *method)
  836. {
  837. return Object::GetVirtualMethod(obj, method);
  838. }
  839. Il2CppObject* il2cpp_object_new(const Il2CppClass *klass)
  840. {
  841. try
  842. {
  843. return Object::New(const_cast<Il2CppClass*>(klass));
  844. }
  845. catch (const Il2CppExceptionWrapper&)
  846. {
  847. // If a static constructor throws, that exception will occur here.
  848. // We don't want that to escape across the embedding API.
  849. return NULL;
  850. }
  851. }
  852. void* il2cpp_object_unbox(Il2CppObject* obj)
  853. {
  854. return Object::Unbox(obj);
  855. }
  856. Il2CppObject* il2cpp_value_box(Il2CppClass *klass, void* data)
  857. {
  858. return Object::Box(klass, data);
  859. }
  860. // monitor
  861. void il2cpp_monitor_enter(Il2CppObject* obj)
  862. {
  863. Monitor::Enter(obj);
  864. }
  865. bool il2cpp_monitor_try_enter(Il2CppObject* obj, uint32_t timeout)
  866. {
  867. return Monitor::TryEnter(obj, timeout);
  868. }
  869. void il2cpp_monitor_exit(Il2CppObject* obj)
  870. {
  871. Monitor::Exit(obj);
  872. }
  873. void il2cpp_monitor_pulse(Il2CppObject* obj)
  874. {
  875. Monitor::Pulse(obj);
  876. }
  877. void il2cpp_monitor_pulse_all(Il2CppObject* obj)
  878. {
  879. Monitor::PulseAll(obj);
  880. }
  881. void il2cpp_monitor_wait(Il2CppObject* obj)
  882. {
  883. Monitor::Wait(obj);
  884. }
  885. bool il2cpp_monitor_try_wait(Il2CppObject* obj, uint32_t timeout)
  886. {
  887. return Monitor::TryWait(obj, timeout);
  888. }
  889. // runtime
  890. Il2CppObject* il2cpp_runtime_invoke_convert_args(const MethodInfo *method, void *obj, Il2CppObject **params, int paramCount, Il2CppException **exc)
  891. {
  892. return Runtime::InvokeConvertArgs(method, obj, params, paramCount, exc);
  893. }
  894. Il2CppObject* il2cpp_runtime_invoke(const MethodInfo *method,
  895. void *obj, void **params, Il2CppException **exc)
  896. {
  897. return Runtime::Invoke(method, obj, params, exc);
  898. }
  899. void il2cpp_runtime_class_init(Il2CppClass* klass)
  900. {
  901. return Runtime::ClassInit(klass);
  902. }
  903. void il2cpp_runtime_object_init(Il2CppObject *obj)
  904. {
  905. Runtime::ObjectInit(obj);
  906. }
  907. void il2cpp_runtime_object_init_exception(Il2CppObject *obj, Il2CppException **exc)
  908. {
  909. Runtime::ObjectInitException(obj, exc);
  910. }
  911. void il2cpp_runtime_unhandled_exception_policy_set(Il2CppRuntimeUnhandledExceptionPolicy value)
  912. {
  913. Runtime::SetUnhandledExceptionPolicy(value);
  914. }
  915. // string
  916. int32_t il2cpp_string_length(Il2CppString* str)
  917. {
  918. return il2cpp::utils::StringUtils::GetLength(str);
  919. }
  920. Il2CppChar* il2cpp_string_chars(Il2CppString* str)
  921. {
  922. return il2cpp::utils::StringUtils::GetChars(str);
  923. }
  924. // Same as il2cpp_string_new_wrapper, because other normally takes a domain
  925. Il2CppString* il2cpp_string_new(const char* str)
  926. {
  927. return String::New(str);
  928. }
  929. Il2CppString* il2cpp_string_new_wrapper(const char* str)
  930. {
  931. return String::NewWrapper(str);
  932. }
  933. Il2CppString* il2cpp_string_new_utf16(const Il2CppChar *text, int32_t len)
  934. {
  935. return String::NewUtf16(text, len);
  936. }
  937. Il2CppString* il2cpp_string_new_len(const char* str, uint32_t length)
  938. {
  939. return String::NewLen(str, length);
  940. }
  941. Il2CppString* il2cpp_string_intern(Il2CppString* str)
  942. {
  943. return String::Intern(str);
  944. }
  945. Il2CppString* il2cpp_string_is_interned(Il2CppString* str)
  946. {
  947. return String::IsInterned(str);
  948. }
  949. // thread
  950. Il2CppThread *il2cpp_thread_current()
  951. {
  952. return Thread::Current();
  953. }
  954. Il2CppThread *il2cpp_thread_attach(Il2CppDomain *domain)
  955. {
  956. return Thread::Attach(domain);
  957. }
  958. void il2cpp_thread_detach(Il2CppThread *thread)
  959. {
  960. Thread::Detach(thread);
  961. }
  962. Il2CppThread **il2cpp_thread_get_all_attached_threads(size_t *size)
  963. {
  964. return Thread::GetAllAttachedThreads(*size);
  965. }
  966. bool il2cpp_is_vm_thread(Il2CppThread *thread)
  967. {
  968. return Thread::IsVmThread(thread);
  969. }
  970. // stacktrace
  971. void il2cpp_current_thread_walk_frame_stack(Il2CppFrameWalkFunc func, void* user_data)
  972. {
  973. StackTrace::WalkFrameStack(func, user_data);
  974. }
  975. void il2cpp_thread_walk_frame_stack(Il2CppThread *thread, Il2CppFrameWalkFunc func, void *user_data)
  976. {
  977. return StackTrace::WalkThreadFrameStack(thread, func, user_data);
  978. }
  979. bool il2cpp_current_thread_get_top_frame(Il2CppStackFrameInfo* frame)
  980. {
  981. IL2CPP_ASSERT(frame);
  982. return StackTrace::GetTopStackFrame(*frame);
  983. }
  984. bool il2cpp_thread_get_top_frame(Il2CppThread* thread, Il2CppStackFrameInfo* frame)
  985. {
  986. IL2CPP_ASSERT(frame);
  987. return StackTrace::GetThreadTopStackFrame(thread, *frame);
  988. }
  989. bool il2cpp_current_thread_get_frame_at(int32_t offset, Il2CppStackFrameInfo* frame)
  990. {
  991. IL2CPP_ASSERT(frame);
  992. return StackTrace::GetStackFrameAt(offset, *frame);
  993. }
  994. bool il2cpp_thread_get_frame_at(Il2CppThread* thread, int32_t offset, Il2CppStackFrameInfo* frame)
  995. {
  996. IL2CPP_ASSERT(frame);
  997. return StackTrace::GetThreadStackFrameAt(thread, offset, *frame);
  998. }
  999. int32_t il2cpp_current_thread_get_stack_depth()
  1000. {
  1001. return static_cast<int32_t>(StackTrace::GetStackDepth());
  1002. }
  1003. int32_t il2cpp_thread_get_stack_depth(Il2CppThread *thread)
  1004. {
  1005. return StackTrace::GetThreadStackDepth(thread);
  1006. }
  1007. void il2cpp_set_default_thread_affinity(int64_t affinity_mask)
  1008. {
  1009. Thread::SetDefaultAffinityMask(affinity_mask);
  1010. }
  1011. void il2cpp_override_stack_backtrace(Il2CppBacktraceFunc stackBacktraceFunc)
  1012. {
  1013. il2cpp::os::StackTrace::OverrideStackBacktrace(stackBacktraceFunc);
  1014. }
  1015. // type
  1016. Il2CppObject* il2cpp_type_get_object(const Il2CppType *type)
  1017. {
  1018. return (Il2CppObject*)Reflection::GetTypeObject(type);
  1019. }
  1020. int il2cpp_type_get_type(const Il2CppType *type)
  1021. {
  1022. return Type::GetType(type);
  1023. }
  1024. Il2CppClass* il2cpp_type_get_class_or_element_class(const Il2CppType *type)
  1025. {
  1026. return Type::GetClassOrElementClass(type);
  1027. }
  1028. char* il2cpp_type_get_name(const Il2CppType *type)
  1029. {
  1030. std::string name = Type::GetName(type, IL2CPP_TYPE_NAME_FORMAT_IL);
  1031. char* buffer = static_cast<char*>(il2cpp_alloc(name.length() + 1));
  1032. memcpy(buffer, name.c_str(), name.length() + 1);
  1033. return buffer;
  1034. }
  1035. char* il2cpp_type_get_assembly_qualified_name(const Il2CppType * type)
  1036. {
  1037. std::string name = Type::GetName(type, IL2CPP_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED);
  1038. char* buffer = static_cast<char*>(il2cpp_alloc(name.length() + 1));
  1039. memcpy(buffer, name.c_str(), name.length() + 1);
  1040. return buffer;
  1041. }
  1042. bool il2cpp_type_is_byref(const Il2CppType *type)
  1043. {
  1044. return type->byref;
  1045. }
  1046. uint32_t il2cpp_type_get_attrs(const Il2CppType *type)
  1047. {
  1048. return type->attrs;
  1049. }
  1050. bool il2cpp_type_equals(const Il2CppType* type, const Il2CppType *otherType)
  1051. {
  1052. return Type::IsEqualToType(type, otherType);
  1053. }
  1054. bool il2cpp_type_is_static(const Il2CppType *type)
  1055. {
  1056. return (type->attrs & FIELD_ATTRIBUTE_STATIC) != 0;
  1057. }
  1058. bool il2cpp_type_is_pointer_type(const Il2CppType *type)
  1059. {
  1060. return type->type == IL2CPP_TYPE_PTR;
  1061. }
  1062. // image
  1063. const Il2CppAssembly* il2cpp_image_get_assembly(const Il2CppImage *image)
  1064. {
  1065. return Image::GetAssembly(image);
  1066. }
  1067. const char* il2cpp_image_get_name(const Il2CppImage *image)
  1068. {
  1069. return Image::GetName(image);
  1070. }
  1071. const char* il2cpp_image_get_filename(const Il2CppImage *image)
  1072. {
  1073. return Image::GetFileName(image);
  1074. }
  1075. const MethodInfo* il2cpp_image_get_entry_point(const Il2CppImage *image)
  1076. {
  1077. return Image::GetEntryPoint(image);
  1078. }
  1079. size_t il2cpp_image_get_class_count(const Il2CppImage * image)
  1080. {
  1081. return Image::GetNumTypes(image);
  1082. }
  1083. const Il2CppClass* il2cpp_image_get_class(const Il2CppImage * image, size_t index)
  1084. {
  1085. return Image::GetType(image, static_cast<AssemblyTypeIndex>(index));
  1086. }
  1087. Il2CppManagedMemorySnapshot* il2cpp_capture_memory_snapshot()
  1088. {
  1089. return MemoryInformation::CaptureManagedMemorySnapshot();
  1090. }
  1091. void il2cpp_free_captured_memory_snapshot(Il2CppManagedMemorySnapshot* snapshot)
  1092. {
  1093. MemoryInformation::FreeCapturedManagedMemorySnapshot(snapshot);
  1094. }
  1095. void il2cpp_set_find_plugin_callback(Il2CppSetFindPlugInCallback method)
  1096. {
  1097. il2cpp::vm::PlatformInvoke::SetFindPluginCallback(method);
  1098. }
  1099. // Logging
  1100. void il2cpp_register_log_callback(Il2CppLogCallback method)
  1101. {
  1102. il2cpp::utils::Logging::SetLogCallback(method);
  1103. }
  1104. // Debugger
  1105. void il2cpp_debugger_set_agent_options(const char* options)
  1106. {
  1107. #if IL2CPP_MONO_DEBUGGER
  1108. il2cpp::utils::Debugger::SetAgentOptions(options);
  1109. #endif
  1110. }
  1111. bool il2cpp_is_debugger_attached()
  1112. {
  1113. return il2cpp::utils::Debugger::GetIsDebuggerAttached();
  1114. }
  1115. void il2cpp_register_debugger_agent_transport(Il2CppDebuggerTransport * debuggerTransport)
  1116. {
  1117. #if IL2CPP_MONO_DEBUGGER
  1118. il2cpp::utils::Debugger::RegisterTransport(debuggerTransport);
  1119. #endif
  1120. }
  1121. bool il2cpp_debug_get_method_info(const MethodInfo* method, Il2CppMethodDebugInfo* methodDebugInfo)
  1122. {
  1123. #if IL2CPP_ENABLE_NATIVE_STACKTRACES
  1124. return il2cpp::utils::NativeSymbol::GetMethodDebugInfo(method, methodDebugInfo);
  1125. #else
  1126. return false;
  1127. #endif
  1128. }
  1129. void il2cpp_unity_install_unitytls_interface(const void* unitytlsInterfaceStruct)
  1130. {
  1131. il2cpp::vm::Runtime::SetUnityTlsInterface(unitytlsInterfaceStruct);
  1132. }
  1133. // Custom Attributes
  1134. Il2CppCustomAttrInfo* il2cpp_custom_attrs_from_class(Il2CppClass *klass)
  1135. {
  1136. return (Il2CppCustomAttrInfo*)(MetadataCache::GetCustomAttributeTypeToken(klass->image, klass->token));
  1137. }
  1138. Il2CppCustomAttrInfo* il2cpp_custom_attrs_from_method(const MethodInfo * method)
  1139. {
  1140. return (Il2CppCustomAttrInfo*)(MetadataCache::GetCustomAttributeTypeToken(method->klass->image, method->token));
  1141. }
  1142. bool il2cpp_custom_attrs_has_attr(Il2CppCustomAttrInfo *ainfo, Il2CppClass *attr_klass)
  1143. {
  1144. return MetadataCache::HasAttribute(reinterpret_cast<Il2CppMetadataCustomAttributeHandle>(ainfo), attr_klass);
  1145. }
  1146. Il2CppObject* il2cpp_custom_attrs_get_attr(Il2CppCustomAttrInfo *ainfo, Il2CppClass *attr_klass)
  1147. {
  1148. return Reflection::GetCustomAttribute(reinterpret_cast<Il2CppMetadataCustomAttributeHandle>(ainfo), attr_klass);
  1149. }
  1150. Il2CppArray* il2cpp_custom_attrs_construct(Il2CppCustomAttrInfo *ainfo)
  1151. {
  1152. return Reflection::ConstructCustomAttributes(reinterpret_cast<Il2CppMetadataCustomAttributeHandle>(ainfo));
  1153. }
  1154. void il2cpp_custom_attrs_free(Il2CppCustomAttrInfo *ainfo)
  1155. {
  1156. // nothing to free, we cache everything
  1157. }
  1158. void il2cpp_type_get_name_chunked(const Il2CppType * type, void(*chunkReportFunc)(void* data, void* userData), void* userData)
  1159. {
  1160. Type::GetNameChunkedRecurse(type, IL2CPP_TYPE_NAME_FORMAT_IL, chunkReportFunc, userData);
  1161. }
  1162. void il2cpp_class_set_userdata(Il2CppClass* klass, void* userdata)
  1163. {
  1164. klass->unity_user_data = userdata;
  1165. }
  1166. int il2cpp_class_get_userdata_offset()
  1167. {
  1168. return offsetof(struct Il2CppClass, unity_user_data);
  1169. }
  1170. void il2cpp_class_for_each(void(*klassReportFunc)(Il2CppClass* klass, void* userData), void* userData)
  1171. {
  1172. MemoryInformation::ReportIL2CppClasses(klassReportFunc, userData);
  1173. }
  1174. // Android
  1175. void il2cpp_unity_set_android_network_up_state_func(Il2CppAndroidUpStateFunc func)
  1176. {
  1177. AndroidRuntime::SetNetworkUpStateFunc(func);
  1178. }