Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - pass the alignment instead of the mask (as Roy asked a...



details:   https://anonhg.NetBSD.org/src/rev/8dd371c8589f
branches:  trunk
changeset: 952798:8dd371c8589f
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 17 22:32:04 2021 +0000

description:
- pass the alignment instead of the mask (as Roy asked and to match the
  other macro)
- use alignof to determine that alignment and CTASSERT what we expect
- remove unused macros

diffstat:

 sys/net/if_arp.h           |  5 +++--
 sys/netinet/icmp_private.h |  3 +--
 sys/netinet/igmp_var.h     |  4 +---
 sys/netinet/ip_private.h   |  5 +++--
 sys/netinet/tcp_private.h  |  5 +++--
 sys/netinet/udp_private.h  |  5 +++--
 sys/netinet6/ip6_private.h |  5 +++--
 sys/sys/mbuf.h             |  7 ++++---
 sys/sys/param.h            |  4 ++--
 9 files changed, 23 insertions(+), 20 deletions(-)

diffs (171 lines):

diff -r 1f621c64f66b -r 8dd371c8589f sys/net/if_arp.h
--- a/sys/net/if_arp.h  Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/net/if_arp.h  Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.h,v 1.41 2021/02/16 10:20:56 martin Exp $       */
+/*     $NetBSD: if_arp.h,v 1.42 2021/02/17 22:32:04 christos Exp $     */
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,7 +72,8 @@
        uint8_t  ar_tpa[];      /* target protocol address */
 #endif
 };
-#define        ARP_HDR_ALIGNMENT       1
+#define        ARP_HDR_ALIGNMENT       __alignof(struct arphdr)
+__CTASSERT(ARP_HDR_ALIGNMENT == 2);
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet/icmp_private.h
--- a/sys/netinet/icmp_private.h        Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet/icmp_private.h        Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: icmp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $        */
+/*     $NetBSD: icmp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -44,7 +44,6 @@
 
 #define        ICMP_STATINC(x)         _NET_STATINC(icmpstat_percpu, x)
 
-#define        ICMP_HDR_ALIGNMENT      3
 #endif /* _KERNEL_ */
 
 #endif /* !_NETINET_ICMP_PRIVATE_H_ */
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet/igmp_var.h
--- a/sys/netinet/igmp_var.h    Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet/igmp_var.h    Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: igmp_var.h,v 1.26 2021/02/14 20:58:35 christos Exp $   */
+/*     $NetBSD: igmp_var.h,v 1.27 2021/02/17 22:32:04 christos Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -105,8 +105,6 @@
  */
 #define        IGMP_RANDOM_DELAY(X)    (cprng_fast32() % (X) + 1)
 
-#define        IGMP_HDR_ALIGNMENT      3
-
 void   igmp_init(void);
 void   igmp_input(struct mbuf *, int, int);
 int    igmp_joingroup(struct in_multi *);
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet/ip_private.h
--- a/sys/netinet/ip_private.h  Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet/ip_private.h  Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $  */
+/*     $NetBSD: ip_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@
 #define        IP_STATINC(x)           _NET_STATINC(ipstat_percpu, x)
 #define        IP_STATDEC(x)           _NET_STATDEC(ipstat_percpu, x)
 
-#define        IP_HDR_ALIGNMENT        3
+#define        IP_HDR_ALIGNMENT        __alignof(struct ip)
+__CTASSERT(IP_HDR_ALIGNMENT == 4);
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_IP_PRIVATE_H_ */
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet/tcp_private.h
--- a/sys/netinet/tcp_private.h Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet/tcp_private.h Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/*     $NetBSD: tcp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@
 #define        TCP_STATINC(x)          _NET_STATINC(tcpstat_percpu, x)
 #define        TCP_STATADD(x, v)       _NET_STATADD(tcpstat_percpu, x, v)
 
-#define        TCP_HDR_ALIGNMENT       3
+#define        TCP_HDR_ALIGNMENT       __alignof(struct tcphdr)
+__CTASSERT(TCP_HDR_ALIGNMENT == 4);
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_TCP_PRIVATE_H_ */
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet/udp_private.h
--- a/sys/netinet/udp_private.h Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet/udp_private.h Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: udp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/*     $NetBSD: udp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -39,7 +39,8 @@
 
 #define        UDP_STATINC(x)          _NET_STATINC(udpstat_percpu, x)
 
-#define        UDP_HDR_ALIGNMENT       3
+#define        UDP_HDR_ALIGNMENT       __alignof(struct udphdr)
+__CTASSERT(UDP_HDR_ALIGNMENT == 2);
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_UDP_PRIVATE_H_ */
diff -r 1f621c64f66b -r 8dd371c8589f sys/netinet6/ip6_private.h
--- a/sys/netinet6/ip6_private.h        Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/netinet6/ip6_private.h        Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/*     $NetBSD: ip6_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@
 #define        IP6_STATINC(x)          _NET_STATINC(ip6stat_percpu, x)
 #define        IP6_STATDEC(x)          _NET_STATDEC(ip6stat_percpu, x)
 
-#define        IP6_HDR_ALIGNMENT       3
+#define        IP6_HDR_ALIGNMENT       __alignof(struct ip6_hdr)
+__CTASSERT(IP6_HDR_ALIGNMENT == 4);
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_IP6_PRIVATE_H_ */
diff -r 1f621c64f66b -r 8dd371c8589f sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/sys/mbuf.h    Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.230 2021/02/15 09:29:56 kre Exp $   */
+/*     $NetBSD: mbuf.h,v 1.231 2021/02/17 22:32:04 christos Exp $      */
 
 /*
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -846,10 +846,11 @@
 static __inline int
 m_get_aligned_hdr(struct mbuf **m, int align, size_t hlen, bool linkhdr)
 {
-       if (POINTER_ALIGNED_P(mtod(*m, void *), align) == 0)
+       if (POINTER_ALIGNED_P(mtod(*m, void *), align) == 0) {
+               --align;        // Turn into mask
                *m = m_copyup(*m, hlen, 
                      linkhdr ? (max_linkhdr + align) & ~align : 0);
-       else if (__predict_false((size_t)(*m)->m_len < hlen))
+       } else if (__predict_false((size_t)(*m)->m_len < hlen))
                *m = m_pullup(*m, hlen);
        return *m == NULL;
 }
diff -r 1f621c64f66b -r 8dd371c8589f sys/sys/param.h
--- a/sys/sys/param.h   Wed Feb 17 21:09:39 2021 +0000
+++ b/sys/sys/param.h   Wed Feb 17 22:32:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: param.h,v 1.688 2021/02/15 19:46:53 christos Exp $     */
+/*     $NetBSD: param.h,v 1.689 2021/02/17 22:32:04 christos Exp $     */
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -290,7 +290,7 @@
 #ifdef __NO_STRICT_ALIGNMENT
 #define        POINTER_ALIGNED_P(p, a)         1
 #else
-#define        POINTER_ALIGNED_P(p, a)         (((uintptr_t)(p) & (a)) == 0)
+#define        POINTER_ALIGNED_P(p, a)         (((uintptr_t)(p) & ((a) - 1)) == 0)
 #endif
 
 /*



Home | Main Index | Thread Index | Old Index