Commit c11d6d1b authored by rockot's avatar rockot Committed by Commit bot

Mojo: Fix wrapping of invalid SharedMemoryHandles.

When wrapping an invalid SharedMemoryHandle, we should always
just return a null ScopedSharedBufferHandle. Currently we return
a non-null ScopedSharedBufferHandle which wraps an invalid platform
handle. This will always fail to serialize and is generally bad.

Also fixes DiscardableSharedMemoryManager mojom to allow a null
shared buffer handle in the response to
AllocateLockedDiscardableSharedMemory. The existing client implementation
already handles the null case, so no additional code changes are required

BUG=674406

Review-Url: https://codereview.chromium.org/2583583002
Cr-Commit-Position: refs/heads/master@{#438955}
parent 23478bc8
...@@ -10,7 +10,7 @@ interface DiscardableSharedMemoryManager { ...@@ -10,7 +10,7 @@ interface DiscardableSharedMemoryManager {
// Allocate a locked discardable shared memory segment. // Allocate a locked discardable shared memory segment.
AllocateLockedDiscardableSharedMemory( AllocateLockedDiscardableSharedMemory(
uint32 size, uint32 size,
int32 id) => (handle<shared_buffer> memory); int32 id) => (handle<shared_buffer>? memory);
// Notify manager that a memory segment has been deleted. // Notify manager that a memory segment has been deleted.
DeletedDiscardableSharedMemory(int32 id); DeletedDiscardableSharedMemory(int32 id);
}; };
...@@ -66,6 +66,13 @@ ScopedSharedBufferHandle WrapSharedMemoryHandle( ...@@ -66,6 +66,13 @@ ScopedSharedBufferHandle WrapSharedMemoryHandle(
const base::SharedMemoryHandle& memory_handle, const base::SharedMemoryHandle& memory_handle,
size_t size, size_t size,
bool read_only) { bool read_only) {
#if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
if (memory_handle.fd == base::kInvalidPlatformFile)
return ScopedSharedBufferHandle();
#else
if (!memory_handle.IsValid())
return ScopedSharedBufferHandle();
#endif
MojoPlatformHandle platform_handle; MojoPlatformHandle platform_handle;
platform_handle.struct_size = sizeof(MojoPlatformHandle); platform_handle.struct_size = sizeof(MojoPlatformHandle);
platform_handle.type = kPlatformSharedBufferHandleType; platform_handle.type = kPlatformSharedBufferHandleType;
...@@ -96,6 +103,8 @@ MojoResult UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle, ...@@ -96,6 +103,8 @@ MojoResult UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle,
base::SharedMemoryHandle* memory_handle, base::SharedMemoryHandle* memory_handle,
size_t* size, size_t* size,
bool* read_only) { bool* read_only) {
if (!handle.is_valid())
return MOJO_RESULT_INVALID_ARGUMENT;
MojoPlatformHandle platform_handle; MojoPlatformHandle platform_handle;
platform_handle.struct_size = sizeof(MojoPlatformHandle); platform_handle.struct_size = sizeof(MojoPlatformHandle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment