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

Side by Side Diff: mojo/shell/dynamic_service_runner.cc

Issue 691653002: Factor out loading & running of DSOs (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Review nits Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « mojo/shell/dynamic_service_runner.h ('k') | mojo/shell/in_process_dynamic_service_runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/shell/dynamic_service_runner.h"
6
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "mojo/public/platform/native/gles2_impl_chromium_sync_point_thunks.h"
10 #include "mojo/public/platform/native/gles2_impl_chromium_texture_mailbox_thunks .h"
11 #include "mojo/public/platform/native/gles2_impl_thunks.h"
12 #include "mojo/public/platform/native/gles2_thunks.h"
13 #include "mojo/public/platform/native/system_thunks.h"
14
15 namespace mojo {
16 namespace shell {
17
18 namespace {
19
20 template <typename Thunks>
21 bool SetThunks(Thunks (*make_thunks)(),
22 const char* function_name,
23 base::NativeLibrary library) {
24 typedef size_t (*SetThunksFn)(const Thunks* thunks);
25 SetThunksFn set_thunks =
26 reinterpret_cast<SetThunksFn>(base::GetFunctionPointerFromNativeLibrary(
27 library, function_name));
28 if (!set_thunks)
29 return false;
30 Thunks thunks = make_thunks();
31 size_t expected_size = set_thunks(&thunks);
32 if (expected_size > sizeof(Thunks)) {
33 LOG(ERROR) << "Invalid app library: expected " << function_name
34 << " to return thunks of size: " << expected_size;
35 return false;
36 }
37 return true;
38 }
39
40 } // namespace
41
42 base::NativeLibrary DynamicServiceRunner::LoadAndRunService(
43 const base::FilePath& app_path,
44 ScopedMessagePipeHandle service_handle) {
45 #if defined(COMPONENT_BUILD)
46 NOTREACHED() << "Only static builds are supported";
47 return nullptr;
48 #endif
49
50 DVLOG(2) << "Loading/running Mojo app in process from library: "
51 << app_path.value();
52 base::NativeLibraryLoadError error;
53 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, &error);
54 do {
55 if (!app_library) {
56 LOG(ERROR) << "Failed to load app library (error: " << error.ToString()
57 << ")";
58 break;
59 }
60 // Go shared library support requires us to initialize the runtime before we
61 // start running any go code. This is a temporary patch.
62 typedef void (*InitGoRuntimeFn)();
63 InitGoRuntimeFn init_go_runtime = reinterpret_cast<InitGoRuntimeFn>(
64 base::GetFunctionPointerFromNativeLibrary(
65 app_library, "InitGoRuntime"));
66 if (init_go_runtime) {
67 DVLOG(2) << "InitGoRuntime: Initializing Go Runtime found in app";
68 init_go_runtime();
69 }
70
71 if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) {
72 LOG(ERROR) << app_path.value() << " MojoSetSystemThunks not found";
73 break;
74 }
75
76 if (SetThunks(&MojoMakeGLES2ControlThunks,
77 "MojoSetGLES2ControlThunks",
78 app_library)) {
79 // If we have the control thunks, we should also have the GLES2
80 // implementation thunks.
81 if (!SetThunks(&MojoMakeGLES2ImplThunks,
82 "MojoSetGLES2ImplThunks",
83 app_library)) {
84 LOG(ERROR) << app_path.value()
85 << " has MojoSetGLES2ControlThunks, "
86 "but doesn't have MojoSetGLES2ImplThunks.";
87 break;
88 }
89
90 // If the application is using GLES2 extension points, register those
91 // thunks. Applications may use or not use any of these, so don't warn if
92 // they are missing.
93 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks,
94 "MojoSetGLES2ImplChromiumTextureMailboxThunks",
95 app_library);
96 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks,
97 "MojoSetGLES2ImplChromiumSyncPointThunks",
98 app_library);
99 }
100 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because
101 // not everything is a visual app.
102
103 typedef MojoResult (*MojoMainFunction)(MojoHandle);
104 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(
105 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain"));
106 if (!main_function) {
107 LOG(ERROR) << app_path.value() << " MojoMain not found";
108 break;
109 }
110 // |MojoMain()| takes ownership of the service handle.
111 MojoResult result = main_function(service_handle.release().value());
112 if (result < MOJO_RESULT_OK) {
113 LOG(ERROR) << app_path.value()
114 << " MojoMain returned error(" << result << ")";
115 }
116 } while (false);
117
118 return app_library;
119 }
120
121 } // namespace shell
122 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/dynamic_service_runner.h ('k') | mojo/shell/in_process_dynamic_service_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698