Open antoyo opened 6 years ago
Could you propose a way to do it?
you could start with the syscall() library call, to get all the functionality with some overhead
and then use inline ASM (in inline C) on a per-architecture basis to drop the overhead.
I would expect that one of the libc-lite libraries already does this, though.
For instance, of x86_64, the code would look like:
%{^
long syscall1(long value) {
long result;
__asm__("mov %1, %%rax;"
"syscall"
: "=r"(result)
:"r"(value)
:"%rax", "%rdi");
return result;
}
long syscall2(long value1, long value2) {
long result;
__asm__("mov %1, %%rax;"
"mov %2, %%rdi;"
"syscall"
: "=r"(result)
:"r"(value1), "r"(value2)
:"%rax", "%rdi");
return result;
}
%}
extern fn syscall1(value: lint): lint =
"ext#"
extern fn syscall2(value1: lint, value2: lint): lint =
"ext#"
(or perhaps using variadics)
cc @master-q - seems like may be of interest
Hi. Could you please add a way to do system calls in the language? That would be useful when you want to do low-level stuff without using C. Thanks.