@@ -1793,12 +1793,14 @@ wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module,
17931793}
17941794
17951795#if WASM_ENABLE_LIBC_WASI != 0
1796+
17961797void
1797- wasm_runtime_set_wasi_args (WASMModuleCommon * module ,
1798+ wasm_runtime_set_wasi_args_ex (WASMModuleCommon * module ,
17981799 const char * dir_list [], uint32 dir_count ,
17991800 const char * map_dir_list [], uint32 map_dir_count ,
18001801 const char * env_list [], uint32 env_count ,
1801- char * argv [], int argc )
1802+ char * argv [], int argc ,
1803+ int stdinfd , int stdoutfd , int stderrfd )
18021804{
18031805 WASIArguments * wasi_args = NULL ;
18041806
@@ -1820,16 +1822,35 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
18201822 wasi_args -> env_count = env_count ;
18211823 wasi_args -> argv = argv ;
18221824 wasi_args -> argc = (uint32 )argc ;
1825+ wasi_args -> stdio [0 ] = stdinfd ;
1826+ wasi_args -> stdio [1 ] = stdoutfd ;
1827+ wasi_args -> stdio [2 ] = stderrfd ;
18231828 }
18241829}
18251830
1831+ void
1832+ wasm_runtime_set_wasi_args (WASMModuleCommon * module ,
1833+ const char * dir_list [], uint32 dir_count ,
1834+ const char * map_dir_list [], uint32 map_dir_count ,
1835+ const char * env_list [], uint32 env_count ,
1836+ char * argv [], int argc )
1837+ {
1838+ wasm_runtime_set_wasi_args_ex (module ,
1839+ dir_list , dir_count ,
1840+ map_dir_list , map_dir_count ,
1841+ env_list , env_count ,
1842+ argv , argc ,
1843+ -1 , -1 , -1 );
1844+ }
1845+
18261846#if WASM_ENABLE_UVWASI == 0
18271847bool
18281848wasm_runtime_init_wasi (WASMModuleInstanceCommon * module_inst ,
18291849 const char * dir_list [], uint32 dir_count ,
18301850 const char * map_dir_list [], uint32 map_dir_count ,
18311851 const char * env [], uint32 env_count ,
18321852 char * argv [], uint32 argc ,
1853+ int stdinfd , int stdoutfd , int stderrfd ,
18331854 char * error_buf , uint32 error_buf_size )
18341855{
18351856 WASIContext * wasi_ctx ;
@@ -1951,9 +1972,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
19511972 argv_environ_inited = true;
19521973
19531974 /* Prepopulate curfds with stdin, stdout, and stderr file descriptors. */
1954- if (!fd_table_insert_existing (curfds , 0 , 0 )
1955- || !fd_table_insert_existing (curfds , 1 , 1 )
1956- || !fd_table_insert_existing (curfds , 2 , 2 )) {
1975+ if (!fd_table_insert_existing (curfds , 0 , ( stdinfd != -1 ) ? stdinfd : 0 )
1976+ || !fd_table_insert_existing (curfds , 1 , ( stdoutfd != -1 ) ? stdoutfd : 1 )
1977+ || !fd_table_insert_existing (curfds , 2 , ( stderrfd != -1 ) ? stderrfd : 2 )) {
19571978 set_error_buf (error_buf , error_buf_size ,
19581979 "Init wasi environment failed: init fd table failed" );
19591980 goto fail ;
@@ -2065,6 +2086,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
20652086 const char * map_dir_list [], uint32 map_dir_count ,
20662087 const char * env [], uint32 env_count ,
20672088 char * argv [], uint32 argc ,
2089+ int stdinfd , int stdoutfd , int stderrfd ,
20682090 char * error_buf , uint32 error_buf_size )
20692091{
20702092 uvwasi_t * uvwasi = NULL ;
@@ -2084,6 +2106,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
20842106 init_options .allocator = & uvwasi_allocator ;
20852107 init_options .argc = argc ;
20862108 init_options .argv = (const char * * )argv ;
2109+ init_options .in = (stdinfd != -1 ) ? (uvwasi_fd_t )stdinfd : init_options .in ;
2110+ init_options .out = (stdoutfd != -1 ) ? (uvwasi_fd_t )stdoutfd : init_options .out ;
2111+ init_options .err = (stderrfd != -1 ) ? (uvwasi_fd_t )stderrfd : init_options .err ;
20872112
20882113 if (dir_count > 0 ) {
20892114 init_options .preopenc = dir_count ;
0 commit comments