diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index d8b468ddd..8a1c8cf3a 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -1,5 +1,6 @@ pub mod account; pub mod loader_instruction; +pub mod native_program; pub mod pubkey; extern crate bincode; diff --git a/sdk/src/native_program.rs b/sdk/src/native_program.rs new file mode 100644 index 000000000..2b9bbf3ec --- /dev/null +++ b/sdk/src/native_program.rs @@ -0,0 +1,8 @@ +use account::KeyedAccount; + +// All native programs export a symbol named process() +pub const ENTRYPOINT: &str = "process"; + +// Native program ENTRYPOINT prototype +pub type Entrypoint = + unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool; diff --git a/src/native_loader.rs b/src/native_loader.rs index db63b12c0..2daf45943 100644 --- a/src/native_loader.rs +++ b/src/native_loader.rs @@ -7,6 +7,7 @@ use libloading::os::unix::*; use libloading::os::windows::*; use solana_sdk::account::KeyedAccount; use solana_sdk::loader_instruction::LoaderInstruction; +use solana_sdk::native_program; use solana_sdk::pubkey::Pubkey; use std::env; use std::path::PathBuf; @@ -44,10 +45,6 @@ const NATIVE_LOADER_PROGRAM_ID: [u8; 32] = [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; -// All native programs export a symbol named process() -const ENTRYPOINT: &str = "process"; -type Entrypoint = unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool; - pub fn check_id(program_id: &Pubkey) -> bool { program_id.as_ref() == NATIVE_LOADER_PROGRAM_ID } @@ -56,7 +53,11 @@ pub fn id() -> Pubkey { Pubkey::new(&NATIVE_LOADER_PROGRAM_ID) } -pub fn process_instruction(keyed_accounts: &mut [KeyedAccount], ix_userdata: &[u8]) -> bool { +pub fn process_instruction( + keyed_accounts: &mut [KeyedAccount], + ix_userdata: &[u8], + tick_height: u64, +) -> bool { if keyed_accounts[0].account.executable { // dispatch it let name = keyed_accounts[0].account.userdata.clone(); @@ -72,13 +73,18 @@ pub fn process_instruction(keyed_accounts: &mut [KeyedAccount], ix_userdata: &[u // TODO linux tls bug can cause crash on dlclose(), workaround by never unloading match Library::open(Some(&path), libc::RTLD_NODELETE | libc::RTLD_NOW) { Ok(library) => unsafe { - let entrypoint: Symbol = match library.get(ENTRYPOINT.as_bytes()) { - Ok(s) => s, - Err(e) => { - warn!("{:?}: Unable to find {:?} in program", e, ENTRYPOINT); - return false; - } - }; + let entrypoint: Symbol = + match library.get(native_program::ENTRYPOINT.as_bytes()) { + Ok(s) => s, + Err(e) => { + warn!( + "{:?}: Unable to find {:?} in program", + e, + native_program::ENTRYPOINT + ); + return false; + } + }; return entrypoint(&mut keyed_accounts[1..], ix_userdata); }, Err(e) => {