* Copyright (c) 1982 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)uipc_mbuf.c 6.5 (Berkeley) %G%
#include "../machine/pte.h"
if (m_clalloc(4096/CLBYTES
, MPG_MBUFS
, M_DONTWAIT
) == 0)
if (m_clalloc(8*4096/CLBYTES
, MPG_CLUSTERS
, M_DONTWAIT
) == 0)
* Must be called at splimp.
m_clalloc(ncl
, how
, canwait
)
mbx
= rmalloc(mbmap
, (long)npg
);
panic("out of mbuf map");
if (memall(&Mbmap
[mbx
], npg
, proc
, CSYS
) == 0) {
rmfree(mbmap
, (long)npg
, (long)mbx
);
vmaccess(&Mbmap
[mbx
], (caddr_t
)m
, npg
);
for (i
= 0; i
< ncl
; i
++) {
m
+= CLBYTES
/ sizeof (*m
);
mbstat
.m_clusters
+= ncl
;
for (i
= ncl
* CLBYTES
/ sizeof (*m
); i
> 0; i
--) {
mbstat
.m_mtypes
[MT_DATA
]++;
* Must be called at splimp.
if (m_clalloc(1, MPG_MBUFS
, canwait
) == 0)
/* should ask protocols to free code */
/* NEED SOME WAY TO RELEASE SPACE */
* Space allocation routines.
* These are also available as macros
bzero(mtod(m
, caddr_t
), MLEN
);
* Get more mbufs; called from MGET macro if mfree list is empty.
* Must be called at splimp.
while (m_expand(canwait
) == 0) {
sleep((caddr_t
)mfree
, PZERO
- 1);
#define m_more(x,y) (panic("m_more"), (struct mbuf *)0)
* Mbuffer utility routines.
* Make a copy of an mbuf chain starting "off" bytes from the beginning,
* continuing for "len" bytes. If len is M_COPYALL, copy to end of mbuf.
* Should get M_WAIT/M_DONTWAIT from caller.
register struct mbuf
*n
, **np
;
MGET(n
, M_DONTWAIT
, m
->m_type
);
n
->m_len
= MIN(len
, m
->m_len
- off
);
if (m
->m_off
> MMAXOFF
) {
p
= mtod(m
, struct mbuf
*);
n
->m_off
= ((int)p
- (int)n
) + off
;
bcopy(mtod(m
, caddr_t
)+off
, mtod(n
, caddr_t
),
register struct mbuf
*m
, *n
;
if (m
->m_off
>= MMAXOFF
||
m
->m_off
+ m
->m_len
+ n
->m_len
> MMAXOFF
) {
/* just join the two chains */
/* splat the data from one into the other */
bcopy(mtod(n
, caddr_t
), mtod(m
, caddr_t
) + m
->m_len
,
register struct mbuf
*m
, *n
;
while (m
!= NULL
&& len
> 0) {
/* a 2 pass algorithm might be better */
while (len
> 0 && m
->m_len
!= 0) {
while (m
!= NULL
&& m
->m_len
!= 0) {
register struct mbuf
*m
, *n
;
MGET(m
, M_DONTWAIT
, n
->m_type
);
count
= MIN(MLEN
- m
->m_len
, len
);
bcopy(mtod(n
, caddr_t
), mtod(m
, caddr_t
)+m
->m_len
,