• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1987, 1993
5  *	The Regents of the University of California.
6  * Copyright (c) 2005, 2009 Robert N. M. Watson
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)malloc.h	8.5 (Berkeley) 5/3/95
34  */
35 
36 #ifndef _SYS_MALLOC_H_
37 #define	_SYS_MALLOC_H_
38 
39 #include <sys/types.h>
40 #include <los_memory.h>
41 #ifdef LOSCFG_LIBC_NEWLIB
42 #include <malloc.h>
43 #endif
44 
45 #define M_NOWAIT        0x0001          /* do not block */
46 #define M_WAITOK        0x0002          /* ok to block */
47 #define M_ZERO          0x0100          /* bzero the allocation */
48 #define M_NOVM          0x0200          /* don't ask VM for pages */
49 #define M_USE_RESERVE   0x0400          /* can alloc out of reserve memory */
50 #define M_NODUMP        0x0800          /* don't dump pages in this allocation */
51 #define M_FIRSTFIT      0x1000          /* Only for vmem, fast fit. */
52 #define M_BESTFIT       0x2000          /* Only for vmem, low fragmentation. */
53 
54 #define M_MAGIC         877983977       /* time when first defined :-) */
55 #define MINALLOCSIZE    4
56 
57 /*
58  *  * Public data structure describing a malloc type.  Private data is hung off
59  *   * of ks_handle to avoid encoding internal malloc(9) data structures in
60  *    * modules, which will statically allocate struct malloc_type.
61  *     */
62 struct malloc_type {
63         struct malloc_type *ks_next;    /* Next in global chain. */
64         u_long           ks_magic;      /* Detect programmer error. */
65         const char      *ks_shortdesc;  /* Printable type name. */
66         void            *ks_handle;     /* Priv. data, was lo_class. */
67 };
68 
69 
70 #define MALLOC_DEFINE(type, shortdesc, longdesc)                        \
71         struct malloc_type type[1] = {                                  \
72                 { NULL, M_MAGIC, shortdesc, NULL }                      \
73         };
74 
75 #define bsd_malloc(size, type, flags)	zalloc(size)
76 #define bsd_free(addr, type)		free(addr)
77 #define bsd_strdup(p,x)			strdup(p)
78 
79 #endif /* !_SYS_MALLOC_H_ */
80