diff --git a/Src/Platform.rux b/Src/Platform.rux index 16db4e2..c15438d 100644 --- a/Src/Platform.rux +++ b/Src/Platform.rux @@ -11,6 +11,7 @@ module Platform { Munmap, Read, Syscall1, + Syscall2, Stdin, Stdout, Write, @@ -18,6 +19,8 @@ module Platform { MAP_PRIVATE, PROT_READ, PROT_WRITE, + SYS_NANOSLEEP, + SYS_CLOCK_GETTIME, SYS_EXIT }; diff --git a/Src/Syscall.rux b/Src/Syscall.rux index 0d43225..e258b39 100644 --- a/Src/Syscall.rux +++ b/Src/Syscall.rux @@ -19,6 +19,11 @@ module Linux { const SYS_BRK: uint64 = 12u64; const SYS_GETPID: uint64 = 39u64; const SYS_EXIT: uint64 = 60u64; + const SYS_NANOSLEEP: uint64 = 35u64; + const SYS_CLOCK_GETTIME: uint64 = 228u64; + + const CLOCK_REALTIME: int32 = 0i32; + const CLOCK_MONOTONIC: int32 = 1i32; // mmap protection and mapping flags used by Mmap. const PROT_READ: int32 = 1i32; @@ -28,6 +33,12 @@ module Linux { const MAP_PRIVATE: int32 = 2i32; const MAP_ANONYMOUS: int32 = 32i32; + // Kernel-level time structures for low-level interaction. + struct Timespec { + tv_sec: int64; + tv_nsec: int64; + } + @[Import(lib: "rux-linux")] extern { // Provided by the Rux Linux ELF linker. These wrappers return raw @@ -103,6 +114,18 @@ module Linux { return Syscall1(SYS_BRK, addr as uint64); } + /* + Linux Time Functions (Passthrough to the Linux API) + */ + + func Nanosleep(req: *const Timespec, rem: *Timespec) -> int64 { + return Syscall2(SYS_NANOSLEEP, req as uint64, rem as uint64); + } + + func ClockGetTime(clockId: int32, tp: *Timespec) -> int64 { + return Syscall2(SYS_CLOCK_GETTIME, clockId as uint64, tp as uint64); + } + // Linux reports syscall errors as -errno in the range -4095..-1. func IsError(result: int64) -> bool { return result < 0i64 && result >= -4095i64;