mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 16:41:33 +00:00
Add some syscalls
This commit is contained in:
committed by
Lachlan Sneff
parent
75ef87824e
commit
399f72df94
@ -1,7 +1,11 @@
|
|||||||
/// NOTE: TODO: These emscripten api implementation only support wasm32 for now because they assume offsets are u32
|
/// NOTE: TODO: These emscripten api implementation only support wasm32 for now because they assume offsets are u32
|
||||||
|
<<<<<<< HEAD
|
||||||
use crate::webassembly::{ImportObject, ImportValue, LinearMemory};
|
use crate::webassembly::{ImportObject, ImportValue, LinearMemory};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
=======
|
||||||
|
use crate::webassembly::{ImportObject, ImportValue};
|
||||||
|
>>>>>>> Add some syscalls
|
||||||
|
|
||||||
// EMSCRIPTEN APIS
|
// EMSCRIPTEN APIS
|
||||||
mod env;
|
mod env;
|
||||||
@ -159,6 +163,7 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
|||||||
"env",
|
"env",
|
||||||
"___syscall140",
|
"___syscall140",
|
||||||
ImportValue::Func(syscalls::___syscall140 as *const u8),
|
ImportValue::Func(syscalls::___syscall140 as *const u8),
|
||||||
|
<<<<<<< HEAD
|
||||||
);
|
);
|
||||||
import_object.set(
|
import_object.set(
|
||||||
"env",
|
"env",
|
||||||
@ -172,6 +177,21 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
|||||||
);
|
);
|
||||||
import_object.set(
|
import_object.set(
|
||||||
"env",
|
"env",
|
||||||
|
=======
|
||||||
|
);
|
||||||
|
import_object.set(
|
||||||
|
"env",
|
||||||
|
"___syscall145",
|
||||||
|
ImportValue::Func(syscalls::___syscall145 as *const u8),
|
||||||
|
);
|
||||||
|
import_object.set(
|
||||||
|
"env",
|
||||||
|
"___syscall146",
|
||||||
|
ImportValue::Func(syscalls::___syscall146 as *const u8),
|
||||||
|
);
|
||||||
|
import_object.set(
|
||||||
|
"env",
|
||||||
|
>>>>>>> Add some syscalls
|
||||||
"___syscall221",
|
"___syscall221",
|
||||||
ImportValue::Func(syscalls::___syscall221 as *const u8),
|
ImportValue::Func(syscalls::___syscall221 as *const u8),
|
||||||
);
|
);
|
||||||
@ -220,8 +240,13 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
|||||||
);
|
);
|
||||||
import_object.set(
|
import_object.set(
|
||||||
"env",
|
"env",
|
||||||
|
<<<<<<< HEAD
|
||||||
"nullFunc_iii",
|
"nullFunc_iii",
|
||||||
ImportValue::Func(nullfunc::nullfunc_iii as *const u8),
|
ImportValue::Func(nullfunc::nullfunc_iii as *const u8),
|
||||||
|
=======
|
||||||
|
"nullFunc_iiii",
|
||||||
|
ImportValue::Func(nullfunc::nullfunc_iiii as *const u8),
|
||||||
|
>>>>>>> Add some syscalls
|
||||||
);
|
);
|
||||||
import_object.set(
|
import_object.set(
|
||||||
"env",
|
"env",
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
|
|
||||||
use crate::webassembly::{LinearMemory, Instance};
|
use crate::webassembly::{LinearMemory, Instance};
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
pub fn align_memory(ptr: u32) -> u32 {
|
pub fn align_memory(ptr: u32) -> u32 {
|
||||||
(ptr + 15) & !15
|
(ptr + 15) & !15
|
||||||
|
=======
|
||||||
|
pub fn align_memory(size: u32, factor: u32) -> u32 {
|
||||||
|
assert!(factor != 0, "memory cannot be aligned by 0 offset!");
|
||||||
|
if size % factor == 1 {
|
||||||
|
(size) - (size % factor) + (factor)
|
||||||
|
} else {
|
||||||
|
size
|
||||||
|
}
|
||||||
|
>>>>>>> Add some syscalls
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn static_alloc(size: u32, instance: &mut Instance) -> u32 {
|
// pub fn static_alloc(size: u32, instance: &mut Instance) -> u32 {
|
||||||
@ -15,7 +25,11 @@ pub fn align_memory(ptr: u32) -> u32 {
|
|||||||
|
|
||||||
pub fn static_alloc(size: u32, static_top: &mut u32, memory: &LinearMemory) -> u32 {
|
pub fn static_alloc(size: u32, static_top: &mut u32, memory: &LinearMemory) -> u32 {
|
||||||
let old_static_top = *static_top;
|
let old_static_top = *static_top;
|
||||||
|
<<<<<<< HEAD
|
||||||
let total_memory = memory.maximum_size() * LinearMemory::PAGE_SIZE;
|
let total_memory = memory.maximum_size() * LinearMemory::PAGE_SIZE;
|
||||||
|
=======
|
||||||
|
let total_memory = memory.maximum.unwrap_or(LinearMemory::MAX_PAGES as u32) * LinearMemory::PAGE_SIZE;
|
||||||
|
>>>>>>> Add some syscalls
|
||||||
// NOTE: The `4294967280` is a u32 conversion of -16 as gotten from emscripten.
|
// NOTE: The `4294967280` is a u32 conversion of -16 as gotten from emscripten.
|
||||||
*static_top = (*static_top + size + 15) & 4294967280;
|
*static_top = (*static_top + size + 15) & 4294967280;
|
||||||
assert!(*static_top < total_memory, "not enough memory for static allocation - increase total_memory!");
|
assert!(*static_top < total_memory, "not enough memory for static allocation - increase total_memory!");
|
||||||
|
@ -30,6 +30,8 @@ use super::memory::LinearMemory;
|
|||||||
use super::module::{Export, ImportableExportable, Module};
|
use super::module::{Export, ImportableExportable, Module};
|
||||||
use super::relocation::{Reloc, RelocSink, RelocationType};
|
use super::relocation::{Reloc, RelocSink, RelocationType};
|
||||||
|
|
||||||
|
use crate::apis::emscripten::{align_memory, static_alloc};
|
||||||
|
|
||||||
type TablesSlice = UncheckedSlice<BoundedSlice<usize>>;
|
type TablesSlice = UncheckedSlice<BoundedSlice<usize>>;
|
||||||
// TODO: this should be `type MemoriesSlice = UncheckedSlice<UncheckedSlice<u8>>;`, but that crashes for some reason.
|
// TODO: this should be `type MemoriesSlice = UncheckedSlice<UncheckedSlice<u8>>;`, but that crashes for some reason.
|
||||||
type MemoriesSlice = UncheckedSlice<BoundedSlice<u8>>;
|
type MemoriesSlice = UncheckedSlice<BoundedSlice<u8>>;
|
||||||
@ -98,6 +100,9 @@ pub struct Instance {
|
|||||||
pub start_func: Option<FuncIndex>,
|
pub start_func: Option<FuncIndex>,
|
||||||
// Region start memory location
|
// Region start memory location
|
||||||
// code_base: *const (),
|
// code_base: *const (),
|
||||||
|
|
||||||
|
/// TODO: This should probably be passed as globals to the module.
|
||||||
|
pub emscripten_data: EmscriptenData,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains pointers to data (heaps, globals, tables) needed
|
/// Contains pointers to data (heaps, globals, tables) needed
|
||||||
@ -116,6 +121,27 @@ pub struct DataPointers {
|
|||||||
pub globals: GlobalsSlice,
|
pub globals: GlobalsSlice,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct EmscriptenData {
|
||||||
|
pub static_sealed: bool,
|
||||||
|
|
||||||
|
// global section
|
||||||
|
pub global_base: u32,
|
||||||
|
pub static_base: u32,
|
||||||
|
pub static_top: u32,
|
||||||
|
|
||||||
|
// stack
|
||||||
|
pub total_stack: u32,
|
||||||
|
pub stack_base: u32,
|
||||||
|
pub stack_max: u32,
|
||||||
|
pub stack_top: u32,
|
||||||
|
|
||||||
|
// heap
|
||||||
|
pub dynamic_base: u32,
|
||||||
|
pub dynamictop_ptr: u32,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct InstanceOptions {
|
pub struct InstanceOptions {
|
||||||
// Shall we mock automatically the imported functions if they don't exist?
|
// Shall we mock automatically the imported functions if they don't exist?
|
||||||
pub mock_missing_imports: bool,
|
pub mock_missing_imports: bool,
|
||||||
@ -502,7 +528,7 @@ impl Instance {
|
|||||||
functions,
|
functions,
|
||||||
import_functions,
|
import_functions,
|
||||||
start_func,
|
start_func,
|
||||||
// emscripten_data,
|
emscripten_data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user