Skip to content

Commit

Permalink
Handle dynamic program dlopen failures gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 13, 2018
1 parent 5ffd84c commit f1e6b76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/dynamic_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libc;
use libloading::os::unix::*;
#[cfg(windows)]
use libloading::os::windows::*;
use result::Result;

use solana_program_interface::account::KeyedAccount;
use solana_program_interface::pubkey::Pubkey;
Expand Down Expand Up @@ -80,12 +81,12 @@ pub enum DynamicProgram {
}

impl DynamicProgram {
pub fn new_native(name: String) -> Self {
pub fn new_native(name: String) -> Result<Self> {
// create native program
let path = ProgramPath::Native {}.create(&name);
// TODO linux tls bug can cause crash on dlclose, workaround by never unloading
let library = Library::open(Some(path), libc::RTLD_NODELETE | libc::RTLD_NOW).unwrap();
DynamicProgram::Native { name, library }
let library = Library::open(Some(path), libc::RTLD_NODELETE | libc::RTLD_NOW)?;
Ok(DynamicProgram::Native { name, library })
}

pub fn new_bpf_from_file(name: String) -> Self {
Expand Down
8 changes: 7 additions & 1 deletion src/system_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ impl SystemProgram {
}
SystemProgram::Load { program_id, name } => {
let mut hashmap = loaded_programs.write().unwrap();
hashmap.insert(program_id, DynamicProgram::new_native(name));
hashmap.insert(
program_id,
DynamicProgram::new_native(name).map_err(|err| {
warn!("SystemProgram::Load failure: {:?}", err);
Error::InvalidArgument
})?,
);
}
}
Ok(())
Expand Down

0 comments on commit f1e6b76

Please sign in to comment.