diff options
Diffstat (limited to '')
-rw-r--r-- | common.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/common.h b/common.h new file mode 100644 index 0000000..f2ac824 --- /dev/null +++ b/common.h @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#ifdef REQUIRE_FLEXABLE_OR_NPARAMS +# if defined(__clang__) || defined(__GNUC__) +# define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ +# else +# define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ NPARAMS +# warning Setting LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ to NPARAMS as it is not known that the compiler supports static allocation of structs with flexible arrays +# endif +#endif +#include "libsyscalls.h" + +#include <stddef.h> +#include <stdint.h> + +#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))]) + + +struct libsyscalls_symbol_printer_data { + enum libsyscalls_arch arch; + int nr; + char buf[]; +}; + + +#include "generated/oses.h" +#include "generated/arches.h" +#include "generated/lowercase.h" +#include "generated/macros.h" + + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif +extern const struct libsyscalls_syscall *const *const *const libsyscalls_syscalls_tables_[]; +#define X(UPPERCASE, LOWERCASE)\ + extern const struct libsyscalls_syscall *const *const libsyscalls_##LOWERCASE##_syscalls_table_[]; +LIST_OSES(X,) +#undef X +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + +#define COUNT_ARG_PAIRS(...) (0 __VA_OPT__(+ COUNT_ARG_PAIRS_1(__VA_ARGS__))) + +/* mk/generate.mk reads these two lines, do not format them as multiline macros! */ +#define COUNT_ARG_PAIRS_1(x1, x2, ...) 1 __VA_OPT__(+ COUNT_ARG_PAIRS_2(__VA_ARGS__)) +#define PARAMS_BUILD_TYPES_1(x, A, ...) LIBSYSCALLS_TYPE_##A __VA_OPT__(, PARAMS_BUILD_TYPES_2(__VA_ARGS__)) + +#define PARAMS(...)\ + .max_argument_count = COUNT_ARG_PAIRS(__VA_ARGS__),\ + .in_pointer_mask = PARAMS_BUILD_MASK(IN, __VA_ARGS__),\ + .out_pointer_mask = PARAMS_BUILD_MASK(OUT, __VA_ARGS__), \ + .symbolic_mask = PARAMS_BUILD_MASK(SYM, __VA_ARGS__)\ + __VA_OPT__(, .parameters_types = {PARAMS_BUILD_TYPES_1(__VA_ARGS__)}) + +#define ZERO(TYPE) TYPE, .expect_zero = 1 +#define LIBSYSCALLS_TYPE_ZERO(TYPE) ZERO(LIBSYSCALLS_TYPE_##TYPE) + +#define SYMB(TYPE) TYPE, .symbolic_return = 1 +#define LIBSYSCALLS_TYPE_SYMB(TYPE) SYMB(LIBSYSCALLS_TYPE_##TYPE) + +#define SYSCALL_ABI(OS, NAME, CATEGORY, SUBCATEGORY, MIN_ARGS, RETURN_TYPE, ...)\ + static struct libsyscalls_syscall_abi OS##_syscall_##NAME = {\ + .category = LIBSYSCALLS_CAT_##CATEGORY,\ + .subcategory.LOWERCASE_##CATEGORY = LIBSYSCALLS_##CATEGORY##_SUBCAT_##SUBCATEGORY,\ + .min_argument_count = MIN_ARGS,\ + .return_type = LIBSYSCALLS_TYPE_##RETURN_TYPE,\ + __VA_ARGS__\ + } |