summaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/support')
-rw-r--r--src/support/crypto.c11
-rw-r--r--src/support/global.c36
-rw-r--r--src/support/hash_city.c52
-rw-r--r--src/support/hash_fnv.c1
4 files changed, 80 insertions, 20 deletions
diff --git a/src/support/crypto.c b/src/support/crypto.c
index 1049621fb44..ab94ec2c829 100644
--- a/src/support/crypto.c
+++ b/src/support/crypto.c
@@ -21,8 +21,12 @@ __wt_decrypt(WT_SESSION_IMPL *session,
uint32_t encrypt_len;
uint8_t *dst, *src;
- encrypt_len = WT_STORE_SIZE(*((uint32_t *)
- ((uint8_t *)in->data + skip)));
+ encrypt_len =
+ WT_STORE_SIZE(*((uint32_t *)((uint8_t *)in->data + skip)));
+#ifdef WORDS_BIGENDIAN
+ encrypt_len = __wt_bswap32(encrypt_len);
+#endif
+
if (encrypt_len > in->size)
WT_RET_MSG(session, WT_ERROR,
"corrupted encrypted item: padded size less than "
@@ -104,6 +108,9 @@ __wt_encrypt(WT_SESSION_IMPL *session,
* decryption side.
*/
*unpadded_lenp = WT_STORE_SIZE(result_len);
+#ifdef WORDS_BIGENDIAN
+ *unpadded_lenp = __wt_bswap32(*unpadded_lenp);
+#endif
/*
* Copy in the skipped header bytes, set the final data size.
*/
diff --git a/src/support/global.c b/src/support/global.c
index 0234455b6ce..e0d5bafeaa8 100644
--- a/src/support/global.c
+++ b/src/support/global.c
@@ -12,6 +12,35 @@ WT_PROCESS __wt_process; /* Per-process structure */
static int __wt_pthread_once_failed; /* If initialization failed */
/*
+ * __wt_endian_check --
+ * Check the build matches the machine.
+ */
+static int
+__wt_endian_check(void)
+{
+ uint64_t v;
+ bool big;
+ const char *e;
+
+ v = 1;
+ big = *((uint8_t *)&v) == 0;
+
+#ifdef WORDS_BIGENDIAN
+ if (big)
+ return (0);
+ e = "big-endian";
+#else
+ if (!big)
+ return (0);
+ e = "little-endian";
+#endif
+ fprintf(stderr,
+ "This is a %s build of the WiredTiger data engine, incompatible "
+ "with this system\n", e);
+ return (EINVAL);
+}
+
+/*
* __wt_global_once --
* Global initialization, run once.
*/
@@ -31,10 +60,6 @@ __wt_global_once(void)
TAILQ_INIT(&__wt_process.connqh);
#ifdef HAVE_DIAGNOSTIC
- /* Verify the pre-computed metadata hash. */
- WT_ASSERT(NULL, WT_METAFILE_NAME_HASH ==
- __wt_hash_city64(WT_METAFILE_URI, strlen(WT_METAFILE_URI)));
-
/* Load debugging code the compiler might optimize out. */
(void)__wt_breakpoint();
#endif
@@ -50,6 +75,9 @@ __wt_library_init(void)
static bool first = true;
WT_DECL_RET;
+ /* Check the build matches the machine. */
+ WT_RET(__wt_endian_check());
+
/*
* Do per-process initialization once, before anything else, but only
* once. I don't know how heavy-weight the function (pthread_once, in
diff --git a/src/support/hash_city.c b/src/support/hash_city.c
index 5780cd7b459..7a700aa809c 100644
--- a/src/support/hash_city.c
+++ b/src/support/hash_city.c
@@ -57,7 +57,6 @@
* compromising on hash quality.
*/
-#include <string.h>
#include "wt_internal.h"
/*
@@ -86,33 +85,60 @@ static uint32_t UNALIGNED_LOAD32(const char *p) {
return (result);
}
-#if !defined(WORDS_BIGENDIAN)
+#ifdef _MSC_VER
-#define uint32_in_expected_order(x) (x)
-#define uint64_in_expected_order(x) (x)
+#include <stdlib.h>
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
-#else
+#elif defined(__APPLE__)
-#ifdef __APPLE__
-/* Mac OS X / Darwin features */
+// Mac OS X / Darwin features
#include <libkern/OSByteOrder.h>
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
-#elif defined(__sun)
+#elif defined(__sun) || defined(sun)
#include <sys/byteorder.h>
-#define bswap_32 BSWAP_32
-#define bswap_64 BSWAP_64
+#define bswap_32(x) BSWAP_32(x)
+#define bswap_64(x) BSWAP_64(x)
+
+#elif defined(__FreeBSD__)
+
+#include <sys/endian.h>
+#define bswap_32(x) bswap32(x)
+#define bswap_64(x) bswap64(x)
+
+#elif defined(__OpenBSD__)
+
+#include <sys/types.h>
+#define bswap_32(x) swap32(x)
+#define bswap_64(x) swap64(x)
+
+#elif defined(__NetBSD__)
+
+#include <sys/types.h>
+#include <machine/bswap.h>
+#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
+#define bswap_32(x) bswap32(x)
+#define bswap_64(x) bswap64(x)
+#endif
#else
-#include <byteswap.h>
+
+#define bswap_32(x) __wt_bswap32(x)
+#define bswap_64(x) __wt_bswap64(x)
+
#endif
+#ifdef WORDS_BIGENDIAN
#define uint32_in_expected_order(x) (bswap_32(x))
#define uint64_in_expected_order(x) (bswap_64(x))
-
-#endif /* WORDS_BIGENDIAN */
+#else
+#define uint32_in_expected_order(x) (x)
+#define uint64_in_expected_order(x) (x)
+#endif
static uint64_t Fetch64(const char *p) {
return uint64_in_expected_order(UNALIGNED_LOAD64(p));
diff --git a/src/support/hash_fnv.c b/src/support/hash_fnv.c
index 35e7e5f3a73..83dd2574099 100644
--- a/src/support/hash_fnv.c
+++ b/src/support/hash_fnv.c
@@ -83,7 +83,6 @@
* Share and Enjoy! :-)
*/
-#include <stdlib.h>
#include "wt_internal.h"
/*