From 6ceac089b6a8fee5aef14307b0561e98202947c5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 15 Oct 2015 11:28:41 +0100 Subject: [PATCH] Fix some portability issues. --- config.h.in | 16 +++++++++++++++- contrib/libottery/ottery-internal.h | 6 +++--- src/libcryptobox/cryptobox.c | 16 ++++------------ src/libutil/regexp.c | 5 ++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/config.h.in b/config.h.in index 04e6416ae..93721f82e 100644 --- a/config.h.in +++ b/config.h.in @@ -102,6 +102,18 @@ #endif +#ifndef RSPAMD_ALIGNED +#if defined(_MSC_VER) +# define RSPAMD_ALIGNED(x) __declspec(align(x)) +#elif defined(__GNUC__) +# define RSPAMD_ALIGNED(x) __attribute__((aligned(x))) +#else +# define RSPAMD_ALIGNED(x) +#endif +#endif + + + #cmakedefine HAVE_SYS_QUEUE_H 1 #cmakedefine HAVE_SYS_MMAN_H 1 #cmakedefine HAVE_SYS_SOCKET_H 1 @@ -339,7 +351,9 @@ typedef off_t goffset; #ifndef PARAM_H_HAS_BITSET /* Bit map related macros. */ -#define NBBY 8 /* number of bits in a byte */ +#ifndef NBBY +# define NBBY 8 /* number of bits in a byte */ +#endif #define setbit(a, \ i) (((unsigned char *)(a))[(i) / NBBY] |= 1 << ((i) % NBBY)) #define clrbit(a, \ diff --git a/contrib/libottery/ottery-internal.h b/contrib/libottery/ottery-internal.h index 2d8a03185..7e3f46e05 100644 --- a/contrib/libottery/ottery-internal.h +++ b/contrib/libottery/ottery-internal.h @@ -196,16 +196,16 @@ struct ottery_config { #define ottery_state_nolock ottery_state -struct __attribute__((aligned(16))) ottery_state { +struct RSPAMD_ALIGNED(16) ottery_state { /** * Holds up to prf.output_len bytes that have been generated by the * pseudorandom function. */ - __attribute__ ((aligned (16))) uint8_t buffer[MAX_OUTPUT_LEN]; + uint8_t buffer[MAX_OUTPUT_LEN] RSPAMD_ALIGNED(16); /** * Holds the state information (typically nonces and keys) used by the * pseudorandom function. */ - __attribute__ ((aligned (16))) uint8_t state[MAX_STATE_LEN]; + uint8_t state[MAX_STATE_LEN] RSPAMD_ALIGNED(16); /** * Parameters and function pointers for the cryptographic pseudorandom * function that we're using. */ diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index 3169c01a0..0923905d7 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -27,6 +27,7 @@ #include #endif +#include "config.h" #include "cryptobox.h" #include "platform_config.h" #include "chacha20/chacha.h" @@ -39,15 +40,6 @@ #include #endif - -#ifndef ALIGNED -#if defined(_MSC_VER) -# define ALIGNED(x) __declspec(align(x)) -#else -# define ALIGNED(x) __attribute__((aligned(x))) -#endif -#endif - unsigned long cpu_config = 0; static const guchar n0[16] = {0}; @@ -174,7 +166,7 @@ void rspamd_cryptobox_encrypt_nm_inplace (guchar *data, gsize len, const rspamd_nm_t nm, rspamd_sig_t sig) { poly1305_state mac_ctx; - guchar ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; + guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; chacha_state s; gsize r; @@ -215,7 +207,7 @@ void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segm const rspamd_nm_t nm, rspamd_sig_t sig) { struct rspamd_cryptobox_segment *cur = segments, *start_seg = segments; - guchar ALIGNED(32) subkey[CHACHA_BLOCKBYTES], + guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES], outbuf[CHACHA_BLOCKBYTES * 16]; poly1305_state mac_ctx; guchar *out, *in; @@ -308,7 +300,7 @@ rspamd_cryptobox_decrypt_nm_inplace (guchar *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, const rspamd_sig_t sig) { poly1305_state mac_ctx; - guchar ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; + guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; rspamd_sig_t mac; chacha_state s; gsize r; diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index f713ca2f7..7ef3f178b 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -664,9 +664,12 @@ rspamd_regexp_library_init (void) rc = pcre_config (PCRE_CONFIG_JIT, &jit); if (rc == 0 && jit == 1) { +#ifdef PCRE_CONFIG_JITTARGET pcre_config (PCRE_CONFIG_JITTARGET, &str); - msg_info ("pcre is compiled with JIT for %s", str); +#else + msg_info ("pcre is compiled with JIT for unknown target"); +#endif can_jit = TRUE; } -- 2.39.5