Deleted Added
full compact
mbuf.h (276136) mbuf.h (276692)
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 14 unchanged lines hidden (view full) ---

23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 14 unchanged lines hidden (view full) ---

23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
31 * $FreeBSD: head/sys/sys/mbuf.h 276136 2014-12-23 12:26:35Z glebius $
31 * $FreeBSD: head/sys/sys/mbuf.h 276692 2015-01-05 09:58:32Z rwatson $
32 */
33
34#ifndef _SYS_MBUF_H_
35#define _SYS_MBUF_H_
36
37/* XXX: These includes suck. Sorry! */
38#include <sys/queue.h>
39#ifdef _KERNEL

--- 765 unchanged lines hidden (view full) ---

805 *
806 * XXX: Broken at the moment. Need some UMA magic to make it work again.
807 */
808#define M_ASSERTVALID(m) \
809 KASSERT((((struct mbuf *)m)->m_flags & 0) == 0, \
810 ("%s: attempted use of a free mbuf!", __func__))
811
812/*
32 */
33
34#ifndef _SYS_MBUF_H_
35#define _SYS_MBUF_H_
36
37/* XXX: These includes suck. Sorry! */
38#include <sys/queue.h>
39#ifdef _KERNEL

--- 765 unchanged lines hidden (view full) ---

805 *
806 * XXX: Broken at the moment. Need some UMA magic to make it work again.
807 */
808#define M_ASSERTVALID(m) \
809 KASSERT((((struct mbuf *)m)->m_flags & 0) == 0, \
810 ("%s: attempted use of a free mbuf!", __func__))
811
812/*
813 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place an
814 * object of the specified size at the end of the mbuf, longword aligned.
815 */
816#define M_ALIGN(m, len) do { \
817 KASSERT(!((m)->m_flags & (M_PKTHDR|M_EXT)), \
818 ("%s: M_ALIGN not normal mbuf", __func__)); \
819 KASSERT((m)->m_data == (m)->m_dat, \
820 ("%s: M_ALIGN not a virgin mbuf", __func__)); \
821 (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \
822} while (0)
823
824/*
825 * As above, for mbufs allocated with m_gethdr/MGETHDR or initialized by
826 * M_DUP/MOVE_PKTHDR.
827 */
828#define MH_ALIGN(m, len) do { \
829 KASSERT((m)->m_flags & M_PKTHDR && !((m)->m_flags & M_EXT), \
830 ("%s: MH_ALIGN not PKTHDR mbuf", __func__)); \
831 KASSERT((m)->m_data == (m)->m_pktdat, \
832 ("%s: MH_ALIGN not a virgin mbuf", __func__)); \
833 (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
834} while (0)
835
836/*
837 * As above, for mbuf with external storage.
838 */
839#define MEXT_ALIGN(m, len) do { \
840 KASSERT((m)->m_flags & M_EXT, \
841 ("%s: MEXT_ALIGN not an M_EXT mbuf", __func__)); \
842 KASSERT((m)->m_data == (m)->m_ext.ext_buf, \
843 ("%s: MEXT_ALIGN not a virgin mbuf", __func__)); \
844 (m)->m_data += ((m)->m_ext.ext_size - (len)) & \
845 ~(sizeof(long) - 1); \
846} while (0)
847
848/*
849 * Return the address of the start of the buffer associated with an mbuf,
850 * handling external storage, packet-header mbufs, and regular data mbufs.
851 */
852#define M_START(m) \
853 (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_buf : \
854 ((m)->m_flags & M_PKTHDR) ? &(m)->m_pktdat[0] : \
855 &(m)->m_dat[0])
856
857/*
858 * Return the size of the buffer associated with an mbuf, handling external
859 * storage, packet-header mbufs, and regular data mbufs.
860 */
861#define M_SIZE(m) \
862 (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \
863 ((m)->m_flags & M_PKTHDR) ? MHLEN : \
864 MLEN)
865
866/*
813 * Return the address of the start of the buffer associated with an mbuf,
814 * handling external storage, packet-header mbufs, and regular data mbufs.
815 */
816#define M_START(m) \
817 (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_buf : \
818 ((m)->m_flags & M_PKTHDR) ? &(m)->m_pktdat[0] : \
819 &(m)->m_dat[0])
820
821/*
822 * Return the size of the buffer associated with an mbuf, handling external
823 * storage, packet-header mbufs, and regular data mbufs.
824 */
825#define M_SIZE(m) \
826 (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \
827 ((m)->m_flags & M_PKTHDR) ? MHLEN : \
828 MLEN)
829
830/*
831 * Set the m_data pointer of a newly allocated mbuf to place an object of the
832 * specified size at the end of the mbuf, longword aligned.
833 *
834 * NB: Historically, we had M_ALIGN(), MH_ALIGN(), and MEXT_ALIGN() as
835 * separate macros, each asserting that it was called at the proper moment.
836 * This required callers to themselves test the storage type and call the
837 * right one. Rather than require callers to be aware of those layout
838 * decisions, we centralize here.
839 */
840static __inline void
841m_align(struct mbuf *m, int len)
842{
843#ifdef INVARIANTS
844 const char *msg = "%s: not a virgin mbuf";
845#endif
846 int adjust;
847
848 KASSERT(m->m_data == M_START(m), (msg, __func__));
849
850 if (m->m_flags & M_EXT) {
851 adjust = m->m_ext.ext_size - len;
852 } else if (m->m_flags & M_PKTHDR) {
853 adjust = MHLEN - len;
854 } else {
855 adjust = MLEN - len;
856 }
857
858 m->m_data += adjust &~ (sizeof(long)-1);
859}
860
861#define M_ALIGN(m, len) m_align(m, len)
862#define MH_ALIGN(m, len) m_align(m, len)
863#define MEXT_ALIGN(m, len) m_align(m, len)
864
865/*
867 * Compute the amount of space available before the current start of data in
868 * an mbuf.
869 *
870 * The M_WRITABLE() is a temporary, conservative safety measure: the burden
871 * of checking writability of the mbuf data area rests solely with the caller.
872 *
873 * NB: In previous versions, M_LEADINGSPACE() would only check M_WRITABLE()
874 * for mbufs with external storage. We now allow mbuf-embedded data to be

--- 325 unchanged lines hidden ---
866 * Compute the amount of space available before the current start of data in
867 * an mbuf.
868 *
869 * The M_WRITABLE() is a temporary, conservative safety measure: the burden
870 * of checking writability of the mbuf data area rests solely with the caller.
871 *
872 * NB: In previous versions, M_LEADINGSPACE() would only check M_WRITABLE()
873 * for mbufs with external storage. We now allow mbuf-embedded data to be

--- 325 unchanged lines hidden ---