summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authormartin <martin@NetBSD.org>2019-12-08 13:23:23 +0000
committermartin <martin@NetBSD.org>2019-12-08 13:23:23 +0000
commita58413f29ff634e939ff5f5d09e6b75ebbc99bab (patch)
tree15579322973fac5abfabbb9d61089d6c5c65a393 /common
parentc6f2b63e994fd064df715239eff48d27ea90549c (diff)
Pull up following revision(s) (requested by riastradh in ticket #505):
common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.7 common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.8 sys/sys/param.h: revision 1.610 sys/arch/amd64/include/param.h: revision 1.31 sys/arch/i386/include/param.h: revision 1.85 New macro ALIGNED_POINTER_LOAD. To be used with ALIGNED_POINTER(p,t) instead of writing *(const t *)p directly. This way, on machines without strict alignment, we can use memcpy to pacify sanitizers, while getting the same compiled code in the end with a single (say) MOV instruction. Fix byte order bug in murmurhash and pacify sanitizers. add now required includes for memcpy prototypes analogue to other hash functions (fix the build)
Diffstat (limited to 'common')
-rw-r--r--common/lib/libc/hash/murmurhash/murmurhash.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/common/lib/libc/hash/murmurhash/murmurhash.c b/common/lib/libc/hash/murmurhash/murmurhash.c
index e4a987ce7f8..b2672666ee3 100644
--- a/common/lib/libc/hash/murmurhash/murmurhash.c
+++ b/common/lib/libc/hash/murmurhash/murmurhash.c
@@ -1,4 +1,4 @@
-/* $NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $ */
+/* $NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $ */
/*
* MurmurHash2 -- from the original code:
@@ -14,15 +14,19 @@
#include <sys/cdefs.h>
#if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $");
+
+#include <lib/libkern/libkern.h>
#else
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $");
+__RCSID("$NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
+#include <string.h>
+
#endif
#include <sys/types.h>
@@ -51,7 +55,10 @@ murmurhash2(const void *key, size_t len, uint32_t seed)
if (__predict_true(ALIGNED_POINTER(key, uint32_t))) {
while (len >= sizeof(uint32_t)) {
- uint32_t k = *(const uint32_t *)data;
+ uint32_t k;
+
+ ALIGNED_POINTER_LOAD(&k, data, uint32_t);
+ k = htole32(k);
k *= m;
k ^= k >> r;