forked from focus-creative-games/il2cpp_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathil2cpp-codegen.cpp
More file actions
1136 lines (933 loc) · 40.9 KB
/
il2cpp-codegen.cpp
File metadata and controls
1136 lines (933 loc) · 40.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <string>
#include <stdarg.h>
#include "il2cpp-config.h"
#include "il2cpp-codegen.h"
#include "utils/Exception.h"
#include "os/Atomic.h"
#include "metadata/GenericMethod.h"
#include "gc/GarbageCollector.h"
#include "gc/WriteBarrier.h"
#include "vm/Array.h"
#include "vm/CCW.h"
#include "vm/COM.h"
#include "vm/Class.h"
#include "vm/Exception.h"
#include "vm/Field.h"
#include "vm/InternalCalls.h"
#include "vm/LastError.h"
#include "vm/MarshalAlloc.h"
#include "vm/MetadataCache.h"
#include "vm/Method.h"
#include "vm/Object.h"
#include "vm/PlatformInvoke.h"
#include "vm/Profiler.h"
#include "vm/RCW.h"
#include "vm/Reflection.h"
#include "vm/Runtime.h"
#include "vm/StackTrace.h"
#include "vm/String.h"
#include "vm/Thread.h"
#include "vm/ThreadPoolMs.h"
#include "vm/Type.h"
#include "vm/WindowsRuntime.h"
#include "vm-utils/VmThreadUtils.h"
#include "utils/Runtime.h"
#if IL2CPP_ENABLE_WRITE_BARRIERS
void Il2CppCodeGenWriteBarrier(void** targetAddress, void* object)
{
il2cpp::gc::GarbageCollector::SetWriteBarrier(targetAddress);
}
#endif
// This function exists to help with generation of callstacks for exceptions
// on iOS and MacOS x64 with clang 6.0 (newer versions of clang don't have this
// problem on x64). There we call the backtrace function, which does not play nicely
// with NORETURN, since the compiler eliminates the method prologue code setting up
// the address of the return frame (which makes sense). So on iOS we need to make
// the NORETURN define do nothing, then we use this dummy method which has the
// attribute for clang on iOS defined to prevent clang compiler errors for
// method that end by throwing a managed exception.
REAL_NORETURN IL2CPP_NO_INLINE void il2cpp_codegen_no_return()
{
IL2CPP_UNREACHABLE;
}
REAL_NORETURN void il2cpp_codegen_abort()
{
il2cpp::utils::Runtime::Abort();
il2cpp_codegen_no_return();
}
#if IL2CPP_ENABLE_WRITE_BARRIERS
void Il2CppCodeGenWriteBarrierForType(const Il2CppType* type, void** targetAddress, void* object)
{
#if IL2CPP_ENABLE_STRICT_WRITE_BARRIERS
if (il2cpp::vm::Type::IsPointerType(type))
return;
if (il2cpp::vm::Type::IsStruct(type))
{
Il2CppClass* klass = il2cpp::vm::Class::FromIl2CppType(type);
FieldInfo* field;
void* iter = NULL;
while ((field = il2cpp::vm::Class::GetFields(klass, &iter)))
{
if (il2cpp::vm::Field::GetFlags(field) & FIELD_ATTRIBUTE_STATIC)
continue;
void* fieldTargetAddress = il2cpp::vm::Field::GetInstanceFieldDataPointer((void*)targetAddress, field);
Il2CppCodeGenWriteBarrierForType(field->type, (void**)fieldTargetAddress, NULL);
}
}
else
{
il2cpp::gc::GarbageCollector::SetWriteBarrier(targetAddress);
}
#else
il2cpp::gc::GarbageCollector::SetWriteBarrier(targetAddress);
#endif
}
void Il2CppCodeGenWriteBarrierForClass(Il2CppClass* klass, void** targetAddress, void* object)
{
#if IL2CPP_ENABLE_STRICT_WRITE_BARRIERS
Il2CppCodeGenWriteBarrierForType(il2cpp::vm::Class::GetType(klass), targetAddress, object);
#else
il2cpp::gc::GarbageCollector::SetWriteBarrier(targetAddress);
#endif
}
#endif // IL2CPP_ENABLE_WRITE_BARRIERS
void* il2cpp_codegen_atomic_compare_exchange_pointer(void** dest, void* exchange, void* comparand)
{
return il2cpp::os::Atomic::CompareExchangePointer(dest, exchange, comparand);
}
void il2cpp_codegen_marshal_store_last_error()
{
il2cpp::vm::LastError::StoreLastError();
}
Il2CppAsyncResult* il2cpp_codegen_delegate_begin_invoke(RuntimeDelegate* delegate, void** params, RuntimeDelegate* asyncCallback, RuntimeObject* state)
{
return il2cpp::vm::ThreadPoolMs::DelegateBeginInvoke(delegate, params, asyncCallback, state);
}
RuntimeObject* il2cpp_codegen_delegate_end_invoke(Il2CppAsyncResult* asyncResult, void **out_args)
{
return il2cpp::vm::ThreadPoolMs::DelegateEndInvoke(asyncResult, out_args);
}
void il2cpp_codegen_set_closed_delegate_invoke(RuntimeObject* delegate, RuntimeObject* target, void* methodPtr)
{
IL2CPP_ASSERT(delegate->klass->parent == il2cpp_defaults.multicastdelegate_class);
il2cpp::vm::Type::SetClosedDelegateInvokeMethod((RuntimeDelegate*)delegate, target, (Il2CppMethodPointer)methodPtr);
}
Il2CppMethodPointer il2cpp_codegen_resolve_icall(const char* name)
{
Il2CppMethodPointer method = il2cpp::vm::InternalCalls::Resolve(name);
if (!method)
{
il2cpp::vm::Exception::Raise(il2cpp::vm::Exception::GetMissingMethodException(name));
}
return method;
}
Type_t* il2cpp_codegen_type_get_object(const RuntimeType* type)
{
return (Type_t*)il2cpp::vm::Reflection::GetTypeObject(type);
}
MethodBase_t* il2cpp_codegen_get_method_object_internal(const RuntimeMethod* method, RuntimeClass* refclass)
{
return (MethodBase_t*)il2cpp::vm::Reflection::GetMethodObject(method, method->klass);
}
Assembly_t* il2cpp_codegen_get_executing_assembly(const RuntimeMethod* method)
{
return (Assembly_t*)il2cpp::vm::Reflection::GetAssemblyObject(method->klass->image->assembly);
}
void il2cpp_codegen_register(const Il2CppCodeRegistration* const codeRegistration, const Il2CppMetadataRegistration* const metadataRegistration, const Il2CppCodeGenOptions* const codeGenOptions)
{
il2cpp::vm::MetadataCache::Register(codeRegistration, metadataRegistration, codeGenOptions);
}
extern MetadataInitializerCleanupFunc g_ClearMethodMetadataInitializedFlags;
void il2cpp_codegen_register_metadata_initialized_cleanup(MetadataInitializerCleanupFunc cleanup)
{
g_ClearMethodMetadataInitializedFlags = cleanup;
}
void il2cpp_codegen_initialize_runtime_metadata(uintptr_t* metadataPointer)
{
il2cpp::vm::MetadataCache::InitializeRuntimeMetadata(metadataPointer);
// We don't need a memory barrier here, InitializeRuntimeMetadata already has one
// What we need is a barrier before setting s_Il2CppMethodInitialized = true in the generated code
// but adding that to every function increases code size, so instead we rely on this function
// being called before s_Il2CppCodeRegistrationInitialized is set to true
il2cpp::os::Atomic::FullMemoryBarrier();
}
void* il2cpp_codegen_initialize_runtime_metadata_inline(uintptr_t* metadataPointer)
{
return il2cpp::vm::MetadataCache::InitializeRuntimeMetadata(metadataPointer);
}
const RuntimeClass* il2cpp_codegen_get_generic_type_definition(const RuntimeClass* klass)
{
IL2CPP_ASSERT(klass->generic_class);
return il2cpp::vm::Class::FromIl2CppType(klass->generic_class->type);
}
const RuntimeMethod* il2cpp_codegen_get_generic_method_definition(const RuntimeMethod* method)
{
return il2cpp::vm::MetadataCache::GetGenericMethodDefinition(method);
}
const RuntimeMethod* il2cpp_codegen_get_generic_instance_method_from_method_definition(RuntimeClass* genericInstanceClass, const RuntimeMethod* methodDefinition)
{
return il2cpp::vm::Class::GetGenericInstanceMethodFromDefintion(genericInstanceClass, methodDefinition);
}
void* il2cpp_codegen_get_thread_static_data(RuntimeClass* klass)
{
return il2cpp::vm::Thread::GetThreadStaticData(klass->thread_static_fields_offset);
}
void il2cpp_codegen_assert_field_size(RuntimeField* field, size_t size)
{
IL2CPP_ASSERT(size == il2cpp_codegen_sizeof(InitializedTypeInfo(il2cpp::vm::Class::FromIl2CppType(field->type))));
}
void* il2cpp_codegen_get_instance_field_data_pointer(void* instance, RuntimeField* field)
{
return il2cpp::vm::Field::GetInstanceFieldDataPointer(instance, field);
}
void il2cpp_codegen_write_instance_field_data(void* instance, RuntimeField* field, void* data, uint32_t size)
{
il2cpp_codegen_assert_field_size(field, size);
IL2CPP_ASSERT(il2cpp::vm::Field::IsInstance(field));
void* fieldPointer = il2cpp_codegen_get_instance_field_data_pointer(instance, field);
il2cpp_codegen_memcpy(fieldPointer, data, size);
Il2CppCodeGenWriteBarrierForType(field->type, (void**)fieldPointer, NULL);
}
void* il2cpp_codegen_get_static_field_data_pointer(RuntimeField* field)
{
IL2CPP_ASSERT(il2cpp::vm::Field::IsNormalStatic(field));
return ((uint8_t*)field->parent->static_fields) + field->offset;
}
void il2cpp_codegen_write_static_field_data(RuntimeField* field, void* data, uint32_t size)
{
il2cpp_codegen_assert_field_size(field, size);
IL2CPP_ASSERT(il2cpp::vm::Field::IsNormalStatic(field));
void* fieldPointer = il2cpp_codegen_get_static_field_data_pointer(field);
il2cpp_codegen_memcpy(fieldPointer, data, size);
Il2CppCodeGenWriteBarrierForType(field->type, (void**)fieldPointer, NULL);
}
void* il2cpp_codegen_get_thread_static_field_data_pointer(RuntimeField* field)
{
IL2CPP_ASSERT(il2cpp::vm::Field::IsThreadStatic(field));
int threadStaticFieldOffset = il2cpp::vm::MetadataCache::GetThreadLocalStaticOffsetForField(field);
void* threadStaticData = il2cpp::vm::Thread::GetThreadStaticData(field->parent->thread_static_fields_offset);
return static_cast<uint8_t*>(threadStaticData) + threadStaticFieldOffset;
}
void il2cpp_codegen_write_thread_static_field_data(RuntimeField* field, void* data, uint32_t size)
{
il2cpp_codegen_assert_field_size(field, size);
IL2CPP_ASSERT(il2cpp::vm::Field::IsThreadStatic(field));
void* fieldPointer = il2cpp_codegen_get_thread_static_field_data_pointer(field);
il2cpp_codegen_memcpy(fieldPointer, data, size);
Il2CppCodeGenWriteBarrierForType(field->type, (void**)fieldPointer, NULL);
}
void il2cpp_codegen_memory_barrier()
{
il2cpp::vm::Thread::FullMemoryBarrier();
}
void SetGenericValueImpl(RuntimeArray* thisPtr, int32_t pos, void* value)
{
il2cpp_array_setrefwithsize(thisPtr, thisPtr->klass->element_size, pos, value);
}
RuntimeArray* SZArrayNew(RuntimeClass* arrayType, uint32_t length)
{
return il2cpp::vm::Array::NewSpecific(arrayType, length);
}
RuntimeArray* GenArrayNew(RuntimeClass* arrayType, il2cpp_array_size_t* dimensions)
{
return il2cpp::vm::Array::NewFull(arrayType, dimensions, NULL);
}
bool il2cpp_codegen_method_is_generic_instance_method(RuntimeMethod* method)
{
return il2cpp::vm::Method::IsGenericInstanceMethod(method);
}
bool il2cpp_codegen_method_is_generic_instance(RuntimeClass* klass)
{
return il2cpp::vm::Class::IsInflated(klass);
}
RuntimeClass* il2cpp_codegen_method_get_declaring_type(const RuntimeMethod* method)
{
return il2cpp::vm::Method::GetClass(method);
}
bool MethodIsStatic(const RuntimeMethod* method)
{
return !il2cpp::vm::Method::IsInstance(method);
}
bool MethodHasParameters(const RuntimeMethod* method)
{
return il2cpp::vm::Method::GetParamCount(method) != 0;
}
NORETURN void il2cpp_codegen_raise_profile_exception(const RuntimeMethod* method)
{
std::string methodName = il2cpp::vm::Method::GetFullName(method);
il2cpp_codegen_raise_exception(il2cpp_codegen_get_not_supported_exception(methodName.c_str()));
}
const RuntimeMethod* il2cpp_codegen_get_generic_virtual_method_internal(const RuntimeMethod* vtableSlotMethod, const RuntimeMethod* genericVirtualMethod)
{
return il2cpp::metadata::GenericMethod::GetGenericVirtualMethod(vtableSlotMethod, genericVirtualMethod);
}
void il2cpp_codegen_runtime_class_init(RuntimeClass* klass)
{
il2cpp::vm::Runtime::ClassInit(klass);
}
void il2cpp_codegen_raise_execution_engine_exception(const RuntimeMethod* method)
{
il2cpp::vm::Runtime::AlwaysRaiseExecutionEngineException(method);
}
void il2cpp_codegen_raise_execution_engine_exception_missing_virtual(const RuntimeMethod* method)
{
il2cpp::vm::Runtime::AlwaysRaiseExecutionEngineExceptionOnVirtualCall(method);
}
RuntimeObject* IsInst(RuntimeObject *obj, RuntimeClass* targetType)
{
return il2cpp::vm::Object::IsInst(obj, targetType);
}
RuntimeObject* Box(RuntimeClass* type, void* data)
{
return il2cpp::vm::Object::Box(type, data);
}
void* Unbox_internal(Il2CppObject* obj)
{
return il2cpp::vm::Object::Unbox(obj);
}
void UnBoxNullable_internal(RuntimeObject* obj, RuntimeClass* nullableClass, void* storage)
{
il2cpp::vm::Object::UnboxNullable(obj, nullableClass, storage);
}
void* UnBox_Any(RuntimeObject* obj, RuntimeClass* expectedBoxedClass, void* unboxStorage)
{
IL2CPP_ASSERT(unboxStorage != NULL);
// We assume unboxStorage is on the stack, if not we'll need a write barrier
IL2CPP_ASSERT_STACK_PTR(unboxStorage);
if (il2cpp::vm::Class::IsValuetype(expectedBoxedClass))
{
if (il2cpp::vm::Class::IsNullable(expectedBoxedClass))
{
UnBoxNullable(obj, expectedBoxedClass, unboxStorage);
return unboxStorage;
}
return UnBox(obj, expectedBoxedClass);
}
// Use unboxStorage to return a pointer to obj
// This keeps the return value of UnBox_Any consistent; it always returns a pointer to the data we want
// This saves a runtime check on the class type
*((void**)unboxStorage) = Castclass(obj, expectedBoxedClass);
return unboxStorage;
}
bool il2cpp_codegen_would_box_to_non_null(RuntimeClass* klass, void* objBuffer)
{
if (il2cpp::vm::Class::IsValuetype(klass))
{
if (il2cpp::vm::Class::IsNullable(klass))
return il2cpp::vm::Object::NullableHasValue(klass, objBuffer);
return true;
}
return *(void**)objBuffer != NULL;
}
RuntimeObject* il2cpp_codegen_object_new(RuntimeClass *klass)
{
return il2cpp::vm::Object::New(klass);
}
void* il2cpp_codegen_marshal_allocate(size_t size)
{
return il2cpp::vm::MarshalAlloc::Allocate(size);
}
#if _DEBUG
void il2cpp_codegen_marshal_allocate_push_allocation_frame()
{
il2cpp::vm::MarshalAlloc::PushAllocationFrame();
}
void il2cpp_codegen_marshal_allocate_pop_allocation_frame()
{
il2cpp::vm::MarshalAlloc::PopAllocationFrame();
}
bool il2cpp_codegen_marshal_allocate_has_unfreed_allocations()
{
return il2cpp::vm::MarshalAlloc::HasUnfreedAllocations();
}
void il2cpp_codegen_marshal_allocate_clear_all_tracked_allocations()
{
il2cpp::vm::MarshalAlloc::ClearAllTrackedAllocations();
}
#endif
#if IL2CPP_ENABLE_PROFILER
void il2cpp_codegen_profiler_method_enter(const RuntimeMethod* method)
{
il2cpp::vm::Profiler::MethodEnter(method);
}
void il2cpp_codegen_profiler_method_exit(const RuntimeMethod* method)
{
il2cpp::vm::Profiler::MethodExit(method);
}
#endif
NORETURN void il2cpp_codegen_raise_exception(Exception_t *ex, MethodInfo* lastManagedFrame)
{
RuntimeException* exc = (RuntimeException*)ex;
IL2CPP_OBJECT_SETREF_NULL(exc, trace_ips);
IL2CPP_OBJECT_SETREF_NULL(exc, stack_trace);
il2cpp::vm::Exception::Raise(exc, lastManagedFrame);
}
NORETURN void il2cpp_codegen_rethrow_exception(Exception_t *ex)
{
il2cpp::vm::Exception::Rethrow((RuntimeException*)ex);
}
NORETURN void il2cpp_codegen_raise_exception(il2cpp_hresult_t hresult, bool defaultToCOMException)
{
il2cpp::vm::Exception::Raise(hresult, defaultToCOMException);
}
NORETURN void il2cpp_codegen_raise_out_of_memory_exception()
{
il2cpp::vm::Exception::RaiseOutOfMemoryException();
}
NORETURN void il2cpp_codegen_raise_null_reference_exception()
{
il2cpp::vm::Exception::RaiseNullReferenceException();
}
NORETURN void il2cpp_codegen_raise_divide_by_zero_exception()
{
il2cpp::vm::Exception::RaiseDivideByZeroException();
}
NORETURN void il2cpp_codegen_raise_index_out_of_range_exception()
{
il2cpp::vm::Exception::RaiseIndexOutOfRangeException();
}
NORETURN void il2cpp_codegen_raise_index_out_of_range_exception(const RuntimeMethod* method)
{
IL2CPP_RAISE_MANAGED_EXCEPTION(il2cpp_codegen_get_overflow_exception(), method);
}
NORETURN void il2cpp_codegen_raise_invalid_unmanaged_callers_usage(const RuntimeMethod* method, const char* msg)
{
std::string fullName = il2cpp::vm::Method::GetFullName(method);
IL2CPP_RAISE_MANAGED_EXCEPTION(il2cpp::vm::Exception::GetExecutionEngineException((fullName + ": " + msg).c_str()), method);
}
Exception_t* il2cpp_codegen_get_argument_exception(const char* param, const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetArgumentException(param, msg);
}
Exception_t* il2cpp_codegen_get_argument_null_exception(const char* param)
{
return (Exception_t*)il2cpp::vm::Exception::GetArgumentNullException(param);
}
Exception_t* il2cpp_codegen_get_overflow_exception()
{
return (Exception_t*)il2cpp::vm::Exception::GetOverflowException("Arithmetic operation resulted in an overflow.");
}
Exception_t* il2cpp_codegen_get_not_supported_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetNotSupportedException(msg);
}
Exception_t* il2cpp_codegen_get_array_type_mismatch_exception()
{
return (Exception_t*)il2cpp::vm::Exception::GetArrayTypeMismatchException();
}
Exception_t* il2cpp_codegen_get_invalid_cast_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetInvalidCastException(msg);
}
Exception_t* il2cpp_codegen_get_invalid_operation_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetInvalidOperationException(msg);
}
Exception_t* il2cpp_codegen_get_marshal_directive_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetMarshalDirectiveException(msg);
}
Exception_t* il2cpp_codegen_get_marshal_directive_exception(const char* msg, const RuntimeType* type)
{
auto formattedMsg = il2cpp::utils::StringUtils::Printf(msg, il2cpp::vm::Type::GetName(type, IL2CPP_TYPE_NAME_FORMAT_FULL_NAME).c_str());
return (Exception_t*)il2cpp::vm::Exception::GetMarshalDirectiveException(formattedMsg.c_str());
}
// format string will require first instance as a field and second instance as a type or this will break
Exception_t* il2cpp_codegen_get_marshal_directive_exception(const char* msg, const RuntimeField *field, const RuntimeType* type)
{
auto formattedMsg = il2cpp::utils::StringUtils::Printf(msg, il2cpp::vm::Field::GetName(field), il2cpp::vm::Type::GetName(type, IL2CPP_TYPE_NAME_FORMAT_FULL_NAME).c_str());
return (Exception_t*)il2cpp::vm::Exception::GetMarshalDirectiveException(formattedMsg.c_str());
}
Exception_t* il2cpp_codegen_get_missing_method_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetMissingMethodException(msg);
}
Exception_t* il2cpp_codegen_get_maximum_nested_generics_exception()
{
return (Exception_t*)il2cpp::vm::Exception::GetMaximumNestedGenericsException();
}
Exception_t* il2cpp_codegen_get_engine_execution_exception(const char* msg)
{
return (Exception_t*)il2cpp::vm::Exception::GetExecutionEngineException(msg);
}
Exception_t* il2cpp_codegen_get_index_out_of_range_exception()
{
return (Exception_t*)il2cpp::vm::Exception::GetIndexOutOfRangeException();
}
Exception_t* il2cpp_codegen_get_exception(il2cpp_hresult_t hresult, bool defaultToCOMException)
{
return (Exception_t*)il2cpp::vm::Exception::Get(hresult, defaultToCOMException);
}
void il2cpp_codegen_store_exception_info(RuntimeException* ex, String_t* exceptionString)
{
il2cpp::vm::Exception::StoreExceptionInfo(ex, reinterpret_cast<RuntimeString*>(exceptionString));
}
void il2cpp_codegen_com_marshal_variant(RuntimeObject* obj, Il2CppVariant* variant)
{
il2cpp::vm::COM::MarshalVariant(obj, variant);
}
RuntimeObject* il2cpp_codegen_com_marshal_variant_result(const Il2CppVariant* variant)
{
return il2cpp::vm::COM::MarshalVariantResult(variant);
}
void il2cpp_codegen_com_destroy_variant(Il2CppVariant* variant)
{
il2cpp::vm::COM::DestroyVariant(variant);
}
Il2CppSafeArray* il2cpp_codegen_com_marshal_safe_array(Il2CppChar type, RuntimeArray* managedArray)
{
return il2cpp::vm::COM::MarshalSafeArray(type, managedArray);
}
RuntimeArray* il2cpp_codegen_com_marshal_safe_array_result(Il2CppChar variantType, RuntimeClass* type, Il2CppSafeArray* safeArray)
{
return il2cpp::vm::COM::MarshalSafeArrayResult(variantType, type, safeArray);
}
Il2CppSafeArray* il2cpp_codegen_com_marshal_safe_array_bstring(RuntimeArray* managedArray)
{
return il2cpp::vm::COM::MarshalSafeArrayBString(managedArray);
}
RuntimeArray* il2cpp_codegen_com_marshal_safe_array_bstring_result(RuntimeClass* type, Il2CppSafeArray* safeArray)
{
return il2cpp::vm::COM::MarshalSafeArrayBStringResult(type, safeArray);
}
void il2cpp_codegen_com_destroy_safe_array(Il2CppSafeArray* safeArray)
{
il2cpp::vm::COM::DestroySafeArray(safeArray);
}
void il2cpp_codegen_com_create_instance(const Il2CppGuid& clsid, Il2CppIUnknown** identity)
{
il2cpp::vm::COM::CreateInstance(clsid, identity);
}
il2cpp_hresult_t il2cpp_codegen_com_handle_invalid_iproperty_conversion(const char* fromType, const char* toType)
{
return il2cpp::vm::CCW::HandleInvalidIPropertyConversion(fromType, toType);
}
il2cpp_hresult_t il2cpp_codegen_com_handle_invalid_iproperty_conversion(RuntimeObject* value, const char* fromType, const char* toType)
{
return il2cpp::vm::CCW::HandleInvalidIPropertyConversion(value, fromType, toType);
}
il2cpp_hresult_t il2cpp_codegen_com_handle_invalid_ipropertyarray_conversion(const char* fromArrayType, const char* fromElementType, const char* toElementType, il2cpp_array_size_t index)
{
return il2cpp::vm::CCW::HandleInvalidIPropertyArrayConversion(fromArrayType, fromElementType, toElementType, index);
}
il2cpp_hresult_t il2cpp_codegen_com_handle_invalid_ipropertyarray_conversion(RuntimeObject* value, const char* fromArrayType, const char* fromElementType, const char* toElementType, il2cpp_array_size_t index)
{
return il2cpp::vm::CCW::HandleInvalidIPropertyArrayConversion(value, fromArrayType, fromElementType, toElementType, index);
}
Il2CppIUnknown* il2cpp_codegen_com_get_or_create_ccw_internal(RuntimeObject* obj, const Il2CppGuid& iid)
{
return il2cpp::vm::CCW::GetOrCreate(obj, iid);
}
Il2CppObject* il2cpp_codegen_com_unpack_ccw(Il2CppIUnknown* obj)
{
return il2cpp::vm::CCW::Unpack(obj);
}
void il2cpp_codegen_com_register_rcw(Il2CppComObject* rcw)
{
il2cpp::vm::RCW::Register(rcw);
}
RuntimeObject* il2cpp_codegen_com_get_or_create_rcw_from_iunknown_internal(Il2CppIUnknown* unknown, RuntimeClass* fallbackClass)
{
return il2cpp::vm::RCW::GetOrCreateFromIUnknown(unknown, fallbackClass);
}
RuntimeObject* il2cpp_codegen_com_get_or_create_rcw_from_iinspectable_internal(Il2CppIInspectable* unknown, RuntimeClass* fallbackClass)
{
return il2cpp::vm::RCW::GetOrCreateFromIInspectable(unknown, fallbackClass);
}
RuntimeObject* il2cpp_codegen_com_get_or_create_rcw_for_sealed_class_internal(Il2CppIUnknown* unknown, RuntimeClass* objectClass)
{
return il2cpp::vm::RCW::GetOrCreateForSealedClass(unknown, objectClass);
}
Il2CppIUnknown* il2cpp_codegen_com_query_interface_internal(Il2CppComObject* rcw, const Il2CppGuid& guid)
{
return il2cpp::vm::RCW::QueryInterfaceNoAddRef<true>(rcw, guid);
}
Il2CppIUnknown* il2cpp_codegen_com_query_interface_no_throw_internal(Il2CppComObject* rcw, const Il2CppGuid& guid)
{
return il2cpp::vm::RCW::QueryInterfaceNoAddRef<false>(rcw, guid);
}
void il2cpp_codegen_com_cache_queried_interface(Il2CppComObject* rcw, const Il2CppGuid& iid, Il2CppIUnknown* queriedInterface)
{
if (il2cpp::vm::RCW::CacheQueriedInterface(rcw, iid, queriedInterface))
queriedInterface->AddRef();
}
void il2cpp_codegen_il2cpp_com_object_cleanup(Il2CppComObject* rcw)
{
il2cpp::vm::RCW::Cleanup(rcw);
}
String_t* il2cpp_codegen_string_new_wrapper(const char* str)
{
return (String_t*)il2cpp::vm::String::NewWrapper(str);
}
String_t* il2cpp_codegen_string_new_utf16(const il2cpp::utils::StringView<Il2CppChar>& str)
{
return (String_t*)il2cpp::vm::String::NewUtf16(str.Str(), static_cast<int32_t>(str.Length()));
}
RuntimeString* il2cpp_codegen_type_append_assembly_name_if_necessary(RuntimeString* typeName, const RuntimeMethod* callingMethod)
{
return il2cpp::vm::Type::AppendAssemblyNameIfNecessary(typeName, callingMethod);
}
Type_t* il2cpp_codegen_get_type(String_t* typeName, const RuntimeMethod* getTypeMethod, const RuntimeMethod* callingMethod)
{
RuntimeString* assemblyQualifiedTypeName = il2cpp_codegen_type_append_assembly_name_if_necessary((RuntimeString*)typeName, callingMethod);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Il2CppException* exc = NULL;
void* params[] = {assemblyQualifiedTypeName};
Type_t* type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
if (type == NULL)
{
params[0] = typeName;
type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
}
return type;
}
Type_t* il2cpp_codegen_get_type(String_t* typeName, bool throwOnError, const RuntimeMethod* getTypeMethod, const RuntimeMethod* callingMethod)
{
typedef Type_t* (*getTypeFuncType)(String_t*, bool);
RuntimeString* assemblyQualifiedTypeName = il2cpp_codegen_type_append_assembly_name_if_necessary((RuntimeString*)typeName, callingMethod);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Il2CppException* exc = NULL;
void* params[] = {assemblyQualifiedTypeName, &throwOnError};
Type_t* type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
if (type == NULL)
{
params[0] = typeName;
type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
}
return type;
}
Type_t* il2cpp_codegen_get_type(String_t* typeName, bool throwOnError, bool ignoreCase, const RuntimeMethod* getTypeMethod , const RuntimeMethod* callingMethod)
{
typedef Type_t* (*getTypeFuncType)(String_t*, bool, bool);
RuntimeString* assemblyQualifiedTypeName = il2cpp_codegen_type_append_assembly_name_if_necessary((RuntimeString*)typeName, callingMethod);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Il2CppException* exc = NULL;
void* params[] = {assemblyQualifiedTypeName, &throwOnError, &ignoreCase};
Type_t* type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
if (type == NULL)
{
params[0] = typeName;
type = (Type_t*)il2cpp::vm::Runtime::Invoke(getTypeMethod, NULL, params, &exc);
if (exc)
il2cpp::vm::Exception::Raise(exc);
}
return type;
}
NORETURN void RaiseInvalidCastException(RuntimeObject* obj, RuntimeClass* targetType)
{
std::string exceptionMessage = il2cpp::utils::Exception::FormatInvalidCastException(obj->klass->element_class, targetType);
Exception_t* exception = il2cpp_codegen_get_invalid_cast_exception(exceptionMessage.c_str());
il2cpp_codegen_raise_exception(exception);
}
bool il2cpp_codegen_method_is_interface_method(RuntimeMethod* method)
{
return il2cpp::vm::Class::IsInterface(il2cpp_codegen_method_get_declaring_type(method));
}
bool il2cpp_codegen_class_is_assignable_from(RuntimeClass *klass, RuntimeClass *oklass)
{
return il2cpp::vm::Class::IsAssignableFrom(klass, oklass);
}
bool il2cpp_codegen_class_is_nullable(RuntimeClass* type)
{
return il2cpp::vm::Class::IsNullable(type);
}
RuntimeClass* il2cpp_codegen_get_generic_argument(RuntimeClass* klass, uint32_t argNum)
{
const Il2CppGenericInst* classInst = il2cpp_codegen_get_generic_class_inst(klass);
IL2CPP_ASSERT(argNum < classInst->type_argc);
return il2cpp::vm::Class::FromIl2CppType(classInst->type_argv[argNum]);
}
RuntimeClass* il2cpp_codegen_inflate_generic_class(RuntimeClass* genericClassDefinition, const Il2CppGenericInst* genericInst)
{
return il2cpp::vm::Class::GetInflatedGenericInstanceClass(genericClassDefinition, genericInst);
}
RuntimeClass* il2cpp_codegen_inflate_generic_class(RuntimeClass* genericClassDefinition, const RuntimeType* p1, /*const RuntimeType*, const RuntimeType* */ ...)
{
IL2CPP_ASSERT(genericClassDefinition->is_generic);
const uint32_t genericParameterCount = il2cpp::vm::MetadataCache::GetGenericContainerCount(genericClassDefinition->genericContainerHandle);
const RuntimeType** types = (const RuntimeType**)alloca(sizeof(RuntimeType*) * genericParameterCount);
types[0] = p1;
if (genericParameterCount > 1)
{
va_list genericArguments;
va_start(genericArguments, p1);
for (uint32_t i = 1; i < genericParameterCount; i++)
types[i] = va_arg(genericArguments, const RuntimeType*);
va_end(genericArguments);
}
return il2cpp::vm::Class::GetInflatedGenericInstanceClass(genericClassDefinition, il2cpp::vm::MetadataCache::GetGenericInst(types, genericParameterCount));
}
int32_t il2cpp_codgen_class_get_instance_size(RuntimeClass* klass)
{
return il2cpp::vm::Class::GetInstanceSize(klass);
}
RuntimeClass* il2cpp_codegen_class_from_type_internal(const RuntimeType* type)
{
return il2cpp::vm::Class::FromIl2CppType(type);
}
char* il2cpp_codegen_marshal_string(String_t* string)
{
return il2cpp::vm::PlatformInvoke::MarshalCSharpStringToCppString((RuntimeString*)string);
}
void il2cpp_codegen_marshal_string_fixed(String_t* string, char* buffer, int numberOfCharacters)
{
return il2cpp::vm::PlatformInvoke::MarshalCSharpStringToCppStringFixed((RuntimeString*)string, buffer, numberOfCharacters);
}
Il2CppChar* il2cpp_codegen_marshal_wstring(String_t* string)
{
return il2cpp::vm::PlatformInvoke::MarshalCSharpStringToCppWString((RuntimeString*)string);
}
void il2cpp_codegen_marshal_wstring_fixed(String_t* string, Il2CppChar* buffer, int numberOfCharacters)
{
return il2cpp::vm::PlatformInvoke::MarshalCSharpStringToCppWStringFixed((RuntimeString*)string, buffer, numberOfCharacters);
}
Il2CppChar* il2cpp_codegen_marshal_bstring(String_t* string)
{
return il2cpp::vm::PlatformInvoke::MarshalCSharpStringToCppBString((RuntimeString*)string);
}
String_t* il2cpp_codegen_marshal_string_result(const char* value)
{
return (String_t*)il2cpp::vm::PlatformInvoke::MarshalCppStringToCSharpStringResult(value);
}
String_t* il2cpp_codegen_marshal_wstring_result(const Il2CppChar* value)
{
return (String_t*)il2cpp::vm::PlatformInvoke::MarshalCppWStringToCSharpStringResult(value);
}
String_t* il2cpp_codegen_marshal_bstring_result(const Il2CppChar* value)
{
return (String_t*)il2cpp::vm::PlatformInvoke::MarshalCppBStringToCSharpStringResult(value);
}
void il2cpp_codegen_marshal_free_bstring(Il2CppChar* value)
{
il2cpp::vm::PlatformInvoke::MarshalFreeBString(value);
}
char* il2cpp_codegen_marshal_empty_string_builder(StringBuilder_t* stringBuilder)
{
return il2cpp::vm::PlatformInvoke::MarshalEmptyStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
char* il2cpp_codegen_marshal_string_builder(StringBuilder_t* stringBuilder)
{
return il2cpp::vm::PlatformInvoke::MarshalStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
Il2CppChar* il2cpp_codegen_marshal_empty_wstring_builder(StringBuilder_t* stringBuilder)
{
return il2cpp::vm::PlatformInvoke::MarshalEmptyWStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
Il2CppChar* il2cpp_codegen_marshal_wstring_builder(StringBuilder_t* stringBuilder)
{
return il2cpp::vm::PlatformInvoke::MarshalWStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
void il2cpp_codegen_marshal_string_builder_result(StringBuilder_t* stringBuilder, char* buffer)
{
il2cpp::vm::PlatformInvoke::MarshalStringBuilderResult((RuntimeStringBuilder*)stringBuilder, buffer);
}
void il2cpp_codegen_marshal_wstring_builder_result(StringBuilder_t* stringBuilder, Il2CppChar* buffer)
{
il2cpp::vm::PlatformInvoke::MarshalWStringBuilderResult((RuntimeStringBuilder*)stringBuilder, buffer);
}
void il2cpp_codegen_marshal_free(void* ptr)
{
il2cpp::vm::PlatformInvoke::MarshalFree(ptr);
}
Il2CppMethodPointer il2cpp_codegen_marshal_delegate(MulticastDelegate_t* d)
{
return (Il2CppMethodPointer)il2cpp::vm::PlatformInvoke::MarshalDelegate((RuntimeDelegate*)d);
}
Il2CppDelegate* il2cpp_codegen_marshal_function_ptr_to_delegate_internal(void* functionPtr, Il2CppClass* delegateType)
{
return il2cpp::vm::PlatformInvoke::MarshalFunctionPointerToDelegate(functionPtr, delegateType);
}
bool il2cpp_codegen_is_marshalled_delegate(MulticastDelegate_t* d)
{
return il2cpp::vm::PlatformInvoke::IsFakeDelegateMethodMarshaledFromNativeCode((const RuntimeDelegate*)d);
}
Il2CppMethodPointer il2cpp_codegen_resolve(const PInvokeArguments& pinvokeArgs)
{
return il2cpp::vm::PlatformInvoke::Resolve(pinvokeArgs);
}
Il2CppHString il2cpp_codegen_create_hstring(String_t* str)
{
return il2cpp::vm::WindowsRuntime::CreateHString(reinterpret_cast<RuntimeString*>(str));
}
String_t* il2cpp_codegen_marshal_hstring_result(Il2CppHString hstring)
{
return reinterpret_cast<String_t*>(il2cpp::vm::WindowsRuntime::HStringToManagedString(hstring));
}
void il2cpp_codegen_marshal_free_hstring(Il2CppHString hstring)
{
il2cpp::vm::WindowsRuntime::DeleteHString(hstring);
}
void il2cpp_codegen_marshal_type_to_native(Type_t* type, Il2CppWindowsRuntimeTypeName& nativeType)
{
return il2cpp::vm::WindowsRuntime::MarshalTypeToNative(type != NULL ? reinterpret_cast<Il2CppReflectionType*>(type)->type : NULL, nativeType);
}
const Il2CppType* il2cpp_codegen_marshal_type_from_native_internal(Il2CppWindowsRuntimeTypeName& nativeType)
{
return il2cpp::vm::WindowsRuntime::MarshalTypeFromNative(nativeType);
}
void il2cpp_codegen_delete_native_type(Il2CppWindowsRuntimeTypeName& nativeType)
{
return il2cpp::vm::WindowsRuntime::DeleteNativeType(nativeType);
}
Il2CppIActivationFactory* il2cpp_codegen_windows_runtime_get_activation_factory(const il2cpp::utils::StringView<Il2CppNativeChar>& runtimeClassName)
{
return il2cpp::vm::WindowsRuntime::GetActivationFactory(runtimeClassName);
}
void il2cpp_codegen_stacktrace_push_frame(Il2CppStackFrameInfo& frame)
{
il2cpp::vm::StackTrace::PushFrame(frame);
}
void il2cpp_codegen_stacktrace_pop_frame()
{
il2cpp::vm::StackTrace::PopFrame();
}
void il2cpp_codegen_array_unsafe_mov(RuntimeClass * destClass, void* dest, RuntimeClass * srcClass, void* src)
{
// A runtime implementation of System.Array::UnsafeMov
IL2CPP_ASSERT(destClass);
IL2CPP_ASSERT(dest);
IL2CPP_ASSERT(srcClass);
IL2CPP_ASSERT(src);
uint32_t destSize = il2cpp_codegen_sizeof(destClass);
uint32_t srcSize = il2cpp_codegen_sizeof(srcClass);
// If the types are the same size we can just memcpy them
// otherwise we need to "move" them using the correct casting rules for primitive types
if (destSize == srcSize)
{
il2cpp_codegen_memcpy(dest, src, destSize);
return;
}
const Il2CppType* destType = il2cpp::vm::Class::IsEnum(destClass) ? il2cpp::vm::Class::GetEnumBaseType(destClass) : &destClass->byval_arg;
const Il2CppType* srcType = il2cpp::vm::Class::IsEnum(srcClass) ? il2cpp::vm::Class::GetEnumBaseType(srcClass) : &srcClass->byval_arg;
switch (destType->type)