Index: base/memory/shared_memory_handle_win.cc |
diff --git a/base/memory/shared_memory_handle_win.cc b/base/memory/shared_memory_handle_win.cc |
index 277a954daa1cd216c55c3b01333cc0fa4838d58a..82ded3453dd27af6afa76252dbb7f7bc1069a57d 100644 |
--- a/base/memory/shared_memory_handle_win.cc |
+++ b/base/memory/shared_memory_handle_win.cc |
@@ -40,6 +40,20 @@ bool SharedMemoryHandle::IsValid() const { |
return handle_ != nullptr; |
} |
+SharedMemoryHandle SharedMemoryHandle::Duplicate() const { |
+ DCHECK(BelongsToCurrentProcess()); |
+ HANDLE duped_handle; |
+ ProcessHandle process = GetCurrentProcess(); |
+ BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0, |
+ FALSE, DUPLICATE_SAME_ACCESS); |
+ if (!success) |
+ return SharedMemoryHandle(); |
+ |
+ base::SharedMemoryHandle handle(duped_handle, GetCurrentProcId()); |
+ handle.SetOwnershipPassesToIPC(true); |
+ return handle; |
+} |
+ |
bool SharedMemoryHandle::BelongsToCurrentProcess() const { |
return pid_ == base::GetCurrentProcId(); |
} |