Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. unsafe {
  2. slice::from_raw_parts(input_data, input_len)
  3. }
  4.  
  5.  
  6. let bytes: [u8; 4] = unsafe { std::mem::transmute::<u32, [u8; 4]>(bytes.to_le()) };
  7.  
  8. unsafe {
  9. #[allow(mutable_transmutes)]
  10. rstd::mem::transmute::<_, &'static mut [u8]>(&b""[..])
  11. }
  12.  
  13. unsafe {
  14. ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
  15. }
  16.  
  17. unsafe {
  18. #c::runtime_api::slice::from_raw_parts(input_data, input_len)
  19. }
  20.  
  21. unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Send for RuntimeApiImpl<C> {}
  22.  
  23. unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Sync for RuntimeApiImpl<C> {}
  24.  
  25. call: unsafe { ::std::mem::transmute(call) }
  26.  
  27. let res = unsafe {
  28. call_api_at(
  29. &self.call,
  30. self,
  31. &self.changes,
  32. &self.initialized_block,
  33. &self.recorder,
  34. )
  35. };
  36.  
  37. unsafe { str::from_utf8_unchecked(&self.name) }
  38.  
  39. unsafe {
  40. std::slice::from_raw_parts(&self.0 as *const u64 as *const _, std::mem::size_of::<u64>())
  41. }
  42.  
  43. unsafe {
  44. std::slice::from_raw_parts(
  45. &self.0 as *const _ as *const u8,
  46. std::mem::size_of::<u64>(),
  47. )
  48. }
  49.  
  50. unsafe {
  51. ffi::ext_sandbox_memory_teardown(self.memory_idx);
  52. }
  53.  
  54. let result = unsafe {
  55. let maximum = if let Some(maximum) = maximum {
  56. maximum
  57. } else {
  58. sandbox_primitives::MEM_UNLIMITED
  59. };
  60. ffi::ext_sandbox_memory_new(initial, maximum)
  61. };
  62.  
  63. let result = unsafe { ffi::ext_sandbox_memory_get(self.handle.memory_idx, offset, buf.as_mut_ptr(), buf.len()) };
  64.  
  65. let result = unsafe { ffi::ext_sandbox_memory_set(self.handle.memory_idx, offset, val.as_ptr(), val.len()) };
  66.  
  67. let serialized_args = unsafe {
  68. if serialized_args_len == 0 {
  69. &[]
  70. } else {
  71. slice::from_raw_parts(serialized_args_ptr, serialized_args_len)
  72. }
  73. };
  74.  
  75. unsafe {
  76. // This should be safe since `coerce_host_index_to_func` is called with an argument
  77. // received in an `dispatch_thunk` implementation, so `f` should point
  78. // on a valid host function.
  79. let f = ffi::coerce_host_index_to_func(f);
  80.  
  81. // This should be safe since mutable reference to T is passed upon the invocation.
  82. let state = &mut *(state as *mut T);
  83.  
  84. // Pass control flow to the designated function.
  85. let result = f(state, &args).encode();
  86.  
  87. // Leak the result vector and return the pointer to return data.
  88. let result_ptr = result.as_ptr() as u64;
  89. let result_len = result.len() as u64;
  90. mem::forget(result);
  91.  
  92. (result_ptr << 32) | result_len
  93. }
  94.  
  95. let result = unsafe {
  96. // It's very important to instantiate thunk with the right type.
  97. let dispatch_thunk = dispatch_thunk::<T>;
  98.  
  99. ffi::ext_sandbox_instantiate(
  100. dispatch_thunk,
  101. code.as_ptr(),
  102. code.len(),
  103. serialized_env_def.as_ptr(),
  104. serialized_env_def.len(),
  105. state as *const T as usize,
  106. )
  107. };
  108.  
  109. let result = unsafe {
  110. ffi::ext_sandbox_invoke(
  111. self.instance_idx,
  112. name.as_ptr(),
  113. name.len(),
  114. serialized_args.as_ptr(),
  115. serialized_args.len(),
  116. return_val.as_mut_ptr(),
  117. return_val.len(),
  118. state as *const T as usize,
  119. )
  120. };
  121.  
  122. unsafe {
  123. ffi::ext_sandbox_instance_teardown(self.instance_idx);
  124. }
  125.  
  126. unsafe {
  127. MUTABLE_STATIC += 1;
  128. MUTABLE_STATIC
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement