github.com/golang/gofrontend@v0.0.0-20240429183944-60f985a78526/libgo/runtime/go-unsafe-pointer.c (about)

     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  
    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  
    16  extern const struct _type unsafe_Pointer
    17    __asm__ (GOSYM_PREFIX "unsafe.Pointer..d");
    18  
    19  extern const byte unsafe_Pointer_gc[]
    20    __asm__ (GOSYM_PREFIX "unsafe.Pointer..g");
    21  
    22  /* Used to determine the field alignment.  */
    23  struct field_align
    24  {
    25    char c;
    26    void *p;
    27  };
    28  
    29  /* The reflection string.  */
    30  #define REFLECTION "unsafe.Pointer"
    31  static const String reflection_string =
    32  {
    33    (const byte *) REFLECTION,
    34    sizeof REFLECTION - 1
    35  };
    36  
    37  const byte unsafe_Pointer_gc[] = { 1 };
    38  
    39  extern const FuncVal runtime_pointerequal_descriptor
    40    __asm__ (GOSYM_PREFIX "runtime.pointerequal..f");
    41  
    42  const struct _type unsafe_Pointer =
    43  {
    44    /* size */
    45    sizeof (void *),
    46    /* ptrdata */
    47    sizeof (void *),
    48    /* hash */
    49    78501163U,
    50    /* tflag */
    51    tflagRegularMemory,
    52    /* align */
    53    __alignof (void *),
    54    /* fieldAlign */
    55    offsetof (struct field_align, p) - 1,
    56    /* kind */
    57    kindUnsafePointer | kindDirectIface,
    58    /* equal */
    59    &runtime_pointerequal_descriptor,
    60    /* gcdata */
    61    unsafe_Pointer_gc,
    62    /* _string */
    63    &reflection_string,
    64    /* uncommontype */
    65    NULL,
    66    /* ptrToThis */
    67    NULL
    68  };
    69  
    70  /* We also need the type descriptor for the pointer to unsafe.Pointer,
    71     since any package which refers to that type descriptor will expect
    72     it to be defined elsewhere.  */
    73  
    74  extern const struct ptrtype pointer_unsafe_Pointer
    75    __asm__ (GOSYM_PREFIX "unsafe.Pointer..p");
    76  
    77  /* The reflection string.  */
    78  #define PREFLECTION "*unsafe.Pointer"
    79  static const String preflection_string =
    80  {
    81    (const byte *) PREFLECTION,
    82    sizeof PREFLECTION - 1,
    83  };
    84  
    85  extern const byte pointer_unsafe_Pointer_gc[]
    86    __asm__ (GOSYM_PREFIX "unsafe.Pointer..p..g");
    87  
    88  const byte pointer_unsafe_Pointer_gc[] = { 1 };
    89  
    90  const struct ptrtype pointer_unsafe_Pointer =
    91  {
    92    /* type */
    93    {
    94      /* size */
    95      sizeof (void *),
    96      /* ptrdata */
    97      sizeof (void *),
    98      /* hash */
    99      1256018616U,
   100      /* tflag */
   101      tflagRegularMemory,
   102      /* align */
   103      __alignof (void *),
   104      /* fieldAlign */
   105      offsetof (struct field_align, p) - 1,
   106      /* kind */
   107      kindPtr | kindDirectIface,
   108      /* equalfn */
   109      &runtime_pointerequal_descriptor,
   110      /* gcdata */
   111      pointer_unsafe_Pointer_gc,
   112      /* _string */
   113      &preflection_string,
   114      /* uncommontype */
   115      NULL,
   116      /* ptrToThis */
   117      NULL
   118    },
   119    /* elem */
   120    &unsafe_Pointer
   121  };