• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdint.h>
2 #include "securec.h"
3 #include "prt_mem.h"
4 #include "prt_module.h"
5 
calloc(size_t nitems,size_t size)6 void *calloc(size_t nitems, size_t size)
7 {
8     size_t real_size;
9     void *ptr = NULL;
10 
11     if ((nitems == 0) || (size == 0) || (nitems > (UINT32_MAX / size))) {
12         return NULL;
13     }
14 
15     real_size = (size_t)(nitems * size);
16     ptr = PRT_MemAlloc(OS_MID_SYS, 0, real_size);
17     if (ptr != NULL) {
18         (void)memset_s(ptr, real_size, 0, real_size);
19     }
20     return ptr;
21 }
22 
free(void * ptr)23 void free(void *ptr)
24 {
25     if (ptr == NULL) {
26         return;
27     }
28 
29     (void)PRT_MemFree(OS_MID_SYS, ptr);
30 }
31 
malloc(size_t size)32 void *malloc(size_t size)
33 {
34     if (size == 0) {
35         return NULL;
36     }
37 
38     return PRT_MemAlloc(OS_MID_SYS, 0, size);
39 }
40 
zalloc(size_t size)41 void *zalloc(size_t size)
42 {
43     void *ptr = NULL;
44 
45     if (size == 0) {
46         return NULL;
47     }
48 
49     ptr = PRT_MemAlloc(OS_MID_SYS, 0, size);
50     if (ptr != NULL) {
51         (void)memset_s(ptr, size, 0, size);
52     }
53     return ptr;
54 }
55 
memalign(size_t boundary,size_t size)56 void *memalign(size_t boundary, size_t size)
57 {
58     if (size == 0) {
59         return NULL;
60     }
61 
62     if ((boundary % sizeof(uintptr_t) != 0)) {
63         return NULL;
64     }
65 
66     return PRT_MemAlloc(OS_MID_SYS, 0, size);
67 }
68