Skip to content

Conversation

@febo
Copy link
Contributor

@febo febo commented Oct 10, 2025

Problem

While most syscall definitions are found in define-syscall, there are two that are defined in the crate where they are used to avoid bringing dependencies. This is not ideal when other crates need access to these syscalls.

Solution

Move the syscall definitions to define-syscall crate and use "generic" pointers.

@febo febo requested review from LucasSte and joncinque October 10, 2025 00:59
@febo febo marked this pull request as ready for review October 10, 2025 00:59
@febo febo added the breaking PR contains breaking changes label Oct 10, 2025
};
use {solana_define_syscall::define_syscall, solana_pubkey::Pubkey};

define_syscall!(fn sol_get_return_data(data: *mut u8, length: u64, program_id: *mut Pubkey) -> u64);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid a breaking change, we could consider just deprecating this definition.

};

#[cfg(target_os = "solana")]
define_syscall!(fn sol_get_processed_sibling_instruction(index: u64, meta: *mut ProcessedSiblingInstruction, program_id: *mut Pubkey, data: *mut u8, accounts: *mut AccountMeta) -> u64);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, we could consider just deprecating this definition instead.

joncinque
joncinque previously approved these changes Oct 10, 2025
Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! We're making a breaking change here anyway with #358, so let's just break the interface for these other syscalls too.

Also, since it's only function definitions, it shouldn't be too annoying for downstream users to deal with the change.

@febo
Copy link
Contributor Author

febo commented Oct 10, 2025

Looks great to me! We're making a breaking change here anyway with #358, so let's just break the interface for these other syscalls too.

Also, since it's only function definitions, it shouldn't be too annoying for downstream users to deal with the change.

For the cpi crate it is straightforward, there are no types there. For the instruction crate, we will need the semver trick since there are types there (e.g., Instruction, AccountMeta).

Another option is to write a wrapper function with the current signature over the new syscall definition.

pub fn sol_get_processed_sibling_instruction(
   index: u64,
   meta: *mut ProcessedSiblingInstruction,
   program_id: *mut Pubkey,
   data: *mut u8,
   accounts: *mut AccountMeta
) -> u64 {
   solana_define_syscall::definitions::sol_get_processed_sibling_instruction(
      index,
      meta as *mut u8,
      program_id as *mut u8,
      data,
      account_meta as *mut u8,
   )
}

@joncinque
Copy link
Collaborator

For the instruction crate, we will need the semver trick since there are types there (e.g., Instruction, AccountMeta). Another option is to write a wrapper function with the current signature over the new syscall definition.

Oh right, I forgot about that redefinition. Let's do a wrapping function now then, and deprecate it. I don't think anyone downstream is using it directly, but better safe than sorry.

LucasSte
LucasSte previously approved these changes Oct 10, 2025
buf.as_mut_ptr(),
buf.len() as u64,
&mut program_id,
&mut program_id as *mut _ as *mut u8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually need two casts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently yes, you can't go from &Pubkey to *mut u8 directly.

// - `address` (`[u8; 32]`): account address
// - `is_signer` (`u8`): `true` if the instruction requires a signature
// - `is_writable` (`u8`): `true` if the instruction requires the account to be writable
define_syscall!(fn sol_get_processed_sibling_instruction(index: u64, meta: *mut u8, program_id: *mut u8, data: *mut u8, accounts: *mut u8) -> u64);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a redefinition, but it looks unsafe to pass an array without telling the length. There is nothing to do about this, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree. At least all syscalls are marked unsafe. 😅

@febo febo dismissed stale reviews from LucasSte and joncinque via c52f09b October 10, 2025 23:02
@febo febo removed the breaking PR contains breaking changes label Oct 10, 2025
@febo
Copy link
Contributor Author

febo commented Oct 10, 2025

Added deprecated wrapping functions and removed the "breaking" label.

Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@joncinque joncinque merged commit 2cc9492 into anza-xyz:master Oct 16, 2025
26 checks passed
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.

3 participants