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

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc

Issue 11592003: Add support for simple run of "main" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace missing stdio Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 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 #if defined(WIN32) 5 #if defined(WIN32)
6 #define _CRT_RAND_S 6 #define _CRT_RAND_S
7 #endif 7 #endif
8 8
9 #include "nacl_mounts/mount_dev.h"
10 #include <errno.h> 9 #include <errno.h>
11 #include <fcntl.h> 10 #include <fcntl.h>
12 #include <string.h> 11 #include <string.h>
12 #include "nacl_mounts/mount_dev.h"
13 #include "nacl_mounts/mount_node.h" 13 #include "nacl_mounts/mount_node.h"
14 #include "nacl_mounts/mount_node_dir.h" 14 #include "nacl_mounts/mount_node_dir.h"
15 #include "nacl_mounts/pepper_interface.h"
15 #include "utils/auto_lock.h" 16 #include "utils/auto_lock.h"
16 17
17 #if defined(__native_client__) 18 #if defined(__native_client__)
18 # include <irt.h> 19 # include <irt.h>
19 #elif defined(WIN32) 20 #elif defined(WIN32)
20 # include <stdlib.h> 21 # include <stdlib.h>
21 #endif 22 #endif
22 23
23 namespace { 24 namespace {
24 25
25 void ReleaseAndNullNode(MountNode** node) { 26 void ReleaseAndNullNode(MountNode** node) {
26 if (*node) 27 if (*node)
27 (*node)->Release(); 28 (*node)->Release();
28 *node = NULL; 29 *node = NULL;
29 } 30 }
30 31
31 class NullNode : public MountNode { 32 class NullNode : public MountNode {
32 public: 33 public:
33 NullNode(Mount* mount, int ino, int dev); 34 NullNode(Mount* mount, int ino, int dev);
34 35
35 virtual int Read(size_t offs, void* buf, size_t count); 36 virtual int Read(size_t offs, void* buf, size_t count);
36 virtual int Write(size_t offs, const void* buf, size_t count); 37 virtual int Write(size_t offs, const void* buf, size_t count);
37 }; 38 };
38 39
40 class ConsoleNode : public NullNode {
41 public:
42 ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level);
43
44 virtual int Write(size_t offs, const void* buf, size_t count);
45
46 private:
47 PP_LogLevel level_;
48 };
49
50
51 class TtyNode : public NullNode {
52 public:
53 TtyNode(Mount* mount, int ino, int dev);
54
55 virtual int Write(size_t offs, const void* buf, size_t count);
56 };
57
58
39 class ZeroNode : public MountNode { 59 class ZeroNode : public MountNode {
40 public: 60 public:
41 ZeroNode(Mount* mount, int ino, int dev); 61 ZeroNode(Mount* mount, int ino, int dev);
42 62
43 virtual int Read(size_t offs, void* buf, size_t count); 63 virtual int Read(size_t offs, void* buf, size_t count);
44 virtual int Write(size_t offs, const void* buf, size_t count); 64 virtual int Write(size_t offs, const void* buf, size_t count);
45 }; 65 };
46 66
47 class UrandomNode : public MountNode { 67 class UrandomNode : public MountNode {
48 public: 68 public:
(...skipping 14 matching lines...) Expand all
63 } 83 }
64 84
65 int NullNode::Read(size_t offs, void* buf, size_t count) { 85 int NullNode::Read(size_t offs, void* buf, size_t count) {
66 return 0; 86 return 0;
67 } 87 }
68 88
69 int NullNode::Write(size_t offs, const void* buf, size_t count) { 89 int NullNode::Write(size_t offs, const void* buf, size_t count) {
70 return count; 90 return count;
71 } 91 }
72 92
93 ConsoleNode::ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level)
94 : NullNode(mount, ino, dev),
95 level_(level) {
96 }
97
98 int ConsoleNode::Write(size_t offs, const void* buf, size_t count) {
99 ConsoleInterface* con_intr = mount_->ppapi()->GetConsoleInterface();
100 VarInterface* var_intr = mount_->ppapi()->GetVarInterface();
101
102 if (var_intr && con_intr) {
103 const char* data = static_cast<const char *>(buf);
104 uint32_t len = static_cast<uint32_t>(count);
105 struct PP_Var val = var_intr->VarFromUtf8(data, len);
106 con_intr->Log(mount_->ppapi()->GetInstance(), level_, val);
107 return count;
108 }
109 return 0;
110 }
111
112
113 TtyNode::TtyNode(Mount* mount, int ino, int dev)
114 : NullNode(mount, ino, dev) {
115 }
116
117 int TtyNode::Write(size_t offs, const void* buf, size_t count) {
118 MessagingInterface* msg_intr = mount_->ppapi()->GetMessagingInterface();
119 VarInterface* var_intr = mount_->ppapi()->GetVarInterface();
120
121 if (var_intr && msg_intr) {
122 const char* data = static_cast<const char *>(buf);
123 uint32_t len = static_cast<uint32_t>(count);
124 struct PP_Var val = var_intr->VarFromUtf8(data, len);
125 msg_intr->PostMessage(mount_->ppapi()->GetInstance(), val);
126 return count;
127 }
128 return 0;
129 }
130
131
73 ZeroNode::ZeroNode(Mount* mount, int ino, int dev) 132 ZeroNode::ZeroNode(Mount* mount, int ino, int dev)
74 : MountNode(mount, ino, dev) { 133 : MountNode(mount, ino, dev) {
75 } 134 }
76 135
77 int ZeroNode::Read(size_t offs, void* buf, size_t count) { 136 int ZeroNode::Read(size_t offs, void* buf, size_t count) {
78 memset(buf, 0, count); 137 memset(buf, 0, count);
79 return count; 138 return count;
80 } 139 }
81 140
82 int ZeroNode::Write(size_t offs, const void* buf, size_t count) { 141 int ZeroNode::Write(size_t offs, const void* buf, size_t count) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 184 }
126 185
127 return count; 186 return count;
128 #endif 187 #endif
129 } 188 }
130 189
131 int UrandomNode::Write(size_t offs, const void* buf, size_t count) { 190 int UrandomNode::Write(size_t offs, const void* buf, size_t count) {
132 return count; 191 return count;
133 } 192 }
134 193
194
195
135 } // namespace 196 } // namespace
136 197
137 MountNode *MountDev::Open(const Path& path, int mode) { 198 MountNode *MountDev::Open(const Path& path, int mode) {
138 AutoLock lock(&lock_); 199 AutoLock lock(&lock_);
139 200
140 // Don't allow creating any files. 201 // Don't allow creating any files.
141 if (mode & O_CREAT) 202 if (mode & O_CREAT)
142 return NULL; 203 return NULL;
143 204
144 MountNode* node = root_->FindChild(path.Join()); 205 MountNode* node = root_->FindChild(path.Join());
(...skipping 25 matching lines...) Expand all
170 } 231 }
171 232
172 int MountDev::Remove(const Path& path) { 233 int MountDev::Remove(const Path& path) {
173 errno = EINVAL; 234 errno = EINVAL;
174 return -1; 235 return -1;
175 } 236 }
176 237
177 MountDev::MountDev() 238 MountDev::MountDev()
178 : null_node_(NULL), 239 : null_node_(NULL),
179 zero_node_(NULL), 240 zero_node_(NULL),
180 random_node_(NULL) { 241 random_node_(NULL),
242 console0_node_(NULL),
243 console1_node_(NULL),
244 console2_node_(NULL),
245 console3_node_(NULL),
246 tty_node_(NULL) {
181 } 247 }
182 248
183 bool MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) { 249 bool MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
184 if (!Mount::Init(dev, args, ppapi)) 250 if (!Mount::Init(dev, args, ppapi))
185 return false; 251 return false;
186 252
187 root_ = new MountNodeDir(this, 1, dev_); 253 root_ = new MountNodeDir(this, 1, dev_);
188 null_node_ = new NullNode(this, 2, dev_); 254 null_node_ = new NullNode(this, 2, dev_);
189 root_->AddChild("/null", null_node_); 255 root_->AddChild("/null", null_node_);
190 zero_node_ = new ZeroNode(this, 3, dev_); 256 zero_node_ = new ZeroNode(this, 3, dev_);
191 root_->AddChild("/zero", zero_node_); 257 root_->AddChild("/zero", zero_node_);
192 random_node_ = new UrandomNode(this, 4, dev_); 258 random_node_ = new UrandomNode(this, 4, dev_);
193 root_->AddChild("/urandom", random_node_); 259 root_->AddChild("/urandom", random_node_);
260
261 console0_node_ = new ConsoleNode(this, 5, dev_, PP_LOGLEVEL_TIP);
262 root_->AddChild("/console0", console0_node_);
263 console1_node_ = new ConsoleNode(this, 6, dev_, PP_LOGLEVEL_LOG);
264 root_->AddChild("/console1", console1_node_);
265 console2_node_ = new ConsoleNode(this, 7, dev_, PP_LOGLEVEL_WARNING);
266 root_->AddChild("/console2", console2_node_);
267 console3_node_ = new ConsoleNode(this, 8, dev_, PP_LOGLEVEL_ERROR);
268 root_->AddChild("/console3", console3_node_);
269
270 tty_node_ = new TtyNode(this, 9, dev_);
271 root_->AddChild("/tty", tty_node_);
194 return true; 272 return true;
195 } 273 }
196 274
197 void MountDev::Destroy() { 275 void MountDev::Destroy() {
276 ReleaseAndNullNode(&tty_node_);
277 ReleaseAndNullNode(&console3_node_);
278 ReleaseAndNullNode(&console2_node_);
279 ReleaseAndNullNode(&console1_node_);
280 ReleaseAndNullNode(&console0_node_);
198 ReleaseAndNullNode(&random_node_); 281 ReleaseAndNullNode(&random_node_);
199 ReleaseAndNullNode(&zero_node_); 282 ReleaseAndNullNode(&zero_node_);
200 ReleaseAndNullNode(&null_node_); 283 ReleaseAndNullNode(&null_node_);
201 ReleaseAndNullNode(&root_); 284 ReleaseAndNullNode(&root_);
202 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698