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 14 matching lines...) Expand all Loading... | |
25 static inline uintptr_t NaClUserToSysAddrArray( | 25 static inline uintptr_t NaClUserToSysAddrArray( |
26 struct NaClApp* nap, | 26 struct NaClApp* nap, |
27 uint32_t uaddr, | 27 uint32_t uaddr, |
28 size_t count, | 28 size_t count, |
29 size_t size) { | 29 size_t size) { |
30 // TODO(ncbray): overflow checking | 30 // TODO(ncbray): overflow checking |
31 size_t range = count * size; | 31 size_t range = count * size; |
32 return NaClUserToSysAddrRange(nap, uaddr, range); | 32 return NaClUserToSysAddrRange(nap, uaddr, range); |
33 } | 33 } |
34 | 34 |
35 void memcpy_volatile_out(void volatile* dst, const void* src, size_t n) { | |
Mark Seaborn
2014/12/08 22:24:12
Shouldn't this be static and/or inline, since it's
Nick Bray (chromium)
2014/12/09 22:14:31
Done.
| |
36 char volatile* c_dst = reinterpret_cast<char volatile*>(dst); | |
37 const char* c_src = reinterpret_cast<const char*>(src); | |
38 for (size_t i = 0; i < n; i++) { | |
39 c_dst[i] = c_src[i]; | |
40 } | |
41 } | |
42 | |
35 template <typename T> bool ConvertScalarInput( | 43 template <typename T> bool ConvertScalarInput( |
36 struct NaClApp* nap, | 44 struct NaClApp* nap, |
37 uint32_t user_ptr, | 45 uint32_t user_ptr, |
38 T* value) { | 46 T* value) { |
39 if (user_ptr) { | 47 if (user_ptr) { |
40 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); | 48 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); |
41 if (temp != kNaClBadAddress) { | 49 if (temp != kNaClBadAddress) { |
42 *value = *reinterpret_cast<T volatile*>(temp); | 50 *value = *reinterpret_cast<T volatile*>(temp); |
43 return true; | 51 return true; |
44 } | 52 } |
45 } | 53 } |
46 return false; | 54 return false; |
47 } | 55 } |
48 | 56 |
49 template <typename T> bool ConvertScalarOutput( | 57 template <typename T> bool ConvertScalarOutput( |
50 struct NaClApp* nap, | 58 struct NaClApp* nap, |
51 uint32_t user_ptr, | 59 uint32_t user_ptr, |
60 bool optional, | |
52 T volatile** sys_ptr) { | 61 T volatile** sys_ptr) { |
53 if (user_ptr) { | 62 if (user_ptr) { |
54 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); | 63 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); |
55 if (temp != kNaClBadAddress) { | 64 if (temp != kNaClBadAddress) { |
56 *sys_ptr = reinterpret_cast<T volatile*>(temp); | 65 *sys_ptr = reinterpret_cast<T volatile*>(temp); |
57 return true; | 66 return true; |
67 } else if (optional) { | |
68 *sys_ptr = 0; | |
69 return true; | |
58 } | 70 } |
59 } | 71 } |
60 *sys_ptr = 0; // Paranoia. | 72 *sys_ptr = 0; // Paranoia. |
61 return false; | 73 return false; |
62 } | 74 } |
63 | 75 |
64 template <typename T> bool ConvertScalarInOut( | 76 template <typename T> bool ConvertScalarInOut( |
65 struct NaClApp* nap, | 77 struct NaClApp* nap, |
66 uint32_t user_ptr, | 78 uint32_t user_ptr, |
67 bool optional, | 79 bool optional, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 132 } |
121 } else if (optional) { | 133 } else if (optional) { |
122 *sys_ptr = 0; | 134 *sys_ptr = 0; |
123 return true; | 135 return true; |
124 } | 136 } |
125 return false; | 137 return false; |
126 } | 138 } |
127 | 139 |
128 // TODO(ncbray): size validation and complete copy. | 140 // TODO(ncbray): size validation and complete copy. |
129 // TODO(ncbray): ensure non-null / missized structs are covered by a test case. | 141 // TODO(ncbray): ensure non-null / missized structs are covered by a test case. |
130 template <typename T> bool ConvertStruct( | 142 template <typename T> bool ConvertExtensibleStructInput( |
131 struct NaClApp* nap, | 143 struct NaClApp* nap, |
132 uint32_t user_ptr, | 144 uint32_t user_ptr, |
133 bool optional, | 145 bool optional, |
134 T** sys_ptr) { | 146 T** sys_ptr) { |
135 if (user_ptr) { | 147 if (user_ptr) { |
136 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); | 148 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T)); |
137 if (temp != kNaClBadAddress) { | 149 if (temp != kNaClBadAddress) { |
138 *sys_ptr = reinterpret_cast<T*>(temp); | 150 *sys_ptr = reinterpret_cast<T*>(temp); |
139 return true; | 151 return true; |
140 } | 152 } |
141 } else if (optional) { | 153 } else if (optional) { |
142 *sys_ptr = 0; | 154 *sys_ptr = 0; |
143 return true; | 155 return true; |
144 } | 156 } |
145 return false; | 157 return false; |
146 } | 158 } |
147 | 159 |
148 } // namespace | 160 } // namespace |
149 | 161 |
150 #endif // MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ | 162 #endif // MOJO_NACL_MOJO_SYSCALL_INTERNAL_H_ |
OLD | NEW |