| OLD | NEW |
| 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2013 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 <errno.h> | 9 #include <errno.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 VarInterface* var_intr = mount_->ppapi()->GetVarInterface(); | 213 VarInterface* var_intr = mount_->ppapi()->GetVarInterface(); |
| 214 | 214 |
| 215 if (!(var_intr && msg_intr)) | 215 if (!(var_intr && msg_intr)) |
| 216 return ENOSYS; | 216 return ENOSYS; |
| 217 | 217 |
| 218 // We append the prefix_ to the data in buf, then package it up | 218 // We append the prefix_ to the data in buf, then package it up |
| 219 // and post it as a message. | 219 // and post it as a message. |
| 220 const char* data = static_cast<const char*>(buf); | 220 const char* data = static_cast<const char*>(buf); |
| 221 std::string message; | 221 std::string message; |
| 222 { | 222 { |
| 223 AutoLock lock(&lock_); | 223 AUTO_LOCK(node_lock_); |
| 224 message = prefix_; | 224 message = prefix_; |
| 225 } | 225 } |
| 226 message.append(data, count); | 226 message.append(data, count); |
| 227 uint32_t len = static_cast<uint32_t>(message.size()); | 227 uint32_t len = static_cast<uint32_t>(message.size()); |
| 228 struct PP_Var val = var_intr->VarFromUtf8(message.data(), len); | 228 struct PP_Var val = var_intr->VarFromUtf8(message.data(), len); |
| 229 msg_intr->PostMessage(mount_->ppapi()->GetInstance(), val); | 229 msg_intr->PostMessage(mount_->ppapi()->GetInstance(), val); |
| 230 *out_bytes = count; | 230 *out_bytes = count; |
| 231 return 0; | 231 return 0; |
| 232 } | 232 } |
| 233 | 233 |
| 234 Error TtyNode::Read(size_t offs, void* buf, size_t count, int* out_bytes) { | 234 Error TtyNode::Read(size_t offs, void* buf, size_t count, int* out_bytes) { |
| 235 AutoLock lock(&lock_); | 235 AUTO_LOCK(node_lock_); |
| 236 while (input_buffer_.size() <= 0) { | 236 while (input_buffer_.size() <= 0) { |
| 237 pthread_cond_wait(&is_readable_, &lock_); | 237 pthread_cond_wait(&is_readable_, node_lock_.mutex()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Copies data from the input buffer into buf. | 240 // Copies data from the input buffer into buf. |
| 241 size_t bytes_to_copy = std::min(count, input_buffer_.size()); | 241 size_t bytes_to_copy = std::min(count, input_buffer_.size()); |
| 242 std::copy(input_buffer_.begin(), input_buffer_.begin() + bytes_to_copy, | 242 std::copy(input_buffer_.begin(), input_buffer_.begin() + bytes_to_copy, |
| 243 static_cast<char*>(buf)); | 243 static_cast<char*>(buf)); |
| 244 *out_bytes = bytes_to_copy; | 244 *out_bytes = bytes_to_copy; |
| 245 input_buffer_.erase(input_buffer_.begin(), | 245 input_buffer_.erase(input_buffer_.begin(), |
| 246 input_buffer_.begin() + bytes_to_copy); | 246 input_buffer_.begin() + bytes_to_copy); |
| 247 return 0; | 247 return 0; |
| 248 } | 248 } |
| 249 | 249 |
| 250 Error TtyNode::Ioctl(int request, char* arg) { | 250 Error TtyNode::Ioctl(int request, char* arg) { |
| 251 if (request == TIOCNACLPREFIX) { | 251 if (request == TIOCNACLPREFIX) { |
| 252 // This ioctl is used to change the prefix for this tty node. | 252 // This ioctl is used to change the prefix for this tty node. |
| 253 // The prefix is used to distinguish messages intended for this | 253 // The prefix is used to distinguish messages intended for this |
| 254 // tty node from all the other messages cluttering up the | 254 // tty node from all the other messages cluttering up the |
| 255 // javascript postMessage() channel. | 255 // javascript postMessage() channel. |
| 256 AutoLock lock(&lock_); | 256 AUTO_LOCK(node_lock_); |
| 257 prefix_ = arg; | 257 prefix_ = arg; |
| 258 return 0; | 258 return 0; |
| 259 } else if (request == TIOCNACLINPUT) { | 259 } else if (request == TIOCNACLINPUT) { |
| 260 // This ioctl is used to deliver data from the user to this tty node's | 260 // This ioctl is used to deliver data from the user to this tty node's |
| 261 // input buffer. We check if the prefix in the input data matches the | 261 // input buffer. We check if the prefix in the input data matches the |
| 262 // prefix for this node, and only deliver the data if so. | 262 // prefix for this node, and only deliver the data if so. |
| 263 struct tioc_nacl_input_string* message = | 263 struct tioc_nacl_input_string* message = |
| 264 reinterpret_cast<struct tioc_nacl_input_string*>(arg); | 264 reinterpret_cast<struct tioc_nacl_input_string*>(arg); |
| 265 AutoLock lock(&lock_); | 265 AUTO_LOCK(node_lock_); |
| 266 if (message->length >= prefix_.size() && | 266 if (message->length >= prefix_.size() && |
| 267 strncmp(message->buffer, prefix_.data(), prefix_.size()) == 0) { | 267 strncmp(message->buffer, prefix_.data(), prefix_.size()) == 0) { |
| 268 input_buffer_.insert(input_buffer_.end(), | 268 input_buffer_.insert(input_buffer_.end(), |
| 269 message->buffer + prefix_.size(), | 269 message->buffer + prefix_.size(), |
| 270 message->buffer + message->length); | 270 message->buffer + message->length); |
| 271 pthread_cond_broadcast(&is_readable_); | 271 pthread_cond_broadcast(&is_readable_); |
| 272 return 0; | 272 return 0; |
| 273 } | 273 } |
| 274 return ENOTTY; | 274 return ENOTTY; |
| 275 } else { | 275 } else { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 // Don't allow execute access. | 357 // Don't allow execute access. |
| 358 if (a_mode & X_OK) | 358 if (a_mode & X_OK) |
| 359 return EACCES; | 359 return EACCES; |
| 360 | 360 |
| 361 return 0; | 361 return 0; |
| 362 } | 362 } |
| 363 | 363 |
| 364 Error MountDev::Open(const Path& path, int mode, ScopedMountNode* out_node) { | 364 Error MountDev::Open(const Path& path, int mode, ScopedMountNode* out_node) { |
| 365 out_node->reset(NULL); | 365 out_node->reset(NULL); |
| 366 AutoLock lock(&lock_); | |
| 367 | 366 |
| 368 // Don't allow creating any files. | 367 // Don't allow creating any files. |
| 369 if (mode & O_CREAT) | 368 if (mode & O_CREAT) |
| 370 return EINVAL; | 369 return EINVAL; |
| 371 | 370 |
| 372 return root_->FindChild(path.Join(), out_node); | 371 return root_->FindChild(path.Join(), out_node); |
| 373 } | 372 } |
| 374 | 373 |
| 375 Error MountDev::Unlink(const Path& path) { return EINVAL; } | 374 Error MountDev::Unlink(const Path& path) { return EINVAL; } |
| 376 | 375 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 407 INITIALIZE_DEV_NODE_1("/console2", ConsoleNode, PP_LOGLEVEL_WARNING); | 406 INITIALIZE_DEV_NODE_1("/console2", ConsoleNode, PP_LOGLEVEL_WARNING); |
| 408 INITIALIZE_DEV_NODE_1("/console3", ConsoleNode, PP_LOGLEVEL_ERROR); | 407 INITIALIZE_DEV_NODE_1("/console3", ConsoleNode, PP_LOGLEVEL_ERROR); |
| 409 INITIALIZE_DEV_NODE("/tty", TtyNode); | 408 INITIALIZE_DEV_NODE("/tty", TtyNode); |
| 410 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); | 409 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); |
| 411 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); | 410 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); |
| 412 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); | 411 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); |
| 413 | 412 |
| 414 return 0; | 413 return 0; |
| 415 } | 414 } |
| 416 | 415 |
| OLD | NEW |