Kernel: Add an errno.h header with definitions for each header, and return those, negated, from syscalls when there is an error. mmap() returns an invalid address with errno encoded, instead of returning a negated errno; this address is encoded as ffffffffffffffEE where EE is errno in hex. libc: make syscall() return -1 and set errno on error, instead of returning the raw return value of the system call. Also, add mmap() and munmap() wrappers in sys/mman.h :). userspace: make the memeater program show the value of errno when allocating memory fails. Things to improve: add perror() and strerror() to make the errno experience even better! >.<
24 lines
374 B
C
24 lines
374 B
C
#include <stddef.h>
|
|
#include <sys/mman.h>
|
|
|
|
int liballoc_lock()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int liballoc_unlock()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void* liballoc_alloc(size_t size)
|
|
{
|
|
void* result = mmap(NULL, size * 4096, 0, 1, 0, 0);
|
|
if (result == MAP_FAILED) return 0;
|
|
return (void*)result;
|
|
}
|
|
|
|
int liballoc_free(void* address, size_t size)
|
|
{
|
|
return munmap(address, size * 4096);
|
|
} |