summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authornfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 00:59:23 +0000
committernfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 00:59:23 +0000
commit577a59c3ac740495f79c4af29efa67e6a2eb5ed1 (patch)
tree226700286489c7965b78cffecf53d445da4fd61a /ppapi
parentf7c820322bb70f26038cf8744705c8f35c0298a8 (diff)
downloadchromium_src-577a59c3ac740495f79c4af29efa67e6a2eb5ed1.zip
chromium_src-577a59c3ac740495f79c4af29efa67e6a2eb5ed1.tar.gz
chromium_src-577a59c3ac740495f79c4af29efa67e6a2eb5ed1.tar.bz2
Pass dup'd handles to nacl::DescWrapper instead of bumping the ref count.
In these cases, the original handle is owned outside of NaCl and shouldn't be closed by the NaCl Plugin. BUG=https://chromiumcodereview.appspot.com/9610008 TEST=ppapi_example_audio, ppb_image_data, ppb_graphics3d Review URL: http://codereview.chromium.org/9677061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_audio_rpc_server.cc34
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc28
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_image_data_rpc_server.cc41
3 files changed, 58 insertions, 45 deletions
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_audio_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_audio_rpc_server.cc
index 39e63a6..f217f3e 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_audio_rpc_server.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_audio_rpc_server.cc
@@ -6,6 +6,7 @@
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/include/portability.h"
+#include "native_client/src/shared/imc/nacl_imc.h"
#include "native_client/src/shared/ppapi_proxy/browser_globals.h"
#include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
#include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
@@ -67,27 +68,42 @@ void StreamCreatedCallback(void* user_data, int32_t result) {
if (NULL == audioTrusted) {
return;
}
- int sync_socket_handle;
- int shared_memory_handle;
- uint32_t shared_memory_size;
+ const int kInvalidIntHandle = int(nacl::kInvalidHandle);
+ int sync_socket_handle = kInvalidIntHandle;
+ int shared_memory_handle = kInvalidIntHandle;
+ uint32_t shared_memory_size = 0;
if (PP_OK != audioTrusted->GetSyncSocket(data->audio_id,
&sync_socket_handle)) {
return;
}
+ if (kInvalidIntHandle == sync_socket_handle) {
+ return;
+ }
if (PP_OK != audioTrusted->GetSharedMemory(data->audio_id,
&shared_memory_handle,
&shared_memory_size)) {
return;
}
+ if (kInvalidIntHandle == shared_memory_handle) {
+ return;
+ }
nacl::DescWrapperFactory factory;
- NaClHandle nacl_shm_handle = (NaClHandle)shared_memory_handle;
- NaClHandle nacl_sync_handle = (NaClHandle)sync_socket_handle;
+ NaClHandle nacl_shm_handle = NaClHandle(shared_memory_handle);
+ NaClHandle nacl_sync_handle = NaClHandle(sync_socket_handle);
+ NaClHandle nacl_shm_dup_handle = NaClDuplicateNaClHandle(nacl_shm_handle);
+ if (nacl::kInvalidHandle == nacl_shm_dup_handle) {
+ return;
+ }
nacl::scoped_ptr<nacl::DescWrapper> shm_wrapper(factory.ImportShmHandle(
- nacl_shm_handle, shared_memory_size));
+ nacl_shm_dup_handle, shared_memory_size));
+ NaClHandle nacl_sync_dup_handle = NaClDuplicateNaClHandle(nacl_sync_handle);
+ if (nacl::kInvalidHandle == nacl_sync_dup_handle) {
+ return;
+ }
nacl::scoped_ptr<nacl::DescWrapper> socket_wrapper(
- factory.ImportSyncSocketHandle(nacl_sync_handle));
- NaClDesc *nacl_shm = NaClDescRef(shm_wrapper->desc());
- NaClDesc *nacl_socket = NaClDescRef(socket_wrapper->desc());
+ factory.ImportSyncSocketHandle(nacl_sync_dup_handle));
+ NaClDesc *nacl_shm = shm_wrapper->desc();
+ NaClDesc *nacl_socket = socket_wrapper->desc();
static_cast<void>(PppAudioRpcClient::PPP_Audio_StreamCreated(
ppapi_proxy::GetMainSrpcChannel(data->instance_id),
data->audio_id,
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc
index 92648c3..427878a 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc
@@ -8,6 +8,7 @@
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/include/portability.h"
+#include "native_client/src/shared/imc/nacl_imc.h"
#include "native_client/src/shared/ppapi_proxy/browser_callback.h"
#include "native_client/src/shared/ppapi_proxy/browser_globals.h"
#include "native_client/src/shared/ppapi_proxy/object_serialize.h"
@@ -365,7 +366,6 @@ void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_DestroyTransferBuffer(
ppapi_proxy::PPBGraphics3DTrustedInterface()->DestroyTransferBuffer(
resource_id, id);
rpc->result = NACL_SRPC_RESULT_OK;
-
}
void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetTransferBuffer(
@@ -377,22 +377,28 @@ void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetTransferBuffer(
int32_t* shm_size) {
DebugPrintf("PPB_Graphics3DTrusted_GetTransferBuffer\n");
nacl::DescWrapperFactory factory;
- nacl::scoped_ptr<nacl::DescWrapper> desc_wrapper;
+ nacl::scoped_ptr<nacl::DescWrapper> desc_wrapper(factory.MakeInvalid());
NaClSrpcClosureRunner runner(done);
rpc->result = NACL_SRPC_RESULT_APP_ERROR;
-
- int native_handle = 0;
+ *shm_desc = desc_wrapper->desc();
+ *shm_size = 0;
+ const int kInvalidIntHandle = int(nacl::kInvalidHandle);
+ int native_handle = kInvalidIntHandle;
uint32_t native_size = 0;
- ppapi_proxy::PPBGraphics3DTrustedInterface()->
+ bool transfer_buffer_aquired = ppapi_proxy::PPBGraphics3DTrustedInterface()->
GetTransferBuffer(resource_id, id, &native_handle, &native_size);
- desc_wrapper.reset(factory.ImportShmHandle(
- (NaClHandle)native_handle, native_size));
- // todo(nfullagar): Dup the handle instead of leak caused by bumping the ref.
- // bug: https://chromiumcodereview.appspot.com/9610008
- *shm_desc = NaClDescRef(desc_wrapper->desc());
+ if (!transfer_buffer_aquired || kInvalidIntHandle == native_handle) {
+ return;
+ }
+ NaClHandle nacl_handle = NaClHandle(native_handle);
+ NaClHandle nacl_dup_handle = NaClDuplicateNaClHandle(nacl_handle);
+ if (nacl::kInvalidHandle == nacl_dup_handle) {
+ return;
+ }
+ desc_wrapper.reset(factory.ImportShmHandle(nacl_dup_handle, native_size));
+ *shm_desc = desc_wrapper->desc();
*shm_size = native_size;
rpc->result = NACL_SRPC_RESULT_OK;
-
}
//@}
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_image_data_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_image_data_rpc_server.cc
index 8a1e46d..67e937c 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_image_data_rpc_server.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_image_data_rpc_server.cc
@@ -7,6 +7,7 @@
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/include/portability.h"
+#include "native_client/src/shared/imc/nacl_imc.h"
#include "native_client/src/shared/ppapi_proxy/browser_globals.h"
#include "native_client/src/shared/ppapi_proxy/utility.h"
#include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
@@ -118,47 +119,37 @@ void PpbImageDataRpcServer::PPB_ImageData_Describe(
return;
}
*shm = desc_wrapper->desc();
- *shm_size = -1;
+ *shm_size = 0;
*success = PP_FALSE;
PP_Bool pp_success =
ppapi_proxy::PPBImageDataInterface()->Describe(
resource, reinterpret_cast<struct PP_ImageDataDesc*>(desc));
if (pp_success == PP_TRUE) {
- int native_handle = 0;
+ const int kInvalidIntHandle = int(nacl::kInvalidHandle);
+ int native_handle = kInvalidIntHandle;
uint32_t native_size = 0;
if (ppapi_proxy::PPBImageDataTrustedInterface()->GetSharedMemory(
static_cast<PP_Resource>(resource),
&native_handle,
&native_size) == PP_OK) {
-
+ if (kInvalidIntHandle != native_handle) {
#if NACL_LINUX
- desc_wrapper.reset(factory.ImportSysvShm(native_handle, native_size));
- *shm = desc_wrapper->desc();
- *shm_size = native_size;
- *success = PP_TRUE;
-#elif NACL_WINDOWS
- HANDLE dup_handle;
- if (DuplicateHandle(GetCurrentProcess(),
- reinterpret_cast<NaClHandle>(native_handle),
- GetCurrentProcess(),
- &dup_handle,
- 0,
- FALSE,
- DUPLICATE_SAME_ACCESS)) {
- desc_wrapper.reset(factory.ImportShmHandle(dup_handle, native_size));
+ desc_wrapper.reset(factory.ImportSysvShm(native_handle, native_size));
*shm = desc_wrapper->desc();
*shm_size = native_size;
*success = PP_TRUE;
- }
#else
- int dup_handle = dup(static_cast<int>(native_handle));
- if (dup_handle >= 0) {
- desc_wrapper.reset(factory.ImportShmHandle(dup_handle, native_size));
- *shm = desc_wrapper->desc();
- *shm_size = native_size;
- *success = PP_TRUE;
- }
+ NaClHandle nacl_handle = NaClHandle(native_handle);
+ NaClHandle nacl_dup_handle = NaClDuplicateNaClHandle(nacl_handle);
+ if (nacl::kInvalidHandle != nacl_dup_handle) {
+ desc_wrapper.reset(
+ factory.ImportShmHandle(nacl_dup_handle, native_size));
+ *shm = desc_wrapper->desc();
+ *shm_size = native_size;
+ *success = PP_TRUE;
+ }
#endif
+ }
}
}
DebugPrintf("PPB_ImageData::Describe: resource=%"NACL_PRId32", "