0

Clean up most Mojo core APIs

TL;DR for non-mojo reviews: No functional changes in your code. All
mechanical aesthetic changes.

This cleans up all message pipe, data pipe, and shared buffer APIs to
reflect the intended stable ABI of the initial mojo_core release, adding
extensible options structs where appropriate and homogenizing argument
ordering conventions. Also renames some badly named types and begins
eliminating the split C/C++ flag constant definitions in favor of using
C macros everywhere.

Documentation formatting is also made more consistent, and the thunk
table ordering is mostly finalized here.

The only functional change is a small drive-by bugfix in
MojoGetBufferInfo where the implementation was not filling in the actual
size of the MojoSharedBufferInfo struct. This has no effect on any
current production uses of the API.

TBR=miu@chromium.org
TBR=jam@chromium.org
TBR=kinuko@chromium.org

Bug: 819046
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I5c1019bf1fe95a9295a0d053544e867fdebadde8
Reviewed-on: https://chromium-review.googlesource.com/1041149
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555808}
This commit is contained in:
Ken Rockot
2018-05-03 18:10:21 +00:00
committed by Commit Bot
parent 1b0eca2c84
commit c12080cd8b
58 changed files with 1333 additions and 1136 deletions

@ -124,8 +124,8 @@ class CastRemotingSenderTest : public ::testing::Test {
remoting_sender_->OnReceivedRtt(base::TimeDelta::FromMilliseconds(1));
const MojoCreateDataPipeOptions data_pipe_options{
sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 1, kDataPipeCapacity};
sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
kDataPipeCapacity};
mojo::ScopedDataPipeConsumerHandle consumer_end;
CHECK_EQ(MOJO_RESULT_OK,
mojo::CreateDataPipe(&data_pipe_options, &producer_end_,

@ -49,8 +49,8 @@ class DataPipeToSourceStreamTest
void Init(base::StringPiece message) {
message_ = message;
const MojoCreateDataPipeOptions data_pipe_options{
sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 1, GetParam().pipe_capacity};
sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
GetParam().pipe_capacity};
mojo::ScopedDataPipeConsumerHandle consumer_end;
CHECK_EQ(MOJO_RESULT_OK,
mojo::CreateDataPipe(&data_pipe_options, &producer_end_,

@ -264,7 +264,7 @@ void MojoAsyncResourceHandler::OnWillRead(
first_call = true;
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = g_allocation_size;
mojo::ScopedDataPipeProducerHandle producer;

@ -53,8 +53,8 @@ class SourceStreamToDataPipeTest
source_ = source.get();
const MojoCreateDataPipeOptions data_pipe_options{
sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 1, GetParam().pipe_capacity};
sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
GetParam().pipe_capacity};
mojo::ScopedDataPipeProducerHandle producer_end;
CHECK_EQ(MOJO_RESULT_OK,
mojo::CreateDataPipe(&data_pipe_options, &producer_end,

@ -63,7 +63,7 @@ class URLLoaderClientImplTest : public ::testing::Test,
static MojoCreateDataPipeOptions DataPipeOptions() {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = 4096;
return options;

@ -144,7 +144,7 @@ class URLResponseBodyConsumerTest : public ::testing::Test {
MojoCreateDataPipeOptions CreateDataPipeOptions() {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = 1024;
return options;

@ -196,7 +196,7 @@ class WebDataConsumerHandleImplTest : public ::testing::Test {
void SetUp() override {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = kDataPipeCapacity;

@ -117,8 +117,8 @@ class DemuxerStreamAdapterTest : public ::testing::Test {
constexpr size_t kDataPipeCapacity = 256;
demuxer_stream_.reset(new FakeDemuxerStream(true)); // audio.
const MojoCreateDataPipeOptions data_pipe_options{
sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 1, kDataPipeCapacity};
sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
kDataPipeCapacity};
mojom::RemotingDataStreamSenderPtr stream_sender;
mojo::ScopedDataPipeProducerHandle producer_end;
mojo::ScopedDataPipeConsumerHandle consumer_end;

@ -80,7 +80,7 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_CreateSharedBuffer(
DCHECK_EQ(options->struct_size, buffer_size);
}
MojoHandle handle;
MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle);
MojoResult result = MojoCreateSharedBuffer(num_bytes, options, &handle);
return Java_CoreImpl_newResultAndInteger(env, result, handle);
}
@ -187,8 +187,11 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_ReadData(
DCHECK(buffer_start);
DCHECK(elements_capacity <= env->GetDirectBufferCapacity(elements));
}
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoReadData(mojo_handle, buffer_start, &buffer_size, flags);
MojoReadData(mojo_handle, &options, buffer_start, &buffer_size);
return Java_CoreImpl_newResultAndInteger(
env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0);
}
@ -201,8 +204,12 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_BeginReadData(
jint flags) {
void const* buffer = 0;
uint32_t buffer_size = num_bytes;
MojoBeginReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoBeginReadData(mojo_handle, &buffer, &buffer_size, flags);
MojoBeginReadData(mojo_handle, &options, &buffer, &buffer_size);
if (result == MOJO_RESULT_OK) {
ScopedJavaLocalRef<jobject> byte_buffer(
env, env->NewDirectByteBuffer(const_cast<void*>(buffer), buffer_size));
@ -216,7 +223,7 @@ static jint JNI_CoreImpl_EndReadData(JNIEnv* env,
const JavaParamRef<jobject>& jcaller,
jint mojo_handle,
jint num_bytes_read) {
return MojoEndReadData(mojo_handle, num_bytes_read);
return MojoEndReadData(mojo_handle, num_bytes_read, nullptr);
}
static ScopedJavaLocalRef<jobject> JNI_CoreImpl_WriteData(
@ -230,8 +237,12 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_WriteData(
DCHECK(buffer_start);
DCHECK(limit <= env->GetDirectBufferCapacity(elements));
uint32_t buffer_size = limit;
MojoWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoWriteData(mojo_handle, buffer_start, &buffer_size, flags);
MojoWriteData(mojo_handle, buffer_start, &buffer_size, &options);
return Java_CoreImpl_newResultAndInteger(
env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0);
}
@ -244,8 +255,11 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_BeginWriteData(
jint flags) {
void* buffer = 0;
uint32_t buffer_size = num_bytes;
MojoBeginWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoBeginWriteData(mojo_handle, &buffer, &buffer_size, flags);
MojoBeginWriteData(mojo_handle, &options, &buffer, &buffer_size);
if (result == MOJO_RESULT_OK) {
ScopedJavaLocalRef<jobject> byte_buffer(
env, env->NewDirectByteBuffer(buffer, buffer_size));
@ -259,7 +273,7 @@ static jint JNI_CoreImpl_EndWriteData(JNIEnv* env,
const JavaParamRef<jobject>& jcaller,
jint mojo_handle,
jint num_bytes_written) {
return MojoEndWriteData(mojo_handle, num_bytes_written);
return MojoEndWriteData(mojo_handle, num_bytes_written, nullptr);
}
static ScopedJavaLocalRef<jobject> JNI_CoreImpl_Duplicate(
@ -290,8 +304,11 @@ static ScopedJavaLocalRef<jobject> JNI_CoreImpl_Map(
jlong num_bytes,
jint flags) {
void* buffer = 0;
MojoMapBufferOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoMapBuffer(mojo_handle, offset, num_bytes, &buffer, flags);
MojoMapBuffer(mojo_handle, offset, num_bytes, &options, &buffer);
if (result == MOJO_RESULT_OK) {
ScopedJavaLocalRef<jobject> byte_buffer(
env, env->NewDirectByteBuffer(buffer, num_bytes));

@ -313,14 +313,14 @@ TEST_F(EmbedderTest, MultiprocessBaseSharedMemory) {
// 2. Map |sb1| and write something into it.
char* buffer = nullptr;
ASSERT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(sb1, 0, 123, reinterpret_cast<void**>(&buffer), 0));
ASSERT_EQ(MOJO_RESULT_OK, MojoMapBuffer(sb1, 0, 123, nullptr,
reinterpret_cast<void**>(&buffer)));
ASSERT_TRUE(buffer);
memcpy(buffer, kHelloWorld, sizeof(kHelloWorld));
// 3. Duplicate |sb1| into |sb2| and pass to |server_mp|.
MojoHandle sb2 = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_OK, MojoDuplicateBufferHandle(sb1, 0, &sb2));
EXPECT_EQ(MOJO_RESULT_OK, MojoDuplicateBufferHandle(sb1, nullptr, &sb2));
EXPECT_NE(MOJO_HANDLE_INVALID, sb2);
WriteMessageWithHandles(server_mp, "hello", &sb2, 1);
@ -350,8 +350,8 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(MultiprocessSharedMemoryClient,
// 2. Map |sb1|.
char* buffer = nullptr;
ASSERT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(sb1, 0, 123, reinterpret_cast<void**>(&buffer), 0));
ASSERT_EQ(MOJO_RESULT_OK, MojoMapBuffer(sb1, 0, 123, nullptr,
reinterpret_cast<void**>(&buffer)));
ASSERT_TRUE(buffer);
// 3. Ensure |buffer| contains the values we expect.

@ -38,36 +38,31 @@ MojoResult MojoQueryHandleSignalsStateImpl(
return g_core->QueryHandleSignalsState(handle, signals_state);
}
MojoResult MojoCreateTrapImpl(MojoTrapEventHandler handler,
const MojoCreateTrapOptions* options,
MojoHandle* trap_handle) {
return g_core->CreateTrap(handler, options, trap_handle);
MojoResult MojoCreateMessagePipeImpl(
const MojoCreateMessagePipeOptions* options,
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1) {
return g_core->CreateMessagePipe(options, message_pipe_handle0,
message_pipe_handle1);
}
MojoResult MojoArmTrapImpl(MojoHandle trap_handle,
const MojoArmTrapOptions* options,
uint32_t* num_ready_triggers,
uintptr_t* ready_triggers,
MojoResult* ready_results,
MojoHandleSignalsState* ready_signals_states) {
return g_core->ArmTrap(trap_handle, options, num_ready_triggers,
ready_triggers, ready_results, ready_signals_states);
MojoResult MojoWriteMessageImpl(MojoHandle message_pipe_handle,
MojoMessageHandle message,
const MojoWriteMessageOptions* options) {
return g_core->WriteMessage(message_pipe_handle, message, options);
}
MojoResult MojoAddTriggerImpl(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const MojoAddTriggerOptions* options) {
return g_core->AddTrigger(trap_handle, handle, signals, condition, context,
options);
MojoResult MojoReadMessageImpl(MojoHandle message_pipe_handle,
const MojoReadMessageOptions* options,
MojoMessageHandle* message) {
return g_core->ReadMessage(message_pipe_handle, options, message);
}
MojoResult MojoRemoveTriggerImpl(MojoHandle trap_handle,
uintptr_t context,
const MojoRemoveTriggerOptions* options) {
return g_core->RemoveTrigger(trap_handle, context, options);
MojoResult MojoFuseMessagePipesImpl(
MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options) {
return g_core->FuseMessagePipes(handle0, handle1, options);
}
MojoResult MojoCreateMessageImpl(const MojoCreateMessageOptions* options,
@ -75,16 +70,16 @@ MojoResult MojoCreateMessageImpl(const MojoCreateMessageOptions* options,
return g_core->CreateMessage(options, message);
}
MojoResult MojoDestroyMessageImpl(MojoMessageHandle message) {
return g_core->DestroyMessage(message);
}
MojoResult MojoSerializeMessageImpl(
MojoMessageHandle message,
const MojoSerializeMessageOptions* options) {
return g_core->SerializeMessage(message, options);
}
MojoResult MojoDestroyMessageImpl(MojoMessageHandle message) {
return g_core->DestroyMessage(message);
}
MojoResult MojoAppendMessageDataImpl(
MojoMessageHandle message,
uint32_t additional_payload_size,
@ -124,28 +119,12 @@ MojoResult MojoGetMessageContextImpl(
return g_core->GetMessageContext(message, options, context);
}
MojoResult MojoCreateMessagePipeImpl(
const MojoCreateMessagePipeOptions* options,
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1) {
return g_core->CreateMessagePipe(options, message_pipe_handle0,
message_pipe_handle1);
}
MojoResult MojoWriteMessageImpl(MojoHandle message_pipe_handle,
MojoMessageHandle message,
MojoWriteMessageFlags flags) {
return g_core->WriteMessage(message_pipe_handle, message, flags);
}
MojoResult MojoReadMessageImpl(MojoHandle message_pipe_handle,
MojoMessageHandle* message,
MojoReadMessageFlags flags) {
return g_core->ReadMessage(message_pipe_handle, message, flags);
}
MojoResult MojoFuseMessagePipesImpl(MojoHandle handle0, MojoHandle handle1) {
return g_core->FuseMessagePipes(handle0, handle1);
MojoResult MojoNotifyBadMessageImpl(
MojoMessageHandle message,
const char* error,
size_t error_num_bytes,
const MojoNotifyBadMessageOptions* options) {
return g_core->NotifyBadMessage(message, error, error_num_bytes, options);
}
MojoResult MojoCreateDataPipeImpl(const MojoCreateDataPipeOptions* options,
@ -158,50 +137,54 @@ MojoResult MojoCreateDataPipeImpl(const MojoCreateDataPipeOptions* options,
MojoResult MojoWriteDataImpl(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
MojoWriteDataFlags flags) {
const MojoWriteDataOptions* options) {
return g_core->WriteData(data_pipe_producer_handle, elements, num_elements,
flags);
options);
}
MojoResult MojoBeginWriteDataImpl(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_elements,
MojoWriteDataFlags flags) {
return g_core->BeginWriteData(data_pipe_producer_handle, buffer,
buffer_num_elements, flags);
uint32_t* buffer_num_elements) {
return g_core->BeginWriteData(data_pipe_producer_handle, options, buffer,
buffer_num_elements);
}
MojoResult MojoEndWriteDataImpl(MojoHandle data_pipe_producer_handle,
uint32_t num_elements_written) {
return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written);
uint32_t num_elements_written,
const MojoEndWriteDataOptions* options) {
return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written,
options);
}
MojoResult MojoReadDataImpl(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_elements,
MojoReadDataFlags flags) {
return g_core->ReadData(data_pipe_consumer_handle, elements, num_elements,
flags);
uint32_t* num_elements) {
return g_core->ReadData(data_pipe_consumer_handle, options, elements,
num_elements);
}
MojoResult MojoBeginReadDataImpl(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_elements,
MojoReadDataFlags flags) {
return g_core->BeginReadData(data_pipe_consumer_handle, buffer,
buffer_num_elements, flags);
uint32_t* buffer_num_elements) {
return g_core->BeginReadData(data_pipe_consumer_handle, options, buffer,
buffer_num_elements);
}
MojoResult MojoEndReadDataImpl(MojoHandle data_pipe_consumer_handle,
uint32_t num_elements_read) {
return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read);
uint32_t num_elements_read,
const MojoEndReadDataOptions* options) {
return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read,
options);
}
MojoResult MojoCreateSharedBufferImpl(
const MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle) {
return g_core->CreateSharedBuffer(options, num_bytes, shared_buffer_handle);
return g_core->CreateSharedBuffer(num_bytes, options, shared_buffer_handle);
}
MojoResult MojoDuplicateBufferHandleImpl(
@ -215,9 +198,9 @@ MojoResult MojoDuplicateBufferHandleImpl(
MojoResult MojoMapBufferImpl(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags) {
return g_core->MapBuffer(buffer_handle, offset, num_bytes, buffer, flags);
const MojoMapBufferOptions* options,
void** buffer) {
return g_core->MapBuffer(buffer_handle, offset, num_bytes, options, buffer);
}
MojoResult MojoUnmapBufferImpl(void* buffer) {
@ -225,11 +208,43 @@ MojoResult MojoUnmapBufferImpl(void* buffer) {
}
MojoResult MojoGetBufferInfoImpl(MojoHandle buffer_handle,
const MojoSharedBufferOptions* options,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) {
return g_core->GetBufferInfo(buffer_handle, options, info);
}
MojoResult MojoCreateTrapImpl(MojoTrapEventHandler handler,
const MojoCreateTrapOptions* options,
MojoHandle* trap_handle) {
return g_core->CreateTrap(handler, options, trap_handle);
}
MojoResult MojoAddTriggerImpl(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const MojoAddTriggerOptions* options) {
return g_core->AddTrigger(trap_handle, handle, signals, condition, context,
options);
}
MojoResult MojoRemoveTriggerImpl(MojoHandle trap_handle,
uintptr_t context,
const MojoRemoveTriggerOptions* options) {
return g_core->RemoveTrigger(trap_handle, context, options);
}
MojoResult MojoArmTrapImpl(MojoHandle trap_handle,
const MojoArmTrapOptions* options,
uint32_t* num_ready_triggers,
uintptr_t* ready_triggers,
MojoResult* ready_results,
MojoHandleSignalsState* ready_signals_states) {
return g_core->ArmTrap(trap_handle, options, num_ready_triggers,
ready_triggers, ready_results, ready_signals_states);
}
MojoResult MojoWrapPlatformHandleImpl(const MojoPlatformHandle* platform_handle,
MojoHandle* mojo_handle) {
return g_core->WrapPlatformHandle(platform_handle, mojo_handle);
@ -260,12 +275,6 @@ MojoResult MojoUnwrapPlatformSharedBufferHandleImpl(
num_bytes, guid, flags);
}
MojoResult MojoNotifyBadMessageImpl(MojoMessageHandle message,
const char* error,
size_t error_num_bytes) {
return g_core->NotifyBadMessage(message, error, error_num_bytes);
}
} // extern "C"
MojoSystemThunks g_thunks = {sizeof(MojoSystemThunks),
@ -276,6 +285,15 @@ MojoSystemThunks g_thunks = {sizeof(MojoSystemThunks),
MojoCreateMessagePipeImpl,
MojoWriteMessageImpl,
MojoReadMessageImpl,
MojoFuseMessagePipesImpl,
MojoCreateMessageImpl,
MojoDestroyMessageImpl,
MojoSerializeMessageImpl,
MojoAppendMessageDataImpl,
MojoGetMessageDataImpl,
MojoSetMessageContextImpl,
MojoGetMessageContextImpl,
MojoNotifyBadMessageImpl,
MojoCreateDataPipeImpl,
MojoWriteDataImpl,
MojoBeginWriteDataImpl,
@ -292,19 +310,10 @@ MojoSystemThunks g_thunks = {sizeof(MojoSystemThunks),
MojoAddTriggerImpl,
MojoRemoveTriggerImpl,
MojoArmTrapImpl,
MojoFuseMessagePipesImpl,
MojoCreateMessageImpl,
MojoDestroyMessageImpl,
MojoSerializeMessageImpl,
MojoAppendMessageDataImpl,
MojoGetMessageDataImpl,
MojoSetMessageContextImpl,
MojoGetMessageContextImpl,
MojoWrapPlatformHandleImpl,
MojoUnwrapPlatformHandleImpl,
MojoWrapPlatformSharedBufferHandleImpl,
MojoUnwrapPlatformSharedBufferHandleImpl,
MojoNotifyBadMessageImpl};
MojoUnwrapPlatformSharedBufferHandleImpl};
} // namespace

@ -18,16 +18,14 @@ TEST(MojoCoreTest, SanityCheck) {
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessage(nullptr, &m));
EXPECT_EQ(MOJO_RESULT_OK,
MojoSetMessageContext(m, 42, nullptr, nullptr, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(a, m, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(a, m, nullptr));
m = MOJO_MESSAGE_HANDLE_INVALID;
MojoHandleSignalsState state;
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
EXPECT_TRUE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(b, &m, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &m));
uintptr_t context = 0;
EXPECT_EQ(MOJO_RESULT_OK, MojoGetMessageContext(m, nullptr, &context));

@ -6,6 +6,7 @@
#include <string.h>
#include <algorithm>
#include <utility>
#include "base/bind.h"
@ -606,7 +607,7 @@ MojoResult Core::CreateMessagePipe(const MojoCreateMessagePipeOptions* options,
MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message_handle,
MojoWriteMessageFlags flags) {
const MojoWriteMessageOptions* options) {
RequestContext request_context;
if (!message_handle)
return MOJO_RESULT_INVALID_ARGUMENT;
@ -618,12 +619,12 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
auto dispatcher = GetDispatcher(message_pipe_handle);
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
return dispatcher->WriteMessage(std::move(message_event), flags);
return dispatcher->WriteMessage(std::move(message_event));
}
MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
MojoMessageHandle* message_handle,
MojoReadMessageFlags flags) {
const MojoReadMessageOptions* options,
MojoMessageHandle* message_handle) {
RequestContext request_context;
auto dispatcher = GetDispatcher(message_pipe_handle);
if (!dispatcher || !message_handle)
@ -639,7 +640,9 @@ MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
return MOJO_RESULT_OK;
}
MojoResult Core::FuseMessagePipes(MojoHandle handle0, MojoHandle handle1) {
MojoResult Core::FuseMessagePipes(MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher0;
scoped_refptr<Dispatcher> dispatcher1;
@ -678,7 +681,8 @@ MojoResult Core::FuseMessagePipes(MojoHandle handle0, MojoHandle handle1) {
MojoResult Core::NotifyBadMessage(MojoMessageHandle message_handle,
const char* error,
size_t error_num_bytes) {
size_t error_num_bytes,
const MojoNotifyBadMessageOptions* options) {
if (!message_handle)
return MOJO_RESULT_INVALID_ARGUMENT;
@ -785,80 +789,131 @@ MojoResult Core::CreateDataPipe(const MojoCreateDataPipeOptions* options,
MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) {
const MojoWriteDataOptions* options) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
return dispatcher->WriteData(elements, num_bytes, flags);
MojoWriteDataOptions validated_options;
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
constexpr MojoWriteDataFlags kSupportedFlags =
MOJO_WRITE_DATA_FLAG_NONE | MOJO_WRITE_DATA_FLAG_ALL_OR_NONE;
if (options->flags & ~kSupportedFlags)
return MOJO_RESULT_UNIMPLEMENTED;
validated_options.flags = options->flags;
} else {
validated_options.flags = MOJO_WRITE_DATA_FLAG_NONE;
}
return dispatcher->WriteData(elements, num_bytes, validated_options);
}
MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) {
uint32_t* buffer_num_bytes) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags);
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_BEGIN_WRITE_DATA_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
return dispatcher->BeginWriteData(buffer, buffer_num_bytes);
}
MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written) {
uint32_t num_bytes_written,
const MojoEndWriteDataOptions* options) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_END_WRITE_DATA_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
return dispatcher->EndWriteData(num_bytes_written);
}
MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) {
uint32_t* num_bytes) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
return dispatcher->ReadData(elements, num_bytes, flags);
MojoReadDataOptions validated_options;
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
constexpr MojoReadDataFlags kSupportedFlags =
MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_ALL_OR_NONE |
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_QUERY |
MOJO_READ_DATA_FLAG_PEEK;
if (options->flags & ~kSupportedFlags)
return MOJO_RESULT_UNIMPLEMENTED;
validated_options.flags = options->flags;
} else {
validated_options.flags = MOJO_WRITE_DATA_FLAG_NONE;
}
return dispatcher->ReadData(validated_options, elements, num_bytes);
}
MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) {
uint32_t* buffer_num_bytes) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags);
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_BEGIN_READ_DATA_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
return dispatcher->BeginReadData(buffer, buffer_num_bytes);
}
MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read) {
uint32_t num_bytes_read,
const MojoEndReadDataOptions* options) {
RequestContext request_context;
scoped_refptr<Dispatcher> dispatcher(
GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_END_READ_DATA_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
return dispatcher->EndReadData(num_bytes_read);
}
MojoResult Core::CreateSharedBuffer(
const MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle) {
RequestContext request_context;
MojoCreateSharedBufferOptions validated_options = {};
@ -914,14 +969,20 @@ MojoResult Core::DuplicateBufferHandle(
MojoResult Core::MapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags) {
const MojoMapBufferOptions* options,
void** buffer) {
scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_MAP_BUFFER_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
std::unique_ptr<PlatformSharedMemoryMapping> mapping;
MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping);
MojoResult result = dispatcher->MapBuffer(offset, num_bytes, &mapping);
if (result != MOJO_RESULT_OK)
return result;
@ -956,11 +1017,15 @@ MojoResult Core::UnmapBuffer(void* buffer) {
}
MojoResult Core::GetBufferInfo(MojoHandle buffer_handle,
const MojoSharedBufferOptions* options,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) {
if (options && options->struct_size != sizeof(MojoSharedBufferOptions))
return MOJO_RESULT_INVALID_ARGUMENT;
if (!info || info->struct_size != sizeof(MojoSharedBufferInfo))
if (options) {
if (options->struct_size < sizeof(*options))
return MOJO_RESULT_INVALID_ARGUMENT;
if (options->flags != MOJO_GET_BUFFER_INFO_FLAG_NONE)
return MOJO_RESULT_UNIMPLEMENTED;
}
if (!info || info->struct_size < sizeof(MojoSharedBufferInfo))
return MOJO_RESULT_INVALID_ARGUMENT;
scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));

@ -219,14 +219,17 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
MojoHandle* message_pipe_handle1);
MojoResult WriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message_handle,
MojoWriteMessageFlags flags);
const MojoWriteMessageOptions* options);
MojoResult ReadMessage(MojoHandle message_pipe_handle,
MojoMessageHandle* message_handle,
MojoReadMessageFlags flags);
MojoResult FuseMessagePipes(MojoHandle handle0, MojoHandle handle1);
const MojoReadMessageOptions* options,
MojoMessageHandle* message_handle);
MojoResult FuseMessagePipes(MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options);
MojoResult NotifyBadMessage(MojoMessageHandle message_handle,
const char* error,
size_t error_num_bytes);
size_t error_num_bytes,
const MojoNotifyBadMessageOptions* options);
// These methods correspond to the API functions defined in
// "mojo/public/c/system/data_pipe.h":
@ -236,28 +239,30 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
MojoResult WriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags);
const MojoWriteDataOptions* options);
MojoResult BeginWriteData(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags);
uint32_t* buffer_num_bytes);
MojoResult EndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written);
uint32_t num_bytes_written,
const MojoEndWriteDataOptions* options);
MojoResult ReadData(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags);
uint32_t* num_bytes);
MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags);
uint32_t* buffer_num_bytes);
MojoResult EndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read);
uint32_t num_bytes_read,
const MojoEndReadDataOptions* options);
// These methods correspond to the API functions defined in
// "mojo/public/c/system/buffer.h":
MojoResult CreateSharedBuffer(const MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
MojoResult CreateSharedBuffer(uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle);
MojoResult DuplicateBufferHandle(
MojoHandle buffer_handle,
@ -266,11 +271,11 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
MojoResult MapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags);
const MojoMapBufferOptions* options,
void** buffer);
MojoResult UnmapBuffer(void* buffer);
MojoResult GetBufferInfo(MojoHandle buffer_handle,
const MojoSharedBufferOptions* options,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info);
// These methods correspond to the API functions defined in

