2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <lttng/bug.h>
15 #include <machine/param.h>
19 #define LTTNG_UST_PAGE_SIZE sysconf(_SC_PAGE_SIZE)
20 #elif defined(PAGE_SIZE)
21 #define LTTNG_UST_PAGE_SIZE PAGE_SIZE
23 #error "Please add page size detection for your OS."
26 #define LTTNG_UST_PAGE_MASK (~(LTTNG_UST_PAGE_SIZE - 1))
28 #define __LTTNG_UST_ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask))
29 #define LTTNG_UST_ALIGN(v, align) __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1)
30 #define LTTNG_UST_PAGE_ALIGN(addr) LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE)
33 * lttng_ust_offset_align - Calculate the offset needed to align an object on
34 * its natural alignment towards higher addresses.
35 * @align_drift: object offset from an "alignment"-aligned address.
36 * @alignment: natural object alignment. Must be non-zero, power of 2.
38 * Returns the offset that must be added to align towards higher
41 #define lttng_ust_offset_align(align_drift, alignment) \
43 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
44 || ((alignment) & ((alignment) - 1))); \
45 (((alignment) - (align_drift)) & ((alignment) - 1)); \
49 * lttng_ust_offset_align_floor - Calculate the offset needed to align an
50 * object on its natural alignment towards lower addresses.
51 * @align_drift: object offset from an "alignment"-aligned address.
52 * @alignment: natural object alignment. Must be non-zero, power of 2.
54 * Returns the offset that must be substracted to align towards lower addresses.
56 #define lttng_ust_offset_align_floor(align_drift, alignment) \
58 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
59 || ((alignment) & ((alignment) - 1))); \
60 (((align_drift) - (alignment)) & ((alignment) - 1)); \
64 * Non-namespaced defines for backwards compatibility,
65 * introduced in 2.13, should be removed in the future.
68 /* Cygwin limits.h defines its own PAGE_SIZE */
70 #define PAGE_SIZE LTTNG_UST_PAGE_SIZE
73 /* FreeBSD and macOS defines their own PAGE_MASK. */
75 #define PAGE_MASK LTTNG_UST_PAGE_MASK
78 /* FreeBSD machine/param.h defines its own ALIGN */
80 #define ALIGN LTTNG_UST_ALIGN
84 #define PAGE_ALIGN LTTNG_UST_PAGE_ALIGN
88 #define offset_align lttng_ust_offset_align
91 #ifndef offset_align_floor
92 #define offset_align_floor lttng_ust_offset_align_floor
95 #endif /* _UST_ALIGN_H */
This page took 0.064808 seconds and 4 git commands to generate.