Module Name: src Committed By: maxv Date: Sat Dec 22 13:55:56 UTC 2018
Modified Files: src/sys/kern: uipc_mbuf.c src/sys/net80211: ieee80211_netbsd.c ieee80211_netbsd.h src/sys/sys: mbuf.h Log Message: Move m_align() back into the kernel, and switch M_ALIGN and MH_ALIGN to it. Forcing a distinction between M_ALIGN and MH_ALIGN is too bug-friendly and serves no particular purpose. To generate a diff of this commit: cvs rdiff -u -r1.226 -r1.227 src/sys/kern/uipc_mbuf.c cvs rdiff -u -r1.32 -r1.33 src/sys/net80211/ieee80211_netbsd.c cvs rdiff -u -r1.21 -r1.22 src/sys/net80211/ieee80211_netbsd.h cvs rdiff -u -r1.215 -r1.216 src/sys/sys/mbuf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/uipc_mbuf.c diff -u src/sys/kern/uipc_mbuf.c:1.226 src/sys/kern/uipc_mbuf.c:1.227 --- src/sys/kern/uipc_mbuf.c:1.226 Sat Dec 22 13:11:37 2018 +++ src/sys/kern/uipc_mbuf.c Sat Dec 22 13:55:56 2018 @@ -1,12 +1,12 @@ -/* $NetBSD: uipc_mbuf.c,v 1.226 2018/12/22 13:11:37 maxv Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.227 2018/12/22 13:55:56 maxv Exp $ */ /* - * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. + * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. + * NASA Ames Research Center, and Maxime Villard. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.226 2018/12/22 13:11:37 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.227 2018/12/22 13:55:56 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" @@ -1754,6 +1754,30 @@ m_move_pkthdr(struct mbuf *to, struct mb } /* + * Set the m_data pointer of a newly-allocated mbuf to place an object of the + * specified size at the end of the mbuf, longword aligned. + */ +void +m_align(struct mbuf *m, int len) +{ + int buflen, adjust; + + KASSERT(len != M_COPYALL); + KASSERT(M_LEADINGSPACE(m) == 0); + + if (m->m_flags & M_EXT) + buflen = m->m_ext.ext_size; + else if (m->m_flags & M_PKTHDR) + buflen = MHLEN; + else + buflen = MLEN; + + KASSERT(len <= buflen); + adjust = buflen - len; + m->m_data += adjust &~ (sizeof(long)-1); +} + +/* * Apply function f to the data in an mbuf chain starting "off" bytes from the * beginning, continuing for "len" bytes. */ Index: src/sys/net80211/ieee80211_netbsd.c diff -u src/sys/net80211/ieee80211_netbsd.c:1.32 src/sys/net80211/ieee80211_netbsd.c:1.33 --- src/sys/net80211/ieee80211_netbsd.c:1.32 Mon Sep 3 16:29:36 2018 +++ src/sys/net80211/ieee80211_netbsd.c Sat Dec 22 13:55:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ieee80211_netbsd.c,v 1.32 2018/09/03 16:29:36 riastradh Exp $ */ +/* $NetBSD: ieee80211_netbsd.c,v 1.33 2018/12/22 13:55:56 maxv Exp $ */ /* * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting @@ -31,7 +31,7 @@ #ifdef __FreeBSD__ __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_freebsd.c,v 1.8 2005/08/08 18:46:35 sam Exp $"); #else -__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.32 2018/09/03 16:29:36 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.33 2018/12/22 13:55:56 maxv Exp $"); #endif /* @@ -724,27 +724,6 @@ ieee80211_load_module(const char *modnam /* -------------------------------------------------------------------------- */ /* - * Set the m_data pointer of a newly-allocated mbuf - * to place an object of the specified size at the - * end of the mbuf, longword aligned. - */ -void -m_align(struct mbuf *m, int len) -{ - int adjust; - - KASSERT(len != M_COPYALL); - - if (m->m_flags & M_EXT) - adjust = m->m_ext.ext_size - len; - else if (m->m_flags & M_PKTHDR) - adjust = MHLEN - len; - else - adjust = MLEN - len; - m->m_data += adjust &~ (sizeof(long)-1); -} - -/* * Append the specified data to the indicated mbuf chain, * Extend the mbuf chain if the new data does not fit in * existing space. Index: src/sys/net80211/ieee80211_netbsd.h diff -u src/sys/net80211/ieee80211_netbsd.h:1.21 src/sys/net80211/ieee80211_netbsd.h:1.22 --- src/sys/net80211/ieee80211_netbsd.h:1.21 Thu May 3 17:14:37 2018 +++ src/sys/net80211/ieee80211_netbsd.h Sat Dec 22 13:55:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ieee80211_netbsd.h,v 1.21 2018/05/03 17:14:37 maxv Exp $ */ +/* $NetBSD: ieee80211_netbsd.h,v 1.22 2018/12/22 13:55:56 maxv Exp $ */ /*- * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting * All rights reserved. @@ -248,7 +248,6 @@ void ieee80211_init(void); static void name(void) #endif -void m_align(struct mbuf *, int); int m_append(struct mbuf *, int, const void *); #endif /* !_NET80211_IEEE80211_NETBSD_H_ */ Index: src/sys/sys/mbuf.h diff -u src/sys/sys/mbuf.h:1.215 src/sys/sys/mbuf.h:1.216 --- src/sys/sys/mbuf.h:1.215 Thu Nov 15 11:18:33 2018 +++ src/sys/sys/mbuf.h Sat Dec 22 13:55:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mbuf.h,v 1.215 2018/11/15 11:18:33 maxv Exp $ */ +/* $NetBSD: mbuf.h,v 1.216 2018/12/22 13:55:56 maxv Exp $ */ /* * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc. @@ -517,28 +517,8 @@ do { \ #define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from) #define M_MOVE_PKTHDR(to, from) m_move_pkthdr(to, from) -/* - * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place - * an object of the specified size at the end of the mbuf, longword aligned. - */ -#define M_ALIGN(m, len) \ -do { \ - KASSERT(((m)->m_flags & (M_PKTHDR|M_EXT)) == 0); \ - KASSERT(M_LEADINGSPACE(m) == 0); \ - (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1); \ -} while (/* CONSTCOND */ 0) - -/* - * As above, for mbufs allocated with m_gethdr/MGETHDR - * or initialized by M_COPY_PKTHDR. - */ -#define MH_ALIGN(m, len) \ -do { \ - KASSERT(((m)->m_flags & M_PKTHDR) != 0); \ - KASSERT(((m)->m_flags & M_EXT) == 0); \ - KASSERT(M_LEADINGSPACE(m) == 0); \ - (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1); \ -} while (/* CONSTCOND */ 0) +#define M_ALIGN(m, len) m_align(m, len) +#define MH_ALIGN(m, len) m_align(m, len) /* * Determine if an mbuf's data area is read-only. This is true @@ -801,6 +781,7 @@ void mbinit(void); void m_remove_pkthdr(struct mbuf *); void m_copy_pkthdr(struct mbuf *, struct mbuf *); void m_move_pkthdr(struct mbuf *, struct mbuf *); +void m_align(struct mbuf *, int); bool m_ensure_contig(struct mbuf **, int); struct mbuf *m_add(struct mbuf *, struct mbuf *);