Commit 2772cb20 authored by rockot's avatar rockot Committed by Commit bot

[mojo-edk] Delete data_pipe.h/cc

These files haven't been used for a while.

Nobody builds or depends on them.

BUG=None
TBR=amistry@chromium.org

Review URL: https://codereview.chromium.org/1923063003

Cr-Commit-Position: refs/heads/master@{#389910}
parent 8510319c
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/edk/system/data_pipe.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <limits>
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/options_validation.h"
#include "mojo/edk/system/raw_channel.h"
#include "mojo/edk/system/transport_data.h"
namespace mojo {
namespace edk {
namespace {
const uint32_t kInvalidDataPipeHandleIndex = static_cast<uint32_t>(-1);
struct MOJO_ALIGNAS(8) SerializedDataPipeHandleDispatcher {
MOJO_ALIGNAS(4)
uint32_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
// These are from MojoCreateDataPipeOptions
MOJO_ALIGNAS(4) MojoCreateDataPipeOptionsFlags flags;
MOJO_ALIGNAS(4) uint32_t element_num_bytes;
MOJO_ALIGNAS(4) uint32_t capacity_num_bytes;
MOJO_ALIGNAS(4)
uint32_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
MOJO_ALIGNAS(4) uint32_t shared_memory_size;
};
} // namespace
MojoCreateDataPipeOptions DataPipe::GetDefaultCreateOptions() {
MojoCreateDataPipeOptions result = {
static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
1u,
static_cast<uint32_t>(
GetConfiguration().default_data_pipe_capacity_bytes)};
return result;
}
MojoResult DataPipe::ValidateCreateOptions(
const MojoCreateDataPipeOptions* in_options,
MojoCreateDataPipeOptions* out_options) {
const MojoCreateDataPipeOptionsFlags kKnownFlags =
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
*out_options = GetDefaultCreateOptions();
if (!in_options)
return MOJO_RESULT_OK;
UserOptionsReader<MojoCreateDataPipeOptions> reader(in_options);
if (!reader.is_valid())
return MOJO_RESULT_INVALID_ARGUMENT;
if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateDataPipeOptions, flags, reader))
return MOJO_RESULT_OK;
if ((reader.options().flags & ~kKnownFlags))
return MOJO_RESULT_UNIMPLEMENTED;
out_options->flags = reader.options().flags;
// Checks for fields beyond |flags|:
if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateDataPipeOptions, element_num_bytes,
reader))
return MOJO_RESULT_OK;
if (reader.options().element_num_bytes == 0)
return MOJO_RESULT_INVALID_ARGUMENT;
out_options->element_num_bytes = reader.options().element_num_bytes;
if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateDataPipeOptions, capacity_num_bytes,
reader) ||
reader.options().capacity_num_bytes == 0) {
// Round the default capacity down to a multiple of the element size (but at
// least one element).
size_t default_data_pipe_capacity_bytes =
GetConfiguration().default_data_pipe_capacity_bytes;
out_options->capacity_num_bytes =
std::max(static_cast<uint32_t>(default_data_pipe_capacity_bytes -
(default_data_pipe_capacity_bytes %
out_options->element_num_bytes)),
out_options->element_num_bytes);
return MOJO_RESULT_OK;
}
if (reader.options().capacity_num_bytes % out_options->element_num_bytes != 0)
return MOJO_RESULT_INVALID_ARGUMENT;
if (reader.options().capacity_num_bytes >
GetConfiguration().max_data_pipe_capacity_bytes)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
out_options->capacity_num_bytes = reader.options().capacity_num_bytes;
return MOJO_RESULT_OK;
}
void DataPipe::StartSerialize(bool have_channel_handle,
bool have_shared_memory,
size_t* max_size,
size_t* max_platform_handles) {
*max_size = sizeof(SerializedDataPipeHandleDispatcher);
*max_platform_handles = 0;
if (have_channel_handle)
(*max_platform_handles)++;
if (have_shared_memory)
(*max_platform_handles)++;
}
void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options,
ScopedPlatformHandle channel_handle,
ScopedPlatformHandle shared_memory_handle,
size_t shared_memory_size,
void* destination,
size_t* actual_size,
PlatformHandleVector* platform_handles) {
SerializedDataPipeHandleDispatcher* serialization =
static_cast<SerializedDataPipeHandleDispatcher*>(destination);
if (channel_handle.is_valid()) {
DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max());
serialization->platform_handle_index =
static_cast<uint32_t>(platform_handles->size());
platform_handles->push_back(channel_handle.release());
} else {
serialization->platform_handle_index = kInvalidDataPipeHandleIndex;
}
serialization->flags = options.flags;
serialization->element_num_bytes = options.element_num_bytes;
serialization->capacity_num_bytes = options.capacity_num_bytes;
serialization->shared_memory_size = static_cast<uint32_t>(shared_memory_size);
if (serialization->shared_memory_size) {
DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max());
serialization->shared_memory_handle_index =
static_cast<uint32_t>(platform_handles->size());
platform_handles->push_back(shared_memory_handle.release());
} else {
serialization->shared_memory_handle_index = kInvalidDataPipeHandleIndex;
}
*actual_size = sizeof(SerializedDataPipeHandleDispatcher);
}
ScopedPlatformHandle DataPipe::Deserialize(
const void* source,
size_t size,
PlatformHandleVector* platform_handles,
MojoCreateDataPipeOptions* options,
ScopedPlatformHandle* shared_memory_handle,
size_t* shared_memory_size) {
if (size != sizeof(SerializedDataPipeHandleDispatcher)) {
LOG(ERROR) << "Invalid serialized data pipe dispatcher (bad size)";
return ScopedPlatformHandle();
}
const SerializedDataPipeHandleDispatcher* serialization =
static_cast<const SerializedDataPipeHandleDispatcher*>(source);
size_t platform_handle_index = serialization->platform_handle_index;
// Starts off invalid, which is what we want.
PlatformHandle platform_handle;
if (platform_handle_index != kInvalidDataPipeHandleIndex) {
if (!platform_handles ||
platform_handle_index >= platform_handles->size()) {
LOG(ERROR)
<< "Invalid serialized data pipe dispatcher (missing handles)";
return ScopedPlatformHandle();
}
// We take ownership of the handle, so we have to invalidate the one in
// |platform_handles|.
std::swap(platform_handle, (*platform_handles)[platform_handle_index]);
}
options->struct_size = sizeof(MojoCreateDataPipeOptions);
options->flags = serialization->flags;
options->element_num_bytes = serialization->element_num_bytes;
options->capacity_num_bytes = serialization->capacity_num_bytes;
if (shared_memory_size) {
*shared_memory_size = serialization->shared_memory_size;
if (*shared_memory_size) {
DCHECK(serialization->shared_memory_handle_index !=
kInvalidDataPipeHandleIndex);
if (!platform_handles ||
serialization->shared_memory_handle_index >=
platform_handles->size()) {
LOG(ERROR) << "Invalid serialized data pipe dispatcher "
<< "(missing handles)";
return ScopedPlatformHandle();
}
PlatformHandle temp_shared_memory_handle;
std::swap(temp_shared_memory_handle,
(*platform_handles)[serialization->shared_memory_handle_index]);
*shared_memory_handle =
ScopedPlatformHandle(temp_shared_memory_handle);
}
}
size -= sizeof(SerializedDataPipeHandleDispatcher);
return ScopedPlatformHandle(platform_handle);
}
} // namespace edk
} // namespace mojo
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_EDK_SYSTEM_DATA_PIPE_H_
#define MOJO_EDK_SYSTEM_DATA_PIPE_H_
#include <stddef.h>
#include "base/compiler_specific.h"
#include "mojo/edk/embedder/platform_handle_vector.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/types.h"
namespace mojo {
namespace edk {
class RawChannel;
// Shared code between DataPipeConsumerDispatcher and
// DataPipeProducerDispatcher.
class MOJO_SYSTEM_IMPL_EXPORT DataPipe {
public:
// The default options for |MojoCreateDataPipe()|. (Real uses should obtain
// this via |ValidateCreateOptions()| with a null |in_options|; this is
// exposed directly for testing convenience.)
static MojoCreateDataPipeOptions GetDefaultCreateOptions();
// Validates and/or sets default options for |MojoCreateDataPipeOptions|. If
// non-null, |in_options| must point to a struct of at least
// |in_options->struct_size| bytes. |out_options| must point to a (current)
// |MojoCreateDataPipeOptions| and will be entirely overwritten on success (it
// may be partly overwritten on failure).
static MojoResult ValidateCreateOptions(
const MojoCreateDataPipeOptions* in_options,
MojoCreateDataPipeOptions* out_options);
// Helper methods used by DataPipeConsumerDispatcher and
// DataPipeProducerDispatcher for serialization and deserialization.
static void StartSerialize(bool have_channel_handle,
bool have_shared_memory,
size_t* max_size,
size_t* max_platform_handles);
static void EndSerialize(const MojoCreateDataPipeOptions& options,
ScopedPlatformHandle channel_handle,
ScopedPlatformHandle shared_memory_handle,
size_t shared_memory_size,
void* destination,
size_t* actual_size,
PlatformHandleVector* platform_handles);
static ScopedPlatformHandle Deserialize(
const void* source,
size_t size,
PlatformHandleVector* platform_handles,
MojoCreateDataPipeOptions* options,
ScopedPlatformHandle* shared_memory_handle,
size_t* shared_memory_size);
};
} // namespace edk
} // namespace mojo
#endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_
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