1- use crate :: error:: SysError ;
21use crate :: debug;
2+ use crate :: error:: SysError ;
3+ use core:: ffi:: c_void;
34use core:: marker:: PhantomData ;
45use core:: mem:: { size_of, zeroed} ;
5- use core:: ffi:: c_void;
66use core:: ptr:: null;
77
8- #[ link( name = "dl-c-impl" , kind= "static" ) ]
8+ #[ link( name = "dl-c-impl" , kind = "static" ) ]
99extern "C" {
10- fn ckb_dlopen2 ( dep_cell_hash : * const u8 , hash_type : u8 ,
11- aligned_addr : * mut u8 , aligned_size : usize , handle : * mut * const c_void ,
12- consumed_size : * mut usize ) -> isize ;
10+ fn ckb_dlopen2 (
11+ dep_cell_hash : * const u8 ,
12+ hash_type : u8 ,
13+ aligned_addr : * mut u8 ,
14+ aligned_size : usize ,
15+ handle : * mut * const c_void ,
16+ consumed_size : * mut usize ,
17+ ) -> isize ;
1318 fn ckb_dlsym ( handle : * const c_void , symbol : * const u8 ) -> usize ;
1419}
1520
@@ -91,7 +96,10 @@ impl Library {
9196 }
9297 let ptr = ckb_dlsym ( self . handle , s. as_ptr ( ) ) ;
9398 if ptr == 0 {
94- debug ! ( "warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}" , self . handle, symbol) ;
99+ debug ! (
100+ "warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}" ,
101+ self . handle, symbol
102+ ) ;
95103 None
96104 } else {
97105 Some ( Symbol :: new ( ptr) )
@@ -102,7 +110,6 @@ impl Library {
102110const RISCV_PGSIZE_SHIFT : usize = 12 ;
103111const RISCV_PGSIZE : usize = 1 << RISCV_PGSIZE_SHIFT ; // 4096
104112
105-
106113#[ repr( C ) ]
107114#[ repr( align( 4096 ) ) ]
108115pub struct CKBDLContext < T > ( T ) ;
@@ -126,14 +133,20 @@ impl<T> CKBDLContext<T> {
126133 }
127134
128135 unsafe {
129- let mut handle : * const c_void = null ( ) ;
130- let mut consumed_size : usize = 0 ;
131- let hash_type : u8 = 0 ;
136+ let mut handle: * const c_void = null ( ) ;
137+ let mut consumed_size: usize = 0 ;
138+ let hash_type: u8 = 0 ;
132139 let mut library = Library :: new ( ) ;
133140 let aligned_size = size;
134141 let aligned_addr = ( & mut self . 0 as * mut T ) . cast :: < u8 > ( ) . add ( offset) ;
135- let code = ckb_dlopen2 ( dep_cell_data_hash. as_ptr ( ) , hash_type, aligned_addr,
136- aligned_size, & mut handle as * mut * const c_void , & mut consumed_size as * mut usize ) ;
142+ let code = ckb_dlopen2 (
143+ dep_cell_data_hash. as_ptr ( ) ,
144+ hash_type,
145+ aligned_addr,
146+ aligned_size,
147+ & mut handle as * mut * const c_void ,
148+ & mut consumed_size as * mut usize ,
149+ ) ;
137150 if code != 0 {
138151 debug ! ( "warning, ckb_dlopen2 return {:?}" , code) ;
139152 return Err ( Error :: OpenFailed ( code) ) ;
0 commit comments