Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - Make ALIGNED_POINTER use __alignof(t) instead of sizeo...
details: https://anonhg.NetBSD.org/src/rev/06e172855ab8
branches: trunk
changeset: 952831:06e172855ab8
user: christos <christos%NetBSD.org@localhost>
date: Fri Feb 19 14:51:59 2021 +0000
description:
- Make ALIGNED_POINTER use __alignof(t) instead of sizeof(t). This is more
correct because it works with non-primitive types and provides the ABI
alignment for the type the compiler will use.
- Remove all the *_HDR_ALIGNMENT macros and asserts
- Replace POINTER_ALIGNED_P with ACCESSIBLE_POINTER which is identical to
ALIGNED_POINTER, but returns that the pointer is always aligned if the
CPU supports unaligned accesses.
[ as proposed in tech-kern ]
diffstat:
sys/net/if_arp.h | 4 +---
sys/net/if_bridge.c | 8 ++++----
sys/netinet/if_arp.c | 8 ++++----
sys/netinet/in_l2tp.c | 7 +++----
sys/netinet/ip_flow.c | 8 ++++----
sys/netinet/ip_input.c | 6 +++---
sys/netinet/ip_private.h | 4 +---
sys/netinet/tcp_input.c | 10 +++++-----
sys/netinet/tcp_private.h | 4 +---
sys/netinet/udp_private.h | 4 +---
sys/netinet/udp_usrreq.c | 8 ++++----
sys/netinet6/icmp6.c | 8 ++++----
sys/netinet6/in6_l2tp.c | 7 +++----
sys/netinet6/ip6_flow.c | 6 +++---
sys/netinet6/ip6_input.c | 12 ++++++------
sys/netinet6/ip6_private.h | 4 +---
sys/netinet6/udp6_usrreq.c | 8 ++++----
sys/sys/mbuf.h | 18 ++++++++++++------
sys/sys/param.h | 16 ++++++++++++----
19 files changed, 76 insertions(+), 74 deletions(-)
diffs (truncated from 588 to 300 lines):
diff -r 16bc916f2066 -r 06e172855ab8 sys/net/if_arp.h
--- a/sys/net/if_arp.h Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/net/if_arp.h Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_arp.h,v 1.42 2021/02/17 22:32:04 christos Exp $ */
+/* $NetBSD: if_arp.h,v 1.43 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (c) 1986, 1993
@@ -72,8 +72,6 @@
uint8_t ar_tpa[]; /* target protocol address */
#endif
};
-#define ARP_HDR_ALIGNMENT __alignof(struct arphdr)
-__CTASSERT(ARP_HDR_ALIGNMENT == 2);
static __inline uint8_t *
ar_data(struct arphdr *ap)
diff -r 16bc916f2066 -r 06e172855ab8 sys/net/if_bridge.c
--- a/sys/net/if_bridge.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/net/if_bridge.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $ */
+/* $NetBSD: if_bridge.c,v 1.179 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.179 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -2806,7 +2806,7 @@
if (*mp == NULL)
return -1;
- if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(*ip), true) != 0) {
+ if (M_GET_ALIGNED_HDR(&m, struct ip, true) != 0) {
/* XXXJRT new stat, please */
ip_statinc(IP_STAT_TOOSMALL);
goto bad;
@@ -2900,7 +2900,7 @@
* it. Otherwise, if it is aligned, make sure the entire base
* IPv6 header is in the first mbuf of the chain.
*/
- if (m_get_aligned_hdr(&m, IP6_HDR_ALIGNMENT, sizeof(*ip6), true) != 0) {
+ if (M_GET_ALIGNED_HDR(&m, struct ip6_hdr, true) != 0) {
struct ifnet *inifp = m_get_rcvif_NOMPSAFE(m);
/* XXXJRT new stat, please */
ip6_statinc(IP6_STAT_TOOSMALL);
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/if_arp.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $ */
+/* $NetBSD: if_arp.c,v 1.307 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.307 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -706,7 +706,7 @@
goto badlen;
}
ar = mtod(m, struct arphdr *);
- KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
+ KASSERT(ACCESSIBLE_POINTER(ar, struct arphdr));
rcvif = m_get_rcvif(m, &s);
if (__predict_false(rcvif == NULL)) {
@@ -735,7 +735,7 @@
if ((m = m_pullup(m, arplen)) == NULL)
goto badlen;
ar = mtod(m, struct arphdr *);
- KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
+ KASSERT(ACCESSIBLE_POINTER(ar, struct arphdr));
}
switch (ntohs(ar->ar_pro)) {
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/in_l2tp.c
--- a/sys/netinet/in_l2tp.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/in_l2tp.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_l2tp.c,v 1.19 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: in_l2tp.c,v 1.20 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.19 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.20 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_l2tp.h"
@@ -197,8 +197,7 @@
error = ENOBUFS;
goto out;
}
- if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(iphdr), false) != 0)
- {
+ if (M_GET_ALIGNED_HDR(&m, struct ip, false) != 0) {
error = ENOBUFS;
goto out;
}
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/ip_flow.c
--- a/sys/netinet/ip_flow.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/ip_flow.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $ */
+/* $NetBSD: ip_flow.c,v 1.85 2021/02/19 14:51:59 christos Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.85 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -231,7 +231,7 @@
* IP header with no option and valid version and length
*/
ip = mtod(m, struct ip *);
- if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT)) {
+ if (!ACCESSIBLE_POINTER(ip, struct ip)) {
memcpy(&ip_store, mtod(m, const void *), sizeof(ip_store));
ip = &ip_store;
}
@@ -313,7 +313,7 @@
*
* XXX Use m_copyback_cow(9) here? --dyoung
*/
- if (!POINTER_ALIGNED_P(mtod(m, void *), IP_HDR_ALIGNMENT))
+ if (!ACCESSIBLE_POINTER(mtod(m, void *), struct ip))
memcpy(mtod(m, void *), &ip_store, sizeof(ip_store));
/*
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/ip_input.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_input.c,v 1.398 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: ip_input.c,v 1.399 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.398 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.399 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -454,7 +454,7 @@
* it. Otherwise, if it is aligned, make sure the entire
* base IP header is in the first mbuf of the chain.
*/
- if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(*ip), true) != 0) {
+ if (M_GET_ALIGNED_HDR(&m, struct ip, true) != 0) {
/* XXXJRT new stat, please */
IP_STATINC(IP_STAT_TOOSMALL);
goto out;
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/ip_private.h
--- a/sys/netinet/ip_private.h Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/ip_private.h Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
+/* $NetBSD: ip_private.h,v 1.6 2021/02/19 14:51:59 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,8 +43,6 @@
#define IP_STATINC(x) _NET_STATINC(ipstat_percpu, x)
#define IP_STATDEC(x) _NET_STATDEC(ipstat_percpu, x)
-#define IP_HDR_ALIGNMENT __alignof(struct ip)
-__CTASSERT(IP_HDR_ALIGNMENT == 4);
#endif /* _KERNEL */
#endif /* !_NETINET_IP_PRIVATE_H_ */
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/tcp_input.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_input.c,v 1.425 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: tcp_input.c,v 1.426 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.425 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.426 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -1274,7 +1274,7 @@
* Enforce alignment requirements that are violated in
* some cases, see kern/50766 for details.
*/
- if (POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT) == 0) {
+ if (ACCESSIBLE_POINTER(th, struct tcp_hdr) == 0) {
m = m_copyup(m, off + sizeof(struct tcphdr), 0);
if (m == NULL) {
TCP_STATINC(TCP_STAT_RCVSHORT);
@@ -1282,7 +1282,7 @@
}
th = (struct tcphdr *)(mtod(m, char *) + off);
}
- KASSERT(POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT));
+ KASSERT(ACCESSIBLE_POINTER(th, struct tcp_hdr));
/*
* Get IP and TCP header.
@@ -1362,7 +1362,7 @@
TCP_STATINC(TCP_STAT_RCVSHORT);
return;
}
- KASSERT(POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT));
+ KASSERT(ACCESSIBLE_POINTER(th, struct tcp_hdr));
optlen = thlen - sizeof(struct tcphdr);
optp = ((u_int8_t *)th) + sizeof(struct tcphdr);
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/tcp_private.h
--- a/sys/netinet/tcp_private.h Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/tcp_private.h Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
+/* $NetBSD: tcp_private.h,v 1.6 2021/02/19 14:51:59 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,8 +43,6 @@
#define TCP_STATINC(x) _NET_STATINC(tcpstat_percpu, x)
#define TCP_STATADD(x, v) _NET_STATADD(tcpstat_percpu, x, v)
-#define TCP_HDR_ALIGNMENT __alignof(struct tcphdr)
-__CTASSERT(TCP_HDR_ALIGNMENT == 4);
#endif /* _KERNEL */
#endif /* !_NETINET_TCP_PRIVATE_H_ */
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/udp_private.h
--- a/sys/netinet/udp_private.h Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/udp_private.h Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
+/* $NetBSD: udp_private.h,v 1.6 2021/02/19 14:51:59 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -39,8 +39,6 @@
#define UDP_STATINC(x) _NET_STATINC(udpstat_percpu, x)
-#define UDP_HDR_ALIGNMENT __alignof(struct udphdr)
-__CTASSERT(UDP_HDR_ALIGNMENT == 2);
#endif /* _KERNEL */
#endif /* !_NETINET_UDP_PRIVATE_H_ */
diff -r 16bc916f2066 -r 06e172855ab8 sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c Fri Feb 19 14:44:29 2021 +0000
+++ b/sys/netinet/udp_usrreq.c Fri Feb 19 14:51:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_usrreq.c,v 1.260 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.261 2021/02/19 14:51:59 christos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.260 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.261 2021/02/19 14:51:59 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -335,7 +335,7 @@
* Enforce alignment requirements that are violated in
Home |
Main Index |
Thread Index |
Old Index