File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
sdk/pinocchio/src/entrypoint Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ //! Defines the middleware entrypoint, enabling a hot path to bypass
2+ //! entrypoint deserialization, ejecting to the cold path on failure.
3+ #[ macro_export]
4+ macro_rules! middleware_entrypoint {
5+ ( $hot: expr, $cold: expr) => {
6+ $crate:: middleware_entrypoint!( $hot, $cold, { $crate:: MAX_TX_ACCOUNTS } ) ;
7+ } ;
8+ ( $hot: expr, $cold: expr, $maximum: expr ) => {
9+
10+ #[ no_mangle]
11+ pub unsafe extern "C" fn entrypoint( input: * mut u8 ) -> u64 {
12+ if $hot( input) == 0 {
13+ return $crate:: SUCCESS
14+ }
15+
16+ const UNINIT : core:: mem:: MaybeUninit <$crate:: account_info:: AccountInfo > = core:: mem:: MaybeUninit :: <$crate:: account_info:: AccountInfo >:: uninit( ) ;
17+ // Create an array of uninitialized account infos.
18+ let mut accounts = [ UNINIT ; $maximum] ;
19+
20+ let ( program_id, count, instruction_data) = unsafe {
21+ $crate:: entrypoint:: deserialize:: <$maximum>( input, & mut accounts) } ;
22+
23+ // Call the program's entrypoint passing `count` account infos; we know that
24+ // they are initialized so we cast the pointer to a slice of `[AccountInfo]`.
25+ match $cold(
26+ & program_id,
27+ unsafe { core:: slice:: from_raw_parts( accounts. as_ptr( ) as _, count) } ,
28+ & instruction_data,
29+ ) {
30+ Ok ( ( ) ) => $crate:: SUCCESS ,
31+ Err ( error) => error. into( ) ,
32+ }
33+ }
34+ } ;
35+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ pub mod lazy;
55
66pub use lazy:: { InstructionContext , MaybeAccount } ;
77
8+ pub mod middleware;
9+
810#[ cfg( not( feature = "std" ) ) ]
911use core:: alloc:: { GlobalAlloc , Layout } ;
1012
You can’t perform that action at this time.
0 commit comments