diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-17 13:23:51 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-17 13:23:51 +0100 |
commit | 2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea (patch) | |
tree | a321a6a0b4bc93cbc1b7704239a675c490383b6d /common.h | |
parent | Tell the user whether signals and errors are signed or unsigned (diff) | |
download | libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.gz libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.bz2 libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.xz |
Miscellaneous improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 102 |
1 files changed, 53 insertions, 49 deletions
@@ -57,12 +57,16 @@ #define COMMA , -#define MISALIGNMENT(ADDR, ALIGN) (((ADDR) - ((ADDR) % (uintptr_t)(ALIGN))) % (uintptr_t)(ALIGN)) -#define ALIGN_BUF(BUF, ALIGN) (&(BUF)[(size_t)MISALIGNMENT((uintptr_t)(char *)(BUF), (ALIGN))]) +#define MISALIGNMENT(ADDR, ALIGN) ((ADDR) & ((uintptr_t)(ALIGN) - 1U)) +#define ALIGNMENT_ADJUSTMENT(ADDR, ALIGN) MISALIGNMENT((ALIGN) - MISALIGNMENT((ADDR), (ALIGN)), (ALIGN)) +#define ALIGN_BUF(BUF, ALIGN) (&(BUF)[(size_t)ALIGNMENT_ADJUSTMENT((uintptr_t)(char *)(BUF), (ALIGN))]) #define ELEMSOF(ARR) (sizeof(ARR) / sizeof *(ARR)) #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define LOWEST_BIT(X) ((X) & ~((X) - 1)) -#define POST_HIGHEST_OF_CONSECUTIVELY_BITS(X) ((X) + LOWEST_BIT(X)) +#define POST_HIGHEST_OF_CONSECUTIVELY_BITS(X) ((X) + LOWEST_BIT((X))) +#define IS_NOT_2POW(X) ((X) & ((X) - 1)) +#define SET_MASK_TRAIL(X) ((X) | ((X) - 1U)) +#define USAT_MINUS(A, B) ((A) < (B) ? 0 : (A) - (B)) struct libsyscalls_symbol_printer_data { @@ -76,54 +80,54 @@ enum endian { Little }; - -/* Don't forget to update SUPPORTED_ARCHES in Makefile */ -#define LIST_ARCH_SPECS(X, D) /* byte intptr size_t endian sign */\ - X(LIBSYSCALLS_ARCH_ALPHA_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_ALPHA_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_AMD64, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_AMD64_X32, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + /* [------ size ------] [align] */ +#define LIST_ARCH_SPECS(X, D) /* byte intptr size_t intmax endian sign */\ + X(LIBSYSCALLS_ARCH_ALPHA_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ALPHA_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_AMD64, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_AMD64_X32, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ /* - X(LIBSYSCALLS_ARCH_ARM_OABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_ARM_OABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_ARM_EABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_ARM_EABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_OABI_LE, 8, TODO, TODO, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_OABI_BE, 8, TODO, TODO, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_EABI_LE, 8, TODO, TODO, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_EABI_BE, 8, TODO, TODO, 64, Big, TWOS_COMPLEMENT) D\ */\ - X(LIBSYSCALLS_ARCH_IA64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_IA64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_IA64_P32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_IA64_P32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_M68K, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MICROBLAZE_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MICROBLAZE_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MICROBLAZE_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MICROBLAZE_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_O32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_O32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_N32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_N32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_N64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_MIPS_N64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_PARISC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_PARISC_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_SPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_POWERPC_SPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_S390_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_S390_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_SH_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_SH_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_SPARC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_SPARC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_SPARC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_I386, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_XTENSA_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ - X(LIBSYSCALLS_ARCH_XTENSA_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) + X(LIBSYSCALLS_ARCH_IA64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_P32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_P32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_M68K, 8, 32, 32, 16, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_32_LE, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_32_BE, 8, 32, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_O32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_O32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_PARISC_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_PARISC_64, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_SPU_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_SPU_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_S390_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_S390_64, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SH_LE, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SH_BE, 8, 32, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_I386, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_XTENSA_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_XTENSA_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) + /* Don't forget to update SUPPORTED_ARCHES in Makefile */ #include "generated/oses.h" |