Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc |
| diff --git a/native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc b/native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc |
| index 211451fd8411246d01dff14e981650373dc7d34b..5d39cf428ab1bc96aa2bd6a09eea67743f3767de 100644 |
| --- a/native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc |
| +++ b/native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc |
| @@ -18,6 +18,7 @@ |
| #include "nacl_io/ioctl.h" |
| #include "nacl_io/kernel_handle.h" |
| #include "nacl_io/kernel_intercept.h" |
| +#include "nacl_io/log.h" |
| #include "nacl_io/pepper_interface.h" |
| #include "sdk_util/auto_lock.h" |
| @@ -167,11 +168,38 @@ Error TtyNode::Echo(const char* string, int count) { |
| return 0; |
| } |
| -Error TtyNode::ProcessInput(struct tioc_nacl_input_string* message) { |
| - AUTO_LOCK(emitter_->GetLock()) |
| +Error TtyNode::ProcessInput(PP_Var message) { |
| + if (message.type != PP_VARTYPE_ARRAY_BUFFER) { |
| + LOG_ERROR("ProcessInput: expected ArrayBuffer but got %d.", message.type); |
| + return EINVAL; |
| + } |
| + |
| + PepperInterface* ppapi = filesystem_->ppapi(); |
| + if (!ppapi) { |
| + LOG_ERROR("ProcessInput: ppapi is NULL."); |
| + return EINVAL; |
| + } |
| + |
| + VarArrayBufferInterface* buffer_iface = ppapi->GetVarArrayBufferInterface(); |
| + if (!buffer_iface) { |
| + LOG_ERROR("ProcessInput: ArrayBuffer interface pointer is NULL."); |
| + return EINVAL; |
| + } |
|
Sam Clegg
2014/06/17 22:29:28
I hate to do this to you now, but I think the actu
binji
2014/06/17 22:55:22
Done.
|
| - const char* buffer = message->buffer; |
| - size_t num_bytes = message->length; |
| + uint32_t num_bytes; |
| + if (buffer_iface->ByteLength(message, &num_bytes) != PP_TRUE) { |
| + LOG_ERROR("ProcessInput: unable to get ArrayBuffer length."); |
| + return EINVAL; |
| + } |
| + |
| + const char* buffer = static_cast<const char*>(buffer_iface->Map(message)); |
| + Error error = ProcessInput(buffer, num_bytes); |
| + buffer_iface->Unmap(message); |
| + return error; |
| +} |
| + |
| +Error TtyNode::ProcessInput(const char* buffer, size_t num_bytes) { |
| + AUTO_LOCK(emitter_->GetLock()) |
| for (size_t i = 0; i < num_bytes; i++) { |
| char c = buffer[i]; |
| @@ -248,12 +276,9 @@ Error TtyNode::VIoctl(int request, va_list args) { |
| output_handler_ = *arg; |
| return 0; |
| } |
| - case TIOCNACLINPUT: { |
| - // This ioctl is used to deliver data from the user to this tty node's |
| - // input buffer. |
| - struct tioc_nacl_input_string* message = |
| - va_arg(args, struct tioc_nacl_input_string*); |
| - return ProcessInput(message); |
| + case NACL_IOC_HANDLEMESSAGE: { |
| + struct PP_Var* message = va_arg(args, struct PP_Var*); |
| + return ProcessInput(*message); |
| } |
| case TIOCSWINSZ: { |
| struct winsize* size = va_arg(args, struct winsize*); |
| @@ -280,6 +305,9 @@ Error TtyNode::VIoctl(int request, va_list args) { |
| size->ws_col = cols_; |
| return 0; |
| } |
| + default: { |
| + LOG_ERROR("TtyNode:VIoctl: Unknown request: %#x", request); |
| + } |
| } |
| return EINVAL; |