silk.platform.linux.syscall.
Direct Linux system calls for programs built with no libc.
When to use#
Use RawLinux only in a raw Linux runtime, such as silk.platform.linux.start. A hosted program uses
the libc providers (the *_native modules and silk.platform.native) instead.
Details#
The module exists only on Linux on x86_64 or aarch64, with the libc profile set to none. The
syscall numbers (READ, WRITE, MMAP, MUNMAP and EXIT_GROUP) are different on
each architecture. Use the constants, not literal numbers.
RawLinux.read and RawLinux.write are safe wrappers for one read or write call on a
borrowed descriptor.
Errors#
A call returns the kernel word without change. A value from -4095 through -1 (as usize) is an
error. RawLinux.error gives 0 for success, or the positive error number, such as 4 for
EINTR.
Gotchas#
The calls do not read or set
errno. They do not retry an interrupted call.Each unsafe caller must prove the pointer, lifetime and resource contract of the syscall.
Import as RawLinux with import silk.platform.linux.syscall { RawLinux }.
Public declarations: 6.
RawLinux#
pub struct RawLinuxThe scope for raw Linux kernel operations on the selected target, for programs built with no libc.
When to use#
Use it only in a raw Linux runtime, such as silk.platform.linux.start. A hosted program uses the libc
providers (the *_native modules and silk.platform.native) instead.
Details#
It exists only on Linux on x86_64 or aarch64, with the libc profile set to none. A call
returns the kernel word without change. A value from -4095 through -1 (as usize) is an
error. RawLinux.error gives 0 for success, or the positive error number.
Gotchas#
The calls do not read or set
errno. They do not retry an interrupted call.Each unsafe caller must prove the pointer, lifetime and resource contract of the syscall.
Implementation RawLinux#
impl RawLinuxAssociated function syscall0#
pub unsafe fn syscall0(number: usize) -> usizeMakes Linux system call number with 0 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall1#
pub unsafe fn syscall1(number: usize, a1: usize) -> usizeMakes Linux system call number with 1 argument and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall2#
pub unsafe fn syscall2(number: usize, a1: usize, a2: usize) -> usizeMakes Linux system call number with 2 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall3#
pub unsafe fn syscall3(number: usize, a1: usize, a2: usize, a3: usize) -> usizeMakes Linux system call number with 3 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall4#
pub unsafe fn syscall4(number: usize, a1: usize, a2: usize, a3: usize, a4: usize) -> usizeMakes Linux system call number with 4 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall5#
pub unsafe fn syscall5(number: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) -> usizeMakes Linux system call number with 5 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscall6#
pub unsafe fn syscall6(
number: usize,
a1: usize,
a2: usize,
a3: usize,
a4: usize,
a5: usize,
a6: usize,
) -> usizeMakes Linux system call number with 6 arguments and returns the raw kernel word.
Gotchas#
The caller must prove the memory, lifetime and resource obligations of the syscall. An
error stays encoded in the result. The call does not read or set errno.
Associated function syscallNoReturn#
pub unsafe fn syscallNoReturn(number: usize, argument: usize) -> ()Makes Linux system call number with one argument, for a call that does not return.
Gotchas#
Use it only for a call such as exit_group. No cleanup runs after it.
Associated function pointer#
pub unsafe fn pointer(address: usize) -> ?[*]mut u8Makes a nullable byte pointer from a kernel address. It does not read memory.
Gotchas#
The address gives no ownership and no readable range. Prove that it is valid before each access.
READ#
pub const READ: usizeThe read syscall number: 0 on x86_64, 63 on aarch64.
WRITE#
pub const WRITE: usizeThe write syscall number: 1 on x86_64, 64 on aarch64.
MMAP#
pub const MMAP: usizeThe mmap syscall number: 9 on x86_64, 222 on aarch64.
MUNMAP#
pub const MUNMAP: usizeThe munmap syscall number: 11 on x86_64, 215 on aarch64.
EXIT_GROUP#
pub const EXIT_GROUP: usizeThe exit_group syscall number: 231 on x86_64, 94 on aarch64.
Implementation RawLinux#
impl RawLinuxAssociated function error#
pub fn error(result: usize) -> usizeReturns 0 for a successful result, or the positive kernel error number.
Details#
A result of usize.MAX - 4094 or more is an error. For example, usize.MAX (-1) gives 1
(EPERM), and usize.MAX - 3 (-4) gives 4 (EINTR).
Associated function read#
pub fn read(descriptor: usize, buffer: &mut [u8]) -> usizeReads into buffer from a borrowed descriptor with one read call.
Details#
Returns the raw kernel word: the byte count, 0 at end of input, or an encoded error. Use
RawLinux.error on it. An interrupted read returns EINTR. Bytes after the count keep
their old values. The call does not close the descriptor.
Associated function write#
pub fn write(descriptor: usize, buffer: &[u8]) -> usizeWrites buffer to a borrowed descriptor with one write call.
Details#
Returns the raw kernel word: the byte count, or an encoded error. Use RawLinux.error on
it. The count can be less than buffer.length, so loop until all bytes are written. The
call does not close the descriptor or keep the input.
Category: Native platform.
Profiles: aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu-no-libc.