(root)/
gcc-13.2.0/
libffi/
include/
ffi_common.h
       1  /* -----------------------------------------------------------------------
       2     ffi_common.h - Copyright (C) 2011, 2012, 2013  Anthony Green
       3                    Copyright (C) 2007  Free Software Foundation, Inc
       4                    Copyright (c) 1996  Red Hat, Inc.
       5                    
       6     Common internal definitions and macros. Only necessary for building
       7     libffi.
       8  
       9     Permission is hereby granted, free of charge, to any person
      10     obtaining a copy of this software and associated documentation
      11     files (the ``Software''), to deal in the Software without
      12     restriction, including without limitation the rights to use, copy,
      13     modify, merge, publish, distribute, sublicense, and/or sell copies
      14     of the Software, and to permit persons to whom the Software is
      15     furnished to do so, subject to the following conditions:
      16  
      17     The above copyright notice and this permission notice shall be
      18     included in all copies or substantial portions of the Software.
      19  
      20     THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
      21     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      22     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
      23     NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
      24     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      25     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      26     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27     DEALINGS IN THE SOFTWARE.
      28  
      29     ----------------------------------------------------------------------- */
      30  
      31  #ifndef FFI_COMMON_H
      32  #define FFI_COMMON_H
      33  
      34  #ifdef __cplusplus
      35  extern "C" {
      36  #endif
      37  
      38  #include <fficonfig.h>
      39  
      40  /* Do not move this. Some versions of AIX are very picky about where
      41     this is positioned. */
      42  #ifdef __GNUC__
      43  # if HAVE_ALLOCA_H
      44  #  include <alloca.h>
      45  # else
      46    /* mingw64 defines this already in malloc.h. */
      47  #  ifndef alloca
      48  #    define alloca __builtin_alloca
      49  #  endif
      50  # endif
      51  # define MAYBE_UNUSED __attribute__((__unused__))
      52  #else
      53  # define MAYBE_UNUSED
      54  # if HAVE_ALLOCA_H
      55  #  include <alloca.h>
      56  # else
      57  #  ifdef _AIX
      58  #   pragma alloca
      59  #  else
      60  #   ifndef alloca /* predefined by HP cc +Olibcalls */
      61  #    ifdef _MSC_VER
      62  #     define alloca _alloca
      63  #    else
      64  char *alloca ();
      65  #   endif
      66  #  endif
      67  # endif
      68  # endif
      69  #endif
      70  
      71  /* Check for the existence of memcpy. */
      72  #if STDC_HEADERS
      73  # include <string.h>
      74  #else
      75  # ifndef HAVE_MEMCPY
      76  #  define memcpy(d, s, n) bcopy ((s), (d), (n))
      77  # endif
      78  #endif
      79  
      80  #if defined(FFI_DEBUG)
      81  #include <stdio.h>
      82  #endif
      83  
      84  #ifdef FFI_DEBUG
      85  void ffi_assert(char *expr, char *file, int line);
      86  void ffi_stop_here(void);
      87  void ffi_type_test(ffi_type *a, char *file, int line);
      88  
      89  #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
      90  #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
      91  #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
      92  #else
      93  #define FFI_ASSERT(x)
      94  #define FFI_ASSERT_AT(x, f, l)
      95  #define FFI_ASSERT_VALID_TYPE(x)
      96  #endif
      97  
      98  /* v cast to size_t and aligned up to a multiple of a */
      99  #define FFI_ALIGN(v, a)  (((((size_t) (v))-1) | ((a)-1))+1)
     100  /* v cast to size_t and aligned down to a multiple of a */
     101  #define FFI_ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
     102  
     103  /* Perform machine dependent cif processing */
     104  ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
     105  ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
     106  	 unsigned int nfixedargs, unsigned int ntotalargs);
     107  
     108  
     109  #if HAVE_LONG_DOUBLE_VARIANT
     110  /* Used to adjust size/alignment of ffi types.  */
     111  void ffi_prep_types (ffi_abi abi);
     112  #endif
     113  
     114  /* Used internally, but overridden by some architectures */
     115  ffi_status ffi_prep_cif_core(ffi_cif *cif,
     116  			     ffi_abi abi,
     117  			     unsigned int isvariadic,
     118  			     unsigned int nfixedargs,
     119  			     unsigned int ntotalargs,
     120  			     ffi_type *rtype,
     121  			     ffi_type **atypes);
     122  
     123  /* Translate a data pointer to a code pointer.  Needed for closures on
     124     some targets.  */
     125  void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN;
     126  
     127  /* The arch code calls this to determine if a given closure has a
     128     static trampoline. */
     129  int ffi_tramp_is_present (void *closure) FFI_HIDDEN;
     130  
     131  /* Extended cif, used in callback from assembly routine */
     132  typedef struct
     133  {
     134    ffi_cif *cif;
     135    void *rvalue;
     136    void **avalue;
     137  } extended_cif;
     138  
     139  /* Terse sized type definitions.  */
     140  #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C)
     141  typedef unsigned char UINT8;
     142  typedef signed char   SINT8;
     143  typedef unsigned short UINT16;
     144  typedef signed short   SINT16;
     145  typedef unsigned int UINT32;
     146  typedef signed int   SINT32;
     147  # ifdef _MSC_VER
     148  typedef unsigned __int64 UINT64;
     149  typedef signed __int64   SINT64;
     150  # else
     151  # include <inttypes.h>
     152  typedef uint64_t UINT64;
     153  typedef int64_t  SINT64;
     154  # endif
     155  #else
     156  typedef unsigned int UINT8  __attribute__((__mode__(__QI__)));
     157  typedef signed int   SINT8  __attribute__((__mode__(__QI__)));
     158  typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));
     159  typedef signed int   SINT16 __attribute__((__mode__(__HI__)));
     160  typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));
     161  typedef signed int   SINT32 __attribute__((__mode__(__SI__)));
     162  typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));
     163  typedef signed int   SINT64 __attribute__((__mode__(__DI__)));
     164  #endif
     165  
     166  typedef float FLOAT32;
     167  
     168  #ifndef __GNUC__
     169  #define __builtin_expect(x, expected_value) (x)
     170  #endif
     171  #define LIKELY(x)    __builtin_expect(!!(x),1)
     172  #define UNLIKELY(x)  __builtin_expect((x)!=0,0)
     173  
     174  #ifdef __cplusplus
     175  }
     176  #endif
     177  
     178  #endif