forked from androidoffsec/baremetal_kasan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap.c
43 lines (34 loc) · 1.13 KB
/
heap.c
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
/*
* Copyright 2024 Google LLC
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "common.h"
#include "kasan.h"
// These symbols are defined in the linker script.
extern char __heap_start;
extern char __heap_end;
static void *heap_head;
static size_t heap_size;
void initialize_heap(void) {
heap_head = (void *)&__heap_start;
heap_size = (void *)&__heap_end - (void *)&__heap_start;
}
void *allocate_chunk(unsigned long size) {
void *result = heap_head;
if (size > heap_size) return NULL;
size = (size + 7) & (~7UL);
heap_head += size;
heap_size -= size;
return result;
}
void free_chunk(void *ptr) { (void)ptr; }
void *malloc(unsigned long size) { return kasan_malloc_hook(size); }
void free(void *ptr) { return kasan_free_hook(ptr); }