-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SOL] Implement syscall instruction #121
[SOL] Implement syscall instruction #121
Conversation
; Syscall declaration in Rust: | ||
; | ||
; #[no_mangle] | ||
; pub unsafe fn rust_declaration(b: u64) -> u32 { | ||
; let syscall : extern "C" fn(b: u64) -> u32 = core::mem::transmute(60u64); | ||
; return syscall(b); | ||
; } | ||
; The following is the unoptimized output from rustc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some circumstances, specially when we build the code with -O0
, the front end may emit a callx
. Instead of creating a peephole or forcing optimizations in the backend, I decided to add the correct declaration example in both C and Rust.
These examples generate LLVM-IR code that even when unoptimized will create a syscall
instruction.
26f146b
into
anza-xyz:solana-rustc/18.1-2024-05-19
* Implement static syscalls * Rename syscall and return * Remove external call from v3 and use pointer value directly
* Implement static syscalls * Rename syscall and return * Remove external call from v3 and use pointer value directly
SIMD-0178 introduces a
syscall
instruction which comprises the opcode0x95
and an immediate value. The value is supposed to be an integer greater than zero, representing the syscall we want to invoke.Following the external call scheme on BPF, we'll consider a syscall any call to a static address.
The reason behind this design was to avoid compile work when introducing of a syscall. Identifying syscalls by their symbol name would required either a hard coded lookup table or loading an external file. The former case would require a toolchain recompilation and the latter a new platform tools release simply to add a syscall, increasing the work overhead.
The front-end must specify the syscall header as a constant function pointer and assign to it the corresponding syscall number. This is similar to existing scheme for static syscalls, except that we won't be using the murmur32 hash anymore. Syscalls should be declared as the following example: