Skip to content

Commit ec414be

Browse files
committed
still WIP: dlclose
1 parent 3d4f58f commit ec414be

File tree

5 files changed

+266
-82
lines changed

5 files changed

+266
-82
lines changed

lib/wasix/src/state/env.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::{
4242
use wasmer_types::ModuleHash;
4343

4444
pub use super::handles::*;
45-
use super::{conv_env_vars, Linker, ModuleHandle, WasiState, MAIN_MODULE_HANDLE};
45+
use super::{conv_env_vars, Linker, WasiState};
4646

4747
/// Data required to construct a [`WasiEnv`].
4848
#[derive(Debug)]
@@ -154,12 +154,6 @@ pub struct WasiEnv {
154154
/// Implementation of the WASI runtime.
155155
pub runtime: Arc<dyn Runtime + Send + Sync + 'static>,
156156

157-
/// The handle of the current module in the Linker. If the module is
158-
/// statically linked, this will always be `MAIN_MODULE_HANDLE` which is
159-
/// zero. Non-zero handles will correspond to the module's entry in the
160-
/// linker, which will live in the `WasiEnv::inner` field.
161-
pub dl_handle: ModuleHandle,
162-
163157
pub capabilities: Capabilities,
164158

165159
/// Is this environment capable and setup for deep sleeping
@@ -211,7 +205,6 @@ impl Clone for WasiEnv {
211205
inner: Default::default(),
212206
owned_handles: self.owned_handles.clone(),
213207
runtime: self.runtime.clone(),
214-
dl_handle: self.dl_handle,
215208
capabilities: self.capabilities.clone(),
216209
enable_deep_sleep: self.enable_deep_sleep,
217210
enable_journal: self.enable_journal,
@@ -253,10 +246,6 @@ impl WasiEnv {
253246
inner: Default::default(),
254247
owned_handles: Vec::new(),
255248
runtime: self.runtime.clone(),
256-
// A fork is meant to support a new process, so presumably, the first
257-
// env should be created for the main module of that process. Hence,
258-
// we set the dl_handle back to the main module's handle.
259-
dl_handle: MAIN_MODULE_HANDLE,
260249
capabilities: self.capabilities.clone(),
261250
enable_deep_sleep: self.enable_deep_sleep,
262251
enable_journal: self.enable_journal,
@@ -405,9 +394,6 @@ impl WasiEnv {
405394
.threading
406395
.enable_exponential_cpu_backoff,
407396
runtime: init.runtime,
408-
// Since we're just initializing the env, the first module (to which
409-
// the new env belongs) should be the main
410-
dl_handle: MAIN_MODULE_HANDLE,
411397
bin_factory: init.bin_factory,
412398
capabilities: init.capabilities,
413399
disable_fs_cleanup: false,
@@ -566,6 +552,9 @@ impl WasiEnv {
566552

567553
// If this module exports an _initialize function, run that first.
568554
if call_initialize {
555+
// This function is exported from PIE executables, and needs to be run before calling
556+
// _initialize or _start. More info:
557+
// https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md
569558
if let Ok(apply_data_relocs) = instance.exports.get_function("__wasm_apply_data_relocs")
570559
{
571560
if let Err(err) = crate::run_wasi_func_start(apply_data_relocs, &mut store) {

0 commit comments

Comments
 (0)