| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#ifndef _STDLIB_H |
| 31 |
#define _STDLIB_H |
| 32 |
|
| 33 |
#include <commonlib/bsd/stdlib.h> |
| 34 |
#include <die.h> |
| 35 |
#include <stddef.h> |
| 36 |
#include <string.h> |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 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); |
| 45 |
|
| 46 |
#if CONFIG(LP_DEBUG_MALLOC) && !defined(IN_MALLOC_C) |
| 47 |
#include <stdio.h> |
| 48 |
void print_malloc_map(void); |
| 49 |
#define free(p) ({ \ |
| 50 |
void *__p = p; \ |
| 51 |
printf("free(%p) called from %s:%s:%d...\n", __p, __FILE__, __func__, \ |
| 52 |
__LINE__);\ |
| 53 |
printf("PRE free()\n"); \ |
| 54 |
print_malloc_map(); \ |
| 55 |
free(__p); \ |
| 56 |
printf("POST free()\n"); \ |
| 57 |
print_malloc_map(); \ |
| 58 |
}) |
| 59 |
#define malloc(s) ({ \ |
| 60 |
size_t __s = s; \ |
| 61 |
void *ptr; \ |
| 62 |
printf("malloc(%zu) called from %s:%s:%d...\n", __s, __FILE__, \ |
| 63 |
__func__, __LINE__);\ |
| 64 |
printf("PRE malloc\n"); \ |
| 65 |
print_malloc_map(); \ |
| 66 |
ptr = malloc(__s); \ |
| 67 |
printf("POST malloc (ptr = %p)\n", ptr); \ |
| 68 |
print_malloc_map(); \ |
| 69 |
ptr; \ |
| 70 |
}) |
| 71 |
#define calloc(n, s) ({ \ |
| 72 |
size_t __n = n, __s = s; \ |
| 73 |
void *ptr; \ |
| 74 |
printf("calloc(%zu, %zu) called from %s:%s:%d...\n", __n, __s, \ |
| 75 |
__FILE__, __func__, __LINE__);\ |
| 76 |
printf("PRE calloc\n"); \ |
| 77 |
print_malloc_map(); \ |
| 78 |
ptr = calloc(__n, __s); \ |
| 79 |
printf("POST calloc (ptr = %p)\n", ptr); \ |
| 80 |
print_malloc_map(); \ |
| 81 |
ptr; \ |
| 82 |
}) |
| 83 |
#define realloc(p, s) ({ \ |
| 84 |
void *__p = p; \ |
| 85 |
size_t __s = s; \ |
| 86 |
void *ptr; \ |
| 87 |
printf("realloc(%p, %zu) called from %s:%s:%d...\n", __p, __s, \ |
| 88 |
__FILE__, __func__, __LINE__);\ |
| 89 |
printf("PRE realloc\n"); \ |
| 90 |
print_malloc_map(); \ |
| 91 |
ptr = realloc(__p, __s); \ |
| 92 |
printf("POST realloc (ptr = %p)\n", ptr); \ |
| 93 |
print_malloc_map(); \ |
| 94 |
ptr; \ |
| 95 |
}) |
| 96 |
#define memalign(a, s) ({ \ |
| 97 |
size_t __a = a, __s = s; \ |
| 98 |
void *ptr; \ |
| 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(); \ |
| 106 |
ptr; \ |
| 107 |
}) |
| 108 |
#define dma_malloc(s) ({ \ |
| 109 |
size_t __s = s; \ |
| 110 |
void *ptr; \ |
| 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(); \ |
| 118 |
ptr; \ |
| 119 |
}) |
| 120 |
#define dma_memalign(a, s) ({ \ |
| 121 |
size_t __a = a, __s = s; \ |
| 122 |
void *ptr; \ |
| 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(); \ |
| 130 |
ptr; \ |
| 131 |
}) |
| 132 |
#endif |
| 133 |
|
| 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); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 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); |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
int rand_r(unsigned int *seed); |
| 157 |
int rand(void); |
| 158 |
void srand(unsigned int seed); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
int abs(int j); |
| 166 |
long int labs(long int j); |
| 167 |
long long int llabs(long long int j); |
| 168 |
|
| 169 |
|
| 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); |
| 176 |
|
| 177 |
void __noreturn exit(int status); |
| 178 |
|
| 179 |
#endif |