Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Src/Platform.rux
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ module Platform {
Munmap,
Read,
Syscall1,
Syscall2,
Stdin,
Stdout,
Write,
MAP_ANONYMOUS,
MAP_PRIVATE,
PROT_READ,
PROT_WRITE,
SYS_NANOSLEEP,
SYS_CLOCK_GETTIME,
SYS_EXIT
};

Expand Down
23 changes: 23 additions & 0 deletions Src/Syscall.rux
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down