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

Side by Side Diff: base/android/linker/linker_jni.cc

Issue 643803003: Add UMA for testing whether device supports memory mapping APK files with executable permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
OLDNEW
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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 567 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
568 if (address == MAP_FAILED) { 568 if (address == MAP_FAILED) {
569 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); 569 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__);
570 return 0; 570 return 0;
571 } 571 }
572 munmap(address, bytes); 572 munmap(address, bytes);
573 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);
574 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address)); 574 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address));
575 } 575 }
576 576
577 // Test whether the device supports memory mapping APK files with executable
578 // permissions.
579 //
580 // |env| is the current JNI environment handle and is ignored here.
581 // |clazz| is the static class handle for org.chromium.base.Linker,
582 // and is ignored here.
583 // |apkfile_name| is the filename of the APK.
584 // Returns true if supported.
585 jboolean TestLoadFromApk(JNIEnv* env, jclass clazz, jstring apkfile_name) {
586 String apkfile_name_str(env, apkfile_name);
587 return crazy_linker_test_load_from_apk(apkfile_name_str.c_str());
588 }
589
577 const JNINativeMethod kNativeMethods[] = { 590 const JNINativeMethod kNativeMethods[] = {
578 {"nativeLoadLibrary", 591 {"nativeLoadLibrary",
579 "(" 592 "("
580 "Ljava/lang/String;" 593 "Ljava/lang/String;"
581 "J" 594 "J"
582 "Lorg/chromium/base/library_loader/Linker$LibInfo;" 595 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
583 ")" 596 ")"
584 "Z", 597 "Z",
585 reinterpret_cast<void*>(&LoadLibrary)}, 598 reinterpret_cast<void*>(&LoadLibrary)},
586 {"nativeLoadLibraryInZipFile", 599 {"nativeLoadLibraryInZipFile",
(...skipping 29 matching lines...) Expand all
616 {"nativeCanUseSharedRelro", 629 {"nativeCanUseSharedRelro",
617 "(" 630 "("
618 ")" 631 ")"
619 "Z", 632 "Z",
620 reinterpret_cast<void*>(&CanUseSharedRelro)}, 633 reinterpret_cast<void*>(&CanUseSharedRelro)},
621 {"nativeGetRandomBaseLoadAddress", 634 {"nativeGetRandomBaseLoadAddress",
622 "(" 635 "("
623 "J" 636 "J"
624 ")" 637 ")"
625 "J", 638 "J",
626 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, }; 639 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)},
640 {"nativeTestLoadFromApk",
641 "("
642 "Ljava/lang/String;"
643 ")"
644 "Z",
645 reinterpret_cast<void*>(&TestLoadFromApk)}, };
627 646
628 } // namespace 647 } // namespace
629 648
630 // JNI_OnLoad() hook called when the linker library is loaded through 649 // JNI_OnLoad() hook called when the linker library is loaded through
631 // the regular System.LoadLibrary) API. This shall save the Java VM 650 // the regular System.LoadLibrary) API. This shall save the Java VM
632 // handle and initialize LibInfo fields. 651 // handle and initialize LibInfo fields.
633 jint JNI_OnLoad(JavaVM* vm, void* reserved) { 652 jint JNI_OnLoad(JavaVM* vm, void* reserved) {
634 LOG_INFO("%s: Entering", __FUNCTION__); 653 LOG_INFO("%s: Entering", __FUNCTION__);
635 // Get new JNIEnv 654 // Get new JNIEnv
636 JNIEnv* env; 655 JNIEnv* env;
(...skipping 30 matching lines...) Expand all
667 crazy_context_t* context = GetCrazyContext(); 686 crazy_context_t* context = GetCrazyContext();
668 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); 687 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4);
669 688
670 // Register the function that the crazy linker can call to post code 689 // Register the function that the crazy linker can call to post code
671 // for later execution. 690 // for later execution.
672 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); 691 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL);
673 692
674 LOG_INFO("%s: Done", __FUNCTION__); 693 LOG_INFO("%s: Done", __FUNCTION__);
675 return JNI_VERSION_1_4; 694 return JNI_VERSION_1_4;
676 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698