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