Luna/libc/src/unistd.cpp

41 lines
924 B
C++
Raw Normal View History

#include <bits/errno-return.h>
#include <stdarg.h>
#include <stdint.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
extern "C"
{
long syscall(long num, ...)
{
va_list ap;
va_start(ap, num);
uintptr_t arg0 = va_arg(ap, uintptr_t);
uintptr_t arg1 = va_arg(ap, uintptr_t);
uintptr_t arg2 = va_arg(ap, uintptr_t);
uintptr_t arg3 = va_arg(ap, uintptr_t);
uintptr_t arg4 = va_arg(ap, uintptr_t);
long rc = arch_invoke_syscall(num, arg0, arg1, arg2, arg3, arg4);
va_end(ap);
return rc;
}
int usleep(useconds_t us)
{
long rc = syscall(SYS_usleep, us);
__errno_return(rc, int);
}
unsigned long sleep(unsigned long seconds)
{
syscall(SYS_usleep, seconds * 1000000);
return 0;
}
}