@@ -19,6 +19,7 @@ use path_slash::PathBufExt as _;
19
19
pub struct WasmConfig {
20
20
pub id : String ,
21
21
pub module_id : String ,
22
+ pub entrypoint : String ,
22
23
pub wasi_args : Vec < String > ,
23
24
pub wasi_envs : Vec < ( String , String ) > ,
24
25
pub wasi_dirs : Vec < String > ,
@@ -59,6 +60,7 @@ impl WasmConfig {
59
60
wasi_envs : Vec :: new ( ) ,
60
61
wasi_dirs : Vec :: new ( ) ,
61
62
wasi_mapdirs : Vec :: new ( ) ,
63
+ entrypoint : "_start" . to_string ( ) // defaults to "_start"
62
64
} ;
63
65
64
66
// insert created WasmConfig object into the HashMap
@@ -212,6 +214,32 @@ impl WasmConfig {
212
214
Ok ( ( ) )
213
215
}
214
216
217
+ // Set the entrypoint for a loaded Wasm Module to an existing Wasm config
218
+ ///
219
+ /// It checks for wrong `config_id`
220
+ /// Returns Result<(), String>, so that in case of error the String will contain the reason.
221
+ ///
222
+ pub fn set_entrypoint_for_config ( config_id : & str , entrypoint : & str ) -> Result < ( ) , String > {
223
+
224
+ // get write access to the WasmConfig HashMap
225
+ let mut configs = WASM_RUNTIME_CONFIGS . write ( )
226
+ . expect ( "ERROR! Poisoned RwLock WASM_RUNTIME_CONFIGS on write()" ) ;
227
+
228
+ // check for existing config_id in the loaded configurations
229
+ let wasm_config = match configs. get_mut ( config_id) {
230
+ Some ( c) => c,
231
+ None => {
232
+ let error_msg = format ! ( "Wasm config \' {}\' not found while setting entrypoint \' {}\' " , config_id, entrypoint) ;
233
+ return Err ( error_msg) ;
234
+ }
235
+ } ;
236
+
237
+ // setting module in Wasm config
238
+ wasm_config. entrypoint = entrypoint. to_string ( ) ;
239
+
240
+ Ok ( ( ) )
241
+ }
242
+
215
243
pub fn get_mapped_path ( config_id : & str , path : & str ) -> Result < Option < String > , String > {
216
244
let configs = WASM_RUNTIME_CONFIGS
217
245
. read ( )
0 commit comments