69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#include <bits/error.h>
|
|
#include <errno.h>
|
|
#include <luna/syscall.h>
|
|
#include <stdarg.h>
|
|
#include <sys/syscall.h>
|
|
|
|
extern "C" long syscall(long number, ...)
|
|
{
|
|
typedef unsigned long arg;
|
|
long result;
|
|
va_list ap;
|
|
va_start(ap, number);
|
|
switch (number)
|
|
{
|
|
case SYS_yield:
|
|
case SYS_fork: result = __luna_syscall0(number); break;
|
|
case SYS_exit:
|
|
case SYS_getprocid:
|
|
case SYS_close:
|
|
case SYS_umask:
|
|
case SYS_setuid:
|
|
case SYS_setgid:
|
|
case SYS_seteuid:
|
|
case SYS_setegid:
|
|
case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break;
|
|
case SYS_munmap:
|
|
case SYS_execv:
|
|
case SYS_access:
|
|
case SYS_fstat:
|
|
case SYS_stat:
|
|
case SYS_mkdir:
|
|
case SYS_dup2:
|
|
case SYS_clock_gettime:
|
|
case SYS_pstat: {
|
|
arg arg0 = va_arg(ap, arg);
|
|
arg arg1 = va_arg(ap, arg);
|
|
result = __luna_syscall2(number, arg0, arg1);
|
|
break;
|
|
}
|
|
case SYS_open:
|
|
case SYS_getdents:
|
|
case SYS_fcntl:
|
|
case SYS_seek:
|
|
case SYS_write:
|
|
case SYS_read:
|
|
case SYS_ioctl:
|
|
case SYS_mprotect:
|
|
case SYS_waitpid: {
|
|
arg arg0 = va_arg(ap, arg);
|
|
arg arg1 = va_arg(ap, arg);
|
|
arg arg2 = va_arg(ap, arg);
|
|
result = __luna_syscall3(number, arg0, arg1, arg2);
|
|
break;
|
|
}
|
|
case SYS_mmap: {
|
|
arg arg0 = va_arg(ap, arg);
|
|
arg arg1 = va_arg(ap, arg);
|
|
arg arg2 = va_arg(ap, arg);
|
|
arg arg3 = va_arg(ap, arg);
|
|
arg arg4 = va_arg(ap, arg);
|
|
result = __luna_syscall5(number, arg0, arg1, arg2, arg3, arg4);
|
|
break;
|
|
}
|
|
default: result = -ENOSYS; break;
|
|
}
|
|
va_end(ap);
|
|
if (number == SYS_mmap) { _RETURN_WITH_MEMORY_ERRNO(result, long int); }
|
|
else { _RETURN_WITH_ERRNO(result, long); }
|
|
} |