summaryrefslogtreecommitdiffstats
path: root/common.h
blob: f2ac824d25eb21f029b1410271352def3e7764f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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__\
	}