1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | /*============================================================================= |
29 | Create the vcos_malloc API from the regular system malloc/free |
30 | =============================================================================*/ |
31 | |
32 | /** |
33 | * \file |
34 | * |
35 | * Create the vcos malloc API from a regular system malloc/free library. |
36 | * |
37 | * The API lets callers specify an alignment. |
38 | * |
39 | * Under VideoCore this is not needed, as we can simply use the rtos_malloc routines. |
40 | * But on host platforms that won't be the case. |
41 | * |
42 | */ |
43 | |
44 | VCOSPRE_ void * VCOSPOST_ vcos_generic_mem_alloc(VCOS_UNSIGNED sz, const char *desc); |
45 | VCOSPRE_ void * VCOSPOST_ vcos_generic_mem_calloc(VCOS_UNSIGNED count, VCOS_UNSIGNED sz, const char *descr); |
46 | VCOSPRE_ void VCOSPOST_ vcos_generic_mem_free(void *ptr); |
47 | VCOSPRE_ void * VCOSPOST_ vcos_generic_mem_alloc_aligned(VCOS_UNSIGNED sz, VCOS_UNSIGNED align, const char *desc); |
48 | |
49 | #ifdef VCOS_INLINE_BODIES |
50 | |
51 | VCOS_INLINE_IMPL |
52 | void *vcos_malloc(VCOS_UNSIGNED size, const char *description) { |
53 | return vcos_generic_mem_alloc(size, description); |
54 | } |
55 | |
56 | VCOS_INLINE_IMPL |
57 | void *vcos_calloc(VCOS_UNSIGNED num, VCOS_UNSIGNED size, const char *description) { |
58 | return vcos_generic_mem_calloc(num, size, description); |
59 | } |
60 | |
61 | VCOS_INLINE_IMPL |
62 | void vcos_free(void *ptr) { |
63 | vcos_generic_mem_free(ptr); |
64 | } |
65 | |
66 | VCOS_INLINE_IMPL |
67 | void * vcos_malloc_aligned(VCOS_UNSIGNED size, VCOS_UNSIGNED align, const char *description) { |
68 | return vcos_generic_mem_alloc_aligned(size, align, description); |
69 | } |
70 | |
71 | /* Returns invalid result, do not use */ |
72 | |
73 | VCOS_INLINE_IMPL |
74 | unsigned long VCOS_DEPRECATED("returns invalid result" ) vcos_get_free_mem(void) { |
75 | return 0; |
76 | } |
77 | |
78 | #endif /* VCOS_INLINE_BODIES */ |
79 | |
80 | |
81 | |