@@ -13,10 +13,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
16- use anyhow:: { bail, Result } ;
1716use alloc:: vec:: Vec ;
1817use core:: slice:: from_raw_parts_mut;
1918
19+ use anyhow:: { bail, Result } ;
20+
2021pub struct InputDataSection {
2122 ptr : * mut u8 ,
2223 len : u64 ,
@@ -33,9 +34,7 @@ impl InputDataSection {
3334 {
3435 let shared_buffer_size = self . len as usize ;
3536
36- let idb = unsafe {
37- from_raw_parts_mut ( self . ptr , shared_buffer_size)
38- } ;
37+ let idb = unsafe { from_raw_parts_mut ( self . ptr , shared_buffer_size) } ;
3938
4039 if idb. is_empty ( ) {
4140 bail ! ( "Got a 0-size buffer in try_pop_shared_input_data_into" ) ;
@@ -48,14 +47,17 @@ impl InputDataSection {
4847 } ) ;
4948
5049 if stack_ptr_rel as usize > shared_buffer_size || stack_ptr_rel < 16 {
51- bail ! ( "Invalid stack pointer: {} in try_pop_shared_input_data_into" , stack_ptr_rel) ;
50+ bail ! (
51+ "Invalid stack pointer: {} in try_pop_shared_input_data_into" ,
52+ stack_ptr_rel
53+ ) ;
5254 }
5355
5456 // go back 8 bytes and read. This is the offset to the element on top of stack
5557 let last_element_offset_rel = u64:: from_le_bytes (
5658 match idb[ stack_ptr_rel as usize - 8 ..stack_ptr_rel as usize ] . try_into ( ) {
5759 Ok ( bytes) => bytes,
58- Err ( _) => bail ! ( "Invalid stack pointer in pop_shared_input_data_into" )
60+ Err ( _) => bail ! ( "Invalid stack pointer in pop_shared_input_data_into" ) ,
5961 } ,
6062 ) ;
6163
@@ -91,18 +93,18 @@ impl OutputDataSection {
9193
9294 pub fn push_shared_output_data ( & self , data : Vec < u8 > ) -> Result < ( ) > {
9395 let shared_buffer_size = self . len as usize ;
94- let odb: & mut [ u8 ] =
95- unsafe { from_raw_parts_mut ( self . ptr , shared_buffer_size) } ;
96+ let odb: & mut [ u8 ] = unsafe { from_raw_parts_mut ( self . ptr , shared_buffer_size) } ;
9697
9798 if odb. len ( ) < Self :: STACK_PTR_SIZE {
9899 bail ! ( "shared output buffer is too small" ) ;
99100 }
100101
101102 // get offset to next free address on the stack
102- let mut stack_ptr_rel: u64 = u64:: from_le_bytes ( match odb[ ..Self :: STACK_PTR_SIZE ] . try_into ( ) {
103- Ok ( bytes) => bytes,
104- Err ( _) => bail ! ( "failed to get stack pointer in shared output buffer" ) ,
105- } ) ;
103+ let mut stack_ptr_rel: u64 =
104+ u64:: from_le_bytes ( match odb[ ..Self :: STACK_PTR_SIZE ] . try_into ( ) {
105+ Ok ( bytes) => bytes,
106+ Err ( _) => bail ! ( "failed to get stack pointer in shared output buffer" ) ,
107+ } ) ;
106108
107109 // if stack_ptr_rel is 0, it means this is the first time we're using the output buffer, so
108110 // we want to offset it by 8 as to not overwrite the stack_ptr location.
@@ -152,4 +154,4 @@ impl From<(u64, u64)> for OutputDataSection {
152154 fn from ( ( ptr, len) : ( u64 , u64 ) ) -> Self {
153155 OutputDataSection :: new ( ptr as * mut u8 , len)
154156 }
155- }
157+ }
0 commit comments