source: rtems-libbsd/rtemsbsd/rtems/rtems-kernel-malloc.c

6-freebsd-12
Last change on this file was 18fa92c, checked in by Sebastian Huber <sebastian.huber@…>, on 08/20/18 at 13:53:03

Update to FreeBSD head 2018-02-01

Git mirror commit d079ae0442af8fa3cfd6d7ede190d04e64a2c0d4.

Update #3472.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*-
10 * SPDX-License-Identifier: BSD-3-Clause
11 *
12 * Copyright (c) 1987, 1991, 1993
13 *      The Regents of the University of California.
14 * Copyright (c) 2005-2009 Robert N. M. Watson
15 * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> (mallocarray)
16 * Copyright (c) 2009, 2018 embedded brains GmbH
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 *    notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 *    notice, this list of conditions and the following disclaimer in the
26 *    documentation and/or other materials provided with the distribution.
27 * 3. Neither the name of the University nor the names of its contributors
28 *    may be used to endorse or promote products derived from this software
29 *    without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * SUCH DAMAGE.
42 *
43 *      @(#)kern_malloc.c       8.3 (Berkeley) 1/4/94
44 */
45
46#include <machine/rtems-bsd-kernel-space.h>
47#include <machine/rtems-bsd-support.h>
48
49#include <sys/param.h>
50#include <sys/types.h>
51#include <sys/systm.h>
52#include <sys/malloc.h>
53#include <sys/kernel.h>
54
55MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory");
56
57MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers");
58
59MALLOC_DEFINE(M_IOV, "iov", "large iov's");
60
61void
62malloc_init(void *data)
63{
64
65}
66
67void
68malloc_uninit(void *data)
69{
70        struct malloc_type *mtp = data;
71
72        BSD_PRINTF( "desc = %s\n", mtp->ks_shortdesc);
73}
74
75#undef malloc
76
77void *
78_bsd_malloc(size_t size, struct malloc_type *mtp, int flags)
79{
80        void *p = malloc(size > 0 ? size : 1);
81
82        if ((flags & M_ZERO) != 0 && p != NULL) {
83                memset(p, 0, size);
84        }
85
86        return (p);
87}
88
89void *
90mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags)
91{
92
93        if (WOULD_OVERFLOW(nmemb, size))
94                panic("mallocarray: %zu * %zu overflowed", nmemb, size);
95
96        return (_bsd_malloc(size * nmemb, type, flags));
97}
98
99#undef realloc
100
101void *
102_bsd_realloc( void *addr, size_t size, struct malloc_type *type, int flags)
103{
104        void *p = realloc(addr, size > 0 ? size : 1);
105
106        if ((flags & M_ZERO) != 0 && p != NULL) {
107                memset(p, 0, size);
108        }
109
110        return p;
111}
112
113#undef reallocf
114
115void *
116_bsd_reallocf( void *addr, size_t size, struct malloc_type *type, int flags)
117{
118        void *p = realloc(addr, size > 0 ? size : 1);
119
120        if (p == NULL) {
121                free(addr, NULL);
122        }
123
124        return (p);
125}
126
127#undef free
128
129void
130_bsd_free(void *addr, struct malloc_type *mtp)
131{
132
133        free(addr);
134}
135
136#undef strdup
137
138char *
139_bsd_strdup(const char *__restrict s, struct malloc_type *type)
140{
141
142        return (strdup(s));
143}
Note: See TracBrowser for help on using the repository browser.