@ -41,8 +41,7 @@ class MockDispatcher : public Dispatcher {
}
MojoResult WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message_event,
MojoWriteMessageFlags /*flags*/) override {
std::unique_ptr<ports::UserMessageEvent> message_event) override {
info_->IncrementWriteMessageCallCount();
return MOJO_RESULT_OK;
}
@ -55,14 +54,13 @@ class MockDispatcher : public Dispatcher {
MojoResult WriteData(const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) override {
const MojoWriteDataOptions& options) override {
info_->IncrementWriteDataCallCount();
return MOJO_RESULT_UNIMPLEMENTED;
}
MojoResult BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) override {
uint32_t* buffer_num_bytes) override {
info_->IncrementBeginWriteDataCallCount();
return MOJO_RESULT_UNIMPLEMENTED;
}
@ -72,16 +70,15 @@ class MockDispatcher : public Dispatcher {
return MOJO_RESULT_UNIMPLEMENTED;
}
MojoResult ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) override {
MojoResult ReadData(const MojoReadDataOptions& options,
void* elements,
uint32_t* num_bytes) override {
info_->IncrementReadDataCallCount();
return MOJO_RESULT_UNIMPLEMENTED;
}
MojoResult BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) override {
uint32_t* buffer_num_bytes) override {
info_->IncrementBeginReadDataCallCount();
return MOJO_RESULT_UNIMPLEMENTED;
}

