1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup rtems_bsd_rtems |
---|
5 | * |
---|
6 | * @brief TODO. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions |
---|
20 | * are met: |
---|
21 | * 1. Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer in the |
---|
25 | * documentation and/or other materials provided with the distribution. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
37 | * SUCH DAMAGE. |
---|
38 | */ |
---|
39 | |
---|
40 | #include <machine/rtems-bsd-kernel-space.h> |
---|
41 | #include <machine/rtems-bsd-support.h> |
---|
42 | |
---|
43 | #include <sys/param.h> |
---|
44 | #include <sys/types.h> |
---|
45 | #include <sys/systm.h> |
---|
46 | #include <sys/malloc.h> |
---|
47 | #include <sys/kernel.h> |
---|
48 | |
---|
49 | MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory"); |
---|
50 | |
---|
51 | MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers"); |
---|
52 | |
---|
53 | MALLOC_DEFINE(M_IOV, "iov", "large iov's"); |
---|
54 | |
---|
55 | void |
---|
56 | malloc_init(void *data) |
---|
57 | { |
---|
58 | struct malloc_type *mtp = data; |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | malloc_uninit(void *data) |
---|
63 | { |
---|
64 | struct malloc_type *mtp = data; |
---|
65 | |
---|
66 | BSD_PRINTF( "desc = %s\n", mtp->ks_shortdesc); |
---|
67 | } |
---|
68 | |
---|
69 | #undef malloc |
---|
70 | |
---|
71 | void * |
---|
72 | _bsd_malloc(unsigned long size, struct malloc_type *mtp, int flags) |
---|
73 | { |
---|
74 | void *p = malloc(size > 0 ? size : 1); |
---|
75 | |
---|
76 | if ((flags & M_ZERO) != 0 && p != NULL) { |
---|
77 | memset(p, 0, size); |
---|
78 | } |
---|
79 | |
---|
80 | return p; |
---|
81 | } |
---|
82 | |
---|
83 | #undef realloc |
---|
84 | void * |
---|
85 | _bsd_realloc( void *addr, unsigned long size, |
---|
86 | struct malloc_type *type, int flags) |
---|
87 | { |
---|
88 | void *p = realloc(addr, size > 0 ? size : 1); |
---|
89 | |
---|
90 | if ((flags & M_ZERO) != 0 && p != NULL) { |
---|
91 | memset(p, 0, size); |
---|
92 | } |
---|
93 | |
---|
94 | return p; |
---|
95 | } |
---|
96 | |
---|
97 | #undef reallocf |
---|
98 | void * |
---|
99 | _bsd_reallocf( void *addr, unsigned long size, |
---|
100 | struct malloc_type *type, int flags) |
---|
101 | { |
---|
102 | void *p = realloc(addr, size > 0 ? size : 1); |
---|
103 | |
---|
104 | if (p == NULL) { |
---|
105 | free(addr,NULL); |
---|
106 | } |
---|
107 | |
---|
108 | return p; |
---|
109 | } |
---|
110 | |
---|
111 | #undef free |
---|
112 | void |
---|
113 | _bsd_free(void *addr, struct malloc_type *mtp) |
---|
114 | { |
---|
115 | free(addr); |
---|
116 | } |
---|
117 | |
---|
118 | #undef strdup |
---|
119 | |
---|
120 | char * |
---|
121 | _bsd_strdup(const char *__restrict s, struct malloc_type *type) |
---|
122 | { |
---|
123 | return strdup(s); |
---|
124 | } |
---|