ladybird/LibC/stdlib.cpp
Andreas Kling e904f193c1 Canonicalize the path used by sh.
With a bunch of LibC work to support the feature. LibC now initializes
AK::StringImpl by default. It's now fine to use AK in LibC/Userland! :^)
2018-10-28 09:36:21 +01:00

50 lines
703 B
C++

#include "stdlib.h"
#include "mman.h"
#include <Kernel/Syscall.h>
#include <AK/Assertions.h>
extern "C" {
void* malloc(size_t size)
{
if (size > 4096) {
volatile char* crashme = (char*)0xc007d00d;
*crashme = 0;
}
void* ptr = mmap(nullptr, 4096);
return ptr;
}
void free(void* ptr)
{
if (!ptr)
return;
munmap(ptr, 4096);
}
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);
}
}