Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsafe {
- slice::from_raw_parts(input_data, input_len)
- }
- let bytes: [u8; 4] = unsafe { std::mem::transmute::<u32, [u8; 4]>(bytes.to_le()) };
- unsafe {
- #[allow(mutable_transmutes)]
- rstd::mem::transmute::<_, &'static mut [u8]>(&b""[..])
- }
- unsafe {
- ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
- }
- unsafe {
- #c::runtime_api::slice::from_raw_parts(input_data, input_len)
- }
- unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Send for RuntimeApiImpl<C> {}
- unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Sync for RuntimeApiImpl<C> {}
- call: unsafe { ::std::mem::transmute(call) }
- let res = unsafe {
- call_api_at(
- &self.call,
- self,
- &self.changes,
- &self.initialized_block,
- &self.recorder,
- )
- };
- unsafe { str::from_utf8_unchecked(&self.name) }
- unsafe {
- std::slice::from_raw_parts(&self.0 as *const u64 as *const _, std::mem::size_of::<u64>())
- }
- unsafe {
- std::slice::from_raw_parts(
- &self.0 as *const _ as *const u8,
- std::mem::size_of::<u64>(),
- )
- }
- unsafe {
- ffi::ext_sandbox_memory_teardown(self.memory_idx);
- }
- let result = unsafe {
- let maximum = if let Some(maximum) = maximum {
- maximum
- } else {
- sandbox_primitives::MEM_UNLIMITED
- };
- ffi::ext_sandbox_memory_new(initial, maximum)
- };
- let result = unsafe { ffi::ext_sandbox_memory_get(self.handle.memory_idx, offset, buf.as_mut_ptr(), buf.len()) };
- let result = unsafe { ffi::ext_sandbox_memory_set(self.handle.memory_idx, offset, val.as_ptr(), val.len()) };
- let serialized_args = unsafe {
- if serialized_args_len == 0 {
- &[]
- } else {
- slice::from_raw_parts(serialized_args_ptr, serialized_args_len)
- }
- };
- unsafe {
- // This should be safe since `coerce_host_index_to_func` is called with an argument
- // received in an `dispatch_thunk` implementation, so `f` should point
- // on a valid host function.
- let f = ffi::coerce_host_index_to_func(f);
- // This should be safe since mutable reference to T is passed upon the invocation.
- let state = &mut *(state as *mut T);
- // Pass control flow to the designated function.
- let result = f(state, &args).encode();
- // Leak the result vector and return the pointer to return data.
- let result_ptr = result.as_ptr() as u64;
- let result_len = result.len() as u64;
- mem::forget(result);
- (result_ptr << 32) | result_len
- }
- let result = unsafe {
- // It's very important to instantiate thunk with the right type.
- let dispatch_thunk = dispatch_thunk::<T>;
- ffi::ext_sandbox_instantiate(
- dispatch_thunk,
- code.as_ptr(),
- code.len(),
- serialized_env_def.as_ptr(),
- serialized_env_def.len(),
- state as *const T as usize,
- )
- };
- let result = unsafe {
- ffi::ext_sandbox_invoke(
- self.instance_idx,
- name.as_ptr(),
- name.len(),
- serialized_args.as_ptr(),
- serialized_args.len(),
- return_val.as_mut_ptr(),
- return_val.len(),
- state as *const T as usize,
- )
- };
- unsafe {
- ffi::ext_sandbox_instance_teardown(self.instance_idx);
- }
- unsafe {
- MUTABLE_STATIC += 1;
- MUTABLE_STATIC
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement