X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a263db98faf9c21d7939f6a780c3f8ab31f15d67..0f328b4aa16b0b47f05a85c440ce1d07719e3cac:/util-print.c diff --git a/util-print.c b/util-print.c index 25ea1386..13191e9c 100644 --- a/util-print.c +++ b/util-print.c @@ -53,6 +53,7 @@ #include #include "netdissect.h" +#include "extract.h" #include "ascii_strcasecmp.h" #include "timeval-operations.h" @@ -759,7 +760,7 @@ print_txt_line(netdissect_options *ndo, const char *protoname, startidx = idx; while (idx < len) { - ND_TCHECK(*(pptr+idx)); + ND_TCHECK_1(pptr + idx); if (*(pptr+idx) == '\n') { /* * LF without CR; end of line. @@ -775,7 +776,7 @@ print_txt_line(netdissect_options *ndo, const char *protoname, /* not in this packet */ return (0); } - ND_TCHECK(*(pptr+idx+1)); + ND_TCHECK_1(pptr + idx + 1); if (*(pptr+idx+1) == '\n') { /* * CR-LF; end of line. @@ -946,11 +947,38 @@ safeputchar(netdissect_options *ndo, ND_PRINT((ndo, (c < 0x80 && ND_ISPRINT(c)) ? "%c" : "\\0x%02x", c)); } -#ifdef LBL_ALIGN +#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \ + (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \ + (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \ + (defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \ + (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || \ + defined(__vax__) /* - * Some compilers try to optimize memcpy(), using the alignment constraint - * on the argument pointer type. by using this function, we try to avoid the - * optimization. + * The procesor natively handles unaligned loads, so just use memcpy() + * and memcmp(), to enable those optimizations. + * + * XXX - are those all the x86 tests we need? + * XXX - do we need to worry about ARMv1 through ARMv5, which didn't + * support unaligned loads, and, if so, do we need to worry about all + * of them, or just some of them, e.g. ARMv5? + * XXX - are those the only 68k tests we need not to generated + * unaligned accesses if the target is the 68000 or 68010? + * XXX - are there any tests we don't need, because some definitions are for + * compilers that also predefine the GCC symbols? + * XXX - do we need to test for both 32-bit and 64-bit versions of those + * architectures in all cases? + */ +#else +/* + * 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. */ void unaligned_memcpy(void *p, const void *q, size_t l)