-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmm.c
50 lines (40 loc) · 851 Bytes
/
mm.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
44
45
46
47
48
49
50
#include "types.h"
#include "vm.h"
#include "printk.h"
#include "mm.h"
extern uintptr_t end;
uintptr_t placement_address = (uintptr_t)&end;
static void *
kmalloc_int(size_t size, int align, uintptr_t *phys)
{
uintptr_t tmp;
if (align && (placement_address & 0xFFFFF000)) {
placement_address &= 0xFFFFF000;
placement_address += PAGE_SIZE;
}
if (phys)
*phys = placement_address;
tmp = placement_address;
placement_address += size;
return (void *)tmp;
}
void *
kmalloc_a(size_t size)
{
return kmalloc_int(size, 1, NULL);
}
void *
kmalloc_p(size_t size, uintptr_t *phys)
{
return kmalloc_int(size, 0, phys);
}
void *
kmalloc_ap(size_t size, uintptr_t *phys)
{
return kmalloc_int(size, 1, phys);
}
void *
kmalloc(size_t size)
{
return kmalloc_int(size, 0, NULL);
}