michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "sandbox/win/src/handle_interception.h" michael@0: michael@0: #include "sandbox/win/src/crosscall_client.h" michael@0: #include "sandbox/win/src/ipc_tags.h" michael@0: #include "sandbox/win/src/sandbox_factory.h" michael@0: #include "sandbox/win/src/sandbox_nt_util.h" michael@0: #include "sandbox/win/src/sharedmem_ipc_client.h" michael@0: #include "sandbox/win/src/target_services.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: ResultCode DuplicateHandleProxy(HANDLE source_handle, michael@0: DWORD target_process_id, michael@0: HANDLE* target_handle, michael@0: DWORD desired_access, michael@0: DWORD options) { michael@0: *target_handle = NULL; michael@0: michael@0: void* memory = GetGlobalIPCMemory(); michael@0: if (NULL == memory) michael@0: return SBOX_ERROR_NO_SPACE; michael@0: michael@0: SharedMemIPCClient ipc(memory); michael@0: CrossCallReturn answer = {0}; michael@0: ResultCode code = CrossCall(ipc, IPC_DUPLICATEHANDLEPROXY_TAG, michael@0: source_handle, target_process_id, michael@0: desired_access, options, &answer); michael@0: if (SBOX_ALL_OK != code) michael@0: return code; michael@0: michael@0: if (answer.win32_result) { michael@0: ::SetLastError(answer.nt_status); michael@0: return SBOX_ERROR_GENERIC; michael@0: } michael@0: michael@0: *target_handle = answer.handle; michael@0: return SBOX_ALL_OK; michael@0: } michael@0: michael@0: } // namespace sandbox michael@0: