Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)
In article <YCxJ044lGyfLpKuP%pony.stderr.spb.ru@localhost>,
Valery Ushakov <uwe%stderr.spb.ru@localhost> wrote:
>But to get back to my main point, PLEASE, can we stop making random
>aimless changes without prior discussion?
Here's the change I'd like to make:
- 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
This incrementally improves things.
christos
Index: net/if_arp.h
===================================================================
RCS file: /cvsroot/src/sys/net/if_arp.h,v
retrieving revision 1.41
diff -u -p -u -r1.41 if_arp.h
--- net/if_arp.h 16 Feb 2021 10:20:56 -0000 1.41
+++ net/if_arp.h 17 Feb 2021 17:45:55 -0000
@@ -72,7 +72,8 @@ struct arphdr {
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)
Index: netinet/icmp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/icmp_private.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 icmp_private.h
--- netinet/icmp_private.h 14 Feb 2021 20:58:35 -0000 1.4
+++ netinet/icmp_private.h 17 Feb 2021 17:45:55 -0000
@@ -44,7 +44,6 @@ extern percpu_t *icmpstat_percpu;
#define ICMP_STATINC(x) _NET_STATINC(icmpstat_percpu, x)
-#define ICMP_HDR_ALIGNMENT 3
#endif /* _KERNEL_ */
#endif /* !_NETINET_ICMP_PRIVATE_H_ */
Index: netinet/igmp_var.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/igmp_var.h,v
retrieving revision 1.26
diff -u -p -u -r1.26 igmp_var.h
--- netinet/igmp_var.h 14 Feb 2021 20:58:35 -0000 1.26
+++ netinet/igmp_var.h 17 Feb 2021 17:45:55 -0000
@@ -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 *);
Index: netinet/ip_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_private.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 ip_private.h
--- netinet/ip_private.h 14 Feb 2021 20:58:35 -0000 1.4
+++ netinet/ip_private.h 17 Feb 2021 17:45:55 -0000
@@ -43,7 +43,8 @@ extern percpu_t *ipstat_percpu;
#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_ */
Index: netinet/tcp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/tcp_private.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 tcp_private.h
--- netinet/tcp_private.h 14 Feb 2021 20:58:35 -0000 1.4
+++ netinet/tcp_private.h 17 Feb 2021 17:45:55 -0000
@@ -43,7 +43,8 @@ extern percpu_t *tcpstat_percpu;
#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_ */
Index: netinet/udp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/udp_private.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 udp_private.h
--- netinet/udp_private.h 14 Feb 2021 20:58:35 -0000 1.4
+++ netinet/udp_private.h 17 Feb 2021 17:45:55 -0000
@@ -39,7 +39,8 @@ extern percpu_t *udpstat_percpu;
#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_ */
Index: netinet6/ip6_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_private.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 ip6_private.h
--- netinet6/ip6_private.h 14 Feb 2021 20:58:35 -0000 1.4
+++ netinet6/ip6_private.h 17 Feb 2021 17:45:55 -0000
@@ -43,7 +43,8 @@ extern percpu_t *ip6stat_percpu;
#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_ */
Index: sys/mbuf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mbuf.h,v
retrieving revision 1.230
diff -u -p -u -r1.230 mbuf.h
--- sys/mbuf.h 15 Feb 2021 09:29:56 -0000 1.230
+++ sys/mbuf.h 17 Feb 2021 17:45:55 -0000
@@ -846,10 +846,11 @@ m_copy_rcvif(struct mbuf *m, const struc
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;
}
Index: sys/param.h
===================================================================
RCS file: /cvsroot/src/sys/sys/param.h,v
retrieving revision 1.688
diff -u -p -u -r1.688 param.h
--- sys/param.h 15 Feb 2021 19:46:53 -0000 1.688
+++ sys/param.h 17 Feb 2021 17:45:55 -0000
@@ -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