Chromium Code Reviews| Index: mojo/public/platform/native/system_thunks.h |
| diff --git a/mojo/public/platform/native/system_thunks.h b/mojo/public/platform/native/system_thunks.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..387ac9230ee8ee122bb97e1e66b6e8594e45919f |
| --- /dev/null |
| +++ b/mojo/public/platform/native/system_thunks.h |
| @@ -0,0 +1,130 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |
| +#define MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |
| + |
|
viettrungluu
2014/04/09 23:06:44
nit: Should also include <stddef.h> for size_t.
DaveMoore
2014/04/10 18:58:58
Done.
|
| +#include "mojo/public/c/system/core.h" |
| + |
| +// The embedder needs to bind the basic Mojo Core functions of a DSO to those of |
| +// the embedder when loading a DSO that is dependent on mojo_system. |
| +// The typical usage would look like: |
| +// base::ScopedNativeLibrary app_library( |
| +// base::LoadNativeLibrary(app_path_, &error)); |
| +// typedef MojoResult (*MojoSetSystemThunksFn)(MojoSystemThunks*); |
| +// MojoSetSystemThunksFn mojo_set_system_thunks_fn = |
| +// reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( |
| +// "MojoSetSystemThunks")); |
| +// MojoSystemThunks system_thunks = MojoMakeSystemThunks(); |
| +// MojoResult set_result = mojo_set_system_thunks_fn(&system_thunks); |
| +// if (set_result != MOJO_RESULT_OK) { |
| +// LOG(ERROR) |
| +// << "Invalid DSO. Expected MojoSystemThunks size: " |
| +// << system_thunks.size; |
| +// } |
| + |
| +// Structure used to bind the basic Mojo Core functions of a DSO to those of |
| +// the embedder. |
| +// This is the ABI between the embedder and the DSO. It can only have new |
| +// functions added to the end. No other changes are supported. |
| +#pragma pack(push, 8) |
| +struct MojoSystemThunks { |
| + size_t size; // Should be set to sizeof(MojoSystemThunks). |
| + MojoTimeTicks (*GetTimeTicksNow)(); |
| + MojoResult (*Close)(MojoHandle handle); |
|
viettrungluu
2014/04/09 23:06:44
Comment: It's unnecessary to include the parameter
|
| + MojoResult (*Wait)(MojoHandle handle, |
| + MojoWaitFlags flags, |
| + MojoDeadline deadline); |
| + MojoResult (*WaitMany)(const MojoHandle* handles, |
| + const MojoWaitFlags* flags, |
| + uint32_t num_handles, |
| + MojoDeadline deadline); |
| + MojoResult (*CreateMessagePipe)(MojoHandle* message_pipe_handle0, |
| + MojoHandle* message_pipe_handle1); |
| + MojoResult (*WriteMessage)(MojoHandle message_pipe_handle, |
| + const void* bytes, |
| + uint32_t num_bytes, |
| + const MojoHandle* handles, |
| + uint32_t num_handles, |
| + MojoWriteMessageFlags flags); |
| + MojoResult (*ReadMessage)(MojoHandle message_pipe_handle, |
| + void* bytes, |
| + uint32_t* num_bytes, |
| + MojoHandle* handles, |
| + uint32_t* num_handles, |
| + MojoReadMessageFlags flags); |
| + MojoResult (*CreateDataPipe)(const 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 MojoCreateSharedBufferOptions* options, |
| + uint64_t num_bytes, |
| + MojoHandle* shared_buffer_handle); |
| + MojoResult (*DuplicateBufferHandle)( |
| + MojoHandle buffer_handle, |
| + const 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); |
| +}; |
| +#pragma pack(pop) |
| + |
| +// Intended to be called from the embedder. Returns a |MojoCore| initialized |
|
viettrungluu
2014/04/09 23:06:44
MojoCore -> MojoSystemThunks
|
| +// to contain pointers to each of the embedder's MojoCore functions. |
|
viettrungluu
2014/04/09 23:06:44
"
|
| +static inline const MojoSystemThunks MojoMakeSystemThunks() { |
|
viettrungluu
2014/04/09 23:06:44
const is unnecessary
|
| + MojoSystemThunks system_thunks { |
| + sizeof(MojoSystemThunks), |
| + MojoGetTimeTicksNow, |
| + MojoClose, |
| + MojoWait, |
| + MojoWaitMany, |
| + MojoCreateMessagePipe, |
| + MojoWriteMessage, |
| + MojoReadMessage, |
| + MojoCreateDataPipe, |
| + MojoWriteData, |
| + MojoBeginWriteData, |
| + MojoEndWriteData, |
| + MojoReadData, |
| + MojoBeginReadData, |
| + MojoEndReadData, |
| + MojoCreateSharedBuffer, |
| + MojoDuplicateBufferHandle, |
| + MojoMapBuffer, |
| + MojoUnmapBuffer |
| + }; |
| + return system_thunks; |
| +} |
| + |
| +typedef size_t (*MojoSetSystemThunksFn)(const MojoSystemThunks* mojo_core); |
| + |
| +// Called to set the MojoCore functionality of a DSO. Returns the expected size. |
|
viettrungluu
2014/04/09 23:06:44
MojoCore
|
| +extern "C" MOJO_SYSTEM_EXPORT size_t MojoSetSystemThunks( |
|
viettrungluu
2014/04/09 23:06:44
Shouldn't be in this header, per my 2nd batch of c
|
| + const MojoSystemThunks* mojo_core); |
| + |
| +#endif // MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |