#endif | #endif | ||||
#endif | #endif | ||||
#ifndef __cplusplus | |||||
# ifdef G_ALIGNOF | |||||
# define RSPAMD_ALIGNOF G_ALIGNOF | |||||
# else | |||||
# define RSPAMD_ALIGNOF(t) _Alignof(t) | |||||
# endif | |||||
#else | |||||
/* glib G_ALIGNOF nor C11 _Alignof are not good enough for C++, nuff said... */ | |||||
# define RSPAMD_ALIGNOF(t) alignof(t) | |||||
#endif | |||||
/* Address sanitizer */ | /* Address sanitizer */ | ||||
#ifdef __clang__ | #ifdef __clang__ | ||||
# if __has_feature(address_sanitizer) | # if __has_feature(address_sanitizer) |
rspamd_cryptobox_auth_ctx_len (enum rspamd_cryptobox_mode mode) | rspamd_cryptobox_auth_ctx_len (enum rspamd_cryptobox_mode mode) | ||||
{ | { | ||||
if (G_LIKELY (mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | if (G_LIKELY (mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | ||||
return sizeof (crypto_onetimeauth_state) + _Alignof (crypto_onetimeauth_state); | |||||
return sizeof (crypto_onetimeauth_state) + RSPAMD_ALIGNOF(crypto_onetimeauth_state); | |||||
} | } | ||||
else { | else { | ||||
#ifndef HAVE_USABLE_OPENSSL | #ifndef HAVE_USABLE_OPENSSL | ||||
rspamd_cryptobox_hash_init (rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen) | rspamd_cryptobox_hash_init (rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen) | ||||
{ | { | ||||
crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p, | crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p, | ||||
_Alignof(crypto_generichash_blake2b_state)); | |||||
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); | |||||
crypto_generichash_blake2b_init (st, key, keylen, | crypto_generichash_blake2b_init (st, key, keylen, | ||||
crypto_generichash_blake2b_BYTES_MAX); | crypto_generichash_blake2b_BYTES_MAX); | ||||
} | } | ||||
rspamd_cryptobox_hash_update (rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len) | rspamd_cryptobox_hash_update (rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len) | ||||
{ | { | ||||
crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p, | crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p, | ||||
_Alignof(crypto_generichash_blake2b_state)); | |||||
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); | |||||
crypto_generichash_blake2b_update (st, data, len); | crypto_generichash_blake2b_update (st, data, len); | ||||
} | } | ||||
rspamd_regexp_set_cache_id (re, i); | rspamd_regexp_set_cache_id (re, i); | ||||
if (re_class->st == NULL) { | if (re_class->st == NULL) { | ||||
(void) !posix_memalign ((void **)&re_class->st, _Alignof (rspamd_cryptobox_hash_state_t), | |||||
(void) !posix_memalign ((void **)&re_class->st, RSPAMD_ALIGNOF(rspamd_cryptobox_hash_state_t), | |||||
sizeof (*re_class->st)); | sizeof (*re_class->st)); | ||||
g_assert (re_class->st != NULL); | g_assert (re_class->st != NULL); | ||||
rspamd_cryptobox_hash_init (re_class->st, NULL, 0); | rspamd_cryptobox_hash_init (re_class->st, NULL, 0); |
#define MEMPOOL_UID_LEN 20 | #define MEMPOOL_UID_LEN 20 | ||||
/* All pointers are aligned as this variable */ | /* All pointers are aligned as this variable */ | ||||
#define MIN_MEM_ALIGNMENT G_MEM_ALIGN | #define MIN_MEM_ALIGNMENT G_MEM_ALIGN | ||||
#ifndef __cplusplus | |||||
#define RSPAMD_ALIGNOF G_ALIGNOF | |||||
#else | |||||
#define RSPAMD_ALIGNOF(t) alignof(t) | |||||
#endif | |||||
/** | /** | ||||
* Destructor type definition | * Destructor type definition | ||||
*/ | */ |
struct rspamd_multipattern *mp; | struct rspamd_multipattern *mp; | ||||
/* Align due to blake2b state */ | /* Align due to blake2b state */ | ||||
(void) !posix_memalign((void **)&mp, _Alignof (struct rspamd_multipattern), | |||||
(void) !posix_memalign((void **)&mp, RSPAMD_ALIGNOF(struct rspamd_multipattern), | |||||
sizeof (*mp)); | sizeof (*mp)); | ||||
g_assert (mp != NULL); | g_assert (mp != NULL); | ||||
memset (mp, 0, sizeof (*mp)); | memset (mp, 0, sizeof (*mp)); | ||||
struct rspamd_multipattern *mp; | struct rspamd_multipattern *mp; | ||||
/* Align due to blake2b state */ | /* Align due to blake2b state */ | ||||
(void) !posix_memalign((void **)&mp, _Alignof (struct rspamd_multipattern), sizeof (*mp)); | |||||
(void) !posix_memalign((void **)&mp, RSPAMD_ALIGNOF(struct rspamd_multipattern), sizeof (*mp)); | |||||
g_assert (mp != NULL); | g_assert (mp != NULL); | ||||
memset (mp, 0, sizeof (*mp)); | memset (mp, 0, sizeof (*mp)); | ||||
mp->flags = flags; | mp->flags = flags; |
* Check if a pointer is aligned; n must be power of two | * Check if a pointer is aligned; n must be power of two | ||||
*/ | */ | ||||
#define rspamd_is_aligned(p, n) (((uintptr_t)(p) & ((uintptr_t)(n) - 1)) == 0) | #define rspamd_is_aligned(p, n) (((uintptr_t)(p) & ((uintptr_t)(n) - 1)) == 0) | ||||
#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, _Alignof(__typeof((v)))) | |||||
#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v)))) | |||||
gboolean rspamd_str_has_8bit (const guchar *beg, gsize len); | gboolean rspamd_str_has_8bit (const guchar *beg, gsize len); | ||||
struct UConverter; | struct UConverter; |