mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 20:51:32 +00:00
add misc changes while debugging
This commit is contained in:
40
lib/emscripten/src/env/mod.rs
vendored
40
lib/emscripten/src/env/mod.rs
vendored
@ -60,21 +60,51 @@ pub fn ___build_environment(ctx: &mut Ctx, environ: c_int) {
|
|||||||
const MAX_ENV_VALUES: u32 = 64;
|
const MAX_ENV_VALUES: u32 = 64;
|
||||||
const TOTAL_ENV_SIZE: u32 = 1024;
|
const TOTAL_ENV_SIZE: u32 = 1024;
|
||||||
let environment = emscripten_memory_pointer!(ctx.memory(0), environ) as *mut c_int;
|
let environment = emscripten_memory_pointer!(ctx.memory(0), environ) as *mut c_int;
|
||||||
unsafe {
|
let (mut pool_offset, env_ptr, mut pool_ptr) = unsafe {
|
||||||
let (pool_offset, _pool_slice): (u32, &mut [u8]) =
|
let (pool_offset, _pool_slice): (u32, &mut [u8]) =
|
||||||
allocate_on_stack(ctx, TOTAL_ENV_SIZE as u32);
|
allocate_on_stack(ctx, TOTAL_ENV_SIZE as u32);
|
||||||
let (env_offset, _env_slice): (u32, &mut [u8]) =
|
let (env_offset, _env_slice): (u32, &mut [u8]) =
|
||||||
allocate_on_stack(ctx, (MAX_ENV_VALUES * 4) as u32);
|
allocate_on_stack(ctx, (MAX_ENV_VALUES * 4) as u32);
|
||||||
let env_ptr = emscripten_memory_pointer!(ctx.memory(0), env_offset) as *mut c_int;
|
let env_ptr = emscripten_memory_pointer!(ctx.memory(0), env_offset) as *mut c_int;
|
||||||
let mut _pool_ptr = emscripten_memory_pointer!(ctx.memory(0), pool_offset) as *mut c_int;
|
let pool_ptr = emscripten_memory_pointer!(ctx.memory(0), pool_offset) as *mut u8;
|
||||||
*env_ptr = pool_offset as i32;
|
*env_ptr = pool_offset as i32;
|
||||||
*environment = env_offset as i32;
|
*environment = env_offset as i32;
|
||||||
|
|
||||||
// *env_ptr = 0;
|
(pool_offset, env_ptr, pool_ptr)
|
||||||
};
|
};
|
||||||
// unsafe {
|
|
||||||
// *env_ptr = 0;
|
// *env_ptr = 0;
|
||||||
// };
|
let default_vars = vec![
|
||||||
|
["USER", "web_user"],
|
||||||
|
["LOGNAME", "web_user"],
|
||||||
|
["PATH", "/"],
|
||||||
|
["PWD", "/"],
|
||||||
|
["HOME", "/home/web_user"],
|
||||||
|
["LANG", "C.UTF-8"],
|
||||||
|
["_", "thisProgram"],
|
||||||
|
];
|
||||||
|
let mut strings = vec![];
|
||||||
|
let mut total_size = 0;
|
||||||
|
for [key, val] in &default_vars {
|
||||||
|
let line = key.to_string() + "=" + val;
|
||||||
|
total_size += line.len();
|
||||||
|
strings.push(line);
|
||||||
|
}
|
||||||
|
if total_size as u32 > TOTAL_ENV_SIZE {
|
||||||
|
panic!("Environment size exceeded TOTAL_ENV_SIZE!");
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
for (i, s) in strings.iter().enumerate() {
|
||||||
|
for (j, c) in s.chars().enumerate() {
|
||||||
|
debug_assert!(c < u8::max_value() as char);
|
||||||
|
*pool_ptr.add(j) = c as u8;
|
||||||
|
}
|
||||||
|
*env_ptr.add(i * 4) = pool_offset as i32;
|
||||||
|
pool_offset += s.len() as u32 + 1;
|
||||||
|
pool_ptr = pool_ptr.add(s.len() + 1);
|
||||||
|
}
|
||||||
|
*env_ptr.add(strings.len() * 4) = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int) {
|
pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int) {
|
||||||
|
@ -7,7 +7,7 @@ use wasmer_runtime_core::vm::Ctx;
|
|||||||
/// setjmp
|
/// setjmp
|
||||||
pub fn __setjmp(ctx: &mut Ctx, _env_addr: u32) -> c_int {
|
pub fn __setjmp(ctx: &mut Ctx, _env_addr: u32) -> c_int {
|
||||||
debug!("emscripten::__setjmp (setjmp)");
|
debug!("emscripten::__setjmp (setjmp)");
|
||||||
abort_with_message(ctx, "missing function: _longjmp");
|
abort_with_message(ctx, "missing function: _setjmp");
|
||||||
unreachable!()
|
unreachable!()
|
||||||
// unsafe {
|
// unsafe {
|
||||||
// // Rather than using the env as the holder of the jump buffer pointer,
|
// // Rather than using the env as the holder of the jump buffer pointer,
|
||||||
|
@ -282,6 +282,7 @@ pub fn run_emscripten_instance(
|
|||||||
instance: &mut Instance,
|
instance: &mut Instance,
|
||||||
path: &str,
|
path: &str,
|
||||||
args: Vec<&str>,
|
args: Vec<&str>,
|
||||||
|
entrypoint: Option<String>,
|
||||||
) -> CallResult<()> {
|
) -> CallResult<()> {
|
||||||
let mut data = EmscriptenData::new(instance);
|
let mut data = EmscriptenData::new(instance);
|
||||||
let data_ptr = &mut data as *mut _ as *mut c_void;
|
let data_ptr = &mut data as *mut _ as *mut c_void;
|
||||||
@ -299,6 +300,13 @@ pub fn run_emscripten_instance(
|
|||||||
|
|
||||||
// println!("running emscripten instance");
|
// println!("running emscripten instance");
|
||||||
|
|
||||||
|
if let Some(ep) = entrypoint {
|
||||||
|
println!("RUnning entry point: {}", &ep);
|
||||||
|
let ep_fn = instance.dyn_func(&ep)?;
|
||||||
|
let arg = unsafe { allocate_cstr_on_stack(instance.context_mut(), args[0]).0 };
|
||||||
|
//let (argc, argv) = store_module_arguments(instance.context_mut(), path, args);
|
||||||
|
instance.call(&ep, &[Value::I32(arg as i32)])?;
|
||||||
|
} else {
|
||||||
let main_func = instance.dyn_func("_main")?;
|
let main_func = instance.dyn_func("_main")?;
|
||||||
let num_params = main_func.signature().params().len();
|
let num_params = main_func.signature().params().len();
|
||||||
let _result = match num_params {
|
let _result = match num_params {
|
||||||
@ -314,6 +322,7 @@ pub fn run_emscripten_instance(
|
|||||||
num_params
|
num_params
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// TODO atexit for emscripten
|
// TODO atexit for emscripten
|
||||||
// println!("{:?}", data);
|
// println!("{:?}", data);
|
||||||
|
@ -21,8 +21,11 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u
|
|||||||
|
|
||||||
/// emscripten: _emscripten_get_heap_size
|
/// emscripten: _emscripten_get_heap_size
|
||||||
pub fn _emscripten_get_heap_size(ctx: &mut Ctx) -> u32 {
|
pub fn _emscripten_get_heap_size(ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::_emscripten_get_heap_size",);
|
debug!("emscripten::_emscripten_get_heap_size");
|
||||||
ctx.memory(0).size().bytes().0 as u32
|
let result = ctx.memory(0).size().bytes().0 as u32;
|
||||||
|
debug!("=> {}", result);
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
// From emscripten implementation
|
// From emscripten implementation
|
||||||
|
@ -82,7 +82,7 @@ pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
||||||
debug!("emscripten::_sem_init");
|
debug!("emscripten::_sem_init: {}, {}, {}", _one, _two, _three);
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,12 +246,22 @@ pub fn ___syscall192(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
|||||||
if fd == -1 {
|
if fd == -1 {
|
||||||
let ptr = env::call_memalign(ctx, 16384, len);
|
let ptr = env::call_memalign(ctx, 16384, len);
|
||||||
if ptr == 0 {
|
if ptr == 0 {
|
||||||
return -1;
|
// ENOMEM
|
||||||
|
return -12;
|
||||||
}
|
}
|
||||||
|
let real_ptr = emscripten_memory_pointer!(ctx.memory(0), ptr) as *const u8;
|
||||||
env::call_memset(ctx, ptr, 0, len);
|
env::call_memset(ctx, ptr, 0, len);
|
||||||
ptr as _
|
for i in 0..(len as usize) {
|
||||||
|
unsafe {
|
||||||
|
assert_eq!(*real_ptr.add(i), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("=> ptr: {}", ptr);
|
||||||
|
return ptr as i32;
|
||||||
} else {
|
} else {
|
||||||
-1
|
unimplemented!("temp during dev");
|
||||||
|
// return ENODEV
|
||||||
|
return -19;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +86,10 @@ struct Run {
|
|||||||
#[structopt(long = "em-symbol-map", parse(from_os_str), group = "emscripten")]
|
#[structopt(long = "em-symbol-map", parse(from_os_str), group = "emscripten")]
|
||||||
em_symbol_map: Option<PathBuf>,
|
em_symbol_map: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Begin execution at the specified symbol
|
||||||
|
#[structopt(long = "with-entry-point")]
|
||||||
|
entrypoint: Option<String>,
|
||||||
|
|
||||||
/// WASI pre-opened directory
|
/// WASI pre-opened directory
|
||||||
#[structopt(long = "dir", multiple = true, group = "wasi")]
|
#[structopt(long = "dir", multiple = true, group = "wasi")]
|
||||||
pre_opened_directories: Vec<String>,
|
pre_opened_directories: Vec<String>,
|
||||||
@ -320,6 +324,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
options.path.to_str().unwrap()
|
options.path.to_str().unwrap()
|
||||||
},
|
},
|
||||||
options.args.iter().map(|arg| arg.as_str()).collect(),
|
options.args.iter().map(|arg| arg.as_str()).collect(),
|
||||||
|
options.entrypoint.clone(),
|
||||||
)
|
)
|
||||||
.map_err(|e| format!("{:?}", e))?;
|
.map_err(|e| format!("{:?}", e))?;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user