| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 // This is the Android-specific Chromium linker, a tiny shared library | 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 | 6 // implementing a custom dynamic linker that can be used to load the |
| 7 // real Chromium libraries (e.g. libcontentshell.so). | 7 // real Chromium libraries (e.g. libcontentshell.so). |
| 8 | 8 |
| 9 // The main point of this linker is to be able to share the RELRO | 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 | 10 // section of libcontentshell.so (or equivalent) between the browser and |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return false; | 445 return false; |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Copy the callback; the one passed as an argument may be temporary. | 448 // Copy the callback; the one passed as an argument may be temporary. |
| 449 crazy_callback_t* callback = new crazy_callback_t(); | 449 crazy_callback_t* callback = new crazy_callback_t(); |
| 450 *callback = *callback_request; | 450 *callback = *callback_request; |
| 451 | 451 |
| 452 LOG_INFO("%s: Calling back to java with handler %p, opaque %p", | 452 LOG_INFO("%s: Calling back to java with handler %p, opaque %p", |
| 453 __FUNCTION__, callback->handler, callback->opaque); | 453 __FUNCTION__, callback->handler, callback->opaque); |
| 454 | 454 |
| 455 jlong arg = static_cast<jlong>(reinterpret_cast<intptr_t>(callback)); | 455 jlong arg = static_cast<jlong>(reinterpret_cast<uintptr_t>(callback)); |
| 456 |
| 456 env->CallStaticVoidMethod( | 457 env->CallStaticVoidMethod( |
| 457 s_java_callback_bindings.clazz, s_java_callback_bindings.method_id, arg); | 458 s_java_callback_bindings.clazz, s_java_callback_bindings.method_id, arg); |
| 458 | 459 |
| 459 // Back out and return false if we encounter a JNI exception. | 460 // Back out and return false if we encounter a JNI exception. |
| 460 if (env->ExceptionCheck() == JNI_TRUE) { | 461 if (env->ExceptionCheck() == JNI_TRUE) { |
| 461 env->ExceptionDescribe(); | 462 env->ExceptionDescribe(); |
| 462 env->ExceptionClear(); | 463 env->ExceptionClear(); |
| 463 delete callback; | 464 delete callback; |
| 464 return false; | 465 return false; |
| 465 } | 466 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 564 |
| 564 jlong GetRandomBaseLoadAddress(JNIEnv* env, jclass clazz, jlong bytes) { | 565 jlong GetRandomBaseLoadAddress(JNIEnv* env, jclass clazz, jlong bytes) { |
| 565 void* address = | 566 void* address = |
| 566 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 567 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 567 if (address == MAP_FAILED) { | 568 if (address == MAP_FAILED) { |
| 568 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); | 569 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); |
| 569 return 0; | 570 return 0; |
| 570 } | 571 } |
| 571 munmap(address, bytes); | 572 munmap(address, bytes); |
| 572 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); | 573 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); |
| 573 return static_cast<jlong>(reinterpret_cast<intptr_t>(address)); | 574 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address)); |
| 574 } | 575 } |
| 575 | 576 |
| 576 const JNINativeMethod kNativeMethods[] = { | 577 const JNINativeMethod kNativeMethods[] = { |
| 577 {"nativeLoadLibrary", | 578 {"nativeLoadLibrary", |
| 578 "(" | 579 "(" |
| 579 "Ljava/lang/String;" | 580 "Ljava/lang/String;" |
| 580 "J" | 581 "J" |
| 581 "Lorg/chromium/base/library_loader/Linker$LibInfo;" | 582 "Lorg/chromium/base/library_loader/Linker$LibInfo;" |
| 582 ")" | 583 ")" |
| 583 "Z", | 584 "Z", |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 crazy_context_t* context = GetCrazyContext(); | 667 crazy_context_t* context = GetCrazyContext(); |
| 667 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 668 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
| 668 | 669 |
| 669 // Register the function that the crazy linker can call to post code | 670 // Register the function that the crazy linker can call to post code |
| 670 // for later execution. | 671 // for later execution. |
| 671 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 672 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
| 672 | 673 |
| 673 LOG_INFO("%s: Done", __FUNCTION__); | 674 LOG_INFO("%s: Done", __FUNCTION__); |
| 674 return JNI_VERSION_1_4; | 675 return JNI_VERSION_1_4; |
| 675 } | 676 } |
| OLD | NEW |