• 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  * $FreeBSD: releng/12.2/sys/sys/malloc.h 365383 2020-09-06 17:40:35Z wulf $
35  */
36 
37 #ifndef _SYS_MALLOC_H_
38 #define	_SYS_MALLOC_H_
39 
40 #include <sys/types.h>
41 #include <los_memory.h>
42 #ifdef LOSCFG_LIBC_NEWLIB
43 #include <malloc.h>
44 #endif
45 
46 #define M_NOWAIT        0x0001          /* do not block */
47 #define M_WAITOK        0x0002          /* ok to block */
48 #define M_ZERO          0x0100          /* bzero the allocation */
49 #define M_NOVM          0x0200          /* don't ask VM for pages */
50 #define M_USE_RESERVE   0x0400          /* can alloc out of reserve memory */
51 #define M_NODUMP        0x0800          /* don't dump pages in this allocation */
52 #define M_FIRSTFIT      0x1000          /* Only for vmem, fast fit. */
53 #define M_BESTFIT       0x2000          /* Only for vmem, low fragmentation. */
54 
55 #define M_MAGIC         877983977       /* time when first defined :-) */
56 #define MINALLOCSIZE    4
57 
58 /*
59  *  * Public data structure describing a malloc type.  Private data is hung off
60  *   * of ks_handle to avoid encoding internal malloc(9) data structures in
61  *    * modules, which will statically allocate struct malloc_type.
62  *     */
63 struct malloc_type {
64         struct malloc_type *ks_next;    /* Next in global chain. */
65         u_long           ks_magic;      /* Detect programmer error. */
66         const char      *ks_shortdesc;  /* Printable type name. */
67         void            *ks_handle;     /* Priv. data, was lo_class. */
68 };
69 
70 
71 #define MALLOC_DEFINE(type, shortdesc, longdesc)                        \
72         struct malloc_type type[1] = {                                  \
73                 { NULL, M_MAGIC, shortdesc, NULL }                      \
74         };
75 
76 #define bsd_malloc(size, type, flags)	zalloc(size)
77 #define bsd_free(addr, type)		free(addr)
78 #define bsd_strdup(p,x)			strdup(p)
79 
80 #endif /* !_SYS_MALLOC_H_ */
81