Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

il2cpp-api.cpp 36KB

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