Publish expected native program entrypoint in sdk/
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod loader_instruction;
|
pub mod loader_instruction;
|
||||||
|
pub mod native_program;
|
||||||
pub mod pubkey;
|
pub mod pubkey;
|
||||||
|
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
8
sdk/src/native_program.rs
Normal file
8
sdk/src/native_program.rs
Normal file
@ -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;
|
@ -7,6 +7,7 @@ use libloading::os::unix::*;
|
|||||||
use libloading::os::windows::*;
|
use libloading::os::windows::*;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
use solana_sdk::loader_instruction::LoaderInstruction;
|
||||||
|
use solana_sdk::native_program;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
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,
|
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 {
|
pub fn check_id(program_id: &Pubkey) -> bool {
|
||||||
program_id.as_ref() == NATIVE_LOADER_PROGRAM_ID
|
program_id.as_ref() == NATIVE_LOADER_PROGRAM_ID
|
||||||
}
|
}
|
||||||
@ -56,7 +53,11 @@ pub fn id() -> Pubkey {
|
|||||||
Pubkey::new(&NATIVE_LOADER_PROGRAM_ID)
|
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 {
|
if keyed_accounts[0].account.executable {
|
||||||
// dispatch it
|
// dispatch it
|
||||||
let name = keyed_accounts[0].account.userdata.clone();
|
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
|
// TODO linux tls bug can cause crash on dlclose(), workaround by never unloading
|
||||||
match Library::open(Some(&path), libc::RTLD_NODELETE | libc::RTLD_NOW) {
|
match Library::open(Some(&path), libc::RTLD_NODELETE | libc::RTLD_NOW) {
|
||||||
Ok(library) => unsafe {
|
Ok(library) => unsafe {
|
||||||
let entrypoint: Symbol<Entrypoint> = match library.get(ENTRYPOINT.as_bytes()) {
|
let entrypoint: Symbol<native_program::Entrypoint> =
|
||||||
Ok(s) => s,
|
match library.get(native_program::ENTRYPOINT.as_bytes()) {
|
||||||
Err(e) => {
|
Ok(s) => s,
|
||||||
warn!("{:?}: Unable to find {:?} in program", e, ENTRYPOINT);
|
Err(e) => {
|
||||||
return false;
|
warn!(
|
||||||
}
|
"{:?}: Unable to find {:?} in program",
|
||||||
};
|
e,
|
||||||
|
native_program::ENTRYPOINT
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
return entrypoint(&mut keyed_accounts[1..], ix_userdata);
|
return entrypoint(&mut keyed_accounts[1..], ix_userdata);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
Reference in New Issue
Block a user