Fix build errors

This commit is contained in:
Lachlan Sneff 2018-11-26 16:11:01 -05:00
parent bd3b78ccc8
commit 3be1bdba30
2 changed files with 30 additions and 3 deletions

View File

@ -10,11 +10,8 @@ use std::os::raw::c_char;
use std::{slice, mem};
use crate::webassembly::Instance;
<<<<<<< HEAD
use super::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
=======
use crate::webassembly::LinearMemory;
>>>>>>> Add a few more syscalls
/// emscripten: _getenv
pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> c_int {

View File

@ -1,4 +1,8 @@
use crate::webassembly::module::Module;
use crate::webassembly::Instance;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::{slice, mem};
/// We check if a provided module is an Emscripten generated one
pub fn is_emscripten_module(module: &Module) -> bool {
@ -10,6 +14,32 @@ pub fn is_emscripten_module(module: &Module) -> bool {
return false;
}
pub unsafe fn copy_cstr_into_wasm(instance: &mut Instance, cstr: *const c_char) -> u32 {
let s = CStr::from_ptr(cstr).to_str().unwrap();
let space_offset = (instance.emscripten_data.malloc)(s.len() as _, instance);
let raw_memory = instance.memory_offset_addr(0, space_offset as _) as *mut u8;
let mut slice = slice::from_raw_parts_mut(raw_memory, s.len());
for (byte, loc) in s.bytes().zip(slice.iter_mut()) {
*loc = byte;
}
space_offset
}
pub unsafe fn copy_terminated_array_of_cstrs(instance: &mut Instance, cstrs: *mut *mut c_char) -> u32 {
let total_num = {
let mut ptr = cstrs;
let mut counter = 0;
while !(*ptr).is_null() {
counter += 1;
ptr = ptr.add(1);
}
counter
};
println!("total_num: {}", total_num);
0
}
#[cfg(test)]
mod tests {
use super::super::generate_emscripten_env;