Index: base/memory/shared_memory_win.cc |
diff --git a/base/memory/shared_memory_win.cc b/base/memory/shared_memory_win.cc |
index 5f706fe648598642584903f39a5aa40786acc88d..3eef9a94d33dc5a4c6e7f98c0d65a2a12b14447c 100644 |
--- a/base/memory/shared_memory_win.cc |
+++ b/base/memory/shared_memory_win.cc |
@@ -45,11 +45,12 @@ SharedMemory::SharedMemory(const std::wstring& name) |
} |
SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) |
- : mapped_file_(handle), |
+ : mapped_file_(handle.GetHandle()), |
mapped_size_(0), |
memory_(NULL), |
read_only_(read_only), |
requested_size_(0) { |
+ DCHECK(!handle.IsValid() || handle.BelongsToCurrentProcess()); |
} |
SharedMemory::SharedMemory(const SharedMemoryHandle& handle, |
@@ -60,11 +61,9 @@ SharedMemory::SharedMemory(const SharedMemoryHandle& handle, |
memory_(NULL), |
read_only_(read_only), |
requested_size_(0) { |
- ::DuplicateHandle(process, handle, |
- GetCurrentProcess(), &mapped_file_, |
- read_only_ ? FILE_MAP_READ : FILE_MAP_READ | |
- FILE_MAP_WRITE, |
- FALSE, 0); |
+ ::DuplicateHandle( |
+ process, handle.GetHandle(), GetCurrentProcess(), &mapped_file_, |
+ read_only_ ? FILE_MAP_READ : FILE_MAP_READ | FILE_MAP_WRITE, FALSE, 0); |
} |
SharedMemory::~SharedMemory() { |
@@ -74,18 +73,17 @@ SharedMemory::~SharedMemory() { |
// static |
bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { |
- return handle != NULL; |
+ return handle.IsValid(); |
} |
// static |
SharedMemoryHandle SharedMemory::NULLHandle() { |
- return NULL; |
+ return SharedMemoryHandle(); |
} |
// static |
void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { |
- DCHECK(handle != NULL); |
- ::CloseHandle(handle); |
+ handle.Close(); |
} |
// static |
@@ -98,13 +96,15 @@ size_t SharedMemory::GetHandleLimit() { |
// static |
SharedMemoryHandle SharedMemory::DuplicateHandle( |
const SharedMemoryHandle& handle) { |
+ DCHECK(handle.BelongsToCurrentProcess()); |
+ HANDLE duped_handle; |
ProcessHandle process = GetCurrentProcess(); |
- SharedMemoryHandle duped_handle; |
- BOOL success = ::DuplicateHandle(process, handle, process, &duped_handle, 0, |
- FALSE, DUPLICATE_SAME_ACCESS); |
+ BOOL success = |
+ ::DuplicateHandle(process, handle.GetHandle(), process, &duped_handle, 0, |
+ FALSE, DUPLICATE_SAME_ACCESS); |
if (success) |
- return duped_handle; |
- return NULLHandle(); |
+ return SharedMemoryHandle(duped_handle, GetCurrentProcId()); |
+ return SharedMemoryHandle(); |
} |
bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
@@ -230,7 +230,7 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
SharedMemoryHandle* new_handle, |
bool close_self, |
ShareMode share_mode) { |
- *new_handle = 0; |
+ *new_handle = SharedMemoryHandle(); |
DWORD access = FILE_MAP_READ; |
DWORD options = 0; |
HANDLE mapped_file = mapped_file_; |
@@ -245,7 +245,7 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
} |
if (process == GetCurrentProcess() && close_self) { |
- *new_handle = mapped_file; |
+ *new_handle = SharedMemoryHandle(mapped_file, base::GetCurrentProcId()); |
return true; |
} |
@@ -253,20 +253,20 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
access, FALSE, options)) { |
return false; |
} |
- *new_handle = result; |
+ *new_handle = SharedMemoryHandle(result, base::GetProcId(process)); |
return true; |
} |
void SharedMemory::Close() { |
if (mapped_file_ != NULL) { |
- CloseHandle(mapped_file_); |
+ ::CloseHandle(mapped_file_); |
mapped_file_ = NULL; |
} |
} |
SharedMemoryHandle SharedMemory::handle() const { |
- return mapped_file_; |
+ return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); |
} |
} // namespace base |