Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Unified Diff: mojo/edk/embedder/core_entrypoints.cc

Issue 1052723003: NaCl: create a separate namespace for Mojo handles. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/edk/embedder/core_entrypoints.cc
diff --git a/mojo/edk/embedder/core_entrypoints.cc b/mojo/edk/embedder/core_entrypoints.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d0a0e0407d725fd3b3429dd66bcc33a2e3319e77
--- /dev/null
+++ b/mojo/edk/embedder/core_entrypoints.cc
@@ -0,0 +1,270 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/edk/embedder/embedder_internal.h"
+#include "mojo/edk/system/core.h"
+#include "mojo/edk/system/dispatcher.h"
+#include "mojo/public/c/system/buffer.h"
+#include "mojo/public/c/system/data_pipe.h"
+#include "mojo/public/c/system/functions.h"
+#include "mojo/public/c/system/message_pipe.h"
+#include "mojo/public/platform/native/core_system_api.h"
+
+using mojo::embedder::internal::g_core;
+using mojo::system::MakeUserPointer;
+
+// HACK
viettrungluu 2015/04/01 23:36:18 delete
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+using mojo::system::Core;
viettrungluu 2015/04/01 23:36:18 These are OK, so you can combine them with the pre
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+using mojo::system::Dispatcher;
+
+// Definitions of the core system functions.
+extern "C" {
+
+MojoCoreHandle MojoCoreGetDefaultCore() {
+ return static_cast<MojoCoreHandle>(g_core);
+}
+
+// TODO before commiting: take core as parameter rather than using g_core?
+MojoCoreHandle MojoCoreCreateCore() {
+ Core* createdCore = new Core(g_core->platform_support());
+ return static_cast<MojoCoreHandle>(createdCore);
+}
+
+MojoResult MojoCoreTransferHandle(MojoCoreHandle from_core,
+ MojoHandle handle,
+ MojoCoreHandle to_core,
+ MojoHandle* result_handle) {
+ Core* fromCorePtr = static_cast<Core*>(from_core);
viettrungluu 2015/04/01 23:36:18 nit: no camelCase
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+ if (fromCorePtr == nullptr) {
viettrungluu 2015/04/01 23:36:18 nit: For consistency, please omit braces from one-
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+
+ if (handle == MOJO_HANDLE_INVALID) {
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+
+ Core* toCorePtr = static_cast<Core*>(to_core);
+ if (toCorePtr == nullptr) {
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+
+ if (result_handle == nullptr) {
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+
+ scoped_refptr<Dispatcher> d = fromCorePtr->PopDispatcher(handle);
+ if (d.get() == nullptr) {
+ // HACK this could also be because the handle does not exist.
viettrungluu 2015/04/01 23:36:18 Hmmm, this seems bad. Maybe you should make PopDis
Nick Bray (chromium) 2015/04/04 00:09:08 Done.
+ return MOJO_RESULT_BUSY;
+ }
+
+ MojoHandle createdHandle = toCorePtr->AddDispatcher(d);
+ // HACK can we recover in this case?
viettrungluu 2015/04/01 23:36:18 The answer is no.
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+ DCHECK(createdHandle != MOJO_HANDLE_INVALID);
viettrungluu 2015/04/01 23:36:18 But probably the right thing to do is not to just
Nick Bray (chromium) 2015/04/04 00:09:08 Done.
+
+ // TODO MakeUserPointer?
viettrungluu 2015/04/01 23:36:18 Probably.
Nick Bray (chromium) 2015/04/04 00:09:09 Done.
+ *result_handle = createdHandle;
+ return MOJO_RESULT_OK;
+}
+
+MojoResult MojoCoreCloseCore(MojoCoreHandle core) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ DCHECK(false);
+ return MOJO_RESULT_OK;
+}
+
+MojoTimeTicks MojoCoreGetTimeTicksNow(MojoCoreHandle core) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->GetTimeTicksNow();
+}
+
+MojoResult MojoCoreClose(MojoCoreHandle core, MojoHandle handle) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->Close(handle);
+}
+
+MojoResult MojoCoreWait(MojoCoreHandle core,
+ MojoHandle handle,
+ MojoHandleSignals signals,
+ MojoDeadline deadline,
+ struct MojoHandleSignalsState* signals_state) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->Wait(handle, signals, deadline,
+ MakeUserPointer(signals_state));
+}
+
+MojoResult MojoCoreWaitMany(MojoCoreHandle core,
+ const MojoHandle* handles,
+ const MojoHandleSignals* signals,
+ uint32_t num_handles,
+ MojoDeadline deadline,
+ uint32_t* result_index,
+ struct MojoHandleSignalsState* signals_states) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals),
+ num_handles, deadline, MakeUserPointer(result_index),
+ MakeUserPointer(signals_states));
+}
+
+MojoResult MojoCoreCreateMessagePipe(
+ MojoCoreHandle core,
+ const struct MojoCreateMessagePipeOptions* options,
+ MojoHandle* message_pipe_handle0,
+ MojoHandle* message_pipe_handle1) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->CreateMessagePipe(MakeUserPointer(options),
+ MakeUserPointer(message_pipe_handle0),
+ MakeUserPointer(message_pipe_handle1));
+}
+
+MojoResult MojoCoreWriteMessage(MojoCoreHandle core,
+ MojoHandle message_pipe_handle,
+ const void* bytes,
+ uint32_t num_bytes,
+ const MojoHandle* handles,
+ uint32_t num_handles,
+ MojoWriteMessageFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->WriteMessage(message_pipe_handle, MakeUserPointer(bytes),
+ num_bytes, MakeUserPointer(handles), num_handles,
+ flags);
+}
+
+MojoResult MojoCoreReadMessage(MojoCoreHandle core,
+ MojoHandle message_pipe_handle,
+ void* bytes,
+ uint32_t* num_bytes,
+ MojoHandle* handles,
+ uint32_t* num_handles,
+ MojoReadMessageFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->ReadMessage(
+ message_pipe_handle, MakeUserPointer(bytes), MakeUserPointer(num_bytes),
+ MakeUserPointer(handles), MakeUserPointer(num_handles), flags);
+}
+
+MojoResult MojoCoreCreateDataPipe(
+ MojoCoreHandle core,
+ const struct MojoCreateDataPipeOptions* options,
+ MojoHandle* data_pipe_producer_handle,
+ MojoHandle* data_pipe_consumer_handle) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->CreateDataPipe(MakeUserPointer(options),
+ MakeUserPointer(data_pipe_producer_handle),
+ MakeUserPointer(data_pipe_consumer_handle));
+}
+
+MojoResult MojoCoreWriteData(MojoCoreHandle core,
+ MojoHandle data_pipe_producer_handle,
+ const void* elements,
+ uint32_t* num_elements,
+ MojoWriteDataFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->WriteData(data_pipe_producer_handle,
+ MakeUserPointer(elements),
+ MakeUserPointer(num_elements), flags);
+}
+
+MojoResult MojoCoreBeginWriteData(MojoCoreHandle core,
+ MojoHandle data_pipe_producer_handle,
+ void** buffer,
+ uint32_t* buffer_num_elements,
+ MojoWriteDataFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->BeginWriteData(data_pipe_producer_handle,
+ MakeUserPointer(buffer),
+ MakeUserPointer(buffer_num_elements), flags);
+}
+
+MojoResult MojoCoreEndWriteData(MojoCoreHandle core,
+ MojoHandle data_pipe_producer_handle,
+ uint32_t num_elements_written) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->EndWriteData(data_pipe_producer_handle, num_elements_written);
+}
+
+MojoResult MojoCoreReadData(MojoCoreHandle core,
+ MojoHandle data_pipe_consumer_handle,
+ void* elements,
+ uint32_t* num_elements,
+ MojoReadDataFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements),
+ MakeUserPointer(num_elements), flags);
+}
+
+MojoResult MojoCoreBeginReadData(MojoCoreHandle core,
+ MojoHandle data_pipe_consumer_handle,
+ const void** buffer,
+ uint32_t* buffer_num_elements,
+ MojoReadDataFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->BeginReadData(data_pipe_consumer_handle,
+ MakeUserPointer(buffer),
+ MakeUserPointer(buffer_num_elements), flags);
+}
+
+MojoResult MojoCoreEndReadData(MojoCoreHandle core,
+ MojoHandle data_pipe_consumer_handle,
+ uint32_t num_elements_read) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->EndReadData(data_pipe_consumer_handle, num_elements_read);
+}
+
+MojoResult MojoCoreCreateSharedBuffer(
+ MojoCoreHandle core,
+ const struct MojoCreateSharedBufferOptions* options,
+ uint64_t num_bytes,
+ MojoHandle* shared_buffer_handle) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->CreateSharedBuffer(MakeUserPointer(options), num_bytes,
+ MakeUserPointer(shared_buffer_handle));
+}
+
+MojoResult MojoCoreDuplicateBufferHandle(
+ MojoCoreHandle core,
+ MojoHandle buffer_handle,
+ const struct MojoDuplicateBufferHandleOptions* options,
+ MojoHandle* new_buffer_handle) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options),
+ MakeUserPointer(new_buffer_handle));
+}
+
+MojoResult MojoCoreMapBuffer(MojoCoreHandle core,
+ MojoHandle buffer_handle,
+ uint64_t offset,
+ uint64_t num_bytes,
+ void** buffer,
+ MojoMapBufferFlags flags) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->MapBuffer(buffer_handle, offset, num_bytes,
+ MakeUserPointer(buffer), flags);
+}
+
+MojoResult MojoCoreUnmapBuffer(MojoCoreHandle core, void* buffer) {
+ mojo::system::Core* corePtr = static_cast<mojo::system::Core*>(core);
+ DCHECK(corePtr);
+ return corePtr->UnmapBuffer(MakeUserPointer(buffer));
+}
+
+} // extern "C"
« no previous file with comments | « mojo/edk/embedder/BUILD.gn ('k') | mojo/edk/system/core.h » ('j') | mojo/edk/system/core.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698