Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ | 5 #ifndef MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ |
| 6 #define MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ | 6 #define MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ |
| 7 | 7 |
| 8 #include "native_client/src/trusted/service_runtime/nacl_copy.h" | 8 #include "native_client/src/trusted/service_runtime/nacl_copy.h" |
| 9 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 9 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 const void* src, | 44 const void* src, |
| 45 size_t n) { | 45 size_t n) { |
| 46 char volatile* c_dst = static_cast<char volatile*>(dst); | 46 char volatile* c_dst = static_cast<char volatile*>(dst); |
| 47 const char* c_src = static_cast<const char*>(src); | 47 const char* c_src = static_cast<const char*>(src); |
| 48 for (size_t i = 0; i < n; i++) { | 48 for (size_t i = 0; i < n; i++) { |
| 49 c_dst[i] = c_src[i]; | 49 c_dst[i] = c_src[i]; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 template <typename T> | 53 template <typename T> |
| 54 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.
| |
| 55 if (user_ptr) { | |
| 56 uintptr_t temp = NaClUserToSysAddr(nap, user_ptr); | |
| 57 if (temp != kNaClBadAddress) { | |
| 58 *value = reinterpret_cast<T*>(temp); | |
| 59 return true; | |
| 60 } | |
| 61 } else { | |
| 62 *value = nullptr; | |
| 63 return true; | |
| 64 } | |
| 65 *value = nullptr; // Paranoia. | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 template <typename T> | |
| 70 bool ConvertPointerInOut(struct NaClApp* nap, | |
|
viettrungluu
2015/04/13 20:09:42
"
| |
| 71 uint32_t user_ptr, | |
| 72 bool optional, | |
| 73 T** value, | |
| 74 uint32_t volatile** sys_ptr) { | |
| 75 if (user_ptr) { | |
| 76 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(uint32_t)); | |
| 77 if (temp != kNaClBadAddress) { | |
| 78 uint32_t volatile* converted_ptr = | |
| 79 reinterpret_cast<uint32_t volatile*>(temp); | |
| 80 uint32_t raw_value = *converted_ptr; | |
| 81 if (!raw_value) { | |
| 82 *sys_ptr = converted_ptr; | |
| 83 *value = nullptr; | |
| 84 return true; | |
| 85 } | |
| 86 uintptr_t temp = NaClUserToSysAddr(nap, raw_value); | |
| 87 if (temp != kNaClBadAddress) { | |
| 88 *sys_ptr = converted_ptr; | |
| 89 *value = reinterpret_cast<T*>(temp); | |
| 90 return true; | |
| 91 } | |
| 92 } | |
| 93 } else if (optional) { | |
| 94 *sys_ptr = nullptr; | |
| 95 *value = nullptr; // Paranoia. | |
| 96 return true; | |
| 97 } | |
| 98 *sys_ptr = nullptr; // Paranoia. | |
| 99 *value = nullptr; // Paranoia. | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 template <typename T> | |
| 104 void CopyOutPointer(struct NaClApp* nap, T* value, uint32_t volatile* sys_ptr) { | |
| 105 if (value) { | |
| 106 // Will kill the process if value if the pointer does not lie in the | |
| 107 // sandbox. | |
| 108 uintptr_t temp = NaClSysToUser(nap, reinterpret_cast<uintptr_t>(value)); | |
| 109 *sys_ptr = static_cast<uint32_t>(temp); | |
| 110 } else { | |
| 111 *sys_ptr = 0; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 template <typename T> | |
| 54 bool ConvertScalarInput(struct NaClApp* nap, uint32_t user_ptr, T* value) { | 116 bool ConvertScalarInput(struct NaClApp* nap, uint32_t user_ptr, T* value) { |
| 55 if (user_ptr) { | 117 if (user_ptr) { |
| 56 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); | 118 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); |
| 57 if (temp != kNaClBadAddress) { | 119 if (temp != kNaClBadAddress) { |
| 58 *value = *reinterpret_cast<T volatile*>(temp); | 120 *value = *reinterpret_cast<T volatile*>(temp); |
| 59 return true; | 121 return true; |
| 60 } | 122 } |
| 61 } | 123 } |
| 62 return false; | 124 return false; |
| 63 } | 125 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 } else if (optional) { | 223 } else if (optional) { |
| 162 *sys_ptr = 0; | 224 *sys_ptr = 0; |
| 163 return true; | 225 return true; |
| 164 } | 226 } |
| 165 return false; | 227 return false; |
| 166 } | 228 } |
| 167 | 229 |
| 168 } // namespace | 230 } // namespace |
| 169 | 231 |
| 170 #endif // MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ | 232 #endif // MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ |
| OLD | NEW |