Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: mojo/monacl/mojo_syscall_internal.h

Issue 385983008: Mojo + NaCl prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ClipDep Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_MONACL_MONACL_SYSCALL_INTERNAL_H_
6 #define MOJO_MONACL_MONACL_SYSCALL_INTERNAL_H_
7
8 #include "native_client/src/trusted/service_runtime/nacl_copy.h"
9 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
10
11 namespace {
12
13 class ScopedCopyLock {
14 public:
15 explicit ScopedCopyLock(struct NaClApp* nap) : nap_(nap) {
16 NaClCopyTakeLock(nap_);
17 }
18 ~ScopedCopyLock() {
19 NaClCopyDropLock(nap_);
20 }
21 private:
22 struct NaClApp* nap_;
23 };
24
25 static INLINE uintptr_t NaClUserToSysAddrArray(
Mark Seaborn 2014/09/10 23:19:21 "inline" (lower case), since this is C++.
Nick Bray (chromium) 2014/09/11 00:56:40 Done.
26 struct NaClApp* nap,
27 uint32_t uaddr,
28 size_t count,
29 size_t size) {
30 // TODO(ncbray): overflow checking
31 size_t range = count * size;
32 return NaClUserToSysAddrRange(nap, uaddr, range);
33 }
34
35 template <typename T> bool ConvertScalarInput(
36 struct NaClApp* nap,
37 uint32_t user_ptr,
38 T* value) {
39 if (user_ptr) {
40 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T));
41 if (temp != kNaClBadAddress) {
42 *value = *reinterpret_cast<T volatile*>(temp);
43 return true;
44 }
45 }
46 return false;
47 }
48
49 template <typename T> bool ConvertScalarOutput(
50 struct NaClApp* nap,
51 uint32_t user_ptr,
52 T volatile** sys_ptr) {
53 if (user_ptr) {
54 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T));
55 if (temp != kNaClBadAddress) {
56 *sys_ptr = reinterpret_cast<T volatile*>(temp);
57 return true;
58 }
59 }
60 *sys_ptr = 0; // Paranoia.
61 return false;
62 }
63
64 template <typename T> bool ConvertScalarInOut(
65 struct NaClApp* nap,
66 uint32_t user_ptr,
67 bool optional,
68 T* value,
69 T volatile** sys_ptr) {
70 if (user_ptr) {
71 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T));
72 if (temp != kNaClBadAddress) {
73 T volatile* converted = reinterpret_cast<T volatile*>(temp);
74 *sys_ptr = converted;
75 *value = *converted;
76 return true;
77 }
78 } else if (optional) {
79 *sys_ptr = 0;
80 *value = static_cast<T>(0); // Paranoia.
81 return true;
82 }
83 *sys_ptr = 0; // Paranoia.
84 *value = static_cast<T>(0); // Paranoia.
85 return false;
86 }
87
88 template <typename T> bool ConvertArray(
89 struct NaClApp* nap,
90 uint32_t user_ptr,
91 uint32_t length,
92 bool optional,
93 T** sys_ptr) {
94 if (user_ptr) {
95 uintptr_t temp = NaClUserToSysAddrArray(nap, user_ptr, length, sizeof(T));
96 if (temp != kNaClBadAddress) {
97 *sys_ptr = reinterpret_cast<T*>(temp);
98 return true;
99 }
100 } else if (optional) {
101 *sys_ptr = 0;
102 return true;
103 }
104 return false;
105 }
106
107 template <typename T> bool ConvertBytes(
108 struct NaClApp* nap,
109 uint32_t user_ptr,
110 uint32_t length,
111 bool optional,
112 T** sys_ptr) {
113 if (user_ptr) {
114 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, length);
115 if (temp != kNaClBadAddress) {
116 *sys_ptr = reinterpret_cast<T*>(temp);
117 return true;
118 }
119 } else if (optional) {
120 *sys_ptr = 0;
121 return true;
122 }
123 return false;
124 }
125
126 // TODO(ncbray): size validation and complete copy.
127 // TODO(ncbray): ensure non-null / missized structs are covered by a test case.
128 template <typename T> bool ConvertStruct(
129 struct NaClApp* nap,
130 uint32_t user_ptr,
131 bool optional,
132 T** sys_ptr) {
133 if (user_ptr) {
134 uintptr_t temp = NaClUserToSysAddrRange(nap, user_ptr, sizeof(T));
135 if (temp != kNaClBadAddress) {
136 *sys_ptr = reinterpret_cast<T*>(temp);
137 return true;
138 }
139 } else if (optional) {
140 *sys_ptr = 0;
141 return true;
142 }
143 return false;
144 }
145
146 } // namespace
147
148 #endif // MOJO_MONACL_MONACL_SYSCALL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698