il2cpp-object-internals.h 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #if !RUNTIME_TINY
  4. #include <stdint.h>
  5. #include <stddef.h>
  6. #include "il2cpp-class-internals.h"
  7. #include "il2cpp-windowsruntime-types.h"
  8. #if defined(__cplusplus)
  9. extern "C"
  10. {
  11. #endif // __cplusplus
  12. // We cannot include il2cpp-api.h here because generated code contains il2cpp
  13. // api declarations with mismatching parameter declarations (char* vs const char*).
  14. // So we only declare il2cpp_gc_wbarrier_set_field here.
  15. IL2CPP_EXPORT void il2cpp_gc_wbarrier_set_field(Il2CppObject * obj, void **targetAddress, void *object);
  16. #if defined(__cplusplus)
  17. }
  18. #endif // __cplusplus
  19. typedef struct Il2CppClass Il2CppClass;
  20. typedef struct MethodInfo MethodInfo;
  21. typedef struct PropertyInfo PropertyInfo;
  22. typedef struct FieldInfo FieldInfo;
  23. typedef struct EventInfo EventInfo;
  24. typedef struct Il2CppType Il2CppType;
  25. typedef struct Il2CppAssembly Il2CppAssembly;
  26. typedef struct Il2CppException Il2CppException;
  27. typedef struct Il2CppImage Il2CppImage;
  28. typedef struct Il2CppDomain Il2CppDomain;
  29. typedef struct Il2CppString Il2CppString;
  30. typedef struct Il2CppReflectionMethod Il2CppReflectionMethod;
  31. typedef struct Il2CppAsyncCall Il2CppAsyncCall;
  32. typedef struct Il2CppIUnknown Il2CppIUnknown;
  33. typedef struct Il2CppWaitHandle Il2CppWaitHandle;
  34. typedef struct MonitorData MonitorData;
  35. #ifdef __cplusplus
  36. namespace il2cpp
  37. {
  38. namespace os
  39. {
  40. class Thread;
  41. }
  42. }
  43. namespace baselib
  44. {
  45. #if !IL2CPP_TINY || IL2CPP_TINY_FROM_IL2CPP_BUILDER
  46. inline namespace il2cpp_baselib
  47. {
  48. #endif
  49. class ReentrantLock;
  50. #if !IL2CPP_TINY || IL2CPP_TINY_FROM_IL2CPP_BUILDER
  51. }
  52. #endif
  53. }
  54. #endif //__cplusplus
  55. typedef struct Il2CppReflectionAssembly Il2CppReflectionAssembly;
  56. typedef Il2CppClass Il2CppVTable;
  57. typedef struct Il2CppObject
  58. {
  59. union
  60. {
  61. Il2CppClass *klass;
  62. Il2CppVTable *vtable;
  63. };
  64. MonitorData *monitor;
  65. } Il2CppObject;
  66. typedef int32_t il2cpp_array_lower_bound_t;
  67. #define IL2CPP_ARRAY_MAX_INDEX ((int32_t) 0x7fffffff)
  68. #define IL2CPP_ARRAY_MAX_SIZE ((uint32_t) 0xffffffff)
  69. typedef struct Il2CppArrayBounds
  70. {
  71. il2cpp_array_size_t length;
  72. il2cpp_array_lower_bound_t lower_bound;
  73. } Il2CppArrayBounds;
  74. #if IL2CPP_COMPILER_MSVC
  75. #pragma warning( push )
  76. #pragma warning( disable : 4200 )
  77. #elif defined(__clang__)
  78. #pragma clang diagnostic push
  79. #pragma clang diagnostic ignored "-Winvalid-offsetof"
  80. #endif
  81. //Warning: Updates to this struct must also be made to IL2CPPArraySize C code
  82. #ifdef __cplusplus
  83. typedef struct Il2CppArray : public Il2CppObject
  84. {
  85. #else
  86. typedef struct Il2CppArray
  87. {
  88. Il2CppObject obj;
  89. #endif //__cplusplus
  90. /* bounds is NULL for szarrays */
  91. Il2CppArrayBounds *bounds;
  92. /* total number of elements of the array */
  93. il2cpp_array_size_t max_length;
  94. } Il2CppArray;
  95. #ifdef __cplusplus
  96. typedef struct Il2CppArraySize : public Il2CppArray
  97. {
  98. #else
  99. //mono code has no inheritance, so its members must be available from this type
  100. typedef struct Il2CppArraySize
  101. {
  102. Il2CppObject obj;
  103. Il2CppArrayBounds *bounds;
  104. il2cpp_array_size_t max_length;
  105. #endif //__cplusplus
  106. ALIGN_TYPE(8) void* vector[IL2CPP_ZERO_LEN_ARRAY];
  107. } Il2CppArraySize;
  108. static const size_t kIl2CppSizeOfArray = (offsetof(Il2CppArraySize, vector));
  109. static const size_t kIl2CppOffsetOfArrayBounds = (offsetof(Il2CppArray, bounds));
  110. static const size_t kIl2CppOffsetOfArrayLength = (offsetof(Il2CppArray, max_length));
  111. // System.String
  112. typedef struct Il2CppString
  113. {
  114. Il2CppObject object;
  115. int32_t length; ///< Length of string *excluding* the trailing null (which is included in 'chars').
  116. Il2CppChar chars[IL2CPP_ZERO_LEN_ARRAY];
  117. } Il2CppString;
  118. #if IL2CPP_COMPILER_MSVC
  119. #pragma warning( pop )
  120. #elif defined(__clang__)
  121. #pragma clang diagnostic pop
  122. #endif
  123. #define IL2CPP_OBJECT_SETREF(obj, fieldname, value) do {\
  124. il2cpp_gc_wbarrier_set_field((Il2CppObject *)(obj), (void**)&(obj)->fieldname, (value));\
  125. } while (0)
  126. /* This should be used if 's' can reside on the heap */
  127. #define IL2CPP_STRUCT_SETREF(s, field, value) do {\
  128. il2cpp_gc_wbarrier_set_field((Il2CppObject *)(s), (void**)&(s)->field, (value));\
  129. } while (0)
  130. typedef struct Il2CppReflectionType
  131. {
  132. Il2CppObject object;
  133. const Il2CppType *type;
  134. } Il2CppReflectionType;
  135. // IMPORTANT: All managed types corresponding to the objects below must be blacklisted in mscorlib.xml
  136. // System.RuntimeType
  137. typedef struct Il2CppReflectionRuntimeType
  138. {
  139. Il2CppReflectionType type;
  140. Il2CppObject* type_info;
  141. Il2CppObject* genericCache;
  142. Il2CppObject* serializationCtor;
  143. } Il2CppReflectionRuntimeType;
  144. // System.MonoType
  145. typedef struct Il2CppReflectionMonoType
  146. {
  147. Il2CppReflectionRuntimeType type;
  148. #ifdef __cplusplus
  149. const Il2CppType* GetIl2CppType() const
  150. {
  151. return type.type.type;
  152. }
  153. #endif //__cplusplus
  154. } Il2CppReflectionMonoType;
  155. // System.Reflection.EventInfo
  156. typedef struct Il2CppReflectionEvent
  157. {
  158. Il2CppObject object;
  159. Il2CppObject *cached_add_event;
  160. } Il2CppReflectionEvent;
  161. // System.Reflection.MonoEvent
  162. typedef struct Il2CppReflectionMonoEvent
  163. {
  164. Il2CppReflectionEvent event;
  165. Il2CppReflectionType* reflectedType;
  166. const EventInfo* eventInfo;
  167. } Il2CppReflectionMonoEvent;
  168. // System.Reflection.MonoEventInfo
  169. typedef struct Il2CppReflectionMonoEventInfo
  170. {
  171. Il2CppReflectionType* declaringType;
  172. Il2CppReflectionType* reflectedType;
  173. Il2CppString* name;
  174. Il2CppReflectionMethod* addMethod;
  175. Il2CppReflectionMethod* removeMethod;
  176. Il2CppReflectionMethod* raiseMethod;
  177. uint32_t eventAttributes;
  178. Il2CppArray* otherMethods;
  179. } Il2CppReflectionMonoEventInfo;
  180. // System.Reflection.MonoField
  181. typedef struct Il2CppReflectionField
  182. {
  183. Il2CppObject object;
  184. Il2CppClass *klass;
  185. FieldInfo *field;
  186. Il2CppString *name;
  187. Il2CppReflectionType *type;
  188. uint32_t attrs;
  189. } Il2CppReflectionField;
  190. // System.Reflection.MonoProperty
  191. typedef struct Il2CppReflectionProperty
  192. {
  193. Il2CppObject object;
  194. Il2CppClass *klass;
  195. const PropertyInfo *property;
  196. } Il2CppReflectionProperty;
  197. // System.Reflection.MonoMethod
  198. typedef struct Il2CppReflectionMethod
  199. {
  200. Il2CppObject object;
  201. const MethodInfo *method;
  202. Il2CppString *name;
  203. Il2CppReflectionType *reftype;
  204. } Il2CppReflectionMethod;
  205. // System.Reflection.MonoGenericMethod
  206. typedef struct Il2CppReflectionGenericMethod
  207. {
  208. Il2CppReflectionMethod base;
  209. } Il2CppReflectionGenericMethod;
  210. // System.Reflection.MonoMethodInfo
  211. typedef struct Il2CppMethodInfo
  212. {
  213. Il2CppReflectionType *parent;
  214. Il2CppReflectionType *ret;
  215. uint32_t attrs;
  216. uint32_t implattrs;
  217. uint32_t callconv;
  218. } Il2CppMethodInfo;
  219. // System.Reflection.MonoPropertyInfo
  220. typedef struct Il2CppPropertyInfo
  221. {
  222. Il2CppReflectionType* parent;
  223. Il2CppReflectionType* declaringType;
  224. Il2CppString *name;
  225. Il2CppReflectionMethod *get;
  226. Il2CppReflectionMethod *set;
  227. uint32_t attrs;
  228. } Il2CppPropertyInfo;
  229. // System.Reflection.ParameterInfo
  230. typedef struct Il2CppReflectionParameter
  231. {
  232. Il2CppObject object;
  233. Il2CppReflectionType *ClassImpl;
  234. Il2CppObject *DefaultValueImpl;
  235. Il2CppObject *MemberImpl;
  236. Il2CppString *NameImpl;
  237. int32_t PositionImpl;
  238. uint32_t AttrsImpl;
  239. Il2CppObject *MarshalAsImpl;
  240. } Il2CppReflectionParameter;
  241. // System.Reflection.Module
  242. typedef struct Il2CppReflectionModule
  243. {
  244. Il2CppObject obj;
  245. const Il2CppImage* image;
  246. Il2CppReflectionAssembly* assembly;
  247. Il2CppString* fqname;
  248. Il2CppString* name;
  249. Il2CppString* scopename;
  250. bool is_resource;
  251. uint32_t token;
  252. } Il2CppReflectionModule;
  253. // System.Reflection.AssemblyName
  254. typedef struct Il2CppReflectionAssemblyName
  255. {
  256. Il2CppObject obj;
  257. Il2CppString *name;
  258. Il2CppString *codebase;
  259. int32_t major, minor, build, revision;
  260. Il2CppObject *cultureInfo;
  261. uint32_t flags;
  262. uint32_t hashalg;
  263. Il2CppObject *keypair;
  264. Il2CppArray *publicKey;
  265. Il2CppArray *keyToken;
  266. uint32_t versioncompat;
  267. Il2CppObject *version;
  268. uint32_t processor_architecture;
  269. uint32_t contentType;
  270. } Il2CppReflectionAssemblyName;
  271. // System.Reflection.Assembly
  272. typedef struct Il2CppReflectionAssembly
  273. {
  274. Il2CppObject object;
  275. const Il2CppAssembly *assembly;
  276. Il2CppObject *resolve_event_holder;
  277. /* CAS related */
  278. Il2CppObject *evidence; /* Evidence */
  279. Il2CppObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
  280. Il2CppObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
  281. Il2CppObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
  282. Il2CppObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
  283. Il2CppObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
  284. /* */
  285. bool from_byte_array;
  286. Il2CppString *name;
  287. } Il2CppReflectionAssembly;
  288. // System.Reflection.Emit.UnmanagedMarshal
  289. typedef struct Il2CppReflectionMarshal
  290. {
  291. Il2CppObject object;
  292. int32_t count;
  293. int32_t type;
  294. int32_t eltype;
  295. Il2CppString* guid;
  296. Il2CppString* mcookie;
  297. Il2CppString* marshaltype;
  298. Il2CppObject* marshaltyperef;
  299. int32_t param_num;
  300. bool has_size;
  301. } Il2CppReflectionMarshal;
  302. // System.Reflection.Pointer
  303. typedef struct Il2CppReflectionPointer
  304. {
  305. Il2CppObject object;
  306. void* data;
  307. Il2CppReflectionType* type;
  308. } Il2CppReflectionPointer;
  309. // System.Threading.InternalThread
  310. typedef struct Il2CppInternalThread
  311. {
  312. Il2CppObject obj;
  313. int lock_thread_id;
  314. #ifdef __cplusplus
  315. il2cpp::os::Thread* handle;
  316. #else
  317. void* handle;
  318. #endif //__cplusplus
  319. void* native_handle;
  320. Il2CppArray* cached_culture_info;
  321. Il2CppChar* name;
  322. int name_len;
  323. uint32_t state;
  324. Il2CppObject* abort_exc;
  325. int abort_state_handle;
  326. uint64_t tid;
  327. intptr_t debugger_thread;
  328. void** static_data;
  329. void* runtime_thread_info;
  330. Il2CppObject* current_appcontext;
  331. Il2CppObject* root_domain_thread;
  332. Il2CppArray* _serialized_principal;
  333. int _serialized_principal_version;
  334. void* appdomain_refs;
  335. int32_t interruption_requested;
  336. #ifdef __cplusplus
  337. baselib::ReentrantLock* synch_cs;
  338. #else
  339. void* synch_cs;
  340. #endif //__cplusplus
  341. bool threadpool_thread;
  342. bool thread_interrupt_requested;
  343. int stack_size;
  344. uint8_t apartment_state;
  345. int critical_region_level;
  346. int managed_id;
  347. uint32_t small_id;
  348. void* manage_callback;
  349. void* interrupt_on_stop;
  350. intptr_t flags;
  351. void* thread_pinning_ref;
  352. void* abort_protected_block_count;
  353. int32_t priority;
  354. void* owned_mutexes;
  355. void * suspended;
  356. int32_t self_suspended;
  357. size_t thread_state;
  358. size_t unused2;
  359. void* last;
  360. } Il2CppInternalThread;
  361. /* Keep in sync with System.IOSelectorJob in mcs/class/System/System/IOSelectorJob.cs */
  362. typedef struct Il2CppIOSelectorJob
  363. {
  364. Il2CppObject object;
  365. int32_t operation;
  366. Il2CppObject *callback;
  367. Il2CppObject *state;
  368. } Il2CppIOSelectorJob;
  369. /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
  370. typedef enum
  371. {
  372. Il2Cpp_CallType_Sync = 0,
  373. Il2Cpp_CallType_BeginInvoke = 1,
  374. Il2Cpp_CallType_EndInvoke = 2,
  375. Il2Cpp_CallType_OneWay = 3
  376. } Il2CppCallType;
  377. typedef struct Il2CppMethodMessage
  378. {
  379. Il2CppObject obj;
  380. Il2CppReflectionMethod *method;
  381. Il2CppArray *args;
  382. Il2CppArray *names;
  383. Il2CppArray *arg_types;
  384. Il2CppObject *ctx;
  385. Il2CppObject *rval;
  386. Il2CppObject *exc;
  387. Il2CppAsyncResult *async_result;
  388. uint32_t call_type;
  389. } Il2CppMethodMessage;
  390. /* This is a copy of System.AppDomainSetup */
  391. typedef struct Il2CppAppDomainSetup
  392. {
  393. Il2CppObject object;
  394. Il2CppString* application_base;
  395. Il2CppString* application_name;
  396. Il2CppString* cache_path;
  397. Il2CppString* configuration_file;
  398. Il2CppString* dynamic_base;
  399. Il2CppString* license_file;
  400. Il2CppString* private_bin_path;
  401. Il2CppString* private_bin_path_probe;
  402. Il2CppString* shadow_copy_directories;
  403. Il2CppString* shadow_copy_files;
  404. uint8_t publisher_policy;
  405. uint8_t path_changed;
  406. int loader_optimization;
  407. uint8_t disallow_binding_redirects;
  408. uint8_t disallow_code_downloads;
  409. Il2CppObject* activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
  410. Il2CppObject* domain_initializer;
  411. Il2CppObject* application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
  412. Il2CppArray* domain_initializer_args;
  413. uint8_t disallow_appbase_probe;
  414. Il2CppArray* configuration_bytes;
  415. Il2CppArray* serialized_non_primitives;
  416. } Il2CppAppDomainSetup;
  417. // System.Threading.Thread
  418. typedef struct Il2CppThread
  419. {
  420. Il2CppObject obj;
  421. Il2CppInternalThread* internal_thread;
  422. Il2CppObject* start_obj;
  423. Il2CppException* pending_exception;
  424. Il2CppObject* principal;
  425. int32_t principal_version;
  426. Il2CppDelegate* delegate;
  427. Il2CppObject* executionContext;
  428. bool executionContextBelongsToOuterScope;
  429. #ifdef __cplusplus
  430. Il2CppInternalThread* GetInternalThread() const
  431. {
  432. return internal_thread;
  433. }
  434. #endif //__cplusplus
  435. } Il2CppThread;
  436. #ifdef __cplusplus
  437. // System.Exception
  438. typedef struct Il2CppException : public Il2CppObject
  439. {
  440. #else
  441. typedef struct Il2CppException
  442. {
  443. Il2CppObject object;
  444. #endif //__cplusplus
  445. Il2CppString* className;
  446. Il2CppString* message;
  447. Il2CppObject* _data;
  448. Il2CppException* inner_ex;
  449. Il2CppString* _helpURL;
  450. Il2CppArray* trace_ips;
  451. Il2CppString* stack_trace;
  452. Il2CppString* remote_stack_trace;
  453. int remote_stack_index;
  454. Il2CppObject* _dynamicMethods;
  455. il2cpp_hresult_t hresult;
  456. Il2CppString* source;
  457. Il2CppObject* safeSerializationManager;
  458. Il2CppArray* captured_traces;
  459. Il2CppArray* native_trace_ips;
  460. } Il2CppException;
  461. // System.SystemException
  462. typedef struct Il2CppSystemException
  463. {
  464. Il2CppException base;
  465. } Il2CppSystemException;
  466. // System.ArgumentException
  467. typedef struct Il2CppArgumentException
  468. {
  469. Il2CppException base;
  470. Il2CppString *argName;
  471. } Il2CppArgumentException;
  472. // System.TypedReference
  473. typedef struct Il2CppTypedRef
  474. {
  475. const Il2CppType *type;
  476. void* value;
  477. Il2CppClass *klass;
  478. } Il2CppTypedRef;
  479. // System.Delegate
  480. typedef struct Il2CppDelegate
  481. {
  482. Il2CppObject object;
  483. #if !IL2CPP_TINY
  484. /* The compiled code of the target method */
  485. Il2CppMethodPointer method_ptr;
  486. /* The invoke code */
  487. InvokerMethod invoke_impl;
  488. Il2CppObject *target;
  489. const MethodInfo *method;
  490. void* delegate_trampoline;
  491. intptr_t extraArg;
  492. /*
  493. * If non-NULL, this points to a memory location which stores the address of
  494. * the compiled code of the method, or NULL if it is not yet compiled.
  495. */
  496. uint8_t **method_code;
  497. Il2CppReflectionMethod *method_info;
  498. Il2CppReflectionMethod *original_method_info;
  499. Il2CppObject *data;
  500. bool method_is_virtual;
  501. #else
  502. void* method_ptr;
  503. Il2CppObject* m_target;
  504. void* m_ReversePInvokeWrapperPtr;
  505. bool m_IsDelegateOpen;
  506. #endif // !IL2CPP_TINY
  507. } Il2CppDelegate;
  508. typedef struct Il2CppMulticastDelegate
  509. {
  510. Il2CppDelegate delegate;
  511. Il2CppArray *delegates;
  512. #if IL2CPP_TINY
  513. int delegateCount;
  514. #endif
  515. } Il2CppMulticastDelegate;
  516. // System.MarshalByRefObject
  517. typedef struct Il2CppMarshalByRefObject
  518. {
  519. Il2CppObject obj;
  520. Il2CppObject *identity;
  521. } Il2CppMarshalByRefObject;
  522. #ifdef __cplusplus
  523. struct QICache
  524. {
  525. const Il2CppGuid* iid;
  526. Il2CppIUnknown* qiResult;
  527. };
  528. // System.__Il2CppComObject (dummy type that replaces System.__ComObject)
  529. struct Il2CppComObject : Il2CppObject
  530. {
  531. Il2CppIUnknown* identity;
  532. QICache qiShortCache[8];
  533. QICache* qiLongCache;
  534. int32_t qiShortCacheSize;
  535. int32_t qiLongCacheSize;
  536. int32_t qiLongCacheCapacity;
  537. // Same native object can be marshaled to managed code several times. If that happens,
  538. // we have to marshal it to the same RCW (same Il2CppComObject). We use a map of
  539. // IUnknown pointer -> weak GC handles to achieve it, and that works. When managed code
  540. // stops referencing the RCW, GC just garbage collects it and the finalizer will clean it
  541. // from our map. So far so good, eh?
  542. //
  543. // Enter Marshal.ReleaseComObject. This beast is designed to release the underlying COM object,
  544. // but ONLY after we used N amount of times (where N is the amount of times we marshaled
  545. // IUnknown into Il2CppComObject). In order to make it work, we need to implement ref counting.
  546. // This ref count gets incremented each time we marshal IUnknown to Il2CppComObject,
  547. // and gets decremented when Marshal.ReleaseComObject gets called. Fortunately, since we
  548. // live in a world of fairies and garbage collectors, we don't actually have to release it
  549. // manually in order for it to get cleaned up automatically in the future.
  550. int32_t refCount;
  551. };
  552. #endif //__cplusplus
  553. // System.AppDomain
  554. typedef struct Il2CppAppDomain
  555. {
  556. Il2CppMarshalByRefObject mbr;
  557. Il2CppDomain *data;
  558. } Il2CppAppDomain;
  559. // System.Diagnostics.StackFrame
  560. typedef struct Il2CppStackFrame
  561. {
  562. Il2CppObject obj;
  563. int32_t il_offset;
  564. int32_t native_offset;
  565. uint64_t methodAddress;
  566. uint32_t methodIndex;
  567. Il2CppReflectionMethod *method;
  568. Il2CppString *filename;
  569. int32_t line;
  570. int32_t column;
  571. Il2CppString *internal_method_name;
  572. } Il2CppStackFrame;
  573. // System.Globalization.DateTimeFormatInfo
  574. typedef struct Il2CppDateTimeFormatInfo
  575. {
  576. Il2CppObject obj;
  577. Il2CppObject* CultureData;
  578. Il2CppString* Name;
  579. Il2CppString* LangName;
  580. Il2CppObject* CompareInfo;
  581. Il2CppObject* CultureInfo;
  582. Il2CppString* AMDesignator;
  583. Il2CppString* PMDesignator;
  584. Il2CppString* DateSeparator;
  585. Il2CppString* GeneralShortTimePattern;
  586. Il2CppString* GeneralLongTimePattern;
  587. Il2CppString* TimeSeparator;
  588. Il2CppString* MonthDayPattern;
  589. Il2CppString* DateTimeOffsetPattern;
  590. Il2CppObject* Calendar;
  591. uint32_t FirstDayOfWeek;
  592. uint32_t CalendarWeekRule;
  593. Il2CppString* FullDateTimePattern;
  594. Il2CppArray* AbbreviatedDayNames;
  595. Il2CppArray* ShortDayNames;
  596. Il2CppArray* DayNames;
  597. Il2CppArray* AbbreviatedMonthNames;
  598. Il2CppArray* MonthNames;
  599. Il2CppArray* GenitiveMonthNames;
  600. Il2CppArray* GenitiveAbbreviatedMonthNames;
  601. Il2CppArray* LeapYearMonthNames;
  602. Il2CppString* LongDatePattern;
  603. Il2CppString* ShortDatePattern;
  604. Il2CppString* YearMonthPattern;
  605. Il2CppString* LongTimePattern;
  606. Il2CppString* ShortTimePattern;
  607. Il2CppArray* YearMonthPatterns;
  608. Il2CppArray* ShortDatePatterns;
  609. Il2CppArray* LongDatePatterns;
  610. Il2CppArray* ShortTimePatterns;
  611. Il2CppArray* LongTimePatterns;
  612. Il2CppArray* EraNames;
  613. Il2CppArray* AbbrevEraNames;
  614. Il2CppArray* AbbrevEnglishEraNames;
  615. Il2CppArray* OptionalCalendars;
  616. bool readOnly;
  617. int32_t FormatFlags;
  618. int32_t CultureID;
  619. bool UseUserOverride;
  620. bool UseCalendarInfo;
  621. int32_t DataItem;
  622. bool IsDefaultCalendar;
  623. Il2CppArray* DateWords;
  624. Il2CppString* FullTimeSpanPositivePattern;
  625. Il2CppString* FullTimeSpanNegativePattern;
  626. Il2CppArray* dtfiTokenHash;
  627. } Il2CppDateTimeFormatInfo;
  628. // System.Globalization.NumberFormatInfo
  629. typedef struct Il2CppNumberFormatInfo
  630. {
  631. Il2CppObject obj;
  632. Il2CppArray* numberGroupSizes;
  633. Il2CppArray* currencyGroupSizes;
  634. Il2CppArray* percentGroupSizes;
  635. Il2CppString* positiveSign;
  636. Il2CppString* negativeSign;
  637. Il2CppString* numberDecimalSeparator;
  638. Il2CppString* numberGroupSeparator;
  639. Il2CppString* currencyGroupSeparator;
  640. Il2CppString* currencyDecimalSeparator;
  641. Il2CppString* currencySymbol;
  642. Il2CppString* ansiCurrencySymbol;
  643. Il2CppString* naNSymbol;
  644. Il2CppString* positiveInfinitySymbol;
  645. Il2CppString* negativeInfinitySymbol;
  646. Il2CppString* percentDecimalSeparator;
  647. Il2CppString* percentGroupSeparator;
  648. Il2CppString* percentSymbol;
  649. Il2CppString* perMilleSymbol;
  650. Il2CppArray* nativeDigits;
  651. int dataItem;
  652. int numberDecimalDigits;
  653. int currencyDecimalDigits;
  654. int currencyPositivePattern;
  655. int currencyNegativePattern;
  656. int numberNegativePattern;
  657. int percentPositivePattern;
  658. int percentNegativePattern;
  659. int percentDecimalDigits;
  660. int digitSubstitution;
  661. bool readOnly;
  662. bool useUserOverride;
  663. bool isInvariant;
  664. bool validForParseAsNumber;
  665. bool validForParseAsCurrency;
  666. } Il2CppNumberFormatInfo;
  667. typedef struct Il2CppCultureData
  668. {
  669. Il2CppObject obj;
  670. Il2CppString *AMDesignator;
  671. Il2CppString *PMDesignator;
  672. Il2CppString *TimeSeparator;
  673. Il2CppArray *LongTimePatterns;
  674. Il2CppArray *ShortTimePatterns;
  675. uint32_t FirstDayOfWeek;
  676. uint32_t CalendarWeekRule;
  677. } Il2CppCultureData;
  678. typedef struct Il2CppCalendarData
  679. {
  680. Il2CppObject obj;
  681. Il2CppString *NativeName;
  682. Il2CppArray *ShortDatePatterns;
  683. Il2CppArray *YearMonthPatterns;
  684. Il2CppArray *LongDatePatterns;
  685. Il2CppString *MonthDayPattern;
  686. Il2CppArray *EraNames;
  687. Il2CppArray *AbbreviatedEraNames;
  688. Il2CppArray *AbbreviatedEnglishEraNames;
  689. Il2CppArray *DayNames;
  690. Il2CppArray *AbbreviatedDayNames;
  691. Il2CppArray *SuperShortDayNames;
  692. Il2CppArray *MonthNames;
  693. Il2CppArray *AbbreviatedMonthNames;
  694. Il2CppArray *GenitiveMonthNames;
  695. Il2CppArray *GenitiveAbbreviatedMonthNames;
  696. } Il2CppCalendarData;
  697. // System.Globalization.CultureInfo
  698. typedef struct Il2CppCultureInfo
  699. {
  700. Il2CppObject obj;
  701. bool is_read_only;
  702. int32_t lcid;
  703. int32_t parent_lcid;
  704. int32_t datetime_index;
  705. int32_t number_index;
  706. int32_t default_calendar_type;
  707. bool use_user_override;
  708. Il2CppNumberFormatInfo* number_format;
  709. Il2CppDateTimeFormatInfo* datetime_format;
  710. Il2CppObject* textinfo;
  711. Il2CppString* name;
  712. Il2CppString* englishname;
  713. Il2CppString* nativename;
  714. Il2CppString* iso3lang;
  715. Il2CppString* iso2lang;
  716. Il2CppString* win3lang;
  717. Il2CppString* territory;
  718. Il2CppArray* native_calendar_names;
  719. Il2CppString* compareinfo;
  720. const void* text_info_data;
  721. int dataItem;
  722. Il2CppObject* calendar;
  723. Il2CppObject* parent_culture;
  724. bool constructed;
  725. Il2CppArray* cached_serialized_form;
  726. Il2CppObject* cultureData;
  727. bool isInherited;
  728. } Il2CppCultureInfo;
  729. // System.Globalization.RegionInfo
  730. typedef struct Il2CppRegionInfo
  731. {
  732. Il2CppObject obj;
  733. int32_t geo_id;
  734. Il2CppString* iso2name;
  735. Il2CppString* iso3name;
  736. Il2CppString* win3name;
  737. Il2CppString* english_name;
  738. Il2CppString* native_name;
  739. Il2CppString* currency_symbol;
  740. Il2CppString* iso_currency_symbol;
  741. Il2CppString* currency_english_name;
  742. Il2CppString* currency_native_name;
  743. } Il2CppRegionInfo;
  744. // System.Runtime.InteropServices.SafeHandle
  745. // Inherited by Microsoft.Win32.SafeHandles.SafeWaitHandle
  746. typedef struct Il2CppSafeHandle
  747. {
  748. Il2CppObject base;
  749. void* handle;
  750. int state;
  751. bool owns_handle;
  752. bool fullyInitialized;
  753. } Il2CppSafeHandle;
  754. // System.Text.StringBuilder
  755. typedef struct Il2CppStringBuilder Il2CppStringBuilder;
  756. typedef struct Il2CppStringBuilder
  757. {
  758. Il2CppObject object;
  759. Il2CppArray* chunkChars;
  760. Il2CppStringBuilder* chunkPrevious;
  761. int chunkLength;
  762. int chunkOffset;
  763. int maxCapacity;
  764. } Il2CppStringBuilder;
  765. // System.Net.SocketAddress
  766. typedef struct Il2CppSocketAddress
  767. {
  768. Il2CppObject base;
  769. int m_Size;
  770. Il2CppArray* data;
  771. bool m_changed;
  772. int m_hash;
  773. } Il2CppSocketAddress;
  774. // System.Globalization.SortKey
  775. typedef struct Il2CppSortKey
  776. {
  777. Il2CppObject base;
  778. Il2CppString *str;
  779. Il2CppArray *key;
  780. int32_t options;
  781. int32_t lcid;
  782. } Il2CppSortKey;
  783. // System.Runtime.InteropServices.ErrorWrapper
  784. typedef struct Il2CppErrorWrapper
  785. {
  786. Il2CppObject base;
  787. int32_t errorCode;
  788. } Il2CppErrorWrapper;
  789. // System.Runtime.Remoting.Messaging.AsyncResult
  790. typedef struct Il2CppAsyncResult
  791. {
  792. Il2CppObject base;
  793. Il2CppObject *async_state;
  794. Il2CppWaitHandle *handle;
  795. Il2CppDelegate *async_delegate;
  796. void* data; // We pass delegate arguments here. This is repurposed. Depends on Mono C# code not using the field.
  797. Il2CppAsyncCall *object_data;
  798. bool sync_completed;
  799. bool completed;
  800. bool endinvoke_called;
  801. Il2CppObject *async_callback;
  802. Il2CppObject *execution_context;
  803. Il2CppObject *original_context;
  804. } Il2CppAsyncResult;
  805. // System.MonoAsyncCall
  806. typedef struct Il2CppAsyncCall
  807. {
  808. Il2CppObject base;
  809. Il2CppMethodMessage *msg;
  810. MethodInfo *cb_method; // We don't set this.
  811. Il2CppDelegate *cb_target; // We pass the actual delegate here.
  812. Il2CppObject *state;
  813. Il2CppObject *res;
  814. Il2CppArray *out_args;
  815. } Il2CppAsyncCall;
  816. typedef struct Il2CppExceptionWrapper Il2CppExceptionWrapper;
  817. typedef struct Il2CppExceptionWrapper
  818. {
  819. Il2CppException* ex;
  820. #ifdef __cplusplus
  821. Il2CppExceptionWrapper(Il2CppException* ex) : ex(ex) {}
  822. #endif //__cplusplus
  823. } Il2CppExceptionWrapper;
  824. typedef struct Il2CppIOAsyncResult
  825. {
  826. Il2CppObject base;
  827. Il2CppDelegate* callback;
  828. Il2CppObject* state;
  829. Il2CppWaitHandle* wait_handle;
  830. bool completed_synchronously;
  831. bool completed;
  832. } Il2CppIOAsyncResult;
  833. /// Corresponds to Mono's internal System.Net.Sockets.Socket.SocketAsyncResult
  834. /// class. Has no relation to Il2CppAsyncResult.
  835. typedef struct Il2CppSocketAsyncResult
  836. {
  837. Il2CppIOAsyncResult base;
  838. Il2CppObject* socket;
  839. int32_t operation;
  840. Il2CppException* delayedException;
  841. Il2CppObject* endPoint;
  842. Il2CppArray* buffer;
  843. int32_t offset;
  844. int32_t size;
  845. int32_t socket_flags;
  846. Il2CppObject* acceptSocket;
  847. Il2CppArray* addresses;
  848. int32_t port;
  849. Il2CppObject* buffers;
  850. bool reuseSocket;
  851. int32_t currentAddress;
  852. Il2CppObject* acceptedSocket;
  853. int32_t total;
  854. int32_t error;
  855. int32_t endCalled;
  856. } Il2CppSocketAsyncResult;
  857. typedef enum Il2CppResourceLocation
  858. {
  859. IL2CPP_RESOURCE_LOCATION_EMBEDDED = 1,
  860. IL2CPP_RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
  861. IL2CPP_RESOURCE_LOCATION_IN_MANIFEST = 4
  862. } Il2CppResourceLocation;
  863. // System.Reflection.ManifestResourceInfo
  864. typedef struct Il2CppManifestResourceInfo
  865. {
  866. Il2CppObject object;
  867. Il2CppReflectionAssembly* assembly;
  868. Il2CppString* filename;
  869. uint32_t location;
  870. } Il2CppManifestResourceInfo;
  871. #define IL2CPP_CHECK_ARG_NULL(arg) do { \
  872. if (arg == NULL) \
  873. { \
  874. il2cpp::vm::Exception::Raise (il2cpp::vm::Exception::GetArgumentNullException (#arg)); \
  875. }; } while (0)
  876. // System.Runtime.Remoting.Contexts.Context
  877. typedef struct Il2CppAppContext
  878. {
  879. Il2CppObject obj;
  880. int32_t domain_id;
  881. int32_t context_id;
  882. void* static_data;
  883. } Il2CppAppContext;
  884. typedef struct Il2CppDecimal
  885. {
  886. // Decimal.cs treats the first two shorts as one long
  887. // And they seriable the data so we need to little endian
  888. // seriliazation
  889. // The wReserved overlaps with Variant's vt member
  890. #if IL2CPP_BYTE_ORDER == IL2CPP_BIG_ENDIAN
  891. union
  892. {
  893. struct
  894. {
  895. uint8_t sign;
  896. uint8_t scale;
  897. } u;
  898. uint16_t signscale;
  899. } u;
  900. uint16_t reserved;
  901. #else
  902. uint16_t reserved;
  903. union
  904. {
  905. struct
  906. {
  907. uint8_t scale;
  908. uint8_t sign;
  909. } u;
  910. uint16_t signscale;
  911. } u;
  912. #endif
  913. uint32_t Hi32;
  914. union
  915. {
  916. struct
  917. {
  918. uint32_t Lo32;
  919. uint32_t Mid32;
  920. } v;
  921. uint64_t Lo64;
  922. } v;
  923. } Il2CppDecimal;
  924. // Structure to access an encoded double floating point
  925. typedef struct Il2CppDouble
  926. {
  927. #if IL2CPP_BYTE_ORDER == IL2CPP_BIG_ENDIAN
  928. uint32_t sign : 1;
  929. uint32_t exp : 11;
  930. uint32_t mantHi : 20;
  931. uint32_t mantLo : 32;
  932. #else // BIGENDIAN
  933. uint32_t mantLo : 32;
  934. uint32_t mantHi : 20;
  935. uint32_t exp : 11;
  936. uint32_t sign : 1;
  937. #endif
  938. } Il2CppDouble;
  939. typedef union Il2CppDouble_double
  940. {
  941. Il2CppDouble s;
  942. double d;
  943. } Il2CppDouble_double;
  944. typedef enum Il2CppDecimalCompareResult
  945. {
  946. IL2CPP_DECIMAL_CMP_LT = -1,
  947. IL2CPP_DECIMAL_CMP_EQ,
  948. IL2CPP_DECIMAL_CMP_GT
  949. } Il2CppDecimalCompareResult;
  950. // Structure to access an encoded single floating point
  951. typedef struct Il2CppSingle
  952. {
  953. #if IL2CPP_BYTE_ORDER == IL2CPP_BIG_ENDIAN
  954. uint32_t sign : 1;
  955. uint32_t exp : 8;
  956. uint32_t mant : 23;
  957. #else
  958. uint32_t mant : 23;
  959. uint32_t exp : 8;
  960. uint32_t sign : 1;
  961. #endif
  962. } Il2CppSingle;
  963. typedef union Il2CppSingle_float
  964. {
  965. Il2CppSingle s;
  966. float f;
  967. } Il2CppSingle_float;
  968. #endif // !RUNTIME_TINY