go-unsafe-pointer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* go-unsafe-pointer.c -- unsafe.Pointer type descriptor for Go.
  2. Copyright 2009 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include <stddef.h>
  6. #include "runtime.h"
  7. #include "go-type.h"
  8. #include "mgc0.h"
  9. /* A pointer with a zero value. */
  10. static void *zero_pointer;
  11. /* This file provides the type descriptor for the unsafe.Pointer type.
  12. The unsafe package is defined by the compiler itself, which means
  13. that there is no package to compile to define the type
  14. descriptor. */
  15. extern const struct __go_type_descriptor unsafe_Pointer
  16. __asm__ (GOSYM_PREFIX "__go_tdn_unsafe.Pointer");
  17. extern const uintptr unsafe_Pointer_gc[]
  18. __asm__ (GOSYM_PREFIX "__go_tdn_unsafe.Pointer$gc");
  19. /* Used to determine the field alignment. */
  20. struct field_align
  21. {
  22. char c;
  23. void *p;
  24. };
  25. /* The reflection string. */
  26. #define REFLECTION "unsafe.Pointer"
  27. static const String reflection_string =
  28. {
  29. (const byte *) REFLECTION,
  30. sizeof REFLECTION - 1
  31. };
  32. const uintptr unsafe_Pointer_gc[] = {sizeof(void*), GC_APTR, 0, GC_END};
  33. const struct __go_type_descriptor unsafe_Pointer =
  34. {
  35. /* __code */
  36. GO_UNSAFE_POINTER | GO_DIRECT_IFACE,
  37. /* __align */
  38. __alignof (void *),
  39. /* __field_align */
  40. offsetof (struct field_align, p) - 1,
  41. /* __size */
  42. sizeof (void *),
  43. /* __hash */
  44. 78501163U,
  45. /* __hashfn */
  46. __go_type_hash_identity,
  47. /* __equalfn */
  48. __go_type_equal_identity,
  49. /* __gc */
  50. unsafe_Pointer_gc,
  51. /* __reflection */
  52. &reflection_string,
  53. /* __uncommon */
  54. NULL,
  55. /* __pointer_to_this */
  56. NULL,
  57. /* __zero */
  58. &zero_pointer
  59. };
  60. /* We also need the type descriptor for the pointer to unsafe.Pointer,
  61. since any package which refers to that type descriptor will expect
  62. it to be defined elsewhere. */
  63. extern const struct __go_ptr_type pointer_unsafe_Pointer
  64. __asm__ (GOSYM_PREFIX "__go_td_pN14_unsafe.Pointer");
  65. /* The reflection string. */
  66. #define PREFLECTION "*unsafe.Pointer"
  67. static const String preflection_string =
  68. {
  69. (const byte *) PREFLECTION,
  70. sizeof PREFLECTION - 1,
  71. };
  72. const struct __go_ptr_type pointer_unsafe_Pointer =
  73. {
  74. /* __common */
  75. {
  76. /* __code */
  77. GO_PTR | GO_DIRECT_IFACE,
  78. /* __align */
  79. __alignof (void *),
  80. /* __field_align */
  81. offsetof (struct field_align, p) - 1,
  82. /* __size */
  83. sizeof (void *),
  84. /* __hash */
  85. 1256018616U,
  86. /* __hashfn */
  87. __go_type_hash_identity,
  88. /* __equalfn */
  89. __go_type_equal_identity,
  90. /* __gc */
  91. unsafe_Pointer_gc,
  92. /* __reflection */
  93. &preflection_string,
  94. /* __uncommon */
  95. NULL,
  96. /* __pointer_to_this */
  97. NULL,
  98. /* __zero */
  99. &zero_pointer
  100. },
  101. /* __element_type */
  102. &unsafe_Pointer
  103. };