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

cpi: change unnecessary &mut MemoryMapping to &MemoryMapping #32643

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ type TranslatedAccounts<'a> = Vec<(IndexOfAccount, Option<CallerAccount<'a>>)>;
trait SyscallInvokeSigned {
fn translate_instruction(
addr: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<StableInstruction, Error>;
fn translate_accounts<'a>(
Expand All @@ -266,14 +266,14 @@ trait SyscallInvokeSigned {
account_infos_addr: u64,
account_infos_len: u64,
is_loader_deprecated: bool,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<TranslatedAccounts<'a>, Error>;
fn translate_signers(
program_id: &Pubkey,
signers_seeds_addr: u64,
signers_seeds_len: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &InvokeContext,
) -> Result<Vec<Pubkey>, Error>;
}
Expand Down Expand Up @@ -305,7 +305,7 @@ declare_syscall!(
impl SyscallInvokeSigned for SyscallInvokeSignedRust {
fn translate_instruction(
addr: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<StableInstruction, Error> {
let ix = translate_type::<StableInstruction>(
Expand Down Expand Up @@ -359,7 +359,7 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
account_infos_addr: u64,
account_infos_len: u64,
is_loader_deprecated: bool,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<TranslatedAccounts<'a>, Error> {
let (account_infos, account_info_keys) = translate_account_infos(
Expand Down Expand Up @@ -387,7 +387,7 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
program_id: &Pubkey,
signers_seeds_addr: u64,
signers_seeds_len: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &InvokeContext,
) -> Result<Vec<Pubkey>, Error> {
let mut signers = Vec::new();
Expand Down Expand Up @@ -516,7 +516,7 @@ declare_syscall!(
impl SyscallInvokeSigned for SyscallInvokeSignedC {
fn translate_instruction(
addr: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<StableInstruction, Error> {
let ix_c = translate_type::<SolInstruction>(
Expand Down Expand Up @@ -592,7 +592,7 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
account_infos_addr: u64,
account_infos_len: u64,
is_loader_deprecated: bool,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<TranslatedAccounts<'a>, Error> {
let (account_infos, account_info_keys) = translate_account_infos(
Expand Down Expand Up @@ -620,7 +620,7 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
program_id: &Pubkey,
signers_seeds_addr: u64,
signers_seeds_len: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &InvokeContext,
) -> Result<Vec<Pubkey>, Error> {
if signers_seeds_len > 0 {
Expand Down Expand Up @@ -673,7 +673,7 @@ fn translate_account_infos<'a, T, F>(
account_infos_addr: u64,
account_infos_len: u64,
key_addr: F,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
invoke_context: &mut InvokeContext,
) -> Result<(&'a [T], Vec<&'a Pubkey>), Error>
where
Expand Down Expand Up @@ -929,7 +929,7 @@ fn cpi_common<S: SyscallInvokeSigned>(
account_infos_len: u64,
signers_seeds_addr: u64,
signers_seeds_len: u64,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
) -> Result<u64, Error> {
// CPI entry.
//
Expand Down Expand Up @@ -1118,7 +1118,7 @@ fn update_callee_account(
// changes.
fn update_caller_account(
invoke_context: &InvokeContext,
memory_mapping: &mut MemoryMapping,
memory_mapping: &MemoryMapping,
is_loader_deprecated: bool,
caller_account: &mut CallerAccount,
callee_account: &mut BorrowedAccount<'_>,
Expand Down Expand Up @@ -1368,12 +1368,11 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();
let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let ins = SyscallInvokeSignedRust::translate_instruction(
vm_addr,
&mut memory_mapping,
&memory_mapping,
&mut invoke_context,
)
.unwrap();
Expand Down Expand Up @@ -1405,14 +1404,13 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();
let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let signers = SyscallInvokeSignedRust::translate_signers(
&program_id,
vm_addr,
1,
&mut memory_mapping,
&memory_mapping,
&invoke_context,
)
.unwrap();
Expand Down Expand Up @@ -1491,7 +1489,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(
let memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
Expand All @@ -1509,7 +1507,7 @@ mod tests {

update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand Down Expand Up @@ -1549,7 +1547,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(
let memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
Expand Down Expand Up @@ -1577,7 +1575,7 @@ mod tests {

update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand All @@ -1602,7 +1600,7 @@ mod tests {
.unwrap();
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand All @@ -1619,7 +1617,7 @@ mod tests {
assert!(matches!(
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand All @@ -1635,7 +1633,7 @@ mod tests {
.unwrap();
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand Down Expand Up @@ -1674,7 +1672,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(
let memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
Expand Down Expand Up @@ -1707,7 +1705,7 @@ mod tests {

update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand Down Expand Up @@ -1772,7 +1770,7 @@ mod tests {
.unwrap();
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand All @@ -1791,7 +1789,7 @@ mod tests {
assert!(matches!(
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand All @@ -1807,7 +1805,7 @@ mod tests {
.unwrap();
update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand Down Expand Up @@ -1845,7 +1843,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(
let memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
Expand All @@ -1869,7 +1867,7 @@ mod tests {

update_caller_account(
&invoke_context,
&mut memory_mapping,
&memory_mapping,
false,
&mut caller_account,
&mut callee_account,
Expand Down Expand Up @@ -2168,8 +2166,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();
let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let accounts = SyscallInvokeSignedRust::translate_accounts(
&[
Expand All @@ -2192,7 +2189,7 @@ mod tests {
vm_addr,
1,
false,
&mut memory_mapping,
&memory_mapping,
&mut invoke_context,
)
.unwrap();
Expand Down