Skip to content

Commit 57e21ba

Browse files
committed
changes
Signed-off-by: José Ulises Niño Rivera <[email protected]>
1 parent 004983b commit 57e21ba

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

src/expect_interface.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::{
16-
expectations::Expect,
17-
tester::{self, Tester},
18-
};
15+
use crate::tester::Tester;
1916

2017
// As of now, the following expectations do not require "fn returning()" implementations and hence
2118
// no structure is provided for them. Setting of these expectations are built directly into tester.rs:

src/hostcalls.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ pub fn generate_import_list(
6868
(HOST.clone(), EXPECT.clone())
6969
}
7070

71+
cfg_if::cfg_if! {
72+
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
73+
fn get_allocator(caller: &mut Caller<'_, ()>) -> Option<Extern> { get_allocator(&mut caller) }
74+
} else {
75+
fn get_allocator(caller: &mut Caller<'_, ()>) -> Option<Extern> { caller.get_export("proxy_on_memory_allocate")}
76+
}
77+
}
78+
7179
fn get_hostfunc(
7280
store: &mut Store<()>,
7381
_abi_version: AbiVersion,
@@ -674,7 +682,7 @@ fn get_hostfunc(
674682
}
675683
};
676684

677-
let malloc = match caller.get_export("malloc") {
685+
let malloc = match get_allocator(&mut caller) {
678686
Some(Extern::Func(func)) => func,
679687
_ => {
680688
println!(
@@ -812,7 +820,7 @@ fn get_hostfunc(
812820
}
813821
};
814822

815-
let malloc = match caller.get_export("malloc") {
823+
let malloc = match get_allocator(&mut caller) {
816824
Some(Extern::Func(func)) => func,
817825
_ => {
818826
println!(
@@ -1120,7 +1128,7 @@ fn get_hostfunc(
11201128
}
11211129
};
11221130

1123-
let malloc = match caller.get_export("malloc") {
1131+
let malloc = match get_allocator(&mut caller) {
11241132
Some(Extern::Func(func)) => func,
11251133
_ => {
11261134
println!("Error: proxy_get_buffer_bytes cannot get export \"malloc\"");
@@ -1684,6 +1692,43 @@ fn get_hostfunc(
16841692
}
16851693

16861694
/* ---------------------------------- System ---------------------------------- */
1695+
"clock_time_get" => Some(Func::wrap(
1696+
store,
1697+
|mut _caller: Caller<'_, ()>, _clock_id: i32, _precision: i64, _time: i32| -> i32 {
1698+
Status::Ok as i32
1699+
},
1700+
)),
1701+
1702+
"random_get" => Some(Func::wrap(
1703+
store,
1704+
|mut _caller: Caller<'_, ()>, _buf: i32, _buf_len: i32| -> i32 { Status::Ok as i32 },
1705+
)),
1706+
1707+
"fd_write" => Some(Func::wrap(
1708+
store,
1709+
|mut _caller: Caller<'_, ()>,
1710+
_param1: i32,
1711+
_param2: i32,
1712+
_param3: i32,
1713+
_param4: i32|
1714+
-> i32 { Status::Ok as i32 },
1715+
)),
1716+
1717+
"environ_get" => Some(Func::wrap(
1718+
store,
1719+
|mut _caller: Caller<'_, ()>, _param1: i32, _param2: i32| -> i32 { Status::Ok as i32 },
1720+
)),
1721+
1722+
"environ_sizes_get" => Some(Func::wrap(
1723+
store,
1724+
|mut _caller: Caller<'_, ()>, _param1: i32, _param2: i32| -> i32 { Status::Ok as i32 },
1725+
)),
1726+
1727+
"proc_exit" => Some(Func::wrap(
1728+
store,
1729+
|mut _caller: Caller<'_, ()>, _param1: i32| -> () { () },
1730+
)),
1731+
16871732
"proxy_set_effective_context" => {
16881733
Some(Func::wrap(
16891734
store,

0 commit comments

Comments
 (0)