29
29
#include <sys/types.h>
30
30
#include <fcntl.h>
31
31
#include <sched.h>
32
- #include <assert.h>
33
32
#include <stdio.h>
34
33
#include <stdlib.h>
35
34
#include <string.h>
@@ -84,17 +83,20 @@ libwasmtime_exec (void *cookie, libcrun_container_t *container arg_unused,
84
83
85
84
// Set up wasmtime context
86
85
wasm_engine_t * engine = wasm_engine_new ();
87
- assert (engine != NULL );
86
+ if (engine == NULL )
87
+ error (EXIT_FAILURE , 0 , "could not create WebAssembly engine" );
88
88
89
89
wasm_byte_vec_t wasm ;
90
90
// Load and parse container entrypoint
91
91
FILE * file = fopen (pathname , "rbe" );
92
92
if (! file )
93
93
error (EXIT_FAILURE , 0 , "error loading entrypoint" );
94
- fseek (file , 0L , SEEK_END );
94
+ if (fseek (file , 0L , SEEK_END ))
95
+ error (EXIT_FAILURE , 0 , "error fully loading entrypoint" );
95
96
size_t file_size = ftell (file );
96
97
wasm_byte_vec_new_uninitialized (& wasm , file_size );
97
- fseek (file , 0L , SEEK_SET );
98
+ if (fseek (file , 0L , SEEK_SET ))
99
+ error (EXIT_FAILURE , 0 , "error resetting entrypoint" );
98
100
if (fread (wasm .data , file_size , 1 , file ) != 1 )
99
101
error (EXIT_FAILURE , 0 , "error load" );
100
102
fclose (file );
@@ -125,22 +127,16 @@ libwasmtime_exec (void *cookie, libcrun_container_t *container arg_unused,
125
127
wasmtime_error_delete (err );
126
128
127
129
if (strcmp ((char * ) error_message .data , "component passed to module validation" ) != 0 )
128
- {
129
- error (EXIT_FAILURE , 0 , "failed to validate module: %.*s" , (int ) error_message .size , error_message .data );
130
- }
130
+ error (EXIT_FAILURE , 0 , "failed to validate module: %.*s" , (int ) error_message .size , error_message .data );
131
131
132
132
err = NULL ;
133
133
is_wasm_module = false;
134
134
}
135
135
136
136
if (is_wasm_module )
137
- {
138
- libwasmtime_run_module (cookie , argv , engine , & wasm );
139
- }
137
+ libwasmtime_run_module (cookie , argv , engine , & wasm );
140
138
else
141
- {
142
- libwasmtime_run_component (cookie , argv , engine , & wasm );
143
- }
139
+ libwasmtime_run_component (cookie , argv , engine , & wasm );
144
140
145
141
exit (EXIT_SUCCESS );
146
142
}
@@ -235,7 +231,8 @@ libwasmtime_run_module (void *cookie, char *const argv[], wasm_engine_t *engine,
235
231
236
232
// Set up wasmtime context
237
233
wasmtime_store_t * store = wasmtime_store_new (engine , NULL , NULL );
238
- assert (store != NULL );
234
+ if (store == NULL )
235
+ error (EXIT_FAILURE , 0 , "could not create WebAssembly store" );
239
236
wasmtime_context_t * context = wasmtime_store_context (store );
240
237
241
238
// Link with wasi functions defined
@@ -261,7 +258,8 @@ libwasmtime_run_module (void *cookie, char *const argv[], wasm_engine_t *engine,
261
258
262
259
// Init WASI program
263
260
wasi_config_t * wasi_config = wasi_config_new ("crun_wasi_program" );
264
- assert (wasi_config );
261
+ if (wasi_config == NULL )
262
+ error (EXIT_FAILURE , 0 , "could not create WASI configuration" );
265
263
266
264
// Calculate argc for `wasi_config_set_argv`
267
265
for (arg = argv ; * arg != NULL ; ++ arg )
@@ -410,7 +408,8 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
410
408
411
409
// Set up wasmtime context
412
410
wasmtime_store_t * store = wasmtime_store_new (engine , NULL , NULL );
413
- assert (store != NULL );
411
+ if (store == NULL )
412
+ error (EXIT_FAILURE , 0 , "could not create WebAssembly store" );
414
413
wasmtime_context_t * context = wasmtime_store_context (store );
415
414
416
415
// Compile wasm component
@@ -426,7 +425,8 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
426
425
427
426
// Set up WASIp2 config
428
427
wasmtime_wasip2_config_t * wasi_config = wasmtime_wasip2_config_new ();
429
- assert (wasi_config != NULL );
428
+ if (wasi_config == NULL )
429
+ error (EXIT_FAILURE , 0 , "could not create WASIp2 configuration" );
430
430
431
431
wasi_config_inherit_env ((wasi_config_t * ) wasi_config );
432
432
wasmtime_wasip2_config_inherit_stdin (wasi_config );
@@ -465,22 +465,22 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
465
465
NULL ,
466
466
wasi_cli_run_interface ,
467
467
strlen (wasi_cli_run_interface ));
468
- assert (run_interface_idx != NULL );
468
+ if (run_interface_idx == NULL )
469
+ error (EXIT_FAILURE , 0 , "failed to fetch export index of %.*s" , (int ) strlen (wasi_cli_run_interface ), wasi_cli_run_interface );
469
470
// Get index of the run function
470
471
wasmtime_component_export_index_t * run_func_idx = wasmtime_component_instance_get_export_index (
471
472
& component_inst ,
472
473
context ,
473
474
run_interface_idx ,
474
475
wasi_cli_run_interface_run ,
475
476
strlen (wasi_cli_run_interface_run ));
476
- assert (run_func_idx != NULL );
477
+ if (run_func_idx == NULL )
478
+ error (EXIT_FAILURE , 0 , "failed to fetch export index of %.*s" , (int ) strlen (wasi_cli_run_interface_run ), wasi_cli_run_interface_run );
477
479
478
480
// Actually retrieve the func
479
481
wasmtime_component_func_t run_func = {};
480
482
if (! wasmtime_component_instance_get_func (& component_inst , context , run_func_idx , & run_func ))
481
- {
482
- error (EXIT_FAILURE , 0 , "failed to retrieve run function" );
483
- }
483
+ error (EXIT_FAILURE , 0 , "failed to retrieve run function" );
484
484
485
485
// Call the func
486
486
wasmtime_component_val_t result = {};
0 commit comments