@@ -244,6 +244,12 @@ ngx_wasm_wasmtime_call(void *data, ngx_str_t *name, bool has_result, int param_t
244244
245245 ngx_log_debug1 (NGX_LOG_DEBUG_CORE , ngx_cycle -> log , 0 , "wasmtime call function %V" , name );
246246
247+ if (plugin == NULL ) {
248+ plugin = cur_plugin ;
249+ } else {
250+ cur_plugin = plugin ;
251+ }
252+
247253 found = wasmtime_instance_export_get (plugin -> context , & plugin -> instance ,
248254 (const char * ) name -> data , name -> len , & func );
249255 if (!found ) {
@@ -252,8 +258,6 @@ ngx_wasm_wasmtime_call(void *data, ngx_str_t *name, bool has_result, int param_t
252258 return NGX_OK ;
253259 }
254260
255- cur_plugin = plugin ;
256-
257261 va_start (args , param_type );
258262
259263 switch (param_type ) {
@@ -360,48 +364,13 @@ ngx_wasm_wasmtime_get_memory(ngx_log_t *log, int32_t addr, int32_t size)
360364}
361365
362366
363- int32_t
364- ngx_wasm_wasmtime_malloc (ngx_log_t * log , int32_t size )
365- {
366- wasmtime_extern_t func ;
367- wasm_trap_t * trap = NULL ;
368- wasmtime_error_t * error ;
369- wasmtime_val_t params [1 ];
370- wasmtime_val_t results [1 ];
371- bool found ;
372-
373- found = wasmtime_instance_export_get (cur_plugin -> context , & cur_plugin -> instance ,
374- "proxy_on_memory_allocate" , 24 , & func );
375- if (!found ) {
376- found = wasmtime_instance_export_get (cur_plugin -> context , & cur_plugin -> instance ,
377- "malloc" , 6 , & func );
378- if (!found ) {
379- ngx_log_error (NGX_LOG_ERR , log , 0 , "can't find malloc in the WASM plugin" );
380- return 0 ;
381- }
382- }
383-
384- params [0 ].kind = WASMTIME_I32 ;
385- params [0 ].of .i32 = size ;
386-
387- error = wasmtime_func_call (cur_plugin -> context , & func .of .func , params , 1 , results , 1 , & trap );
388- if (error != NULL || trap != NULL ) {
389- ngx_wasm_wasmtime_report_error (log , "failed to malloc: " , error , trap );
390- return 0 ;
391- }
392-
393- return results [0 ].of .i64 ;
394- }
395-
396-
397367ngx_wasm_vm_t ngx_wasm_vm = {
398368 & vm_name ,
399369 ngx_wasm_wasmtime_init ,
400370 ngx_wasm_wasmtime_cleanup ,
401371 ngx_wasm_wasmtime_load ,
402372 ngx_wasm_wasmtime_unload ,
403373 ngx_wasm_wasmtime_get_memory ,
404- ngx_wasm_wasmtime_malloc ,
405374 ngx_wasm_wasmtime_call ,
406375 ngx_wasm_wasmtime_has ,
407376};
0 commit comments