~aleteoryx/muditaos

ref: 134c949f58f2676c31a90f8b202fe2c8eb0ac753 muditaos/board/rt1051/memwrap.c -rw-r--r-- 2.1 KiB
134c949f — Adam Dobrowolski [EGD-7932] Added token export for build 4 years ago
                                                                                
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

//
// Created by mati on 08.05.19.
//

#include <stddef.h>
#include <string.h>
#include <stdint.h>
#include <time.h>

#include "memory/usermem.h"


void free(void *pv)
{
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_free((uint32_t)pv,caller);
#endif
    return userfree(pv);
}

void *malloc(size_t xWantedSize)
{
    void * ptr = usermalloc(xWantedSize);

#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_malloc((uint32_t)ptr,(uint32_t)caller,xWantedSize);
#endif

    return ptr;
}

void* _malloc_r (struct _reent *r, size_t sz)
{
    void * ptr = usermalloc(sz);

#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_malloc((uint32_t)ptr,(uint32_t)caller,sz);
#endif

    return ptr;
}

void* calloc (size_t num, size_t size)
{
    size_t total = num * size;
    void * p = usermalloc(total);

#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_malloc((uint32_t)p,(uint32_t)caller,total);
#endif

    if (!p) return NULL;

    return memset(p, 0, total);
}

void *realloc(void *aptr, size_t nbytes)
{
    return userrealloc(aptr, nbytes);
}


void* _calloc_r (struct _reent *r, size_t a, size_t b)
{
    size_t total = a * b;
    void * p = usermalloc(total);

#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_malloc((uint32_t)p,(uint32_t)caller,total);
#endif

    if (!p) return NULL;

    return memset(p, 0, total);
}

void _free_r (struct _reent *r, void* x)
{
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
    uint32_t caller = (uint32_t)__builtin_return_address (0);
  memleaks_log_free((uint32_t)x,caller);
#endif
    return userfree(x);
}

void* _realloc_r (struct _reent *r, void* x, size_t sz)
{
    return realloc(x, sz);
}

void _putchar(char character)
{
    // Use of printf is banned
}