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

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

Issue 533173002: Fix conversions from 32-bit pointers to signed 64-bit integers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 <sys/mman.h>
21 #include <unistd.h> 21 #include <unistd.h>
22 22
23 // 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.
24 // 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
25 // in base/ which hasn't been loaded yet. 25 // in base/ which hasn't been loaded yet.
26 #define DEBUG 0 26 #define DEBUG 1
Yaron 2014/09/03 14:24:56 revert
whywhat 2014/09/03 14:40:28 Done.
27 27
28 #define TAG "chromium_android_linker" 28 #define TAG "chromium_android_linker"
29 29
30 #if DEBUG 30 #if DEBUG
31 #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) 31 #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
32 #else 32 #else
33 #define LOG_INFO(...) ((void)0) 33 #define LOG_INFO(...) ((void)0)
34 #endif 34 #endif
35 #define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) 35 #define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
36 36
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698