Protect libc functions via m3ApiCheckMem
@@ -39,6 +39,8 @@ m3ApiRawFunction(m3_libc_memset)
m3ApiGetArg (int32_t, i_value)
m3ApiGetArg (int32_t, i_size)
+ m3ApiCheckMem(i_ptr, i_size);
+
u32 result = m3ApiPtrToOffset(memset (i_ptr, i_value, i_size));
m3ApiReturn(result);
}
@@ -51,6 +53,9 @@ m3ApiRawFunction(m3_libc_memmove)
m3ApiGetArgMem (void*, i_src)
m3ApiGetArg (int32_t, i_size)
+ m3ApiCheckMem(o_dst, i_size);
+ m3ApiCheckMem(i_src, i_size);
+
u32 result = m3ApiPtrToOffset(memmove (o_dst, i_src, i_size));
m3ApiReturn(result);
}
@@ -62,6 +67,8 @@ m3ApiRawFunction(m3_libc_print)
m3ApiGetArgMem (void*, i_ptr)
m3ApiGetArg (uint32_t, i_size)
+ m3ApiCheckMem(i_ptr, i_size);
+
fwrite(i_ptr, i_size, 1, stdout);
fflush(stdout);
@@ -89,33 +96,11 @@ m3ApiRawFunction(m3_spectest_dummy)
m3ApiSuccess();
}
-m3ApiRawFunction(m3_wasm3_raw_sum)
-{
- m3ApiReturnType (int64_t)
- m3ApiGetArg (int32_t, val1)
- m3ApiGetArg (int32_t, val2)
- m3ApiGetArg (int32_t, val3)
- m3ApiGetArg (int32_t, val4)
-
- m3ApiReturn(val1 + val2 + val3 + val4);
-
- m3ApiSuccess();
-}
-
-/* TODO: implement direct native function calls (using libffi?)
-i64 m3_wasm3_native_sum(i32 val1, i32 val2, i32 val3, i32 val4)
-{
- return val1 + val2 + val3 + val4;
-}
-*/
-
-
M3Result m3_LinkSpecTest (IM3Module module)
{
M3Result result = m3Err_none;
const char* spectest = "spectest";
- const char* wasm3 = "wasm3";
_ (SuppressLookupFailure (m3_LinkRawFunction (module, spectest, "print", "v()", &m3_spectest_dummy)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, spectest, "print_i32", "v(i)", &m3_spectest_dummy)));
@@ -125,10 +110,6 @@ _ (SuppressLookupFailure (m3_LinkRawFunction (module, spectest, "print_f64",
_ (SuppressLookupFailure (m3_LinkRawFunction (module, spectest, "print_i32_f32", "v(if)", &m3_spectest_dummy)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, spectest, "print_i64_f64", "v(IF)", &m3_spectest_dummy)));
-
-_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasm3, "raw_sum", "I(iiii)", &m3_wasm3_raw_sum)));
-//_ (SuppressLookupFailure (m3_LinkCFunction (module, wasm3, "native_sum", "I(iiii)", &m3_wasm3_native_sum)));
-
_catch:
return result;
}
