diff options
Diffstat (limited to 'libsyscalls')
-rw-r--r-- | libsyscalls/advanced.h | 19 | ||||
-rw-r--r-- | libsyscalls/internal-begin.h | 85 | ||||
-rw-r--r-- | libsyscalls/internal-end.h | 3 |
3 files changed, 90 insertions, 17 deletions
diff --git a/libsyscalls/advanced.h b/libsyscalls/advanced.h index 22ed3d0..7876178 100644 --- a/libsyscalls/advanced.h +++ b/libsyscalls/advanced.h @@ -4,10 +4,15 @@ #endif -#define LIBSYSCALLS_TYPEOFFSET_SPECIAL_TYPES 0 /* does not use LIBSYSCALLS_TYPEBITSMASK */ -#define LIBSYSCALLS_TYPEOFFSET_SPLIT_PRIMITIVES 8 -#define LIBSYSCALLS_TYPEOFFSET_COMPOSITE_PRIMITIVES 48 -#define LIBSYSCALLS_TYPEOFFSET_UNANNOTATED_NUMERICALS 64 -#define LIBSYSCALLS_TYPEOFFSET_ANNOTATED_NUMERICALS 256 -#define LIBSYSCALLS_TYPEOFFSET_FIXED_ARRAYS 512 -#define LIBSYSCALLS_TYPEOFFSET_STRUCTS_AND_UNIONS 1024 +#define LIBSYSCALLS_TYPEOFFSET_SPECIAL_TYPES 0 /* does not use LIBSYSCALLS_TYPEBITSMASK */ +#define LIBSYSCALLS_TYPEOFFSET_SPLIT_PRIMITIVES 8 +#define LIBSYSCALLS_TYPEOFFSET_COMPOSITE_PRIMITIVES 48 +#define LIBSYSCALLS_TYPEOFFSET_UNANNOTATED_NUMERICALS 64 +#define LIBSYSCALLS_TYPEOFFSET_ANNOTATED_NUMERICALS 256 +#define LIBSYSCALLS_TYPEOFFSET_FIXED_ARRAYS 512 +#define LIBSYSCALLS_TYPEOFFSET_STRUCTS_AND_UNIONS 1024 +#define LIBSYSCALLS_TYPEOFFSET_ANON_STRUCTS_AND_UNIONS 3072 /* these are OS and maybe even architecture specific structures + * structures and unions that do not have a name (or has a name + * but is only used as a substructure); they are not listed in + * `enum libsyscalls_datatype`, but can appear when querying + * the layout of a struct or union */ diff --git a/libsyscalls/internal-begin.h b/libsyscalls/internal-begin.h index 5c42b7e..0d89bb7 100644 --- a/libsyscalls/internal-begin.h +++ b/libsyscalls/internal-begin.h @@ -7,6 +7,18 @@ #include <limits.h> #include <stddef.h> + +/** + * Opaque type for symbol printer function identification + */ +typedef unsigned short int LIBSYSCALLS_SYMBOL_PRINTER; + +/** + * Opaque type for symbol printer function parameters + */ +typedef struct libsyscalls_symbol_printer_data LIBSYSCALLS_SYMBOL_PRINTER_DATA; + + /* a comma possible into a macro */ #define LIBSYSCALLS_COMMA_ , @@ -14,6 +26,9 @@ #ifndef LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ # define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ #endif +#ifndef LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ +# define LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ +#endif #if defined(__GNUC__) # define LIBSYSCALLS_GCC_ATTRIBUTES_(...) __attribute__((__VA_ARGS__)) @@ -23,16 +38,65 @@ #define LIBSYSCALLS_PAD_(WANT, HAVE) (((WANT) - (HAVE) % (WANT)) % (WANT)) - -/** - * Opaque type for symbol printer function identification - */ -typedef unsigned short int LIBSYSCALLS_SYMBOL_PRINTER; - -/** - * Opaque type for symbol printer function parameters - */ -typedef struct libsyscalls_symbol_printer_data LIBSYSCALLS_SYMBOL_PRINTER_DATA; +#define LIBSYSCALLS_IS_PADDING_REQUIRED_(FIELDS, FIELD_BITSIZE, ALIGN_TO_BITS)\ + ((((FIELDS) & ~((FIELDS) - 1)) * (FIELD_BITSIZE)) % ALIGN_TO_BITS) + +#define LIBSYSCALLS_CAN_ALIGN_(FIELDS, FIELD_BITSIZE, ALIGN_BITS)\ + (!((FIELDS) * (FIELD_BITSIZE) % (ALIGN_BITS) || (ALIGN_BITS) > (FIELDS) * (FIELD_BITSIZE))) + +#if defined(__INTPTR_WIDTH__) +# define LIBSYSCALLS_POINTER_BIT_ __INTPTR_WIDTH__ +#elif defined(__SIZEOF_POINTER__) +# define LIBSYSCALLS_POINTER_BIT_ (__SIZEOF_POINTER__ * CHAR_BIT) +#elif defined(__LLP128__) || defined(_LLP128) +# define LIBSYSCALLS_POINTER_BIT_ 128 +#elif defined(__LLP64__) || defined(_LLP64) +# define LIBSYSCALLS_POINTER_BIT_ 64 +#elif defined(__LP64__) || defined(_LP64) +# define LIBSYSCALLS_POINTER_BIT_ 64 +#elif defined(__ILP64__) || defined(_ILP64) +# define LIBSYSCALLS_POINTER_BIT_ 64 +#elif defined(__SILP64__) || defined(_SILP64) +# define LIBSYSCALLS_POINTER_BIT_ 64 +#elif defined(__LLP32__) || defined(_LLP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__LP32__) || defined(_LP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__ILP32__) || defined(_ILP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__SILP32__) || defined(_SILP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__IP32__) || defined(_IP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__SIP32__) || defined(_SIP32) +# define LIBSYSCALLS_POINTER_BIT_ 32 +#elif defined(__IP16__) || defined(_IP16) +# define LIBSYSCALLS_POINTER_BIT_ 16 +#elif defined(__SIP16__) || defined(_SIP16) +# define LIBSYSCALLS_POINTER_BIT_ 16 +#elif defined(__SP16__) || defined(_SP16) +# define LIBSYSCALLS_POINTER_BIT_ 16 +#elif defined(__INTPTR_MAX__) && defined(__LONG_MAX__) +# if __INTPTR_MAX__ == __LONG_MAX__ +# define LIBSYSCALLS_POINTER_BIT_ LONG_BIT +# elif __INTPTR_MAX__ / __LONG_MAX__ / __LONG_MAX__ == 2 +# define LIBSYSCALLS_POINTER_BIT_ (LONG_BIT + LONG_BIT) +# elif __INTPTR_MAX__ / __LONG_MAX__ / __LONG_MAX__ / __LONG_MAX__ / __LONG_MAX__ == 8 +# define LIBSYSCALLS_POINTER_BIT_ (LONG_BIT + LONG_BIT + LONG_BIT + LONG_BIT) +# endif +#endif +#if !defined(LIBSYSCALLS_POINTER_BIT_) && defined(__INTPTR_MAX__) +# if __INTPTR_MAX__ == 32767ULL +# define LIBSYSCALLS_POINTER_BIT_ 16 +# elif __INTPTR_MAX__ == 2147483647ULL +# define LIBSYSCALLS_POINTER_BIT_ 32 +# elif __INTPTR_MAX__ == 9223372036854775807ULL +# define LIBSYSCALLS_POINTER_BIT_ 64 +# endif +#endif +#if !defined(LIBSYSCALLS_POINTER_BIT_) +# error Cannot figure out bit width of (void *) +#endif #define LIBSYSCALLS_LIST_ERRORS_X_(ENUM, STR) ENUM @@ -75,6 +139,7 @@ typedef struct libsyscalls_symbol_printer_data LIBSYSCALLS_SYMBOL_PRINTER_DATA; = LIBSYSCALLS_TYPEOFFSET_FIXED_ARRAYS\ | LIBSYSCALLS_TYPEBITS##SUFFIX) + #define LIBSYSCALLS_BITSIZEOF_(T) (sizeof(T) / sizeof(char) * CHAR_BIT) #define LIBSYSCALLS_FIELD_BITSIZEOF_(S, F) LIBSYSCALLS_BITSIZEOF_(((S *)0)->F) diff --git a/libsyscalls/internal-end.h b/libsyscalls/internal-end.h index ed7af58..2aeb2f0 100644 --- a/libsyscalls/internal-end.h +++ b/libsyscalls/internal-end.h @@ -8,6 +8,9 @@ #undef LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ #undef LIBSYSCALLS_GCC_ATTRIBUTES_ #undef LIBSYSCALLS_PAD_ +#undef LIBSYSCALLS_IS_PADDING_REQUIRED_ +#undef LIBSYSCALLS_CAN_ALIGN_ +#undef LIBSYSCALLS_POINTER_BIT_ #undef LIBSYSCALLS_LIST_ERRORS_X_ #undef LIBSYSCALLS_DATATYPE_X_ |