mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 14:45:40 +00:00
impl ValueType for fdstat_t
This commit is contained in:
parent
147d71a32c
commit
42e8523c0b
@ -1,8 +1,8 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
use crate::ptr::{Array, WasmPtr};
|
use crate::ptr::{Array, WasmPtr};
|
||||||
use wasmer_runtime_core::types::{ValueError, ValueType};
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use wasmer_runtime_core::types::{ValueError, ValueType};
|
||||||
|
|
||||||
pub type __wasi_advice_t = u8;
|
pub type __wasi_advice_t = u8;
|
||||||
pub const __WASI_ADVICE_DONTNEED: u8 = 0;
|
pub const __WASI_ADVICE_DONTNEED: u8 = 0;
|
||||||
@ -178,7 +178,7 @@ impl ValueType for __wasi_prestat_u_dir_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
||||||
if buffer.len() >= mem::size_of::<__wasi_iovec_t>() {
|
if buffer.len() >= mem::size_of::<__wasi_prestat_u_dir_t>() {
|
||||||
let pr_name_len = ValueType::from_le(&buffer[..mem::size_of::<u32>()])?;
|
let pr_name_len = ValueType::from_le(&buffer[..mem::size_of::<u32>()])?;
|
||||||
Ok(Self { pr_name_len })
|
Ok(Self { pr_name_len })
|
||||||
} else {
|
} else {
|
||||||
@ -195,12 +195,14 @@ pub union __wasi_prestat_u {
|
|||||||
|
|
||||||
impl ValueType for __wasi_prestat_u {
|
impl ValueType for __wasi_prestat_u {
|
||||||
fn into_le(self, buffer: &mut [u8]) {
|
fn into_le(self, buffer: &mut [u8]) {
|
||||||
unsafe {self.dir
|
unsafe {
|
||||||
.into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])};
|
self.dir
|
||||||
|
.into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
||||||
if buffer.len() >= mem::size_of::<__wasi_iovec_t>() {
|
if buffer.len() >= mem::size_of::<__wasi_prestat_u>() {
|
||||||
let dir = ValueType::from_le(&buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])?;
|
let dir = ValueType::from_le(&buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])?;
|
||||||
Ok(Self { dir })
|
Ok(Self { dir })
|
||||||
} else {
|
} else {
|
||||||
@ -225,7 +227,7 @@ impl ValueType for __wasi_prestat_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
||||||
if buffer.len() >= mem::size_of::<__wasi_iovec_t>() {
|
if buffer.len() >= mem::size_of::<__wasi_prestat_t>() {
|
||||||
let pr_type = ValueType::from_le(&buffer[..mem::size_of::<__wasi_preopentype_t>()])?;
|
let pr_type = ValueType::from_le(&buffer[..mem::size_of::<__wasi_preopentype_t>()])?;
|
||||||
let u = ValueType::from_le(&buffer[mem::size_of::<__wasi_preopentype_t>()..])?;
|
let u = ValueType::from_le(&buffer[mem::size_of::<__wasi_preopentype_t>()..])?;
|
||||||
Ok(Self { pr_type, u })
|
Ok(Self { pr_type, u })
|
||||||
@ -244,6 +246,51 @@ pub struct __wasi_fdstat_t {
|
|||||||
pub fs_rights_inheriting: __wasi_rights_t,
|
pub fs_rights_inheriting: __wasi_rights_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ValueType for __wasi_fdstat_t {
|
||||||
|
fn into_le(self, buffer: &mut [u8]) {
|
||||||
|
self.fs_filetype
|
||||||
|
.into_le(&mut buffer[..mem::size_of::<__wasi_filetype_t>()]);
|
||||||
|
self.fs_flags.into_le(
|
||||||
|
&mut buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()],
|
||||||
|
);
|
||||||
|
self.fs_rights_base.into_le(
|
||||||
|
&mut buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>())
|
||||||
|
..mem::size_of::<__wasi_rights_t>()],
|
||||||
|
);
|
||||||
|
self.fs_rights_inheriting.into_le(
|
||||||
|
&mut buffer[(mem::size_of::<__wasi_filetype_t>()
|
||||||
|
+ mem::size_of::<__wasi_fdflags_t>()
|
||||||
|
+ mem::size_of::<__wasi_rights_t>())..],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_le(buffer: &[u8]) -> Result<Self, ValueError> {
|
||||||
|
if buffer.len() >= mem::size_of::<__wasi_fdstat_t>() {
|
||||||
|
let fs_filetype = ValueType::from_le(&buffer[..mem::size_of::<__wasi_filetype_t>()])?;
|
||||||
|
let fs_flags = ValueType::from_le(
|
||||||
|
&buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()],
|
||||||
|
)?;
|
||||||
|
let fs_rights_base = ValueType::from_le(
|
||||||
|
&buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>())
|
||||||
|
..mem::size_of::<__wasi_rights_t>()],
|
||||||
|
)?;
|
||||||
|
let fs_rights_inheriting = ValueType::from_le(
|
||||||
|
&buffer[(mem::size_of::<__wasi_filetype_t>()
|
||||||
|
+ mem::size_of::<__wasi_fdflags_t>()
|
||||||
|
+ mem::size_of::<__wasi_rights_t>())..],
|
||||||
|
)?;
|
||||||
|
Ok(Self {
|
||||||
|
fs_filetype,
|
||||||
|
fs_flags,
|
||||||
|
fs_rights_base,
|
||||||
|
fs_rights_inheriting,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(ValueError::BufferTooSmall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type __wasi_filedelta_t = i64;
|
pub type __wasi_filedelta_t = i64;
|
||||||
|
|
||||||
pub type __wasi_filesize_t = u64;
|
pub type __wasi_filesize_t = u64;
|
||||||
|
Loading…
Reference in New Issue
Block a user