LibC: Add simple definition for realloc

The syscall just crashes the kernel currently. I will implement
this when needed
This commit is contained in:
Bananymous 2023-06-02 17:56:13 +03:00
parent 2207357b93
commit 3c3c7826ef
3 changed files with 18 additions and 0 deletions

View File

@ -20,6 +20,7 @@ __BEGIN_DECLS
#define SYS_FORK 13
#define SYS_SLEEP 14
#define SYS_EXEC 15
#define SYS_REALLOC 16
__END_DECLS

View File

@ -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)

View File

@ -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;