|
|
@@ -86,70 +86,6 @@ pub(crate) fn set_return_data(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, le
|
|
|
wasm::entrypoint::SUCCESS
|
|
|
}
|
|
|
|
|
|
-/// Appends a new object to the [`Env`] objects store.
|
|
|
-/// The data for the object is read from `ptr`.
|
|
|
-///
|
|
|
-/// Returns an index corresponding to the new object's index in the objects
|
|
|
-/// store. (This index is equal to the last index in the store.)
|
|
|
-///
|
|
|
-/// Permissions:
|
|
|
-pub(crate) fn put_object_bytes(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u32) -> i64 {
|
|
|
- let (env, mut store) = ctx.data_and_store_mut();
|
|
|
- let cid = env.contract_id;
|
|
|
-
|
|
|
- // Enforce function ACL
|
|
|
- if let Err(e) = acl_allow(env, &[]) {
|
|
|
- error!(
|
|
|
- target: "runtime::util::put_object_bytes()",
|
|
|
- "[WASM] [{}] put_object_bytes(): Called in unauthorized section: {}", cid, e,
|
|
|
- );
|
|
|
- return darkfi_sdk::error::CALLER_ACCESS_DENIED
|
|
|
- }
|
|
|
-
|
|
|
- // Subtract used gas. Here we count the length read from the memory slice.
|
|
|
- env.subtract_gas(&mut store, len as u64);
|
|
|
-
|
|
|
- let memory_view = env.memory_view(&store);
|
|
|
- //debug!(target: "runtime::util", "diagnostic:");
|
|
|
- let pages = memory_view.size().0;
|
|
|
- //debug!(target: "runtime::util", " pages: {}", pages);
|
|
|
-
|
|
|
- let Ok(slice) = ptr.slice(&memory_view, len) else {
|
|
|
- error!(
|
|
|
- target: "runtime::util::put_object_bytes",
|
|
|
- "[WASM] [{}] put_object_bytes(): Failed to make slice from ptr", cid,
|
|
|
- );
|
|
|
- return darkfi_sdk::error::INTERNAL_ERROR
|
|
|
- };
|
|
|
-
|
|
|
- let mut buf = vec![0_u8; len as usize];
|
|
|
- if let Err(e) = slice.read_slice(&mut buf) {
|
|
|
- error!(
|
|
|
- target: "runtime::util::put_object_bytes",
|
|
|
- "[WASM] [{}] put_object_bytes(): Failed to read from memory slice: {}", cid, e,
|
|
|
- );
|
|
|
- return darkfi_sdk::error::INTERNAL_ERROR
|
|
|
- };
|
|
|
-
|
|
|
- // There would be a serious problem if this is zero.
|
|
|
- // The number of pages is calculated as a quantity X + 1 where X >= 0
|
|
|
- assert!(pages > 0);
|
|
|
-
|
|
|
- //debug!(target: "runtime::util", " memory: {:02x?}", &buf[0..32]);
|
|
|
- //debug!(target: "runtime::util", " {:x?}", &buf[32..64]);
|
|
|
- //debug!(target: "runtime::util", " ptr location: {}", ptr.offset());
|
|
|
-
|
|
|
- let mut objects = env.objects.borrow_mut();
|
|
|
- objects.push(buf);
|
|
|
- let obj_idx = objects.len() - 1;
|
|
|
-
|
|
|
- if obj_idx > u32::MAX as usize {
|
|
|
- return darkfi_sdk::error::DATA_TOO_LARGE
|
|
|
- }
|
|
|
-
|
|
|
- obj_idx as i64
|
|
|
-}
|
|
|
-
|
|
|
/// Retrieve an object from the object store specified by the index `idx`.
|
|
|
/// The object's data is written to `ptr`.
|
|
|
///
|