Fix BPF parameter alignment to work regardless of target ABI (#21271) (#21299)

(cherry picked from commit 7e600bd451)

Co-authored-by: Ben Newhouse <newhouseb@gmail.com>
This commit is contained in:
mergify[bot]
2021-11-16 21:06:42 +00:00
committed by GitHub
parent 80c3591391
commit 40c86a0605
3 changed files with 21 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ use solana_rbpf::{aligned_memory::AlignedMemory, ebpf::HOST_ALIGN};
use solana_sdk::{
account::{ReadableAccount, WritableAccount},
bpf_loader_deprecated,
entrypoint::MAX_PERMITTED_DATA_INCREASE,
entrypoint::{MAX_PERMITTED_DATA_INCREASE, PARAMETER_ALIGNMENT},
instruction::InstructionError,
keyed_account::KeyedAccount,
pubkey::Pubkey,
@@ -227,7 +227,7 @@ pub fn serialize_parameters_aligned(
.map_err(|_| InstructionError::InvalidArgument)?;
v.resize(
MAX_PERMITTED_DATA_INCREASE
+ (v.write_index() as *const u8).align_offset(align_of::<u128>()),
+ (v.write_index() as *const u8).align_offset(PARAMETER_ALIGNMENT),
0,
)
.map_err(|_| InstructionError::InvalidArgument)?;