| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 char* ptr_; | 66 char* ptr_; |
| 67 size_t size_; | 67 size_t size_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 String::String(JNIEnv* env, jstring str) { | 70 String::String(JNIEnv* env, jstring str) { |
| 71 size_ = env->GetStringUTFLength(str); | 71 size_ = env->GetStringUTFLength(str); |
| 72 ptr_ = static_cast<char*>(::malloc(size_ + 1)); | 72 ptr_ = static_cast<char*>(::malloc(size_ + 1)); |
| 73 | 73 |
| 74 // Note: the result contains Java "modified UTF-8" bytes. | 74 // Note: This runs before browser native code is loaded, and so cannot |
| 75 // Good enough for the linker though. | 75 // rely on anything from base/. This means that we must use |
| 76 // GetStringUTFChars() and not base::android::ConvertJavaStringToUTF8(). |
| 77 // |
| 78 // GetStringUTFChars() suffices because the only strings used here are |
| 79 // paths to APK files or names of shared libraries, all of which are |
| 80 // plain ASCII, defined and hard-coded by the Chromium Android build. |
| 81 // |
| 82 // For more: see |
| 83 // https://crbug.com/508876 |
| 84 // |
| 85 // Note: GetStringUTFChars() returns Java UTF-8 bytes. This is good |
| 86 // enough for the linker though. |
| 76 const char* bytes = env->GetStringUTFChars(str, NULL); | 87 const char* bytes = env->GetStringUTFChars(str, NULL); |
| 77 ::memcpy(ptr_, bytes, size_); | 88 ::memcpy(ptr_, bytes, size_); |
| 78 ptr_[size_] = '\0'; | 89 ptr_[size_] = '\0'; |
| 79 | 90 |
| 80 env->ReleaseStringUTFChars(str, bytes); | 91 env->ReleaseStringUTFChars(str, bytes); |
| 81 } | 92 } |
| 82 | 93 |
| 83 // Return true iff |address| is a valid address for the target CPU. | 94 // Return true iff |address| is a valid address for the target CPU. |
| 84 bool IsValidAddress(jlong address) { | 95 bool IsValidAddress(jlong address) { |
| 85 return static_cast<jlong>(static_cast<size_t>(address)) == address; | 96 return static_cast<jlong>(static_cast<size_t>(address)) == address; |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 crazy_context_t* context = GetCrazyContext(); | 768 crazy_context_t* context = GetCrazyContext(); |
| 758 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 769 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
| 759 | 770 |
| 760 // Register the function that the crazy linker can call to post code | 771 // Register the function that the crazy linker can call to post code |
| 761 // for later execution. | 772 // for later execution. |
| 762 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 773 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
| 763 | 774 |
| 764 LOG_INFO("%s: Done", __FUNCTION__); | 775 LOG_INFO("%s: Done", __FUNCTION__); |
| 765 return JNI_VERSION_1_4; | 776 return JNI_VERSION_1_4; |
| 766 } | 777 } |
| OLD | NEW |