Source-Changes-HG archive

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

[src/trunk]: src/sys change M_COPYALL to be -1 instead of depending on it too...



details:   https://anonhg.NetBSD.org/src/rev/b29af183d102
branches:  trunk
changeset: 791346:b29af183d102
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Nov 14 00:50:36 2013 +0000

description:
change M_COPYALL to be -1 instead of depending on it too be "too large",
so that we check explicitly against it in all places. ok gimpy

diffstat:

 sys/kern/uipc_mbuf.c |  15 ++++++++++-----
 sys/sys/mbuf.h       |   4 ++--
 2 files changed, 12 insertions(+), 7 deletions(-)

diffs (75 lines):

diff -r ccda9e827cb3 -r b29af183d102 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c      Thu Nov 14 00:27:05 2013 +0000
+++ b/sys/kern/uipc_mbuf.c      Thu Nov 14 00:50:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_mbuf.c,v 1.153 2013/10/09 20:15:20 christos Exp $ */
+/*     $NetBSD: uipc_mbuf.c,v 1.154 2013/11/14 00:50:36 christos Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.153 2013/10/09 20:15:20 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.154 2013/11/14 00:50:36 christos Exp $");
 
 #include "opt_mbuftrace.h"
 #include "opt_nmbclusters.h"
@@ -722,6 +722,11 @@
        return m_copym0(m, off0, len, wait, 1); /* deep copy */
 }
 
+static inline int
+m_copylen(int len, int copylen) {
+    return len == M_COPYALL ? copylen : min(len, copylen);
+}
+
 static struct mbuf *
 m_copym0(struct mbuf *m, int off0, int len, int wait, int deep)
 {
@@ -730,7 +735,7 @@
        struct mbuf *top;
        int copyhdr = 0;
 
-       if (off < 0 || len < 0)
+       if (off < 0 || (len != M_COPYALL && len < 0))
                panic("m_copym: off %d, len %d", off, len);
        if (off == 0 && m->m_flags & M_PKTHDR)
                copyhdr = 1;
@@ -764,7 +769,7 @@
                                n->m_pkthdr.len = len;
                        copyhdr = 0;
                }
-               n->m_len = min(len, m->m_len - off);
+               n->m_len = m_copylen(len, m->m_len - off);
                if (m->m_flags & M_EXT) {
                        if (!deep) {
                                n->m_data = m->m_data + off;
@@ -776,7 +781,7 @@
                                 */
                                MCLGET(n, wait);
                                n->m_len = M_TRAILINGSPACE(n);
-                               n->m_len = min(n->m_len, len);
+                               n->m_len = m_copylen(len, n->m_len);
                                n->m_len = min(n->m_len, m->m_len - off);
                                memcpy(mtod(n, void *), mtod(m, char *) + off,
                                    (unsigned)n->m_len);
diff -r ccda9e827cb3 -r b29af183d102 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Thu Nov 14 00:27:05 2013 +0000
+++ b/sys/sys/mbuf.h    Thu Nov 14 00:50:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.152 2013/06/27 17:47:18 christos Exp $      */
+/*     $NetBSD: mbuf.h,v 1.153 2013/11/14 00:50:36 christos Exp $      */
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -686,7 +686,7 @@
 } while (/* CONSTCOND */ 0)
 
 /* length to m_copy to copy all */
-#define        M_COPYALL       1000000000
+#define        M_COPYALL       -1
 
 /* compatibility with 4.3 */
 #define  m_copy(m, o, l)       m_copym((m), (o), (l), M_DONTWAIT)



Home | Main Index | Thread Index | Old Index