@@ -4444,25 +4444,25 @@ aot_process_export(wasm_store_t *store, const AOTModuleInstance *inst_aot,
44444444
44454445wasm_instance_t *
44464446wasm_instance_new (wasm_store_t * store , const wasm_module_t * module ,
4447- const wasm_extern_vec_t * imports , own wasm_trap_t * * traps )
4447+ const wasm_extern_vec_t * imports , own wasm_trap_t * * trap )
44484448{
4449- return wasm_instance_new_with_args (store , module , imports , traps ,
4449+ return wasm_instance_new_with_args (store , module , imports , trap ,
44504450 KILOBYTE (32 ), KILOBYTE (32 ));
44514451}
44524452
44534453wasm_instance_t *
44544454wasm_instance_new_with_args (wasm_store_t * store , const wasm_module_t * module ,
44554455 const wasm_extern_vec_t * imports ,
4456- own wasm_trap_t * * traps , const uint32 stack_size ,
4456+ own wasm_trap_t * * trap , const uint32 stack_size ,
44574457 const uint32 heap_size )
44584458{
4459- char error_buf [128 ] = { 0 };
4459+ char sub_error_buf [128 ] = { 0 };
4460+ char error_buf [256 ] = { 0 };
44604461 uint32 import_count = 0 ;
44614462 bool import_count_verified = false;
44624463 wasm_instance_t * instance = NULL ;
44634464 uint32 i = 0 ;
44644465 bool processed = false;
4465- (void )traps ;
44664466
44674467 bh_assert (singleton_engine );
44684468
@@ -4474,6 +4474,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
44744474
44754475 instance = malloc_internal (sizeof (wasm_instance_t ));
44764476 if (!instance ) {
4477+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4478+ "Failed to malloc instance" );
44774479 goto failed ;
44784480 }
44794481
@@ -4490,6 +4492,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
44904492 /* make sure a complete import list */
44914493 if ((int32 )import_count < 0
44924494 || import_count != actual_link_import_count ) {
4495+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4496+ "Failed to validate imports" );
44934497 goto failed ;
44944498 }
44954499 }
@@ -4508,6 +4512,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
45084512 import_count = aot_link (instance , MODULE_AOT (module ),
45094513 (wasm_extern_t * * )imports -> data );
45104514 if ((int32 )import_count < 0 ) {
4515+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4516+ "Failed to validate imports" );
45114517 goto failed ;
45124518 }
45134519 }
@@ -4520,18 +4526,21 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
45204526 * also leads to below branch
45214527 */
45224528 if (!import_count_verified ) {
4529+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4530+ "Failed to verify import count" );
45234531 goto failed ;
45244532 }
45254533 }
45264534
45274535 instance -> inst_comm_rt = wasm_runtime_instantiate (
4528- * module , stack_size , heap_size , error_buf , sizeof (error_buf ));
4536+ * module , stack_size , heap_size , sub_error_buf , sizeof (sub_error_buf ));
45294537 if (!instance -> inst_comm_rt ) {
4530- LOG_ERROR (error_buf );
45314538 goto failed ;
45324539 }
45334540
45344541 if (!wasm_runtime_create_exec_env_singleton (instance -> inst_comm_rt )) {
4542+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4543+ "Failed to create exec env singleton" );
45354544 goto failed ;
45364545 }
45374546
@@ -4556,6 +4565,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
45564565 instance -> inst_comm_rt ;
45574566 break ;
45584567 default :
4568+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4569+ "Unknown import kind" );
45594570 goto failed ;
45604571 }
45614572 }
@@ -4572,6 +4583,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
45724583 if (!interp_process_export (store ,
45734584 (WASMModuleInstance * )instance -> inst_comm_rt ,
45744585 instance -> exports )) {
4586+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4587+ "Interpreter failed to process exports" );
45754588 goto failed ;
45764589 }
45774590
@@ -4594,6 +4607,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
45944607 if (!aot_process_export (store ,
45954608 (AOTModuleInstance * )instance -> inst_comm_rt ,
45964609 instance -> exports )) {
4610+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4611+ "AOT failed to process exports" );
45974612 goto failed ;
45984613 }
45994614
@@ -4606,11 +4621,15 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
46064621 * leads to below branch
46074622 */
46084623 if (!processed ) {
4624+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4625+ "Incorrect filetype and compilation flags" );
46094626 goto failed ;
46104627 }
46114628
46124629 /* add it to a watching list in store */
46134630 if (!bh_vector_append ((Vector * )store -> instances , & instance )) {
4631+ snprintf (sub_error_buf , sizeof (sub_error_buf ),
4632+ "Failed to add to store instances" );
46144633 goto failed ;
46154634 }
46164635
@@ -4619,7 +4638,15 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
46194638 return instance ;
46204639
46214640failed :
4622- LOG_DEBUG ("%s failed" , __FUNCTION__ );
4641+ snprintf (error_buf , sizeof (error_buf ), "%s failed: %s" , __FUNCTION__ ,
4642+ sub_error_buf );
4643+ if (trap != NULL ) {
4644+ wasm_message_t message = { 0 };
4645+ wasm_name_new_from_string (& message , error_buf );
4646+ * trap = wasm_trap_new (store , & message );
4647+ wasm_byte_vec_delete (& message );
4648+ }
4649+ LOG_DEBUG (error_buf );
46234650 wasm_instance_delete_internal (instance );
46244651 return NULL ;
46254652}
0 commit comments