2018-10-24 12:43:52 +02:00
|
|
|
#include "stdlib.h"
|
|
|
|
#include "mman.h"
|
2018-10-28 09:57:22 +01:00
|
|
|
#include "stdio.h"
|
2018-10-28 09:36:21 +01:00
|
|
|
#include <Kernel/Syscall.h>
|
|
|
|
#include <AK/Assertions.h>
|
2018-10-24 12:43:52 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
void* malloc(size_t size)
|
|
|
|
{
|
|
|
|
if (size > 4096) {
|
|
|
|
volatile char* crashme = (char*)0xc007d00d;
|
|
|
|
*crashme = 0;
|
|
|
|
}
|
|
|
|
void* ptr = mmap(nullptr, 4096);
|
2018-10-28 09:57:22 +01:00
|
|
|
if (ptr) {
|
|
|
|
int rc = set_mmap_name(ptr, 4096, "malloc");
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("set_mmap_name failed");
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 12:43:52 +02:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void* ptr)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
munmap(ptr, 4096);
|
|
|
|
}
|
|
|
|
|
2018-10-28 09:36:21 +01:00
|
|
|
void* calloc(size_t nmemb, size_t)
|
|
|
|
{
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* realloc(void *ptr, size_t)
|
|
|
|
{
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void exit(int status)
|
|
|
|
{
|
|
|
|
Syscall::invoke(Syscall::PosixExit, (dword)status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void abort()
|
|
|
|
{
|
|
|
|
// FIXME: Implement proper abort().
|
|
|
|
exit(253);
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:43:52 +02:00
|
|
|
}
|
|
|
|
|