PatchworkOS
Loading...
Searching...
No Matches
malloc.c
Go to the documentation of this file.
1
#include <
stdlib.h
>
2
3
#include "
common/heap.h
"
4
5
void
*
malloc
(
size_t
size)
6
{
7
_heap_acquire
();
8
9
_heap_header_t
* block =
_heap_alloc
(size);
10
if
(block ==
NULL
)
11
{
12
_heap_release
();
13
return
NULL
;
14
}
15
16
// When this function returns we have no way of knowing whether the caller
17
// will fill the memory or not, so we clear the zeroed flag.
18
block->
flags
&= ~_HEAP_ZEROED;
19
20
_heap_release
();
21
return
block->
data
;
22
}
_heap_acquire
void _heap_acquire(void)
Acquire the heap lock.
Definition
heap.c:81
_heap_alloc
_heap_header_t * _heap_alloc(uint64_t size)
Allocates a block of memory of given size.
Definition
heap.c:199
_heap_release
void _heap_release(void)
Release the heap lock.
Definition
heap.c:90
NULL
#define NULL
Pointer error value.
Definition
NULL.h:23
heap.h
malloc
void * malloc(size_t size)
Definition
malloc.c:5
stdlib.h
_heap_header_t
Definition
heap.h:67
_heap_header_t::data
uint8_t data[]
Definition
heap.h:73
_heap_header_t::flags
_heap_flags_t flags
Definition
heap.h:69
src
libstd
functions
stdlib
malloc.c
Generated by
1.9.8