Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
target: x86_64-unknown-none
target: x86_64-unknown-none,wasm32-unknown-unknown
components: clippy
- name: Setup
run: sudo apt update && sudo apt install gcc-multilib just
Expand All @@ -43,7 +43,7 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
target: x86_64-unknown-none
target: x86_64-unknown-none,wasm32-unknown-unknown
- name: Setup
run: |
sudo apt update && sudo apt install gcc-multilib just
Expand Down
93 changes: 90 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@
#![feature(unboxed_closures)]
#![cfg_attr(feature = "thread_local_cache", feature(thread_local))]

pub mod buddy;
pub mod refcnt;
pub use buddy::BuddyAllocator;
pub mod arrayvec;
pub mod bitpack;
pub mod controlreg;
pub mod elfloader;
pub mod ipaddr;
pub mod pipe;
pub mod protocol;
pub mod sendable;
pub mod util;

#[cfg(feature = "std")]
pub mod mmap;
#[cfg(not(target_family = "wasm"))]
#[path = "."]
mod not_wasm {
pub mod arrayvec;
pub mod buddy;
pub mod controlreg;
pub mod elfloader;
pub mod ipaddr;
pub mod pipe;
pub mod protocol;
pub mod refcnt;
pub mod sendable;
pub mod util;

#[cfg(feature = "std")]
pub mod mmap;
}

#[cfg(not(target_family = "wasm"))]
pub use not_wasm::{buddy::BuddyAllocator, *};

#[repr(C)]
#[derive(Debug)]
Expand Down
2 changes: 2 additions & 0 deletions fix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ crossbeam-queue = {

[build-dependencies]
fixshell = { path = "shell", artifact="staticlib", target = "x86_64-unknown-none" }
fixpostprocessor = { path = "postprocessor" }
fixprocedure = { path = "procedure", artifact = "cdylib", target = "wasm32-unknown-unknown" }
anyhow = "1.0.98"
bindgen = "0.72.1"
cc = "1.2.30"
Expand Down
2 changes: 1 addition & 1 deletion fix/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn main() -> Result<()> {
);
}
let wat = std::fs::read(f.path())?;
let wasm = wat2wasm(&wat)?;
let wasm = fixpostprocessor::process(&wat2wasm(&wat)?)?;
let (c, h) = wasm2c(&wasm)?;
let elf = c2elf(&c, &h)?;
std::fs::write(&dst, elf)?;
Expand Down
9 changes: 9 additions & 0 deletions fix/postprocessor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "fixpostprocessor"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0.104"
wasm-encoder = { version = "0.245.1", features = ["wasmparser"] }
wasmparser = "0.245.1"
38 changes: 38 additions & 0 deletions fix/postprocessor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::Result;
use wasm_encoder::{
MemorySection, MemoryType, Module, RawSection,
reencode::{Reencode, RoundtripReencoder},
};
use wasmparser::{Parser, Payload};

pub fn process(wasm: &[u8]) -> Result<Vec<u8>> {
let mut module = Module::new();
for payload in Parser::new(0).parse_all(wasm) {
match payload? {
Payload::MemorySection(section) => {
let mut memory_section = MemorySection::new();
RoundtripReencoder.parse_memory_section(&mut memory_section, section)?;
// Inject one hardcoded memory
memory_section.memory(MemoryType {
minimum: 1,
maximum: None,
memory64: false,
shared: false,
page_size_log2: None,
});
module.section(&memory_section);
}
// Don't change other sections
payload => {
if let Some((id, range)) = payload.as_section() {
module.section(&RawSection {
id,
data: &wasm[range],
});
}
}
}
}

Ok(module.finish())
}
11 changes: 11 additions & 0 deletions fix/procedure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "fixprocedure"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
fixutils = { path = "../utils" }
dlmalloc = { version = "0.2.14", features = ["global"] }
25 changes: 25 additions & 0 deletions fix/procedure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![cfg_attr(target_arch = "wasm32", no_std)]
use dlmalloc::GlobalDlmalloc;
#[global_allocator]
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;
use fixutils::*;

extern crate alloc;
use alloc::vec::Vec;

const HELLO: &[u8] = b"hello";
const WORLD: &[u8] = b" world";

#[fix_entrypoint]
pub fn _fixpoint_apply(_combination: RustHandle) -> RustHandle {
unsafe {
let mut blob: Vec<u8> = HELLO.to_vec();
memory_1_write(blob.as_ptr() as u32, blob.len());
let handle = create_blob(1, blob.len());
attach_blob(1, &handle);
memory_1_read(blob.as_mut_ptr() as u32, len(&handle));
blob.append(&mut WORLD.to_vec());
memory_1_write(blob.as_ptr() as u32, blob.len());
create_blob(1, blob.len())
}
}
30 changes: 28 additions & 2 deletions fix/shell/src/fixpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub unsafe extern "C" fn w2c_fixpoint_attach_blob(
let addr = (1usize << 32) * memory_idx as usize;
let len = shell::fixpoint_attach_blob(addr as *mut c_void, handle.bytes);
// TODO: this math is wrong
(*memory).pages = (len as u64 / PAGE_SIZE as u64) + 1;
(*memory).pages = len.div_ceil(PAGE_SIZE as usize) as u64;
(*memory).max_pages = (1u64 << 32) / PAGE_SIZE as u64;
(*memory).size = len as u64;
(*memory).size = (*memory).pages * PAGE_SIZE as u64;
}
}

Expand Down Expand Up @@ -102,6 +102,24 @@ pub unsafe extern "C" fn w2c_fixpoint_create_blob_i32(
}
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn w2c_fixpoint_create_blob(
fixpoint: *mut w2c_fixpoint,
memory_index: u32,
length: u32,
) -> wasm_rt_externref_t {
assert!(memory_index < 63);
unsafe {
let memory = crate::rt::MEMORIES[memory_index as usize];
wasm_rt_externref_t {
bytes: shell::fixpoint_create_blob(core::slice::from_raw_parts(
(*memory).data,
length as usize,
)),
}
}
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn w2c_fixpoint_is_blob_obj(
fixpoint: *mut w2c_fixpoint,
Expand Down Expand Up @@ -162,3 +180,11 @@ pub unsafe extern "C" fn w2c_fixpoint_create_strict_encode(
bytes: shell::fixpoint_create_strict_encode(handle.bytes),
}
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn w2c_fixpoint_len(
fixpoint: *mut w2c_fixpoint,
handle: wasm_rt_externref_t,
) -> usize {
shell::fixpoint_len(handle.bytes)
}
2 changes: 1 addition & 1 deletion fix/shell/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub fn fixpoint_create_strict_encode(handle: [u8; 32]) -> [u8; 32] {
encode.pack()
}

fn fixpoint_len(handle: [u8; 32]) -> usize {
pub fn fixpoint_len(handle: [u8; 32]) -> usize {
let handle = Handle::unpack(handle);
handle.len()
}
Loading
Loading