Chromium Code Reviews| Index: nacl_bindings/mojo_syscall_internal.h |
| diff --git a/nacl_bindings/mojo_syscall_internal.h b/nacl_bindings/mojo_syscall_internal.h |
| index 9200c1a1b3f37256a9e77220573cff47e035232b..5bcbd3400bd9591561bbab3c148e435003134983 100644 |
| --- a/nacl_bindings/mojo_syscall_internal.h |
| +++ b/nacl_bindings/mojo_syscall_internal.h |
| @@ -51,6 +51,68 @@ static inline void memcpy_volatile_out(void volatile* dst, |
| } |
| template <typename T> |
| +bool ConvertPointerInput(struct NaClApp* nap, uint32_t user_ptr, T** value) { |
|
viettrungluu
2015/04/13 20:09:42
Note: You could achieve this via a specialization
Nick Bray (chromium)
2015/04/13 21:13:51
Done.
|
| + if (user_ptr) { |
| + uintptr_t temp = NaClUserToSysAddr(nap, user_ptr); |
| + if (temp != kNaClBadAddress) { |
| + *value = reinterpret_cast<T*>(temp); |
| + return true; |
| + } |
| + } else { |
| + *value = nullptr; |
| + return true; |
| + } |
| + *value = nullptr; // Paranoia. |
| + return false; |
| +} |
| + |
| +template <typename T> |
| +bool ConvertPointerInOut(struct NaClApp* nap, |
|
viettrungluu
2015/04/13 20:09:42
"
|
| + uint32_t user_ptr, |
| + bool optional, |
| + T** value, |
| + uint32_t volatile** sys_ptr) { |
| + if (user_ptr) { |
| + uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(uint32_t)); |
| + if (temp != kNaClBadAddress) { |
| + uint32_t volatile* converted_ptr = |
| + reinterpret_cast<uint32_t volatile*>(temp); |
| + uint32_t raw_value = *converted_ptr; |
| + if (!raw_value) { |
| + *sys_ptr = converted_ptr; |
| + *value = nullptr; |
| + return true; |
| + } |
| + uintptr_t temp = NaClUserToSysAddr(nap, raw_value); |
| + if (temp != kNaClBadAddress) { |
| + *sys_ptr = converted_ptr; |
| + *value = reinterpret_cast<T*>(temp); |
| + return true; |
| + } |
| + } |
| + } else if (optional) { |
| + *sys_ptr = nullptr; |
| + *value = nullptr; // Paranoia. |
| + return true; |
| + } |
| + *sys_ptr = nullptr; // Paranoia. |
| + *value = nullptr; // Paranoia. |
| + return false; |
| +} |
| + |
| +template <typename T> |
| +void CopyOutPointer(struct NaClApp* nap, T* value, uint32_t volatile* sys_ptr) { |
| + if (value) { |
| + // Will kill the process if value if the pointer does not lie in the |
| + // sandbox. |
| + uintptr_t temp = NaClSysToUser(nap, reinterpret_cast<uintptr_t>(value)); |
| + *sys_ptr = static_cast<uint32_t>(temp); |
| + } else { |
| + *sys_ptr = 0; |
| + } |
| +} |
| + |
| +template <typename T> |
| bool ConvertScalarInput(struct NaClApp* nap, uint32_t user_ptr, T* value) { |
| if (user_ptr) { |
| uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); |