Skip to content
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

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

LucasSte
Copy link
Collaborator

@LucasSte LucasSte commented Dec 17, 2024

SIMD-0178 introduces a syscall instruction which comprises the opcode 0x95 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:

int (*const syscall)(int a, int b) = (void*)(syscall_number);

@LucasSte LucasSte marked this pull request as ready for review December 17, 2024 23:43
@LucasSte LucasSte requested review from Lichtso and dmakarov December 17, 2024 23:44
@LucasSte LucasSte marked this pull request as draft December 18, 2024 16:55
Comment on lines +29 to +36
; 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:
Copy link
Collaborator Author

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.

@LucasSte LucasSte marked this pull request as ready for review December 18, 2024 19:27
@LucasSte LucasSte merged commit 26f146b into anza-xyz:solana-rustc/18.1-2024-05-19 Dec 19, 2024
15 checks passed
@LucasSte LucasSte deleted the syscall-1 branch December 19, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants