Align host addresses (#11384)
* Align host addresses * support new program abi * update epoch rollout * Enforce aligned pointers in cross-program invocations
This commit is contained in:
@ -1 +1 @@
|
||||
crate::declare_id!("BPFLoader1111111111111111111111111111111111");
|
||||
crate::declare_id!("BPFLoader2111111111111111111111111111111111");
|
||||
|
1
sdk/src/bpf_loader_deprecated.rs
Normal file
1
sdk/src/bpf_loader_deprecated.rs
Normal file
@ -0,0 +1 @@
|
||||
crate::declare_id!("BPFLoader1111111111111111111111111111111111");
|
@ -76,9 +76,18 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
let is_writable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
offset += 4; // padding
|
||||
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let lamports = Rc::new(RefCell::new(&mut *(input.add(offset) as *mut u64)));
|
||||
offset += size_of::<u64>();
|
||||
@ -92,12 +101,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
}));
|
||||
offset += data_len;
|
||||
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
offset += 16 - (offset % 16); // padding
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rent_epoch = *(input.add(offset) as *const u64);
|
||||
@ -114,6 +118,8 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
rent_epoch,
|
||||
});
|
||||
} else {
|
||||
offset += 7; // padding
|
||||
|
||||
// Duplicate account, clone the original
|
||||
accounts.push(accounts[dup_info as usize].clone());
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub type LoaderEntrypoint = unsafe extern "C" fn(
|
||||
#[rustversion::since(1.46.0)]
|
||||
#[macro_export]
|
||||
macro_rules! declare_name {
|
||||
($name:ident) => {
|
||||
($name:ident, $filename:ident, $id:path) => {
|
||||
#[macro_export]
|
||||
macro_rules! $name {
|
||||
() => {
|
||||
@ -66,8 +66,8 @@ macro_rules! declare_name {
|
||||
// `respan!` respans the path `$crate::id`, which we then call (hence the extra
|
||||
// parens)
|
||||
(
|
||||
stringify!($name).to_string(),
|
||||
::solana_sdk::respan!($crate::id, $name)(),
|
||||
stringify!($filename).to_string(),
|
||||
::solana_sdk::respan!($crate::$id, $name)(),
|
||||
)
|
||||
};
|
||||
}
|
||||
@ -77,11 +77,11 @@ macro_rules! declare_name {
|
||||
#[rustversion::not(since(1.46.0))]
|
||||
#[macro_export]
|
||||
macro_rules! declare_name {
|
||||
($name:ident) => {
|
||||
($name:ident, $filename:ident, $id:path) => {
|
||||
#[macro_export]
|
||||
macro_rules! $name {
|
||||
() => {
|
||||
(stringify!($name).to_string(), $crate::id())
|
||||
(stringify!($filename).to_string(), $crate::$id())
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -90,8 +90,10 @@ macro_rules! declare_name {
|
||||
/// Convenience macro to declare a native program
|
||||
///
|
||||
/// bs58_string: bs58 string representation the program's id
|
||||
/// name: Name of the program, must match the library name in Cargo.toml
|
||||
/// name: Name of the program
|
||||
/// filename: must match the library name in Cargo.toml
|
||||
/// entrypoint: Program's entrypoint, must be of `type Entrypoint`
|
||||
/// id: Path to the program id access function, used if not called in `src/lib`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -159,7 +161,7 @@ macro_rules! declare_name {
|
||||
macro_rules! declare_program(
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr) => (
|
||||
$crate::declare_id!($bs58_string);
|
||||
$crate::declare_name!($name);
|
||||
$crate::declare_name!($name, $name, id);
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn $name(
|
||||
@ -174,12 +176,16 @@ macro_rules! declare_program(
|
||||
|
||||
/// Same as declare_program but for native loaders
|
||||
#[macro_export]
|
||||
macro_rules! declare_loader(
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr) => (
|
||||
macro_rules! declare_loader {
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr) => {
|
||||
$crate::declare_loader!($bs58_string, $name, $entrypoint, $name, id);
|
||||
};
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr, $filename:ident) => {
|
||||
$crate::declare_loader!($bs58_string, $name, $entrypoint, $filename, id);
|
||||
};
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr, $filename:ident, $id:path) => {
|
||||
$crate::declare_id!($bs58_string);
|
||||
$crate::declare_name!($name);
|
||||
|
||||
|
||||
$crate::declare_name!($name, $filename, $id);
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn $name(
|
||||
@ -190,8 +196,8 @@ macro_rules! declare_loader(
|
||||
) -> Result<(), $crate::instruction::InstructionError> {
|
||||
$entrypoint(program_id, keyed_accounts, instruction_data, invoke_context)
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
pub type ProcessInstruction = fn(&Pubkey, &[KeyedAccount], &[u8]) -> Result<(), InstructionError>;
|
||||
|
||||
|
@ -12,6 +12,7 @@ pub mod abi_example;
|
||||
pub mod account;
|
||||
pub mod account_utils;
|
||||
pub mod bpf_loader;
|
||||
pub mod bpf_loader_deprecated;
|
||||
pub mod clock;
|
||||
pub mod commitment_config;
|
||||
pub mod decode_error;
|
||||
|
Reference in New Issue
Block a user