Chromium Code Reviews| 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 |
| 11 // renderer process. | 11 // renderer process. |
| 12 | 12 |
| 13 // This source code *cannot* depend on anything from base/ or the C++ | 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. | 14 // STL, to keep the final library small, and avoid ugly dependency issues. |
| 15 | 15 |
| 16 #include <android/log.h> | 16 #include <android/log.h> |
| 17 #include <crazy_linker.h> | 17 #include <crazy_linker.h> |
| 18 #include <jni.h> | 18 #include <jni.h> |
| 19 #include <stdlib.h> | 19 #include <stdlib.h> |
| 20 #include <sys/mman.h> | |
| 20 #include <unistd.h> | 21 #include <unistd.h> |
| 21 | 22 |
| 22 // Set this to 1 to enable debug traces to the Android log. | 23 // Set this to 1 to enable debug traces to the Android log. |
| 23 // Note that LOG() from "base/logging.h" cannot be used, since it is | 24 // Note that LOG() from "base/logging.h" cannot be used, since it is |
| 24 // in base/ which hasn't been loaded yet. | 25 // in base/ which hasn't been loaded yet. |
| 25 #define DEBUG 0 | 26 #define DEBUG 0 |
| 26 | 27 |
| 27 #define TAG "chromium_android_linker" | 28 #define TAG "chromium_android_linker" |
| 28 | 29 |
| 29 #if DEBUG | 30 #if DEBUG |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 __FUNCTION__, | 554 __FUNCTION__, |
| 554 lib_name.c_str()); | 555 lib_name.c_str()); |
| 555 | 556 |
| 556 return true; | 557 return true; |
| 557 } | 558 } |
| 558 | 559 |
| 559 jboolean CanUseSharedRelro(JNIEnv* env, jclass clazz) { | 560 jboolean CanUseSharedRelro(JNIEnv* env, jclass clazz) { |
| 560 return crazy_system_can_share_relro(); | 561 return crazy_system_can_share_relro(); |
| 561 } | 562 } |
| 562 | 563 |
| 563 jlong GetPageSize(JNIEnv* env, jclass clazz) { | 564 jlong GetPageSize(JNIEnv* env, jclass clazz) { |
|
rmcilroy
2014/08/14 13:19:07
Ditto
simonb (inactive)
2014/08/14 14:25:14
Done.
| |
| 564 jlong result = static_cast<jlong>(sysconf(_SC_PAGESIZE)); | 565 jlong result = static_cast<jlong>(sysconf(_SC_PAGESIZE)); |
| 565 LOG_INFO("%s: System page size is %lld bytes\n", __FUNCTION__, result); | 566 LOG_INFO("%s: System page size is %lld bytes\n", __FUNCTION__, result); |
| 566 return result; | 567 return result; |
| 567 } | 568 } |
| 568 | 569 |
| 570 jlong GetRandomBaseLoadAddress(JNIEnv* env, jclass clazz, jlong bytes) { | |
| 571 void* address = | |
| 572 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| 573 if (address == MAP_FAILED) { | |
| 574 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); | |
| 575 return 0; | |
| 576 } | |
| 577 munmap(address, bytes); | |
| 578 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); | |
| 579 return static_cast<jlong>(reinterpret_cast<intptr_t>(address)); | |
| 580 } | |
| 581 | |
| 569 const JNINativeMethod kNativeMethods[] = { | 582 const JNINativeMethod kNativeMethods[] = { |
| 570 {"nativeLoadLibrary", | 583 {"nativeLoadLibrary", |
| 571 "(" | 584 "(" |
| 572 "Ljava/lang/String;" | 585 "Ljava/lang/String;" |
| 573 "J" | 586 "J" |
| 574 "Lorg/chromium/base/library_loader/Linker$LibInfo;" | 587 "Lorg/chromium/base/library_loader/Linker$LibInfo;" |
| 575 ")" | 588 ")" |
| 576 "Z", | 589 "Z", |
| 577 reinterpret_cast<void*>(&LoadLibrary)}, | 590 reinterpret_cast<void*>(&LoadLibrary)}, |
| 578 {"nativeLoadLibraryInZipFile", | 591 {"nativeLoadLibraryInZipFile", |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 607 reinterpret_cast<void*>(&UseSharedRelro)}, | 620 reinterpret_cast<void*>(&UseSharedRelro)}, |
| 608 {"nativeCanUseSharedRelro", | 621 {"nativeCanUseSharedRelro", |
| 609 "(" | 622 "(" |
| 610 ")" | 623 ")" |
| 611 "Z", | 624 "Z", |
| 612 reinterpret_cast<void*>(&CanUseSharedRelro)}, | 625 reinterpret_cast<void*>(&CanUseSharedRelro)}, |
| 613 {"nativeGetPageSize", | 626 {"nativeGetPageSize", |
| 614 "(" | 627 "(" |
| 615 ")" | 628 ")" |
| 616 "J", | 629 "J", |
| 617 reinterpret_cast<void*>(&GetPageSize)}, }; | 630 reinterpret_cast<void*>(&GetPageSize)}, |
| 631 {"nativeGetRandomBaseLoadAddress", | |
| 632 "(" | |
| 633 "J" | |
| 634 ")" | |
| 635 "J", | |
| 636 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, }; | |
| 618 | 637 |
| 619 } // namespace | 638 } // namespace |
| 620 | 639 |
| 621 // JNI_OnLoad() hook called when the linker library is loaded through | 640 // JNI_OnLoad() hook called when the linker library is loaded through |
| 622 // the regular System.LoadLibrary) API. This shall save the Java VM | 641 // the regular System.LoadLibrary) API. This shall save the Java VM |
| 623 // handle and initialize LibInfo fields. | 642 // handle and initialize LibInfo fields. |
| 624 jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 643 jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 625 LOG_INFO("%s: Entering", __FUNCTION__); | 644 LOG_INFO("%s: Entering", __FUNCTION__); |
| 626 // Get new JNIEnv | 645 // Get new JNIEnv |
| 627 JNIEnv* env; | 646 JNIEnv* env; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 658 crazy_context_t* context = GetCrazyContext(); | 677 crazy_context_t* context = GetCrazyContext(); |
| 659 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 678 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
| 660 | 679 |
| 661 // Register the function that the crazy linker can call to post code | 680 // Register the function that the crazy linker can call to post code |
| 662 // for later execution. | 681 // for later execution. |
| 663 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 682 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
| 664 | 683 |
| 665 LOG_INFO("%s: Done", __FUNCTION__); | 684 LOG_INFO("%s: Done", __FUNCTION__); |
| 666 return JNI_VERSION_1_4; | 685 return JNI_VERSION_1_4; |
| 667 } | 686 } |
| OLD | NEW |