1 // Copyright 2013 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.
5 #include "components/nacl/loader/nacl_ipc_adapter.h"
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/location.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/shared_memory.h"
15 #include "build/build_config.h"
16 #include "ipc/ipc_channel.h"
17 #include "ipc/ipc_platform_file.h"
18 #include "native_client/src/trusted/desc/nacl_desc_base.h"
19 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
20 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h"
21 #include "native_client/src/trusted/desc/nacl_desc_io.h"
22 #include "native_client/src/trusted/desc/nacl_desc_quota.h"
23 #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h"
24 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h"
25 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
26 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
27 #include "ppapi/c/ppb_file_io.h"
28 #include "ppapi/proxy/ppapi_messages.h"
29 #include "ppapi/proxy/serialized_handle.h"
31 using ppapi::proxy::NaClMessageScanner
;
35 enum BufferSizeStatus
{
36 // The buffer contains a full message with no extra bytes.
39 // The message doesn't fit and the buffer contains only some of it.
42 // The buffer contains a full message + extra data.
43 MESSAGE_HAS_EXTRA_DATA
46 BufferSizeStatus
GetBufferStatus(const char* data
, size_t len
) {
47 if (len
< sizeof(NaClIPCAdapter::NaClMessageHeader
))
48 return MESSAGE_IS_TRUNCATED
;
50 const NaClIPCAdapter::NaClMessageHeader
* header
=
51 reinterpret_cast<const NaClIPCAdapter::NaClMessageHeader
*>(data
);
53 sizeof(NaClIPCAdapter::NaClMessageHeader
) + header
->payload_size
;
55 if (len
== message_size
)
56 return MESSAGE_IS_COMPLETE
;
57 if (len
> message_size
)
58 return MESSAGE_HAS_EXTRA_DATA
;
59 return MESSAGE_IS_TRUNCATED
;
62 //------------------------------------------------------------------------------
63 // This object allows the NaClDesc to hold a reference to a NaClIPCAdapter and
64 // forward calls to it.
66 explicit DescThunker(NaClIPCAdapter
* adapter_arg
)
67 : adapter(adapter_arg
) {
69 scoped_refptr
<NaClIPCAdapter
> adapter
;
72 NaClIPCAdapter
* ToAdapter(void* handle
) {
73 return static_cast<DescThunker
*>(handle
)->adapter
.get();
76 // NaClDescCustom implementation.
77 void NaClDescCustomDestroy(void* handle
) {
78 delete static_cast<DescThunker
*>(handle
);
81 ssize_t
NaClDescCustomSendMsg(void* handle
, const NaClImcTypedMsgHdr
* msg
,
83 return static_cast<ssize_t
>(ToAdapter(handle
)->Send(msg
));
86 ssize_t
NaClDescCustomRecvMsg(void* handle
, NaClImcTypedMsgHdr
* msg
,
88 return static_cast<ssize_t
>(ToAdapter(handle
)->BlockingReceive(msg
));
91 NaClDesc
* MakeNaClDescCustom(NaClIPCAdapter
* adapter
) {
92 NaClDescCustomFuncs funcs
= NACL_DESC_CUSTOM_FUNCS_INITIALIZER
;
93 funcs
.Destroy
= NaClDescCustomDestroy
;
94 funcs
.SendMsg
= NaClDescCustomSendMsg
;
95 funcs
.RecvMsg
= NaClDescCustomRecvMsg
;
96 // NaClDescMakeCustomDesc gives us a reference on the returned NaClDesc.
97 return NaClDescMakeCustomDesc(new DescThunker(adapter
), &funcs
);
100 //------------------------------------------------------------------------------
101 // This object is passed to a NaClDescQuota to intercept writes and forward them
102 // to the NaClIPCAdapter, which checks quota. This is a NaCl-style struct. Don't
103 // add non-trivial fields or virtual methods. Construction should use malloc,
104 // because this is owned by the NaClDesc, and the NaCl Dtor code will call free.
105 struct QuotaInterface
{
106 // The "base" struct must be first. NaCl code expects a NaCl style ref-counted
107 // object, so the "vtable" and other base class fields must be first.
108 struct NaClDescQuotaInterface base NACL_IS_REFCOUNT_SUBCLASS
;
110 NaClMessageScanner::FileIO
* file_io
;
113 static void QuotaInterfaceDtor(NaClRefCount
* nrcp
) {
114 // Trivial class, just pass through to the "base" struct Dtor.
115 nrcp
->vtbl
= reinterpret_cast<NaClRefCountVtbl
*>(
116 const_cast<NaClDescQuotaInterfaceVtbl
*>(&kNaClDescQuotaInterfaceVtbl
));
117 (*nrcp
->vtbl
->Dtor
)(nrcp
);
120 static int64_t QuotaInterfaceWriteRequest(NaClDescQuotaInterface
* ndqi
,
121 const uint8_t* /* unused_id */,
124 if (offset
< 0 || length
< 0)
126 if (std::numeric_limits
<int64_t>::max() - length
< offset
)
127 return 0; // offset + length would overflow.
128 int64_t max_offset
= offset
+ length
;
132 QuotaInterface
* quota_interface
= reinterpret_cast<QuotaInterface
*>(ndqi
);
133 NaClMessageScanner::FileIO
* file_io
= quota_interface
->file_io
;
134 int64_t increase
= max_offset
- file_io
->max_written_offset();
135 if (increase
<= 0 || file_io
->Grow(increase
))
141 static int64_t QuotaInterfaceFtruncateRequest(NaClDescQuotaInterface
* ndqi
,
142 const uint8_t* /* unused_id */,
144 // We can't implement SetLength on the plugin side due to sandbox limitations.
145 // See crbug.com/156077.
150 static const struct NaClDescQuotaInterfaceVtbl kQuotaInterfaceVtbl
= {
154 QuotaInterfaceWriteRequest
,
155 QuotaInterfaceFtruncateRequest
158 NaClDesc
* MakeNaClDescQuota(
159 NaClMessageScanner::FileIO
* file_io
,
160 NaClDesc
* wrapped_desc
) {
161 // Create the QuotaInterface.
162 QuotaInterface
* quota_interface
=
163 static_cast<QuotaInterface
*>(malloc(sizeof *quota_interface
));
164 if (quota_interface
&& NaClDescQuotaInterfaceCtor("a_interface
->base
)) {
165 quota_interface
->base
.base
.vtbl
=
166 (struct NaClRefCountVtbl
*)(&kQuotaInterfaceVtbl
);
167 // QuotaInterface is a trivial class, so skip the ctor.
168 quota_interface
->file_io
= file_io
;
169 // Create the NaClDescQuota.
170 NaClDescQuota
* desc
= static_cast<NaClDescQuota
*>(malloc(sizeof *desc
));
171 uint8_t unused_id
[NACL_DESC_QUOTA_FILE_ID_LEN
] = {0};
172 if (desc
&& NaClDescQuotaCtor(desc
,
175 "a_interface
->base
)) {
179 NaClDescUnref(reinterpret_cast<NaClDesc
*>(desc
));
183 NaClDescQuotaInterfaceUnref("a_interface
->base
);
188 //------------------------------------------------------------------------------
190 void DeleteChannel(IPC::Channel
* channel
) {
194 // Translates Pepper's read/write open flags into the NaCl equivalents.
195 // Since the host has already opened the file, flags such as O_CREAT, O_TRUNC,
196 // and O_EXCL don't make sense, so we filter those out. If no read or write
197 // flags are set, the function returns NACL_ABI_O_RDONLY as a safe fallback.
198 int TranslatePepperFileReadWriteOpenFlags(int32_t pp_open_flags
) {
199 bool read
= (pp_open_flags
& PP_FILEOPENFLAG_READ
) != 0;
200 bool write
= (pp_open_flags
& PP_FILEOPENFLAG_WRITE
) != 0;
201 bool append
= (pp_open_flags
& PP_FILEOPENFLAG_APPEND
) != 0;
203 int nacl_open_flag
= NACL_ABI_O_RDONLY
; // NACL_ABI_O_RDONLY == 0.
204 if (read
&& (write
|| append
)) {
205 nacl_open_flag
= NACL_ABI_O_RDWR
;
206 } else if (write
|| append
) {
207 nacl_open_flag
= NACL_ABI_O_WRONLY
;
209 DLOG(WARNING
) << "One of PP_FILEOPENFLAG_READ, PP_FILEOPENFLAG_WRITE, "
210 << "or PP_FILEOPENFLAG_APPEND should be set.";
213 nacl_open_flag
|= NACL_ABI_O_APPEND
;
215 return nacl_open_flag
;
218 class NaClDescWrapper
{
220 explicit NaClDescWrapper(NaClDesc
* desc
): desc_(desc
) {}
222 NaClDescUnref(desc_
);
225 NaClDesc
* desc() { return desc_
; }
229 DISALLOW_COPY_AND_ASSIGN(NaClDescWrapper
);
234 class NaClIPCAdapter::RewrittenMessage
235 : public base::RefCounted
<RewrittenMessage
> {
239 bool is_consumed() const { return data_read_cursor_
== data_len_
; }
241 void SetData(const NaClIPCAdapter::NaClMessageHeader
& header
,
242 const void* payload
, size_t payload_length
);
244 int Read(NaClImcTypedMsgHdr
* msg
);
246 void AddDescriptor(NaClDescWrapper
* desc
) { descs_
.push_back(desc
); }
248 size_t desc_count() const { return descs_
.size(); }
251 friend class base::RefCounted
<RewrittenMessage
>;
252 ~RewrittenMessage() {}
254 scoped_ptr
<char[]> data_
;
257 // Offset into data where the next read will happen. This will be equal to
258 // data_len_ when all data has been consumed.
259 size_t data_read_cursor_
;
261 // Wrapped descriptors for transfer to untrusted code.
262 ScopedVector
<NaClDescWrapper
> descs_
;
265 NaClIPCAdapter::RewrittenMessage::RewrittenMessage()
267 data_read_cursor_(0) {
270 void NaClIPCAdapter::RewrittenMessage::SetData(
271 const NaClIPCAdapter::NaClMessageHeader
& header
,
273 size_t payload_length
) {
274 DCHECK(!data_
.get() && data_len_
== 0);
275 size_t header_len
= sizeof(NaClIPCAdapter::NaClMessageHeader
);
276 data_len_
= header_len
+ payload_length
;
277 data_
.reset(new char[data_len_
]);
279 memcpy(data_
.get(), &header
, sizeof(NaClIPCAdapter::NaClMessageHeader
));
280 memcpy(&data_
[header_len
], payload
, payload_length
);
283 int NaClIPCAdapter::RewrittenMessage::Read(NaClImcTypedMsgHdr
* msg
) {
284 CHECK(data_len_
>= data_read_cursor_
);
285 char* dest_buffer
= static_cast<char*>(msg
->iov
[0].base
);
286 size_t dest_buffer_size
= msg
->iov
[0].length
;
287 size_t bytes_to_write
= std::min(dest_buffer_size
,
288 data_len_
- data_read_cursor_
);
289 if (bytes_to_write
== 0)
292 memcpy(dest_buffer
, &data_
[data_read_cursor_
], bytes_to_write
);
293 data_read_cursor_
+= bytes_to_write
;
295 // Once all data has been consumed, transfer any file descriptors.
297 nacl_abi_size_t desc_count
= static_cast<nacl_abi_size_t
>(descs_
.size());
298 CHECK(desc_count
<= msg
->ndesc_length
);
299 msg
->ndesc_length
= desc_count
;
300 for (nacl_abi_size_t i
= 0; i
< desc_count
; i
++) {
301 // Copy the NaClDesc to the buffer and add a ref so it won't be freed
302 // when we clear our ScopedVector.
303 msg
->ndescv
[i
] = descs_
[i
]->desc();
304 NaClDescRef(descs_
[i
]->desc());
308 msg
->ndesc_length
= 0;
310 return static_cast<int>(bytes_to_write
);
313 NaClIPCAdapter::LockedData::LockedData()
314 : channel_closed_(false) {
317 NaClIPCAdapter::LockedData::~LockedData() {
320 NaClIPCAdapter::IOThreadData::IOThreadData() {
323 NaClIPCAdapter::IOThreadData::~IOThreadData() {
326 NaClIPCAdapter::NaClIPCAdapter(const IPC::ChannelHandle
& handle
,
327 base::TaskRunner
* runner
)
330 task_runner_(runner
),
332 io_thread_data_
.channel_
= IPC::Channel::CreateServer(handle
, this);
333 // Note, we can not PostTask for ConnectChannelOnIOThread here. If we did,
334 // and that task ran before this constructor completes, the reference count
335 // would go to 1 and then to 0 because of the Task, before we've been returned
336 // to the owning scoped_refptr, which is supposed to give us our first
340 NaClIPCAdapter::NaClIPCAdapter(scoped_ptr
<IPC::Channel
> channel
,
341 base::TaskRunner
* runner
)
344 task_runner_(runner
),
346 io_thread_data_
.channel_
= channel
.Pass();
349 void NaClIPCAdapter::ConnectChannel() {
350 task_runner_
->PostTask(FROM_HERE
,
351 base::Bind(&NaClIPCAdapter::ConnectChannelOnIOThread
, this));
354 // Note that this message is controlled by the untrusted code. So we should be
355 // skeptical of anything it contains and quick to give up if anything is fishy.
356 int NaClIPCAdapter::Send(const NaClImcTypedMsgHdr
* msg
) {
357 if (msg
->iov_length
!= 1)
360 base::AutoLock
lock(lock_
);
362 const char* input_data
= static_cast<char*>(msg
->iov
[0].base
);
363 size_t input_data_len
= msg
->iov
[0].length
;
364 if (input_data_len
> IPC::Channel::kMaximumMessageSize
) {
369 // current_message[_len] refers to the total input data received so far.
370 const char* current_message
;
371 size_t current_message_len
;
372 bool did_append_input_data
;
373 if (locked_data_
.to_be_sent_
.empty()) {
374 // No accumulated data, we can avoid a copy by referring to the input
375 // buffer (the entire message fitting in one call is the common case).
376 current_message
= input_data
;
377 current_message_len
= input_data_len
;
378 did_append_input_data
= false;
380 // We've already accumulated some data, accumulate this new data and
381 // point to the beginning of the buffer.
383 // Make sure our accumulated message size doesn't overflow our max. Since
384 // we know that data_len < max size (checked above) and our current
385 // accumulated value is also < max size, we just need to make sure that
386 // 2x max size can never overflow.
387 COMPILE_ASSERT(IPC::Channel::kMaximumMessageSize
< (UINT_MAX
/ 2),
388 MaximumMessageSizeWillOverflow
);
389 size_t new_size
= locked_data_
.to_be_sent_
.size() + input_data_len
;
390 if (new_size
> IPC::Channel::kMaximumMessageSize
) {
395 locked_data_
.to_be_sent_
.append(input_data
, input_data_len
);
396 current_message
= &locked_data_
.to_be_sent_
[0];
397 current_message_len
= locked_data_
.to_be_sent_
.size();
398 did_append_input_data
= true;
401 // Check the total data we've accumulated so far to see if it contains a full
403 switch (GetBufferStatus(current_message
, current_message_len
)) {
404 case MESSAGE_IS_COMPLETE
: {
405 // Got a complete message, can send it out. This will be the common case.
406 bool success
= SendCompleteMessage(current_message
, current_message_len
);
408 return success
? static_cast<int>(input_data_len
) : -1;
410 case MESSAGE_IS_TRUNCATED
:
411 // For truncated messages, just accumulate the new data (if we didn't
412 // already do so above) and go back to waiting for more.
413 if (!did_append_input_data
)
414 locked_data_
.to_be_sent_
.append(input_data
, input_data_len
);
415 return static_cast<int>(input_data_len
);
416 case MESSAGE_HAS_EXTRA_DATA
:
418 // When the plugin gives us too much data, it's an error.
424 int NaClIPCAdapter::BlockingReceive(NaClImcTypedMsgHdr
* msg
) {
425 if (msg
->iov_length
!= 1)
430 base::AutoLock
lock(lock_
);
431 while (locked_data_
.to_be_received_
.empty() &&
432 !locked_data_
.channel_closed_
)
434 if (locked_data_
.channel_closed_
) {
437 retval
= LockedReceive(msg
);
445 void NaClIPCAdapter::CloseChannel() {
447 base::AutoLock
lock(lock_
);
448 locked_data_
.channel_closed_
= true;
452 task_runner_
->PostTask(FROM_HERE
,
453 base::Bind(&NaClIPCAdapter::CloseChannelOnIOThread
, this));
456 NaClDesc
* NaClIPCAdapter::MakeNaClDesc() {
457 return MakeNaClDescCustom(this);
460 #if defined(OS_POSIX)
461 int NaClIPCAdapter::TakeClientFileDescriptor() {
462 return io_thread_data_
.channel_
->TakeClientFileDescriptor();
466 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message
& msg
) {
467 uint32_t type
= msg
.type();
468 if (type
== IPC_REPLY_ID
) {
469 int id
= IPC::SyncMessage::GetMessageId(msg
);
470 IOThreadData::PendingSyncMsgMap::iterator it
=
471 io_thread_data_
.pending_sync_msgs_
.find(id
);
472 DCHECK(it
!= io_thread_data_
.pending_sync_msgs_
.end());
473 if (it
!= io_thread_data_
.pending_sync_msgs_
.end()) {
475 io_thread_data_
.pending_sync_msgs_
.erase(it
);
480 base::AutoLock
lock(lock_
);
481 scoped_refptr
<RewrittenMessage
> rewritten_msg(new RewrittenMessage
);
483 typedef std::vector
<ppapi::proxy::SerializedHandle
> Handles
;
485 scoped_ptr
<IPC::Message
> new_msg
;
487 if (!locked_data_
.nacl_msg_scanner_
.ScanMessage(
488 msg
, type
, &handles
, &new_msg
))
491 // Now add any descriptors we found to rewritten_msg. |handles| is usually
492 // empty, unless we read a message containing a FD or handle.
493 for (Handles::const_iterator iter
= handles
.begin();
494 iter
!= handles
.end();
496 scoped_ptr
<NaClDescWrapper
> nacl_desc
;
497 switch (iter
->type()) {
498 case ppapi::proxy::SerializedHandle::SHARED_MEMORY
: {
499 const base::SharedMemoryHandle
& shm_handle
= iter
->shmem();
500 uint32_t size
= iter
->size();
501 nacl_desc
.reset(new NaClDescWrapper(NaClDescImcShmMake(
507 static_cast<size_t>(size
))));
510 case ppapi::proxy::SerializedHandle::SOCKET
: {
511 nacl_desc
.reset(new NaClDescWrapper(NaClDescSyncSocketMake(
515 iter
->descriptor().fd
520 case ppapi::proxy::SerializedHandle::FILE: {
521 // Create the NaClDesc for the file descriptor. If quota checking is
522 // required, wrap it in a NaClDescQuota.
523 NaClDesc
* desc
= NaClDescIoDescFromHandleAllocCtor(
527 iter
->descriptor().fd
,
529 TranslatePepperFileReadWriteOpenFlags(iter
->open_flags()));
530 if (desc
&& iter
->file_io()) {
531 desc
= MakeNaClDescQuota(
532 locked_data_
.nacl_msg_scanner_
.GetFile(iter
->file_io()),
536 nacl_desc
.reset(new NaClDescWrapper(desc
));
540 case ppapi::proxy::SerializedHandle::INVALID
: {
541 // Nothing to do. TODO(dmichael): Should we log this? Or is it
542 // sometimes okay to pass an INVALID handle?
545 // No default, so the compiler will warn us if new types get added.
548 rewritten_msg
->AddDescriptor(nacl_desc
.release());
551 SaveMessage(*new_msg
, rewritten_msg
.get());
553 SaveMessage(msg
, rewritten_msg
.get());
559 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid
) {
562 void NaClIPCAdapter::OnChannelError() {
566 NaClIPCAdapter::~NaClIPCAdapter() {
567 // Make sure the channel is deleted on the IO thread.
568 task_runner_
->PostTask(FROM_HERE
,
569 base::Bind(&DeleteChannel
, io_thread_data_
.channel_
.release()));
572 int NaClIPCAdapter::LockedReceive(NaClImcTypedMsgHdr
* msg
) {
573 lock_
.AssertAcquired();
575 if (locked_data_
.to_be_received_
.empty())
577 scoped_refptr
<RewrittenMessage
> current
=
578 locked_data_
.to_be_received_
.front();
580 int retval
= current
->Read(msg
);
582 // When a message is entirely consumed, remove if from the waiting queue.
583 if (current
->is_consumed())
584 locked_data_
.to_be_received_
.pop();
589 bool NaClIPCAdapter::SendCompleteMessage(const char* buffer
,
591 lock_
.AssertAcquired();
592 // The message will have already been validated, so we know it's large enough
594 const NaClMessageHeader
* header
=
595 reinterpret_cast<const NaClMessageHeader
*>(buffer
);
597 // Length of the message not including the body. The data passed to us by the
598 // plugin should match that in the message header. This should have already
599 // been validated by GetBufferStatus.
600 int body_len
= static_cast<int>(buffer_len
- sizeof(NaClMessageHeader
));
601 DCHECK(body_len
== static_cast<int>(header
->payload_size
));
603 // We actually discard the flags and only copy the ones we care about. This
604 // is just because message doesn't have a constructor that takes raw flags.
605 scoped_ptr
<IPC::Message
> msg(
606 new IPC::Message(header
->routing
, header
->type
,
607 IPC::Message::PRIORITY_NORMAL
));
608 if (header
->flags
& IPC::Message::SYNC_BIT
)
610 if (header
->flags
& IPC::Message::REPLY_BIT
)
612 if (header
->flags
& IPC::Message::REPLY_ERROR_BIT
)
613 msg
->set_reply_error();
614 if (header
->flags
& IPC::Message::UNBLOCK_BIT
)
615 msg
->set_unblock(true);
617 msg
->WriteBytes(&buffer
[sizeof(NaClMessageHeader
)], body_len
);
619 // Technically we didn't have to do any of the previous work in the lock. But
620 // sometimes our buffer will point to the to_be_sent_ string which is
621 // protected by the lock, and it's messier to factor Send() such that it can
622 // unlock for us. Holding the lock for the message construction, which is
623 // just some memcpys, shouldn't be a big deal.
624 lock_
.AssertAcquired();
625 if (locked_data_
.channel_closed_
) {
626 // If we ever pass handles from the plugin to the host, we should close them
627 // here before we drop the message.
631 // Scan all untrusted messages.
632 scoped_ptr
<IPC::Message
> new_msg
;
633 locked_data_
.nacl_msg_scanner_
.ScanUntrustedMessage(*msg
, &new_msg
);
635 msg
.reset(new_msg
.release());
637 // Actual send must be done on the I/O thread.
638 task_runner_
->PostTask(FROM_HERE
,
639 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread
, this,
640 base::Passed(&msg
)));
644 void NaClIPCAdapter::ClearToBeSent() {
645 lock_
.AssertAcquired();
647 // Don't let the string keep its buffer behind our back.
649 locked_data_
.to_be_sent_
.swap(empty
);
652 void NaClIPCAdapter::ConnectChannelOnIOThread() {
653 if (!io_thread_data_
.channel_
->Connect())
657 void NaClIPCAdapter::CloseChannelOnIOThread() {
658 io_thread_data_
.channel_
->Close();
661 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr
<IPC::Message
> message
) {
662 int id
= IPC::SyncMessage::GetMessageId(*message
.get());
663 DCHECK(io_thread_data_
.pending_sync_msgs_
.find(id
) ==
664 io_thread_data_
.pending_sync_msgs_
.end());
666 if (message
->is_sync())
667 io_thread_data_
.pending_sync_msgs_
[id
] = message
->type();
668 io_thread_data_
.channel_
->Send(message
.release());
671 void NaClIPCAdapter::SaveMessage(const IPC::Message
& msg
,
672 RewrittenMessage
* rewritten_msg
) {
673 lock_
.AssertAcquired();
674 // There is some padding in this structure (the "padding" member is 16
675 // bits but this then gets padded to 32 bits). We want to be sure not to
676 // leak data to the untrusted plugin, so zero everything out first.
677 NaClMessageHeader header
;
678 memset(&header
, 0, sizeof(NaClMessageHeader
));
680 header
.payload_size
= static_cast<uint32
>(msg
.payload_size());
681 header
.routing
= msg
.routing_id();
682 header
.type
= msg
.type();
683 header
.flags
= msg
.flags();
684 header
.num_fds
= static_cast<int>(rewritten_msg
->desc_count());
686 rewritten_msg
->SetData(header
, msg
.payload(), msg
.payload_size());
687 locked_data_
.to_be_received_
.push(rewritten_msg
);
690 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags
) {
691 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags
);