Module Name: src
Committed By: christos
Date: Thu Nov 14 00:50:36 UTC 2013
Modified Files:
src/sys/kern: uipc_mbuf.c
src/sys/sys: mbuf.h
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/sys/kern/uipc_mbuf.c
cvs rdiff -u -r1.152 -r1.153 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.153 src/sys/kern/uipc_mbuf.c:1.154
--- src/sys/kern/uipc_mbuf.c:1.153 Wed Oct 9 16:15:20 2013
+++ src/sys/kern/uipc_mbuf.c Wed Nov 13 19:50:36 2013
@@ -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 @@ m_dup(struct mbuf *m, int off0, int len,
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 @@ m_copym0(struct mbuf *m, int off0, int l
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 @@ m_copym0(struct mbuf *m, int off0, int l
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 @@ m_copym0(struct mbuf *m, int off0, int l
*/
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);
Index: src/sys/sys/mbuf.h
diff -u src/sys/sys/mbuf.h:1.152 src/sys/sys/mbuf.h:1.153
--- src/sys/sys/mbuf.h:1.152 Thu Jun 27 13:47:18 2013
+++ src/sys/sys/mbuf.h Wed Nov 13 19:50:36 2013
@@ -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 @@ do { \
} 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)