]> The Tcpdump Group git mirrors - tcpdump/blobdiff - netdissect.h
More UNALIGNED_MEM{CPY,CMP} on IP addresses.
[tcpdump] / netdissect.h
index 0b194c95661753702e00fb94a6d1f53f529477c1..b4c24e64b7fec6597fec2e72eb2d219d167ba237 100644 (file)
@@ -270,7 +270,30 @@ extern char *copy_argv(netdissect_options *, char **);
 extern void safeputchar(int);
 extern void safeputs(const char *, int);
 
+#ifdef LBL_ALIGN
+/*
+ * The processor doesn't natively handle unaligned loads,
+ * and the compiler might "helpfully" optimize memcpy()
+ * and memcmp(), when handed pointers that would normally
+ * be properly aligned, into sequences that assume proper
+ * alignment.
+ *
+ * Do copies and compares of possibly-unaligned data by
+ * calling routines that wrap memcpy() and memcmp(), to
+ * prevent that optimization.
+ */
 extern void unaligned_memcpy(void *, const void *, size_t);
+extern int unaligned_memcmp(const void *, const void *, size_t);
+#define UNALIGNED_MEMCPY(p, q, l)      unaligned_memcpy((p), (q), (l))
+#define UNALIGNED_MEMCMP(p, q, l)      unaligned_memcmp((p), (q), (l))
+#else
+/*
+ * The procesor natively handles unaligned loads, so just use memcpy()
+ * and memcmp(), to enable those optimizations.
+ */
+#define UNALIGNED_MEMCPY(p, q, l)      memcpy((p), (q), (l))
+#define UNALIGNED_MEMCMP(p, q, l)      memcmp((p), (q), (l))
+#endif
 
 #define PLURAL_SUFFIX(n) \
        (((n) != 1) ? "s" : "")