forked from Kasuromi/libil2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
il2cpp-api.cpp
1467 lines (1172 loc) · 34.8 KB
/
il2cpp-api.cpp
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 "il2cpp-api.h"
#include "il2cpp-object-internals.h"
#include "il2cpp-runtime-stats.h"
#include "gc/WriteBarrier.h"
#include "os/StackTrace.h"
#include "os/Image.h"
#include "vm/Array.h"
#include "vm/Assembly.h"
#include "vm/Class.h"
#include "vm/Domain.h"
#include "vm/Exception.h"
#include "vm/Field.h"
#include "vm/Image.h"
#include "vm/InternalCalls.h"
#include "vm/Liveness.h"
#include "vm/MemoryInformation.h"
#include "vm/Method.h"
#include "vm/Monitor.h"
#include "vm/Object.h"
#include "vm/Path.h"
#include "vm/PlatformInvoke.h"
#include "vm/Profiler.h"
#include "vm/Property.h"
#include "vm/Reflection.h"
#include "vm/Runtime.h"
#include "vm/StackTrace.h"
#include "vm/String.h"
#include "vm/Thread.h"
#include "vm/Type.h"
#include "utils/Exception.h"
#include "utils/Logging.h"
#include "utils/Memory.h"
#include "utils/StringUtils.h"
#include "utils/Runtime.h"
#include "utils/Environment.h"
#include "vm-utils/Debugger.h"
#include "vm-utils/NativeSymbol.h"
#include "gc/GarbageCollector.h"
#include "gc/GCHandle.h"
#include "gc/WriteBarrierValidation.h"
#include <locale.h>
#include <fstream>
#include <string>
using namespace il2cpp::vm;
using il2cpp::utils::Memory;
using namespace il2cpp::gc;
#if IL2CPP_API_DYNAMIC_NO_DLSYM
#include <map>
struct SymbolCompare : public std::binary_function<char*, char*, bool>
{
bool operator()(const char* lhs, const char* rhs) const
{
return strcmp(lhs, rhs) < 0;
}
};
typedef std::map<const char*, void*, SymbolCompare> SymbolTable;
static SymbolTable s_SymbolTable;
static void RegisterAPIFunction(const char* name, void* symbol)
{
s_SymbolTable.insert(std::make_pair(name, symbol));
}
void il2cpp_api_register_symbols(void)
{
#define DO_API(r, n, p) RegisterAPIFunction(#n, (void*)n);
#define DO_API_NO_RETURN(r, n, p) DO_API(r, n, p)
#include "il2cpp-api-functions.h"
#undef DO_API
#undef DO_API_NO_RETURN
}
void* il2cpp_api_lookup_symbol(const char* name)
{
SymbolTable::iterator it = s_SymbolTable.find(name);
if (it != s_SymbolTable.end())
{
return it->second;
}
return NULL;
}
#endif // IL2CPP_API_DYNAMIC_NO_DLSYM
int il2cpp_init(const char* domain_name)
{
// Use environment's default locale
setlocale(LC_ALL, "");
return Runtime::Init(domain_name);
}
int il2cpp_init_utf16(const Il2CppChar* domain_name)
{
return il2cpp_init(il2cpp::utils::StringUtils::Utf16ToUtf8(domain_name).c_str());
}
void il2cpp_shutdown()
{
Runtime::Shutdown();
}
void il2cpp_set_config_dir(const char *config_path)
{
il2cpp::vm::Runtime::SetConfigDir(config_path);
}
void il2cpp_set_data_dir(const char *data_path)
{
il2cpp::utils::Runtime::SetDataDir(data_path);
}
void il2cpp_set_temp_dir(const char *temp_dir)
{
il2cpp::vm::Path::SetTempPath(temp_dir);
}
void il2cpp_set_commandline_arguments(int argc, const char* const argv[], const char* basedir)
{
il2cpp::utils::Environment::SetMainArgs(argv, argc);
}
void il2cpp_set_commandline_arguments_utf16(int argc, const Il2CppChar* const argv[], const char* basedir)
{
il2cpp::utils::Environment::SetMainArgs(argv, argc);
}
void il2cpp_set_config_utf16(const Il2CppChar* executablePath)
{
il2cpp::vm::Runtime::SetConfigUtf16(executablePath);
}
void il2cpp_set_config(const char* executablePath)
{
il2cpp::vm::Runtime::SetConfig(executablePath);
}
void il2cpp_set_memory_callbacks(Il2CppMemoryCallbacks* callbacks)
{
Memory::SetMemoryCallbacks(callbacks);
}
const Il2CppImage* il2cpp_get_corlib()
{
return Image::GetCorlib();
}
void il2cpp_add_internal_call(const char* name, Il2CppMethodPointer method)
{
return InternalCalls::Add(name, method);
}
Il2CppMethodPointer il2cpp_resolve_icall(const char* name)
{
return InternalCalls::Resolve(name);
}
void* il2cpp_alloc(size_t size)
{
return IL2CPP_MALLOC(size);
}
void il2cpp_free(void* ptr)
{
IL2CPP_FREE(ptr);
}
// array
Il2CppClass *il2cpp_array_class_get(Il2CppClass *element_class, uint32_t rank)
{
return Class::GetArrayClass(element_class, rank);
}
uint32_t il2cpp_array_length(Il2CppArray* array)
{
return Array::GetLength(array);
}
uint32_t il2cpp_array_get_byte_length(Il2CppArray *array)
{
return Array::GetByteLength(array);
}
Il2CppArray* il2cpp_array_new(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
{
return Array::New(elementTypeInfo, length);
}
Il2CppArray* il2cpp_array_new_specific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length)
{
return Array::NewSpecific(arrayTypeInfo, length);
}
Il2CppArray* il2cpp_array_new_full(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds)
{
return Array::NewFull(array_class, lengths, lower_bounds);
}
Il2CppClass* il2cpp_bounded_array_class_get(Il2CppClass *element_class, uint32_t rank, bool bounded)
{
return Class::GetBoundedArrayClass(element_class, rank, bounded);
}
int il2cpp_array_element_size(const Il2CppClass* klass)
{
return Array::GetElementSize(klass);
}
// assembly
const Il2CppImage* il2cpp_assembly_get_image(const Il2CppAssembly *assembly)
{
return Assembly::GetImage(assembly);
}
// class
const Il2CppType* il2cpp_class_enum_basetype(Il2CppClass *klass)
{
return Class::GetEnumBaseType(klass);
}
Il2CppClass* il2cpp_class_from_system_type(Il2CppReflectionType *type)
{
return Class::FromSystemType(type);
}
bool il2cpp_class_is_generic(const Il2CppClass *klass)
{
return Class::IsGeneric(klass);
}
bool il2cpp_class_is_inflated(const Il2CppClass *klass)
{
return Class::IsInflated(klass);
}
bool il2cpp_class_is_assignable_from(Il2CppClass *klass, Il2CppClass *oklass)
{
return Class::IsAssignableFrom(klass, oklass);
}
bool il2cpp_class_is_subclass_of(Il2CppClass *klass, Il2CppClass *klassc, bool check_interfaces)
{
return Class::IsSubclassOf(klass, klassc, check_interfaces);
}
bool il2cpp_class_has_parent(Il2CppClass *klass, Il2CppClass *klassc)
{
return Class::HasParent(klass, klassc);
}
Il2CppClass* il2cpp_class_from_il2cpp_type(const Il2CppType* type)
{
return Class::FromIl2CppType(type);
}
Il2CppClass* il2cpp_class_from_name(const Il2CppImage* image, const char* namespaze, const char *name)
{
return Class::FromName(image, namespaze, name);
}
Il2CppClass* il2cpp_class_get_element_class(Il2CppClass *klass)
{
return Class::GetElementClass(klass);
}
const EventInfo* il2cpp_class_get_events(Il2CppClass *klass, void* *iter)
{
return Class::GetEvents(klass, iter);
}
FieldInfo* il2cpp_class_get_fields(Il2CppClass *klass, void* *iter)
{
return Class::GetFields(klass, iter);
}
Il2CppClass* il2cpp_class_get_nested_types(Il2CppClass *klass, void* *iter)
{
return Class::GetNestedTypes(klass, iter);
}
Il2CppClass* il2cpp_class_get_interfaces(Il2CppClass *klass, void* *iter)
{
return Class::GetInterfaces(klass, iter);
}
const PropertyInfo* il2cpp_class_get_properties(Il2CppClass *klass, void* *iter)
{
return Class::GetProperties(klass, iter);
}
const PropertyInfo* il2cpp_class_get_property_from_name(Il2CppClass *klass, const char *name)
{
return Class::GetPropertyFromName(klass, name);
}
FieldInfo* il2cpp_class_get_field_from_name(Il2CppClass* klass, const char *name)
{
return Class::GetFieldFromName(klass, name);
}
const MethodInfo* il2cpp_class_get_methods(Il2CppClass *klass, void* *iter)
{
return Class::GetMethods(klass, iter);
}
const MethodInfo* il2cpp_class_get_method_from_name(Il2CppClass *klass, const char* name, int argsCount)
{
return Class::GetMethodFromName(klass, name, argsCount);
}
const char* il2cpp_class_get_name(Il2CppClass *klass)
{
return Class::GetName(klass);
}
const char* il2cpp_class_get_namespace(Il2CppClass *klass)
{
return Class::GetNamespace(klass);
}
Il2CppClass* il2cpp_class_get_parent(Il2CppClass *klass)
{
return Class::GetParent(klass);
}
Il2CppClass* il2cpp_class_get_declaring_type(Il2CppClass* klass)
{
return Class::GetDeclaringType(klass);
}
int32_t il2cpp_class_instance_size(Il2CppClass *klass)
{
return Class::GetInstanceSize(klass);
}
size_t il2cpp_class_num_fields(const Il2CppClass* klass)
{
return Class::GetNumFields(klass);
}
bool il2cpp_class_is_valuetype(const Il2CppClass* klass)
{
return Class::IsValuetype(klass);
}
bool il2cpp_class_is_blittable(const Il2CppClass* klass)
{
return Class::IsBlittable(klass);
}
int32_t il2cpp_class_value_size(Il2CppClass *klass, uint32_t *align)
{
return Class::GetValueSize(klass, align);
}
int il2cpp_class_get_flags(const Il2CppClass *klass)
{
return Class::GetFlags(klass);
}
bool il2cpp_class_is_abstract(const Il2CppClass *klass)
{
return Class::IsAbstract(klass);
}
bool il2cpp_class_is_interface(const Il2CppClass *klass)
{
return Class::IsInterface(klass);
}
int il2cpp_class_array_element_size(const Il2CppClass *klass)
{
return Class::GetArrayElementSize(klass);
}
Il2CppClass* il2cpp_class_from_type(const Il2CppType *type)
{
return Class::FromIl2CppType(type);
}
const Il2CppType* il2cpp_class_get_type(Il2CppClass *klass)
{
return Class::GetType(klass);
}
uint32_t il2cpp_class_get_type_token(Il2CppClass *klass)
{
return klass->token;
}
bool il2cpp_class_has_attribute(Il2CppClass *klass, Il2CppClass *attr_class)
{
return Class::HasAttribute(klass, attr_class);
}
bool il2cpp_class_has_references(Il2CppClass *klass)
{
return Class::HasReferences(klass);
}
bool il2cpp_class_is_enum(const Il2CppClass *klass)
{
return Class::IsEnum(klass);
}
const Il2CppImage* il2cpp_class_get_image(Il2CppClass* klass)
{
return Class::GetImage(klass);
}
const char *il2cpp_class_get_assemblyname(const Il2CppClass *klass)
{
return Class::GetAssemblyNameNoExtension(klass);
}
int il2cpp_class_get_rank(const Il2CppClass *klass)
{
return klass->rank;
}
uint32_t il2cpp_class_get_data_size(const Il2CppClass *klass)
{
return klass->static_fields_size;
}
void* il2cpp_class_get_static_field_data(const Il2CppClass *klass)
{
return klass->static_fields;
}
// testing only
size_t il2cpp_class_get_bitmap_size(const Il2CppClass *klass)
{
return Class::GetBitmapSize(klass);
}
void il2cpp_class_get_bitmap(Il2CppClass *klass, size_t* bitmap)
{
size_t dummy = 0;
Class::GetBitmap(klass, bitmap, dummy);
}
// stats
extern Il2CppRuntimeStats il2cpp_runtime_stats;
bool il2cpp_stats_dump_to_file(const char *path)
{
std::fstream fs;
fs.open(path, std::fstream::out | std::fstream::trunc);
fs << "New object count: " << il2cpp_stats_get_value(IL2CPP_STAT_NEW_OBJECT_COUNT) << "\n";
fs << "Method count: " << il2cpp_stats_get_value(IL2CPP_STAT_METHOD_COUNT) << "\n";
fs << "Class static data size: " << il2cpp_stats_get_value(IL2CPP_STAT_CLASS_STATIC_DATA_SIZE) << "\n";
fs << "Inflated method count: " << il2cpp_stats_get_value(IL2CPP_STAT_INFLATED_METHOD_COUNT) << "\n";
fs << "Inflated type count: " << il2cpp_stats_get_value(IL2CPP_STAT_INFLATED_TYPE_COUNT) << "\n";
fs << "Initialized class count: " << il2cpp_stats_get_value(IL2CPP_STAT_INITIALIZED_CLASS_COUNT) << "\n";
fs << "Generic instance count: " << il2cpp_stats_get_value(IL2CPP_STAT_GENERIC_INSTANCE_COUNT) << "\n";
fs << "Generic class count: " << il2cpp_stats_get_value(IL2CPP_STAT_GENERIC_CLASS_COUNT) << "\n";
fs.close();
return true;
}
uint64_t il2cpp_stats_get_value(Il2CppStat stat)
{
switch (stat)
{
case IL2CPP_STAT_NEW_OBJECT_COUNT:
return il2cpp_runtime_stats.new_object_count;
case IL2CPP_STAT_INITIALIZED_CLASS_COUNT:
return il2cpp_runtime_stats.initialized_class_count;
/*case IL2CPP_STAT_GENERIC_VTABLE_COUNT:
return il2cpp_runtime_stats.generic_vtable_count;
case IL2CPP_STAT_USED_CLASS_COUNT:
return il2cpp_runtime_stats.used_class_count;*/
case IL2CPP_STAT_METHOD_COUNT:
return il2cpp_runtime_stats.method_count;
/*case IL2CPP_STAT_CLASS_VTABLE_SIZE:
return il2cpp_runtime_stats.class_vtable_size;*/
case IL2CPP_STAT_CLASS_STATIC_DATA_SIZE:
return il2cpp_runtime_stats.class_static_data_size;
case IL2CPP_STAT_GENERIC_INSTANCE_COUNT:
return il2cpp_runtime_stats.generic_instance_count;
case IL2CPP_STAT_GENERIC_CLASS_COUNT:
return il2cpp_runtime_stats.generic_class_count;
case IL2CPP_STAT_INFLATED_METHOD_COUNT:
return il2cpp_runtime_stats.inflated_method_count;
case IL2CPP_STAT_INFLATED_TYPE_COUNT:
return il2cpp_runtime_stats.inflated_type_count;
/*case IL2CPP_STAT_DELEGATE_CREATIONS:
return il2cpp_runtime_stats.delegate_creations;
case IL2CPP_STAT_MINOR_GC_COUNT:
return il2cpp_runtime_stats.minor_gc_count;
case IL2CPP_STAT_MAJOR_GC_COUNT:
return il2cpp_runtime_stats.major_gc_count;
case IL2CPP_STAT_MINOR_GC_TIME_USECS:
return il2cpp_runtime_stats.minor_gc_time_usecs;
case IL2CPP_STAT_MAJOR_GC_TIME_USECS:
return il2cpp_runtime_stats.major_gc_time_usecs;*/
}
return 0;
}
// domain
Il2CppDomain* il2cpp_domain_get()
{
return Domain::GetCurrent();
}
const Il2CppAssembly* il2cpp_domain_assembly_open(Il2CppDomain *domain, const char *name)
{
return Assembly::Load(name);
}
const Il2CppAssembly** il2cpp_domain_get_assemblies(const Il2CppDomain* domain, size_t* size)
{
il2cpp::vm::AssemblyVector* assemblies = Assembly::GetAllAssemblies();
*size = assemblies->size();
return &(*assemblies)[0];
}
// exception
void il2cpp_raise_exception(Il2CppException* exc)
{
Exception::Raise(exc);
}
Il2CppException* il2cpp_exception_from_name_msg(const Il2CppImage* image, const char *name_space, const char *name, const char *msg)
{
return Exception::FromNameMsg(image, name_space, name, msg);
}
Il2CppException* il2cpp_get_exception_argument_null(const char *arg)
{
return Exception::GetArgumentNullException(arg);
}
void il2cpp_format_exception(const Il2CppException* ex, char* message, int message_size)
{
strncpy(message, il2cpp::utils::Exception::FormatException(ex).c_str(), message_size);
}
void il2cpp_format_stack_trace(const Il2CppException* ex, char* output, int output_size)
{
strncpy(output, il2cpp::utils::Exception::FormatStackTrace(ex).c_str(), output_size);
}
void il2cpp_unhandled_exception(Il2CppException* exc)
{
Runtime::UnhandledException(exc);
}
void il2cpp_native_stack_trace(const Il2CppException * ex, uintptr_t** addresses, int* numFrames, char** imageUUID, char** imageName)
{
#if IL2CPP_ENABLE_NATIVE_INSTRUCTION_POINTER_EMISSION && !IL2CPP_TINY
if (ex == NULL || ex->native_trace_ips == NULL)
{
*numFrames = 0;
*addresses = NULL;
*imageUUID = NULL;
*imageName = NULL;
return;
}
*numFrames = il2cpp_array_length(ex->native_trace_ips);
if (*numFrames <= 0)
{
*addresses = NULL;
*imageUUID = NULL;
*imageName = NULL;
}
else
{
*addresses = static_cast<uintptr_t*>(il2cpp_alloc((*numFrames) * sizeof(uintptr_t)));
for (int i = 0; i < *numFrames; i++)
{
uintptr_t ptrAddr = il2cpp_array_get(ex->native_trace_ips, uintptr_t, i);
(*addresses)[i] = ptrAddr;
}
*imageUUID = il2cpp::os::Image::GetImageUUID();
*imageName = il2cpp::os::Image::GetImageName();
}
#endif
}
// field
const char* il2cpp_field_get_name(FieldInfo *field)
{
return Field::GetName(field);
}
int il2cpp_field_get_flags(FieldInfo *field)
{
return Field::GetFlags(field);
}
Il2CppClass* il2cpp_field_get_parent(FieldInfo *field)
{
return Field::GetParent(field);
}
size_t il2cpp_field_get_offset(FieldInfo *field)
{
return Field::GetOffset(field);
}
const Il2CppType* il2cpp_field_get_type(FieldInfo *field)
{
return Field::GetType(field);
}
void il2cpp_field_get_value(Il2CppObject *obj, FieldInfo *field, void *value)
{
return Field::GetValue(obj, field, value);
}
Il2CppObject* il2cpp_field_get_value_object(FieldInfo *field, Il2CppObject *obj)
{
return Field::GetValueObject(field, obj);
}
bool il2cpp_field_has_attribute(FieldInfo *field, Il2CppClass *attr_class)
{
return Field::HasAttribute(field, attr_class);
}
void il2cpp_field_set_value(Il2CppObject *obj, FieldInfo *field, void *value)
{
Field::SetValue(obj, field, value);
}
void il2cpp_field_set_value_object(Il2CppObject* objectInstance, FieldInfo* field, Il2CppObject* value)
{
Field::SetInstanceFieldValueObject(objectInstance, field, value);
}
void il2cpp_field_static_get_value(FieldInfo *field, void *value)
{
Field::StaticGetValue(field, value);
}
void il2cpp_field_static_set_value(FieldInfo *field, void *value)
{
Field::StaticSetValue(field, value);
}
bool il2cpp_field_is_literal(FieldInfo *field)
{
return (field->type->attrs & FIELD_ATTRIBUTE_LITERAL) != 0;
}
// gc
void il2cpp_gc_collect(int maxGenerations)
{
GarbageCollector::Collect(maxGenerations);
}
int32_t il2cpp_gc_collect_a_little()
{
return GarbageCollector::CollectALittle();
}
void il2cpp_gc_start_incremental_collection()
{
GarbageCollector::StartIncrementalCollection();
}
void il2cpp_gc_enable()
{
GarbageCollector::Enable();
}
void il2cpp_gc_disable()
{
GarbageCollector::Disable();
}
bool il2cpp_gc_is_disabled()
{
return GarbageCollector::IsDisabled();
}
void il2cpp_gc_set_mode(Il2CppGCMode mode)
{
GarbageCollector::SetMode(mode);
}
bool il2cpp_gc_is_incremental()
{
return GarbageCollector::IsIncremental();
}
int64_t il2cpp_gc_get_max_time_slice_ns()
{
return GarbageCollector::GetMaxTimeSliceNs();
}
void il2cpp_gc_set_max_time_slice_ns(int64_t maxTimeSlice)
{
GarbageCollector::SetMaxTimeSliceNs(maxTimeSlice);
}
int64_t il2cpp_gc_get_used_size()
{
return GarbageCollector::GetUsedHeapSize();
}
int64_t il2cpp_gc_get_heap_size()
{
return GarbageCollector::GetAllocatedHeapSize();
}
void il2cpp_gc_foreach_heap(void(*func)(void* data, void* context), void* userData)
{
MemoryInformation::IterationContext ctx;
ctx.callback = func;
ctx.userData = userData;
il2cpp::gc::GarbageCollector::ForEachHeapSection(&ctx, MemoryInformation::ReportGcHeapSection);
}
void il2cpp_stop_gc_world()
{
il2cpp::gc::GarbageCollector::StopWorld();
}
void il2cpp_start_gc_world()
{
il2cpp::gc::GarbageCollector::StartWorld();
}
void* il2cpp_gc_alloc_fixed(size_t size)
{
return il2cpp::gc::GarbageCollector::AllocateFixed(size, NULL);
}
void il2cpp_gc_free_fixed(void* address)
{
il2cpp::gc::GarbageCollector::FreeFixed(address);
}
// gchandle
uint32_t il2cpp_gchandle_new(Il2CppObject *obj, bool pinned)
{
return GCHandle::New(obj, pinned);
}
uint32_t il2cpp_gchandle_new_weakref(Il2CppObject *obj, bool track_resurrection)
{
// Note that the call to Get will assert if an error occurred.
return GCHandle::NewWeakref(obj, track_resurrection).Get();
}
Il2CppObject* il2cpp_gchandle_get_target(uint32_t gchandle)
{
return GCHandle::GetTarget(gchandle);
}
void il2cpp_gchandle_foreach_get_target(void(*func)(void*, void*), void* userData)
{
MemoryInformation::IterationContext ctx;
ctx.callback = func;
ctx.userData = userData;
il2cpp::gc::GCHandle::WalkStrongGCHandleTargets(MemoryInformation::ReportGcHandleTarget, &ctx);
}
void il2cpp_gc_wbarrier_set_field(Il2CppObject *obj, void **targetAddress, void *object)
{
il2cpp::gc::WriteBarrier::GenericStore(targetAddress, object);
}
bool il2cpp_gc_has_strict_wbarriers()
{
#if IL2CPP_ENABLE_STRICT_WRITE_BARRIERS
return true;
#else
return false;
#endif
}
void il2cpp_gc_set_external_allocation_tracker(void(*func)(void*, size_t, int))
{
#if IL2CPP_ENABLE_WRITE_BARRIER_VALIDATION
il2cpp::gc::WriteBarrierValidation::SetExternalAllocationTracker(func);
#endif
}
void il2cpp_gc_set_external_wbarrier_tracker(void(*func)(void**))
{
#if IL2CPP_ENABLE_WRITE_BARRIER_VALIDATION
il2cpp::gc::WriteBarrierValidation::SetExternalWriteBarrierTracker(func);
#endif
}
void il2cpp_gchandle_free(uint32_t gchandle)
{
GCHandle::Free(gchandle);
}
// vm runtime info
uint32_t il2cpp_object_header_size()
{
return static_cast<uint32_t>(sizeof(Il2CppObject));
}
uint32_t il2cpp_array_object_header_size()
{
return static_cast<uint32_t>(kIl2CppSizeOfArray);
}
uint32_t il2cpp_offset_of_array_length_in_array_object_header()
{
return kIl2CppOffsetOfArrayLength;
}
uint32_t il2cpp_offset_of_array_bounds_in_array_object_header()
{
return kIl2CppOffsetOfArrayBounds;
}
uint32_t il2cpp_allocation_granularity()
{
return static_cast<uint32_t>(2 * sizeof(void*));
}
// liveness
void* il2cpp_unity_liveness_allocate_struct(Il2CppClass* filter, int max_object_count, il2cpp_register_object_callback callback, void* userdata, il2cpp_liveness_reallocate_callback reallocate)
{
return Liveness::AllocateStruct(filter, max_object_count, callback, userdata, reallocate);
}
void il2cpp_unity_liveness_calculation_from_root(Il2CppObject* root, void* state)
{
Liveness::FromRoot(root, state);
}
void il2cpp_unity_liveness_calculation_from_statics(void* state)
{
Liveness::FromStatics(state);
}
void il2cpp_unity_liveness_finalize(void* state)
{
Liveness::Finalize(state);
}
void il2cpp_unity_liveness_free_struct(void* state)
{
Liveness::FreeStruct(state);
}
// method
const Il2CppType* il2cpp_method_get_return_type(const MethodInfo* method)
{
return Method::GetReturnType(method);
}
const MethodInfo* il2cpp_method_get_from_reflection(const Il2CppReflectionMethod *method)
{
return Reflection::GetMethod(method);
}
Il2CppReflectionMethod* il2cpp_method_get_object(const MethodInfo *method, Il2CppClass *refclass)
{
return Reflection::GetMethodObject(method, refclass);
}
const char* il2cpp_method_get_name(const MethodInfo *method)
{
return Method::GetName(method);
}
bool il2cpp_method_is_generic(const MethodInfo *method)
{
return Method::IsGeneric(method);
}
bool il2cpp_method_is_inflated(const MethodInfo *method)
{
return Method::IsInflated(method);
}
bool il2cpp_method_is_instance(const MethodInfo *method)
{
return Method::IsInstance(method);
}
uint32_t il2cpp_method_get_param_count(const MethodInfo *method)
{
return Method::GetParamCount(method);
}
const Il2CppType* il2cpp_method_get_param(const MethodInfo *method, uint32_t index)
{
return Method::GetParam(method, index);
}
Il2CppClass* il2cpp_method_get_class(const MethodInfo *method)
{
return Method::GetClass(method);
}
bool il2cpp_method_has_attribute(const MethodInfo *method, Il2CppClass *attr_class)
{
return Method::HasAttribute(method, attr_class);
}
Il2CppClass* il2cpp_method_get_declaring_type(const MethodInfo* method)
{
return Method::GetDeclaringType(method);
}
uint32_t il2cpp_method_get_flags(const MethodInfo *method, uint32_t *iflags)
{
if (iflags != 0)
*iflags = Method::GetImplementationFlags(method);
return Method::GetFlags(method);
}
uint32_t il2cpp_method_get_token(const MethodInfo *method)
{
return Method::GetToken(method);
}
const char *il2cpp_method_get_param_name(const MethodInfo *method, uint32_t index)
{
return Method::GetParamName(method, index);
}
// profiler
#if IL2CPP_ENABLE_PROFILER
void il2cpp_profiler_install(Il2CppProfiler *prof, Il2CppProfileFunc shutdown_callback)
{
Profiler::Install(prof, shutdown_callback);
}
void il2cpp_profiler_set_events(Il2CppProfileFlags events)
{
Profiler::SetEvents(events);
}
void il2cpp_profiler_install_enter_leave(Il2CppProfileMethodFunc enter, Il2CppProfileMethodFunc fleave)
{
Profiler::InstallEnterLeave(enter, fleave);
}
void il2cpp_profiler_install_allocation(Il2CppProfileAllocFunc callback)
{
Profiler::InstallAllocation(callback);
}
void il2cpp_profiler_install_gc(Il2CppProfileGCFunc callback, Il2CppProfileGCResizeFunc heap_resize_callback)
{
Profiler::InstallGC(callback, heap_resize_callback);
}
void il2cpp_profiler_install_fileio(Il2CppProfileFileIOFunc callback)
{
Profiler::InstallFileIO(callback);
}
void il2cpp_profiler_install_thread(Il2CppProfileThreadFunc start, Il2CppProfileThreadFunc end)