Remove Native Loader's use of GenericError (#8285)
This commit is contained in:
parent
a0bcbf70d5
commit
940519ea5a
|
@ -4349,6 +4349,8 @@ dependencies = [
|
|||
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -4365,6 +4367,7 @@ dependencies = [
|
|||
"solana-vote-program 0.24.0",
|
||||
"sys-info 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -14,26 +14,30 @@ bv = { version = "0.11.0", features = ["serde"] }
|
|||
byteorder = "1.3.2"
|
||||
fnv = "1.0.6"
|
||||
fs_extra = "1.1.0"
|
||||
itertools = "0.8.2"
|
||||
libc = "0.2.66"
|
||||
libloading = "0.5.2"
|
||||
log = "0.4.8"
|
||||
memmap = "0.7.0"
|
||||
num-derive = { version = "0.3" }
|
||||
num-traits = { version = "0.2" }
|
||||
rand = "0.6.5"
|
||||
rayon = "1.2.0"
|
||||
serde = { version = "1.0.104", features = ["rc"] }
|
||||
serde_derive = "1.0.103"
|
||||
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "0.24.0" }
|
||||
solana-logger = { path = "../logger", version = "0.24.0" }
|
||||
solana-measure = { path = "../measure", version = "0.24.0" }
|
||||
solana-metrics = { path = "../metrics", version = "0.24.0" }
|
||||
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "0.24.0" }
|
||||
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.24.0" }
|
||||
solana-sdk = { path = "../sdk", version = "0.24.0" }
|
||||
solana-stake-program = { path = "../programs/stake", version = "0.24.0" }
|
||||
solana-storage-program = { path = "../programs/storage", version = "0.24.0" }
|
||||
solana-vote-program = { path = "../programs/vote", version = "0.24.0" }
|
||||
sys-info = "0.5.9"
|
||||
tempfile = "3.1.0"
|
||||
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.24.0" }
|
||||
itertools = "0.8.2"
|
||||
thiserror = "1.0"
|
||||
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
|
|
|
@ -5,10 +5,28 @@ use libloading::os::unix::*;
|
|||
#[cfg(windows)]
|
||||
use libloading::os::windows::*;
|
||||
use log::*;
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use solana_sdk::{
|
||||
account::KeyedAccount, entrypoint_native, instruction::InstructionError, pubkey::Pubkey,
|
||||
account::KeyedAccount, entrypoint_native, instruction::InstructionError,
|
||||
program_utils::DecodeError, pubkey::Pubkey,
|
||||
};
|
||||
use std::{env, path::PathBuf, str};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug, Serialize, Clone, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
pub enum NativeLoaderError {
|
||||
#[error("Entrypoint name in the account data is not a valid UTF-8 string")]
|
||||
InvalidEntrypointName,
|
||||
#[error("Entrypoint was not found in the module")]
|
||||
EntrypointNotFound,
|
||||
#[error("Failed to load the module")]
|
||||
FailedToLoad,
|
||||
}
|
||||
impl<T> DecodeError<T> for NativeLoaderError {
|
||||
fn type_of() -> &'static str {
|
||||
"NativeLoaderError"
|
||||
}
|
||||
}
|
||||
|
||||
/// Dynamic link library prefixes
|
||||
#[cfg(unix)]
|
||||
|
@ -79,7 +97,7 @@ pub fn invoke_entrypoint(
|
|||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
warn!("Invalid UTF-8 sequence: {}", e);
|
||||
return Err(InstructionError::GenericError);
|
||||
return Err(NativeLoaderError::InvalidEntrypointName.into());
|
||||
}
|
||||
};
|
||||
trace!("Call native {:?}", name);
|
||||
|
@ -95,7 +113,7 @@ pub fn invoke_entrypoint(
|
|||
name.as_bytes(),
|
||||
e
|
||||
);
|
||||
return Err(InstructionError::GenericError);
|
||||
return Err(NativeLoaderError::EntrypointNotFound.into());
|
||||
}
|
||||
};
|
||||
let ret = entrypoint(program_id, params, instruction_data);
|
||||
|
@ -106,8 +124,8 @@ pub fn invoke_entrypoint(
|
|||
ret
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Unable to load: {:?}", e);
|
||||
Err(InstructionError::GenericError)
|
||||
warn!("Failed to load: {:?}", e);
|
||||
Err(NativeLoaderError::FailedToLoad.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue