2 * Copyright (c) 2012, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __BREEDLINE_MM_H__
31 #define __BREEDLINE_MM_H__
36 /* Macro that can be used to pass the location of its usage further. */
37 #define BRL_LOC __FILE__, __LINE__, __func__
39 /* Memory allocation macros used by breedline. */
40 #define brl_allocz(size) ({ \
42 size_t _size = size; \
44 if ((_ptr = __brl_mm.allocfn(_size, BRL_LOC)) != NULL) \
45 memset(_ptr, 0, _size); \
47 __brl_mm_busy = TRUE; \
51 #define brl_reallocz(ptr, o, n) ({ \
53 size_t _size = sizeof(*_ptr) * (n); \
62 _ptr = __brl_mm.reallocfn(ptr, _size, BRL_LOC); \
63 if (_ptr != NULL || _n == 0) { \
64 if ((unsigned)(_n) > (unsigned)(_o)) \
65 memset(_ptr + (_o), 0, \
66 ((_n) - (_o)) * sizeof(*_ptr)); \
70 __brl_mm_busy = TRUE; \
74 #define brl_strdup(s) ({ \
75 __brl_mm_busy = TRUE; \
77 __brl_mm.strdupfn((s), BRL_LOC); \
80 #define brl_free(ptr) __brl_mm.freefn((ptr), BRL_LOC)
82 extern brl_allocator_t __brl_mm;
83 extern int __brl_mm_busy;
85 #endif /* __BREEDLINE_MM_H__ */