diff options
author | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 19:52:35 +0000 |
---|---|---|
committer | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 19:52:35 +0000 |
commit | ad4af64a54dcf76e2957315ac94a640f5dfe6409 (patch) | |
tree | 9c71e8b577b7966c0194062271cb53b156121979 /chrome/renderer/nacl_desc_wrapper_chrome.cc | |
parent | 22b5f52c422118fd6f090e9f6784ae9aede919f7 (diff) | |
download | chromium_src-ad4af64a54dcf76e2957315ac94a640f5dfe6409.zip chromium_src-ad4af64a54dcf76e2957315ac94a640f5dfe6409.tar.gz chromium_src-ad4af64a54dcf76e2957315ac94a640f5dfe6409.tar.bz2 |
Add the descriptor support needed for Pepper in a way that does
not include chrome/common or base/ files from the NaCl tree.
Review URL: http://codereview.chromium.org/969006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/nacl_desc_wrapper_chrome.cc')
-rw-r--r-- | chrome/renderer/nacl_desc_wrapper_chrome.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/renderer/nacl_desc_wrapper_chrome.cc b/chrome/renderer/nacl_desc_wrapper_chrome.cc new file mode 100644 index 0000000..86653b7 --- /dev/null +++ b/chrome/renderer/nacl_desc_wrapper_chrome.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/shared_memory.h" +#include "base/sync_socket.h" +#include "chrome/common/transport_dib.h" +#include "native_client/src/trusted/desc/nacl_desc_base.h" +#include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" +#include "native_client/src/trusted/desc/nacl_desc_wrapper.h" + +namespace nacl { + +DescWrapper* DescWrapperFactory::ImportPepperSharedMemory(intptr_t shm_int, + size_t size) { + base::SharedMemory* shm = reinterpret_cast<base::SharedMemory*>(shm_int); +#if defined(OS_LINUX) || defined(OS_MACOSX) + return ImportShmHandle(shm->handle().fd, size); +#elif defined(OS_WIN) + return ImportShmHandle(shm->handle(), size); +#else +# error "What platform?" +#endif +} + +DescWrapper* DescWrapperFactory::ImportPepper2DSharedMemory(intptr_t shm_int) { + TransportDIB* dib = reinterpret_cast<TransportDIB*>(shm_int); +#if defined(OS_LINUX) + // TransportDIBs use SysV (X) shared memory on Linux. + return ImportSysvShm(dib->handle(), dib->size()); +#elif defined(OS_MACOSX) + // TransportDIBs use mmap shared memory on OSX. + return ImportShmHandle(dib->handle().fd, dib->size()); +#elif defined(OS_WIN) + // TransportDIBs use MapViewOfFile shared memory on Windows. + return ImportShmHandle(dib->handle(), dib->size()); +#else +# error "What platform?" +#endif +} + +DescWrapper* DescWrapperFactory::ImportPepperSync(intptr_t sync_int) { + base::SyncSocket* sock = reinterpret_cast<base::SyncSocket*>(sync_int); + struct NaClDescSyncSocket* ss_desc = NULL; + DescWrapper* wrapper = NULL; + + ss_desc = static_cast<NaClDescSyncSocket*>( + calloc(1, sizeof(*ss_desc))); + if (NULL == ss_desc) { + // TODO(sehr): Gotos are awful. Add a scoped_ptr variant that + // invokes NaClDescSafeUnref. + goto cleanup; + } + if (!NaClDescSyncSocketCtor(ss_desc, sock->handle())) { + free(ss_desc); + ss_desc = NULL; + goto cleanup; + } + wrapper = new DescWrapper(common_data_, &ss_desc->base); + if (NULL == wrapper) { + goto cleanup; + } + ss_desc = NULL; // DescWrapper takes ownership of ss_desc. + return wrapper; + + cleanup: + NaClDescSafeUnref(&ss_desc->base); + return NULL; +} + +} // namespace nacl |