summaryrefslogtreecommitdiff
path: root/kernel/mem.c
blob: 531dd811f8cf634d5a895999ada635c1f5088f53 (plain)
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
#include <types.h>
#include <mem.h>

static char eheap[EHEAP_SIZE] = {0};
static size_t eheap_off = 0;

void* kmalloc(size_t size) {
    return (void*)size;
}

void* kemalloc(size_t size) {
    size = (size + 7) & ~7;

    if (eheap_off + size > EHEAP_SIZE) {
        return NULL;
    }

    void *ptr = &eheap[eheap_off];
    eheap_off += size;
    return ptr;
}

void* memcpy(void *to, const void *from, size_t size) {
    char *dest = (char *)to;
    const char *src = (const char *)from;

    while (size--) {
        *dest++ = *src++;
    }

    return dest;
}