@@ -1099,179 +1099,6 @@ pub extern "C" fn componentize_py_to_canon_handle(
10991099    } 
11001100} 
11011101
1102- // TODO: Update to the latest `wit-component`, which has a `use_built_in_libdl` option that makes the following 
1103- // unecessary: 
1104- pub  mod  dl { 
1105-     use  std:: { 
1106-         ffi:: { c_char,  c_int,  c_void,  CStr } , 
1107-         ptr,  slice, 
1108-     } ; 
1109- 
1110-     const  RTLD_LAZY :  c_int  = 1 ; 
1111-     const  RTLD_NOW :  c_int  = 2 ; 
1112- 
1113-     const  RTLD_NEXT :  isize  = -1 ; 
1114-     const  RTLD_DEFAULT :  isize  = 0 ; 
1115- 
1116-     #[ repr( C ) ]  
1117-     pub  struct  Name  { 
1118-         length :  u32 , 
1119-         data :  * const  u8 , 
1120-     } 
1121- 
1122-     #[ repr( C ) ]  
1123-     pub  struct  Symbol  { 
1124-         name :  Name , 
1125-         address :  * const  c_void , 
1126-     } 
1127- 
1128-     #[ repr( C ) ]  
1129-     pub  struct  Symbols  { 
1130-         count :  u32 , 
1131-         symbols :  * const  Symbol , 
1132-     } 
1133- 
1134-     #[ repr( C ) ]  
1135-     pub  struct  Library  { 
1136-         name :  Name , 
1137-         symbols :  Symbols , 
1138-     } 
1139- 
1140-     #[ repr( C ) ]  
1141-     pub  struct  Libraries  { 
1142-         count :  u32 , 
1143-         libraries :  * const  Library , 
1144-     } 
1145- 
1146-     struct  Pointer < T > ( * const  T ) ; 
1147- 
1148-     unsafe  impl < T >  Sync  for  Pointer < T >  { } 
1149- 
1150-     static  mut  ERROR :  Pointer < c_char >  = Pointer ( ptr:: null ( ) ) ; 
1151-     static  mut  LIBRARIES :  Pointer < Libraries >  = Pointer ( ptr:: null ( ) ) ; 
1152- 
1153-     unsafe  fn  invalid_handle ( library :  * const  c_void )  -> bool  { 
1154-         if  LIBRARIES . 0 . is_null ( )  { 
1155-             panic ! ( 
1156-                 "`__wasm_set_libraries` should have been called during \  
1157- 
1158-             ) ; 
1159-         } 
1160- 
1161-         let  library = library as  * const  Library ; 
1162-         if  ( 0 ..( * LIBRARIES . 0 ) . count ) . any ( |index| { 
1163-             ( * LIBRARIES . 0 ) 
1164-                 . libraries 
1165-                 . add ( usize:: try_from ( index) . unwrap ( ) ) 
1166-                 == library
1167-         } )  { 
1168-             false 
1169-         }  else  { 
1170-             ERROR . 0  = b"invalid library handle\0 "  as  * const  _  as  _ ; 
1171-             true 
1172-         } 
1173-     } 
1174- 
1175-     /// # Safety 
1176- /// TODO 
1177- #[ no_mangle]  
1178-     pub  unsafe  extern  "C"  fn  dlclose ( library :  * mut  c_void )  -> c_int  { 
1179-         if  invalid_handle ( library)  { 
1180-             -1 
1181-         }  else  { 
1182-             0 
1183-         } 
1184-     } 
1185- 
1186-     /// # Safety 
1187- /// TODO 
1188- #[ no_mangle]  
1189-     pub  unsafe  extern  "C"  fn  dlerror ( )  -> * const  c_char  { 
1190-         let  value = ERROR . 0 ; 
1191-         ERROR . 0  = ptr:: null ( ) ; 
1192-         value
1193-     } 
1194- 
1195-     /// # Safety 
1196- /// TODO 
1197- #[ no_mangle]  
1198-     pub  unsafe  extern  "C"  fn  dlopen ( name :  * const  c_char ,  flags :  c_int )  -> * const  c_void  { 
1199-         if  LIBRARIES . 0 . is_null ( )  { 
1200-             panic ! ( 
1201-                 "`__wasm_set_libraries` should have been called during \  
1202- 
1203-             ) ; 
1204-         } 
1205- 
1206-         if  ( flags &  !( RTLD_LAZY  | RTLD_NOW ) )  != 0  { 
1207-             // TODO 
1208-             ERROR . 0  = b"dlopen flags not yet supported\0 "  as  * const  _  as  _ ; 
1209-             return  ptr:: null ( ) ; 
1210-         } 
1211- 
1212-         let  name = CStr :: from_ptr ( name) ; 
1213-         let  name = name. to_bytes ( ) ; 
1214-         let  libraries = slice:: from_raw_parts ( 
1215-             ( * LIBRARIES . 0 ) . libraries , 
1216-             usize:: try_from ( ( * LIBRARIES . 0 ) . count ) . unwrap ( ) , 
1217-         ) ; 
1218-         if  let  Ok ( index)  = libraries. binary_search_by ( |library| { 
1219-             slice:: from_raw_parts ( 
1220-                 library. name . data , 
1221-                 usize:: try_from ( library. name . length ) . unwrap ( ) , 
1222-             ) 
1223-             . cmp ( name) 
1224-         } )  { 
1225-             & libraries[ index]  as  * const  _  as  _ 
1226-         }  else  { 
1227-             ERROR . 0  = "library not found\0 "  as  * const  _  as  _ ; 
1228-             ptr:: null ( ) 
1229-         } 
1230-     } 
1231- 
1232-     /// # Safety 
1233- /// TODO 
1234- #[ no_mangle]  
1235-     pub  unsafe  extern  "C"  fn  dlsym ( library :  * const  c_void ,  name :  * const  c_char )  -> * const  c_void  { 
1236-         if  library as  isize  == RTLD_NEXT  || library as  isize  == RTLD_DEFAULT  { 
1237-             // TODO 
1238-             ERROR . 0  = "dlsym RTLD_NEXT and RTLD_DEFAULT not yet supported\0 "  as  * const  _  as  _ ; 
1239-             return  ptr:: null ( ) ; 
1240-         } 
1241- 
1242-         if  invalid_handle ( library)  { 
1243-             return  ptr:: null ( ) ; 
1244-         } 
1245- 
1246-         let  library = library as  * const  Library ; 
1247-         let  name = CStr :: from_ptr ( name) ; 
1248-         let  name = name. to_bytes ( ) ; 
1249-         let  symbols = slice:: from_raw_parts ( 
1250-             ( * library) . symbols . symbols , 
1251-             usize:: try_from ( ( * library) . symbols . count ) . unwrap ( ) , 
1252-         ) ; 
1253-         if  let  Ok ( index)  = symbols. binary_search_by ( |symbol| { 
1254-             slice:: from_raw_parts ( 
1255-                 symbol. name . data , 
1256-                 usize:: try_from ( symbol. name . length ) . unwrap ( ) , 
1257-             ) 
1258-             . cmp ( name) 
1259-         } )  { 
1260-             symbols[ index] . address 
1261-         }  else  { 
1262-             ERROR . 0  = "library not found\0 "  as  * const  _  as  _ ; 
1263-             ptr:: null ( ) 
1264-         } 
1265-     } 
1266- 
1267-     /// # Safety 
1268- /// TODO 
1269- #[ no_mangle]  
1270-     pub  unsafe  extern  "C"  fn  __wasm_set_libraries ( libraries :  * const  Libraries )  { 
1271-         LIBRARIES . 0  = libraries; 
1272-     } 
1273- } 
1274- 
12751102// As of this writing, recent Rust `nightly` builds include a version of the `libc` crate that expects `wasi-libc` 
12761103// to define the following global variables, but `wasi-libc` defines them as preprocessor constants which aren't 
12771104// visible at link time, so we need to define them somewhere.  Ideally, we should fix this upstream, but for now we 
0 commit comments