Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.
Merged
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
70 changes: 58 additions & 12 deletions Cargo.lock

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

30 changes: 22 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![allow(unused_variables)] // TODO: remove this when more things are implemented

use crate::bindings::{
wasi_clocks, wasi_default_clocks, wasi_exit, wasi_filesystem, wasi_logging, wasi_poll,
wasi_random, wasi_stderr, wasi_tcp,
wasi_clocks, wasi_default_clocks, wasi_exit, wasi_filesystem, wasi_poll, wasi_random,
wasi_stderr, wasi_tcp,
};
use core::arch::wasm32;
use core::cell::{Cell, RefCell, UnsafeCell};
use core::cmp::min;
use core::ffi::c_void;
use core::hint::black_box;
use core::mem::{align_of, forget, replace, size_of, ManuallyDrop, MaybeUninit};
use core::mem::{self, align_of, forget, replace, size_of, ManuallyDrop, MaybeUninit};
use core::ptr::{self, null_mut};
use core::slice;
use wasi::*;
Expand Down Expand Up @@ -149,7 +149,7 @@ fn align_to(ptr: usize, align: usize) -> usize {
/// traps when it runs out of data. This means that the total size of
/// arguments/env/etc coming into a component is bounded by the current 64k
/// (ish) limit. That's just an implementation limit though which can be lifted
/// by dynamically calling `memory.grow` as necessary for more data.
/// by dynamically calling the main module's allocator as necessary for more data.
#[no_mangle]
pub unsafe extern "C" fn cabi_export_realloc(
old_ptr: *mut u8,
Expand Down Expand Up @@ -2265,11 +2265,25 @@ impl State {

#[cold]
fn new() -> &'static RefCell<State> {
let grew = wasm32::memory_grow(0, 1);
if grew == usize::MAX {
unreachable!();
#[link(wasm_import_module = "__main_module__")]
extern "C" {
fn cabi_realloc(
old_ptr: *mut u8,
old_len: usize,
align: usize,
new_len: usize,
) -> *mut u8;
}
let ret = (grew * PAGE_SIZE) as *mut RefCell<State>;

let ret = unsafe {
cabi_realloc(
ptr::null_mut(),
0,
mem::align_of::<RefCell<State>>(),
mem::size_of::<RefCell<State>>(),
) as *mut RefCell<State>
};

let ret = unsafe {
ret.write(RefCell::new(State {
magic1: MAGIC,
Expand Down
3 changes: 2 additions & 1 deletion test-programs/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ test = false
quote = "1.0"

[build-dependencies]
wit-component = "0.4.2"
# TODO: switch to release once https://github.com/bytecodealliance/wasm-tools/pull/900 has been released:
wit-component = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "5ba052b9862466258f7e4d153823520ae8dabd88" }