1 /*
2 * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "securec.h"
32 #include "los_config.h"
33 #include "los_memory.h"
34 #include <malloc.h>
35
__wrap__free_r(struct _reent * reent,void * aptr)36 void __wrap__free_r(struct _reent *reent, void *aptr)
37 {
38 if (aptr == NULL) {
39 return;
40 }
41
42 LOS_MemFree(OS_SYS_MEM_ADDR, aptr);
43 }
44
__wrap__malloc_usable_size_r(struct _reent * reent,void * aptr)45 size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
46 {
47 return 0;
48 }
49
__wrap__malloc_r(struct _reent * reent,size_t nbytes)50 void *__wrap__malloc_r(struct _reent *reent, size_t nbytes)
51 {
52 if (nbytes == 0) {
53 return NULL;
54 }
55
56 return LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
57 }
58
__wrap__memalign_r(struct _reent * reent,size_t align,size_t nbytes)59 void *__wrap__memalign_r(struct _reent *reent, size_t align, size_t nbytes)
60 {
61 if (nbytes == 0) {
62 return NULL;
63 }
64
65 return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, nbytes, align);
66 }
67
__wrap__realloc_r(struct _reent * reent,void * aptr,size_t nbytes)68 void *__wrap__realloc_r(struct _reent *reent, void *aptr, size_t nbytes)
69 {
70 if (aptr == NULL) {
71 return malloc(nbytes);
72 }
73
74 if (nbytes == 0) {
75 free(aptr);
76 return NULL;
77 }
78
79 return LOS_MemRealloc(OS_SYS_MEM_ADDR, aptr, nbytes);
80 }
81
__wrap__calloc_r(struct _reent * reent,size_t nitems,size_t size)82 void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
83 {
84 size_t real_size;
85 void *ptr = NULL;
86
87 if (nitems == 0 || size == 0) {
88 return NULL;
89 }
90
91 real_size = (size_t)(nitems * size);
92 ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
93 if (ptr != NULL) {
94 (void)memset_s(ptr, real_size, 0, real_size);
95 }
96 return ptr;
97 }
98
_sbrk(intptr_t __incr)99 void *_sbrk(intptr_t __incr)
100 {
101 return NULL;
102 }
103
104