PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
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
static void _heap_acquire(void)
Acquire the heap lock.
Definition
heap.h:109
_heap_header_t
_heap_header_t
Definition
heap.h:84
_heap_alloc
_heap_header_t * _heap_alloc(uint64_t size)
Allocates a block of memory of given size.
Definition
heap.c:203
_heap_release
static void _heap_release(void)
Release the heap lock.
Definition
heap.h:121
NULL
#define NULL
Pointer error value.
Definition
NULL.h:25
heap.h
malloc
void * malloc(size_t size)
Definition
malloc.c:5
stdlib.h
src
libstd
functions
stdlib
malloc.c
Generated on Sat Jan 24 2026 10:59:25 for PatchworkOS by
1.9.8