20#ifndef LC_MEMORY_SUPPORT_H
21#define LC_MEMORY_SUPPORT_H
23#include "ext_headers.h"
30#define LC_MEM_COMMON_ALIGNMENT (8)
41#define LC_ALIGNED_BUFFER(name, size, alignment) \
42 uint64_t name[(size + sizeof(uint64_t) - 1) / sizeof(uint64_t)] \
43 __attribute__((aligned(alignment)))
46#define LC_ALIGNMENT_MASK(alignment) (alignment - 1)
47#define LC_ALIGN_APPLY(x, mask) (((x) + (mask)) & ~(mask))
48#define LC_ALIGN(x, a) LC_ALIGN_APPLY((x), (uintptr_t)(a))
56#define LC_ALIGN_PTR_64(p, a) ((uint64_t *)LC_ALIGN((uintptr_t)(p), (a)));
64#define LC_ALIGN_PTR_32(p, a) ((uint32_t *)LC_ALIGN((uintptr_t)(p), (a)))
72#define LC_ALIGN_PTR_16(p, a) ((uint16_t *)LC_ALIGN((uintptr_t)(p), (a)))
80#define LC_ALIGN_PTR_8(p, a) ((uint8_t *)LC_ALIGN((uintptr_t)(p), (a)))
85#define LC_XOR_MIN_ALIGNMENT(min, requested) \
86 ((min < requested) ? (requested) : (min))
89#define LC_DEF_HOST_X86_64
90#undef LC_DEF_HOST_ARM32_NEON
91#undef LC_DEF_HOST_AARCH64
93#ifdef LC_DEF_HOST_X86_64
99#define LC_XOR_AVX2_ALIGNMENT (sizeof(uint64_t))
100#define LC_XOR_ALIGNMENT(min) LC_XOR_MIN_ALIGNMENT(min, LC_XOR_AVX2_ALIGNMENT)
102#elif (defined(LC_DEF_HOST_ARM32_NEON) || defined(LC_DEF_HOST_AARCH64)) && \
103 !defined(LINUX_KERNEL)
109#define LC_XOR_NEON_ALIGNMENT (sizeof(uint64_t))
110#define LC_XOR_ALIGNMENT(min) LC_XOR_MIN_ALIGNMENT(min, LC_XOR_NEON_ALIGNMENT)
114#define LC_XOR_ALIGNMENT(min) LC_XOR_MIN_ALIGNMENT(min, (sizeof(uint64_t)))
175 if ((uintptr_t)ptr & alignmask)
static int lc_mem_aligned(const uint8_t *ptr, uint32_t alignmask)
Check if memory pointer is aligned to given alignment mask.
int lc_alloc_high_aligned(void **memptr, size_t alignment, size_t size)
allocate aligned memory with arbitrary alignment
void lc_free(void *ptr)
free the memory allocated with lc_alloc_aligned
int lc_alloc_aligned_secure(void **memptr, size_t alignment, size_t size)
allocate aligned memory up to 8 bytes alignment with additional security precautions
int lc_alloc_aligned(void **memptr, size_t alignment, size_t size)
allocate aligned memory up to 8 bytes alignment
void lc_free_high_aligned(void *ptr, size_t size)
free the memory allocated with lc_alloc_high_aligned