forked from Bananymous/banan-os
LibC: Add simple definition for realloc
The syscall just crashes the kernel currently. I will implement this when needed
This commit is contained in:
parent
2207357b93
commit
3c3c7826ef
|
@ -20,6 +20,7 @@ __BEGIN_DECLS
|
|||
#define SYS_FORK 13
|
||||
#define SYS_SLEEP 14
|
||||
#define SYS_EXEC 15
|
||||
#define SYS_REALLOC 16
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -76,6 +76,16 @@ void* calloc(size_t nmemb, size_t size)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void* realloc(void* ptr, size_t size)
|
||||
{
|
||||
if (ptr == nullptr)
|
||||
return malloc(size);
|
||||
long ret = syscall(SYS_REALLOC, ptr, size);
|
||||
if (ret == -1)
|
||||
return nullptr;
|
||||
return (void*)ret;
|
||||
}
|
||||
|
||||
void free(void* ptr)
|
||||
{
|
||||
if (ptr == nullptr)
|
||||
|
|
|
@ -130,6 +130,13 @@ long syscall(long syscall, ...)
|
|||
ret = Kernel::syscall(SYS_EXEC, (uintptr_t)pathname, (uintptr_t)argv, (uintptr_t)envp);
|
||||
break;
|
||||
}
|
||||
case SYS_REALLOC:
|
||||
{
|
||||
void* ptr = va_arg(args, void*);
|
||||
size_t size = va_arg(args, size_t);
|
||||
ret = Kernel::syscall(SYS_REALLOC, (uintptr_t)ptr, size);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
puts("LibC: Unhandeled syscall");
|
||||
ret = -ENOSYS;
|
||||
|
|
Loading…
Reference in New Issue