Skip to content

Commit

Permalink
Update the loader interface for 128 bit types.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewycky committed Jul 22, 2019
1 parent f8e8b1c commit 4535274
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/kernel-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Loader for KernelLoader {
if module.imported_globals.len() > 0 {
return Err("imported globals are not supported".into());
}
let globals: Vec<u64> = unsafe {
let globals: Vec<u128> = unsafe {
let globals: &[*mut LocalGlobal] =
::std::slice::from_raw_parts(ctx.globals, module.globals.len());
globals.iter().map(|x| (**x).data).collect()
Expand Down Expand Up @@ -138,11 +138,11 @@ pub struct KernelInstance {

impl Instance for KernelInstance {
type Error = String;
fn call(&mut self, id: usize, args: &[Value]) -> Result<u64, String> {
fn call(&mut self, id: usize, args: &[Value]) -> Result<u128, String> {
if args.len() != self.param_counts[id] {
return Err("param count mismatch".into());
}
let args: Vec<u64> = args.iter().map(|x| x.to_u64()).collect();
let args: Vec<u128> = args.iter().map(|x| x.to_u128()).collect();

let ret = self
.context
Expand Down
12 changes: 6 additions & 6 deletions lib/kernel-loader/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct LoadCodeRequest {
memory_max: u32,
table: *const TableEntryRequest,
table_count: u32,
globals: *const u64,
globals: *const u128,
global_count: u32,

imported_funcs: *const ImportRequest,
Expand All @@ -67,15 +67,15 @@ struct LoadCodeRequest {
#[repr(C)]
struct RunCodeRequest {
entry_offset: u32,
params: *const u64,
params: *const u128,
param_count: u32,
result: *mut RunCodeResult,
}

#[repr(C)]
struct RunCodeResult {
success: u32,
retval: u64,
retval: u128,
}

#[repr(C)]
Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct LoadProfile<'a> {
pub code: &'a [u8],
pub memory: Option<&'a [u8]>,
pub memory_max: usize,
pub globals: &'a [u64],
pub globals: &'a [u128],
pub imports: &'a [ImportInfo],
pub dynamic_sigindices: &'a [u32],
pub table: Option<&'a [TableEntryRequest]>,
Expand All @@ -121,7 +121,7 @@ pub struct ImportInfo {

pub struct RunProfile<'a> {
pub entry_offset: u32,
pub params: &'a [u64],
pub params: &'a [u128],
}

pub struct ServiceContext {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl ServiceContext {
}
}

pub fn run_code(&mut self, run: RunProfile) -> ServiceResult<u64> {
pub fn run_code(&mut self, run: RunProfile) -> ServiceResult<u128> {
let mut result: RunCodeResult = unsafe { ::std::mem::zeroed() };
let mut req = RunCodeRequest {
entry_offset: run.entry_offset,
Expand Down
16 changes: 8 additions & 8 deletions lib/runtime-core/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Loader {

pub trait Instance {
type Error: Debug;
fn call(&mut self, id: usize, args: &[Value]) -> Result<u64, Self::Error>;
fn call(&mut self, id: usize, args: &[Value]) -> Result<u128, Self::Error>;
fn read_memory(&mut self, _offset: u32, _len: u32) -> Result<Vec<u8>, Self::Error> {
unimplemented!()
}
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct LocalInstance {

impl Instance for LocalInstance {
type Error = String;
fn call(&mut self, id: usize, args: &[Value]) -> Result<u64, Self::Error> {
fn call(&mut self, id: usize, args: &[Value]) -> Result<u128, Self::Error> {
let mut args_u64: Vec<u64> = Vec::new();
for arg in args {
if arg.ty() == Type::V128 {
Expand All @@ -81,23 +81,23 @@ impl Instance for LocalInstance {
use std::mem::transmute;
Ok(unsafe {
match args_u64.len() {
0 => (transmute::<_, extern "C" fn() -> u64>(addr))(),
1 => (transmute::<_, extern "C" fn(u64) -> u64>(addr))(args_u64[0]),
0 => (transmute::<_, extern "C" fn() -> u128>(addr))(),
1 => (transmute::<_, extern "C" fn(u64) -> u128>(addr))(args_u64[0]),
2 => {
(transmute::<_, extern "C" fn(u64, u64) -> u64>(addr))(args_u64[0], args_u64[1])
(transmute::<_, extern "C" fn(u64, u64) -> u128>(addr))(args_u64[0], args_u64[1])
}
3 => (transmute::<_, extern "C" fn(u64, u64, u64) -> u64>(addr))(
3 => (transmute::<_, extern "C" fn(u64, u64, u64) -> u128>(addr))(
args_u64[0],
args_u64[1],
args_u64[2],
),
4 => (transmute::<_, extern "C" fn(u64, u64, u64, u64) -> u64>(addr))(
4 => (transmute::<_, extern "C" fn(u64, u64, u64, u64) -> u128>(addr))(
args_u64[0],
args_u64[1],
args_u64[2],
args_u64[3],
),
5 => (transmute::<_, extern "C" fn(u64, u64, u64, u64, u64) -> u64>(addr))(
5 => (transmute::<_, extern "C" fn(u64, u64, u64, u64, u64) -> u128>(addr))(
args_u64[0],
args_u64[1],
args_u64[2],
Expand Down

0 comments on commit 4535274

Please sign in to comment.