2 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * SPDX-License-Identifier: MIT
15 #ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE. */
16 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
19 #ifndef PAGE_MASK /* macOS defines its own PAGE_MASK. */
20 #define PAGE_MASK (~(PAGE_SIZE - 1))
23 #define __ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask))
25 #ifndef ALIGN /* macOS defines its own ALIGN. */
26 #define ALIGN(v, align) __ALIGN_MASK(v, (__typeof__(v)) (align) - 1)
29 #define __ALIGN_FLOOR_MASK(v, mask) ((v) & ~(mask))
32 #define ALIGN_FLOOR(v, align) __ALIGN_FLOOR_MASK(v, (__typeof__(v)) (align) - 1)
35 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
38 * offset_align - Calculate the offset needed to align an object on its natural
39 * alignment towards higher addresses.
40 * @align_drift: object offset from an "alignment"-aligned address.
41 * @alignment: natural object alignment. Must be non-zero, power of 2.
43 * Returns the offset that must be added to align towards higher
46 #define offset_align(align_drift, alignment) \
48 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
49 || ((alignment) & ((alignment) - 1))); \
50 (((alignment) - (align_drift)) & ((alignment) - 1)); \
54 * offset_align_floor - Calculate the offset needed to align an object
55 * on its natural alignment towards lower addresses.
56 * @align_drift: object offset from an "alignment"-aligned address.
57 * @alignment: natural object alignment. Must be non-zero, power of 2.
59 * Returns the offset that must be substracted to align towards lower addresses.
61 #define offset_align_floor(align_drift, alignment) \
63 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
64 || ((alignment) & ((alignment) - 1))); \
65 (((align_drift) - (alignment)) & ((alignment) - 1)); \
68 #endif /* _LTTNG_ALIGN_H */
This page took 0.034209 seconds and 4 git commands to generate.