Skip to content

Commit

Permalink
Gate pointer alignment enforcement (#12176)
Browse files Browse the repository at this point in the history
(cherry picked from commit ae7b15f)

# Conflicts:
#	programs/bpf/tests/programs.rs
  • Loading branch information
jackcmay authored and mergify-bot committed Sep 11, 2020
1 parent 640bf70 commit c7af4db
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 100 deletions.
6 changes: 3 additions & 3 deletions programs/bpf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use solana_runtime::{
loader_utils::load_program,
};
use solana_sdk::{
account::{create_keyed_readonly_accounts, Account, KeyedAccount},
account::{create_keyed_readonly_accounts, Account},
bpf_loader, bpf_loader_deprecated,
client::SyncClient,
entrypoint::SUCCESS,
Expand Down Expand Up @@ -92,12 +92,12 @@ fn bench_program_alu(bencher: &mut Bencher) {
.write_u64::<LittleEndian>(ARMSTRONG_LIMIT)
.unwrap();
inner_iter.write_u64::<LittleEndian>(0).unwrap();
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();

let elf = load_elf("bench_alu").unwrap();
let (mut vm, _) =
solana_bpf_loader_program::create_vm(&bpf_loader::id(), &elf, &[], &mut invoke_context)
.unwrap();
solana_bpf_loader_program::create_vm(&loader_id, &elf, &[], &mut invoke_context).unwrap();

println!("Interpreted:");
assert_eq!(
Expand Down
40 changes: 40 additions & 0 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,46 @@ fn load_bpf_program(
load_program(bank_client, payer_keypair, loader_id, elf)
}

<<<<<<< HEAD
=======
fn run_program(
name: &str,
program_id: &Pubkey,
parameter_accounts: &[KeyedAccount],
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
let path = create_bpf_path(name);
let mut file = File::open(path).unwrap();

let mut program_account = Account::default();
file.read_to_end(&mut program_account.data).unwrap();

let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
let (mut vm, heap_region) = create_vm(
&loader_id,
&program_account.data,
parameter_accounts,
&mut invoke_context,
)
.unwrap();
let mut parameter_bytes = serialize_parameters(
&bpf_loader::id(),
program_id,
parameter_accounts,
&instruction_data,
)
.unwrap();
assert_eq!(
SUCCESS,
vm.execute_program(parameter_bytes.as_mut_slice(), &[], &[heap_region.clone()])
.unwrap()
);
deserialize_parameters(&bpf_loader::id(), parameter_accounts, &parameter_bytes).unwrap();
Ok(vm.get_total_instruction_count())
}

>>>>>>> ae7b15f06... Gate pointer alignment enforcement (#12176)
#[test]
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
fn test_program_bpf_sanity() {
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum BPFError {
impl UserDefinedError for BPFError {}

pub fn create_vm<'a>(
loader_id: &Pubkey,
loader_id: &'a Pubkey,
prog: &'a [u8],
parameter_accounts: &'a [KeyedAccount<'a>],
invoke_context: &'a mut dyn InvokeContext,
Expand Down
Loading

0 comments on commit c7af4db

Please sign in to comment.