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.
5 // This is the Android-specific Chromium linker, a tiny shared library
6 // implementing a custom dynamic linker that can be used to load the
7 // real Chromium libraries (e.g. libcontentshell.so).
9 // The main point of this linker is to be able to share the RELRO
10 // section of libcontentshell.so (or equivalent) between the browser and
13 // This source code *cannot* depend on anything from base/ or the C++
14 // STL, to keep the final library small, and avoid ugly dependency issues.
16 #include <android/log.h>
17 #include <crazy_linker.h>
25 // Set this to 1 to enable debug traces to the Android log.
26 // Note that LOG() from "base/logging.h" cannot be used, since it is
27 // in base/ which hasn't been loaded yet.
30 #define TAG "chromium_android_linker"
33 #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
35 #define LOG_INFO(...) ((void)0)
37 #define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
39 #define UNUSED __attribute__((unused))
43 // A simply scoped UTF String class that can be initialized from
44 // a Java jstring handle. Modeled like std::string, which cannot
48 String(JNIEnv
* env
, jstring str
);
55 const char* c_str() const { return ptr_
? ptr_
: ""; }
56 size_t size() const { return size_
; }
63 String::String(JNIEnv
* env
, jstring str
) {
64 size_
= env
->GetStringUTFLength(str
);
65 ptr_
= static_cast<char*>(::malloc(size_
+ 1));
67 // Note: the result contains Java "modified UTF-8" bytes.
68 // Good enough for the linker though.
69 const char* bytes
= env
->GetStringUTFChars(str
, NULL
);
70 ::memcpy(ptr_
, bytes
, size_
);
73 env
->ReleaseStringUTFChars(str
, bytes
);
76 // Return true iff |address| is a valid address for the target CPU.
77 bool IsValidAddress(jlong address
) {
78 return static_cast<jlong
>(static_cast<size_t>(address
)) == address
;
81 // Find the jclass JNI reference corresponding to a given |class_name|.
82 // |env| is the current JNI environment handle.
83 // On success, return true and set |*clazz|.
84 bool InitClassReference(JNIEnv
* env
, const char* class_name
, jclass
* clazz
) {
85 *clazz
= env
->FindClass(class_name
);
87 LOG_ERROR("Could not find class for %s", class_name
);
93 // Initialize a jfieldID corresponding to the field of a given |clazz|,
94 // with name |field_name| and signature |field_sig|.
95 // |env| is the current JNI environment handle.
96 // On success, return true and set |*field_id|.
97 bool InitFieldId(JNIEnv
* env
,
99 const char* field_name
,
100 const char* field_sig
,
101 jfieldID
* field_id
) {
102 *field_id
= env
->GetFieldID(clazz
, field_name
, field_sig
);
104 LOG_ERROR("Could not find ID for field '%s'", field_name
);
108 "%s: Found ID %p for field '%s'", __FUNCTION__
, *field_id
, field_name
);
112 // Initialize a jmethodID corresponding to the static method of a given
113 // |clazz|, with name |method_name| and signature |method_sig|.
114 // |env| is the current JNI environment handle.
115 // On success, return true and set |*method_id|.
116 bool InitStaticMethodId(JNIEnv
* env
,
118 const char* method_name
,
119 const char* method_sig
,
120 jmethodID
* method_id
) {
121 *method_id
= env
->GetStaticMethodID(clazz
, method_name
, method_sig
);
123 LOG_ERROR("Could not find ID for static method '%s'", method_name
);
126 LOG_INFO("%s: Found ID %p for static method '%s'",
127 __FUNCTION__
, *method_id
, method_name
);
131 // A class used to model the field IDs of the org.chromium.base.Linker
132 // LibInfo inner class, used to communicate data with the Java side
134 struct LibInfo_class
{
135 jfieldID load_address_id
;
136 jfieldID load_size_id
;
137 jfieldID relro_start_id
;
138 jfieldID relro_size_id
;
139 jfieldID relro_fd_id
;
141 // Initialize an instance.
142 bool Init(JNIEnv
* env
) {
144 if (!InitClassReference(
145 env
, "org/chromium/base/library_loader/Linker$LibInfo", &clazz
)) {
149 return InitFieldId(env
, clazz
, "mLoadAddress", "J", &load_address_id
) &&
150 InitFieldId(env
, clazz
, "mLoadSize", "J", &load_size_id
) &&
151 InitFieldId(env
, clazz
, "mRelroStart", "J", &relro_start_id
) &&
152 InitFieldId(env
, clazz
, "mRelroSize", "J", &relro_size_id
) &&
153 InitFieldId(env
, clazz
, "mRelroFd", "I", &relro_fd_id
);
156 void SetLoadInfo(JNIEnv
* env
,
157 jobject library_info_obj
,
160 env
->SetLongField(library_info_obj
, load_address_id
, load_address
);
161 env
->SetLongField(library_info_obj
, load_size_id
, load_size
);
164 // Use this instance to convert a RelroInfo reference into
165 // a crazy_library_info_t.
166 void GetRelroInfo(JNIEnv
* env
,
167 jobject library_info_obj
,
171 *relro_start
= static_cast<size_t>(
172 env
->GetLongField(library_info_obj
, relro_start_id
));
175 static_cast<size_t>(env
->GetLongField(library_info_obj
, relro_size_id
));
177 *relro_fd
= env
->GetIntField(library_info_obj
, relro_fd_id
);
180 void SetRelroInfo(JNIEnv
* env
,
181 jobject library_info_obj
,
185 env
->SetLongField(library_info_obj
, relro_start_id
, relro_start
);
186 env
->SetLongField(library_info_obj
, relro_size_id
, relro_size
);
187 env
->SetIntField(library_info_obj
, relro_fd_id
, relro_fd
);
191 static LibInfo_class s_lib_info_fields
;
193 // The linker uses a single crazy_context_t object created on demand.
194 // There is no need to protect this against concurrent access, locking
195 // is already handled on the Java side.
196 static crazy_context_t
* s_crazy_context
;
198 crazy_context_t
* GetCrazyContext() {
199 if (!s_crazy_context
) {
200 // Create new context.
201 s_crazy_context
= crazy_context_create();
203 // Ensure libraries located in the same directory as the linker
204 // can be loaded before system ones.
205 crazy_context_add_search_path_for_address(
206 s_crazy_context
, reinterpret_cast<void*>(&s_crazy_context
));
209 return s_crazy_context
;
212 // A scoped crazy_library_t that automatically closes the handle
213 // on scope exit, unless Release() has been called.
214 class ScopedLibrary
{
216 ScopedLibrary() : lib_(NULL
) {}
220 crazy_library_close_with_context(lib_
, GetCrazyContext());
223 crazy_library_t
* Get() { return lib_
; }
225 crazy_library_t
** GetPtr() { return &lib_
; }
227 crazy_library_t
* Release() {
228 crazy_library_t
* ret
= lib_
;
234 crazy_library_t
* lib_
;
239 template <class LibraryOpener
>
240 bool GenericLoadLibrary(
242 const char* library_name
, jlong load_address
, jobject lib_info_obj
,
243 const LibraryOpener
& opener
) {
244 crazy_context_t
* context
= GetCrazyContext();
246 if (!IsValidAddress(load_address
)) {
247 LOG_ERROR("%s: Invalid address 0x%llx", __FUNCTION__
, load_address
);
251 // Set the desired load address (0 means randomize it).
252 crazy_context_set_load_address(context
, static_cast<size_t>(load_address
));
254 ScopedLibrary library
;
255 if (!opener
.Open(library
.GetPtr(), library_name
, context
)) {
259 crazy_library_info_t info
;
260 if (!crazy_library_get_info(library
.Get(), context
, &info
)) {
261 LOG_ERROR("%s: Could not get library information for %s: %s",
264 crazy_context_get_error(context
));
268 // Release library object to keep it alive after the function returns.
271 s_lib_info_fields
.SetLoadInfo(
272 env
, lib_info_obj
, info
.load_address
, info
.load_size
);
273 LOG_INFO("%s: Success loading library %s", __FUNCTION__
, library_name
);
277 // Used for opening the library in a regular file.
278 class FileLibraryOpener
{
281 crazy_library_t
** library
,
282 const char* library_name
,
283 crazy_context_t
* context
) const;
286 bool FileLibraryOpener::Open(
287 crazy_library_t
** library
,
288 const char* library_name
,
289 crazy_context_t
* context
) const {
290 if (!crazy_library_open(library
, library_name
, context
)) {
291 LOG_ERROR("%s: Could not open %s: %s",
294 crazy_context_get_error(context
));
300 // Used for opening the library in a zip file.
301 class ZipLibraryOpener
{
303 explicit ZipLibraryOpener(const char* zip_file
) : zip_file_(zip_file
) {}
305 crazy_library_t
** library
,
306 const char* library_name
,
307 crazy_context_t
* context
) const;
309 const char* zip_file_
;
312 bool ZipLibraryOpener::Open(
313 crazy_library_t
** library
,
314 const char* library_name
,
315 crazy_context_t
* context
) const {
316 if (!crazy_library_open_in_zip_file(
317 library
, zip_file_
, library_name
, context
)) {
318 LOG_ERROR("%s: Could not open %s in zip file %s: %s",
319 __FUNCTION__
, library_name
, zip_file_
,
320 crazy_context_get_error(context
));
326 } // unnamed namespace
328 // Load a library with the chromium linker. This will also call its
329 // JNI_OnLoad() method, which shall register its methods. Note that
330 // lazy native method resolution will _not_ work after this, because
331 // Dalvik uses the system's dlsym() which won't see the new library,
332 // so explicit registration is mandatory.
333 // |env| is the current JNI environment handle.
334 // |clazz| is the static class handle for org.chromium.base.Linker,
335 // and is ignored here.
336 // |library_name| is the library name (e.g. libfoo.so).
337 // |load_address| is an explicit load address.
338 // |library_info| is a LibInfo handle used to communicate information
339 // with the Java side.
340 // Return true on success.
341 jboolean
LoadLibrary(JNIEnv
* env
,
343 jstring library_name
,
345 jobject lib_info_obj
) {
346 String
lib_name(env
, library_name
);
347 FileLibraryOpener opener
;
348 return GenericLoadLibrary(
349 env
, lib_name
.c_str(),
350 static_cast<size_t>(load_address
), lib_info_obj
, opener
);
353 // Load a library from a zipfile with the chromium linker. The
354 // library in the zipfile must be uncompressed and page aligned.
355 // The basename of the library is given. The library is expected
356 // to be lib/<abi_tag>/crazy.<basename>. The <abi_tag> used will be the
357 // same as the abi for this linker. The "crazy." prefix is included
358 // so that the Android Package Manager doesn't extract the library into
361 // Loading the library will also call its JNI_OnLoad() method, which
362 // shall register its methods. Note that lazy native method resolution
363 // will _not_ work after this, because Dalvik uses the system's dlsym()
364 // which won't see the new library, so explicit registration is mandatory.
366 // |env| is the current JNI environment handle.
367 // |clazz| is the static class handle for org.chromium.base.Linker,
368 // and is ignored here.
369 // |zipfile_name| is the filename of the zipfile containing the library.
370 // |library_name| is the library base name (e.g. libfoo.so).
371 // |load_address| is an explicit load address.
372 // |library_info| is a LibInfo handle used to communicate information
373 // with the Java side.
374 // Returns true on success.
375 jboolean
LoadLibraryInZipFile(JNIEnv
* env
,
377 jstring zipfile_name
,
378 jstring library_name
,
380 jobject lib_info_obj
) {
381 String
zipfile_name_str(env
, zipfile_name
);
382 String
lib_name(env
, library_name
);
383 ZipLibraryOpener
opener(zipfile_name_str
.c_str());
384 return GenericLoadLibrary(
385 env
, lib_name
.c_str(),
386 static_cast<size_t>(load_address
), lib_info_obj
, opener
);
389 // Enable the fallback due to lack of support for mapping the APK file with
390 // executable permission in the crazy linker.
392 // |env| is the current JNI environment handle and is ignored here.
393 // |clazz| is the static class handle for org.chromium.base.Linker,
394 // and is ignored here.
395 void EnableNoMapExecSupportFallback(JNIEnv
* env
, jclass clazz
) {
396 crazy_context_t
* context
= GetCrazyContext();
397 crazy_context_set_no_map_exec_support_fallback_enabled(context
, true);
400 // Class holding the Java class and method ID for the Java side Linker
401 // postCallbackOnMainThread method.
402 struct JavaCallbackBindings_class
{
406 // Initialize an instance.
407 bool Init(JNIEnv
* env
, jclass linker_class
) {
408 clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(linker_class
));
409 return InitStaticMethodId(env
,
411 "postCallbackOnMainThread",
417 static JavaCallbackBindings_class s_java_callback_bindings
;
419 // Designated receiver function for callbacks from Java. Its name is known
421 // |env| is the current JNI environment handle and is ignored here.
422 // |clazz| is the static class handle for org.chromium.base.Linker,
423 // and is ignored here.
424 // |arg| is a pointer to an allocated crazy_callback_t, deleted after use.
425 void RunCallbackOnUiThread(JNIEnv
* env
, jclass clazz
, jlong arg
) {
426 crazy_callback_t
* callback
= reinterpret_cast<crazy_callback_t
*>(arg
);
428 LOG_INFO("%s: Called back from java with handler %p, opaque %p",
429 __FUNCTION__
, callback
->handler
, callback
->opaque
);
431 crazy_callback_run(callback
);
435 // Request a callback from Java. The supplied crazy_callback_t is valid only
436 // for the duration of this call, so we copy it to a newly allocated
437 // crazy_callback_t and then call the Java side's postCallbackOnMainThread.
438 // This will call back to to our RunCallbackOnUiThread some time
439 // later on the UI thread.
440 // |callback_request| is a crazy_callback_t.
441 // |poster_opaque| is unused.
442 // Returns true if the callback request succeeds.
443 static bool PostForLaterExecution(crazy_callback_t
* callback_request
,
444 void* poster_opaque UNUSED
) {
445 crazy_context_t
* context
= GetCrazyContext();
448 int minimum_jni_version
;
449 crazy_context_get_java_vm(context
,
450 reinterpret_cast<void**>(&vm
),
451 &minimum_jni_version
);
453 // Do not reuse JNIEnv from JNI_OnLoad, but retrieve our own.
455 if (JNI_OK
!= vm
->GetEnv(
456 reinterpret_cast<void**>(&env
), minimum_jni_version
)) {
457 LOG_ERROR("Could not create JNIEnv");
461 // Copy the callback; the one passed as an argument may be temporary.
462 crazy_callback_t
* callback
= new crazy_callback_t();
463 *callback
= *callback_request
;
465 LOG_INFO("%s: Calling back to java with handler %p, opaque %p",
466 __FUNCTION__
, callback
->handler
, callback
->opaque
);
468 jlong arg
= static_cast<jlong
>(reinterpret_cast<uintptr_t>(callback
));
470 env
->CallStaticVoidMethod(
471 s_java_callback_bindings
.clazz
, s_java_callback_bindings
.method_id
, arg
);
473 // Back out and return false if we encounter a JNI exception.
474 if (env
->ExceptionCheck() == JNI_TRUE
) {
475 env
->ExceptionDescribe();
476 env
->ExceptionClear();
484 jboolean
CreateSharedRelro(JNIEnv
* env
,
486 jstring library_name
,
488 jobject lib_info_obj
) {
489 String
lib_name(env
, library_name
);
491 LOG_INFO("%s: Called for %s", __FUNCTION__
, lib_name
.c_str());
493 if (!IsValidAddress(load_address
)) {
494 LOG_ERROR("%s: Invalid address 0x%llx", __FUNCTION__
, load_address
);
498 ScopedLibrary library
;
499 if (!crazy_library_find_by_name(lib_name
.c_str(), library
.GetPtr())) {
500 LOG_ERROR("%s: Could not find %s", __FUNCTION__
, lib_name
.c_str());
504 crazy_context_t
* context
= GetCrazyContext();
505 size_t relro_start
= 0;
506 size_t relro_size
= 0;
509 if (!crazy_library_create_shared_relro(library
.Get(),
511 static_cast<size_t>(load_address
),
515 LOG_ERROR("%s: Could not create shared RELRO sharing for %s: %s\n",
518 crazy_context_get_error(context
));
522 s_lib_info_fields
.SetRelroInfo(
523 env
, lib_info_obj
, relro_start
, relro_size
, relro_fd
);
527 jboolean
UseSharedRelro(JNIEnv
* env
,
529 jstring library_name
,
530 jobject lib_info_obj
) {
531 String
lib_name(env
, library_name
);
533 LOG_INFO("%s: called for %s, lib_info_ref=%p",
538 ScopedLibrary library
;
539 if (!crazy_library_find_by_name(lib_name
.c_str(), library
.GetPtr())) {
540 LOG_ERROR("%s: Could not find %s", __FUNCTION__
, lib_name
.c_str());
544 crazy_context_t
* context
= GetCrazyContext();
545 size_t relro_start
= 0;
546 size_t relro_size
= 0;
548 s_lib_info_fields
.GetRelroInfo(
549 env
, lib_info_obj
, &relro_start
, &relro_size
, &relro_fd
);
551 LOG_INFO("%s: library=%s relro start=%p size=%p fd=%d",
558 if (!crazy_library_use_shared_relro(
559 library
.Get(), context
, relro_start
, relro_size
, relro_fd
)) {
560 LOG_ERROR("%s: Could not use shared RELRO for %s: %s",
563 crazy_context_get_error(context
));
567 LOG_INFO("%s: Library %s using shared RELRO section!",
574 jboolean
CanUseSharedRelro(JNIEnv
* env
, jclass clazz
) {
575 return crazy_system_can_share_relro();
578 jlong
GetRandomBaseLoadAddress(JNIEnv
* env
, jclass clazz
, jlong bytes
) {
580 mmap(NULL
, bytes
, PROT_NONE
, MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
581 if (address
== MAP_FAILED
) {
582 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__
);
585 munmap(address
, bytes
);
586 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__
, address
);
587 return static_cast<jlong
>(reinterpret_cast<uintptr_t>(address
));
590 // Get the full path of a library in the zip file
591 // (lib/<abi>/crazy.<lib_name>).
593 // |env| is the current JNI environment handle.
594 // |clazz| is the static class handle which is not used here.
595 // |lib_name| is the library base name.
596 // Returns the full path (or empty string on failure).
597 jstring
GetLibraryFilePathInZipFile(JNIEnv
* env
,
600 String
lib_name_str(env
, lib_name
);
601 const char* lib_name_c_str
= lib_name_str
.c_str();
602 char buffer
[kMaxFilePathLengthInZip
+ 1];
603 if (crazy_library_file_path_in_zip_file(
604 lib_name_c_str
, buffer
, sizeof(buffer
)) == CRAZY_STATUS_FAILURE
) {
605 LOG_ERROR("%s: Failed to get full filename for library '%s'",
606 __FUNCTION__
, lib_name_c_str
);
609 return env
->NewStringUTF(buffer
);
612 // Check whether the device supports mapping the APK file with executable
615 // |env| is the current JNI environment handle.
616 // |clazz| is the static class handle which is not used here.
617 // |apkfile_name| is the filename of the APK.
618 // Returns true if supported.
619 jboolean
CheckMapExecSupport(JNIEnv
* env
, jclass clazz
, jstring apkfile_name
) {
620 String
apkfile_name_str(env
, apkfile_name
);
621 const char* apkfile_name_c_str
= apkfile_name_str
.c_str();
623 int fd
= open(apkfile_name_c_str
, O_RDONLY
);
625 LOG_ERROR("%s: Failed to open %s\n", __FUNCTION__
, apkfile_name_c_str
);
630 "%s: Memory mapping the first page of %s with executable permissions\n",
631 __FUNCTION__
, apkfile_name_c_str
);
632 void* address
= mmap(NULL
, PAGE_SIZE
, PROT_EXEC
, MAP_PRIVATE
, fd
, 0);
635 if (address
== MAP_FAILED
) {
639 munmap(address
, PAGE_SIZE
);
644 LOG_INFO("%s: %s\n", __FUNCTION__
, status
? "Supported" : "NOT supported");
648 // Check whether a library is page aligned and uncompressed in the APK file.
650 // |env| is the current JNI environment handle.
651 // |clazz| is the static class handle which is not used here.
652 // |apkfile_name| is the filename of the APK.
653 // |library_name| is the library base name.
654 // Returns true if page aligned and uncompressed.
655 jboolean
CheckLibraryIsMappableInApk(JNIEnv
* env
, jclass clazz
,
656 jstring apkfile_name
,
657 jstring library_name
) {
658 String
apkfile_name_str(env
, apkfile_name
);
659 const char* apkfile_name_c_str
= apkfile_name_str
.c_str();
660 String
library_name_str(env
, library_name
);
661 const char* library_name_c_str
= library_name_str
.c_str();
663 LOG_INFO("%s: Checking if %s is page-aligned and uncompressed in %s\n",
664 __FUNCTION__
, library_name_c_str
, apkfile_name_c_str
);
665 jboolean mappable
= crazy_linker_check_library_is_mappable_in_zip_file(
666 apkfile_name_c_str
, library_name_c_str
) == CRAZY_STATUS_SUCCESS
;
667 LOG_INFO("%s: %s\n", __FUNCTION__
, mappable
? "Mappable" : "NOT mappable");
672 const JNINativeMethod kNativeMethods
[] = {
673 {"nativeLoadLibrary",
677 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
680 reinterpret_cast<void*>(&LoadLibrary
)},
681 {"nativeLoadLibraryInZipFile",
686 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
689 reinterpret_cast<void*>(&LoadLibraryInZipFile
)},
690 {"nativeEnableNoMapExecSupportFallback",
694 reinterpret_cast<void*>(&EnableNoMapExecSupportFallback
)},
695 {"nativeRunCallbackOnUiThread",
700 reinterpret_cast<void*>(&RunCallbackOnUiThread
)},
701 {"nativeCreateSharedRelro",
705 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
708 reinterpret_cast<void*>(&CreateSharedRelro
)},
709 {"nativeUseSharedRelro",
712 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
715 reinterpret_cast<void*>(&UseSharedRelro
)},
716 {"nativeCanUseSharedRelro",
720 reinterpret_cast<void*>(&CanUseSharedRelro
)},
721 {"nativeGetRandomBaseLoadAddress",
726 reinterpret_cast<void*>(&GetRandomBaseLoadAddress
)},
727 {"nativeGetLibraryFilePathInZipFile",
731 "Ljava/lang/String;",
732 reinterpret_cast<void*>(&GetLibraryFilePathInZipFile
)},
733 {"nativeCheckMapExecSupport",
738 reinterpret_cast<void*>(&CheckMapExecSupport
)},
739 {"nativeCheckLibraryIsMappableInApk",
745 reinterpret_cast<void*>(&CheckLibraryIsMappableInApk
)}, };
749 // JNI_OnLoad() hook called when the linker library is loaded through
750 // the regular System.LoadLibrary) API. This shall save the Java VM
751 // handle and initialize LibInfo fields.
752 jint
JNI_OnLoad(JavaVM
* vm
, void* reserved
) {
753 LOG_INFO("%s: Entering", __FUNCTION__
);
756 if (JNI_OK
!= vm
->GetEnv(reinterpret_cast<void**>(&env
), JNI_VERSION_1_4
)) {
757 LOG_ERROR("Could not create JNIEnv");
761 // Register native methods.
763 if (!InitClassReference(env
,
764 "org/chromium/base/library_loader/Linker",
768 LOG_INFO("%s: Registering native methods", __FUNCTION__
);
769 env
->RegisterNatives(linker_class
,
771 sizeof(kNativeMethods
) / sizeof(kNativeMethods
[0]));
773 // Find LibInfo field ids.
774 LOG_INFO("%s: Caching field IDs", __FUNCTION__
);
775 if (!s_lib_info_fields
.Init(env
)) {
779 // Resolve and save the Java side Linker callback class and method.
780 LOG_INFO("%s: Resolving callback bindings", __FUNCTION__
);
781 if (!s_java_callback_bindings
.Init(env
, linker_class
)) {
785 // Save JavaVM* handle into context.
786 crazy_context_t
* context
= GetCrazyContext();
787 crazy_context_set_java_vm(context
, vm
, JNI_VERSION_1_4
);
789 // Register the function that the crazy linker can call to post code
790 // for later execution.
791 crazy_context_set_callback_poster(context
, &PostForLaterExecution
, NULL
);
793 LOG_INFO("%s: Done", __FUNCTION__
);
794 return JNI_VERSION_1_4
;