#include #include #include #include #include extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t); extern "C" { pid_t getpid(void) { return (pid_t)syscall(SYS_getpid); } 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; } int close(int fd) { long rc = syscall(SYS_close, fd); __errno_return(rc, int); } ssize_t read(int fd, void* buf, size_t size) { long rc = syscall(SYS_read, fd, buf, size); __errno_return(rc, ssize_t); } ssize_t write(int fd, const void* buf, size_t size) { long rc = syscall(SYS_write, fd, buf, size); __errno_return(rc, ssize_t); } }