Commit 04708acf authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

[mojo] Make failure to init more obvious

Currently when you try using Mojo without first initializing it
properly, you get an error message about the function not being
supported in "this version" of Mojo Core. This is marginally better
than a cryptic crash stack, but still misleading.

This CL detects when a missing function is due to a lack of Mojo
initialization and reports it as such.

Bug: 682732
Change-Id: Ia3f057171f2387a0387a7547a1a55fcc413cf7c0
Reviewed-on: https://chromium-review.googlesource.com/c/1337813Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#608503}
parent 3302b446
...@@ -36,24 +36,26 @@ base::ProtectedMemory<MojoGetSystemThunksFunction> g_get_thunks; ...@@ -36,24 +36,26 @@ base::ProtectedMemory<MojoGetSystemThunksFunction> g_get_thunks;
PROTECTED_MEMORY_SECTION base::ProtectedMemory<MojoSystemThunks> g_thunks; PROTECTED_MEMORY_SECTION base::ProtectedMemory<MojoSystemThunks> g_thunks;
MojoResult NotImplemented(const char* name) { MojoResult NotImplemented(const char* name) {
DLOG(ERROR) << "Function 'Mojo" << name if (g_thunks->size > 0) {
<< "()' not supported in this version of Mojo Core."; DLOG(ERROR) << "Function 'Mojo" << name
<< "()' not supported in this version of Mojo Core.";
return MOJO_RESULT_UNIMPLEMENTED;
}
LOG(FATAL)
<< "Mojo has not been initialized in this process. You must call "
<< "either mojo::core::Init() as an embedder, or |MojoInitialize()| if "
<< "using the mojo_core shared library.";
return MOJO_RESULT_UNIMPLEMENTED; return MOJO_RESULT_UNIMPLEMENTED;
} }
} // namespace } // namespace
// Macro to verify that the thunk symbol |name| is actually present in the #define INVOKE_THUNK(name, ...) \
// runtime version of Mojo Core that is currently in use. offsetof(MojoSystemThunks, name) < g_thunks->size \
#define FUNCTION_IS_IMPLEMENTED(name) \ ? base::UnsanitizedCfiCall(g_thunks, \
(reinterpret_cast<uintptr_t>(static_cast<const void*>(&g_thunks->name)) - \ &MojoSystemThunks::name)(__VA_ARGS__) \
reinterpret_cast<uintptr_t>(static_cast<const void*>(&g_thunks)) < \ : NotImplemented(#name)
g_thunks->size)
#define INVOKE_THUNK(name, ...) \
FUNCTION_IS_IMPLEMENTED(name) \
? base::UnsanitizedCfiCall(g_thunks, &MojoSystemThunks::name)(__VA_ARGS__) \
: NotImplemented(#name)
namespace mojo { namespace mojo {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment