Array.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. struct Il2CppArray;
  5. struct Il2CppObject;
  6. struct Il2CppString;
  7. struct Il2CppClass;
  8. namespace il2cpp
  9. {
  10. namespace vm
  11. {
  12. class LIBIL2CPP_CODEGEN_API Array
  13. {
  14. public:
  15. static int32_t GetElementSize(const Il2CppClass *klass);
  16. static uint32_t GetLength(Il2CppArray* array);
  17. static uint32_t GetByteLength(Il2CppArray* array);
  18. static Il2CppArray* New(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length);
  19. static Il2CppArray* NewSpecific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length);
  20. static Il2CppArray* NewFull(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds);
  21. public:
  22. // internal
  23. static Il2CppArray* NewCached(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
  24. {
  25. return New(elementTypeInfo, length);
  26. }
  27. static char* GetFirstElementAddress(Il2CppArray *array);
  28. };
  29. } /* namespace vm */
  30. } /* namespace il2cpp */
  31. LIBIL2CPP_CODEGEN_API char* il2cpp_array_addr_with_size(Il2CppArray *array, int32_t size, uintptr_t idx);
  32. extern "C"
  33. {
  34. IL2CPP_EXPORT int il2cpp_array_element_size(const Il2CppClass *ac);
  35. }
  36. #define load_array_elema(arr, idx, size) ((((uint8_t*)(arr)) + kIl2CppSizeOfArray) + ((size) * (idx)))
  37. #define il2cpp_array_setwithsize(array, elementSize, index, value) \
  38. do { \
  39. void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  40. memcpy(__p, &(value), elementSize); \
  41. } while (0)
  42. #define il2cpp_array_setrefwithsize(array, elementSize, index, value) \
  43. do { \
  44. void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  45. memcpy(__p, value, elementSize); \
  46. } while (0)
  47. #define il2cpp_array_addr(array, type, index) ((type*)(void*) il2cpp_array_addr_with_size (array, sizeof (type), index))
  48. #define il2cpp_array_get(array, type, index) ( *(type*)il2cpp_array_addr ((array), type, (index)) )
  49. #define il2cpp_array_set(array, type, index, value) \
  50. do { \
  51. type *__p = (type *) il2cpp_array_addr ((array), type, (index)); \
  52. *__p = (value); \
  53. } while (0)
  54. #define il2cpp_array_setref(array, index, value) \
  55. do { \
  56. void* *__p = (void* *) il2cpp_array_addr ((array), void*, (index)); \
  57. /* il2cpp_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); */\
  58. *__p = (value); \
  59. } while (0)