Path: blob/master/runtime/include/ffi_common.h
5986 views
/* -----------------------------------------------------------------------1ffi_common.h - Copyright (C) 2011, 2012, 2013 Anthony Green2Copyright (C) 2007 Free Software Foundation, Inc3Copyright (c) 1996 Red Hat, Inc.45Common internal definitions and macros. Only necessary for building6libffi.7----------------------------------------------------------------------- */89/*10* ===========================================================================11* Copyright (c) 2021, 2021 IBM Corp. and others12* ===========================================================================13*/1415#ifndef FFI_COMMON_H16#define FFI_COMMON_H1718#ifdef __cplusplus19extern "C" {20#endif2122#include <fficonfig.h>2324/* Do not move this. Some versions of AIX are very picky about where25this is positioned. */26#ifdef __THW_370__27#include <stdlib.h>28#else29#ifdef __GNUC__30# if HAVE_ALLOCA_H31# include <alloca.h>32# else33/* mingw64 defines this already in malloc.h. */34# ifndef alloca35# define alloca __builtin_alloca36# endif37# endif38# define MAYBE_UNUSED __attribute__((__unused__))39#else40# define MAYBE_UNUSED41# if HAVE_ALLOCA_H42# include <alloca.h>43# else44# ifdef _AIX45# pragma alloca46# else47# ifndef alloca /* predefined by HP cc +Olibcalls */48# ifdef _MSC_VER49# define alloca _alloca50# else51char *alloca ();52# endif53# endif54# endif55# endif56#endif57#endif5859/* Check for the existence of memcpy. */60#if STDC_HEADERS61# include <string.h>62#else63# ifndef HAVE_MEMCPY64# define memcpy(d, s, n) bcopy ((s), (d), (n))65# endif66#endif6768#if defined(FFI_DEBUG)69#include <stdio.h>70#endif7172#ifdef FFI_DEBUG73void ffi_assert(char *expr, char *file, int line);74void ffi_stop_here(void);75void ffi_type_test(ffi_type *a, char *file, int line);7677#define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))78#define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))79#define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)80#else81#define FFI_ASSERT(x)82#define FFI_ASSERT_AT(x, f, l)83#define FFI_ASSERT_VALID_TYPE(x)84#endif8586#define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)87#define ALIGN_DOWN(v, a) (((size_t) (v)) & -a)8889/* v cast to size_t and aligned up to a multiple of a */90#define FFI_ALIGN ALIGN91/* v cast to size_t and aligned down to a multiple of a */92#define FFI_ALIGN_DOWN ALIGN_DOWN9394/* Perform machine dependent cif processing */95ffi_status ffi_prep_cif_machdep(ffi_cif *cif);96ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,97unsigned int nfixedargs, unsigned int ntotalargs);9899/* Extended cif, used in callback from assembly routine */100typedef struct101{102ffi_cif *cif;103void *rvalue;104void **avalue;105} extended_cif;106107/* Terse sized type definitions. */108#if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C) || defined(__THW_370__)109typedef unsigned char UINT8;110typedef signed char SINT8;111typedef unsigned short UINT16;112typedef signed short SINT16;113typedef unsigned int UINT32;114typedef signed int SINT32;115# ifdef _MSC_VER116typedef unsigned __int64 UINT64;117typedef signed __int64 SINT64;118# else119# include <inttypes.h>120typedef uint64_t UINT64;121typedef int64_t SINT64;122# endif123#else124typedef unsigned int UINT8 __attribute__((__mode__(__QI__)));125typedef signed int SINT8 __attribute__((__mode__(__QI__)));126typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));127typedef signed int SINT16 __attribute__((__mode__(__HI__)));128typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));129typedef signed int SINT32 __attribute__((__mode__(__SI__)));130typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));131typedef signed int SINT64 __attribute__((__mode__(__DI__)));132#endif133134typedef float FLOAT32;135136#if !defined(__GNUC__) || !defined(__THW_370__)137#define __builtin_expect(x, expected_value) (x)138#endif139#define LIKELY(x) __builtin_expect(!!(x),1)140#define UNLIKELY(x) __builtin_expect((x)!=0,0)141142#ifdef __cplusplus143}144#endif145146#endif147148149