- Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathstdlib.c
More file actions
Latest commit
36 lines (27 loc) · 703 Bytes
/
Copy pathstdlib.c
File metadata and controls
36 lines (27 loc) · 703 Bytes
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
#include"stdlib.h"
#include"assembly_interface.h"
#include"data_structures/page_table.h"
#include"loader.h"
// naive strategy for now: keep track of highest allocated
// address, don't worry about freeing memory.
void*lowest_free_memory=&kernel_stack_lowest_address;
void*malloc(uint32_tbytes) {
void*chunk_start=lowest_free_memory;
lowest_free_memory+=bytes;
if (lowest_free_memory >= current_stack_pointer()) {
interrupt_out_of_memory();
}
returnchunk_start;
}
boolisdigit(charc) {
returnc >= '0'&&c <= '9';
}
intatoi (constchar*str) {
intvalue=0;
while(isdigit(*str)) {
value *= 10;
value+= (*str)-'0';
str++;
}
returnvalue;
}