1994-05-24 06:09:53 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1987, 1993
|
|
|
|
|
* The 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.
|
|
|
|
|
*
|
1996-03-10 21:08:50 -05:00
|
|
|
* @(#)malloc.h 8.5 (Berkeley) 5/3/95
|
1999-08-27 21:08:13 -04:00
|
|
|
* $FreeBSD$
|
1994-05-24 06:09:53 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _SYS_MALLOC_H_
|
|
|
|
|
#define _SYS_MALLOC_H_
|
|
|
|
|
|
2002-09-15 12:48:25 -04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
#include <sys/_lock.h>
|
|
|
|
|
#include <sys/_mutex.h>
|
2002-03-19 04:11:49 -05:00
|
|
|
|
2002-09-15 13:10:18 -04:00
|
|
|
#define MINALLOCSIZE UMA_SMALLEST_UNIT
|
2002-03-19 04:11:49 -05:00
|
|
|
|
1994-05-24 06:09:53 -04:00
|
|
|
/*
|
1999-01-21 03:29:12 -05:00
|
|
|
* flags to malloc.
|
1994-05-24 06:09:53 -04:00
|
|
|
*/
|
1999-09-11 13:11:21 -04:00
|
|
|
#define M_NOWAIT 0x0001 /* do not block */
|
2003-08-19 12:41:12 -04:00
|
|
|
#define M_WAITOK 0x0002 /* ok to block */
|
2003-03-10 14:39:53 -05:00
|
|
|
#define M_ZERO 0x0100 /* bzero the allocation */
|
|
|
|
|
#define M_NOVM 0x0200 /* don't ask VM for pages */
|
|
|
|
|
#define M_USE_RESERVE 0x0400 /* can alloc out of reserve memory */
|
1994-05-24 06:09:53 -04:00
|
|
|
|
1997-12-05 14:14:36 -05:00
|
|
|
#define M_MAGIC 877983977 /* time when first defined :-) */
|
1997-10-28 14:01:02 -05:00
|
|
|
|
1997-10-10 14:15:47 -04:00
|
|
|
struct malloc_type {
|
1997-12-05 14:14:36 -05:00
|
|
|
struct malloc_type *ks_next; /* next in list */
|
2002-04-30 18:39:32 -04:00
|
|
|
u_long ks_memuse; /* total memory held in bytes */
|
|
|
|
|
u_long ks_size; /* sizes of this thing that are allocated */
|
|
|
|
|
u_long ks_inuse; /* # of packets of this type currently in use */
|
2002-04-08 06:37:27 -04:00
|
|
|
uint64_t ks_calls; /* total packets of this type ever allocated */
|
2002-04-30 18:39:32 -04:00
|
|
|
u_long ks_maxused; /* maximum number ever used */
|
1997-12-05 14:14:36 -05:00
|
|
|
u_long ks_magic; /* if it's not magic, don't touch it */
|
|
|
|
|
const char *ks_shortdesc; /* short description */
|
2002-09-15 13:10:18 -04:00
|
|
|
struct mtx ks_mtx; /* lock for stats */
|
1994-05-24 06:09:53 -04:00
|
|
|
};
|
|
|
|
|
|
1999-12-28 23:46:21 -05:00
|
|
|
#ifdef _KERNEL
|
1997-10-11 14:31:40 -04:00
|
|
|
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
|
1997-12-05 14:14:36 -05:00
|
|
|
struct malloc_type type[1] = { \
|
2002-05-02 03:22:19 -04:00
|
|
|
{ NULL, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, {} } \
|
1997-12-05 14:14:36 -05:00
|
|
|
}; \
|
2000-06-14 14:31:42 -04:00
|
|
|
SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_SECOND, malloc_init, type); \
|
1998-11-10 03:46:24 -05:00
|
|
|
SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, malloc_uninit, type)
|
1997-10-11 14:31:40 -04:00
|
|
|
|
|
|
|
|
#define MALLOC_DECLARE(type) \
|
1998-11-10 03:46:24 -05:00
|
|
|
extern struct malloc_type type[1]
|
1997-10-10 10:06:34 -04:00
|
|
|
|
1999-09-11 12:41:39 -04:00
|
|
|
MALLOC_DECLARE(M_CACHE);
|
|
|
|
|
MALLOC_DECLARE(M_DEVBUF);
|
|
|
|
|
MALLOC_DECLARE(M_TEMP);
|
1999-11-05 09:41:39 -05:00
|
|
|
|
|
|
|
|
MALLOC_DECLARE(M_IP6OPT); /* for INET6 */
|
|
|
|
|
MALLOC_DECLARE(M_IP6NDP); /* for INET6 */
|
1994-05-24 06:09:53 -04:00
|
|
|
|
|
|
|
|
/*
|
2000-06-14 13:11:47 -04:00
|
|
|
* Deprecated macro versions of not-quite-malloc() and free().
|
1994-05-24 06:09:53 -04:00
|
|
|
*/
|
|
|
|
|
#define MALLOC(space, cast, size, type, flags) \
|
2002-04-21 07:08:52 -04:00
|
|
|
((space) = (cast)malloc((u_long)(size), (type), (flags)))
|
2000-06-14 13:11:47 -04:00
|
|
|
#define FREE(addr, type) free((addr), (type))
|
1996-01-26 19:13:33 -05:00
|
|
|
|
1997-12-05 13:58:13 -05:00
|
|
|
/*
|
|
|
|
|
* XXX this should be declared in <sys/uio.h>, but that tends to fail
|
|
|
|
|
* because <sys/uio.h> is included in a header before the source file
|
|
|
|
|
* has a chance to include <sys/malloc.h> to get MALLOC_DECLARE() defined.
|
|
|
|
|
*/
|
|
|
|
|
MALLOC_DECLARE(M_IOV);
|
|
|
|
|
|
2002-09-15 13:10:18 -04:00
|
|
|
extern struct mtx malloc_mtx;
|
|
|
|
|
|
1999-08-10 18:21:13 -04:00
|
|
|
/* XXX struct malloc_type is unused for contig*(). */
|
2002-03-23 03:46:52 -05:00
|
|
|
void contigfree(void *addr, unsigned long size, struct malloc_type *type);
|
|
|
|
|
void *contigmalloc(unsigned long size, struct malloc_type *type, int flags,
|
2003-03-24 19:07:06 -05:00
|
|
|
vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
|
2002-03-23 03:46:52 -05:00
|
|
|
unsigned long boundary);
|
2002-03-19 15:18:42 -05:00
|
|
|
void free(void *addr, struct malloc_type *type);
|
|
|
|
|
void *malloc(unsigned long size, struct malloc_type *type, int flags);
|
|
|
|
|
void malloc_init(void *);
|
2002-11-01 13:58:12 -05:00
|
|
|
int malloc_last_fail(void);
|
2002-03-19 15:18:42 -05:00
|
|
|
void malloc_uninit(void *);
|
2002-03-23 03:46:52 -05:00
|
|
|
void *realloc(void *addr, unsigned long size, struct malloc_type *type,
|
|
|
|
|
int flags);
|
|
|
|
|
void *reallocf(void *addr, unsigned long size, struct malloc_type *type,
|
|
|
|
|
int flags);
|
1999-12-28 23:46:21 -05:00
|
|
|
#endif /* _KERNEL */
|
1996-01-26 19:13:33 -05:00
|
|
|
|
1994-05-24 06:09:53 -04:00
|
|
|
#endif /* !_SYS_MALLOC_H_ */
|