3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
4 * Copyright 2013 Google Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <commonlib/bsd/stdlib.h>
39 * @defgroup malloc Memory allocation functions
42 void *realloc(void *ptr
, size_t size
);
43 void *dma_malloc(size_t size
);
44 void *dma_memalign(size_t align
, size_t size
);
46 #if CONFIG(LP_DEBUG_MALLOC) && !defined(IN_MALLOC_C)
48 void print_malloc_map(void);
51 printf("free(%p) called from %s:%s:%d...\n", __p, __FILE__, __func__, \
53 printf("PRE free()\n"); \
56 printf("POST free()\n"); \
59 #define malloc(s) ({ \
62 printf("malloc(%zu) called from %s:%s:%d...\n", __s, __FILE__, \
64 printf("PRE malloc\n"); \
67 printf("POST malloc (ptr = %p)\n", ptr); \
71 #define calloc(n, s) ({ \
72 size_t __n = n, __s = s; \
74 printf("calloc(%zu, %zu) called from %s:%s:%d...\n", __n, __s, \
75 __FILE__, __func__, __LINE__);\
76 printf("PRE calloc\n"); \
78 ptr = calloc(__n, __s); \
79 printf("POST calloc (ptr = %p)\n", ptr); \
83 #define realloc(p, s) ({ \
87 printf("realloc(%p, %zu) called from %s:%s:%d...\n", __p, __s, \
88 __FILE__, __func__, __LINE__);\
89 printf("PRE realloc\n"); \
91 ptr = realloc(__p, __s); \
92 printf("POST realloc (ptr = %p)\n", ptr); \
96 #define memalign(a, s) ({ \
97 size_t __a = a, __s = s; \
99 printf("memalign(%zu, %zu) called from %s:%s:%d...\n", __a, __s, \
100 __FILE__, __func__, __LINE__);\
101 printf("PRE memalign\n"); \
102 print_malloc_map(); \
103 ptr = memalign(__a, __s); \
104 printf("POST memalign (ptr = %p)\n", ptr); \
105 print_malloc_map(); \
108 #define dma_malloc(s) ({ \
111 printf("dma_malloc(%zu) called from %s:%s:%d...\n", __s, __FILE__, \
112 __func__, __LINE__);\
113 printf("PRE dma_malloc\n"); \
114 print_malloc_map(); \
115 ptr = dma_malloc(__s); \
116 printf("POST dma_malloc (ptr = %p)\n", ptr); \
117 print_malloc_map(); \
120 #define dma_memalign(a, s) ({ \
121 size_t __a = a, __s = s; \
123 printf("dma_memalign(%zu, %zu) called from %s:%s:%d...\n", __a, __s, \
124 __FILE__, __func__, __LINE__);\
125 printf("PRE dma_memalign\n"); \
126 print_malloc_map(); \
127 ptr = dma_memalign(__a, __s); \
128 printf("POST dma_memalign (ptr = %p)\n", ptr); \
129 print_malloc_map(); \
134 void init_dma_memory(void *start
, u32 size
);
135 int dma_initialized(void);
136 void dma_allocator_range(void **start_out
, size_t *size_out
);
141 * @defgroup stdlib String conversion functions
144 long int strtol(const char *s
, char **nptr
, int base
);
145 long long int strtoll(const char *s
, char **nptr
, int base
);
146 unsigned long int strtoul(const char *s
, char **nptr
, int base
);
147 unsigned long long int strtoull(const char *s
, char **nptr
, int base
);
148 long atol(const char *nptr
);
153 * @defgroup rand Random number generator functions
156 int rand_r(unsigned int *seed
);
158 void srand(unsigned int seed
);
162 * @defgroup misc Misc functions
166 long int labs(long int j
);
167 long long int llabs(long long int j
);
170 void qsort(void *aa
, size_t n
, size_t es
, int (*cmp
)(const void *, const void *));
171 char *getenv(const char*);
172 uint64_t __umoddi3(uint64_t num
, uint64_t den
);
173 uint64_t __udivdi3(uint64_t num
, uint64_t den
);
174 uint64_t __ashldi3(uint64_t num
, unsigned shift
);
175 uint64_t __lshrdi3(uint64_t num
, unsigned shift
);
177 void __noreturn
exit(int status
);