Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <fcntl.h> | 5 #include "irt_mojo_nonsfi.h" |
|
Mark Seaborn
2015/09/02 20:27:16
Nit: #includes should use the full path, so add "m
Sean Klein
2015/09/02 22:36:19
Done.
| |
| 6 #include <iostream> | |
| 7 | 6 |
| 8 #include "mojo/edk/embedder/embedder.h" | 7 #include "mojo/public/c/system/functions.h" |
| 9 #include "mojo/edk/embedder/simple_platform_support.h" | |
| 10 #include "mojo/public/platform/nacl/mojo_irt.h" | 8 #include "mojo/public/platform/nacl/mojo_irt.h" |
| 11 #include "native_client/src/public/irt_core.h" | 9 #include "native_client/src/public/irt_core.h" |
| 12 #include "native_client/src/public/nonsfi/elf_loader.h" | |
| 13 | 10 |
| 14 namespace { | 11 namespace { |
| 15 | 12 |
| 13 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID; | |
| 14 | |
| 15 MojoResult _MojoGetInitialHandle(MojoHandle* handle) { | |
| 16 *handle = g_mojo_handle; | |
| 17 return MOJO_RESULT_OK; | |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 void MojoSetInitialHandle(MojoHandle handle) { | |
| 23 g_mojo_handle = handle; | |
| 24 } | |
| 25 | |
| 16 const struct nacl_irt_mojo kIrtMojo = { | 26 const struct nacl_irt_mojo kIrtMojo = { |
|
Mark Seaborn
2015/09/02 20:27:16
Nit: these two vars can go inside the anon namespa
Sean Klein
2015/09/02 22:36:19
Done.
| |
| 17 MojoCreateSharedBuffer, | 27 MojoCreateSharedBuffer, |
| 18 MojoDuplicateBufferHandle, | 28 MojoDuplicateBufferHandle, |
| 19 MojoMapBuffer, | 29 MojoMapBuffer, |
| 20 MojoUnmapBuffer, | 30 MojoUnmapBuffer, |
| 21 MojoCreateDataPipe, | 31 MojoCreateDataPipe, |
| 22 MojoWriteData, | 32 MojoWriteData, |
| 23 MojoBeginWriteData, | 33 MojoBeginWriteData, |
| 24 MojoEndWriteData, | 34 MojoEndWriteData, |
| 25 MojoReadData, | 35 MojoReadData, |
| 26 MojoBeginReadData, | 36 MojoBeginReadData, |
| 27 MojoEndReadData, | 37 MojoEndReadData, |
| 28 MojoGetTimeTicksNow, | 38 MojoGetTimeTicksNow, |
| 29 MojoClose, | 39 MojoClose, |
| 30 MojoWait, | 40 MojoWait, |
| 31 MojoWaitMany, | 41 MojoWaitMany, |
| 32 MojoCreateMessagePipe, | 42 MojoCreateMessagePipe, |
| 33 MojoWriteMessage, | 43 MojoWriteMessage, |
| 34 MojoReadMessage, | 44 MojoReadMessage, |
| 35 nullptr, // TODO(smklein): Add _MojoGetInitialHandle. | 45 _MojoGetInitialHandle, |
| 36 }; | 46 }; |
| 37 | 47 |
| 38 const struct nacl_irt_interface kIrtInterfaces[] = { | 48 const struct nacl_irt_interface kIrtInterfaces[] = { |
| 39 { NACL_IRT_MOJO_v0_1, &kIrtMojo, sizeof(kIrtMojo), nullptr } | 49 { NACL_IRT_MOJO_v0_1, &kIrtMojo, sizeof(kIrtMojo), nullptr } |
| 40 }; | 50 }; |
| 41 | 51 |
| 42 size_t mojo_irt_nonsfi_query(const char* interface_ident, | 52 size_t mojo_irt_nonsfi_query(const char* interface_ident, |
| 43 void* table, size_t tablesize) { | 53 void* table, size_t tablesize) { |
| 44 size_t result = nacl_irt_query_list(interface_ident, | 54 size_t result = nacl_irt_query_list(interface_ident, |
| 45 table, | 55 table, |
| 46 tablesize, | 56 tablesize, |
| 47 kIrtInterfaces, | 57 kIrtInterfaces, |
| 48 sizeof(kIrtInterfaces)); | 58 sizeof(kIrtInterfaces)); |
| 49 if (result != 0) | 59 if (result != 0) |
| 50 return result; | 60 return result; |
| 51 return nacl_irt_query_core(interface_ident, table, tablesize); | 61 return nacl_irt_query_core(interface_ident, table, tablesize); |
| 52 } | 62 } |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 int main(int argc, char** argv, char** environ) { | |
| 57 nacl_irt_nonsfi_allow_dev_interfaces(); | |
| 58 if (argc < 2) { | |
| 59 std::cerr << "Usage: " << argv[0] << " <executable> <args...>\n"; | |
| 60 return 1; | |
| 61 } | |
| 62 const char* nexe_filename = argv[1]; | |
| 63 int fd = open(nexe_filename, O_RDONLY); | |
| 64 if (fd < 0) { | |
| 65 std::cerr << "Failed to open " << nexe_filename << ": " << | |
| 66 strerror(errno) << "\n"; | |
| 67 return 1; | |
| 68 } | |
| 69 uintptr_t entry = NaClLoadElfFile(fd); | |
| 70 | |
| 71 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | |
| 72 new mojo::embedder::SimplePlatformSupport())); | |
| 73 | |
| 74 return nacl_irt_nonsfi_entry(argc - 1, argv + 1, environ, | |
| 75 reinterpret_cast<nacl_entry_func_t>(entry), | |
| 76 mojo_irt_nonsfi_query); | |
| 77 } | |
| OLD | NEW |