home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
comm
/
amitcp-3.0ß2.lha
/
AmiTCP
/
src
/
amitcp
/
kern
/
uipc_mbuf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-12
|
22KB
|
907 lines
RCS_ID_C = "$Id: uipc_mbuf.c,v 1.18 1993/06/04 11:16:15 jraja Exp $";
/*
* Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* Last modified: Fri Jun 4 00:36:45 1993 jraja
*
* HISTORY
* $Log: uipc_mbuf.c,v $
* Revision 1.18 1993/06/04 11:16:15 jraja
* Fixes for first public release.
*
* Revision 1.17 1993/05/29 20:57:23 jraja
* Added function mb_read_stats() to return mbuf type specific statistics.
*
* Revision 1.16 1993/05/16 15:20:25 ppessi
* Fixed bug with cluster allocation.
*
* Revision 1.16 1993/05/16 15:20:25 ppessi
* Fixed bug with cluster allocation.
*
* Revision 1.15 93/05/04 12:52:25 12:52:25 jraja (Jarno Tapio Rajahalme)
* Fixed default values of the configuration variables.
*
* Revision 1.14 93/04/25 02:59:37 02:59:37 jraja (Jarno Tapio Rajahalme)
* Added some comments.
*
* Revision 1.13 93/04/24 22:19:41 22:19:41 jraja (Jarno Tapio Rajahalme)
* Removed MBTYPES, moved configurable variables to a structure (mbconf),
* removed nmbufs and nmbclusters (already in mbstat), moved mbufmemsize to
* mbstat (as m_memused), added configuration notify function
* mb_check_conf() to validate configurable variables,
* added checks for maximum memory usage,
* removed m_retryhdr(), since m_retry() is already called by MGETHDR,
* removed all USECLUSTERS (now using clusters always.
*
* Revision 1.12 93/04/23 02:26:28 02:26:28 ppessi (Pekka Pessi)
* Added some configureable parameters
*
* Revision 1.11 93/04/13 22:31:51 22:31:51 jraja (Jarno Tapio Rajahalme)
* Added #ifdef USECLUSTERS ... #endif to compile without.
*
* Revision 1.10 93/04/06 15:16:04 15:16:04 jraja (Jarno Tapio Rajahalme)
* Changed spl function return value storage to spl_t,
* changed bcopys and bzeros to aligned and/or const when possible,
* added inclusion of conf.h to every .c file.
*
* Revision 1.9 93/04/02 01:08:17 01:08:17 jraja (Jarno Tapio Rajahalme)
* Implemented clusters.
* Updated memory allocation.
* Added memHeader structure to keep account of allocated memory.
*
* Revision 1.8 93/03/05 03:26:21 03:26:21 ppessi (Pekka Pessi)
* Compiles with SASC. Initial test version.
*
* Revision 1.7 93/03/04 09:55:46 09:55:46 jraja (Jarno Tapio Rajahalme)
* Fixed includes.
*
* Revision 1.6 93/03/03 19:59:29 19:59:29 jraja (Jarno Tapio Rajahalme)
* Added static initializers to globals.
*
* Revision 1.5 93/03/03 19:20:43 19:20:43 jraja (Jarno Tapio Rajahalme)
* Moved some definitions from sys/mbuf.h to here.
*
* Revision 1.4 93/02/24 12:55:20 12:55:20 jraja (Jarno Tapio Rajahalme)
* Changed init to remember if initialized.
*
* Revision 1.3 93/01/06 19:24:53 19:24:53 jraja (Jarno Tapio Rajahalme)
* Ported this for AmigaOS. Added function mbdeinit(), which is used to free
* memory allocated by mbuf subsystem.
* Alse commented all memory cluster related stuff with #ifdef USECLUSTERS.
*
* Revision 1.2 92/11/20 15:14:25 15:14:25 jraja (Jarno Tapio Rajahalme)
* Added #ifndef AMITCP's to make this compile.
*
* Revision 1.1 92/11/19 12:07:15 12:07:15 jraja (Jarno Tapio Rajahalme)
* Initial revision
*/
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* HISTORY
* Log: uipc_mbuf.c,v
* Revision 2.2 92/06/25 17:25:22 mrt
* Preallocate mbufs in a chunk.
* [92/06/24 rwd]
*
* Revision 2.1 92/04/21 17:12:59 rwd
* BSDSS
*
*
*/
/*
* Copyright (c) 1982, 1986, 1988, 1991 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)uipc_mbuf.c 7.19 (Berkeley) 4/20/91
*/
#include <conf.h>
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/synch.h>
#include <kern/amiga_includes.h>
#include <dos/rdargs.h>
/*
* Configuration information.
*/
struct mbconf mbconf = {
2, /* # of mbuf chunks to allocate initially */
64, /* # of mbufs to allocate at a time */
4, /* # of clusters to allocate at a time */
256, /* maximum memory to use (in kilobytes) */
2048 /* size of the mbuf cluster */
};
/*
* List of free mbufs. Access to this list is protected by splimp()
*/
struct mbuf *mfree = NULL;
struct mbstat mbstat = { 0 };
struct mcluster *mclfree = NULL;
int max_linkhdr = 0; /* largest link-level header */
int max_protohdr = 0; /* largest protocol header */
int max_hdr = 0; /* largest link+protocol header */
int max_datalen = 0; /* MHLEN - max_hdr */
/*
* Header structure that is placed at the start of every allocated memory
* region to be freed on deinit. All memory alloctions are thus
* sizeof(memHeader) larger and the data pointer is set past this header
* before used. These headers are linked together and the mbufmem pointer
* holds the pointer to the start of the list.
*/
struct memHeader {
struct memHeader *next;
ULONG size;
};
static struct memHeader *mbufmem = NULL;
static BOOL initialized = FALSE;
LONG mb_read_stats(struct CSource *args, UBYTE **errstrp, struct CSource *res)
{
int i, total = 0;
UBYTE *p = res->CS_Buffer;
for(i = 0; i < MTCOUNT; i++) {
p += sprintf(p, "%ld ", mbstat.m_mtypes[i]);
total += mbstat.m_mtypes[i];
}
p += sprintf(p, "%ld", total);
res->CS_CurChr =