-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathstdlib.c
More file actions
36 lines (27 loc) · 703 Bytes
/
stdlib.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_t bytes) {
void* chunk_start = lowest_free_memory;
lowest_free_memory += bytes;
if (lowest_free_memory >= current_stack_pointer()) {
interrupt_out_of_memory();
}
return chunk_start;
}
bool isdigit(char c) {
return c >= '0' && c <= '9';
}
int atoi (const char * str) {
int value = 0;
while(isdigit(*str)) {
value *= 10;
value += (*str)-'0';
str++;
}
return value;
}