@ -51,46 +51,41 @@ TEST_F(CoreTest, Basic) {
ASSERT_EQ(0u, info.GetWriteMessageCallCount());
MojoMessageHandle message;
ASSERT_EQ(MOJO_RESULT_OK, core()->CreateMessage(nullptr, &message));
ASSERT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h, message, MOJO_WRITE_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->WriteMessage(h, message, nullptr));
ASSERT_EQ(1u, info.GetWriteMessageCallCount());
ASSERT_EQ(0u, info.GetReadMessageCallCount());
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadMessage(h, &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadMessage(h, nullptr, &message));
ASSERT_EQ(1u, info.GetReadMessageCallCount());
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadMessage(h, &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadMessage(h, nullptr, &message));
ASSERT_EQ(2u, info.GetReadMessageCallCount());
ASSERT_EQ(0u, info.GetWriteDataCallCount());
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED,
core()->WriteData(h, nullptr, nullptr, MOJO_WRITE_DATA_FLAG_NONE));
core()->WriteData(h, nullptr, nullptr, nullptr));
ASSERT_EQ(1u, info.GetWriteDataCallCount());
ASSERT_EQ(0u, info.GetBeginWriteDataCallCount());
ASSERT_EQ(
MOJO_RESULT_UNIMPLEMENTED,
core()->BeginWriteData(h, nullptr, nullptr, MOJO_WRITE_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED,
core()->BeginWriteData(h, nullptr, nullptr, nullptr));
ASSERT_EQ(1u, info.GetBeginWriteDataCallCount());
ASSERT_EQ(0u, info.GetEndWriteDataCallCount());
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndWriteData(h, 0));
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndWriteData(h, 0, nullptr));
ASSERT_EQ(1u, info.GetEndWriteDataCallCount());
ASSERT_EQ(0u, info.GetReadDataCallCount());
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED,
core()->ReadData(h, nullptr, nullptr, MOJO_READ_DATA_FLAG_NONE));
core()->ReadData(h, nullptr, nullptr, nullptr));
ASSERT_EQ(1u, info.GetReadDataCallCount());
ASSERT_EQ(0u, info.GetBeginReadDataCallCount());
ASSERT_EQ(
MOJO_RESULT_UNIMPLEMENTED,
core()->BeginReadData(h, nullptr, nullptr, MOJO_READ_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED,
core()->BeginReadData(h, nullptr, nullptr, nullptr));
ASSERT_EQ(1u, info.GetBeginReadDataCallCount());
ASSERT_EQ(0u, info.GetEndReadDataCallCount());
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0));
ASSERT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0, nullptr));
ASSERT_EQ(1u, info.GetEndReadDataCallCount());
ASSERT_EQ(0u, info.GetDtorCallCount());
@ -122,23 +117,20 @@ TEST_F(CoreTest, InvalidArguments) {
// |WriteMessageNew()|:
// Only check arguments checked by |Core|, namely |handle|, |handles|, and
// |num_handles|.
{
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->WriteMessage(MOJO_HANDLE_INVALID, 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
}
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->WriteMessage(MOJO_HANDLE_INVALID, 0, nullptr));
// |ReadMessageNew()|:
// Only check arguments checked by |Core|, namely |handle|, |handles|, and
// |num_handles|.
{
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadMessage(MOJO_HANDLE_INVALID, nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
core()->ReadMessage(MOJO_HANDLE_INVALID, nullptr, nullptr));
MockHandleInfo info;
MojoHandle h = CreateMockHandle(&info);
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadMessage(h, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
core()->ReadMessage(h, nullptr, nullptr));
// Checked by |Core|, shouldn't go through to the dispatcher.
ASSERT_EQ(0u, info.GetReadMessageCallCount());
ASSERT_EQ(MOJO_RESULT_OK, core()->Close(h));
@ -168,7 +160,7 @@ TEST_F(CoreTest, MessagePipe) {
// Try to read anyway.
MojoMessageHandle message;
ASSERT_EQ(MOJO_RESULT_SHOULD_WAIT,
core()->ReadMessage(h[0], &message, MOJO_READ_MESSAGE_FLAG_NONE));
core()->ReadMessage(h[0], nullptr, &message));
// Write to |h[1]|.
const uintptr_t kTestMessageContext = 123;
@ -176,16 +168,14 @@ TEST_F(CoreTest, MessagePipe) {
ASSERT_EQ(MOJO_RESULT_OK,
core()->SetMessageContext(message, kTestMessageContext, nullptr,
nullptr, nullptr));
ASSERT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h[1], message, MOJO_WRITE_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->WriteMessage(h[1], message, nullptr));
// Wait for |h[0]| to become readable.
EXPECT_EQ(MOJO_RESULT_OK, mojo::Wait(mojo::Handle(h[0]),
MOJO_HANDLE_SIGNAL_READABLE, &hss[0]));
// Read from |h[0]|.
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadMessage(h[0], &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadMessage(h[0], nullptr, &message));
uintptr_t context;
ASSERT_EQ(MOJO_RESULT_OK,
core()->GetMessageContext(message, nullptr, &context));
@ -205,8 +195,7 @@ TEST_F(CoreTest, MessagePipe) {
ASSERT_EQ(MOJO_RESULT_OK,
core()->SetMessageContext(message, kTestMessageContext, nullptr,
nullptr, nullptr));
ASSERT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h[0], message, MOJO_WRITE_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->WriteMessage(h[0], message, nullptr));
// Close |h[0]|.
ASSERT_EQ(MOJO_RESULT_OK, core()->Close(h[0]));
@ -229,8 +218,7 @@ TEST_F(CoreTest, MessagePipe) {
hss[1].satisfiable_signals);
// Discard a message from |h[1]|.
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadMessage(h[1], &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadMessage(h[1], nullptr, &message));
ASSERT_EQ(MOJO_RESULT_OK, core()->DestroyMessage(message));
// |h[1]| is no longer readable (and will never be).
@ -245,7 +233,7 @@ TEST_F(CoreTest, MessagePipe) {
core()->SetMessageContext(message, kTestMessageContext, nullptr,
nullptr, nullptr));
ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
core()->WriteMessage(h[1], message, MOJO_WRITE_MESSAGE_FLAG_NONE));
core()->WriteMessage(h[1], message, nullptr));
ASSERT_EQ(MOJO_RESULT_OK, core()->Close(h[1]));
}
@ -264,8 +252,8 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
ASSERT_EQ(MOJO_RESULT_OK,
core()->SetMessageContext(message, kTestMessageContext, nullptr,
nullptr, nullptr));
ASSERT_EQ(MOJO_RESULT_OK, core()->WriteMessage(h_passing[0], message,
MOJO_WRITE_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h_passing[0], message, nullptr));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK, mojo::Wait(mojo::Handle(h_passing[1]),
MOJO_HANDLE_SIGNAL_READABLE, &hss));
@ -273,8 +261,8 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
hss.satisfied_signals);
ASSERT_EQ(kAllSignals, hss.satisfiable_signals);
MojoMessageHandle message_handle;
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadMessage(h_passing[1], &message_handle,
MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadMessage(h_passing[1], nullptr, &message_handle));
uintptr_t context;
ASSERT_EQ(MOJO_RESULT_OK,
core()->GetMessageContext(message_handle, nullptr, &context));
@ -317,8 +305,8 @@ TEST_F(CoreTest, DataPipe) {
// Write.
signed char elements[2] = {'A', 'B'};
uint32_t num_bytes = 2u;
ASSERT_EQ(MOJO_RESULT_OK, core()->WriteData(ph, elements, &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK,
core()->WriteData(ph, elements, &num_bytes, nullptr));
ASSERT_EQ(2u, num_bytes);
// Wait for the data to arrive to the consumer.
@ -339,9 +327,11 @@ TEST_F(CoreTest, DataPipe) {
elements[0] = -1;
elements[1] = -1;
num_bytes = 1u;
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadData(ch, elements, &num_bytes,
MOJO_READ_DATA_FLAG_NONE |
MOJO_READ_DATA_FLAG_PEEK));
MojoReadDataOptions read_options;
read_options.struct_size = sizeof(read_options);
read_options.flags = MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK;
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadData(ch, &read_options, elements, &num_bytes));
ASSERT_EQ('A', elements[0]);
ASSERT_EQ(-1, elements[1]);
@ -349,30 +339,31 @@ TEST_F(CoreTest, DataPipe) {
elements[0] = -1;
elements[1] = -1;
num_bytes = 1u;
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadData(ch, elements, &num_bytes,
MOJO_READ_DATA_FLAG_NONE));
read_options.flags = MOJO_READ_DATA_FLAG_NONE;
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadData(ch, &read_options, elements, &num_bytes));
ASSERT_EQ('A', elements[0]);
ASSERT_EQ(-1, elements[1]);
// Two-phase write.
void* write_ptr = nullptr;
num_bytes = 0u;
ASSERT_EQ(MOJO_RESULT_OK, core()->BeginWriteData(ph, &write_ptr, &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginWriteData(ph, nullptr, &write_ptr, &num_bytes));
// We count on the default options providing a decent buffer size.
ASSERT_GE(num_bytes, 3u);
// Trying to do a normal write during a two-phase write should fail.
elements[0] = 'X';
num_bytes = 1u;
ASSERT_EQ(MOJO_RESULT_BUSY, core()->WriteData(ph, elements, &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_BUSY,
core()->WriteData(ph, elements, &num_bytes, nullptr));
// Actually write the data, and complete it now.
static_cast<char*>(write_ptr)[0] = 'C';
static_cast<char*>(write_ptr)[1] = 'D';
static_cast<char*>(write_ptr)[2] = 'E';
ASSERT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 3u));
ASSERT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 3u, nullptr));
// Wait for the data to arrive to the consumer.
ASSERT_EQ(MOJO_RESULT_OK,
@ -380,73 +371,61 @@ TEST_F(CoreTest, DataPipe) {
// Query how much data we have.
num_bytes = 0;
ASSERT_EQ(MOJO_RESULT_OK, core()->ReadData(ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_QUERY));
read_options.flags = MOJO_READ_DATA_FLAG_QUERY;
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
ASSERT_GE(num_bytes, 1u);
// Try to query with peek. Should fail.
num_bytes = 0;
ASSERT_EQ(
MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadData(ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_QUERY | MOJO_READ_DATA_FLAG_PEEK));
read_options.flags = MOJO_READ_DATA_FLAG_QUERY | MOJO_READ_DATA_FLAG_PEEK;
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
ASSERT_EQ(0u, num_bytes);
// Try to discard ten characters, in all-or-none mode. Should fail.
num_bytes = 10;
read_options.flags =
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE;
ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE,
core()->ReadData(
ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
// Try to discard two characters, in peek mode. Should fail.
num_bytes = 2;
ASSERT_EQ(
MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadData(ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK));
read_options.flags = MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK;
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
// Discard a character.
num_bytes = 1;
read_options.flags =
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE;
ASSERT_EQ(MOJO_RESULT_OK,
core()->ReadData(
ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
// Ensure the 3 bytes were read.
ASSERT_EQ(MOJO_RESULT_OK,
mojo::Wait(mojo::Handle(ch), MOJO_HANDLE_SIGNAL_READABLE, &hss));
// Try a two-phase read of the remaining three bytes with peek. Should fail.
// Read the remaining three characters, in two-phase mode.
const void* read_ptr = nullptr;
num_bytes = 3;
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->BeginReadData(ch, &read_ptr, &num_bytes,
MOJO_READ_DATA_FLAG_PEEK));
// Try a two-phase read of the remaining two bytes with all-or-none. Should
// fail.
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->BeginReadData(ch, &read_ptr, &num_bytes,
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
// Read the remaining three characters, in two-phase mode.
num_bytes = 3;
ASSERT_EQ(MOJO_RESULT_OK, core()->BeginReadData(ch, &read_ptr, &num_bytes,
MOJO_READ_DATA_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginReadData(ch, nullptr, &read_ptr, &num_bytes));
// Note: Count on still being able to do the contiguous read here.
ASSERT_EQ(3u, num_bytes);
// Discarding right now should fail.
num_bytes = 1;
ASSERT_EQ(MOJO_RESULT_BUSY, core()->ReadData(ch, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_DISCARD));
read_options.flags = MOJO_READ_DATA_FLAG_DISCARD;
ASSERT_EQ(MOJO_RESULT_BUSY,
core()->ReadData(ch, &read_options, nullptr, &num_bytes));
// Actually check our data and end the two-phase read.
ASSERT_EQ('C', static_cast<const char*>(read_ptr)[0]);
ASSERT_EQ('D', static_cast<const char*>(read_ptr)[1]);
ASSERT_EQ('E', static_cast<const char*>(read_ptr)[2]);
ASSERT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 3u));
ASSERT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 3u, nullptr));
// Consumer should now be no longer readable.
hss = kFullMojoHandleSignalsState;

@ -96,9 +96,10 @@ MojoResult DataPipeConsumerDispatcher::Close() {
return CloseNoLock();
}
MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) {
MojoResult DataPipeConsumerDispatcher::ReadData(
const MojoReadDataOptions& options,
void* elements,
uint32_t* num_bytes) {
base::AutoLock lock(lock_);
if (!shared_ring_buffer_.IsValid() || in_transit_)
@ -110,11 +111,11 @@ MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
const bool had_new_data = new_data_available_;
new_data_available_ = false;
if ((flags & MOJO_READ_DATA_FLAG_QUERY)) {
if ((flags & MOJO_READ_DATA_FLAG_PEEK) ||
(flags & MOJO_READ_DATA_FLAG_DISCARD))
if ((options.flags & MOJO_READ_DATA_FLAG_QUERY)) {
if ((options.flags & MOJO_READ_DATA_FLAG_PEEK) ||
(options.flags & MOJO_READ_DATA_FLAG_DISCARD))
return MOJO_RESULT_INVALID_ARGUMENT;
DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above.
DCHECK(!(options.flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above.
DVLOG_IF(2, elements) << "Query mode: ignoring non-null |elements|";
*num_bytes = static_cast<uint32_t>(bytes_available_);
@ -124,9 +125,9 @@ MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
}
bool discard = false;
if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
if ((options.flags & MOJO_READ_DATA_FLAG_DISCARD)) {
// These flags are mutally exclusive.
if (flags & MOJO_READ_DATA_FLAG_PEEK)
if (options.flags & MOJO_READ_DATA_FLAG_PEEK)
return MOJO_RESULT_INVALID_ARGUMENT;
DVLOG_IF(2, elements) << "Discard mode: ignoring non-null |elements|";
discard = true;
@ -136,7 +137,7 @@ MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
if (max_num_bytes_to_read % options_.element_num_bytes != 0)
return MOJO_RESULT_INVALID_ARGUMENT;
bool all_or_none = flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE;
bool all_or_none = options.flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE;
uint32_t min_num_bytes_to_read = all_or_none ? max_num_bytes_to_read : 0;
if (min_num_bytes_to_read > bytes_available_) {
@ -173,7 +174,7 @@ MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
}
*num_bytes = bytes_to_read;
bool peek = !!(flags & MOJO_READ_DATA_FLAG_PEEK);
bool peek = !!(options.flags & MOJO_READ_DATA_FLAG_PEEK);
if (discard || !peek) {
read_offset_ = (read_offset_ + bytes_to_read) % options_.capacity_num_bytes;
bytes_available_ -= bytes_to_read;
@ -189,9 +190,9 @@ MojoResult DataPipeConsumerDispatcher::ReadData(void* elements,
return MOJO_RESULT_OK;
}
MojoResult DataPipeConsumerDispatcher::BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) {
MojoResult DataPipeConsumerDispatcher::BeginReadData(
const void** buffer,
uint32_t* buffer_num_bytes) {
base::AutoLock lock(lock_);
if (!shared_ring_buffer_.IsValid() || in_transit_)
return MOJO_RESULT_INVALID_ARGUMENT;
@ -199,13 +200,6 @@ MojoResult DataPipeConsumerDispatcher::BeginReadData(const void** buffer,
if (in_two_phase_read_)
return MOJO_RESULT_BUSY;
// These flags may not be used in two-phase mode.
if ((flags & MOJO_READ_DATA_FLAG_DISCARD) ||
(flags & MOJO_READ_DATA_FLAG_QUERY) ||
(flags & MOJO_READ_DATA_FLAG_PEEK) ||
(flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE))
return MOJO_RESULT_INVALID_ARGUMENT;
const bool had_new_data = new_data_available_;
new_data_available_ = false;

@ -42,12 +42,11 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final
// Dispatcher:
Type GetType() const override;
MojoResult Close() override;
MojoResult ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) override;
MojoResult ReadData(const MojoReadDataOptions& validated_options,
void* elements,
uint32_t* num_bytes) override;
MojoResult BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) override;
uint32_t* buffer_num_bytes) override;
MojoResult EndReadData(uint32_t num_bytes_read) override;
HandleSignalsState GetHandleSignalsState() const override;
MojoResult AddWatcherRef(const scoped_refptr<WatcherDispatcher>& watcher,

@ -95,9 +95,10 @@ MojoResult DataPipeProducerDispatcher::Close() {
return CloseNoLock();
}
MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) {
MojoResult DataPipeProducerDispatcher::WriteData(
const void* elements,
uint32_t* num_bytes,
const MojoWriteDataOptions& options) {
base::AutoLock lock(lock_);
if (!shared_ring_buffer_.IsValid() || in_transit_)
return MOJO_RESULT_INVALID_ARGUMENT;
@ -113,7 +114,7 @@ MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
if (*num_bytes == 0)
return MOJO_RESULT_OK; // Nothing to do.
if ((flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE) &&
if ((options.flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE) &&
(*num_bytes > available_capacity_)) {
// Don't return "should wait" since you can't wait for a specified amount of
// data.
@ -159,16 +160,11 @@ MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
MojoResult DataPipeProducerDispatcher::BeginWriteData(
void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) {
uint32_t* buffer_num_bytes) {
base::AutoLock lock(lock_);
if (!shared_ring_buffer_.IsValid() || in_transit_)
return MOJO_RESULT_INVALID_ARGUMENT;
// These flags may not be used in two-phase mode.
if (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)
return MOJO_RESULT_INVALID_ARGUMENT;
if (in_two_phase_write_)
return MOJO_RESULT_BUSY;
if (peer_closed_)

@ -44,10 +44,8 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final
MojoResult Close() override;
MojoResult WriteData(const void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) override;
MojoResult BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) override;
const MojoWriteDataOptions& options) override;
MojoResult BeginWriteData(void** buffer, uint32_t* buffer_num_bytes) override;
MojoResult EndWriteData(uint32_t num_bytes_written) override;
HandleSignalsState GetHandleSignalsState() const override;
MojoResult AddWatcherRef(const scoped_refptr<WatcherDispatcher>& watcher,

@ -80,9 +80,11 @@ class DataPipeTest : public test::MojoTestBase {
MojoResult WriteData(const void* elements,
uint32_t* num_bytes,
bool all_or_none = false) {
return MojoWriteData(producer_, elements, num_bytes,
all_or_none ? MOJO_WRITE_DATA_FLAG_ALL_OR_NONE
: MOJO_WRITE_DATA_FLAG_NONE);
MojoWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = all_or_none ? MOJO_WRITE_DATA_FLAG_ALL_OR_NONE
: MOJO_WRITE_DATA_FLAG_NONE;
return MojoWriteData(producer_, elements, num_bytes, &options);
}
MojoResult ReadData(void* elements,
@ -94,41 +96,44 @@ class DataPipeTest : public test::MojoTestBase {
flags |= MOJO_READ_DATA_FLAG_ALL_OR_NONE;
if (peek)
flags |= MOJO_READ_DATA_FLAG_PEEK;
return MojoReadData(consumer_, elements, num_bytes, flags);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoReadData(consumer_, &options, elements, num_bytes);
}
MojoResult QueryData(uint32_t* num_bytes) {
return MojoReadData(consumer_, nullptr, num_bytes,
MOJO_READ_DATA_FLAG_QUERY);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_QUERY;
return MojoReadData(consumer_, &options, nullptr, num_bytes);
}
MojoResult DiscardData(uint32_t* num_bytes, bool all_or_none = false) {
MojoReadDataFlags flags = MOJO_READ_DATA_FLAG_DISCARD;
if (all_or_none)
flags |= MOJO_READ_DATA_FLAG_ALL_OR_NONE;
return MojoReadData(consumer_, nullptr, num_bytes, flags);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoReadData(consumer_, &options, nullptr, num_bytes);
}
MojoResult BeginReadData(const void** elements, uint32_t* num_bytes) {
return MojoBeginReadData(consumer_, elements, num_bytes,
MOJO_READ_DATA_FLAG_NONE);
return MojoBeginReadData(consumer_, nullptr, elements, num_bytes);
}
MojoResult EndReadData(uint32_t num_bytes_read) {
return MojoEndReadData(consumer_, num_bytes_read);
return MojoEndReadData(consumer_, num_bytes_read, nullptr);
}
MojoResult BeginWriteData(void** elements,
uint32_t* num_bytes,
bool all_or_none = false) {
MojoReadDataFlags flags = MOJO_WRITE_DATA_FLAG_NONE;
if (all_or_none)
flags |= MOJO_WRITE_DATA_FLAG_ALL_OR_NONE;
return MojoBeginWriteData(producer_, elements, num_bytes, flags);
MojoResult BeginWriteData(void** elements, uint32_t* num_bytes) {
return MojoBeginWriteData(producer_, nullptr, elements, num_bytes);
}
MojoResult EndWriteData(uint32_t num_bytes_written) {
return MojoEndWriteData(producer_, num_bytes_written);
return MojoEndWriteData(producer_, num_bytes_written, nullptr);
}
MojoResult CloseProducer() {
@ -151,10 +156,10 @@ class DataPipeTest : public test::MojoTestBase {
TEST_F(DataPipeTest, Basic) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -191,20 +196,20 @@ TEST_F(DataPipeTest, CreateAndMaybeTransfer) {
// Default options.
{},
// Trivial element size, non-default capacity.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
1000}, // |capacity_num_bytes|.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
1000}, // |capacity_num_bytes|.
// Nontrivial element size, non-default capacity.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
4, // |element_num_bytes|.
4000}, // |capacity_num_bytes|.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
4, // |element_num_bytes|.
4000}, // |capacity_num_bytes|.
// Nontrivial element size, default capacity.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
100, // |element_num_bytes|.
0} // |capacity_num_bytes|.
{kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
100, // |element_num_bytes|.
0} // |capacity_num_bytes|.
};
for (size_t i = 0; i < arraysize(test_options); i++) {
MojoHandle producer_handle, consumer_handle;
@ -218,10 +223,10 @@ TEST_F(DataPipeTest, CreateAndMaybeTransfer) {
TEST_F(DataPipeTest, SimpleReadWrite) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -337,10 +342,10 @@ TEST_F(DataPipeTest, BasicProducerWaiting) {
// the API.
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
};
Create(&options);
MojoHandleSignalsState hss;
@ -427,10 +432,10 @@ TEST_F(DataPipeTest, BasicProducerWaiting) {
TEST_F(DataPipeTest, PeerClosedProducerWaiting) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -448,10 +453,10 @@ TEST_F(DataPipeTest, PeerClosedProducerWaiting) {
TEST_F(DataPipeTest, PeerClosedConsumerWaiting) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
2 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -469,10 +474,10 @@ TEST_F(DataPipeTest, PeerClosedConsumerWaiting) {
TEST_F(DataPipeTest, BasicConsumerWaiting) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -604,13 +609,13 @@ TEST_F(DataPipeTest, BasicConsumerWaiting) {
}
TEST_F(DataPipeTest, ConsumerNewDataReadable) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
const MojoCreateDataPipeOptions create_options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
EXPECT_EQ(MOJO_RESULT_OK, Create(&options));
EXPECT_EQ(MOJO_RESULT_OK, Create(&create_options));
int32_t elements[2] = {123, 456};
uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
@ -625,9 +630,12 @@ TEST_F(DataPipeTest, ConsumerNewDataReadable) {
// Now try to read a minimum of 6 elements.
int32_t read_elements[6];
uint32_t num_read_bytes = sizeof(read_elements);
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
MojoReadData(consumer_, read_elements, &num_read_bytes,
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
MojoReadDataOptions read_options;
read_options.struct_size = sizeof(read_options);
read_options.flags = MOJO_READ_DATA_FLAG_ALL_OR_NONE;
EXPECT_EQ(
MOJO_RESULT_OUT_OF_RANGE,
MojoReadData(consumer_, &read_options, read_elements, &num_read_bytes));
// The consumer should still appear to be readable but not with new data.
EXPECT_TRUE(GetSignalsState(consumer_).satisfied_signals &
@ -644,9 +652,8 @@ TEST_F(DataPipeTest, ConsumerNewDataReadable) {
WaitForSignals(consumer_, MOJO_HANDLE_SIGNAL_READABLE));
// Try again to read a minimum of 6 elements. Should succeed this time.
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadData(consumer_, read_elements, &num_read_bytes,
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(consumer_, &read_options,
read_elements, &num_read_bytes));
// And now the consumer is unreadable.
EXPECT_FALSE(GetSignalsState(consumer_).satisfied_signals &
@ -659,10 +666,10 @@ TEST_F(DataPipeTest, ConsumerNewDataReadable) {
// consumer waiter.
TEST_F(DataPipeTest, ConsumerWaitingTwoPhase) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -672,7 +679,7 @@ TEST_F(DataPipeTest, ConsumerWaitingTwoPhase) {
void* buffer = nullptr;
// Request room for three (but we'll only write two).
uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes, false));
ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes));
EXPECT_TRUE(buffer);
EXPECT_GE(num_bytes, static_cast<uint32_t>(3u * sizeof(elements[0])));
elements = static_cast<int32_t*>(buffer);
@ -736,10 +743,10 @@ TEST_F(DataPipeTest, ConsumerWaitingTwoPhase) {
// Tests that data pipes aren't writable/readable during two-phase writes/reads.
TEST_F(DataPipeTest, BasicTwoPhaseWaiting) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -856,10 +863,10 @@ void Seq(int32_t start, size_t count, int32_t* out) {
TEST_F(DataPipeTest, AllOrNone) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
10 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1026,10 +1033,10 @@ TEST_F(DataPipeTest, WrapAround) {
test_data[i] = static_cast<unsigned char>(i);
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
100u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
100u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -1060,8 +1067,7 @@ TEST_F(DataPipeTest, WrapAround) {
// checks an implementation detail; this behavior is not guaranteed.)
void* write_buffer_ptr = nullptr;
num_bytes = 0u;
ASSERT_EQ(MOJO_RESULT_OK,
BeginWriteData(&write_buffer_ptr, &num_bytes, false));
ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_buffer_ptr, &num_bytes));
EXPECT_TRUE(write_buffer_ptr);
ASSERT_EQ(80u, num_bytes);
ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(0));
@ -1114,10 +1120,10 @@ TEST_F(DataPipeTest, WriteCloseProducerRead) {
const uint32_t kTestDataSize = static_cast<uint32_t>(sizeof(kTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -1134,8 +1140,7 @@ TEST_F(DataPipeTest, WriteCloseProducerRead) {
// Start two-phase write.
void* write_buffer_ptr = nullptr;
num_bytes = 0u;
ASSERT_EQ(MOJO_RESULT_OK,
BeginWriteData(&write_buffer_ptr, &num_bytes, false));
ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_buffer_ptr, &num_bytes));
EXPECT_TRUE(write_buffer_ptr);
EXPECT_GT(num_bytes, 0u);
@ -1179,10 +1184,10 @@ TEST_F(DataPipeTest, TwoPhaseWriteReadCloseConsumer) {
const uint32_t kTestDataSize = static_cast<uint32_t>(sizeof(kTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1252,10 +1257,10 @@ TEST_F(DataPipeTest, TwoPhaseWriteCloseBoth) {
const uint32_t kTestDataSize = 15u;
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -1274,10 +1279,10 @@ TEST_F(DataPipeTest, WriteCloseProducerReadNoData) {
const uint32_t kTestDataSize = static_cast<uint32_t>(sizeof(kTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1338,10 +1343,10 @@ TEST_F(DataPipeTest, TwoPhaseReadMemoryStable) {
const uint32_t kTestDataSize = static_cast<uint32_t>(sizeof(kTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1396,10 +1401,10 @@ TEST_F(DataPipeTest, TwoPhaseReadMemoryStable) {
// arguments.
TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
10 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1522,10 +1527,10 @@ TEST_F(DataPipeTest, SendProducer) {
const uint32_t kTestDataSize = static_cast<uint32_t>(sizeof(kTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1u, // |element_num_bytes|.
1000u // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
@ -1598,10 +1603,10 @@ TEST_F(DataPipeTest, SendProducer) {
// peer.
TEST_F(DataPipeTest, ConsumerWithClosedProducerSent) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -1659,8 +1664,8 @@ bool WriteAllData(MojoHandle producer,
for (size_t i = 0; i < kMaxPoll; i++) {
// Write as much data as we can.
uint32_t write_bytes = num_bytes;
MojoResult result = MojoWriteData(producer, elements, &write_bytes,
MOJO_WRITE_DATA_FLAG_NONE);
MojoResult result =
MojoWriteData(producer, elements, &write_bytes, nullptr);
if (result == MOJO_RESULT_OK) {
num_bytes -= write_bytes;
elements = static_cast<const uint8_t*>(elements) + write_bytes;
@ -1690,8 +1695,7 @@ bool ReadAllData(MojoHandle consumer,
for (size_t i = 0; i < kMaxPoll; i++) {
// Read as much data as we can.
uint32_t read_bytes = num_bytes;
MojoResult result =
MojoReadData(consumer, elements, &read_bytes, MOJO_READ_DATA_FLAG_NONE);
MojoResult result = MojoReadData(consumer, nullptr, elements, &read_bytes);
if (result == MOJO_RESULT_OK) {
num_bytes -= read_bytes;
elements = static_cast<uint8_t*>(elements) + read_bytes;
@ -1699,8 +1703,10 @@ bool ReadAllData(MojoHandle consumer,
if (expect_empty) {
// Expect no more data.
test::Sleep(test::TinyDeadline());
MojoReadData(consumer, nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_QUERY);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_QUERY;
MojoReadData(consumer, &options, nullptr, &num_bytes);
EXPECT_EQ(0u, num_bytes);
}
return true;
@ -1727,10 +1733,10 @@ TEST_F(DataPipeTest, Multiprocess) {
const uint32_t kTestDataSize =
static_cast<uint32_t>(sizeof(kMultiprocessTestData));
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
kMultiprocessCapacity // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
kMultiprocessCapacity // |capacity_num_bytes|.
};
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
@ -1848,8 +1854,8 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(WriteAndCloseProducer, DataPipeTest, h) {
// Write some data to the producer and close it.
uint32_t num_bytes = static_cast<uint32_t>(message.size());
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(p, message.data(), &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteData(p, message.data(), &num_bytes, nullptr));
EXPECT_EQ(num_bytes, static_cast<uint32_t>(message.size()));
// Close the producer before quitting.
@ -1869,8 +1875,7 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadAndCloseConsumer, DataPipeTest, h) {
// Drain the consumer and expect to find the given message.
uint32_t num_bytes = static_cast<uint32_t>(expected_message.size());
std::vector<char> bytes(expected_message.size());
EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(c, bytes.data(), &num_bytes,
MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(c, nullptr, bytes.data(), &num_bytes));
EXPECT_EQ(num_bytes, static_cast<uint32_t>(bytes.size()));
std::string message(bytes.data(), bytes.size());
@ -1902,10 +1907,10 @@ TEST_F(DataPipeTest, SendConsumerAndCloseProducer) {
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndWrite, DataPipeTest, h) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
kMultiprocessCapacity // |capacity_num_bytes|.
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_FLAG_NONE, // |flags|.
1, // |element_num_bytes|.
kMultiprocessCapacity // |capacity_num_bytes|.
};
MojoHandle p, c;
@ -1916,8 +1921,8 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndWrite, DataPipeTest, h) {
// Write some data to the producer and close it.
uint32_t num_bytes = static_cast<uint32_t>(kMessage.size());
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(p, kMessage.data(), &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteData(p, kMessage.data(), &num_bytes, nullptr));
EXPECT_EQ(num_bytes, static_cast<uint32_t>(kMessage.size()));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(p));
@ -1936,8 +1941,8 @@ TEST_F(DataPipeTest, CreateInChild) {
// Drain the consumer and expect to find the given message.
uint32_t num_bytes = static_cast<uint32_t>(expected_message.size());
std::vector<char> bytes(expected_message.size());
EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(c, bytes.data(), &num_bytes,
MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadData(c, nullptr, bytes.data(), &num_bytes));
EXPECT_EQ(num_bytes, static_cast<uint32_t>(bytes.size()));
std::string message(bytes.data(), bytes.size());
@ -1998,8 +2003,7 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(DataPipeStatusChangeInTransitClient,
MojoResult result;
do {
uint32_t num_bytes = 0;
result = MojoWriteData(producers[2], nullptr, &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE);
result = MojoWriteData(producers[2], nullptr, &num_bytes, nullptr);
} while (result == MOJO_RESULT_OK);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);
@ -2007,8 +2011,7 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(DataPipeStatusChangeInTransitClient,
do {
char byte;
uint32_t num_bytes = 1;
result =
MojoReadData(consumers[2], &byte, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
result = MojoReadData(consumers[2], nullptr, &byte, &num_bytes);
} while (result == MOJO_RESULT_SHOULD_WAIT);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);

@ -42,8 +42,7 @@ MojoResult Dispatcher::Arm(uint32_t* num_ready_contexts,
}
MojoResult Dispatcher::WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message,
MojoWriteMessageFlags flags) {
std::unique_ptr<ports::UserMessageEvent> message) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
@ -61,7 +60,6 @@ MojoResult Dispatcher::DuplicateBufferHandle(
MojoResult Dispatcher::MapBuffer(
uint64_t offset,
uint64_t num_bytes,
MojoMapBufferFlags flags,
std::unique_ptr<PlatformSharedMemoryMapping>* mapping) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
@ -70,15 +68,14 @@ MojoResult Dispatcher::GetBufferInfo(MojoSharedBufferInfo* info) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) {
MojoResult Dispatcher::ReadData(const MojoReadDataOptions& options,
void* elements,
uint32_t* num_bytes) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) {
uint32_t* buffer_num_bytes) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
@ -88,13 +85,12 @@ MojoResult Dispatcher::EndReadData(uint32_t num_bytes_read) {
MojoResult Dispatcher::WriteData(const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) {
const MojoWriteDataOptions& options) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) {
uint32_t* buffer_num_bytes) {
return MOJO_RESULT_INVALID_ARGUMENT;
}

@ -85,8 +85,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher
///////////// Message pipe API /////////////
virtual MojoResult WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message,
MojoWriteMessageFlags flags);
std::unique_ptr<ports::UserMessageEvent> message);
virtual MojoResult ReadMessage(
std::unique_ptr<ports::UserMessageEvent>* message);
@ -103,20 +102,18 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher
virtual MojoResult MapBuffer(
uint64_t offset,
uint64_t num_bytes,
MojoMapBufferFlags flags,
std::unique_ptr<PlatformSharedMemoryMapping>* mapping);
virtual MojoResult GetBufferInfo(MojoSharedBufferInfo* info);
///////////// Data pipe consumer API /////////////
virtual MojoResult ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags);
virtual MojoResult ReadData(const MojoReadDataOptions& options,
void* elements,
uint32_t* num_bytes);
virtual MojoResult BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags);
uint32_t* buffer_num_bytes);
virtual MojoResult EndReadData(uint32_t num_bytes_read);
@ -124,11 +121,9 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher
virtual MojoResult WriteData(const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags);
const MojoWriteDataOptions& options);
virtual MojoResult BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags);
virtual MojoResult BeginWriteData(void** buffer, uint32_t* buffer_num_bytes);
virtual MojoResult EndWriteData(uint32_t num_bytes_written);

@ -136,8 +136,7 @@ MojoResult MessagePipeDispatcher::Close() {
}
MojoResult MessagePipeDispatcher::WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message,
MojoWriteMessageFlags flags) {
std::unique_ptr<ports::UserMessageEvent> message) {
if (port_closed_ || in_transit_)
return MOJO_RESULT_INVALID_ARGUMENT;

@ -47,8 +47,8 @@ class MessagePipeDispatcher : public Dispatcher {
// Dispatcher:
Type GetType() const override;
MojoResult Close() override;
MojoResult WriteMessage(std::unique_ptr<ports::UserMessageEvent> message,
MojoWriteMessageFlags flags) override;
MojoResult WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message) override;
MojoResult ReadMessage(
std::unique_ptr<ports::UserMessageEvent>* message) override;
HandleSignalsState GetHandleSignalsState() const override;

@ -54,8 +54,8 @@ class MessagePipeTest : public test::MojoTestBase {
uint32_t* num_bytes,
bool may_discard = false) {
MojoMessageHandle message_handle;
MojoResult rv = MojoReadMessage(message_pipe_handle, &message_handle,
MOJO_READ_MESSAGE_FLAG_NONE);
MojoResult rv =
MojoReadMessage(message_pipe_handle, nullptr, &message_handle);
if (rv != MOJO_RESULT_OK)
return rv;
@ -376,7 +376,7 @@ TEST_F(MessagePipeTest, DISABLED_DataPipeProducerHandlePingPong) {
TEST_F(MessagePipeTest, SharedBufferHandlePingPong) {
MojoHandle buffers[kPingPongHandlesPerIteration];
for (size_t i = 0; i < kPingPongHandlesPerIteration; ++i)
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateSharedBuffer(nullptr, 1, &buffers[i]));
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateSharedBuffer(1, nullptr, &buffers[i]));
RunTestClient("HandlePingPong", [&](MojoHandle h) {
for (size_t i = 0; i < kPingPongIterations; i++) {
@ -398,7 +398,7 @@ TEST_F(FuseMessagePipeTest, Basic) {
CreateMessagePipe(&a, &b);
CreateMessagePipe(&c, &d);
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c, nullptr));
// Handles b and c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(b));
@ -429,7 +429,7 @@ TEST_F(FuseMessagePipeTest, FuseAfterPeerWrite) {
WriteMessage(a, kTestMessage1);
WriteMessage(d, kTestMessage2);
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c, nullptr));
// Handles b and c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(b));
@ -450,7 +450,8 @@ TEST_F(FuseMessagePipeTest, NoFuseAfterWrite) {
CreateMessagePipe(&c, &d);
WriteMessage(b, "shouldn't have done that!");
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
MojoFuseMessagePipes(b, c, nullptr));
// Handles b and c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(b));
@ -466,7 +467,8 @@ TEST_F(FuseMessagePipeTest, NoFuseSelf) {
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, MojoFuseMessagePipes(a, b));
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
MojoFuseMessagePipes(a, b, nullptr));
// Handles a and b should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(a));
@ -481,7 +483,7 @@ TEST_F(FuseMessagePipeTest, FuseInvalidArguments) {
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b));
// Can't fuse an invalid handle.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoFuseMessagePipes(b, c, nullptr));
// Handle c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(c));
@ -490,7 +492,7 @@ TEST_F(FuseMessagePipeTest, FuseInvalidArguments) {
MojoHandle e, f;
CreateDataPipe(&e, &f, 16);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoFuseMessagePipes(e, d));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoFuseMessagePipes(e, d, nullptr));
// Handles d and e should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(d));
@ -508,7 +510,7 @@ TEST_F(FuseMessagePipeTest, FuseAfterPeerClosure) {
CreateMessagePipe(&c, &d);
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c, nullptr));
// Handles b and c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(b));
@ -530,7 +532,7 @@ TEST_F(FuseMessagePipeTest, FuseAfterPeerWriteAndClosure) {
WriteMessage(a, kTestMessage);
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(b, c, nullptr));
// Handles b and c should be closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(b));

@ -193,15 +193,14 @@ TEST_F(MessageTest, SendLocalMessageWithContext) {
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(
MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)), nullptr));
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_READABLE));
MojoMessageHandle read_message_handle;
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, &read_message_handle,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &read_message_handle));
message = TestMessageBase::UnwrapMessageHandle<NeverSerializedMessage>(
&read_message_handle);
EXPECT_EQ(original_message, message.get());
@ -240,7 +239,7 @@ TEST_F(MessageTest, SerializeSimpleMessageNoHandlesWithContext) {
RunTestClient("ReceiveMessageNoHandles", [&](MojoHandle h) {
auto message = std::make_unique<SimpleMessage>(kTestMessageWithContext1);
MojoWriteMessage(h, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE);
nullptr);
});
}
@ -264,7 +263,7 @@ TEST_F(MessageTest, SerializeDynamicallySizedMessage) {
memcpy(buffer, kTestMessageWithContext1,
sizeof(kTestMessageWithContext1) - 1);
MojoWriteMessage(h, message, MOJO_WRITE_MESSAGE_FLAG_NONE);
MojoWriteMessage(h, message, nullptr);
});
}
@ -282,7 +281,7 @@ TEST_F(MessageTest, SerializeSimpleMessageOneHandleWithContext) {
mojo::MessagePipe pipe;
message->AddMessagePipe(std::move(pipe.handle0));
MojoWriteMessage(h, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE);
nullptr);
EXPECT_EQ(kTestMessageWithContext2,
MojoTestBase::ReadMessage(pipe.handle1.get().value()));
});
@ -308,7 +307,7 @@ TEST_F(MessageTest, SerializeSimpleMessageWithHandlesWithContext) {
message->AddMessagePipe(std::move(pipes[2].handle0));
message->AddMessagePipe(std::move(pipes[3].handle0));
MojoWriteMessage(h, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE);
nullptr);
EXPECT_EQ(kTestMessageWithContext1,
MojoTestBase::ReadMessage(pipes[0].handle1.get().value()));
EXPECT_EQ(kTestMessageWithContext2,
@ -337,15 +336,14 @@ TEST_F(MessageTest, SendLocalSimpleMessageWithHandlesWithContext) {
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(
MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)), nullptr));
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_READABLE));
MojoMessageHandle read_message_handle;
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, &read_message_handle,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &read_message_handle));
message =
TestMessageBase::UnwrapMessageHandle<SimpleMessage>(&read_message_handle);
EXPECT_EQ(original_message, message.get());
@ -373,10 +371,10 @@ TEST_F(MessageTest, DropUnreadLocalMessageWithContext) {
message->AddMessagePipe(std::move(pipe.handle0));
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(
MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)), nullptr));
MojoClose(a);
MojoClose(b);
@ -441,15 +439,14 @@ TEST_F(MessageTest, ReadMessageWithContextAsSerializedMessage) {
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)),
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(
MOJO_RESULT_OK,
MojoWriteMessage(
a, TestMessageBase::MakeMessageHandle(std::move(message)), nullptr));
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_READABLE));
MojoMessageHandle message_handle;
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(b, &message_handle, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &message_handle));
EXPECT_FALSE(message_was_destroyed);
// Not a serialized message, so we can't get serialized contents.
@ -475,8 +472,7 @@ TEST_F(MessageTest, ReadSerializedMessageAsMessageWithContext) {
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_READABLE));
MojoMessageHandle message_handle;
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(b, &message_handle, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &message_handle));
uintptr_t context;
EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
MojoGetMessageContext(message_handle, nullptr, &context));
@ -569,13 +565,11 @@ TEST_F(MessageTest, DoubleSerialize) {
// message object from a pipe.
MessagePipe pipe;
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(pipe.handle0->value(), message_handle,
MOJO_WRITE_MESSAGE_FLAG_NONE));
MojoWriteMessage(pipe.handle0->value(), message_handle, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
WaitForSignals(pipe.handle1->value(), MOJO_HANDLE_SIGNAL_READABLE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(pipe.handle1->value(), &message_handle,
MOJO_READ_MESSAGE_FLAG_NONE));
MojoReadMessage(pipe.handle1->value(), nullptr, &message_handle));
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
MojoSerializeMessage(message_handle, nullptr));
@ -854,8 +848,7 @@ TEST_F(MessageTest, ExtendPayloadWithHandlesAttached) {
// Send the message out of process to exercise the regression path where
// internally cached, stale payload pointers may be dereferenced and written
// into.
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(h, message, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(h, message, nullptr));
});
}
@ -904,8 +897,7 @@ TEST_F(MessageTest, ExtendPayloadWithHandlesAttachedViaExtension) {
// Send the message out of process to exercise the regression path where
// internally cached, stale payload pointers may be dereferenced and written
// into.
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(h, message, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(h, message, nullptr));
});
}

@ -284,9 +284,7 @@ DEFINE_TEST_CLIENT_WITH_PIPE(CheckSharedBuffer,
// Make a mapping.
void* buffer;
CHECK_EQ(MojoMapBuffer(handles[0], 0, 100, &buffer,
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE),
MOJO_RESULT_OK);
CHECK_EQ(MojoMapBuffer(handles[0], 0, 100, nullptr, &buffer), MOJO_RESULT_OK);
// Write some stuff to the shared buffer.
static const char kHello[] = "hello";
@ -333,11 +331,11 @@ TEST_F(MultiprocessMessagePipeTest, SharedBufferPassing) {
// Make a shared buffer.
MojoCreateSharedBufferOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_SHARED_BUFFER_FLAG_NONE;
MojoHandle shared_buffer;
ASSERT_EQ(MOJO_RESULT_OK,
MojoCreateSharedBuffer(&options, 100, &shared_buffer));
MojoCreateSharedBuffer(100, &options, &shared_buffer));
MojoSharedBufferInfo buffer_info;
buffer_info.struct_size = sizeof(buffer_info);
ASSERT_EQ(MOJO_RESULT_OK,
@ -381,8 +379,7 @@ TEST_F(MultiprocessMessagePipeTest, SharedBufferPassing) {
// buffer.
static const char kHello[] = "hello";
void* buffer;
CHECK_EQ(MojoMapBuffer(shared_buffer, 0, 100, &buffer,
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE),
CHECK_EQ(MojoMapBuffer(shared_buffer, 0, 100, nullptr, &buffer),
MOJO_RESULT_OK);
ASSERT_EQ(0, memcmp(buffer, kHello, sizeof(kHello)));
@ -561,7 +558,7 @@ TEST_P(MultiprocessMessagePipeTestWithPeerSupport, MessagePipePassing) {
RunTestClient("CheckMessagePipe", [&](MojoHandle h) {
MojoCreateSharedBufferOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_SHARED_BUFFER_FLAG_NONE;
MojoHandle mp1, mp2;
ASSERT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp1, &mp2));
@ -679,7 +676,7 @@ TEST_F(MultiprocessMessagePipeTest, DataPipeConsumer) {
RunTestClient("DataPipeConsumer", [&](MojoHandle h) {
MojoCreateSharedBufferOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_SHARED_BUFFER_FLAG_NONE;
MojoHandle mp1, mp2;
ASSERT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp1));
@ -1374,20 +1371,18 @@ TEST_F(MultiprocessMessagePipeTest, NotifyBadMessage) {
// Read a message from the pipe we sent to child1 and flag it as bad.
ASSERT_EQ(MOJO_RESULT_OK, WaitForSignals(a, MOJO_HANDLE_SIGNAL_READABLE));
MojoMessageHandle message;
ASSERT_EQ(MOJO_RESULT_OK,
::MojoReadMessage(a, &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, ::MojoReadMessage(a, nullptr, &message));
EXPECT_EQ(MOJO_RESULT_OK,
MojoNotifyBadMessage(message, kFirstErrorMessage.data(),
kFirstErrorMessage.size()));
kFirstErrorMessage.size(), nullptr));
EXPECT_EQ(MOJO_RESULT_OK, MojoDestroyMessage(message));
// Read a message from the pipe we sent to child2 and flag it as bad.
ASSERT_EQ(MOJO_RESULT_OK, WaitForSignals(c, MOJO_HANDLE_SIGNAL_READABLE));
ASSERT_EQ(MOJO_RESULT_OK,
::MojoReadMessage(c, &message, MOJO_READ_MESSAGE_FLAG_NONE));
ASSERT_EQ(MOJO_RESULT_OK, ::MojoReadMessage(c, nullptr, &message));
EXPECT_EQ(MOJO_RESULT_OK,
MojoNotifyBadMessage(message, kSecondErrorMessage.data(),
kSecondErrorMessage.size()));
kSecondErrorMessage.size(), nullptr));
EXPECT_EQ(MOJO_RESULT_OK, MojoDestroyMessage(message));
WriteMessage(child2, "bye");

@ -48,14 +48,14 @@ static_assert(sizeof(SerializedState) % 8 == 0,
const MojoCreateSharedBufferOptions
SharedBufferDispatcher::kDefaultCreateOptions = {
static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)),
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE};
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE};
// static
MojoResult SharedBufferDispatcher::ValidateCreateOptions(
const MojoCreateSharedBufferOptions* in_options,
MojoCreateSharedBufferOptions* out_options) {
const MojoCreateSharedBufferOptionsFlags kKnownFlags =
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
const MojoCreateSharedBufferFlags kKnownFlags =
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE;
*out_options = kDefaultCreateOptions;
if (!in_options)
@ -200,8 +200,7 @@ MojoResult SharedBufferDispatcher::DuplicateBufferHandle(
if (in_transit_)
return MOJO_RESULT_INVALID_ARGUMENT;
if ((validated_options.flags &
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY)) {
if ((validated_options.flags & MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY)) {
// If a read-only duplicate is requested and this handle is not already
// read-only, we need to make it read-only before duplicating. If it's
// unsafe it can't be made read-only, and we must fail instead.
@ -249,7 +248,6 @@ MojoResult SharedBufferDispatcher::DuplicateBufferHandle(
MojoResult SharedBufferDispatcher::MapBuffer(
uint64_t offset,
uint64_t num_bytes,
MojoMapBufferFlags flags,
std::unique_ptr<PlatformSharedMemoryMapping>* mapping) {
if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max()))
return MOJO_RESULT_INVALID_ARGUMENT;
@ -279,6 +277,7 @@ MojoResult SharedBufferDispatcher::GetBufferInfo(MojoSharedBufferInfo* info) {
return MOJO_RESULT_INVALID_ARGUMENT;
base::AutoLock lock(lock_);
info->struct_size = sizeof(*info);
info->size = region_.GetSize();
return MOJO_RESULT_OK;
}
@ -354,11 +353,11 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::CreateInternal(
MojoResult SharedBufferDispatcher::ValidateDuplicateOptions(
const MojoDuplicateBufferHandleOptions* in_options,
MojoDuplicateBufferHandleOptions* out_options) {
const MojoDuplicateBufferHandleOptionsFlags kKnownFlags =
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
const MojoDuplicateBufferHandleFlags kKnownFlags =
MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY;
static const MojoDuplicateBufferHandleOptions kDefaultOptions = {
static_cast<uint32_t>(sizeof(MojoDuplicateBufferHandleOptions)),
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE};
*out_options = kDefaultOptions;
if (!in_options)

@ -81,7 +81,6 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final : public Dispatcher {
MojoResult MapBuffer(
uint64_t offset,
uint64_t num_bytes,
MojoMapBufferFlags flags,
std::unique_ptr<PlatformSharedMemoryMapping>* mapping) override;
MojoResult GetBufferInfo(MojoSharedBufferInfo* info) override;
void StartSerialize(uint32_t* num_bytes,

@ -64,10 +64,10 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsValid) {
}
// Different flags.
MojoCreateSharedBufferOptionsFlags flags_values[] = {
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE};
MojoCreateSharedBufferFlags flags_values[] = {
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE};
for (size_t i = 0; i < arraysize(flags_values); i++) {
const MojoCreateSharedBufferOptionsFlags flags = flags_values[i];
const MojoCreateSharedBufferFlags flags = flags_values[i];
// Different capacities (size 1).
for (uint32_t capacity = 1; capacity <= 100 * 1000 * 1000; capacity *= 10) {
@ -90,8 +90,8 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsInvalid) {
// Invalid |struct_size|.
{
MojoCreateSharedBufferOptions options = {
1, // |struct_size|.
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE // |flags|.
1, // |struct_size|.
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE // |flags|.
};
MojoCreateSharedBufferOptions unused;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
@ -122,8 +122,7 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
// Make a couple of mappings.
std::unique_ptr<PlatformSharedMemoryMapping> mapping1;
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(0, 100, &mapping1));
ASSERT_TRUE(mapping1);
ASSERT_TRUE(mapping1->GetBase());
EXPECT_EQ(100u, mapping1->GetLength());
@ -131,8 +130,7 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
static_cast<char*>(mapping1->GetBase())[50] = 'x';
std::unique_ptr<PlatformSharedMemoryMapping> mapping2;
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
50, 50, MOJO_MAP_BUFFER_FLAG_NONE, &mapping2));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(50, 50, &mapping2));
ASSERT_TRUE(mapping2);
ASSERT_TRUE(mapping2->GetBase());
EXPECT_EQ(50u, mapping2->GetLength());
@ -161,8 +159,7 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBufferFromPlatformBuffer) {
// Make a couple of mappings.
std::unique_ptr<PlatformSharedMemoryMapping> mapping1;
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(0, 100, &mapping1));
ASSERT_TRUE(mapping1);
ASSERT_TRUE(mapping1->GetBase());
EXPECT_EQ(100u, mapping1->GetLength());
@ -170,8 +167,7 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBufferFromPlatformBuffer) {
static_cast<char*>(mapping1->GetBase())[50] = 'x';
std::unique_ptr<PlatformSharedMemoryMapping> mapping2;
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
50, 50, MOJO_MAP_BUFFER_FLAG_NONE, &mapping2));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(50, 50, &mapping2));
ASSERT_TRUE(mapping2);
ASSERT_TRUE(mapping2->GetBase());
EXPECT_EQ(50u, mapping2->GetLength());
@ -193,8 +189,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
// Map and write something.
std::unique_ptr<PlatformSharedMemoryMapping> mapping;
EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer(
0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer(0, 100, &mapping));
static_cast<char*>(mapping->GetBase())[0] = 'x';
mapping.reset();
@ -208,8 +203,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
// Map |dispatcher2| and read something.
EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer(
0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer(0, 100, &mapping));
EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
@ -228,7 +222,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
MojoDuplicateBufferHandleOptions kReadOnlyOptions = {
sizeof(MojoCreateSharedBufferOptions),
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY};
MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY};
// NOTE: We forbid handles from being duplicated read-only after they've been
// duplicated non-read-only; conversely we also forbid handles from being
@ -243,7 +237,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
{
std::unique_ptr<PlatformSharedMemoryMapping> mapping;
EXPECT_EQ(MOJO_RESULT_OK,
writable_duped_dispatcher1->MapBuffer(0, 100, 0, &mapping));
writable_duped_dispatcher1->MapBuffer(0, 100, &mapping));
}
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
dispatcher1->DuplicateBufferHandle(&kReadOnlyOptions,
@ -261,7 +255,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
{
std::unique_ptr<PlatformSharedMemoryMapping> mapping;
EXPECT_EQ(MOJO_RESULT_OK,
read_only_duped_dispatcher2->MapBuffer(0, 100, 0, &mapping));
read_only_duped_dispatcher2->MapBuffer(0, 100, &mapping));
}
EXPECT_EQ(
MOJO_RESULT_FAILED_PRECONDITION,
@ -283,7 +277,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) {
// Invalid |struct_size|.
{
MojoDuplicateBufferHandleOptions options = {
1u, MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
1u, MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE};
scoped_refptr<Dispatcher> dispatcher2;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dispatcher1->DuplicateBufferHandle(&options, &dispatcher2));
@ -331,17 +325,15 @@ TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) {
std::unique_ptr<PlatformSharedMemoryMapping> mapping;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dispatcher->MapBuffer(0, info.size + 1, MOJO_MAP_BUFFER_FLAG_NONE,
&mapping));
EXPECT_FALSE(mapping);
EXPECT_EQ(
MOJO_RESULT_INVALID_ARGUMENT,
dispatcher->MapBuffer(1, info.size, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
dispatcher->MapBuffer(0, info.size + 1, &mapping));
EXPECT_FALSE(mapping);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
dispatcher->MapBuffer(1, info.size, &mapping));
EXPECT_FALSE(mapping);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dispatcher->MapBuffer(0, 0, &mapping));
EXPECT_FALSE(mapping);
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());

@ -159,7 +159,7 @@ TEST_F(SignalsTest, RemotePeers) {
// And so should |c| after we fuse |d| to |a|.
MojoHandle c, d;
CreateMessagePipe(&c, &d);
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(d, a));
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(d, a, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
WaitForSignals(c, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));

@ -448,9 +448,11 @@ TEST_F(WatcherTest, WatchDataPipeConsumerNewDataReadable) {
// NEW_DATA_READABLE signal.
char large_buffer[512];
uint32_t large_read_size = 512;
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_ALL_OR_NONE;
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
MojoReadData(consumer, large_buffer, &large_read_size,
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
MojoReadData(consumer, &options, large_buffer, &large_read_size));
// Attempt to arm again. Should succeed.
EXPECT_EQ(MOJO_RESULT_OK,
@ -1746,10 +1748,8 @@ void ReadAllMessages(const MojoTrapEvent* event) {
if (event->result == MOJO_RESULT_OK) {
MojoHandle handle = static_cast<MojoHandle>(event->trigger_context);
MojoMessageHandle message;
while (MojoReadMessage(handle, &message, MOJO_READ_MESSAGE_FLAG_NONE) ==
MOJO_RESULT_OK) {
while (MojoReadMessage(handle, nullptr, &message) == MOJO_RESULT_OK)
MojoDestroyMessage(message);
}
}
constexpr size_t kNumRandomThingsToDoOnNotify = 5;
@ -1780,7 +1780,7 @@ void DoRandomThing(MojoHandle* watchers,
ASSERT_EQ(MOJO_RESULT_OK,
MojoSetMessageContext(message, 1, nullptr, nullptr, nullptr));
MojoWriteMessage(RandomHandle(watched_handles, num_watched_handles),
message, MOJO_WRITE_MESSAGE_FLAG_NONE);
message, nullptr);
break;
}
case 5:

@ -206,7 +206,7 @@ void MojoTestBase::VerifyEcho(MojoHandle mp, const std::string& message) {
// static
MojoHandle MojoTestBase::CreateBuffer(uint64_t size) {
MojoHandle h;
EXPECT_EQ(MojoCreateSharedBuffer(nullptr, size, &h), MOJO_RESULT_OK);
EXPECT_EQ(MojoCreateSharedBuffer(size, nullptr, &h), MOJO_RESULT_OK);
return h;
}
@ -215,9 +215,9 @@ MojoHandle MojoTestBase::DuplicateBuffer(MojoHandle h, bool read_only) {
MojoHandle new_handle;
MojoDuplicateBufferHandleOptions options = {
sizeof(MojoDuplicateBufferHandleOptions),
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE};
if (read_only)
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY;
EXPECT_EQ(MOJO_RESULT_OK,
MojoDuplicateBufferHandle(h, &options, &new_handle));
return new_handle;
@ -228,9 +228,8 @@ void MojoTestBase::WriteToBuffer(MojoHandle h,
size_t offset,
const base::StringPiece& s) {
char* data;
EXPECT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(h, offset, s.size(), reinterpret_cast<void**>(&data),
MOJO_MAP_BUFFER_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoMapBuffer(h, offset, s.size(), nullptr,
reinterpret_cast<void**>(&data)));
memcpy(data, s.data(), s.size());
EXPECT_EQ(MOJO_RESULT_OK, MojoUnmapBuffer(static_cast<void*>(data)));
}
@ -240,9 +239,8 @@ void MojoTestBase::ExpectBufferContents(MojoHandle h,
size_t offset,
const base::StringPiece& s) {
char* data;
EXPECT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(h, offset, s.size(), reinterpret_cast<void**>(&data),
MOJO_MAP_BUFFER_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoMapBuffer(h, offset, s.size(), nullptr,
reinterpret_cast<void**>(&data)));
EXPECT_EQ(s, base::StringPiece(data, s.size()));
EXPECT_EQ(MOJO_RESULT_OK, MojoUnmapBuffer(static_cast<void*>(data)));
}
@ -253,7 +251,7 @@ void MojoTestBase::CreateDataPipe(MojoHandle* p0,
size_t capacity) {
MojoCreateDataPipeOptions options;
options.struct_size = static_cast<uint32_t>(sizeof(options));
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = static_cast<uint32_t>(capacity);
@ -267,8 +265,10 @@ void MojoTestBase::WriteData(MojoHandle producer, const std::string& data) {
CHECK_EQ(WaitForSignals(producer, MOJO_HANDLE_SIGNAL_WRITABLE),
MOJO_RESULT_OK);
uint32_t num_bytes = static_cast<uint32_t>(data.size());
CHECK_EQ(MojoWriteData(producer, data.data(), &num_bytes,
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
MojoWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_WRITE_DATA_FLAG_ALL_OR_NONE;
CHECK_EQ(MojoWriteData(producer, data.data(), &num_bytes, &options),
MOJO_RESULT_OK);
CHECK_EQ(num_bytes, static_cast<uint32_t>(data.size()));
}
@ -279,8 +279,10 @@ std::string MojoTestBase::ReadData(MojoHandle consumer, size_t size) {
MOJO_RESULT_OK);
std::vector<char> buffer(size);
uint32_t num_bytes = static_cast<uint32_t>(size);
CHECK_EQ(MojoReadData(consumer, buffer.data(), &num_bytes,
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_ALL_OR_NONE;
CHECK_EQ(MojoReadData(consumer, &options, buffer.data(), &num_bytes),
MOJO_RESULT_OK);
CHECK_EQ(num_bytes, static_cast<uint32_t>(size));

@ -209,7 +209,7 @@ no need to subsequently call `MojoDestroyMessage` on that message.
### Writing Messages
``` c
result = MojoWriteMessage(a, message, MOJO_WRITE_MESSAGE_FLAG_NONE);
result = MojoWriteMessage(a, message, nullptr);
```
`MojoWriteMessage` is a *non-blocking* call: it always returns
@ -237,7 +237,7 @@ We can read a new message object from a pipe:
``` c
MojoMessageHandle message;
MojoResult result = MojoReadMessage(b, &message, MOJO_READ_MESSAGE_FLAG_NONE);
MojoResult result = MojoReadMessage(b, nullptr, &message);
```
and extract its data:
@ -257,7 +257,7 @@ If we try were to try reading again now that there are no messages on `b`:
``` c
MojoMessageHandle message;
MojoResult result = MojoReadMessage(b, &message, MOJO_READ_MESSAGE_FLAG_NONE);
MojoResult result = MojoReadMessage(b, nullptr, &message);
```
We'll get a `result` of `MOJO_RESULT_SHOULD_WAIT`, indicating that the pipe is
@ -302,12 +302,12 @@ options.struct_size = sizeof(options);
options.flags = MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE;
MojoAppendMessageData(message, &options, 2, &c, 1, &buffer, &buffer_size);
memcpy(buffer, "hi", 2);
MojoWriteMessage(a, message, MOJO_WRITE_MESSAGE_FLAG_NONE);
MojoWriteMessage(a, message, nullptr);
// Some time later...
MojoHandle e;
uint32_t num_handles = 1;
MojoReadMessage(b, &message, MOJO_READ_MESSAGE_FLAG_NONE);
MojoReadMessage(b, nullptr, &message);
MojoGetMessageData(message, nullptr, &buffer, &buffer_size, &e, &num_handles);
```
@ -378,7 +378,7 @@ also less efficient due to extra copying.
``` c
uint32_t num_bytes = 12;
MojoResult result = MojoWriteData(producer, "datadatadata", &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE);
nullptr);
```
The above snippet will attempt to write 12 bytes into the data pipe, which
@ -393,8 +393,7 @@ Reading from the consumer is a similar operation.
``` c
char buffer[64];
uint32_t num_bytes = 64;
MojoResult result = MojoReadData(consumer, buffer, &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
MojoResult result = MojoReadData(consumer, nullptr, buffer, &num_bytes);
```
This will attempt to read up to 64 bytes, returning the actual number of bytes
@ -417,8 +416,7 @@ temporarily lock a portion of the data pipe's storage for direct memory access.
``` c
void* buffer;
uint32_t num_bytes = 1024;
MojoResult result = MojoBeginWriteData(producer, &buffer, &num_bytes,
MOJO_WRITE_DATA_FLAG_NONE);
MojoResult result = MojoBeginWriteData(producer, nullptr, &buffer, &num_bytes);
```
This requests write access to a region of up to 1024 bytes of the data pipe's
@ -430,7 +428,7 @@ ASAP, indicating the number of bytes actually written:
``` c
memcpy(buffer, "hello", 6);
MojoResult result = MojoEndWriteData(producer, 6);
MojoResult result = MojoEndWriteData(producer, 6, nullptr);
```
Two-phase reads look similar:
@ -438,19 +436,18 @@ Two-phase reads look similar:
``` c
void* buffer;
uint32_t num_bytes = 1024;
MojoResult result = MojoBeginReadData(consumer, &buffer, &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
MojoResult result = MojoBeginReadData(consumer, nullptr, &buffer, &num_bytes);
// result should be MOJO_RESULT_OK, since there is some data available.
printf("Pipe says: %s", (const char*)buffer); // Should say "hello".
result = MojoEndReadData(consumer, 1); // Say we only consumed one byte.
// Say we only consumed one byte.
result = MojoEndReadData(consumer, 1, nullptr);
num_bytes = 1024;
result = MojoBeginReadData(consumer, &buffer, &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
result = MojoBeginReadData(consumer, nullptr, &buffer, &num_bytes);
printf("Pipe says: %s", (const char*)buffer); // Should say "ello".
result = MojoEndReadData(consumer, 5);
result = MojoEndReadData(consumer, 5, nullptr);
```
## Shared Buffers
@ -469,7 +466,7 @@ Usage is straightforward. You can create a new buffer:
``` c
// Allocate a shared buffer of 4 kB.
MojoHandle buffer;
MojoResult result = MojoCreateSharedBuffer(NULL, 4096, &buffer);
MojoResult result = MojoCreateSharedBuffer(4096, NULL, &buffer);
```
You can also duplicate an existing shared buffer handle:
@ -491,8 +488,7 @@ memory access to its contents:
``` c
void* data;
MojoResult result = MojoMapBuffer(buffer, 0, 64, &data,
MOJO_MAP_BUFFER_FLAG_NONE);
MojoResult result = MojoMapBuffer(buffer, 0, 64, nullptr, &data);
*(int*)data = 42;
result = MojoUnmapBuffer(data);
@ -510,14 +506,13 @@ that the newly duplicated handle can only be mapped to read-only memory:
MojoHandle read_only_buffer;
MojoDuplicateBufferHandleOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
options.flags = MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY;
MojoResult result = MojoDuplicateBufferHandle(buffer, &options,
&read_only_buffer);
// Attempt to map and write to the buffer using the read-only handle:
void* data;
result = MojoMapBuffer(read_only_buffer, 0, 64, &data,
MOJO_MAP_BUFFER_FLAG_NONE);
result = MojoMapBuffer(read_only_buffer, 0, 64, nullptr, &data);
*(int*)data = 42; // CRASH
```
@ -760,7 +755,9 @@ MojoResult result = MojoArmWatcher(w, NULL, NULL, NULL, NULL);
Now we can write to `b` to make `a` readable:
``` c
MojoWriteMessage(b, NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_NONE);
MojoMessageHandle m;
MojoCreateMessage(nullptr, &m);
MojoWriteMessage(b, m, nullptr);
```
Eventually -- and in practice possibly before `MojoWriteMessage` even

@ -15,53 +15,45 @@
#include "mojo/public/c/system/system_export.h"
#include "mojo/public/c/system/types.h"
// |MojoCreateSharedBufferOptions|: Used to specify creation parameters for a
// shared buffer to |MojoCreateSharedBuffer()|.
//
// |uint32_t struct_size|: Set to the size of the
// |MojoCreateSharedBufferOptions| struct. (Used to allow for future
// extensions.)
//
// |MojoCreateSharedBufferOptionsFlags flags|: Reserved for future use.
// |MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE|: No flags; default mode.
// Flags passed to |MojoCreateSharedBuffer()| via
// |MojoCreateSharedBufferOptions|. See values defined below.
typedef uint32_t MojoCreateSharedBufferFlags;
typedef uint32_t MojoCreateSharedBufferOptionsFlags;
// No flags. Default behavior.
#define MOJO_CREATE_SHARED_BUFFER_FLAG_NONE ((uint32_t)0)
#ifdef __cplusplus
const MojoCreateSharedBufferOptionsFlags
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0;
#else
#define MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE \
((MojoCreateSharedBufferOptionsFlags)0)
#endif
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
// Options passed to |MojoCreateSharedBuffer()|.
struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions {
uint32_t struct_size;
MojoCreateSharedBufferOptionsFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8,
"MojoCreateSharedBufferOptions has wrong size");
// Flags passed to |MojoGetBufferInfo()| via |MojoSharedBufferOptions|.
typedef uint32_t MojoSharedBufferOptionsFlags;
#ifdef __cplusplus
const MojoSharedBufferOptionsFlags MOJO_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0;
#else
#define MOJO_SHARED_BUFFER_OPTIONS_FLAG_NONE ((MojoSharedBufferOptionsFlags)0)
#endif
struct MOJO_ALIGNAS(8) MojoSharedBufferOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoSharedBufferOptionsFlags|.
MojoSharedBufferOptionsFlags flags;
// See |MojoCreateSharedBufferFlags|.
MojoCreateSharedBufferFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoSharedBufferOptions) == 8,
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8,
"MojoCreateSharedBufferOptions has wrong size");
// Flags passed to |MojoGetBufferInfo()| via |MojoGetBufferInfoOptions|. See
// values defined below.
typedef uint32_t MojoGetBufferInfoFlags;
// No flags. Default behavior.
#define MOJO_GET_BUFFER_INFO_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoGetBufferInfo()|.
struct MOJO_ALIGNAS(8) MojoGetBufferInfoOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoGetBufferInfoFlags|.
MojoGetBufferInfoFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoGetBufferInfoOptions) == 8,
"MojoSharedBufferOptions has wrong size");
// Structure used to receive information about a shared buffer via
// |MojoGetBufferInfo()|.
struct MOJO_ALIGNAS(8) MojoSharedBufferInfo {
// The size of this structure, used for versioning.
uint32_t struct_size;
@ -72,63 +64,59 @@ struct MOJO_ALIGNAS(8) MojoSharedBufferInfo {
MOJO_STATIC_ASSERT(sizeof(MojoSharedBufferInfo) == 16,
"MojoSharedBufferInfo has wrong size");
// |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating
// access to a shared buffer to |MojoDuplicateBufferHandle()|.
//
// |uint32_t struct_size|: Set to the size of the
// |MojoDuplicateBufferHandleOptions| struct. (Used to allow for future
// extensions.)
//
// |MojoDuplicateBufferHandleOptionsFlags flags|: Flags to control the
// behavior of |MojoDuplicateBufferHandle()|. May be some combination of
// the following:
//
// |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE|: No flags; default
// mode.
// |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY|: The duplicate
// shared buffer can only be mapped read-only. A read-only duplicate
// may only be created before any handles to the buffer are passed
// over a message pipe.
// Flags passed to |MojoDuplicateBufferHandle()| via
// |MojoDuplicateBufferHandleOptions|. See values defined below.
typedef uint32_t MojoDuplicateBufferHandleFlags;
typedef uint32_t MojoDuplicateBufferHandleOptionsFlags;
// No options. Default behavior. Note that if a shared buffer handle is ever
// duplicated without |MOJO_DUPLICATE_BUFFER_HANDLE_READ_ONLY| (see below),
// neither it nor any of its duplicates can ever be duplicated *with*
// |MOJO_DUPLICATE_BUFFER_HANDLE_READ_ONLY| in the future. That is, once a
// writable handle has been duplicated as another writable handle, it is no
// longer possible to create read-only handles to the underlying buffer object.
#define MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE ((uint32_t)0)
#ifdef __cplusplus
const MojoDuplicateBufferHandleOptionsFlags
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE = 0;
const MojoDuplicateBufferHandleOptionsFlags
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY = 1 << 0;
#else
#define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \
((MojoDuplicateBufferHandleOptionsFlags)0)
#define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY \
((MojoDuplicateBufferHandleOptionsFlags)1 << 0)
#endif
// Duplicates the handle as read-only. If successful, the resulting new handle
// will always map to a read-only memory region. Successful use of this flag
// also imposes the limitation that the handle or any of its subsequent
// duplicates may never be duplicated *without* this flag in the future. That
// is, once a read-only handle is produced for a buffer object, all future
// handles to that object must also be read-only.
#define MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY ((uint32_t)1 << 0)
// Options passed to |MojoDuplicateBufferHandle()|.
struct MojoDuplicateBufferHandleOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
MojoDuplicateBufferHandleOptionsFlags flags;
// See |MojoDuplicateBufferHandleFlags|.
MojoDuplicateBufferHandleFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8,
"MojoDuplicateBufferHandleOptions has wrong size");
// |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|.
// |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode.
// Flags passed to |MojoMapBuffer()| via |MojoMapBufferOptions|. See values
// defined below.
typedef uint32_t MojoMapBufferFlags;
#ifdef __cplusplus
const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0;
#else
#define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_MAP_BUFFER_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoMapBuffer()|.
struct MojoMapBufferOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoMapBufferFlags|.
MojoMapBufferFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoMapBufferOptions) == 8,
"MojoMapBufferOptions has wrong size");
#ifdef __cplusplus
extern "C" {
#endif
// Note: See the comment in functions.h about the meaning of the "optional"
// label for pointer parameters.
// Creates a buffer of size |num_bytes| bytes that can be shared between
// processes. The returned handle may be duplicated any number of times by
// |MojoDuplicateBufferHandle()|.
@ -148,10 +136,10 @@ extern "C" {
// been reached (e.g., if the requested size was too large, or if the
// maximum number of handles was exceeded).
// |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer(
const struct MojoCreateSharedBufferOptions* options, // Optional.
uint64_t num_bytes, // In.
MojoHandle* shared_buffer_handle); // Out.
MOJO_SYSTEM_EXPORT MojoResult
MojoCreateSharedBuffer(uint64_t num_bytes,
const struct MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle);
// Duplicates the handle |buffer_handle| as a new shared buffer handle. On
// success this returns the new handle in |*new_buffer_handle|. A shared buffer
@ -161,20 +149,31 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer(
// |options| may be set to null to duplicate the buffer handle with the default
// options.
//
// Access rights to mapped memory from the duplicated handle may be controlled
// by flags in |*options|, with some limitations. See notes on
// |MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE| and
// |MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY| regarding restrictions on
// duplication with respect to these flags.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |buffer_handle| is not a valid buffer handle or |*options| is invalid).
// |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
// |MOJO_RESULT_FAILED_PRECONDITION| if
// |MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY| was set but the handle
// was already previously duplicated without that flag; or if
// |MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY| was not set but the
// handle was already previously duplicated with that flag.
MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle(
MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options, // Optional.
MojoHandle* new_buffer_handle); // Out.
const struct MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle);
// Maps the part (at offset |offset| of length |num_bytes|) of the buffer given
// by |buffer_handle| into memory, with options specified by |flags|. |offset +
// num_bytes| must be less than or equal to the size of the buffer. On success,
// |*buffer| points to memory with the requested part of the buffer. On
// by |buffer_handle| into memory, with options specified by |options|.
// |offset+num_bytes| must be less than or equal to the size of the buffer. On
// success, |*buffer| points to memory with the requested part of the buffer. On
// failure |*buffer| it is not modified.
//
// A single buffer handle may have multiple active mappings. The permissions
@ -185,18 +184,21 @@ MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle(
// A mapped buffer must eventually be unmapped by calling |MojoUnmapBuffer()|
// with the value of |*buffer| returned by this function.
//
// |options| may be null to map the buffer with default behavior.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |buffer_handle| is not a valid buffer handle or the range specified by
// |offset| and |num_bytes| is not valid).
// |buffer_handle| is not a valid buffer handle, the range specified by
// |offset| and |num_bytes| is not valid, or |*options| is invalid).
// |MOJO_RESULT_RESOURCE_EXHAUSTED| if the mapping operation itself failed
// (e.g., due to not having appropriate address space available).
MOJO_SYSTEM_EXPORT MojoResult MojoMapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer, // Out.
MojoMapBufferFlags flags);
MOJO_SYSTEM_EXPORT MojoResult
MojoMapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
const struct MojoMapBufferOptions* options,
void** buffer);
// Unmaps a buffer pointer that was mapped by |MojoMapBuffer()|. |buffer| must
// have been the result of |MojoMapBuffer()| (not some other pointer inside
@ -208,22 +210,26 @@ MOJO_SYSTEM_EXPORT MojoResult MojoMapBuffer(MojoHandle buffer_handle,
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the
// result of |MojoMapBuffer()| or has already been unmapped).
MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer); // In.
MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer);
// Retrieve information about |buffer_handle| into |info|. |options| is optional
// and reserved for future use.
// Retrieve information about |buffer_handle| into |info|.
//
// Callers must initialize |info->struct_size| to |sizeof(MojoSharedBufferInfo)|
// before calling this function.
//
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if |buffer_handle| is invalid or if |info|
// is NULL.
// |MOJO_RESULT_INVALID_ARGUMENT| if |buffer_handle| is invalid, |info| is
// null, or |*options| is invalid.
//
// On success, |info->size| will be set to the size of the buffer. On failure it
// is not modified.
MOJO_SYSTEM_EXPORT MojoResult
MojoGetBufferInfo(MojoHandle buffer_handle,
const struct MojoSharedBufferOptions* options, // Optional.
struct MojoSharedBufferInfo* info); // Out.
const struct MojoGetBufferInfoOptions* options,
struct MojoSharedBufferInfo* info);
#ifdef __cplusplus
} // extern "C"

@ -15,103 +15,173 @@
#include "mojo/public/c/system/system_export.h"
#include "mojo/public/c/system/types.h"
// |MojoCreateDataPipeOptions|: Used to specify creation parameters for a data
// pipe to |MojoCreateDataPipe()|.
//
// |uint32_t struct_size|: Set to the size of the |MojoCreateDataPipeOptions|
// struct. (Used to allow for future extensions.)
//
// |MojoCreateDataPipeOptionsFlags flags|: Used to specify different modes of
// operation. May be some combination of the following values:
//
// |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode.
//
// |uint32_t element_num_bytes|: The size of an element, in bytes. All
// transactions and buffers will consist of an integral number of
// elements. Must be nonzero.
//
// |uint32_t capacity_num_bytes|: The capacity of the data pipe, in number of
// bytes; must be a multiple of |element_num_bytes|. The data pipe will
// always be able to queue AT LEAST this much data. Set to zero to opt for
// a system-dependent automatically-calculated capacity (which will always
// be at least one element).
// Flags passed to |MojoCreateDataPipe()| via |MojoCreateDataPipeOptions|. See
// values defined below.
typedef uint32_t MojoCreateDataPipeFlags;
typedef uint32_t MojoCreateDataPipeOptionsFlags;
// No flags. Default behavior.
#define MOJO_CREATE_DATA_PIPE_FLAG_NONE ((uint32_t)0)
#ifdef __cplusplus
const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE =
0;
#else
#define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \
((MojoCreateDataPipeOptionsFlags)0)
#endif
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
// Options passed to |MojoCreateDataPipe()|.
struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions {
MOJO_ALIGNAS(4) uint32_t struct_size;
MOJO_ALIGNAS(4) MojoCreateDataPipeOptionsFlags flags;
MOJO_ALIGNAS(4) uint32_t element_num_bytes;
MOJO_ALIGNAS(4) uint32_t capacity_num_bytes;
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoCreateDataPipeFlags|.
MojoCreateDataPipeFlags flags;
// The size of an element in bytes. All transactions and buffer sizes must
// consist of an integral number of elements. Must be non-zero.
uint32_t element_num_bytes;
// The capacity of the data pipe in bytes. Must be a multiple of
// |element_num_bytes|. If successfully created, the pipe will always be able
// to queue at least this much data. If zero, the pipe buffer will be of a
// system-dependent capacity of at least one element in size.
uint32_t capacity_num_bytes;
};
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16,
"MojoCreateDataPipeOptions has wrong size");
// |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()|
// and |MojoBeginWriteData()|. May be some combination of the following values:
//
// |MOJO_WRITE_DATA_FLAG_NONE| - No flags; default mode.
// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| - Write either all the elements
// requested or none of them.
// Flags passed to |MojoWriteData()| via |MojoWriteDataOptions|. See values
// defined below.
typedef uint32_t MojoWriteDataFlags;
#ifdef __cplusplus
const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0;
const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0;
#else
#define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags)0)
#define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags)1 << 0)
#endif
// No flags. Default behavior.
#define MOJO_WRITE_DATA_FLAG_NONE ((uint32_t)0)
// |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and
// |MojoBeginReadData()|. May be some combination of the following values:
//
// |MOJO_READ_DATA_FLAG_NONE| - No flags; default mode.
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| - Read (or discard) either the requested
// number of elements or none. For use with |MojoReadData()| only.
// |MOJO_READ_DATA_FLAG_DISCARD| - Discard (up to) the requested number of
// elements. For use with |MojoReadData()| only.
// |MOJO_READ_DATA_FLAG_QUERY| - Query the number of elements available to
// read. For use with |MojoReadData()| only. Mutually exclusive with
// |MOJO_READ_DATA_FLAG_DISCARD|, and |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
// is ignored if this flag is set.
// |MOJO_READ_DATA_FLAG_PEEK| - Read elements without removing them. For use
// with |MojoReadData()| only. Mutually exclusive with
// |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_QUERY|.
// Requires that all provided data must fit into the pipe's available capacity
// in order for the write to succeed. Otherwise the write fails and no data is
// written into the pipe.
#define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((uint32_t)1 << 0)
// Options passed to |MojoWriteData()|.
struct MOJO_ALIGNAS(8) MojoWriteDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoWriteDataFlags|.
MojoWriteDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoWriteDataOptions) == 8,
"MojoWriteDataOptions has wrong size");
// Flags passed to |MojoBeginWriteData()| via |MojoBeginWriteDataOptions|. See
// values defined below.
typedef uint32_t MojoBeginWriteDataFlags;
// No flags. Default behavior.
#define MOJO_BEGIN_WRITE_DATA_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoBeginWriteData()|.
struct MOJO_ALIGNAS(8) MojoBeginWriteDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoBeginWriteDataFlags|.
MojoBeginWriteDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoBeginWriteDataOptions) == 8,
"MojoBeginWriteDataOptions has wrong size");
// Flags passed to |MojoEndWriteData()| via |MojoEndWriteDataOptions|. See
// values defined below.
typedef uint32_t MojoEndWriteDataFlags;
// No flags. Default behavior.
#define MOJO_END_WRITE_DATA_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoEndWriteData()|.
struct MOJO_ALIGNAS(8) MojoEndWriteDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoEndWriteDataFlags|.
MojoEndWriteDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoEndWriteDataOptions) == 8,
"MojoEndWriteDataOptions has wrong size");
// Flags passed to |MojoReadData()| via |MojoReadDataOptions|.
typedef uint32_t MojoReadDataFlags;
#ifdef __cplusplus
const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_PEEK = 1 << 3;
#else
#define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0)
#define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0)
#define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1)
#define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2)
#define MOJO_READ_DATA_FLAG_PEEK ((MojoReadDataFlags)1 << 3)
#endif
// No flags. Default behavior.
#define MOJO_READ_DATA_FLAG_NONE ((uint32_t)0)
// Requires that all request bytes can be read from the data pipe in order for
// the read to succeed. If that many bytes are not available for reading, the
// read will fail and no bytes will be read. Ignored of
// |MOJO_READ_DATA_FLAG_QUERY| is also set.
#define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((uint32_t)1 << 0)
// Discards the data read rather than copying it into the caller's provided
// buffer. May not be combined with |MOJO_READ_DATA_FLAG_PEEK| or
// |MOJO_READ_DATA_FLAG_QUERY|.
#define MOJO_READ_DATA_FLAG_DISCARD ((uint32_t)1 << 1)
// Queries the number of bytes available for reading without actually reading
// the data. May not be combined with |MOJO_READ_DATA_FLAG_DISCARD| or
// |MOJO_READ_DATA_FLAG_PEEK|. |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is ignored if
// this is set.
#define MOJO_READ_DATA_FLAG_QUERY ((uint32_t)1 << 2)
// Reads data from the pipe and copies it to the caller's provided buffer
// without actually removing the data from the pipe. May not be combined with
// |MOJO_READ_DATA_FLAG_DISCARD| or |MOJO_READ_DATA_FLAG_QUERY|.
#define MOJO_READ_DATA_FLAG_PEEK ((uint32_t)1 << 3)
// Options passed to |MojoReadData()|.
struct MOJO_ALIGNAS(8) MojoReadDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoReadDataFlags|.
MojoReadDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoReadDataOptions) == 8,
"MojoReadDataOptions has wrong size");
// Flags passed to |MojoBeginReadData()| via |MojoBeginReadDataOptions|. See
// values defined below.
typedef uint32_t MojoBeginReadDataFlags;
// No flags. Default behavior.
#define MOJO_BEGIN_READ_DATA_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoBeginReadData()|.
struct MOJO_ALIGNAS(8) MojoBeginReadDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoBeginReadDataFlags|.
MojoBeginReadDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoBeginReadDataOptions) == 8,
"MojoBeginReadDataOptions has wrong size");
// Flags passed to |MojoEndReadData()| via |MojoEndReadDataOptions|. See
// values defined below.
typedef uint32_t MojoEndReadDataFlags;
// No flags. Default behavior.
#define MOJO_END_READ_DATA_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoEndReadData()|.
struct MOJO_ALIGNAS(8) MojoEndReadDataOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoEndReadDataFlags|.
MojoEndReadDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoEndReadDataOptions) == 8,
"MojoEndReadDataOptions has wrong size");
#ifdef __cplusplus
extern "C" {
#endif
// Note: See the comment in functions.h about the meaning of the "optional"
// label for pointer parameters.
// Creates a data pipe, which is a unidirectional communication channel for
// unframed data. Data must be read and written in multiples of discrete
// discrete elements of size given in |options|.
@ -136,21 +206,22 @@ extern "C" {
// been reached (e.g., if the requested capacity was too large, or if the
// maximum number of handles was exceeded).
// |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe(
const struct MojoCreateDataPipeOptions* options, // Optional.
MojoHandle* data_pipe_producer_handle, // Out.
MojoHandle* data_pipe_consumer_handle); // Out.
MOJO_SYSTEM_EXPORT MojoResult
MojoCreateDataPipe(const struct MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle);
// Writes the data pipe producer given by |data_pipe_producer_handle|.
//
// |elements| points to data of size |*num_bytes|; |*num_bytes| must be a
// multiple of the data pipe's element size. If
// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data
// is written (if enough write capacity is available) or none is.
// multiple of the data pipe's element size.
//
// On success |*num_bytes| is set to the amount of data that was actually
// written. On failure it is unmodified.
//
// |options| may be null for default options. See |MojoWriteDataOptions| for
// the effect of various options on the behavior of this function.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
@ -159,20 +230,20 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe(
// size.)
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
// closed.
// |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
// |MOJO_RESULT_OUT_OF_RANGE| if |options->flags| has
// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
// (specified by |*num_bytes|) could not be written.
// |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with
// |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
// called, but not yet the matching |MojoEndWriteData()|).
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
// consumer is still open) and |flags| does *not* have
// consumer is still open) and |options->flags| does *not* have
// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
MOJO_SYSTEM_EXPORT MojoResult
MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes, // In/out.
MojoWriteDataFlags flags);
MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes,
const struct MojoWriteDataOptions* options);
// Begins a two-phase write to the data pipe producer given by
// |data_pipe_producer_handle|. On success |*buffer| will be a pointer to which
@ -188,11 +259,13 @@ MOJO_SYSTEM_EXPORT MojoResult
// write operation. |MojoEndWriteData()| need not be called when
// |MojoBeginWriteData()| fails.
//
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |data_pipe_producer_handle| is not a handle to a data pipe producer or
// flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
// |*options| is invalid.
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
// closed.
// |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with
@ -201,10 +274,10 @@ MOJO_SYSTEM_EXPORT MojoResult
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
// consumer is still open).
MOJO_SYSTEM_EXPORT MojoResult
MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
void** buffer, // Out.
uint32_t* buffer_num_bytes, // In/out.
MojoWriteDataFlags flags);
MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
const struct MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_bytes);
// Ends a two-phase write that was previously initiated by
// |MojoBeginWriteData()| for the same |data_pipe_producer_handle|.
@ -218,6 +291,8 @@ MOJO_SYSTEM_EXPORT MojoResult
// writable again if there's space available) but no data written to |*buffer|
// is "put into" the data pipe.
//
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
@ -228,13 +303,14 @@ MOJO_SYSTEM_EXPORT MojoResult
// two-phase write (e.g., |MojoBeginWriteData()| was not called or
// |MojoEndWriteData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult
MojoEndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written);
MojoEndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written,
const struct MojoEndWriteDataOptions* options);
// Reads data from the data pipe consumer given by |data_pipe_consumer_handle|.
// May also be used to discard data or query the amount of data available.
//
// If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor
// If |options->flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor
// |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which
// must be a multiple of the data pipe's element size) bytes of data to
// |elements| and set |*num_bytes| to the amount actually read. If flags has
@ -257,28 +333,32 @@ MOJO_SYSTEM_EXPORT MojoResult
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is ignored, as are |elements| and the input
// value of |*num_bytes|.
//
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success (see above for a description of the different
// operations).
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |data_pipe_consumer_handle| is invalid, the combination of flags in
// |flags| is invalid, etc.).
// |options->flags| is invalid, or |*options| itself is invalid).
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been
// closed and data (or the required amount of data) was not available to
// be read or discarded.
// |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
// set and the required amount of data is not available to be read or
// discarded (and the producer is still open).
// |MOJO_RESULT_OUT_OF_RANGE| if |options->flags| has
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
// is not available to be read or discarded and the producer is still
// open.
// |MOJO_RESULT_BUSY| if there is a two-phase read ongoing with
// |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been
// called, but not yet the matching |MojoEndReadData()|).
// |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and
// the producer is still open) and |flags| does *not* have
// the producer is still open) and |options->flags| does *not* have
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
void* elements, // Out.
uint32_t* num_bytes, // In/out.
MojoReadDataFlags flags);
MOJO_SYSTEM_EXPORT MojoResult
MojoReadData(MojoHandle data_pipe_consumer_handle,
const struct MojoReadDataOptions* options,
void* elements,
uint32_t* num_bytes);
// Begins a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from
@ -292,15 +372,13 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
// must be called to indicate the number of bytes read and to complete the
// two-phase read operation.
//
// |flags| must not have |MOJO_READ_DATA_FLAG_DISCARD|,
// |MOJO_READ_DATA_FLAG_QUERY|, |MOJO_READ_DATA_FLAG_PEEK|, or
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |data_pipe_consumer_handle| is not a handle to a data pipe consumer,
// or |flags| has invalid flags set.)
// or |*options| is invalid.)
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been
// closed.
// |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with
@ -310,9 +388,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
// producer is still open).
MOJO_SYSTEM_EXPORT MojoResult
MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
const void** buffer, // Out.
uint32_t* buffer_num_bytes, // Out.
MojoReadDataFlags flags);
const struct MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_bytes);
// Ends a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()|
@ -324,6 +402,8 @@ MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
// On failure, the two-phase read (if any) is ended (so the handle may become
// readable again) but no data is "removed" from the data pipe.
//
// |options| may be null for default options.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
@ -334,8 +414,9 @@ MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
// two-phase read (e.g., |MojoBeginReadData()| was not called or
// |MojoEndReadData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult
MojoEndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read);
MojoEndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read,
const struct MojoEndReadDataOptions* options);
#ifdef __cplusplus
} // extern "C"

@ -19,13 +19,6 @@
extern "C" {
#endif
// Note: Pointer parameters that are labelled "optional" may be null (at least
// under some circumstances). Non-const pointer parameters are also labeled
// "in", "out", or "in/out", to indicate how they are used. (Note that how/if
// such a parameter is used may depend on other parameters or the requested
// operation's success/failure. E.g., a separate |flags| parameter may control
// whether a given "in/out" parameter is used for input, output, or both.)
// Initializes Mojo in the calling application.
//
// With the exception of EDK embedders, applications using Mojo APIs must call

@ -15,75 +15,89 @@
#include "mojo/public/c/system/system_export.h"
#include "mojo/public/c/system/types.h"
// |MojoMessageHandle|: Used to refer to message objects.
// Used to refer to message objects created by |MojoCreateMessage()|.
typedef uintptr_t MojoMessageHandle;
#ifdef __cplusplus
const MojoMessageHandle MOJO_MESSAGE_HANDLE_INVALID = 0;
#else
#define MOJO_MESSAGE_HANDLE_INVALID ((MojoMessageHandle)0)
#endif
// |MojoCreateMessagePipeOptions|: Used to specify creation parameters for a
// message pipe to |MojoCreateMessagePipe()|.
// |uint32_t struct_size|: Set to the size of the
// |MojoCreateMessagePipeOptions| struct. (Used to allow for future
// extensions.)
// |MojoCreateMessagePipeOptionsFlags flags|: Used to specify different modes
// of operation.
// |MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode.
// Flags passed to |MojoCreateMessagePipe()| via |MojoCreateMessagePipeOptions|.
// See values defined below.
typedef uint32_t MojoCreateMessagePipeFlags;
typedef uint32_t MojoCreateMessagePipeOptionsFlags;
// No flags. Default behavior.
#define MOJO_CREATE_MESSAGE_PIPE_FLAG_NONE ((uint32_t)0)
#ifdef __cplusplus
const MojoCreateMessagePipeOptionsFlags
MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE = 0;
#else
#define MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE \
((MojoCreateMessagePipeOptionsFlags)0)
#endif
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
// Options passed to |MojoCreateMessagePipe()|.
struct MOJO_ALIGNAS(8) MojoCreateMessagePipeOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
MojoCreateMessagePipeOptionsFlags flags;
// See |MojoCreateMessagePipeFlags|.
MojoCreateMessagePipeFlags flags;
};
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8,
"MojoCreateMessagePipeOptions has wrong size");
// |MojoWriteMessageFlags|: Used to specify different modes to
// |MojoWriteMessage()|.
// |MOJO_WRITE_MESSAGE_FLAG_NONE| - No flags; default mode.
// Flags passed to |MojoWriteMessage()| via |MojoWriteMessageOptions|. See
// values defined below.
typedef uint32_t MojoWriteMessageFlags;
#ifdef __cplusplus
const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0;
#else
#define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_WRITE_MESSAGE_FLAG_NONE ((uint32_t)0)
// |MojoReadMessageFlags|: Used to specify different modes to
// |MojoReadMessage()|.
// |MOJO_READ_MESSAGE_FLAG_NONE| - No flags; default mode.
// Options passed to |MojoWriteMessage()|.
struct MOJO_ALIGNAS(8) MojoWriteMessageOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoWriteMessageFlags|.
MojoWriteMessageFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoWriteMessageOptions) == 8,
"MojoWriteMessageOptions has wrong size");
// Flags passed to |MojoReadMessage()| via |MojoReadMessageOptions|. See values
// defined below.
typedef uint32_t MojoReadMessageFlags;
#ifdef __cplusplus
const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0;
#else
#define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_READ_MESSAGE_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoReadMessage()|.
struct MOJO_ALIGNAS(8) MojoReadMessageOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoReadMessageFlags|.
MojoReadMessageFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoReadMessageOptions) == 8,
"MojoReadMessageOptions has wrong size");
// Flags passed to |MojoFuseMessagePipes()| via |MojoFuseMessagePipeOptions|.
// See values defined below.
typedef uint32_t MojoFuseMessagePipesFlags;
// No flags. Default behavior.
#define MOJO_FUSE_MESSAGE_PIPES_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoFuseMessagePipes()|.
struct MOJO_ALIGNAS(8) MojoFuseMessagePipesOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoFuseMessagePipesFlags|.
MojoFuseMessagePipesFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoFuseMessagePipesOptions) == 8,
"MojoFuseMessagePipesOptions has wrong size");
// Flags passed to |MojoCreateMessage()| via |MojoCreateMessageOptions|.
typedef uint32_t MojoCreateMessageFlags;
#ifdef __cplusplus
const MojoCreateMessageFlags MOJO_CREATE_MESSAGE__FLAG_NONE = 0;
#else
#define MOJO_CREATE_MESSAGE_FLAG_NONE ((MojoCreateMessageFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_CREATE_MESSAGE_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoCreateMessage()|.
struct MOJO_ALIGNAS(8) MojoCreateMessageOptions {
@ -93,15 +107,14 @@ struct MOJO_ALIGNAS(8) MojoCreateMessageOptions {
// See |MojoCreateMessageFlags|.
MojoCreateMessageFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoCreateMessageOptions) == 8,
"MojoCreateMessageOptions has wrong size");
// Flags passed to |MojoSerializeMessage()| via |MojoSerializeMessageOptions|.
typedef uint32_t MojoSerializeMessageFlags;
#ifdef __cplusplus
const MojoSerializeMessageFlags MOJO_SERIALIZE_MESSAGE_FLAG_NONE = 0;
#else
#define MOJO_SERIALIZE_MESSAGE_FLAG_NONE ((MojoSerializeMessageFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_SERIALIZE_MESSAGE_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoSerializeMessage()|.
struct MOJO_ALIGNAS(8) MojoSerializeMessageOptions {
@ -111,18 +124,19 @@ struct MOJO_ALIGNAS(8) MojoSerializeMessageOptions {
// See |MojoSerializeMessageFlags|.
MojoSerializeMessageFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoSerializeMessageOptions) == 8,
"MojoSerializeMessageOptions has wrong size");
// Flags passed to |MojoAppendMessageData()| via |MojoAppendMessageDataOptions|.
typedef uint32_t MojoAppendMessageDataFlags;
#ifdef __cplusplus
const MojoAppendMessageDataFlags MOJO_APPEND_MESSAGE_DATA_FLAG_NONE = 0;
const MojoAppendMessageDataFlags MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE = 1;
#else
#define MOJO_APPEND_MESSAGE_DATA_FLAG_NONE ((MojoAppendMessageDataFlags)0)
// No flags. Default behavior.
#define MOJO_APPEND_MESSAGE_DATA_FLAG_NONE ((uint32_t)0)
// If set, this comments the resulting (post-append) message size as the final
// size of the message payload, in terms of both bytes and attached handles.
#define MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE \
((MojoAppendMessageDataFlags)1)
#endif
// Options passed to |MojoAppendMessageData()|.
struct MOJO_ALIGNAS(8) MojoAppendMessageDataOptions {
@ -132,17 +146,18 @@ struct MOJO_ALIGNAS(8) MojoAppendMessageDataOptions {
// See |MojoAppendMessageDataFlags|.
MojoAppendMessageDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoAppendMessageDataOptions) == 8,
"MojoAppendMessageDataOptions has wrong size");
// Flags passed to |MojoGetMessageData()| via |MojoGetMessageDataOptions|.
typedef uint32_t MojoGetMessageDataFlags;
#ifdef __cplusplus
const MojoGetMessageDataFlags MOJO_GET_MESSAGE_DATA_FLAG_NONE = 0;
const MojoGetMessageDataFlags MOJO_GET_MESSAGE_DATA_FLAG_IGNORE_HANDLES = 1;
#else
#define MOJO_GET_MESSAGE_DATA_FLAG_NONE ((MojoGetMessageDataFlags)0)
#define MOJO_GET_MESSAGE_DATA_FLAG_IGNORE_HANDLES ((MojoGetMessageDataFlags)1);
#endif
// No flags. Default behavior.
#define MOJO_GET_MESSAGE_DATA_FLAG_NONE ((uint32_t)0)
// Ignores attached handles when retrieving message data. This leaves any
// attached handles intact and owned by the message object.
#define MOJO_GET_MESSAGE_DATA_FLAG_IGNORE_HANDLES ((uint32_t)1)
// Options passed to |MojoGetMessageData()|.
struct MOJO_ALIGNAS(8) MojoGetMessageDataOptions {
@ -152,15 +167,14 @@ struct MOJO_ALIGNAS(8) MojoGetMessageDataOptions {
// See |MojoGetMessageDataFlags|.
MojoGetMessageDataFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoGetMessageDataOptions) == 8,
"MojoGetMessageDataOptions has wrong size");
// Flags passed to |MojoSetMessageContext()| via |MojoSetMessageContextOptions|.
typedef uint32_t MojoSetMessageContextFlags;
#ifdef __cplusplus
const MojoSetMessageContextFlags MOJO_SET_MESSAGE_CONTEXT_FLAG_NONE = 0;
#else
#define MOJO_SET_MESSAGE_CONTEXT_FLAG_NONE ((MojoSetMessageContextFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_SET_MESSAGE_CONTEXT_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoSetMessageContext()|.
struct MOJO_ALIGNAS(8) MojoSetMessageContextOptions {
@ -170,15 +184,14 @@ struct MOJO_ALIGNAS(8) MojoSetMessageContextOptions {
// See |MojoSetMessageContextFlags|.
MojoSetMessageContextFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoSetMessageContextOptions) == 8,
"MojoSetMessageContextOptions has wrong size");
// Flags passed to |MojoGetMessageContext()| via |MojoGetMessageContextOptions|.
typedef uint32_t MojoGetMessageContextFlags;
#ifdef __cplusplus
const MojoGetMessageContextFlags MOJO_GET_MESSAGE_CONTEXT_FLAG_NONE = 0;
#else
#define MOJO_GET_MESSAGE_CONTEXT_FLAG_NONE ((MojoGetMessageContextFlags)0)
#endif
// No flags. Default behavior.
#define MOJO_GET_MESSAGE_CONTEXT_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoGetMessageContext()|.
struct MOJO_ALIGNAS(8) MojoGetMessageContextOptions {
@ -188,6 +201,25 @@ struct MOJO_ALIGNAS(8) MojoGetMessageContextOptions {
// See |MojoGetMessageContextFlags|.
MojoGetMessageContextFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoGetMessageContextOptions) == 8,
"MojoGetMessageContextOptions has wrong size");
// Flags passed to |MojoNotifyBadMessage()| via |MojoNotifyBadMessageOptions|.
typedef uint32_t MojoNotifyBadMessageFlags;
// No flags. Default behavior.
#define MOJO_NOTIFY_BAD_MESSAGE_FLAG_NONE ((uint32_t)0)
// Options passed to |MojoNotifyBadMessage()|.
struct MOJO_ALIGNAS(8) MojoNotifyBadMessageOptions {
// The size of this structure, used for versioning.
uint32_t struct_size;
// See |MojoNotifyBadMessageFlags|.
MojoNotifyBadMessageFlags flags;
};
MOJO_STATIC_ASSERT(sizeof(MojoNotifyBadMessageOptions) == 8,
"MojoNotifyBadMessageOptions has wrong size");
#ifdef __cplusplus
extern "C" {
@ -239,6 +271,8 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe(
// Note that regardless of success or failure, |message| is destroyed by this
// call and therefore invalidated.
//
// |options| may be null.
//
// Returns:
// |MOJO_RESULT_OK| on success (i.e., the message was enqueued).
// |MOJO_RESULT_INVALID_ARGUMENT| if |message_pipe_handle| or |message| is
@ -249,9 +283,10 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe(
// endpoint has been closed (in which case the message would be dropped).
// |MOJO_RESULT_NOT_FOUND| if |message| has neither a context nor serialized
// buffer attached and therefore has nothing to be written.
MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message,
MojoWriteMessageFlags flags);
MOJO_SYSTEM_EXPORT MojoResult
MojoWriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message,
const struct MojoWriteMessageOptions* options);
// Reads the next message from a message pipe and returns a message as an opaque
// message handle. The returned message must eventually be destroyed using
@ -261,7 +296,7 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
// Unserialized messages, context may be accessed using
// |MojoGetMessageContext()|.
//
// |message| must be non-null.
// |options| may be null. |message| must be non-null.
//
// Returns:
// |MOJO_RESULT_OK| on success (i.e., a message was actually read).
@ -269,9 +304,10 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
// |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed
// and there are no more messages to read.
// |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read.
MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
MojoMessageHandle* message,
MojoReadMessageFlags flags);
MOJO_SYSTEM_EXPORT MojoResult
MojoReadMessage(MojoHandle message_pipe_handle,
const struct MojoReadMessageOptions* options,
MojoMessageHandle* message);
// Fuses two message pipe endpoints together. Given two pipes:
//
@ -288,6 +324,8 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
// NOTE: A handle may only be fused if it is an open message pipe handle which
// has not been written to.
//
// |options| may be null.
//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_FAILED_PRECONDITION| if both handles were valid message pipe
@ -295,7 +333,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
// |MOJO_INVALID_ARGUMENT| if either handle is not a fusable message pipe
// handle.
MOJO_SYSTEM_EXPORT MojoResult
MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1);
MojoFuseMessagePipes(MojoHandle handle0,
MojoHandle handle1,
const struct MojoFuseMessagePipesOptions* options);
// Creates a new message object which may be sent over a message pipe via
// |MojoWriteMessage()|. Returns a handle to the new message object in
@ -543,13 +583,16 @@ MojoGetMessageContext(MojoMessageHandle message,
// notified of this error.
// |error_num_bytes|: The length of |error| in bytes.
//
// |options| may be null.
//
// Returns:
// |MOJO_RESULT_OK| if successful.
// |MOJO_RESULT_INVALID_ARGUMENT| if |message| is not a valid message.
MOJO_SYSTEM_EXPORT MojoResult
MojoNotifyBadMessage(MojoMessageHandle message,
const char* error,
size_t error_num_bytes);
size_t error_num_bytes,
const struct MojoNotifyBadMessageOptions* options);
#ifdef __cplusplus
} // extern "C"

@ -44,35 +44,32 @@ TEST(CoreAPITest, InvalidHandle) {
// Message pipe:
h0 = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWriteMessage(h0, MOJO_MESSAGE_HANDLE_INVALID,
MOJO_WRITE_MESSAGE_FLAG_NONE));
MojoWriteMessage(h0, MOJO_MESSAGE_HANDLE_INVALID, nullptr));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoReadMessage(h0, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
MojoReadMessage(h0, nullptr, nullptr));
// Data pipe:
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWriteData(h0, buffer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
MojoWriteData(h0, buffer, &buffer_size, nullptr));
write_pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoBeginWriteData(h0, &write_pointer, &buffer_size,
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1));
MojoBeginWriteData(h0, nullptr, &write_pointer, &buffer_size));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1, nullptr));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoReadData(h0, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
MojoReadData(h0, nullptr, buffer, &buffer_size));
read_pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoBeginReadData(h0, &read_pointer, &buffer_size,
MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1));
MojoBeginReadData(h0, nullptr, &read_pointer, &buffer_size));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1, nullptr));
// Shared buffer:
h1 = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoDuplicateBufferHandle(h0, nullptr, &h1));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoMapBuffer(h0, 0, 1, &write_pointer, MOJO_MAP_BUFFER_FLAG_NONE));
MojoMapBuffer(h0, 0, 1, nullptr, &write_pointer));
}
TEST(CoreAPITest, BasicMessagePipe) {
@ -93,16 +90,14 @@ TEST(CoreAPITest, BasicMessagePipe) {
// Try to read.
MojoMessageHandle message;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
MojoReadMessage(h0, &message, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, MojoReadMessage(h0, nullptr, &message));
// Write to |h1|.
const uintptr_t kTestMessageContext = 1234;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessage(nullptr, &message));
EXPECT_EQ(MOJO_RESULT_OK, MojoSetMessageContext(message, kTestMessageContext,
nullptr, nullptr, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(h1, message, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(h1, message, nullptr));
// |h0| should be readable.
size_t result_index = 1;
@ -117,8 +112,7 @@ TEST(CoreAPITest, BasicMessagePipe) {
EXPECT_EQ(kSignalAll, states[0].satisfiable_signals);
// Read from |h0|.
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(h0, &message, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(h0, nullptr, &message));
uintptr_t context;
EXPECT_EQ(MOJO_RESULT_OK, MojoGetMessageContext(message, nullptr, &context));
EXPECT_EQ(MOJO_RESULT_OK,
@ -183,20 +177,18 @@ TEST(CoreAPITest, BasicDataPipe) {
// Try to read from |hc|.
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
MojoReadData(hc, nullptr, buffer, &buffer_size));
// Try to begin a two-phase read from |hc|.
read_pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
MojoBeginReadData(hc, &read_pointer, &buffer_size,
MOJO_READ_DATA_FLAG_NONE));
MojoBeginReadData(hc, nullptr, &read_pointer, &buffer_size));
// Write to |hp|.
static const char kHello[] = "hello ";
// Don't include terminating null.
buffer_size = static_cast<uint32_t>(strlen(kHello));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(hp, kHello, &buffer_size,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(hp, kHello, &buffer_size, nullptr));
// |hc| should be(come) readable.
size_t result_index = 1;
@ -214,20 +206,20 @@ TEST(CoreAPITest, BasicDataPipe) {
states[0].satisfiable_signals);
// Do a two-phase write to |hp|.
EXPECT_EQ(MOJO_RESULT_OK, MojoBeginWriteData(hp, &write_pointer, &buffer_size,
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoBeginWriteData(hp, nullptr, &write_pointer, &buffer_size));
static const char kWorld[] = "world";
ASSERT_GE(buffer_size, sizeof(kWorld));
// Include the terminating null.
memcpy(write_pointer, kWorld, sizeof(kWorld));
EXPECT_EQ(MOJO_RESULT_OK,
MojoEndWriteData(hp, static_cast<uint32_t>(sizeof(kWorld))));
EXPECT_EQ(
MOJO_RESULT_OK,
MojoEndWriteData(hp, static_cast<uint32_t>(sizeof(kWorld)), nullptr));
// Read one character from |hc|.
memset(buffer, 0, sizeof(buffer));
buffer_size = 1;
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(hc, nullptr, buffer, &buffer_size));
// Close |hp|.
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp));
@ -243,11 +235,11 @@ TEST(CoreAPITest, BasicDataPipe) {
// Do a two-phase read from |hc|.
read_pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_OK, MojoBeginReadData(hc, &read_pointer, &buffer_size,
MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoBeginReadData(hc, nullptr, &read_pointer, &buffer_size));
ASSERT_LE(buffer_size, sizeof(buffer) - 1);
memcpy(&buffer[1], read_pointer, buffer_size);
EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size));
EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size, nullptr));
EXPECT_STREQ("hello world", buffer);
// |hc| should no longer be readable.
@ -271,7 +263,7 @@ TEST(CoreAPITest, BasicSharedBuffer) {
MojoGetBufferInfo(h0, nullptr, &buffer_info));
// Create a shared buffer (|h0|).
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateSharedBuffer(nullptr, 100, &h0));
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateSharedBuffer(100, nullptr, &h0));
EXPECT_NE(h0, MOJO_HANDLE_INVALID);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
@ -281,8 +273,7 @@ TEST(CoreAPITest, BasicSharedBuffer) {
// Map everything.
void* pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(h0, 0, 100, &pointer, MOJO_MAP_BUFFER_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoMapBuffer(h0, 0, 100, nullptr, &pointer));
ASSERT_TRUE(pointer);
static_cast<char*>(pointer)[50] = 'x';
@ -302,8 +293,7 @@ TEST(CoreAPITest, BasicSharedBuffer) {
// Map half of |h1|.
pointer = nullptr;
EXPECT_EQ(MOJO_RESULT_OK,
MojoMapBuffer(h1, 50, 50, &pointer, MOJO_MAP_BUFFER_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoMapBuffer(h1, 50, 50, nullptr, &pointer));
ASSERT_TRUE(pointer);
// It should have what we wrote.

@ -146,8 +146,7 @@ class CorePerftest : public testing::Test {
static void MessagePipe_EmptyRead(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoMessageHandle message;
MojoResult result =
MojoReadMessage(self->h0_, &message, MOJO_READ_MESSAGE_FLAG_NONE);
MojoResult result = MojoReadMessage(self->h0_, nullptr, &message);
ALLOW_UNUSED_LOCAL(result);
assert(result == MOJO_RESULT_SHOULD_WAIT);
}

@ -59,11 +59,9 @@ const char* MinimalCTest(void) {
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessage(NULL, &message));
EXPECT_EQ(MOJO_RESULT_OK,
MojoSetMessageContext(message, 42, NULL, NULL, NULL));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(handle0, message, MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(handle0, message, NULL));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(handle1, NULL, &message));
EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(handle1, &message,
MOJO_READ_MESSAGE_FLAG_NONE));
uintptr_t context;
EXPECT_EQ(MOJO_RESULT_OK, MojoGetMessageContext(message, NULL, &context));
EXPECT_EQ(MOJO_RESULT_OK,

@ -122,15 +122,20 @@ MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options,
MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message_handle,
MojoWriteMessageFlags flags) {
return g_thunks.WriteMessage(message_pipe_handle, message_handle, flags);
const MojoWriteMessageOptions* options) {
return g_thunks.WriteMessage(message_pipe_handle, message_handle, options);
}
MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
MojoMessageHandle* message_handle,
MojoReadMessageFlags flags) {
assert(g_thunks.ReadMessage);
return g_thunks.ReadMessage(message_pipe_handle, message_handle, flags);
const MojoReadMessageOptions* options,
MojoMessageHandle* message_handle) {
return g_thunks.ReadMessage(message_pipe_handle, options, message_handle);
}
MojoResult MojoFuseMessagePipes(MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options) {
return g_thunks.FuseMessagePipes(handle0, handle1, options);
}
MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
@ -143,55 +148,58 @@ MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
MojoWriteDataFlags flags) {
const MojoWriteDataOptions* options) {
return g_thunks.WriteData(data_pipe_producer_handle, elements, num_elements,
flags);
options);
}
MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_elements,
MojoWriteDataFlags flags) {
return g_thunks.BeginWriteData(data_pipe_producer_handle, buffer,
buffer_num_elements, flags);
uint32_t* buffer_num_elements) {
return g_thunks.BeginWriteData(data_pipe_producer_handle, options, buffer,
buffer_num_elements);
}
MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_elements_written) {
return g_thunks.EndWriteData(data_pipe_producer_handle, num_elements_written);
uint32_t num_elements_written,
const MojoEndWriteDataOptions* options) {
return g_thunks.EndWriteData(data_pipe_producer_handle, num_elements_written,
options);
}
MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_elements,
MojoReadDataFlags flags) {
return g_thunks.ReadData(data_pipe_consumer_handle, elements, num_elements,
flags);
uint32_t* num_elements) {
return g_thunks.ReadData(data_pipe_consumer_handle, options, elements,
num_elements);
}
MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_elements,
MojoReadDataFlags flags) {
return g_thunks.BeginReadData(data_pipe_consumer_handle, buffer,
buffer_num_elements, flags);
uint32_t* buffer_num_elements) {
return g_thunks.BeginReadData(data_pipe_consumer_handle, options, buffer,
buffer_num_elements);
}
MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_elements_read) {
return g_thunks.EndReadData(data_pipe_consumer_handle, num_elements_read);
uint32_t num_elements_read,
const MojoEndReadDataOptions* options) {
return g_thunks.EndReadData(data_pipe_consumer_handle, num_elements_read,
options);
}
MojoResult MojoCreateSharedBuffer(
const struct MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
MojoHandle* shared_buffer_handle) {
return g_thunks.CreateSharedBuffer(options, num_bytes, shared_buffer_handle);
MojoResult MojoCreateSharedBuffer(uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle) {
return g_thunks.CreateSharedBuffer(num_bytes, options, shared_buffer_handle);
}
MojoResult MojoDuplicateBufferHandle(
MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options,
const MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle) {
return g_thunks.DuplicateBufferHandle(buffer_handle, options,
new_buffer_handle);
@ -200,9 +208,9 @@ MojoResult MojoDuplicateBufferHandle(
MojoResult MojoMapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags) {
return g_thunks.MapBuffer(buffer_handle, offset, num_bytes, buffer, flags);
const MojoMapBufferOptions* options,
void** buffer) {
return g_thunks.MapBuffer(buffer_handle, offset, num_bytes, options, buffer);
}
MojoResult MojoUnmapBuffer(void* buffer) {
@ -210,9 +218,8 @@ MojoResult MojoUnmapBuffer(void* buffer) {
}
MojoResult MojoGetBufferInfo(MojoHandle buffer_handle,
const struct MojoSharedBufferOptions* options,
struct MojoSharedBufferInfo* info) {
assert(g_thunks.GetBufferInfo);
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) {
return g_thunks.GetBufferInfo(buffer_handle, options, info);
}
@ -248,10 +255,6 @@ MojoResult MojoArmTrap(MojoHandle trap_handle,
ready_triggers, ready_results, ready_signals_states);
}
MojoResult MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1) {
return g_thunks.FuseMessagePipes(handle0, handle1);
}
MojoResult MojoCreateMessage(const MojoCreateMessageOptions* options,
MojoMessageHandle* message) {
return g_thunks.CreateMessage(options, message);
@ -302,6 +305,13 @@ MojoResult MojoGetMessageContext(MojoMessageHandle message,
return g_thunks.GetMessageContext(message, options, context);
}
MojoResult MojoNotifyBadMessage(MojoMessageHandle message,
const char* error,
size_t error_num_bytes,
const MojoNotifyBadMessageOptions* options) {
return g_thunks.NotifyBadMessage(message, error, error_num_bytes, options);
}
MojoResult MojoWrapPlatformHandle(
const struct MojoPlatformHandle* platform_handle,
MojoHandle* mojo_handle) {
@ -334,12 +344,6 @@ MojoResult MojoUnwrapPlatformSharedBufferHandle(
num_bytes, guid, flags);
}
MojoResult MojoNotifyBadMessage(MojoMessageHandle message,
const char* error,
size_t error_num_bytes) {
return g_thunks.NotifyBadMessage(message, error, error_num_bytes);
}
} // extern "C"
void MojoEmbedderSetSystemThunks(const MojoSystemThunks* thunks) {

@ -20,81 +20,34 @@
#pragma pack(push, 8)
struct MojoSystemThunks {
size_t size; // Should be set to sizeof(MojoSystemThunks).
MojoResult (*Initialize)(const struct MojoInitializeOptions* options);
MojoTimeTicks (*GetTimeTicksNow)();
// Generic handle API.
MojoResult (*Close)(MojoHandle handle);
MojoResult (*QueryHandleSignalsState)(
MojoHandle handle,
struct MojoHandleSignalsState* signals_state);
// Message pipe API.
MojoResult (*CreateMessagePipe)(
const struct MojoCreateMessagePipeOptions* options,
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1);
MojoResult (*WriteMessage)(MojoHandle message_pipe_handle,
MojoMessageHandle message_handle,
MojoWriteMessageFlags flags);
const struct MojoWriteMessageOptions* options);
MojoResult (*ReadMessage)(MojoHandle message_pipe_handle,
MojoMessageHandle* message_handle,
MojoReadMessageFlags flags);
MojoResult (*CreateDataPipe)(const struct MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle);
MojoResult (*WriteData)(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
MojoWriteDataFlags flags);
MojoResult (*BeginWriteData)(MojoHandle data_pipe_producer_handle,
void** buffer,
uint32_t* buffer_num_elements,
MojoWriteDataFlags flags);
MojoResult (*EndWriteData)(MojoHandle data_pipe_producer_handle,
uint32_t num_elements_written);
MojoResult (*ReadData)(MojoHandle data_pipe_consumer_handle,
void* elements,
uint32_t* num_elements,
MojoReadDataFlags flags);
MojoResult (*BeginReadData)(MojoHandle data_pipe_consumer_handle,
const void** buffer,
uint32_t* buffer_num_elements,
MojoReadDataFlags flags);
MojoResult (*EndReadData)(MojoHandle data_pipe_consumer_handle,
uint32_t num_elements_read);
MojoResult (*CreateSharedBuffer)(
const struct MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
MojoHandle* shared_buffer_handle);
MojoResult (*DuplicateBufferHandle)(
MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle);
MojoResult (*MapBuffer)(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags);
MojoResult (*UnmapBuffer)(void* buffer);
MojoResult (*GetBufferInfo)(MojoHandle buffer_handle,
const struct MojoSharedBufferOptions* options,
struct MojoSharedBufferInfo* info);
MojoResult (*CreateTrap)(MojoTrapEventHandler handler,
const struct MojoCreateTrapOptions* options,
MojoHandle* trap_handle);
MojoResult (*AddTrigger)(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const struct MojoAddTriggerOptions* options);
MojoResult (*RemoveTrigger)(MojoHandle trap_handle,
uintptr_t context,
const struct MojoRemoveTriggerOptions* options);
MojoResult (*ArmTrap)(MojoHandle trap_handle,
const struct MojoArmTrapOptions* options,
uint32_t* num_ready_triggers,
uintptr_t* ready_triggers,
MojoResult* ready_results,
MojoHandleSignalsState* ready_signals_states);
MojoResult (*FuseMessagePipes)(MojoHandle handle0, MojoHandle handle1);
const struct MojoReadMessageOptions* options,
MojoMessageHandle* message_handle);
MojoResult (*FuseMessagePipes)(
MojoHandle handle0,
MojoHandle handle1,
const struct MojoFuseMessagePipesOptions* options);
// Message object API.
MojoResult (*CreateMessage)(const struct MojoCreateMessageOptions* options,
MojoMessageHandle* message);
MojoResult (*DestroyMessage)(MojoMessageHandle message);
@ -125,6 +78,79 @@ struct MojoSystemThunks {
MojoMessageHandle message,
const struct MojoGetMessageContextOptions* options,
uintptr_t* context);
MojoResult (*NotifyBadMessage)(
MojoMessageHandle message,
const char* error,
size_t error_num_bytes,
const struct MojoNotifyBadMessageOptions* options);
// Data pipe API.
MojoResult (*CreateDataPipe)(const struct MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle);
MojoResult (*WriteData)(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
const struct MojoWriteDataOptions* options);
MojoResult (*BeginWriteData)(MojoHandle data_pipe_producer_handle,
const struct MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_elements);
MojoResult (*EndWriteData)(MojoHandle data_pipe_producer_handle,
uint32_t num_elements_written,
const struct MojoEndWriteDataOptions* options);
MojoResult (*ReadData)(MojoHandle data_pipe_consumer_handle,
const struct MojoReadDataOptions* options,
void* elements,
uint32_t* num_elements);
MojoResult (*BeginReadData)(MojoHandle data_pipe_consumer_handle,
const struct MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_elements);
MojoResult (*EndReadData)(MojoHandle data_pipe_consumer_handle,
uint32_t num_elements_read,
const struct MojoEndReadDataOptions* options);
// Shared buffer API.
MojoResult (*CreateSharedBuffer)(
uint64_t num_bytes,
const struct MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle);
MojoResult (*DuplicateBufferHandle)(
MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle);
MojoResult (*MapBuffer)(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
const struct MojoMapBufferOptions* options,
void** buffer);
MojoResult (*UnmapBuffer)(void* buffer);
MojoResult (*GetBufferInfo)(MojoHandle buffer_handle,
const struct MojoGetBufferInfoOptions* options,
struct MojoSharedBufferInfo* info);
// Traps API.
MojoResult (*CreateTrap)(MojoTrapEventHandler handler,
const struct MojoCreateTrapOptions* options,
MojoHandle* trap_handle);
MojoResult (*AddTrigger)(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const struct MojoAddTriggerOptions* options);
MojoResult (*RemoveTrigger)(MojoHandle trap_handle,
uintptr_t context,
const struct MojoRemoveTriggerOptions* options);
MojoResult (*ArmTrap)(MojoHandle trap_handle,
const struct MojoArmTrapOptions* options,
uint32_t* num_ready_triggers,
uintptr_t* ready_triggers,
MojoResult* ready_results,
MojoHandleSignalsState* ready_signals_states);
// Platform handle API.
MojoResult (*WrapPlatformHandle)(
const struct MojoPlatformHandle* platform_handle,
MojoHandle* mojo_handle);
@ -143,9 +169,6 @@ struct MojoSystemThunks {
size_t* num_bytes,
struct MojoSharedBufferGuid* guid,
MojoPlatformSharedBufferHandleFlags* flags);
MojoResult (*NotifyBadMessage)(MojoMessageHandle message,
const char* error,
size_t error_num_bytes);
};
#pragma pack(pop)

@ -260,8 +260,7 @@ TEST_P(HandlePassingTest, DataPipe) {
ScopedDataPipeProducerHandle producer_handle;
ScopedDataPipeConsumerHandle consumer_handle;
MojoCreateDataPipeOptions options = {sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
1,
MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
1024};
ASSERT_EQ(MOJO_RESULT_OK,
CreateDataPipe(&options, &producer_handle, &consumer_handle));

@ -57,7 +57,7 @@ FooPtr MakeFoo() {
for (size_t i = 0; i < input_streams.size(); ++i) {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = 1024;
mojo::ScopedDataPipeProducerHandle producer;

@ -8,10 +8,10 @@ namespace mojo {
// static
ScopedSharedBufferHandle SharedBufferHandle::Create(uint64_t num_bytes) {
MojoCreateSharedBufferOptions options = {
sizeof(options), MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE};
MojoCreateSharedBufferOptions options = {sizeof(options),
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE};
SharedBufferHandle handle;
MojoCreateSharedBuffer(&options, num_bytes, handle.mutable_value());
MojoCreateSharedBuffer(num_bytes, &options, handle.mutable_value());
return MakeScopedHandle(handle);
}
@ -22,9 +22,9 @@ ScopedSharedBufferHandle SharedBufferHandle::Clone(
return result;
MojoDuplicateBufferHandleOptions options = {
sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE};
if (access_mode == AccessMode::READ_ONLY)
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY;
SharedBufferHandle result_handle;
MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value());
result.reset(result_handle);
@ -39,7 +39,7 @@ ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset(
uint64_t size,
uint64_t offset) const {
void* buffer = nullptr;
MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE);
MojoMapBuffer(value(), offset, size, nullptr, &buffer);
return ScopedSharedBufferMapping(buffer);
}

@ -32,21 +32,27 @@ class DataPipeProducerHandle : public Handle {
MojoResult WriteData(const void* elements,
uint32_t* num_bytes,
MojoWriteDataFlags flags) const {
return MojoWriteData(value(), elements, num_bytes, flags);
MojoWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoWriteData(value(), elements, num_bytes, &options);
}
// Begins a two-phase write to a data pipe. See |MojoBeginWriteData()| for
// complete documentation.
MojoResult BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoWriteDataFlags flags) const {
return MojoBeginWriteData(value(), buffer, buffer_num_bytes, flags);
MojoBeginWriteDataFlags flags) const {
MojoBeginWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoBeginWriteData(value(), &options, buffer, buffer_num_bytes);
}
// Completes a two-phase write to a data pipe. See |MojoEndWriteData()| for
// complete documentation.
MojoResult EndWriteData(uint32_t num_bytes_written) const {
return MojoEndWriteData(value(), num_bytes_written);
return MojoEndWriteData(value(), num_bytes_written, nullptr);
}
// Copying and assignment allowed.
@ -71,21 +77,27 @@ class DataPipeConsumerHandle : public Handle {
MojoResult ReadData(void* elements,
uint32_t* num_bytes,
MojoReadDataFlags flags) const {
return MojoReadData(value(), elements, num_bytes, flags);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoReadData(value(), &options, elements, num_bytes);
}
// Begins a two-phase read from a data pipe. See |MojoBeginReadData()| for
// complete documentation.
MojoResult BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes,
MojoReadDataFlags flags) const {
return MojoBeginReadData(value(), buffer, buffer_num_bytes, flags);
MojoBeginReadDataFlags flags) const {
MojoBeginReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoBeginReadData(value(), &options, buffer, buffer_num_bytes);
}
// Completes a two-phase read from a data pipe. See |MojoEndReadData()| for
// complete documentation.
MojoResult EndReadData(uint32_t num_bytes_read) const {
return MojoEndReadData(value(), num_bytes_read);
return MojoEndReadData(value(), num_bytes_read, nullptr);
}
// Copying and assignment allowed.
@ -144,7 +156,7 @@ inline DataPipe::DataPipe() {
inline DataPipe::DataPipe(uint32_t capacity_num_bytes) {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = capacity_num_bytes;
mojo::DataPipe data_pipe(options);

@ -90,7 +90,8 @@ inline MojoResult GetMessageData(MessageHandle message,
inline MojoResult NotifyBadMessage(MessageHandle message,
const base::StringPiece& error) {
DCHECK(message.is_valid());
return MojoNotifyBadMessage(message.value(), error.data(), error.size());
return MojoNotifyBadMessage(message.value(), error.data(), error.size(),
nullptr);
}
} // namespace mojo

@ -18,15 +18,15 @@ MojoResult WriteMessageRaw(MessagePipeHandle message_pipe,
MojoResult rv = CreateMessage(&message_handle);
DCHECK_EQ(MOJO_RESULT_OK, rv);
MojoAppendMessageDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE;
MojoAppendMessageDataOptions append_options;
append_options.struct_size = sizeof(append_options);
append_options.flags = MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE;
void* buffer;
uint32_t buffer_size;
rv = MojoAppendMessageData(message_handle->value(),
base::checked_cast<uint32_t>(num_bytes), handles,
base::checked_cast<uint32_t>(num_handles),
&options, &buffer, &buffer_size);
&append_options, &buffer, &buffer_size);
if (rv != MOJO_RESULT_OK)
return MOJO_RESULT_ABORTED;
@ -34,8 +34,11 @@ MojoResult WriteMessageRaw(MessagePipeHandle message_pipe,
DCHECK_GE(buffer_size, base::checked_cast<uint32_t>(num_bytes));
memcpy(buffer, bytes, num_bytes);
MojoWriteMessageOptions write_options;
write_options.struct_size = sizeof(write_options);
write_options.flags = flags;
return MojoWriteMessage(message_pipe.value(),
message_handle.release().value(), flags);
message_handle.release().value(), &write_options);
}
MojoResult ReadMessageRaw(MessagePipeHandle message_pipe,

@ -91,8 +91,11 @@ ReadMessageRaw(MessagePipeHandle message_pipe,
inline MojoResult WriteMessageNew(MessagePipeHandle message_pipe,
ScopedMessageHandle message,
MojoWriteMessageFlags flags) {
MojoWriteMessageOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
return MojoWriteMessage(message_pipe.value(), message.release().value(),
flags);
&options);
}
// Reads from a message pipe. See |MojoReadMessage()| for complete
@ -100,8 +103,11 @@ inline MojoResult WriteMessageNew(MessagePipeHandle message_pipe,
inline MojoResult ReadMessageNew(MessagePipeHandle message_pipe,
ScopedMessageHandle* message,
MojoReadMessageFlags flags) {
MojoReadMessageOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoMessageHandle raw_message;
MojoResult rv = MojoReadMessage(message_pipe.value(), &raw_message, flags);
MojoResult rv = MojoReadMessage(message_pipe.value(), &options, &raw_message);
if (rv != MOJO_RESULT_OK)
return rv;
@ -114,7 +120,7 @@ inline MojoResult ReadMessageNew(MessagePipeHandle message_pipe,
inline MojoResult FuseMessagePipes(ScopedMessagePipeHandle message_pipe0,
ScopedMessagePipeHandle message_pipe1) {
return MojoFuseMessagePipes(message_pipe0.release().value(),
message_pipe1.release().value());
message_pipe1.release().value(), nullptr);
}
// A wrapper class that automatically creates a message pipe and owns both

@ -46,8 +46,7 @@ bool ReadTextMessage(const MessagePipeHandle& handle, std::string* text) {
bool DiscardMessage(const MessagePipeHandle& handle) {
MojoMessageHandle message;
int rv =
MojoReadMessage(handle.value(), &message, MOJO_READ_MESSAGE_FLAG_NONE);
int rv = MojoReadMessage(handle.value(), nullptr, &message);
if (rv != MOJO_RESULT_OK)
return false;
MojoDestroyMessage(message);

@ -522,8 +522,7 @@ class URLLoaderTest : public testing::Test {
const void* buffer;
uint32_t num_bytes;
MojoResult rv = MojoBeginReadData(consumer, &buffer, &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
MojoResult rv = MojoBeginReadData(consumer, nullptr, &buffer, &num_bytes);
// If no data has been received yet, spin the message loop until it has.
if (rv == MOJO_RESULT_SHOULD_WAIT) {
mojo::SimpleWatcher watcher(
@ -550,7 +549,7 @@ class URLLoaderTest : public testing::Test {
CHECK_EQ(rv, MOJO_RESULT_OK);
body.append(static_cast<const char*>(buffer), num_bytes);
MojoEndReadData(consumer, num_bytes);
MojoEndReadData(consumer, num_bytes, nullptr);
}
return body;
@ -560,15 +559,16 @@ class URLLoaderTest : public testing::Test {
MojoHandle consumer = client()->response_body().value();
uint32_t num_bytes = 0;
MojoResult result =
MojoReadData(consumer, nullptr, &num_bytes, MOJO_READ_DATA_FLAG_QUERY);
MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_QUERY;
MojoResult result = MojoReadData(consumer, &options, nullptr, &num_bytes);
CHECK_EQ(MOJO_RESULT_OK, result);
if (num_bytes == 0)
return std::string();
std::vector<char> buffer(num_bytes);
result = MojoReadData(consumer, buffer.data(), &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
result = MojoReadData(consumer, nullptr, buffer.data(), &num_bytes);
CHECK_EQ(MOJO_RESULT_OK, result);
CHECK_EQ(num_bytes, buffer.size());

@ -149,7 +149,7 @@ class DataPipeTransportStrategy : public BlobTransportStrategy {
mojo::ScopedDataPipeProducerHandle producer_handle;
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes =
std::min(expected_source_size, limits_.max_shared_memory_size);

@ -29,7 +29,7 @@ namespace blink {
void Mojo::createMessagePipe(MojoCreateMessagePipeResult& result_dict) {
MojoCreateMessagePipeOptions options = {0};
options.struct_size = sizeof(::MojoCreateMessagePipeOptions);
options.flags = MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_MESSAGE_PIPE_FLAG_NONE;
mojo::ScopedMessagePipeHandle handle0, handle1;
MojoResult result = mojo::CreateMessagePipe(&options, &handle0, &handle1);
@ -54,7 +54,7 @@ void Mojo::createDataPipe(const MojoCreateDataPipeOptions& options_dict,
::MojoCreateDataPipeOptions options = {0};
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = options_dict.elementNumBytes();
options.capacity_num_bytes = options_dict.capacityNumBytes();
@ -76,7 +76,7 @@ void Mojo::createSharedBuffer(unsigned num_bytes,
MojoCreateSharedBufferOptions* options = nullptr;
mojo::Handle handle;
MojoResult result =
MojoCreateSharedBuffer(options, num_bytes, handle.mutable_value());
MojoCreateSharedBuffer(num_bytes, options, handle.mutable_value());
result_dict.setResult(result);
if (result == MOJO_RESULT_OK) {

@ -146,16 +146,22 @@ void MojoHandle::writeData(const ArrayBufferOrArrayBufferView& buffer,
num_bytes = view->byteLength();
}
::MojoWriteDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoWriteData(handle_.get().value(), elements, &num_bytes, flags);
MojoWriteData(handle_.get().value(), elements, &num_bytes, &options);
result_dict.setResult(result);
result_dict.setNumBytes(result == MOJO_RESULT_OK ? num_bytes : 0);
}
void MojoHandle::queryData(MojoReadDataResult& result_dict) {
uint32_t num_bytes = 0;
MojoResult result = MojoReadData(handle_.get().value(), nullptr, &num_bytes,
MOJO_READ_DATA_FLAG_QUERY);
::MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_QUERY;
MojoResult result =
MojoReadData(handle_.get().value(), &options, nullptr, &num_bytes);
result_dict.setResult(result);
result_dict.setNumBytes(num_bytes);
}
@ -167,8 +173,11 @@ void MojoHandle::discardData(unsigned num_bytes,
if (options_dict.allOrNone())
flags |= MOJO_READ_DATA_FLAG_ALL_OR_NONE;
::MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoReadData(handle_.get().value(), nullptr, &num_bytes, flags);
MojoReadData(handle_.get().value(), &options, nullptr, &num_bytes);
result_dict.setResult(result);
result_dict.setNumBytes(result == MOJO_RESULT_OK ? num_bytes : 0);
}
@ -194,8 +203,11 @@ void MojoHandle::readData(ArrayBufferOrArrayBufferView& buffer,
num_bytes = view->byteLength();
}
::MojoReadDataOptions options;
options.struct_size = sizeof(options);
options.flags = flags;
MojoResult result =
MojoReadData(handle_.get().value(), elements, &num_bytes, flags);
MojoReadData(handle_.get().value(), &options, elements, &num_bytes);
result_dict.setResult(result);
result_dict.setNumBytes(result == MOJO_RESULT_OK ? num_bytes : 0);
}
@ -204,8 +216,8 @@ void MojoHandle::mapBuffer(unsigned offset,
unsigned num_bytes,
MojoMapBufferResult& result_dict) {
void* data = nullptr;
MojoResult result = MojoMapBuffer(handle_.get().value(), offset, num_bytes,
&data, MOJO_MAP_BUFFER_FLAG_NONE);
MojoResult result =
MojoMapBuffer(handle_.get().value(), offset, num_bytes, nullptr, &data);
result_dict.setResult(result);
if (result == MOJO_RESULT_OK) {
WTF::ArrayBufferContents::DataHandle data_handle(
@ -223,9 +235,9 @@ void MojoHandle::duplicateBufferHandle(
const MojoDuplicateBufferHandleOptions& options_dict,
MojoCreateSharedBufferResult& result_dict) {
::MojoDuplicateBufferHandleOptions options = {
sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_NONE};
if (options_dict.readOnly())
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_FLAG_READ_ONLY;
mojo::Handle handle;
MojoResult result = MojoDuplicateBufferHandle(handle_.get().value(), &options,

@ -24,7 +24,7 @@ TEST(BufferingDataPipeWriterTest, WriteMany) {
mojo::ScopedDataPipeConsumerHandle consumer;
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = kCapacity;

@ -300,7 +300,7 @@ bool RawResource::MatchPreload(const FetchParameters& params,
mojo::ScopedDataPipeConsumerHandle consumer;
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = kCapacity;