diff options
Diffstat (limited to 'core/jni')
44 files changed, 1541 insertions, 804 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 2e0acb1..fda4114 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -134,7 +134,6 @@ LOCAL_SRC_FILES:= \ android_hardware_UsbDevice.cpp \ android_hardware_UsbDeviceConnection.cpp \ android_hardware_UsbRequest.cpp \ - android_debug_JNITest.cpp \ android_util_FileObserver.cpp \ android/opengl/poly_clip.cpp.arm \ android/opengl/util.cpp.arm \ @@ -150,7 +149,8 @@ LOCAL_SRC_FILES:= \ android_content_res_ObbScanner.cpp \ android_content_res_Configuration.cpp \ android_animation_PropertyValuesHolder.cpp \ - com_android_internal_net_NetworkStatsFactory.cpp + com_android_internal_net_NetworkStatsFactory.cpp \ + com_android_internal_os_Zygote.cpp LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index b4599b6..362a54e 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -131,7 +131,6 @@ extern int register_android_database_CursorWindow(JNIEnv* env); extern int register_android_database_SQLiteConnection(JNIEnv* env); extern int register_android_database_SQLiteGlobal(JNIEnv* env); extern int register_android_database_SQLiteDebug(JNIEnv* env); -extern int register_android_debug_JNITest(JNIEnv* env); extern int register_android_nio_utils(JNIEnv* env); extern int register_android_text_format_Time(JNIEnv* env); extern int register_android_os_Debug(JNIEnv* env); @@ -178,6 +177,7 @@ extern int register_android_content_res_Configuration(JNIEnv* env); extern int register_android_animation_PropertyValuesHolder(JNIEnv *env); extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env); extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env); +extern int register_com_android_internal_os_Zygote(JNIEnv *env); static AndroidRuntime* gCurRuntime = NULL; @@ -228,9 +228,10 @@ int register_com_android_internal_os_RuntimeInit(JNIEnv* env) /*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; - -AndroidRuntime::AndroidRuntime() : - mExitWithoutCleanup(false) +AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) : + mExitWithoutCleanup(false), + mArgBlockStart(argBlockStart), + mArgBlockLength(argBlockLength) { SkGraphics::Init(); // this sets our preference for 16bit images during decode @@ -265,13 +266,17 @@ AndroidRuntime::~AndroidRuntime() return jniRegisterNativeMethods(env, className, gMethods, numMethods); } -status_t AndroidRuntime::callMain(const char* className, - jclass clazz, int argc, const char* const argv[]) +void AndroidRuntime::setArgv0(const char* argv0) { + strlcpy(mArgBlockStart, argv0, mArgBlockLength); +} + +status_t AndroidRuntime::callMain(const String8& className, jclass clazz, + const Vector<String8>& args) { JNIEnv* env; jmethodID methodId; - ALOGD("Calling main entry %s", className); + ALOGD("Calling main entry %s", className.string()); env = getJNIEnv(); if (clazz == NULL || env == NULL) { @@ -280,7 +285,7 @@ status_t AndroidRuntime::callMain(const char* className, methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V"); if (methodId == NULL) { - ALOGE("ERROR: could not find method %s.main(String[])\n", className); + ALOGE("ERROR: could not find method %s.main(String[])\n", className.string()); return UNKNOWN_ERROR; } @@ -291,11 +296,12 @@ status_t AndroidRuntime::callMain(const char* className, jclass stringClass; jobjectArray strArray; + const size_t numArgs = args.size(); stringClass = env->FindClass("java/lang/String"); - strArray = env->NewObjectArray(argc, stringClass, NULL); + strArray = env->NewObjectArray(numArgs, stringClass, NULL); - for (int i = 0; i < argc; i++) { - jstring argStr = env->NewStringUTF(argv[i]); + for (size_t i = 0; i < numArgs; i++) { + jstring argStr = env->NewStringUTF(args[i].string()); env->SetObjectArrayElement(strArray, i, argStr); } @@ -396,16 +402,16 @@ static void readLocale(char* language, char* region) * * This will cut up "extraOptsBuf" as we chop it into individual options. * + * If "quotingArg" is non-null, it is passed before each extra option in mOptions. + * * Adds the strings, if any, to mOptions. */ -void AndroidRuntime::parseExtraOpts(char* extraOptsBuf) +void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg) { JavaVMOption opt; - char* start; - char* end; - memset(&opt, 0, sizeof(opt)); - start = extraOptsBuf; + char* start = extraOptsBuf; + char* end = NULL; while (*start != '\0') { while (*start == ' ') /* skip leading whitespace */ start++; @@ -419,6 +425,11 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf) *end++ = '\0'; /* mark end, advance to indicate more */ opt.optionString = start; + if (quotingArg != NULL) { + JavaVMOption quotingOpt; + quotingOpt.optionString = quotingArg; + mOptions.add(quotingOpt); + } mOptions.add(opt); start = end; } @@ -430,6 +441,14 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf) * Various arguments, most determined by system properties, are passed in. * The "mOptions" vector is updated. * + * CAUTION: when adding options in here, be careful not to put the + * char buffer inside a nested scope. Adding the buffer to the + * options using mOptions.add() does not copy the buffer, so if the + * buffer goes out of scope the option may be overwritten. It's best + * to put the buffer at the top of the function so that it is more + * unlikely that someone will surround it in a scope at a later time + * and thus introduce a bug. + * * Returns 0 on success. */ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) @@ -450,6 +469,9 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX]; char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX]; char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX]; + char dalvikVmLibBuf[PROPERTY_VALUE_MAX]; + char dex2oatFlagsBuf[PROPERTY_VALUE_MAX]; + char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX]; char extraOptsBuf[PROPERTY_VALUE_MAX]; char* stackTraceFile = NULL; bool checkJni = false; @@ -461,7 +483,15 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) kEMIntFast, kEMJitCompiler, } executionMode = kEMDefault; - + char profile_period[sizeof("-Xprofile-period:") + PROPERTY_VALUE_MAX]; + char profile_duration[sizeof("-Xprofile-duration:") + PROPERTY_VALUE_MAX]; + char profile_interval[sizeof("-Xprofile-interval:") + PROPERTY_VALUE_MAX]; + char profile_backoff[sizeof("-Xprofile-backoff:") + PROPERTY_VALUE_MAX]; + char langOption[sizeof("-Duser.language=") + 3]; + char regionOption[sizeof("-Duser.region=") + 3]; + char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)]; + char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX]; + char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX]; property_get("dalvik.vm.checkjni", propBuf, ""); if (strcmp(propBuf, "true") == 0) { @@ -662,7 +692,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) //mOptions.add(opt); } - char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)]; property_get("dalvik.vm.lockprof.threshold", propBuf, ""); if (strlen(propBuf) > 0) { strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:"); @@ -672,7 +701,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) } /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */ - char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX]; property_get("dalvik.vm.jit.op", propBuf, ""); if (strlen(propBuf) > 0) { strcpy(jitOpBuf, "-Xjitop:"); @@ -682,7 +710,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) } /* Force interpreter-only mode for selected methods */ - char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX]; property_get("dalvik.vm.jit.method", propBuf, ""); if (strlen(propBuf) > 0) { strcpy(jitMethodBuf, "-Xjitmethod:"); @@ -742,14 +769,26 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) mOptions.add(opt); } + // libart tolerates libdvm flags, but not vice versa, so only pass some options if libart. + property_get("persist.sys.dalvik.vm.lib.1", dalvikVmLibBuf, "libdvm.so"); + bool libart = (strncmp(dalvikVmLibBuf, "libart", 6) == 0); + + if (libart) { + // Extra options for DexClassLoader. + property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, ""); + parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option"); + + // Extra options for boot.art/boot.oat image generation. + property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, ""); + parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option"); + } + /* extra options; parse this late so it overrides others */ property_get("dalvik.vm.extra-opts", extraOptsBuf, ""); - parseExtraOpts(extraOptsBuf); + parseExtraOpts(extraOptsBuf, NULL); /* Set the properties for locale */ { - char langOption[sizeof("-Duser.language=") + 3]; - char regionOption[sizeof("-Duser.region=") + 3]; strcpy(langOption, "-Duser.language="); strcpy(regionOption, "-Duser.region="); readLocale(langOption, regionOption); @@ -760,6 +799,37 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) mOptions.add(opt); } + /* + * Set profiler options + */ + if (libart) { + // Number of seconds during profile runs. + strcpy(profile_period, "-Xprofile-period:"); + property_get("dalvik.vm.profile.period_secs", profile_period+17, "10"); + opt.optionString = profile_period; + mOptions.add(opt); + + // Length of each profile run (seconds). + strcpy(profile_duration, "-Xprofile-duration:"); + property_get("dalvik.vm.profile.duration_secs", profile_duration+19, "30"); + opt.optionString = profile_duration; + mOptions.add(opt); + + + // Polling interval during profile run (microseconds). + strcpy(profile_interval, "-Xprofile-interval:"); + property_get("dalvik.vm.profile.interval_us", profile_interval+19, "10000"); + opt.optionString = profile_interval; + mOptions.add(opt); + + // Coefficient for period backoff. The the period is multiplied + // by this value after each profile run. + strcpy(profile_backoff, "-Xprofile-backoff:"); + property_get("dalvik.vm.profile.backoff_coeff", profile_backoff+18, "2.0"); + opt.optionString = profile_backoff; + mOptions.add(opt); + } + initArgs.version = JNI_VERSION_1_4; initArgs.options = mOptions.editArray(); initArgs.nOptions = mOptions.size(); @@ -803,20 +873,23 @@ char* AndroidRuntime::toSlashClassName(const char* className) * Passes the main function two arguments, the class name and the specified * options string. */ -void AndroidRuntime::start(const char* className, const char* options) +void AndroidRuntime::start(const char* className, const Vector<String8>& options) { ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n", className != NULL ? className : "(unknown)"); + static const String8 startSystemServer("start-system-server"); + /* * 'startSystemServer == true' means runtime is obsolete and not run from * init.rc anymore, so we print out the boot start event here. */ - if (strcmp(options, "start-system-server") == 0) { - /* track our progress through the boot sequence */ - const int LOG_BOOT_PROGRESS_START = 3000; - LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, - ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); + for (size_t i = 0; i < options.size(); ++i) { + if (options[i] == startSystemServer) { + /* track our progress through the boot sequence */ + const int LOG_BOOT_PROGRESS_START = 3000; + LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); + } } const char* rootDir = getenv("ANDROID_ROOT"); @@ -857,17 +930,20 @@ void AndroidRuntime::start(const char* className, const char* options) jclass stringClass; jobjectArray strArray; jstring classNameStr; - jstring optionsStr; stringClass = env->FindClass("java/lang/String"); assert(stringClass != NULL); - strArray = env->NewObjectArray(2, stringClass, NULL); + strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL); assert(strArray != NULL); classNameStr = env->NewStringUTF(className); assert(classNameStr != NULL); env->SetObjectArrayElement(strArray, 0, classNameStr); - optionsStr = env->NewStringUTF(options); - env->SetObjectArrayElement(strArray, 1, optionsStr); + + for (size_t i = 0; i < options.size(); ++i) { + jstring optionsStr = env->NewStringUTF(options.itemAt(i).string()); + assert(optionsStr != NULL); + env->SetObjectArrayElement(strArray, i + 1, optionsStr); + } /* * Start VM. This thread becomes the main thread of the VM, and will @@ -1093,7 +1169,6 @@ static void register_jam_procs(const RegJAMProc array[], size_t count) } static const RegJNIRec gRegJNI[] = { - REG_JNI(register_android_debug_JNITest), REG_JNI(register_com_android_internal_os_RuntimeInit), REG_JNI(register_android_os_SystemClock), REG_JNI(register_android_util_EventLog), @@ -1179,6 +1254,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_net_wifi_WifiNative), REG_JNI(register_android_os_MemoryFile), REG_JNI(register_com_android_internal_os_ZygoteInit), + REG_JNI(register_com_android_internal_os_Zygote), REG_JNI(register_android_hardware_Camera), REG_JNI(register_android_hardware_camera2_CameraMetadata), REG_JNI(register_android_hardware_SensorManager), diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index e8feacb..2b9a5c4 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -107,17 +107,19 @@ static void scaleNinePatchChunk(android::Res_png_9patch* chunk, float scale) { chunk->paddingRight = int(chunk->paddingRight * scale + 0.5f); chunk->paddingBottom = int(chunk->paddingBottom * scale + 0.5f); + int32_t* xDivs = chunk->getXDivs(); for (int i = 0; i < chunk->numXDivs; i++) { - chunk->xDivs[i] = int(chunk->xDivs[i] * scale + 0.5f); - if (i > 0 && chunk->xDivs[i] == chunk->xDivs[i - 1]) { - chunk->xDivs[i]++; + xDivs[i] = int32_t(xDivs[i] * scale + 0.5f); + if (i > 0 && xDivs[i] == xDivs[i - 1]) { + xDivs[i]++; } } + int32_t* yDivs = chunk->getYDivs(); for (int i = 0; i < chunk->numYDivs; i++) { - chunk->yDivs[i] = int(chunk->yDivs[i] * scale + 0.5f); - if (i > 0 && chunk->yDivs[i] == chunk->yDivs[i - 1]) { - chunk->yDivs[i]++; + yDivs[i] = int32_t(yDivs[i] * scale + 0.5f); + if (i > 0 && yDivs[i] == yDivs[i - 1]) { + yDivs[i]++; } } } @@ -379,7 +381,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding return nullObjectReturn("primitive array == null"); } - peeker.fPatch->serialize(array); + memcpy(array, peeker.fPatch, peeker.fPatchSize); env->ReleasePrimitiveArrayCritical(ninePatchChunk, array, 0); } diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp index da8f083..2cb1015 100644 --- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp +++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp @@ -63,9 +63,14 @@ private: size_t bytesRead = 0; // read the bytes do { - size_t requested = size; - if (requested > fCapacity) + jint requested = 0; + if (size > static_cast<size_t>(fCapacity)) { requested = fCapacity; + } else { + // This is safe because requested is clamped to (jint) + // fCapacity. + requested = static_cast<jint>(size); + } jint n = env->CallIntMethod(fJavaInputStream, gInputStream_readMethodID, fJavaByteArray, 0, requested); @@ -120,7 +125,7 @@ private: JNIEnv* fEnv; jobject fJavaInputStream; // the caller owns this object jbyteArray fJavaByteArray; // the caller owns this object - size_t fCapacity; + jint fCapacity; size_t fBytesRead; bool fIsAtEnd; }; @@ -174,14 +179,18 @@ public: fCapacity = env->GetArrayLength(storage); } - virtual bool write(const void* buffer, size_t size) { + virtual bool write(const void* buffer, size_t size) { JNIEnv* env = fEnv; jbyteArray storage = fJavaByteArray; while (size > 0) { - size_t requested = size; - if (requested > fCapacity) { + jint requested = 0; + if (size > static_cast<size_t>(fCapacity)) { requested = fCapacity; + } else { + // This is safe because requested is clamped to (jint) + // fCapacity. + requested = static_cast<jint>(size); } env->SetByteArrayRegion(storage, 0, requested, @@ -216,7 +225,7 @@ private: JNIEnv* fEnv; jobject fJavaOutputStream; // the caller owns this object jbyteArray fJavaByteArray; // the caller owns this object - size_t fCapacity; + jint fCapacity; }; SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream, diff --git a/core/jni/android/graphics/NinePatchImpl.cpp b/core/jni/android/graphics/NinePatchImpl.cpp index 01e7e3e..86ff13c 100644 --- a/core/jni/android/graphics/NinePatchImpl.cpp +++ b/core/jni/android/graphics/NinePatchImpl.cpp @@ -115,13 +115,15 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, defaultPaint.setDither(true); paint = &defaultPaint; } - + + const int32_t* xDivs = chunk.getXDivs(); + const int32_t* yDivs = chunk.getYDivs(); // if our SkCanvas were back by GL we should enable this and draw this as // a mesh, which will be faster in most cases. if (false) { SkNinePatch::DrawMesh(canvas, bounds, bitmap, - chunk.xDivs, chunk.numXDivs, - chunk.yDivs, chunk.numYDivs, + xDivs, chunk.numXDivs, + yDivs, chunk.numYDivs, paint); return; } @@ -145,8 +147,8 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, if (gTrace) { ALOGV("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height())); ALOGV("======== ninepatch paint bm [%d,%d]\n", bitmap.width(), bitmap.height()); - ALOGV("======== ninepatch xDivs [%d,%d]\n", chunk.xDivs[0], chunk.xDivs[1]); - ALOGV("======== ninepatch yDivs [%d,%d]\n", chunk.yDivs[0], chunk.yDivs[1]); + ALOGV("======== ninepatch xDivs [%d,%d]\n", xDivs[0], xDivs[1]); + ALOGV("======== ninepatch yDivs [%d,%d]\n", yDivs[0], yDivs[1]); } #endif @@ -171,8 +173,8 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, SkRect dst; SkIRect src; - const int32_t x0 = chunk.xDivs[0]; - const int32_t y0 = chunk.yDivs[0]; + const int32_t x0 = xDivs[0]; + const int32_t y0 = yDivs[0]; const SkColor initColor = ((SkPaint*)paint)->getColor(); const uint8_t numXDivs = chunk.numXDivs; const uint8_t numYDivs = chunk.numYDivs; @@ -191,12 +193,12 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, int numStretchyXPixelsRemaining = 0; for (i = 0; i < numXDivs; i += 2) { - numStretchyXPixelsRemaining += chunk.xDivs[i + 1] - chunk.xDivs[i]; + numStretchyXPixelsRemaining += xDivs[i + 1] - xDivs[i]; } int numFixedXPixelsRemaining = bitmapWidth - numStretchyXPixelsRemaining; int numStretchyYPixelsRemaining = 0; for (i = 0; i < numYDivs; i += 2) { - numStretchyYPixelsRemaining += chunk.yDivs[i + 1] - chunk.yDivs[i]; + numStretchyYPixelsRemaining += yDivs[i + 1] - yDivs[i]; } int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining; @@ -235,7 +237,7 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, src.fBottom = bitmapHeight; dst.fBottom = bounds.fBottom; } else { - src.fBottom = chunk.yDivs[j]; + src.fBottom = yDivs[j]; const int srcYSize = src.fBottom - src.fTop; if (yIsStretchable) { dst.fBottom = dst.fTop + calculateStretch(bounds.fBottom, dst.fTop, @@ -252,15 +254,16 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, xIsStretchable = initialXIsStretchable; // The initial xDiv and whether the first column is considered // stretchable or not depends on whether xDiv[0] was zero or not. + const uint32_t* colors = chunk.getColors(); for (i = xIsStretchable ? 1 : 0; i <= numXDivs && src.fLeft < bitmapWidth; i++, xIsStretchable = !xIsStretchable) { - color = chunk.colors[colorIndex++]; + color = colors[colorIndex++]; if (i == numXDivs) { src.fRight = bitmapWidth; dst.fRight = bounds.fRight; } else { - src.fRight = chunk.xDivs[i]; + src.fRight = xDivs[i]; if (dstRightsHaveBeenCached) { dst.fRight = dstRights[i]; } else { diff --git a/core/jni/android/graphics/NinePatchPeeker.cpp b/core/jni/android/graphics/NinePatchPeeker.cpp index d3482da..5daa1ad 100644 --- a/core/jni/android/graphics/NinePatchPeeker.cpp +++ b/core/jni/android/graphics/NinePatchPeeker.cpp @@ -28,11 +28,11 @@ bool NinePatchPeeker::peek(const char tag[], const void* data, size_t length) { // You have to copy the data because it is owned by the png reader Res_png_9patch* patchNew = (Res_png_9patch*) malloc(patchSize); memcpy(patchNew, patch, patchSize); - // this relies on deserialization being done in place Res_png_9patch::deserialize(patchNew); patchNew->fileToDevice(); free(fPatch); fPatch = patchNew; + fPatchSize = patchSize; //printf("9patch: (%d,%d)-(%d,%d)\n", // fPatch.sizeLeft, fPatch.sizeTop, // fPatch.sizeRight, fPatch.sizeBottom); diff --git a/core/jni/android/graphics/NinePatchPeeker.h b/core/jni/android/graphics/NinePatchPeeker.h index 10d268a..2043862 100644 --- a/core/jni/android/graphics/NinePatchPeeker.h +++ b/core/jni/android/graphics/NinePatchPeeker.h @@ -29,6 +29,7 @@ public: // the host lives longer than we do, so a raw ptr is safe fHost = host; fPatch = NULL; + fPatchSize = 0; fLayoutBounds = NULL; } @@ -38,6 +39,7 @@ public: } Res_png_9patch* fPatch; + size_t fPatchSize; int *fLayoutBounds; virtual bool peek(const char tag[], const void* data, size_t length); diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index 144ac39..5db083a 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -70,7 +70,7 @@ void TextLayoutCache::operator()(TextLayoutCacheKey& text, sp<TextLayoutValue>& size_t totalSizeToDelete = text.getSize() + desc->getSize(); mSize -= totalSizeToDelete; if (mDebugEnabled) { - ALOGD("Cache value %p deleted, size = %d", desc.get(), totalSizeToDelete); + ALOGD("Cache value %p deleted, size = %zu", desc.get(), totalSizeToDelete); } } @@ -130,7 +130,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, bool removedOne = mCache.removeOldest(); LOG_ALWAYS_FATAL_IF(!removedOne, "The cache is non-empty but we " "failed to remove the oldest entry. " - "mSize = %u, size = %u, mMaxSize = %u, mCache.size() = %u", + "mSize = %u, size = %zu, mMaxSize = %u, mCache.size() = %zu", mSize, size, mMaxSize, mCache.size()); } } @@ -149,7 +149,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, nsecs_t totalTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime; ALOGD("CACHE MISS: Added entry %p " "with start = %d, count = %d, contextCount = %d, " - "entry size %d bytes, remaining space %d bytes" + "entry size %zu bytes, remaining space %d bytes" " - Compute time %0.6f ms - Put time %0.6f ms - Text = '%s'", value.get(), start, count, contextCount, size, mMaxSize - mSize, value->getElapsedTime() * 0.000001f, @@ -160,7 +160,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, if (mDebugEnabled) { ALOGD("CACHE MISS: Calculated but not storing entry because it is too big " "with start = %d, count = %d, contextCount = %d, " - "entry size %d bytes, remaining space %d bytes" + "entry size %zu bytes, remaining space %d bytes" " - Compute time %0.6f ms - Text = '%s'", start, count, contextCount, size, mMaxSize - mSize, value->getElapsedTime() * 0.000001f, @@ -205,7 +205,7 @@ void TextLayoutCache::dumpCacheStats() { ALOGD("------------------------------------------------"); ALOGD("pid : %d", getpid()); ALOGD("running : %.0f seconds", timeRunningInSec); - ALOGD("entries : %d", cacheSize); + ALOGD("entries : %zu", cacheSize); ALOGD("max size : %d bytes", mMaxSize); ALOGD("used : %d bytes according to mSize", mSize); ALOGD("remaining : %d bytes or %2.2f percent", mMaxSize - mSize, remainingPercent); diff --git a/core/jni/android/graphics/pdf/PdfDocument.cpp b/core/jni/android/graphics/pdf/PdfDocument.cpp index 6175a8f..d54aaa8 100644 --- a/core/jni/android/graphics/pdf/PdfDocument.cpp +++ b/core/jni/android/graphics/pdf/PdfDocument.cpp @@ -113,24 +113,24 @@ private: PageRecord* mCurrentPage; }; -static jint nativeCreateDocument(JNIEnv* env, jobject thiz) { - return reinterpret_cast<jint>(new PdfDocument()); +static jlong nativeCreateDocument(JNIEnv* env, jobject thiz) { + return reinterpret_cast<jlong>(new PdfDocument()); } -static jint nativeStartPage(JNIEnv* env, jobject thiz, jint documentPtr, +static jlong nativeStartPage(JNIEnv* env, jobject thiz, jlong documentPtr, jint pageWidth, jint pageHeight, jint contentLeft, jint contentTop, jint contentRight, jint contentBottom) { PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); - return reinterpret_cast<jint>(document->startPage(pageWidth, pageHeight, + return reinterpret_cast<jlong>(document->startPage(pageWidth, pageHeight, contentLeft, contentTop, contentRight, contentBottom)); } -static void nativeFinishPage(JNIEnv* env, jobject thiz, jint documentPtr) { +static void nativeFinishPage(JNIEnv* env, jobject thiz, jlong documentPtr) { PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); document->finishPage(); } -static void nativeWriteTo(JNIEnv* env, jobject thiz, jint documentPtr, jobject out, +static void nativeWriteTo(JNIEnv* env, jobject thiz, jlong documentPtr, jobject out, jbyteArray chunk) { PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); SkWStream* skWStream = CreateJavaOutputStreamAdaptor(env, out, chunk); @@ -138,17 +138,17 @@ static void nativeWriteTo(JNIEnv* env, jobject thiz, jint documentPtr, jobject o delete skWStream; } -static void nativeClose(JNIEnv* env, jobject thiz, jint documentPtr) { +static void nativeClose(JNIEnv* env, jobject thiz, jlong documentPtr) { PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); document->close(); } static JNINativeMethod gPdfDocument_Methods[] = { - {"nativeCreateDocument", "()I", (void*) nativeCreateDocument}, - {"nativeStartPage", "(IIIIIII)I", (void*) nativeStartPage}, - {"nativeFinishPage", "(I)V", (void*) nativeFinishPage}, - {"nativeWriteTo", "(ILjava/io/OutputStream;[B)V", (void*) nativeWriteTo}, - {"nativeClose", "(I)V", (void*) nativeClose} + {"nativeCreateDocument", "()J", (void*) nativeCreateDocument}, + {"nativeStartPage", "(JIIIIII)J", (void*) nativeStartPage}, + {"nativeFinishPage", "(J)V", (void*) nativeFinishPage}, + {"nativeWriteTo", "(JLjava/io/OutputStream;[B)V", (void*) nativeWriteTo}, + {"nativeClose", "(J)V", (void*) nativeClose} }; int register_android_graphics_pdf_PdfDocument(JNIEnv* env) { diff --git a/core/jni/android_animation_PropertyValuesHolder.cpp b/core/jni/android_animation_PropertyValuesHolder.cpp index 5991805..1e3ec18 100644 --- a/core/jni/android_animation_PropertyValuesHolder.cpp +++ b/core/jni/android_animation_PropertyValuesHolder.cpp @@ -29,44 +29,44 @@ namespace android { const char* const kClassPathName = "android/animation/PropertyValuesHolder"; -static jmethodID android_animation_PropertyValuesHolder_getIntMethod( +static jlong android_animation_PropertyValuesHolder_getIntMethod( JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName) { const char *nativeString = env->GetStringUTFChars(methodName, 0); jmethodID mid = env->GetMethodID(targetClass, nativeString, "(I)V"); env->ReleaseStringUTFChars(methodName, nativeString); - return mid; + return reinterpret_cast<jlong>(mid); } -static jmethodID android_animation_PropertyValuesHolder_getFloatMethod( +static jlong android_animation_PropertyValuesHolder_getFloatMethod( JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName) { const char *nativeString = env->GetStringUTFChars(methodName, 0); jmethodID mid = env->GetMethodID(targetClass, nativeString, "(F)V"); env->ReleaseStringUTFChars(methodName, nativeString); - return mid; + return reinterpret_cast<jlong>(mid); } static void android_animation_PropertyValuesHolder_callIntMethod( - JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, int arg) + JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jint arg) { - env->CallVoidMethod(target, methodID, arg); + env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg); } static void android_animation_PropertyValuesHolder_callFloatMethod( - JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, float arg) + JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloat arg) { - env->CallVoidMethod(target, methodID, arg); + env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg); } static JNINativeMethod gMethods[] = { - { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)I", + { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)J", (void*)android_animation_PropertyValuesHolder_getIntMethod }, - { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)I", + { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)J", (void*)android_animation_PropertyValuesHolder_getFloatMethod }, - { "nCallIntMethod", "(Ljava/lang/Object;II)V", + { "nCallIntMethod", "(Ljava/lang/Object;JI)V", (void*)android_animation_PropertyValuesHolder_callIntMethod }, - { "nCallFloatMethod", "(Ljava/lang/Object;IF)V", + { "nCallFloatMethod", "(Ljava/lang/Object;JF)V", (void*)android_animation_PropertyValuesHolder_callFloatMethod } }; diff --git a/core/jni/android_content_res_Configuration.cpp b/core/jni/android_content_res_Configuration.cpp index 246e3bd..201ffe8 100644 --- a/core/jni/android_content_res_Configuration.cpp +++ b/core/jni/android_content_res_Configuration.cpp @@ -70,15 +70,6 @@ void android_Configuration_getFromJava( gConfigurationClassInfo.smallestScreenWidthDp); } -/* - * JNI registration. - */ -static JNINativeMethod gMethods[] = { - /* name, signature, funcPtr */ - //{ "getObbInfo_native", "(Ljava/lang/String;Landroid/content/res/ObbInfo;)Z", - // (void*) android_content_res_ObbScanner_getObbInfo }, -}; - #define FIND_CLASS(var, className) \ var = env->FindClass(className); \ LOG_FATAL_IF(! var, "Unable to find class " className); @@ -123,8 +114,7 @@ int register_android_content_res_Configuration(JNIEnv* env) GET_FIELD_ID(gConfigurationClassInfo.smallestScreenWidthDp, clazz, "smallestScreenWidthDp", "I"); - return AndroidRuntime::registerNativeMethods(env, "android/content/res/Configuration", gMethods, - NELEM(gMethods)); + return 0; } }; // namespace android diff --git a/core/jni/android_database_SQLiteGlobal.cpp b/core/jni/android_database_SQLiteGlobal.cpp index acc2276..89d64fa 100644 --- a/core/jni/android_database_SQLiteGlobal.cpp +++ b/core/jni/android_database_SQLiteGlobal.cpp @@ -39,7 +39,7 @@ static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) { bool verboseLog = !!data; if (iErrCode == 0 || iErrCode == SQLITE_CONSTRAINT || iErrCode == SQLITE_SCHEMA) { if (verboseLog) { - ALOGV(LOG_VERBOSE, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg); + ALOG(LOG_VERBOSE, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg); } } else { ALOG(LOG_ERROR, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg); diff --git a/core/jni/android_debug_JNITest.cpp b/core/jni/android_debug_JNITest.cpp deleted file mode 100644 index 9147284..0000000 --- a/core/jni/android_debug_JNITest.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* //device/libs/android_runtime/android_debug_JNITest.cpp -** -** Copyright 2006, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#define LOG_TAG "DebugJNI" - -#include "jni.h" -#include "nativehelper/JNIHelp.h" -#include "utils/Log.h" -#include "utils/misc.h" -//#include "android_runtime/AndroidRuntime.h" - -namespace android { - -/* - * Implements: - * native int part1(int intArg, double doubleArg, String stringArg, - * int[] arrayArg) - */ -static jint android_debug_JNITest_part1(JNIEnv* env, jobject object, - jint intArg, jdouble doubleArg, jstring stringArg, jobjectArray arrayArg) -{ - jclass clazz; - jmethodID part2id; - jsize arrayLen; - jint arrayVal; - int result = -2; - - ALOGI("JNI test: in part1, intArg=%d, doubleArg=%.3f\n", intArg, doubleArg); - - /* find "int part2(double doubleArg, int fromArray, String stringArg)" */ - clazz = env->GetObjectClass(object); - part2id = env->GetMethodID(clazz, - "part2", "(DILjava/lang/String;)I"); - if (part2id == NULL) { - ALOGE("JNI test: unable to find part2\n"); - return -1; - } - - /* get the length of the array */ - arrayLen = env->GetArrayLength(arrayArg); - ALOGI(" array size is %d\n", arrayLen); - - /* - * Get the last element in the array. - * Use the Get<type>ArrayElements functions instead if you need access - * to multiple elements. - */ - arrayVal = (int) env->GetObjectArrayElement(arrayArg, arrayLen-1); - ALOGI(" array val is %d\n", arrayVal); - - /* call this->part2 */ - result = env->CallIntMethod(object, part2id, - doubleArg, arrayVal, stringArg); - - return result; -} - -/* - * Implements: - * private static native int part3(String stringArg); - */ -static jint android_debug_JNITest_part3(JNIEnv* env, jclass clazz, - jstring stringArg) -{ - const char* utfChars; - jboolean isCopy; - - ALOGI("JNI test: in part3\n"); - - utfChars = env->GetStringUTFChars(stringArg, &isCopy); - - ALOGI(" String is '%s', isCopy=%d\n", (const char*) utfChars, isCopy); - - env->ReleaseStringUTFChars(stringArg, utfChars); - - return 2000; -} - -/* - * JNI registration. - */ -static JNINativeMethod gMethods[] = { - /* name, signature, funcPtr */ - { "part1", "(IDLjava/lang/String;[I)I", - (void*) android_debug_JNITest_part1 }, - { "part3", "(Ljava/lang/String;)I", - (void*) android_debug_JNITest_part3 }, -}; -int register_android_debug_JNITest(JNIEnv* env) -{ - return jniRegisterNativeMethods(env, "android/debug/JNITest", - gMethods, NELEM(gMethods)); -} - -#if 0 -/* trampoline into C++ */ -extern "C" -int register_android_debug_JNITest_C(JNIEnv* env) -{ - return android::register_android_debug_JNITest(env); -} -#endif - -}; // namespace android - diff --git a/core/jni/android_emoji_EmojiFactory.cpp b/core/jni/android_emoji_EmojiFactory.cpp index 5276934..f127d29 100644 --- a/core/jni/android_emoji_EmojiFactory.cpp +++ b/core/jni/android_emoji_EmojiFactory.cpp @@ -104,7 +104,7 @@ static void InitializeCaller() { static jobject create_java_EmojiFactory( JNIEnv* env, EmojiFactory* factory, jstring name) { jobject obj = env->NewObject(gEmojiFactory_class, gEmojiFactory_constructorMethodID, - static_cast<jint>(reinterpret_cast<uintptr_t>(factory)), name); + reinterpret_cast<jlong>(factory), name); if (env->ExceptionCheck() != 0) { ALOGE("*** Uncaught exception returned from Java call!\n"); env->ExceptionDescribe(); @@ -155,7 +155,7 @@ static jobject android_emoji_EmojiFactory_newAvailableInstance( } static jobject android_emoji_EmojiFactory_getBitmapFromAndroidPua( - JNIEnv* env, jobject clazz, jint nativeEmojiFactory, jint pua) { + JNIEnv* env, jobject clazz, jlong nativeEmojiFactory, jint pua) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); int size; @@ -175,7 +175,7 @@ static jobject android_emoji_EmojiFactory_getBitmapFromAndroidPua( } static void android_emoji_EmojiFactory_destructor( - JNIEnv* env, jobject obj, jint nativeEmojiFactory) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory) { /* // Must not delete this object!! EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); @@ -184,49 +184,49 @@ static void android_emoji_EmojiFactory_destructor( } static jint android_emoji_EmojiFactory_getAndroidPuaFromVendorSpecificSjis( - JNIEnv* env, jobject obj, jint nativeEmojiFactory, jchar sjis) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory, jchar sjis) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetAndroidPuaFromVendorSpecificSjis(sjis); } static jint android_emoji_EmojiFactory_getVendorSpecificSjisFromAndroidPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory, jint pua) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory, jint pua) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetVendorSpecificSjisFromAndroidPua(pua); } static jint android_emoji_EmojiFactory_getAndroidPuaFromVendorSpecificPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory, jint vsu) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory, jint vsu) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetAndroidPuaFromVendorSpecificPua(vsu); } static jint android_emoji_EmojiFactory_getVendorSpecificPuaFromAndroidPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory, jint pua) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory, jint pua) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetVendorSpecificPuaFromAndroidPua(pua); } static jint android_emoji_EmojiFactory_getMaximumVendorSpecificPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetMaximumVendorSpecificPua(); } static jint android_emoji_EmojiFactory_getMinimumVendorSpecificPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetMinimumVendorSpecificPua(); } static jint android_emoji_EmojiFactory_getMaximumAndroidPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetMaximumAndroidPua(); } static jint android_emoji_EmojiFactory_getMinimumAndroidPua( - JNIEnv* env, jobject obj, jint nativeEmojiFactory) { + JNIEnv* env, jobject obj, jlong nativeEmojiFactory) { EmojiFactory *factory = reinterpret_cast<EmojiFactory *>(nativeEmojiFactory); return factory->GetMinimumAndroidPua(); } @@ -236,25 +236,25 @@ static JNINativeMethod gMethods[] = { (void*)android_emoji_EmojiFactory_newInstance}, { "newAvailableInstance", "()Landroid/emoji/EmojiFactory;", (void*)android_emoji_EmojiFactory_newAvailableInstance}, - { "nativeDestructor", "(I)V", + { "nativeDestructor", "(J)V", (void*)android_emoji_EmojiFactory_destructor}, - { "nativeGetBitmapFromAndroidPua", "(II)Landroid/graphics/Bitmap;", + { "nativeGetBitmapFromAndroidPua", "(JI)Landroid/graphics/Bitmap;", (void*)android_emoji_EmojiFactory_getBitmapFromAndroidPua}, - { "nativeGetAndroidPuaFromVendorSpecificSjis", "(IC)I", + { "nativeGetAndroidPuaFromVendorSpecificSjis", "(JC)I", (void*)android_emoji_EmojiFactory_getAndroidPuaFromVendorSpecificSjis}, - { "nativeGetVendorSpecificSjisFromAndroidPua", "(II)I", + { "nativeGetVendorSpecificSjisFromAndroidPua", "(JI)I", (void*)android_emoji_EmojiFactory_getVendorSpecificSjisFromAndroidPua}, - { "nativeGetAndroidPuaFromVendorSpecificPua", "(II)I", + { "nativeGetAndroidPuaFromVendorSpecificPua", "(JI)I", (void*)android_emoji_EmojiFactory_getAndroidPuaFromVendorSpecificPua}, - { "nativeGetVendorSpecificPuaFromAndroidPua", "(II)I", + { "nativeGetVendorSpecificPuaFromAndroidPua", "(JI)I", (void*)android_emoji_EmojiFactory_getVendorSpecificPuaFromAndroidPua}, - { "nativeGetMaximumVendorSpecificPua", "(I)I", + { "nativeGetMaximumVendorSpecificPua", "(J)I", (void*)android_emoji_EmojiFactory_getMaximumVendorSpecificPua}, - { "nativeGetMinimumVendorSpecificPua", "(I)I", + { "nativeGetMinimumVendorSpecificPua", "(J)I", (void*)android_emoji_EmojiFactory_getMinimumVendorSpecificPua}, - { "nativeGetMaximumAndroidPua", "(I)I", + { "nativeGetMaximumAndroidPua", "(J)I", (void*)android_emoji_EmojiFactory_getMaximumAndroidPua}, - { "nativeGetMinimumAndroidPua", "(I)I", + { "nativeGetMinimumAndroidPua", "(J)I", (void*)android_emoji_EmojiFactory_getMinimumAndroidPua} }; @@ -276,7 +276,7 @@ static jfieldID getFieldIDCheck(JNIEnv* env, jclass clazz, int register_android_emoji_EmojiFactory(JNIEnv* env) { gEmojiFactory_class = make_globalref(env, "android/emoji/EmojiFactory"); gEmojiFactory_constructorMethodID = env->GetMethodID( - gEmojiFactory_class, "<init>", "(ILjava/lang/String;)V"); + gEmojiFactory_class, "<init>", "(JLjava/lang/String;)V"); return jniRegisterNativeMethods(env, "android/emoji/EmojiFactory", gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp index b22668b..ab70f25 100644 --- a/core/jni/android_media_AudioRecord.cpp +++ b/core/jni/android_media_AudioRecord.cpp @@ -18,6 +18,7 @@ #define LOG_TAG "AudioRecord-JNI" +#include <inttypes.h> #include <jni.h> #include <JNIHelp.h> #include <android_runtime/AndroidRuntime.h> @@ -316,7 +317,7 @@ static void android_media_AudioRecord_release(JNIEnv *env, jobject thiz) { if (lpRecorder == NULL) { return; } - ALOGV("About to delete lpRecorder: %x\n", (int)lpRecorder.get()); + ALOGV("About to delete lpRecorder: %" PRIxPTR "\n", lpRecorder.get()); lpRecorder->stop(); audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetLongField( @@ -329,7 +330,7 @@ static void android_media_AudioRecord_release(JNIEnv *env, jobject thiz) { // delete the callback information if (lpCookie) { Mutex::Autolock l(sLock); - ALOGV("deleting lpCookie: %x\n", (int)lpCookie); + ALOGV("deleting lpCookie: %" PRIxPTR "\n", lpCookie); while (lpCookie->busy) { if (lpCookie->cond.waitRelative(sLock, milliseconds(CALLBACK_COND_WAIT_TIMEOUT_MS)) != diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp index 9f79f74..98f4bed 100644 --- a/core/jni/android_net_LocalSocketImpl.cpp +++ b/core/jni/android_net_LocalSocketImpl.cpp @@ -111,7 +111,7 @@ socket_bind_local (JNIEnv *env, jobject object, jobject fileDescriptor, /* private native void listen_native(int fd, int backlog) throws IOException; */ static void -socket_listen (JNIEnv *env, jobject object, jobject fileDescriptor, int backlog) +socket_listen (JNIEnv *env, jobject object, jobject fileDescriptor, jint backlog) { int ret; int fd; @@ -231,7 +231,7 @@ java_opt_to_real(int optID, int* opt, int* level) } static jint -socket_getOption(JNIEnv *env, jobject object, jobject fileDescriptor, int optID) +socket_getOption(JNIEnv *env, jobject object, jobject fileDescriptor, jint optID) { int ret, value; int opt, level; @@ -279,7 +279,7 @@ socket_getOption(JNIEnv *env, jobject object, jobject fileDescriptor, int optID) } static void socket_setOption( - JNIEnv *env, jobject object, jobject fileDescriptor, int optID, + JNIEnv *env, jobject object, jobject fileDescriptor, jint optID, jint boolValue, jint intValue) { int ret; int optname; diff --git a/core/jni/android_nio_utils.cpp b/core/jni/android_nio_utils.cpp index 7cbbe12..59d6e41 100644 --- a/core/jni/android_nio_utils.cpp +++ b/core/jni/android_nio_utils.cpp @@ -37,7 +37,7 @@ void* android::nio_getPointer(JNIEnv *_env, jobject buffer, jarray *array) { gNioJNI.getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void *>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(gNioJNI.nioAccessClass, diff --git a/core/jni/android_opengl_EGL14.cpp b/core/jni/android_opengl_EGL14.cpp index 5b0a4b2..19e4d99 100644 --- a/core/jni/android_opengl_EGL14.cpp +++ b/core/jni/android_opengl_EGL14.cpp @@ -69,22 +69,22 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); - egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getHandle", "()I"); - eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getHandle", "()I"); - eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getHandle", "()I"); - eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getHandle", "()I"); + egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J"); + eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J"); + eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J"); + eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J"); - egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(I)V"); - eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(I)V"); - eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(I)V"); - eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(I)V"); + egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V"); + eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V"); + eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V"); + eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V"); - jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, (jint)EGL_NO_CONTEXT); + jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT)); eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); - jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, (jint)EGL_NO_DISPLAY); + jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY)); eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); - jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, (jint)EGL_NO_SURFACE); + jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE)); eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); @@ -106,7 +106,8 @@ fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { "Object is set to null."); } - return (void*) (_env->CallIntMethod(obj, mid)); + jlong handle = _env->CallLongMethod(obj, mid); + return reinterpret_cast<void*>(handle); } static jobject @@ -126,7 +127,7 @@ toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { return eglNoSurfaceObject; } - return _env->NewObject(cls, con, (jint)handle); + return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); } // -------------------------------------------------------------------------- @@ -142,14 +143,26 @@ android_eglGetError /* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */ static jobject android_eglGetDisplay - (JNIEnv *_env, jobject _this, jint display_id) { + (JNIEnv *_env, jobject _this, jlong display_id) { EGLDisplay _returnValue = (EGLDisplay) 0; _returnValue = eglGetDisplay( - (EGLNativeDisplayType)display_id + reinterpret_cast<EGLNativeDisplayType>(display_id) ); return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue); } +/* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */ +static jobject +android_eglGetDisplayInt + (JNIEnv *_env, jobject _this, jint display_id) { + + if ((EGLNativeDisplayType)display_id != EGL_DEFAULT_DISPLAY) { + jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglGetDisplay"); + return 0; + } + return android_eglGetDisplay(_env, _this, display_id); +} + /* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */ static jboolean android_eglInitialize @@ -852,7 +865,7 @@ android_eglReleaseThread /* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */ static jobject android_eglCreatePbufferFromClientBuffer - (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) { + (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jlong buffer, jobject config, jintArray attrib_list_ref, jint offset) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; @@ -897,7 +910,7 @@ android_eglCreatePbufferFromClientBuffer _returnValue = eglCreatePbufferFromClientBuffer( (EGLDisplay)dpy_native, (EGLenum)buftype, - (EGLClientBuffer)buffer, + reinterpret_cast<EGLClientBuffer>(buffer), (EGLConfig)config_native, (EGLint *)attrib_list ); @@ -913,6 +926,16 @@ exit: return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); } +static jobject +android_eglCreatePbufferFromClientBufferInt + (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) { + if(sizeof(void*) != sizeof(uint32_t)) { + jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePbufferFromClientBuffer"); + return 0; + } + return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset); +} + /* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */ static jboolean android_eglSurfaceAttrib @@ -1207,7 +1230,8 @@ static const char *classPathName = "android/opengl/EGL14"; static JNINativeMethod methods[] = { {"_nativeClassInit", "()V", (void*)nativeClassInit }, {"eglGetError", "()I", (void *) android_eglGetError }, -{"eglGetDisplay", "(I)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplay }, +{"eglGetDisplay", "(I)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplayInt }, +{"eglGetDisplay", "(J)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplay }, {"eglInitialize", "(Landroid/opengl/EGLDisplay;[II[II)Z", (void *) android_eglInitialize }, {"eglTerminate", "(Landroid/opengl/EGLDisplay;)Z", (void *) android_eglTerminate }, {"eglQueryString", "(Landroid/opengl/EGLDisplay;I)Ljava/lang/String;", (void *) android_eglQueryString__Landroind_opengl_EGLDisplay_2I }, @@ -1224,7 +1248,8 @@ static JNINativeMethod methods[] = { {"eglQueryAPI", "()I", (void *) android_eglQueryAPI }, {"eglWaitClient", "()Z", (void *) android_eglWaitClient }, {"eglReleaseThread", "()Z", (void *) android_eglReleaseThread }, -{"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IILandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBuffer }, +{"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IILandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBufferInt }, +{"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IJLandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBuffer }, {"eglSurfaceAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;II)Z", (void *) android_eglSurfaceAttrib }, {"eglBindTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglBindTexImage }, {"eglReleaseTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglReleaseTexImage }, diff --git a/core/jni/android_opengl_EGLExt.cpp b/core/jni/android_opengl_EGLExt.cpp index 5179ddc..15899f5 100644 --- a/core/jni/android_opengl_EGLExt.cpp +++ b/core/jni/android_opengl_EGLExt.cpp @@ -70,22 +70,22 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); - egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getHandle", "()I"); - eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getHandle", "()I"); - eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getHandle", "()I"); - eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getHandle", "()I"); + egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J"); + eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J"); + eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J"); + eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J"); - egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(I)V"); - eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(I)V"); - eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(I)V"); - eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(I)V"); + egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V"); + eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V"); + eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V"); + eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V"); - jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, (jint)EGL_NO_CONTEXT); + jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT)); eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); - jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, (jint)EGL_NO_DISPLAY); + jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY)); eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); - jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, (jint)EGL_NO_SURFACE); + jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE)); eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); @@ -107,7 +107,7 @@ fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { "Object is set to null."); } - return (void*) (_env->CallIntMethod(obj, mid)); + return reinterpret_cast<void*>(_env->CallLongMethod(obj, mid)); } static jobject @@ -127,7 +127,7 @@ toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { return eglNoSurfaceObject; } - return _env->NewObject(cls, con, (jint)handle); + return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle)); } // -------------------------------------------------------------------------- diff --git a/core/jni/android_opengl_GLES10.cpp b/core/jni/android_opengl_GLES10.cpp index cc34e99..21e19e1 100644 --- a/core/jni/android_opengl_GLES10.cpp +++ b/core/jni/android_opengl_GLES10.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, diff --git a/core/jni/android_opengl_GLES10Ext.cpp b/core/jni/android_opengl_GLES10Ext.cpp index 9284384..bc83234 100644 --- a/core/jni/android_opengl_GLES10Ext.cpp +++ b/core/jni/android_opengl_GLES10Ext.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, diff --git a/core/jni/android_opengl_GLES11.cpp b/core/jni/android_opengl_GLES11.cpp index 871e84d..a45f269 100644 --- a/core/jni/android_opengl_GLES11.cpp +++ b/core/jni/android_opengl_GLES11.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, @@ -578,7 +578,7 @@ android_glColorPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -679,7 +679,7 @@ android_glDrawElements__IIII (GLenum)mode, (GLsizei)count, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); @@ -2302,7 +2302,7 @@ android_glNormalPointer__III glNormalPointer( (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -2529,7 +2529,7 @@ android_glTexCoordPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -2937,7 +2937,7 @@ android_glVertexPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } diff --git a/core/jni/android_opengl_GLES11Ext.cpp b/core/jni/android_opengl_GLES11Ext.cpp index 3e038ad..05728ef 100644 --- a/core/jni/android_opengl_GLES11Ext.cpp +++ b/core/jni/android_opengl_GLES11Ext.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, diff --git a/core/jni/android_opengl_GLES20.cpp b/core/jni/android_opengl_GLES20.cpp index db03b70..d3e5014 100644 --- a/core/jni/android_opengl_GLES20.cpp +++ b/core/jni/android_opengl_GLES20.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, @@ -1180,7 +1180,7 @@ android_glDrawElements__IIII (GLenum)mode, (GLsizei)count, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); @@ -1804,7 +1804,7 @@ android_glGetActiveAttrib__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_ni (GLsizei *)length, (GLint *)size, (GLenum *)type, - (char *)name + reinterpret_cast<char *>(name) ); if (_typeArray) { releasePointer(_env, _typeArray, type, JNI_TRUE); @@ -2132,7 +2132,7 @@ android_glGetActiveUniform__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_n (GLsizei *)length, (GLint *)size, (GLenum *)type, - (char *)name + reinterpret_cast<char *>(name) ); if (_typeArray) { releasePointer(_env, _typeArray, type, JNI_TRUE); @@ -3212,7 +3212,7 @@ android_glGetShaderSource__IILjava_nio_IntBuffer_2B (GLuint)shader, (GLsizei)bufsize, (GLsizei *)length, - (char *)source + reinterpret_cast<char *>(source) ); if (_array) { releasePointer(_env, _array, length, JNI_TRUE); @@ -5985,7 +5985,7 @@ android_glVertexAttribPointer__IIIZII (GLenum)type, (GLboolean)normalized, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } diff --git a/core/jni/android_opengl_GLES30.cpp b/core/jni/android_opengl_GLES30.cpp index 4c62a75..8821352 100644 --- a/core/jni/android_opengl_GLES30.cpp +++ b/core/jni/android_opengl_GLES30.cpp @@ -111,7 +111,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void*>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, @@ -370,7 +370,7 @@ android_glDrawRangeElements__IIIIII (GLuint)end, (GLsizei)count, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -419,7 +419,7 @@ android_glTexImage3D__IIIIIIIIII (GLint)border, (GLenum)format, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -470,7 +470,7 @@ android_glTexSubImage3D__IIIIIIIIIII (GLsizei)depth, (GLenum)format, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -534,7 +534,7 @@ android_glCompressedTexImage3D__IIIIIIIII (GLsizei)depth, (GLint)border, (GLsizei)imageSize, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -585,7 +585,7 @@ android_glCompressedTexSubImage3D__IIIIIIIIIII (GLsizei)depth, (GLenum)format, (GLsizei)imageSize, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -2134,7 +2134,7 @@ android_glVertexAttribIPointer__IIIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index a041693..d4873d6 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -800,7 +800,7 @@ static void dumpNativeHeap(FILE* fp) fprintf(fp, "Total memory: %zu\n", totalMemory); fprintf(fp, "Allocation records: %zd\n", recordCount); if (backtraceSize != BACKTRACE_SIZE) { - fprintf(fp, "WARNING: mismatched backtrace sizes (%d vs. %d)\n", + fprintf(fp, "WARNING: mismatched backtrace sizes (%zu vs. %d)\n", backtraceSize, BACKTRACE_SIZE); } fprintf(fp, "\n"); @@ -823,7 +823,11 @@ static void dumpNativeHeap(FILE* fp) if (backtrace[bt] == 0) { break; } else { +#ifdef __LP64__ + fprintf(fp, " %016x", backtrace[bt]); +#else fprintf(fp, " %08x", backtrace[bt]); +#endif } } fprintf(fp, "\n"); diff --git a/core/jni/android_os_SELinux.cpp b/core/jni/android_os_SELinux.cpp index ca278cf..26405b5 100644 --- a/core/jni/android_os_SELinux.cpp +++ b/core/jni/android_os_SELinux.cpp @@ -411,11 +411,11 @@ static jboolean native_restorecon(JNIEnv *env, jobject, jstring pathnameStr) { ScopedUtfChars pathname(env, pathnameStr); if (pathname.c_str() == NULL) { - ALOGV("restorecon(%p) => threw exception", pathname); + ALOGV("restorecon(%p) => threw exception", pathnameStr); return false; } - int ret = selinux_android_restorecon(pathname.c_str()); + int ret = selinux_android_restorecon(pathname.c_str(), 0); ALOGV("restorecon(%s) => %d", pathname.c_str(), ret); return (ret == 0); } @@ -443,8 +443,21 @@ static JNINativeMethod method_table[] = { static int log_callback(int type, const char *fmt, ...) { va_list ap; + int priority; + + switch (type) { + case SELINUX_WARNING: + priority = ANDROID_LOG_WARN; + break; + case SELINUX_INFO: + priority = ANDROID_LOG_INFO; + break; + default: + priority = ANDROID_LOG_ERROR; + break; + } va_start(ap, fmt); - LOG_PRI_VA(ANDROID_LOG_ERROR, "SELinux", fmt, ap); + LOG_PRI_VA(priority, "SELinux", fmt, ap); va_end(ap); return 0; } diff --git a/core/jni/android_os_SystemClock.cpp b/core/jni/android_os_SystemClock.cpp index 5f4d570..6247844 100644 --- a/core/jni/android_os_SystemClock.cpp +++ b/core/jni/android_os_SystemClock.cpp @@ -19,13 +19,6 @@ * System clock functions. */ -#ifdef HAVE_ANDROID_OS -#include <linux/ioctl.h> -#include <linux/rtc.h> -#include <utils/Atomic.h> -#include <linux/android_alarm.h> -#endif - #include <sys/time.h> #include <limits.h> #include <fcntl.h> @@ -43,109 +36,6 @@ namespace android { -static int setCurrentTimeMillisAlarmDriver(struct timeval *tv) -{ - struct timespec ts; - int fd; - int res; - - fd = open("/dev/alarm", O_RDWR); - if(fd < 0) { - ALOGV("Unable to open alarm driver: %s\n", strerror(errno)); - return -1; - } - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * 1000; - res = ioctl(fd, ANDROID_ALARM_SET_RTC, &ts); - if (res < 0) - ALOGV("ANDROID_ALARM_SET_RTC ioctl failed: %s\n", strerror(errno)); - close(fd); - return res; -} - -static int setCurrentTimeMillisRtc(struct timeval *tv) -{ - struct rtc_time rtc; - struct tm tm, *gmtime_res; - int fd; - int res; - - fd = open("/dev/rtc0", O_RDWR); - if (fd < 0) { - ALOGV("Unable to open RTC driver: %s\n", strerror(errno)); - return -1; - } - - res = settimeofday(tv, NULL); - if (res < 0) { - ALOGV("settimeofday() failed: %s\n", strerror(errno)); - goto done; - } - - gmtime_res = gmtime_r(&tv->tv_sec, &tm); - if (!gmtime_res) { - ALOGV("gmtime_r() failed: %s\n", strerror(errno)); - res = -1; - goto done; - } - - memset(&rtc, 0, sizeof(rtc)); - rtc.tm_sec = tm.tm_sec; - rtc.tm_min = tm.tm_min; - rtc.tm_hour = tm.tm_hour; - rtc.tm_mday = tm.tm_mday; - rtc.tm_mon = tm.tm_mon; - rtc.tm_year = tm.tm_year; - rtc.tm_wday = tm.tm_wday; - rtc.tm_yday = tm.tm_yday; - rtc.tm_isdst = tm.tm_isdst; - res = ioctl(fd, RTC_SET_TIME, &rtc); - if (res < 0) - ALOGV("RTC_SET_TIME ioctl failed: %s\n", strerror(errno)); -done: - close(fd); - return res; -} - -/* - * Set the current time. This only works when running as root. - */ -static int setCurrentTimeMillis(int64_t millis) -{ - struct timeval tv; - int ret; - - if (millis <= 0 || millis / 1000LL >= INT_MAX) { - return -1; - } - - tv.tv_sec = (time_t) (millis / 1000LL); - tv.tv_usec = (suseconds_t) ((millis % 1000LL) * 1000LL); - - ALOGD("Setting time of day to sec=%d\n", (int) tv.tv_sec); - - ret = setCurrentTimeMillisAlarmDriver(&tv); - if (ret < 0) - ret = setCurrentTimeMillisRtc(&tv); - - if(ret < 0) { - ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno)); - ret = -1; - } - return ret; -} - -/* - * native public static void setCurrentTimeMillis(long millis) - * - * Set the current time. This only works when running as root. - */ -static jboolean android_os_SystemClock_setCurrentTimeMillis(JNIEnv* env, - jobject clazz, jlong millis) -{ - return (setCurrentTimeMillis(millis) == 0); -} - /* * native public static long uptimeMillis(); */ @@ -230,8 +120,6 @@ static jlong android_os_SystemClock_elapsedRealtimeNano(JNIEnv* env, */ static JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ - { "setCurrentTimeMillis", "(J)Z", - (void*) android_os_SystemClock_setCurrentTimeMillis }, { "uptimeMillis", "()J", (void*) android_os_SystemClock_uptimeMillis }, { "elapsedRealtime", "()J", diff --git a/core/jni/android_server_NetworkManagementSocketTagger.cpp b/core/jni/android_server_NetworkManagementSocketTagger.cpp index 12beff7..7e12b1e 100644 --- a/core/jni/android_server_NetworkManagementSocketTagger.cpp +++ b/core/jni/android_server_NetworkManagementSocketTagger.cpp @@ -47,8 +47,8 @@ static jint QTagUid_tagSocketFd(JNIEnv* env, jclass, return (jint)res; } -static int QTagUid_untagSocketFd(JNIEnv* env, jclass, - jobject fileDescriptor) { +static jint QTagUid_untagSocketFd(JNIEnv* env, jclass, + jobject fileDescriptor) { int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (env->ExceptionOccurred() != NULL) { diff --git a/core/jni/android_text_AndroidBidi.cpp b/core/jni/android_text_AndroidBidi.cpp index d50a69f..6f7ee49 100644 --- a/core/jni/android_text_AndroidBidi.cpp +++ b/core/jni/android_text_AndroidBidi.cpp @@ -26,7 +26,7 @@ namespace android { static jint runBidi(JNIEnv* env, jobject obj, jint dir, jcharArray chsArray, - jbyteArray infoArray, int n, jboolean haveInfo) + jbyteArray infoArray, jint n, jboolean haveInfo) { // Parameters are checked on java side // Failures from GetXXXArrayElements indicate a serious out-of-memory condition diff --git a/core/jni/android_text_AndroidCharacter.cpp b/core/jni/android_text_AndroidCharacter.cpp index 8b85a7b7..94bd40f 100644 --- a/core/jni/android_text_AndroidCharacter.cpp +++ b/core/jni/android_text_AndroidCharacter.cpp @@ -51,7 +51,8 @@ static int directionality_map[U_CHAR_DIRECTION_COUNT] = { namespace android { -static void getDirectionalities(JNIEnv* env, jobject obj, jcharArray srcArray, jbyteArray destArray, int count) +static void getDirectionalities(JNIEnv* env, jobject obj, jcharArray srcArray, + jbyteArray destArray, jint count) { ScopedCharArrayRO src(env, srcArray); if (src.get() == NULL) { @@ -102,7 +103,7 @@ static jint getEastAsianWidth(JNIEnv* env, jobject obj, jchar input) } static void getEastAsianWidths(JNIEnv* env, jobject obj, jcharArray srcArray, - int start, int count, jbyteArray destArray) + jint start, jint count, jbyteArray destArray) { ScopedCharArrayRO src(env, srcArray); if (src.get() == NULL) { @@ -144,20 +145,20 @@ static void getEastAsianWidths(JNIEnv* env, jobject obj, jcharArray srcArray, } } -static jboolean mirror(JNIEnv* env, jobject obj, jcharArray charArray, int start, int count) +static jboolean mirror(JNIEnv* env, jobject obj, jcharArray charArray, jint start, jint count) { ScopedCharArrayRW data(env, charArray); if (data.get() == NULL) { - return false; + return JNI_FALSE; } if (start < 0 || start > start + count || env->GetArrayLength(charArray) < start + count) { jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", NULL); - return false; + return JNI_FALSE; } - bool ret = false; + jboolean ret = JNI_FALSE; for (int i = start; i < start + count; i++) { // XXX this thinks it knows that surrogates are never mirrored @@ -166,7 +167,7 @@ static jboolean mirror(JNIEnv* env, jobject obj, jcharArray charArray, int start if (c1 != c2) { data[i] = c2; - ret = true; + ret = JNI_TRUE; } } return ret; diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp index aa2c5f39..28a8a5d 100644 --- a/core/jni/android_text_format_Time.cpp +++ b/core/jni/android_text_format_Time.cpp @@ -117,7 +117,7 @@ static jlong android_text_format_Time_normalize(JNIEnv* env, jobject This, time2java(env, This, t); RELEASE_TIMEZONE(This, t) - return result; + return static_cast<jlong>(result); } static void android_text_format_Time_switchTimezone(JNIEnv* env, jobject This, @@ -155,7 +155,7 @@ static jint android_text_format_Time_compare(JNIEnv* env, jobject clazz, RELEASE_TIMEZONE(aObject, a) RELEASE_TIMEZONE(bObject, b) - return result; + return static_cast<jint>(result); } static jstring android_text_format_Time_format2445(JNIEnv* env, jobject This) @@ -346,7 +346,7 @@ static jlong android_text_format_Time_toMillis(JNIEnv* env, jobject This, RELEASE_TIMEZONE(This, t) - return result; + return static_cast<jlong>(result); } static void android_text_format_Time_set(JNIEnv* env, jobject This, jlong millis) @@ -400,10 +400,10 @@ static jboolean android_text_format_Time_parse(JNIEnv* env, jobject This, jstrin if (len < 8) { jniThrowException(env, "android/util/TimeFormatException", "String too short -- expected at least 8 characters."); - return false; + return JNI_FALSE; } - jboolean inUtc = false; + jboolean inUtc = JNI_FALSE; ScopedStringChars s(env, strObj); @@ -414,49 +414,49 @@ static jboolean android_text_format_Time_parse(JNIEnv* env, jobject This, jstrin n += get_char(env, s, 1, 100, &thrown); n += get_char(env, s, 2, 10, &thrown); n += get_char(env, s, 3, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_yearField, n); // month n = get_char(env, s, 4, 10, &thrown); n += get_char(env, s, 5, 1, &thrown); n--; - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_monField, n); // day of month n = get_char(env, s, 6, 10, &thrown); n += get_char(env, s, 7, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_mdayField, n); if (len > 8) { // T - if (!check_char(env, s, 8, 'T')) return false; + if (!check_char(env, s, 8, 'T')) return JNI_FALSE; env->SetBooleanField(This, g_allDayField, JNI_FALSE); // hour n = get_char(env, s, 9, 10, &thrown); n += get_char(env, s, 10, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_hourField, n); // min n = get_char(env, s, 11, 10, &thrown); n += get_char(env, s, 12, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_minField, n); // sec n = get_char(env, s, 13, 10, &thrown); n += get_char(env, s, 14, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_secField, n); if (len > 15) { // Z - if (!check_char(env, s, 15, 'Z')) return false; - inUtc = true; + if (!check_char(env, s, 15, 'Z')) return JNI_FALSE; + inUtc = JNI_TRUE; } } else { env->SetBooleanField(This, g_allDayField, JNI_TRUE); @@ -481,10 +481,10 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env, if (len < 10) { jniThrowException(env, "android/util/TimeFormatException", "String too short --- expected at least 10 characters."); - return false; + return JNI_FALSE; } - jboolean inUtc = false; + jboolean inUtc = JNI_FALSE; ScopedStringChars s(env, strObj); @@ -495,57 +495,57 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env, n += get_char(env, s, 1, 100, &thrown); n += get_char(env, s, 2, 10, &thrown); n += get_char(env, s, 3, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_yearField, n); // - - if (!check_char(env, s, 4, '-')) return false; + if (!check_char(env, s, 4, '-')) return JNI_FALSE; // month n = get_char(env, s, 5, 10, &thrown); n += get_char(env, s, 6, 1, &thrown); --n; - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_monField, n); // - - if (!check_char(env, s, 7, '-')) return false; + if (!check_char(env, s, 7, '-')) return JNI_FALSE; // day n = get_char(env, s, 8, 10, &thrown); n += get_char(env, s, 9, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_mdayField, n); if (len >= 19) { // T - if (!check_char(env, s, 10, 'T')) return false; + if (!check_char(env, s, 10, 'T')) return JNI_FALSE; env->SetBooleanField(This, g_allDayField, JNI_FALSE); // hour n = get_char(env, s, 11, 10, &thrown); n += get_char(env, s, 12, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; int hour = n; // env->SetIntField(This, g_hourField, n); // : - if (!check_char(env, s, 13, ':')) return false; + if (!check_char(env, s, 13, ':')) return JNI_FALSE; // minute n = get_char(env, s, 14, 10, &thrown); n += get_char(env, s, 15, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; int minute = n; // env->SetIntField(This, g_minField, n); // : - if (!check_char(env, s, 16, ':')) return false; + if (!check_char(env, s, 16, ':')) return JNI_FALSE; // second n = get_char(env, s, 17, 10, &thrown); n += get_char(env, s, 18, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; env->SetIntField(This, g_secField, n); // skip the '.XYZ' -- we don't care about subsecond precision. @@ -579,32 +579,32 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env, jniThrowExceptionFmt(env, "android/util/TimeFormatException", "Unexpected character 0x%02x at position %d. Expected + or -", c, tz_index); - return false; + return JNI_FALSE; } - inUtc = true; + inUtc = JNI_TRUE; if (offset != 0) { if (len < tz_index + 6) { jniThrowExceptionFmt(env, "android/util/TimeFormatException", "Unexpected length; should be %d characters", tz_index + 6); - return false; + return JNI_FALSE; } // hour n = get_char(env, s, tz_index + 1, 10, &thrown); n += get_char(env, s, tz_index + 2, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; n *= offset; hour += n; // : - if (!check_char(env, s, tz_index + 3, ':')) return false; + if (!check_char(env, s, tz_index + 3, ':')) return JNI_FALSE; // minute n = get_char(env, s, tz_index + 4, 10, &thrown); n += get_char(env, s, tz_index + 5, 1, &thrown); - if (thrown) return false; + if (thrown) return JNI_FALSE; n *= offset; minute += n; } diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index 8836918..7162a1c 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -35,7 +35,16 @@ #include <androidfw/AssetManager.h> #include <androidfw/ResourceTypes.h> +#include <private/android_filesystem_config.h> // for AID_SYSTEM + #include <stdio.h> +#include <sys/types.h> +#include <sys/wait.h> + +#include <linux/capability.h> +extern "C" int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern "C" int capset(cap_user_header_t hdrp, const cap_user_data_t datap); + namespace android { @@ -88,7 +97,7 @@ jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, { env->SetIntField(outValue, gTypedValueOffsets.mType, value.dataType); env->SetIntField(outValue, gTypedValueOffsets.mAssetCookie, - (jint)table->getTableCookie(block)); + static_cast<jint>(table->getTableCookie(block))); env->SetIntField(outValue, gTypedValueOffsets.mData, value.data); env->SetObjectField(outValue, gTypedValueOffsets.mString, NULL); env->SetIntField(outValue, gTypedValueOffsets.mResourceId, ref); @@ -100,12 +109,70 @@ jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, return block; } +// This is called by zygote (running as user root) as part of preloadResources. +static void verifySystemIdmaps() +{ + pid_t pid; + char system_id[10]; + + snprintf(system_id, sizeof(system_id), "%d", AID_SYSTEM); + + switch (pid = fork()) { + case -1: + ALOGE("failed to fork for idmap: %s", strerror(errno)); + break; + case 0: // child + { + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata; + + memset(&capheader, 0, sizeof(capheader)); + memset(&capdata, 0, sizeof(capdata)); + + capheader.version = _LINUX_CAPABILITY_VERSION; + capheader.pid = 0; + + if (capget(&capheader, &capdata) != 0) { + ALOGE("capget: %s\n", strerror(errno)); + exit(1); + } + + capdata.effective = capdata.permitted; + if (capset(&capheader, &capdata) != 0) { + ALOGE("capset: %s\n", strerror(errno)); + exit(1); + } + + if (setgid(AID_SYSTEM) != 0) { + ALOGE("setgid: %s\n", strerror(errno)); + exit(1); + } + + if (setuid(AID_SYSTEM) != 0) { + ALOGE("setuid: %s\n", strerror(errno)); + exit(1); + } + + execl(AssetManager::IDMAP_BIN, AssetManager::IDMAP_BIN, "--scan", + AssetManager::OVERLAY_DIR, AssetManager::TARGET_PACKAGE_NAME, + AssetManager::TARGET_APK_PATH, AssetManager::IDMAP_DIR, (char*)NULL); + ALOGE("failed to execl for idmap: %s", strerror(errno)); + exit(1); // should never get here + } + break; + default: // parent + waitpid(pid, NULL, 0); + break; + } +} + // ---------------------------------------------------------------------------- // this guy is exported to other jni routines AssetManager* assetManagerForJavaObject(JNIEnv* env, jobject obj) { - AssetManager* am = (AssetManager*)env->GetIntField(obj, gAssetManagerOffsets.mObject); + jlong amHandle = env->GetLongField(obj, gAssetManagerOffsets.mObject); + AssetManager* am = reinterpret_cast<AssetManager*>(amHandle); if (am != NULL) { return am; } @@ -113,7 +180,7 @@ AssetManager* assetManagerForJavaObject(JNIEnv* env, jobject obj) return NULL; } -static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, jstring fileName, jint mode) { AssetManager* am = assetManagerForJavaObject(env, clazz); @@ -125,6 +192,7 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, ScopedUtfChars fileName8(env, fileName); if (fileName8.c_str() == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", "Empty file name"); return -1; } @@ -143,7 +211,7 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, //printf("Created Asset Stream: %p\n", a); - return (jint)a; + return reinterpret_cast<jlong>(a); } static jobject returnParcelFileDescriptor(JNIEnv* env, Asset* a, jlongArray outOffsets) @@ -205,7 +273,7 @@ static jobject android_content_AssetManager_openAssetFd(JNIEnv* env, jobject cla return returnParcelFileDescriptor(env, a, outOffsets); } -static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject clazz, jint cookie, jstring fileName, jint mode) @@ -240,7 +308,7 @@ static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject //printf("Created Asset Stream: %p\n", a); - return (jint)a; + return reinterpret_cast<jlong>(a); } static jobject android_content_AssetManager_openNonAssetFdNative(JNIEnv* env, jobject clazz, @@ -320,9 +388,9 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz } static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); //printf("Destroying Asset Stream: %p\n", a); @@ -335,9 +403,9 @@ static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz } static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -350,10 +418,10 @@ static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject claz } static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, - jint asset, jbyteArray bArray, + jlong assetHandle, jbyteArray bArray, jint off, jint len) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL || bArray == NULL) { jniThrowNullPointerException(env, "asset"); @@ -374,7 +442,7 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, ssize_t res = a->read(b+off, len); env->ReleaseByteArrayElements(bArray, b, 0); - if (res > 0) return res; + if (res > 0) return static_cast<jint>(res); if (res < 0) { jniThrowException(env, "java/io/IOException", ""); @@ -383,10 +451,10 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, } static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz, - jint asset, + jlong assetHandle, jlong offset, jint whence) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -398,9 +466,9 @@ static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz, } static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -411,9 +479,9 @@ static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject cl } static jlong android_content_AssetManager_getAssetRemainingLength(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -442,6 +510,25 @@ static jint android_content_AssetManager_addAssetPath(JNIEnv* env, jobject clazz return (res) ? static_cast<jint>(cookie) : 0; } +static jint android_content_AssetManager_addOverlayPath(JNIEnv* env, jobject clazz, + jstring idmapPath) +{ + ScopedUtfChars idmapPath8(env, idmapPath); + if (idmapPath8.c_str() == NULL) { + return 0; + } + + AssetManager* am = assetManagerForJavaObject(env, clazz); + if (am == NULL) { + return 0; + } + + int32_t cookie; + bool res = am->addOverlayPath(String8(idmapPath8.c_str()), &cookie); + + return (res) ? (jint)cookie : 0; +} + static jboolean android_content_AssetManager_isUpToDate(JNIEnv* env, jobject clazz) { AssetManager* am = assetManagerForJavaObject(env, clazz); @@ -725,7 +812,11 @@ static jint android_content_AssetManager_loadResourceValue(JNIEnv* env, jobject } #endif } - return block >= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config) : block; + if (block >= 0) { + return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config); + } + + return static_cast<jint>(block); } static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobject clazz, @@ -759,7 +850,7 @@ static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobje res.unlock(); if (block < 0) { - return block; + return static_cast<jint>(block); } uint32_t ref = ident; @@ -772,7 +863,11 @@ static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobje } #endif } - return block >= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags) : block; + if (block >= 0) { + return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags); + } + + return static_cast<jint>(block); } static jint android_content_AssetManager_getStringBlockCount(JNIEnv* env, jobject clazz) @@ -784,14 +879,14 @@ static jint android_content_AssetManager_getStringBlockCount(JNIEnv* env, jobjec return am->getResources().getTableCount(); } -static jint android_content_AssetManager_getNativeStringBlock(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_getNativeStringBlock(JNIEnv* env, jobject clazz, jint block) { AssetManager* am = assetManagerForJavaObject(env, clazz); if (am == NULL) { return 0; } - return (jint)am->getResources().getTableStringBlock(block); + return reinterpret_cast<jlong>(am->getResources().getTableStringBlock(block)); } static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject clazz, @@ -810,43 +905,43 @@ static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject c return str; } -static jint android_content_AssetManager_newTheme(JNIEnv* env, jobject clazz) +static jlong android_content_AssetManager_newTheme(JNIEnv* env, jobject clazz) { AssetManager* am = assetManagerForJavaObject(env, clazz); if (am == NULL) { return 0; } - return (jint)(new ResTable::Theme(am->getResources())); + return reinterpret_cast<jlong>(new ResTable::Theme(am->getResources())); } static void android_content_AssetManager_deleteTheme(JNIEnv* env, jobject clazz, - jint themeInt) + jlong themeHandle) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); delete theme; } static void android_content_AssetManager_applyThemeStyle(JNIEnv* env, jobject clazz, - jint themeInt, + jlong themeHandle, jint styleRes, jboolean force) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); theme->applyStyle(styleRes, force ? true : false); } static void android_content_AssetManager_copyTheme(JNIEnv* env, jobject clazz, - jint destInt, jint srcInt) + jlong destHandle, jlong srcHandle) { - ResTable::Theme* dest = (ResTable::Theme*)destInt; - ResTable::Theme* src = (ResTable::Theme*)srcInt; + ResTable::Theme* dest = reinterpret_cast<ResTable::Theme*>(destHandle); + ResTable::Theme* src = reinterpret_cast<ResTable::Theme*>(srcHandle); dest->setTo(*src); } static jint android_content_AssetManager_loadThemeAttributeValue( - JNIEnv* env, jobject clazz, jint themeInt, jint ident, jobject outValue, jboolean resolve) + JNIEnv* env, jobject clazz, jlong themeHandle, jint ident, jobject outValue, jboolean resolve) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); const ResTable& res(theme->getResTable()); Res_value value; @@ -867,10 +962,10 @@ static jint android_content_AssetManager_loadThemeAttributeValue( } static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, - jint themeInt, jint pri, + jlong themeHandle, jint pri, jstring tag, jstring prefix) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); const ResTable& res(theme->getResTable()); // XXX Need to use params. @@ -878,10 +973,10 @@ static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, } static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject clazz, - jint themeToken, + jlong themeToken, jint defStyleAttr, jint defStyleRes, - jint xmlParserToken, + jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) @@ -902,9 +997,9 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla DEBUG_STYLES(LOGI("APPLY STYLE: theme=0x%x defStyleAttr=0x%x defStyleRes=0x%x xml=0x%x", themeToken, defStyleAttr, defStyleRes, xmlParserToken)); - ResTable::Theme* theme = (ResTable::Theme*)themeToken; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); const ResTable& res = theme->getResTable(); - ResXMLParser* xmlParser = (ResXMLParser*)xmlParserToken; + ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); ResTable_config config; Res_value value; @@ -1097,7 +1192,7 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; dest[STYLE_ASSET_COOKIE] = - block != kXmlBlock ? (jint)res.getTableCookie(block) : (jint)-1; + block != kXmlBlock ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1; dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1123,7 +1218,7 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla } static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, - jint xmlParserToken, + jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) @@ -1240,7 +1335,7 @@ static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, job dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; dest[STYLE_ASSET_COOKIE] = - block != kXmlBlock ? (jint)res.getTableCookie(block) : (jint)-1; + block != kXmlBlock ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1; dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1280,7 +1375,7 @@ static jint android_content_AssetManager_getArraySize(JNIEnv* env, jobject clazz ssize_t bagOff = res.getBagLocked(id, &defStyleEnt); res.unlock(); - return bagOff; + return static_cast<jint>(bagOff); } static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject clazz, @@ -1352,7 +1447,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz // Write the final value back to Java. dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; - dest[STYLE_ASSET_COOKIE] = (jint)res.getTableCookie(block); + dest[STYLE_ASSET_COOKIE] = reinterpret_cast<jint>(res.getTableCookie(block)); dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1370,7 +1465,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz return i; } -static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject clazz, jint cookie, jstring fileName) { @@ -1405,7 +1500,7 @@ static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject return 0; } - return (jint)block; + return reinterpret_cast<jlong>(block); } static jintArray android_content_AssetManager_getArrayStringInfo(JNIEnv* env, jobject clazz, @@ -1569,8 +1664,11 @@ static jintArray android_content_AssetManager_getArrayIntResource(JNIEnv* env, j return array; } -static void android_content_AssetManager_init(JNIEnv* env, jobject clazz) +static void android_content_AssetManager_init(JNIEnv* env, jobject clazz, jboolean isSystem) { + if (isSystem) { + verifySystemIdmaps(); + } AssetManager* am = new AssetManager(); if (am == NULL) { jniThrowException(env, "java/lang/OutOfMemoryError", ""); @@ -1580,17 +1678,17 @@ static void android_content_AssetManager_init(JNIEnv* env, jobject clazz) am->addDefaultAssets(); ALOGV("Created AssetManager %p for Java object %p\n", am, clazz); - env->SetIntField(clazz, gAssetManagerOffsets.mObject, (jint)am); + env->SetLongField(clazz, gAssetManagerOffsets.mObject, reinterpret_cast<jlong>(am)); } static void android_content_AssetManager_destroy(JNIEnv* env, jobject clazz) { AssetManager* am = (AssetManager*) - (env->GetIntField(clazz, gAssetManagerOffsets.mObject)); + (env->GetLongField(clazz, gAssetManagerOffsets.mObject)); ALOGV("Destroying AssetManager %p for Java object %p\n", am, clazz); if (am != NULL) { delete am; - env->SetIntField(clazz, gAssetManagerOffsets.mObject, 0); + env->SetLongField(clazz, gAssetManagerOffsets.mObject, 0); } } @@ -1624,30 +1722,32 @@ static JNINativeMethod gAssetManagerMethods[] = { /* name, signature, funcPtr */ // Basic asset stuff. - { "openAsset", "(Ljava/lang/String;I)I", + { "openAsset", "(Ljava/lang/String;I)J", (void*) android_content_AssetManager_openAsset }, { "openAssetFd", "(Ljava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", (void*) android_content_AssetManager_openAssetFd }, - { "openNonAssetNative", "(ILjava/lang/String;I)I", + { "openNonAssetNative", "(ILjava/lang/String;I)J", (void*) android_content_AssetManager_openNonAssetNative }, { "openNonAssetFdNative", "(ILjava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", (void*) android_content_AssetManager_openNonAssetFdNative }, { "list", "(Ljava/lang/String;)[Ljava/lang/String;", (void*) android_content_AssetManager_list }, - { "destroyAsset", "(I)V", + { "destroyAsset", "(J)V", (void*) android_content_AssetManager_destroyAsset }, - { "readAssetChar", "(I)I", + { "readAssetChar", "(J)I", (void*) android_content_AssetManager_readAssetChar }, - { "readAsset", "(I[BII)I", + { "readAsset", "(J[BII)I", (void*) android_content_AssetManager_readAsset }, - { "seekAsset", "(IJI)J", + { "seekAsset", "(JJI)J", (void*) android_content_AssetManager_seekAsset }, - { "getAssetLength", "(I)J", + { "getAssetLength", "(J)J", (void*) android_content_AssetManager_getAssetLength }, - { "getAssetRemainingLength", "(I)J", + { "getAssetRemainingLength", "(J)J", (void*) android_content_AssetManager_getAssetRemainingLength }, { "addAssetPathNative", "(Ljava/lang/String;)I", (void*) android_content_AssetManager_addAssetPath }, + { "addOverlayPath", "(Ljava/lang/String;)I", + (void*) android_content_AssetManager_addOverlayPath }, { "isUpToDate", "()Z", (void*) android_content_AssetManager_isUpToDate }, @@ -1674,27 +1774,27 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_loadResourceBagValue }, { "getStringBlockCount","()I", (void*) android_content_AssetManager_getStringBlockCount }, - { "getNativeStringBlock","(I)I", + { "getNativeStringBlock","(I)J", (void*) android_content_AssetManager_getNativeStringBlock }, { "getCookieName","(I)Ljava/lang/String;", (void*) android_content_AssetManager_getCookieName }, // Themes. - { "newTheme", "()I", + { "newTheme", "()J", (void*) android_content_AssetManager_newTheme }, - { "deleteTheme", "(I)V", + { "deleteTheme", "(J)V", (void*) android_content_AssetManager_deleteTheme }, - { "applyThemeStyle", "(IIZ)V", + { "applyThemeStyle", "(JIZ)V", (void*) android_content_AssetManager_applyThemeStyle }, - { "copyTheme", "(II)V", + { "copyTheme", "(JJ)V", (void*) android_content_AssetManager_copyTheme }, - { "loadThemeAttributeValue", "(IILandroid/util/TypedValue;Z)I", + { "loadThemeAttributeValue", "(JILandroid/util/TypedValue;Z)I", (void*) android_content_AssetManager_loadThemeAttributeValue }, - { "dumpTheme", "(IILjava/lang/String;Ljava/lang/String;)V", + { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", (void*) android_content_AssetManager_dumpTheme }, - { "applyStyle","(IIII[I[I[I)Z", + { "applyStyle","(JIIJ[I[I[I)Z", (void*) android_content_AssetManager_applyStyle }, - { "retrieveAttributes","(I[I[I[I)Z", + { "retrieveAttributes","(J[I[I[I)Z", (void*) android_content_AssetManager_retrieveAttributes }, { "getArraySize","(I)I", (void*) android_content_AssetManager_getArraySize }, @@ -1702,7 +1802,7 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_retrieveArray }, // XML files. - { "openXmlAssetNative", "(ILjava/lang/String;)I", + { "openXmlAssetNative", "(ILjava/lang/String;)J", (void*) android_content_AssetManager_openXmlAssetNative }, // Arrays. @@ -1714,7 +1814,7 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_getArrayIntResource }, // Bookkeeping. - { "init", "()V", + { "init", "(Z)V", (void*) android_content_AssetManager_init }, { "destroy", "()V", (void*) android_content_AssetManager_destroy }, @@ -1766,7 +1866,7 @@ int register_android_content_AssetManager(JNIEnv* env) jclass assetManager = env->FindClass("android/content/res/AssetManager"); LOG_FATAL_IF(assetManager == NULL, "Unable to find class android/content/res/AssetManager"); gAssetManagerOffsets.mObject - = env->GetFieldID(assetManager, "mObject", "I"); + = env->GetFieldID(assetManager, "mObject", "J"); LOG_FATAL_IF(gAssetManagerOffsets.mObject == NULL, "Unable to find AssetManager.mObject"); jclass stringClass = env->FindClass("java/lang/String"); diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp index 2593420..8a0eaa2 100644 --- a/core/jni/android_util_EventLog.cpp +++ b/core/jni/android_util_EventLog.cpp @@ -177,13 +177,13 @@ static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz UNUSED, break; } if (ret < 0) { - if (errno == EINTR) { + if (ret == -EINTR) { continue; } - if (errno == EINVAL) { + if (ret == -EINVAL) { jniThrowException(env, "java/io/IOException", "Event too short"); - } else if (errno != EAGAIN) { - jniThrowIOException(env, errno); // Will throw on return + } else if (ret != -EAGAIN) { + jniThrowIOException(env, -ret); // Will throw on return } break; } diff --git a/core/jni/android_util_Log.cpp b/core/jni/android_util_Log.cpp index 536a582..93dcbef 100644 --- a/core/jni/android_util_Log.cpp +++ b/core/jni/android_util_Log.cpp @@ -85,7 +85,7 @@ static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring jboolean result = false; if ((strlen(chars)+sizeof(LOG_NAMESPACE)) > PROPERTY_KEY_MAX) { char buf2[200]; - snprintf(buf2, sizeof(buf2), "Log tag \"%s\" exceeds limit of %d characters\n", + snprintf(buf2, sizeof(buf2), "Log tag \"%s\" exceeds limit of %zu characters\n", chars, PROPERTY_KEY_MAX - sizeof(LOG_NAMESPACE)); jniThrowException(env, "java/lang/IllegalArgumentException", buf2); diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index cbed99f..a4efed7 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -19,8 +19,8 @@ #include <utils/Log.h> #include <binder/IPCThreadState.h> -#include <binder/ProcessState.h> #include <binder/IServiceManager.h> +#include <cutils/process_name.h> #include <cutils/sched_policy.h> #include <utils/String8.h> #include <utils/Vector.h> @@ -385,7 +385,9 @@ void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) } if (name8.size() > 0) { - ProcessState::self()->setArgV0(name8.string()); + const char* procName = name8.string(); + set_process_name(procName); + AndroidRuntime::getRuntime()->setArgv0(procName); } } diff --git a/core/jni/android_util_StringBlock.cpp b/core/jni/android_util_StringBlock.cpp index 463d3c0..f29250f 100644 --- a/core/jni/android_util_StringBlock.cpp +++ b/core/jni/android_util_StringBlock.cpp @@ -31,7 +31,7 @@ namespace android { // ---------------------------------------------------------------------------- -static jint android_content_StringBlock_nativeCreate(JNIEnv* env, jobject clazz, +static jlong android_content_StringBlock_nativeCreate(JNIEnv* env, jobject clazz, jbyteArray bArray, jint off, jint len) { @@ -56,13 +56,13 @@ static jint android_content_StringBlock_nativeCreate(JNIEnv* env, jobject clazz, return 0; } - return (jint)osb; + return reinterpret_cast<jlong>(osb); } static jint android_content_StringBlock_nativeGetSize(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResStringPool* osb = (ResStringPool*)token; + ResStringPool* osb = reinterpret_cast<ResStringPool*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return 0; @@ -72,9 +72,9 @@ static jint android_content_StringBlock_nativeGetSize(JNIEnv* env, jobject clazz } static jstring android_content_StringBlock_nativeGetString(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResStringPool* osb = (ResStringPool*)token; + ResStringPool* osb = reinterpret_cast<ResStringPool*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return 0; @@ -96,9 +96,9 @@ static jstring android_content_StringBlock_nativeGetString(JNIEnv* env, jobject } static jintArray android_content_StringBlock_nativeGetStyle(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResStringPool* osb = (ResStringPool*)token; + ResStringPool* osb = reinterpret_cast<ResStringPool*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return NULL; @@ -139,9 +139,9 @@ static jintArray android_content_StringBlock_nativeGetStyle(JNIEnv* env, jobject } static void android_content_StringBlock_nativeDestroy(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResStringPool* osb = (ResStringPool*)token; + ResStringPool* osb = reinterpret_cast<ResStringPool*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return; @@ -157,15 +157,15 @@ static void android_content_StringBlock_nativeDestroy(JNIEnv* env, jobject clazz */ static JNINativeMethod gStringBlockMethods[] = { /* name, signature, funcPtr */ - { "nativeCreate", "([BII)I", + { "nativeCreate", "([BII)J", (void*) android_content_StringBlock_nativeCreate }, - { "nativeGetSize", "(I)I", + { "nativeGetSize", "(J)I", (void*) android_content_StringBlock_nativeGetSize }, - { "nativeGetString", "(II)Ljava/lang/String;", + { "nativeGetString", "(JI)Ljava/lang/String;", (void*) android_content_StringBlock_nativeGetString }, - { "nativeGetStyle", "(II)[I", + { "nativeGetStyle", "(JI)[I", (void*) android_content_StringBlock_nativeGetStyle }, - { "nativeDestroy", "(I)V", + { "nativeDestroy", "(J)V", (void*) android_content_StringBlock_nativeDestroy }, }; diff --git a/core/jni/android_util_XmlBlock.cpp b/core/jni/android_util_XmlBlock.cpp index ad6033b..03de5c0 100644 --- a/core/jni/android_util_XmlBlock.cpp +++ b/core/jni/android_util_XmlBlock.cpp @@ -31,7 +31,7 @@ namespace android { // ---------------------------------------------------------------------------- -static jint android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz, +static jlong android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz, jbyteArray bArray, jint off, jint len) { @@ -55,25 +55,25 @@ static jint android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz, return 0; } - return (jint)osb; + return reinterpret_cast<jlong>(osb); } -static jint android_content_XmlBlock_nativeGetStringBlock(JNIEnv* env, jobject clazz, - jint token) +static jlong android_content_XmlBlock_nativeGetStringBlock(JNIEnv* env, jobject clazz, + jlong token) { - ResXMLTree* osb = (ResXMLTree*)token; + ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)&osb->getStrings(); + return reinterpret_cast<jlong>(&osb->getStrings()); } -static jint android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject clazz, - jint token) +static jlong android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject clazz, + jlong token) { - ResXMLTree* osb = (ResXMLTree*)token; + ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return 0; @@ -87,19 +87,19 @@ static jint android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject st->restart(); - return (jint)st; + return reinterpret_cast<jlong>(st); } static jint android_content_XmlBlock_nativeNext(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { return ResXMLParser::END_DOCUMENT; } do { - jint code = (jint)st->next(); + ResXMLParser::event_code_t code = st->next(); switch (code) { case ResXMLParser::START_TAG: return 2; @@ -123,139 +123,139 @@ bad: } static jint android_content_XmlBlock_nativeGetNamespace(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { return -1; } - return (jint)st->getElementNamespaceID(); + return static_cast<jint>(st->getElementNamespaceID()); } static jint android_content_XmlBlock_nativeGetName(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { return -1; } - return (jint)st->getElementNameID(); + return static_cast<jint>(st->getElementNameID()); } static jint android_content_XmlBlock_nativeGetText(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { return -1; } - return (jint)st->getTextID(); + return static_cast<jint>(st->getTextID()); } static jint android_content_XmlBlock_nativeGetLineNumber(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getLineNumber(); + return static_cast<jint>(st->getLineNumber()); } static jint android_content_XmlBlock_nativeGetAttributeCount(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeCount(); + return static_cast<jint>(st->getAttributeCount()); } static jint android_content_XmlBlock_nativeGetAttributeNamespace(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeNamespaceID(idx); + return static_cast<jint>(st->getAttributeNamespaceID(idx)); } static jint android_content_XmlBlock_nativeGetAttributeName(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeNameID(idx); + return static_cast<jint>(st->getAttributeNameID(idx)); } static jint android_content_XmlBlock_nativeGetAttributeResource(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeNameResID(idx); + return static_cast<jint>(st->getAttributeNameResID(idx)); } static jint android_content_XmlBlock_nativeGetAttributeDataType(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeDataType(idx); + return static_cast<jint>(st->getAttributeDataType(idx)); } static jint android_content_XmlBlock_nativeGetAttributeData(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeData(idx); + return static_cast<jint>(st->getAttributeData(idx)); } static jint android_content_XmlBlock_nativeGetAttributeStringValue(JNIEnv* env, jobject clazz, - jint token, jint idx) + jlong token, jint idx) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } - return (jint)st->getAttributeValueStringID(idx); + return static_cast<jint>(st->getAttributeValueStringID(idx)); } static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobject clazz, - jint token, + jlong token, jstring ns, jstring name) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL || name == NULL) { jniThrowNullPointerException(env, NULL); return 0; @@ -271,7 +271,7 @@ static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobjec const char16_t* name16 = env->GetStringChars(name, NULL); jsize nameLen = env->GetStringLength(name); - jint idx = (jint)st->indexOfAttribute(ns16, nsLen, name16, nameLen); + jint idx = static_cast<jint>(st->indexOfAttribute(ns16, nsLen, name16, nameLen)); if (ns) { env->ReleaseStringChars(ns, ns16); @@ -282,35 +282,35 @@ static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobjec } static jint android_content_XmlBlock_nativeGetIdAttribute(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } ssize_t idx = st->indexOfID(); - return idx >= 0 ? (jint)st->getAttributeValueStringID(idx) : -1; + return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1; } static jint android_content_XmlBlock_nativeGetClassAttribute(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; } ssize_t idx = st->indexOfClass(); - return idx >= 0 ? (jint)st->getAttributeValueStringID(idx) : -1; + return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1; } static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return 0; @@ -332,9 +332,9 @@ static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobjec } static void android_content_XmlBlock_nativeDestroyParseState(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLParser* st = (ResXMLParser*)token; + ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); if (st == NULL) { jniThrowNullPointerException(env, NULL); return; @@ -344,9 +344,9 @@ static void android_content_XmlBlock_nativeDestroyParseState(JNIEnv* env, jobjec } static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz, - jint token) + jlong token) { - ResXMLTree* osb = (ResXMLTree*)token; + ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); if (osb == NULL) { jniThrowNullPointerException(env, NULL); return; @@ -362,47 +362,47 @@ static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz, */ static JNINativeMethod gXmlBlockMethods[] = { /* name, signature, funcPtr */ - { "nativeCreate", "([BII)I", + { "nativeCreate", "([BII)J", (void*) android_content_XmlBlock_nativeCreate }, - { "nativeGetStringBlock", "(I)I", + { "nativeGetStringBlock", "(J)J", (void*) android_content_XmlBlock_nativeGetStringBlock }, - { "nativeCreateParseState", "(I)I", + { "nativeCreateParseState", "(J)J", (void*) android_content_XmlBlock_nativeCreateParseState }, - { "nativeNext", "(I)I", + { "nativeNext", "(J)I", (void*) android_content_XmlBlock_nativeNext }, - { "nativeGetNamespace", "(I)I", + { "nativeGetNamespace", "(J)I", (void*) android_content_XmlBlock_nativeGetNamespace }, - { "nativeGetName", "(I)I", + { "nativeGetName", "(J)I", (void*) android_content_XmlBlock_nativeGetName }, - { "nativeGetText", "(I)I", + { "nativeGetText", "(J)I", (void*) android_content_XmlBlock_nativeGetText }, - { "nativeGetLineNumber", "(I)I", + { "nativeGetLineNumber", "(J)I", (void*) android_content_XmlBlock_nativeGetLineNumber }, - { "nativeGetAttributeCount", "(I)I", + { "nativeGetAttributeCount", "(J)I", (void*) android_content_XmlBlock_nativeGetAttributeCount }, - { "nativeGetAttributeNamespace","(II)I", + { "nativeGetAttributeNamespace","(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeNamespace }, - { "nativeGetAttributeName", "(II)I", + { "nativeGetAttributeName", "(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeName }, - { "nativeGetAttributeResource", "(II)I", + { "nativeGetAttributeResource", "(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeResource }, - { "nativeGetAttributeDataType", "(II)I", + { "nativeGetAttributeDataType", "(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeDataType }, - { "nativeGetAttributeData", "(II)I", + { "nativeGetAttributeData", "(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeData }, - { "nativeGetAttributeStringValue", "(II)I", + { "nativeGetAttributeStringValue", "(JI)I", (void*) android_content_XmlBlock_nativeGetAttributeStringValue }, - { "nativeGetAttributeIndex", "(ILjava/lang/String;Ljava/lang/String;)I", + { "nativeGetAttributeIndex", "(JLjava/lang/String;Ljava/lang/String;)I", (void*) android_content_XmlBlock_nativeGetAttributeIndex }, - { "nativeGetIdAttribute", "(I)I", + { "nativeGetIdAttribute", "(J)I", (void*) android_content_XmlBlock_nativeGetIdAttribute }, - { "nativeGetClassAttribute", "(I)I", + { "nativeGetClassAttribute", "(J)I", (void*) android_content_XmlBlock_nativeGetClassAttribute }, - { "nativeGetStyleAttribute", "(I)I", + { "nativeGetStyleAttribute", "(J)I", (void*) android_content_XmlBlock_nativeGetStyleAttribute }, - { "nativeDestroyParseState", "(I)V", + { "nativeDestroyParseState", "(J)V", (void*) android_content_XmlBlock_nativeDestroyParseState }, - { "nativeDestroy", "(I)V", + { "nativeDestroy", "(J)V", (void*) android_content_XmlBlock_nativeDestroy }, }; diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index d3c40cf..591ff77 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -118,14 +118,12 @@ static void android_view_GLES20Canvas_terminateCaches(JNIEnv* env, jobject clazz // ---------------------------------------------------------------------------- static void android_view_GLES20Canvas_initAtlas(JNIEnv* env, jobject clazz, - jobject graphicBuffer, jintArray atlasMapArray, jint count) { + jobject graphicBuffer, jlongArray atlasMapArray, jint count) { sp<GraphicBuffer> buffer = graphicBufferForJavaObject(env, graphicBuffer); - jint* atlasMap = env->GetIntArrayElements(atlasMapArray, NULL); - - Caches::getInstance().assetAtlas.init(buffer, atlasMap, count); - - env->ReleaseIntArrayElements(atlasMapArray, atlasMap, 0); + jlong* jAtlasMap = env->GetLongArrayElements(atlasMapArray, NULL); + Caches::getInstance().assetAtlas.init(buffer, jAtlasMap, count); + env->ReleaseLongArrayElements(atlasMapArray, jAtlasMap, 0); } // ---------------------------------------------------------------------------- @@ -1163,7 +1161,7 @@ static JNINativeMethod gMethods[] = { { "nInitCaches", "()Z", (void*) android_view_GLES20Canvas_initCaches }, { "nTerminateCaches", "()V", (void*) android_view_GLES20Canvas_terminateCaches }, - { "nInitAtlas", "(Landroid/view/GraphicBuffer;[II)V", + { "nInitAtlas", "(Landroid/view/GraphicBuffer;[JI)V", (void*) android_view_GLES20Canvas_initAtlas }, { "nCreateRenderer", "()J", (void*) android_view_GLES20Canvas_createRenderer }, diff --git a/core/jni/android_view_SurfaceSession.cpp b/core/jni/android_view_SurfaceSession.cpp index 87e339c..609c565 100644 --- a/core/jni/android_view_SurfaceSession.cpp +++ b/core/jni/android_view_SurfaceSession.cpp @@ -35,22 +35,22 @@ static struct { sp<SurfaceComposerClient> android_view_SurfaceSession_getClient( JNIEnv* env, jobject surfaceSessionObj) { return reinterpret_cast<SurfaceComposerClient*>( - env->GetIntField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient)); + env->GetLongField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient)); } -static jint nativeCreate(JNIEnv* env, jclass clazz) { +static jlong nativeCreate(JNIEnv* env, jclass clazz) { SurfaceComposerClient* client = new SurfaceComposerClient(); client->incStrong((void*)nativeCreate); - return reinterpret_cast<jint>(client); + return reinterpret_cast<jlong>(client); } -static void nativeDestroy(JNIEnv* env, jclass clazz, jint ptr) { +static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) { SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); client->decStrong((void*)nativeCreate); } -static void nativeKill(JNIEnv* env, jclass clazz, jint ptr) { +static void nativeKill(JNIEnv* env, jclass clazz, jlong ptr) { SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); client->dispose(); } @@ -58,11 +58,11 @@ static void nativeKill(JNIEnv* env, jclass clazz, jint ptr) { static JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ - { "nativeCreate", "()I", + { "nativeCreate", "()J", (void*)nativeCreate }, - { "nativeDestroy", "(I)V", + { "nativeDestroy", "(J)V", (void*)nativeDestroy }, - { "nativeKill", "(I)V", + { "nativeKill", "(J)V", (void*)nativeKill } }; @@ -72,7 +72,7 @@ int register_android_view_SurfaceSession(JNIEnv* env) { LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods."); jclass clazz = env->FindClass("android/view/SurfaceSession"); - gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "I"); + gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "J"); return 0; } diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp index a860918..2004576 100644 --- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp +++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp @@ -19,11 +19,12 @@ #include <android_runtime/AndroidRuntime.h> -#include <utils/Log.h> -#include <androidfw/ZipFileRO.h> -#include <androidfw/ZipUtils.h> #include <ScopedUtfChars.h> #include <UniquePtr.h> +#include <androidfw/ZipFileRO.h> +#include <androidfw/ZipUtils.h> +#include <utils/Log.h> +#include <utils/Vector.h> #include <zlib.h> @@ -54,17 +55,19 @@ namespace android { // These match PackageManager.java install codes -typedef enum { +enum install_status_t { INSTALL_SUCCEEDED = 1, INSTALL_FAILED_INVALID_APK = -2, INSTALL_FAILED_INSUFFICIENT_STORAGE = -4, INSTALL_FAILED_CONTAINER_ERROR = -18, INSTALL_FAILED_INTERNAL_ERROR = -110, -} install_status_t; + INSTALL_FAILED_NO_MATCHING_ABIS = -112, + NO_NATIVE_LIBRARIES = -113 +}; typedef install_status_t (*iterFunc)(JNIEnv*, void*, ZipFileRO*, ZipEntryRO, const char*); -// Equivalent to isFilenameSafe +// Equivalent to android.os.FileUtils.isFilenameSafe static bool isFilenameSafe(const char* filename) { @@ -268,126 +271,252 @@ copyFileIfChanged(JNIEnv *env, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntr return INSTALL_SUCCEEDED; } -static install_status_t -iterateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2, - iterFunc callFunc, void* callArg) { - ScopedUtfChars filePath(env, javaFilePath); - ScopedUtfChars cpuAbi(env, javaCpuAbi); - ScopedUtfChars cpuAbi2(env, javaCpuAbi2); - - UniquePtr<ZipFileRO> zipFile(ZipFileRO::open(filePath.c_str())); - if (zipFile.get() == NULL) { - ALOGI("Couldn't open APK %s\n", filePath.c_str()); - return INSTALL_FAILED_INVALID_APK; +/* + * An iterator over all shared libraries in a zip file. An entry is + * considered to be a shared library if all of the conditions below are + * satisfied : + * + * - The entry is under the lib/ directory. + * - The entry name ends with ".so" and the entry name starts with "lib", + * an exception is made for entries whose name is "gdbserver". + * - The entry filename is "safe" (as determined by isFilenameSafe). + * + */ +class NativeLibrariesIterator { +private: + NativeLibrariesIterator(ZipFileRO* zipFile, void* cookie) + : mZipFile(zipFile), mCookie(cookie), mLastSlash(NULL) { + fileName[0] = '\0'; } - char fileName[PATH_MAX]; - bool hasPrimaryAbi = false; +public: + static NativeLibrariesIterator* create(ZipFileRO* zipFile) { + void* cookie = NULL; + if (!zipFile->startIteration(&cookie)) { + return NULL; + } - void* cookie = NULL; - if (!zipFile->startIteration(&cookie)) { - ALOGI("Couldn't iterate over APK%s\n", filePath.c_str()); - return INSTALL_FAILED_INVALID_APK; + return new NativeLibrariesIterator(zipFile, cookie); } - ZipEntryRO entry = NULL; - while ((entry = zipFile->nextEntry(cookie)) != NULL) { - // Make sure this entry has a filename. - if (zipFile->getEntryFileName(entry, fileName, sizeof(fileName))) { - continue; - } + ZipEntryRO next() { + ZipEntryRO next = NULL; + while ((next = mZipFile->nextEntry(mCookie)) != NULL) { + // Make sure this entry has a filename. + if (mZipFile->getEntryFileName(next, fileName, sizeof(fileName))) { + continue; + } - // Make sure we're in the lib directory of the ZIP. - if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) { - continue; - } + // Make sure we're in the lib directory of the ZIP. + if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) { + continue; + } - // Make sure the filename is at least to the minimum library name size. - const size_t fileNameLen = strlen(fileName); - static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN; - if (fileNameLen < minLength) { - continue; - } + // Make sure the filename is at least to the minimum library name size. + const size_t fileNameLen = strlen(fileName); + static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN; + if (fileNameLen < minLength) { + continue; + } - const char* lastSlash = strrchr(fileName, '/'); - ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName); + const char* lastSlash = strrchr(fileName, '/'); + ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName); - // Check to make sure the CPU ABI of this file is one we support. - const char* cpuAbiOffset = fileName + APK_LIB_LEN; - const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset; + // Exception: If we find the gdbserver binary, return it. + if (!strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) { + break; + } - ALOGV("Comparing ABIs %s and %s versus %s\n", cpuAbi.c_str(), cpuAbi2.c_str(), cpuAbiOffset); - if (cpuAbi.size() == cpuAbiRegionSize - && *(cpuAbiOffset + cpuAbi.size()) == '/' - && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) { - ALOGV("Using primary ABI %s\n", cpuAbi.c_str()); - hasPrimaryAbi = true; - } else if (cpuAbi2.size() == cpuAbiRegionSize - && *(cpuAbiOffset + cpuAbi2.size()) == '/' - && !strncmp(cpuAbiOffset, cpuAbi2.c_str(), cpuAbiRegionSize)) { - - /* - * If this library matches both the primary and secondary ABIs, - * only use the primary ABI. - */ - if (hasPrimaryAbi) { - ALOGV("Already saw primary ABI, skipping secondary ABI %s\n", cpuAbi2.c_str()); + // Make sure the filename starts with lib and ends with ".so". + if (strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN) + || strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)) { continue; - } else { - ALOGV("Using secondary ABI %s\n", cpuAbi2.c_str()); } - } else { - ALOGV("abi didn't match anything: %s (end at %zd)\n", cpuAbiOffset, cpuAbiRegionSize); - continue; + + // Make sure the filename is safe. + if (!isFilenameSafe(lastSlash + 1)) { + continue; + } + + mLastSlash = lastSlash; + break; } - // If this is a .so file, check to see if we need to copy it. - if ((!strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN) - && !strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN) - && isFilenameSafe(lastSlash + 1)) - || !strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) { + return next; + } + + inline const char* currentEntry() const { + return fileName; + } + + inline const char* lastSlash() const { + return mLastSlash; + } + + virtual ~NativeLibrariesIterator() { + mZipFile->endIteration(mCookie); + } +private: + + char fileName[PATH_MAX]; + ZipFileRO* const mZipFile; + void* mCookie; + const char* mLastSlash; +}; - install_status_t ret = callFunc(env, callArg, zipFile.get(), entry, lastSlash + 1); +static install_status_t +iterateOverNativeFiles(JNIEnv *env, jlong apkHandle, jstring javaCpuAbi, + iterFunc callFunc, void* callArg) { + ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle); + if (zipFile == NULL) { + return INSTALL_FAILED_INVALID_APK; + } + + UniquePtr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile)); + if (it.get() == NULL) { + return INSTALL_FAILED_INVALID_APK; + } + + const ScopedUtfChars cpuAbi(env, javaCpuAbi); + if (cpuAbi.c_str() == NULL) { + // This would've thrown, so this return code isn't observable by + // Java. + return INSTALL_FAILED_INVALID_APK; + } + ZipEntryRO entry = NULL; + while ((entry = it->next()) != NULL) { + const char* fileName = it->currentEntry(); + const char* lastSlash = it->lastSlash(); + + // Check to make sure the CPU ABI of this file is one we support. + const char* cpuAbiOffset = fileName + APK_LIB_LEN; + const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset; + + if (cpuAbi.size() == cpuAbiRegionSize && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) { + install_status_t ret = callFunc(env, callArg, zipFile, entry, lastSlash + 1); if (ret != INSTALL_SUCCEEDED) { ALOGV("Failure for entry %s", lastSlash + 1); - zipFile->endIteration(cookie); return ret; } } } - zipFile->endIteration(cookie); - return INSTALL_SUCCEEDED; } + +static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray) { + const int numAbis = env->GetArrayLength(supportedAbisArray); + Vector<ScopedUtfChars*> supportedAbis; + + for (int i = 0; i < numAbis; ++i) { + supportedAbis.add(new ScopedUtfChars(env, + (jstring) env->GetObjectArrayElement(supportedAbisArray, i))); + } + + ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle); + if (zipFile == NULL) { + return INSTALL_FAILED_INVALID_APK; + } + + UniquePtr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile)); + if (it.get() == NULL) { + return INSTALL_FAILED_INVALID_APK; + } + + ZipEntryRO entry = NULL; + char fileName[PATH_MAX]; + int status = NO_NATIVE_LIBRARIES; + while ((entry = it->next()) != NULL) { + // We're currently in the lib/ directory of the APK, so it does have some native + // code. We should return INSTALL_FAILED_NO_MATCHING_ABIS if none of the + // libraries match. + if (status == NO_NATIVE_LIBRARIES) { + status = INSTALL_FAILED_NO_MATCHING_ABIS; + } + + const char* fileName = it->currentEntry(); + const char* lastSlash = it->lastSlash(); + + // Check to see if this CPU ABI matches what we are looking for. + const char* abiOffset = fileName + APK_LIB_LEN; + const size_t abiSize = lastSlash - abiOffset; + for (int i = 0; i < numAbis; i++) { + const ScopedUtfChars* abi = supportedAbis[i]; + if (abi->size() == abiSize && !strncmp(abiOffset, abi->c_str(), abiSize)) { + // The entry that comes in first (i.e. with a lower index) has the higher priority. + if (((i < status) && (status >= 0)) || (status < 0) ) { + status = i; + } + } + } + } + + for (int i = 0; i < numAbis; ++i) { + delete supportedAbis[i]; + } + + return status; +} + static jint com_android_internal_content_NativeLibraryHelper_copyNativeBinaries(JNIEnv *env, jclass clazz, - jstring javaFilePath, jstring javaNativeLibPath, jstring javaCpuAbi, jstring javaCpuAbi2) + jlong apkHandle, jstring javaNativeLibPath, jstring javaCpuAbi) { - return (jint) iterateOverNativeFiles(env, javaFilePath, javaCpuAbi, javaCpuAbi2, + return (jint) iterateOverNativeFiles(env, apkHandle, javaCpuAbi, copyFileIfChanged, &javaNativeLibPath); } static jlong com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env, jclass clazz, - jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2) + jlong apkHandle, jstring javaCpuAbi) { size_t totalSize = 0; - iterateOverNativeFiles(env, javaFilePath, javaCpuAbi, javaCpuAbi2, sumFiles, &totalSize); + iterateOverNativeFiles(env, apkHandle, javaCpuAbi, sumFiles, &totalSize); return totalSize; } +static jint +com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz, + jlong apkHandle, jobjectArray javaCpuAbisToSearch) +{ + return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch); +} + +static jlong +com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv *env, jclass, jstring apkPath) +{ + ScopedUtfChars filePath(env, apkPath); + ZipFileRO* zipFile = ZipFileRO::open(filePath.c_str()); + + return reinterpret_cast<jlong>(zipFile); +} + +static void +com_android_internal_content_NativeLibraryHelper_close(JNIEnv *env, jclass, jlong apkHandle) +{ + delete reinterpret_cast<ZipFileRO*>(apkHandle); +} + static JNINativeMethod gMethods[] = { + {"nativeOpenApk", + "(Ljava/lang/String;)J", + (void *)com_android_internal_content_NativeLibraryHelper_openApk}, + {"nativeClose", + "(J)V", + (void *)com_android_internal_content_NativeLibraryHelper_close}, {"nativeCopyNativeBinaries", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", + "(JLjava/lang/String;Ljava/lang/String;)I", (void *)com_android_internal_content_NativeLibraryHelper_copyNativeBinaries}, {"nativeSumNativeBinaries", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J", + "(JLjava/lang/String;)J", (void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries}, + {"nativeFindSupportedAbi", + "(J[Ljava/lang/String;)I", + (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi}, }; diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp new file mode 100644 index 0000000..a61fa87 --- /dev/null +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -0,0 +1,608 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "android_runtime/AndroidRuntime.h" + +// sys/mount.h has to come before linux/fs.h due to redefinition of MS_RDONLY, MS_BIND, etc +#include <sys/mount.h> +#include <linux/fs.h> + +#include <grp.h> +#include <paths.h> +#include <signal.h> +#include <stdlib.h> +#include <sys/resource.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <unistd.h> +#include <fcntl.h> + +#include "cutils/fs.h" +#include "cutils/multiuser.h" +#include "cutils/sched_policy.h" +#include "utils/String8.h" +#include "JNIHelp.h" +#include "ScopedLocalRef.h" +#include "ScopedPrimitiveArray.h" +#include "ScopedUtfChars.h" + +#if defined(HAVE_PRCTL) +#include <sys/prctl.h> +#endif + +#include <selinux/android.h> + +#if defined(__linux__) +#include <sys/personality.h> +#include <sys/utsname.h> +#if defined(HAVE_ANDROID_OS) +#include <sys/capability.h> +#endif +#endif + +namespace { + +using android::String8; + +static pid_t gSystemServerPid = 0; + +static const char kZygoteClassName[] = "com/android/internal/os/Zygote"; +static jclass gZygoteClass; +static jmethodID gCallPostForkChildHooks; + +// Must match values in com.android.internal.os.Zygote. +enum MountExternalKind { + MOUNT_EXTERNAL_NONE = 0, + MOUNT_EXTERNAL_SINGLEUSER = 1, + MOUNT_EXTERNAL_MULTIUSER = 2, + MOUNT_EXTERNAL_MULTIUSER_ALL = 3, +}; + +static void RuntimeAbort(JNIEnv* env) { + env->FatalError("RuntimeAbort"); +} + +// This signal handler is for zygote mode, since the zygote must reap its children +static void SigChldHandler(int /*signal_number*/) { + pid_t pid; + int status; + + while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { + // Log process-death status that we care about. In general it is + // not safe to call LOG(...) from a signal handler because of + // possible reentrancy. However, we know a priori that the + // current implementation of LOG() is safe to call from a SIGCHLD + // handler in the zygote process. If the LOG() implementation + // changes its locking strategy or its use of syscalls within the + // lazy-init critical section, its use here may become unsafe. + if (WIFEXITED(status)) { + if (WEXITSTATUS(status)) { + ALOGI("Process %d exited cleanly (%d)", pid, WEXITSTATUS(status)); + } else if (false) { + ALOGI("Process %d exited cleanly (%d)", pid, WEXITSTATUS(status)); + } + } else if (WIFSIGNALED(status)) { + if (WTERMSIG(status) != SIGKILL) { + ALOGI("Process %d exited cleanly (%d)", pid, WTERMSIG(status)); + } else if (false) { + ALOGI("Process %d exited cleanly (%d)", pid, WTERMSIG(status)); + } +#ifdef WCOREDUMP + if (WCOREDUMP(status)) { + ALOGI("Process %d dumped core.", pid); + } +#endif /* ifdef WCOREDUMP */ + } + + // If the just-crashed process is the system_server, bring down zygote + // so that it is restarted by init and system server will be restarted + // from there. + if (pid == gSystemServerPid) { + ALOGE("Exit zygote because system server (%d) has terminated"); + kill(getpid(), SIGKILL); + } + } + + if (pid < 0) { + ALOGW("Zygote SIGCHLD error in waitpid: %d", errno); + } +} + +// Configures the SIGCHLD handler for the zygote process. This is configured +// very late, because earlier in the runtime we may fork() and exec() +// other processes, and we want to waitpid() for those rather than +// have them be harvested immediately. +// +// This ends up being called repeatedly before each fork(), but there's +// no real harm in that. +static void SetSigChldHandler() { + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SigChldHandler; + + int err = sigaction(SIGCHLD, &sa, NULL); + if (err < 0) { + ALOGW("Error setting SIGCHLD handler: %d", errno); + } +} + +// Sets the SIGCHLD handler back to default behavior in zygote children. +static void UnsetSigChldHandler() { + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIG_DFL; + + int err = sigaction(SIGCHLD, &sa, NULL); + if (err < 0) { + ALOGW("Error unsetting SIGCHLD handler: %d", errno); + } +} + +// Calls POSIX setgroups() using the int[] object as an argument. +// A NULL argument is tolerated. +static void SetGids(JNIEnv* env, jintArray javaGids) { + if (javaGids == NULL) { + return; + } + + ScopedIntArrayRO gids(env, javaGids); + if (gids.get() == NULL) { + RuntimeAbort(env); + } + int rc = setgroups(gids.size(), reinterpret_cast<const gid_t*>(&gids[0])); + if (rc == -1) { + ALOGE("setgroups failed"); + RuntimeAbort(env); + } +} + +// Sets the resource limits via setrlimit(2) for the values in the +// two-dimensional array of integers that's passed in. The second dimension +// contains a tuple of length 3: (resource, rlim_cur, rlim_max). NULL is +// treated as an empty array. +static void SetRLimits(JNIEnv* env, jobjectArray javaRlimits) { + if (javaRlimits == NULL) { + return; + } + + rlimit rlim; + memset(&rlim, 0, sizeof(rlim)); + + for (int i = 0; i < env->GetArrayLength(javaRlimits); ++i) { + ScopedLocalRef<jobject> javaRlimitObject(env, env->GetObjectArrayElement(javaRlimits, i)); + ScopedIntArrayRO javaRlimit(env, reinterpret_cast<jintArray>(javaRlimitObject.get())); + if (javaRlimit.size() != 3) { + ALOGE("rlimits array must have a second dimension of size 3"); + RuntimeAbort(env); + } + + rlim.rlim_cur = javaRlimit[1]; + rlim.rlim_max = javaRlimit[2]; + + int rc = setrlimit(javaRlimit[0], &rlim); + if (rc == -1) { + ALOGE("setrlimit(%d, {%d, %d}) failed", javaRlimit[0], rlim.rlim_cur, rlim.rlim_max); + RuntimeAbort(env); + } + } +} + +#if defined(HAVE_ANDROID_OS) + +// The debug malloc library needs to know whether it's the zygote or a child. +extern "C" int gMallocLeakZygoteChild; + +static void EnableKeepCapabilities(JNIEnv* env) { + int rc = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0); + if (rc == -1) { + ALOGE("prctl(PR_SET_KEEPCAPS) failed"); + RuntimeAbort(env); + } +} + +static void DropCapabilitiesBoundingSet(JNIEnv* env) { + for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) { + int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0); + if (rc == -1) { + if (errno == EINVAL) { + ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify " + "your kernel is compiled with file capabilities support"); + } else { + ALOGE("prctl(PR_CAPBSET_DROP) failed"); + RuntimeAbort(env); + } + } + } +} + +static void SetCapabilities(JNIEnv* env, int64_t permitted, int64_t effective) { + __user_cap_header_struct capheader; + memset(&capheader, 0, sizeof(capheader)); + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capheader.pid = 0; + + __user_cap_data_struct capdata[2]; + memset(&capdata, 0, sizeof(capdata)); + capdata[0].effective = effective; + capdata[1].effective = effective >> 32; + capdata[0].permitted = permitted; + capdata[1].permitted = permitted >> 32; + + if (capset(&capheader, &capdata[0]) == -1) { + ALOGE("capset(%lld, %lld) failed", permitted, effective); + RuntimeAbort(env); + } +} + +static void SetSchedulerPolicy(JNIEnv* env) { + errno = -set_sched_policy(0, SP_DEFAULT); + if (errno != 0) { + ALOGE("set_sched_policy(0, SP_DEFAULT) failed"); + RuntimeAbort(env); + } +} + +#else + +static int gMallocLeakZygoteChild = 0; + +static void EnableKeepCapabilities(JNIEnv*) {} +static void DropCapabilitiesBoundingSet(JNIEnv*) {} +static void SetCapabilities(JNIEnv*, int64_t, int64_t) {} +static void SetSchedulerPolicy(JNIEnv*) {} + +#endif + +// Create a private mount namespace and bind mount appropriate emulated +// storage for the given user. +static bool MountEmulatedStorage(uid_t uid, jint mount_mode) { + if (mount_mode == MOUNT_EXTERNAL_NONE) { + return true; + } + + // See storage config details at http://source.android.com/tech/storage/ + userid_t user_id = multiuser_get_user_id(uid); + + // Create a second private mount namespace for our process + if (unshare(CLONE_NEWNS) == -1) { + ALOGW("Failed to unshare(): %d", errno); + return false; + } + + // Create bind mounts to expose external storage + if (mount_mode == MOUNT_EXTERNAL_MULTIUSER || mount_mode == MOUNT_EXTERNAL_MULTIUSER_ALL) { + // These paths must already be created by init.rc + const char* source = getenv("EMULATED_STORAGE_SOURCE"); + const char* target = getenv("EMULATED_STORAGE_TARGET"); + const char* legacy = getenv("EXTERNAL_STORAGE"); + if (source == NULL || target == NULL || legacy == NULL) { + ALOGW("Storage environment undefined; unable to provide external storage"); + return false; + } + + // Prepare source paths + + // /mnt/shell/emulated/0 + const String8 source_user(String8::format("%s/%d", source, user_id)); + // /storage/emulated/0 + const String8 target_user(String8::format("%s/%d", target, user_id)); + + if (fs_prepare_dir(source_user.string(), 0000, 0, 0) == -1 + || fs_prepare_dir(target_user.string(), 0000, 0, 0) == -1) { + return false; + } + + if (mount_mode == MOUNT_EXTERNAL_MULTIUSER_ALL) { + // Mount entire external storage tree for all users + if (TEMP_FAILURE_RETRY(mount(source, target, NULL, MS_BIND, NULL)) == -1) { + ALOGW("Failed to mount %s to %s :%d", source, target, errno); + return false; + } + } else { + // Only mount user-specific external storage + if (TEMP_FAILURE_RETRY( + mount(source_user.string(), target_user.string(), NULL, MS_BIND, NULL)) == -1) { + ALOGW("Failed to mount %s to %s: %d", source_user.string(), target_user.string(), errno); + return false; + } + } + + if (fs_prepare_dir(legacy, 0000, 0, 0) == -1) { + return false; + } + + // Finally, mount user-specific path into place for legacy users + if (TEMP_FAILURE_RETRY( + mount(target_user.string(), legacy, NULL, MS_BIND | MS_REC, NULL)) == -1) { + ALOGW("Failed to mount %s to %s: %d", target_user.string(), legacy, errno); + return false; + } + } else { + ALOGW("Mount mode %d unsupported", mount_mode); + return false; + } + + return true; +} + +#if defined(__linux__) +static bool NeedsNoRandomizeWorkaround() { +#if !defined(__arm__) + return false; +#else + int major; + int minor; + struct utsname uts; + if (uname(&uts) == -1) { + return false; + } + + if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) { + return false; + } + + // Kernels before 3.4.* need the workaround. + return (major < 3) || ((major == 3) && (minor < 4)); +#endif +} +#endif + +// Utility to close down the Zygote socket file descriptors while +// the child is still running as root with Zygote's privileges. Each +// descriptor (if any) is closed via dup2(), replacing it with a valid +// (open) descriptor to /dev/null. + +static void DetachDescriptors(JNIEnv* env, jintArray fdsToClose) { + if (!fdsToClose) { + return; + } + jsize count = env->GetArrayLength(fdsToClose); + jint *ar = env->GetIntArrayElements(fdsToClose, 0); + if (!ar) { + ALOGE("Bad fd array"); + RuntimeAbort(env); + } + jsize i; + int devnull; + for (i = 0; i < count; i++) { + devnull = open("/dev/null", O_RDWR); + if (devnull < 0) { + ALOGE("Failed to open /dev/null"); + RuntimeAbort(env); + continue; + } + ALOGV("Switching descriptor %d to /dev/null: %d", ar[i], errno); + if (dup2(devnull, ar[i]) < 0) { + ALOGE("Failed dup2() on descriptor %d", ar[i]); + RuntimeAbort(env); + } + close(devnull); + } +} + +void SetThreadName(const char* thread_name) { + bool hasAt = false; + bool hasDot = false; + const char* s = thread_name; + while (*s) { + if (*s == '.') { + hasDot = true; + } else if (*s == '@') { + hasAt = true; + } + s++; + } + const int len = s - thread_name; + if (len < 15 || hasAt || !hasDot) { + s = thread_name; + } else { + s = thread_name + len - 15; + } + // pthread_setname_np fails rather than truncating long strings. + char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded into bionic + strlcpy(buf, s, sizeof(buf)-1); + errno = pthread_setname_np(pthread_self(), buf); + if (errno != 0) { + ALOGW("Unable to set the name of current thread to '%s'", buf); + } +} + +// Utility routine to fork zygote and specialize the child process. +static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGids, + jint debug_flags, jobjectArray javaRlimits, + jlong permittedCapabilities, jlong effectiveCapabilities, + jint mount_external, + jstring java_se_info, jstring java_se_name, + bool is_system_server, jintArray fdsToClose) { + SetSigChldHandler(); + + pid_t pid = fork(); + + if (pid == 0) { + // The child process. + gMallocLeakZygoteChild = 1; + + // Clean up any descriptors which must be closed immediately + DetachDescriptors(env, fdsToClose); + + // Keep capabilities across UID change, unless we're staying root. + if (uid != 0) { + EnableKeepCapabilities(env); + } + + DropCapabilitiesBoundingSet(env); + + if (!MountEmulatedStorage(uid, mount_external)) { + ALOGW("Failed to mount emulated storage: %d", errno); + if (errno == ENOTCONN || errno == EROFS) { + // When device is actively encrypting, we get ENOTCONN here + // since FUSE was mounted before the framework restarted. + // When encrypted device is booting, we get EROFS since + // FUSE hasn't been created yet by init. + // In either case, continue without external storage. + } else { + ALOGE("Cannot continue without emulated storage"); + RuntimeAbort(env); + } + } + + SetGids(env, javaGids); + + SetRLimits(env, javaRlimits); + + int rc = setresgid(gid, gid, gid); + if (rc == -1) { + ALOGE("setresgid(%d) failed", gid); + RuntimeAbort(env); + } + + rc = setresuid(uid, uid, uid); + if (rc == -1) { + ALOGE("setresuid(%d) failed", uid); + RuntimeAbort(env); + } + +#if defined(__linux__) + if (NeedsNoRandomizeWorkaround()) { + // Work around ARM kernel ASLR lossage (http://b/5817320). + int old_personality = personality(0xffffffff); + int new_personality = personality(old_personality | ADDR_NO_RANDOMIZE); + if (new_personality == -1) { + ALOGW("personality(%d) failed", new_personality); + } + } +#endif + + SetCapabilities(env, permittedCapabilities, effectiveCapabilities); + + SetSchedulerPolicy(env); + +#if defined(HAVE_ANDROID_OS) + { // NOLINT(whitespace/braces) + const char* se_info_c_str = NULL; + ScopedUtfChars* se_info = NULL; + if (java_se_info != NULL) { + se_info = new ScopedUtfChars(env, java_se_info); + se_info_c_str = se_info->c_str(); + if (se_info_c_str == NULL) { + ALOGE("se_info_c_str == NULL"); + RuntimeAbort(env); + } + } + const char* se_name_c_str = NULL; + ScopedUtfChars* se_name = NULL; + if (java_se_name != NULL) { + se_name = new ScopedUtfChars(env, java_se_name); + se_name_c_str = se_name->c_str(); + if (se_name_c_str == NULL) { + ALOGE("se_name_c_str == NULL"); + RuntimeAbort(env); + } + } + rc = selinux_android_setcontext(uid, is_system_server, se_info_c_str, se_name_c_str); + if (rc == -1) { + ALOGE("selinux_android_setcontext(%d, %d, \"%s\", \"%s\") failed", uid, + is_system_server, se_info_c_str, se_name_c_str); + RuntimeAbort(env); + } + + // Make it easier to debug audit logs by setting the main thread's name to the + // nice name rather than "app_process". + if (se_info_c_str == NULL && is_system_server) { + se_name_c_str = "system_server"; + } + if (se_info_c_str != NULL) { + SetThreadName(se_name_c_str); + } + + delete se_info; + delete se_name; + } +#else + UNUSED(is_system_server); + UNUSED(java_se_info); + UNUSED(java_se_name); +#endif + + UnsetSigChldHandler(); + + env->CallStaticVoidMethod(gZygoteClass, gCallPostForkChildHooks, debug_flags); + if (env->ExceptionCheck()) { + ALOGE("Error calling post fork hooks."); + RuntimeAbort(env); + } + } else if (pid > 0) { + // the parent process + } + return pid; +} +} // anonymous namespace + +namespace android { + +static jint com_android_internal_os_Zygote_nativeForkAndSpecialize( + JNIEnv* env, jclass, jint uid, jint gid, jintArray gids, + jint debug_flags, jobjectArray rlimits, + jint mount_external, jstring se_info, jstring se_name, + jintArray fdsToClose) { + return ForkAndSpecializeCommon(env, uid, gid, gids, debug_flags, + rlimits, 0, 0, mount_external, se_info, se_name, false, fdsToClose); +} + +static jint com_android_internal_os_Zygote_nativeForkSystemServer( + JNIEnv* env, jclass, uid_t uid, gid_t gid, jintArray gids, + jint debug_flags, jobjectArray rlimits, jlong permittedCapabilities, + jlong effectiveCapabilities) { + pid_t pid = ForkAndSpecializeCommon(env, uid, gid, gids, + debug_flags, rlimits, + permittedCapabilities, effectiveCapabilities, + MOUNT_EXTERNAL_NONE, NULL, NULL, true, NULL); + if (pid > 0) { + // The zygote process checks whether the child process has died or not. + ALOGI("System server process %d has been created", pid); + gSystemServerPid = pid; + // There is a slight window that the system server process has crashed + // but it went unnoticed because we haven't published its pid yet. So + // we recheck here just to make sure that all is well. + int status; + if (waitpid(pid, &status, WNOHANG) == pid) { + ALOGE("System server process %d has died. Restarting Zygote!", pid); + RuntimeAbort(env); + } + } + return pid; +} + +static JNINativeMethod gMethods[] = { + { "nativeForkAndSpecialize", "(II[II[[IILjava/lang/String;Ljava/lang/String;[I)I", + (void *) com_android_internal_os_Zygote_nativeForkAndSpecialize }, + { "nativeForkSystemServer", "(II[II[[IJJ)I", + (void *) com_android_internal_os_Zygote_nativeForkSystemServer } +}; + +int register_com_android_internal_os_Zygote(JNIEnv* env) { + gZygoteClass = (jclass) env->NewGlobalRef(env->FindClass(kZygoteClassName)); + if (gZygoteClass == NULL) { + RuntimeAbort(env); + } + gCallPostForkChildHooks = env->GetStaticMethodID(gZygoteClass, "callPostForkChildHooks", "(I)V"); + + return AndroidRuntime::registerNativeMethods(env, "com/android/internal/os/Zygote", + gMethods, NELEM(gMethods)); +} +} // namespace android + diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp index a0982bd..3035d15 100644 --- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp @@ -50,36 +50,41 @@ static jfieldID gBitmap_NativeBitmapFieldID; static inline EGLDisplay getDisplay(JNIEnv* env, jobject o) { if (!o) return EGL_NO_DISPLAY; - return (EGLDisplay)env->GetIntField(o, gDisplay_EGLDisplayFieldID); + return (EGLDisplay)env->GetLongField(o, gDisplay_EGLDisplayFieldID); } static inline EGLSurface getSurface(JNIEnv* env, jobject o) { if (!o) return EGL_NO_SURFACE; - return (EGLSurface)env->GetIntField(o, gSurface_EGLSurfaceFieldID); + return (EGLSurface)env->GetLongField(o, gSurface_EGLSurfaceFieldID); } static inline EGLContext getContext(JNIEnv* env, jobject o) { if (!o) return EGL_NO_CONTEXT; - return (EGLContext)env->GetIntField(o, gContext_EGLContextFieldID); + return (EGLContext)env->GetLongField(o, gContext_EGLContextFieldID); } static inline EGLConfig getConfig(JNIEnv* env, jobject o) { if (!o) return 0; - return (EGLConfig)env->GetIntField(o, gConfig_EGLConfigFieldID); + return (EGLConfig)env->GetLongField(o, gConfig_EGLConfigFieldID); } + +static inline jboolean EglBoolToJBool(EGLBoolean eglBool) { + return eglBool == EGL_TRUE ? JNI_TRUE : JNI_FALSE; +} + static void nativeClassInit(JNIEnv *_env, jclass eglImplClass) { jclass config_class = _env->FindClass("com/google/android/gles_jni/EGLConfigImpl"); gConfig_class = (jclass) _env->NewGlobalRef(config_class); - gConfig_ctorID = _env->GetMethodID(gConfig_class, "<init>", "(I)V"); - gConfig_EGLConfigFieldID = _env->GetFieldID(gConfig_class, "mEGLConfig", "I"); + gConfig_ctorID = _env->GetMethodID(gConfig_class, "<init>", "(J)V"); + gConfig_EGLConfigFieldID = _env->GetFieldID(gConfig_class, "mEGLConfig", "J"); jclass display_class = _env->FindClass("com/google/android/gles_jni/EGLDisplayImpl"); - gDisplay_EGLDisplayFieldID = _env->GetFieldID(display_class, "mEGLDisplay", "I"); + gDisplay_EGLDisplayFieldID = _env->GetFieldID(display_class, "mEGLDisplay", "J"); jclass context_class = _env->FindClass("com/google/android/gles_jni/EGLContextImpl"); - gContext_EGLContextFieldID = _env->GetFieldID(context_class, "mEGLContext", "I"); + gContext_EGLContextFieldID = _env->GetFieldID(context_class, "mEGLContext", "J"); jclass surface_class = _env->FindClass("com/google/android/gles_jni/EGLSurfaceImpl"); - gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "I"); - gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "I"); + gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "J"); + gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "J"); jclass bitmap_class = _env->FindClass("android/graphics/Bitmap"); gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "J"); @@ -123,7 +128,7 @@ static jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, } EGLDisplay dpy = getDisplay(_env, display); - jboolean success = eglInitialize(dpy, NULL, NULL); + EGLBoolean success = eglInitialize(dpy, NULL, NULL); if (success && major_minor) { int len = _env->GetArrayLength(major_minor); if (len) { @@ -134,7 +139,7 @@ static jboolean jni_eglInitialize(JNIEnv *_env, jobject _this, jobject display, _env->ReleasePrimitiveArrayCritical(major_minor, base, JNI_ABORT); } } - return success; + return EglBoolToJBool(success); } static jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display, @@ -146,14 +151,14 @@ static jboolean jni_eglQueryContext(JNIEnv *_env, jobject _this, jobject display } EGLDisplay dpy = getDisplay(_env, display); EGLContext ctx = getContext(_env, context); - jboolean success = JNI_FALSE; + EGLBoolean success = EGL_FALSE; int len = _env->GetArrayLength(value); if (len) { jint* base = (jint *)_env->GetPrimitiveArrayCritical(value, (jboolean *)0); success = eglQueryContext(dpy, ctx, attribute, base); _env->ReleasePrimitiveArrayCritical(value, base, JNI_ABORT); } - return success; + return EglBoolToJBool(success); } static jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display, @@ -166,14 +171,14 @@ static jboolean jni_eglQuerySurface(JNIEnv *_env, jobject _this, jobject display EGLDisplay dpy = getDisplay(_env, display); EGLContext sur = getSurface(_env, surface); - jboolean success = JNI_FALSE; + EGLBoolean success = EGL_FALSE; int len = _env->GetArrayLength(value); if (len) { jint* base = (jint *)_env->GetPrimitiveArrayCritical(value, (jboolean *)0); success = eglQuerySurface(dpy, sur, attribute, base); _env->ReleasePrimitiveArrayCritical(value, base, JNI_ABORT); } - return success; + return EglBoolToJBool(success); } static jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) { @@ -183,7 +188,7 @@ static jint jni_getInitCount(JNIEnv *_env, jobject _clazz, jobject display) { } static jboolean jni_eglReleaseThread(JNIEnv *_env, jobject _this) { - return eglReleaseThread(); + return EglBoolToJBool(eglReleaseThread()); } static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display, @@ -196,7 +201,7 @@ static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display return JNI_FALSE; } EGLDisplay dpy = getDisplay(_env, display); - jboolean success = JNI_FALSE; + EGLBoolean success = EGL_FALSE; if (configs == NULL) { config_size = 0; @@ -214,14 +219,14 @@ static jboolean jni_eglChooseConfig(JNIEnv *_env, jobject _this, jobject display if (success && configs!=NULL) { for (int i=0 ; i<num ; i++) { - jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]); + jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i])); _env->SetObjectArrayElement(configs, i, obj); } } - return success; + return EglBoolToJBool(success); } -static jint jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, +static jlong jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, jobject config, jobject share_context, jintArray attrib_list) { if (display == NULL || config == NULL || share_context == NULL || !validAttribList(_env, attrib_list)) { @@ -234,10 +239,10 @@ static jint jni_eglCreateContext(JNIEnv *_env, jobject _this, jobject display, jint* base = beginNativeAttribList(_env, attrib_list); EGLContext ctx = eglCreateContext(dpy, cnf, shr, base); endNativeAttributeList(_env, attrib_list, base); - return (jint)ctx; + return reinterpret_cast<jlong>(ctx); } -static jint jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display, +static jlong jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject display, jobject config, jintArray attrib_list) { if (display == NULL || config == NULL || !validAttribList(_env, attrib_list)) { @@ -249,7 +254,7 @@ static jint jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject dis jint* base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreatePbufferSurface(dpy, cnf, base); endNativeAttributeList(_env, attrib_list, base); - return (jint)sur; + return reinterpret_cast<jlong>(sur); } static PixelFormat convertPixelFormat(SkBitmap::Config format) @@ -300,15 +305,15 @@ static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_ endNativeAttributeList(_env, attrib_list, base); if (sur != EGL_NO_SURFACE) { - _env->SetIntField(out_sur, gSurface_EGLSurfaceFieldID, (int)sur); - _env->SetIntField(out_sur, gSurface_NativePixelRefFieldID, (int)ref); + _env->SetLongField(out_sur, gSurface_EGLSurfaceFieldID, reinterpret_cast<jlong>(sur)); + _env->SetLongField(out_sur, gSurface_NativePixelRefFieldID, reinterpret_cast<jlong>(ref)); } else { ref->unlockPixels(); SkSafeUnref(ref); } } -static jint jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display, +static jlong jni_eglCreateWindowSurface(JNIEnv *_env, jobject _this, jobject display, jobject config, jobject native_window, jintArray attrib_list) { if (display == NULL || config == NULL || !validAttribList(_env, attrib_list)) { @@ -332,15 +337,15 @@ not_valid_surface: jint* base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base); endNativeAttributeList(_env, attrib_list, base); - return (jint)sur; + return reinterpret_cast<jlong>(sur); } -static jint jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display, +static jlong jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display, jobject config, jobject native_window, jintArray attrib_list) { if (display == NULL || config == NULL || !validAttribList(_env, attrib_list)) { jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); - return JNI_FALSE; + return 0; } EGLDisplay dpy = getDisplay(_env, display); EGLContext cnf = getConfig(_env, config); @@ -360,7 +365,7 @@ not_valid_surface: jint* base = beginNativeAttribList(_env, attrib_list); EGLSurface sur = eglCreateWindowSurface(dpy, cnf, window.get(), base); endNativeAttributeList(_env, attrib_list, base); - return (jint)sur; + return reinterpret_cast<jlong>(sur); } static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject display, @@ -372,13 +377,13 @@ static jboolean jni_eglGetConfigAttrib(JNIEnv *_env, jobject _this, jobject disp } EGLDisplay dpy = getDisplay(_env, display); EGLContext cnf = getConfig(_env, config); - jboolean success = JNI_FALSE; + EGLBoolean success = EGL_FALSE; jint localValue; success = eglGetConfigAttrib(dpy, cnf, attribute, &localValue); if (success) { _env->SetIntArrayRegion(value, 0, 1, &localValue); } - return success; + return EglBoolToJBool(success); } static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, @@ -389,7 +394,7 @@ static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, return JNI_FALSE; } EGLDisplay dpy = getDisplay(_env, display); - jboolean success = JNI_FALSE; + EGLBoolean success = EGL_FALSE; if (configs == NULL) { config_size = 0; } @@ -401,11 +406,11 @@ static jboolean jni_eglGetConfigs(JNIEnv *_env, jobject _this, jobject display, } if (success && configs) { for (int i=0 ; i<num ; i++) { - jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, (jint)nativeConfigs[i]); + jobject obj = _env->NewObject(gConfig_class, gConfig_ctorID, reinterpret_cast<jlong>(nativeConfigs[i])); _env->SetObjectArrayElement(configs, i, obj); } } - return success; + return EglBoolToJBool(success); } static jint jni_eglGetError(JNIEnv *_env, jobject _this) { @@ -413,20 +418,20 @@ static jint jni_eglGetError(JNIEnv *_env, jobject _this) { return error; } -static jint jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) { - return (jint)eglGetCurrentContext(); +static jlong jni_eglGetCurrentContext(JNIEnv *_env, jobject _this) { + return reinterpret_cast<jlong>(eglGetCurrentContext()); } -static jint jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) { - return (jint)eglGetCurrentDisplay(); +static jlong jni_eglGetCurrentDisplay(JNIEnv *_env, jobject _this) { + return reinterpret_cast<jlong>(eglGetCurrentDisplay()); } -static jint jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { +static jlong jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) { jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); return 0; } - return (jint)eglGetCurrentSurface(readdraw); + return reinterpret_cast<jlong>(eglGetCurrentSurface(readdraw)); } static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject display, jobject context) { @@ -436,7 +441,7 @@ static jboolean jni_eglDestroyContext(JNIEnv *_env, jobject _this, jobject displ } EGLDisplay dpy = getDisplay(_env, display); EGLContext ctx = getContext(_env, context); - return eglDestroyContext(dpy, ctx); + return EglBoolToJBool(eglDestroyContext(dpy, ctx)); } static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject display, jobject surface) { @@ -448,18 +453,18 @@ static jboolean jni_eglDestroySurface(JNIEnv *_env, jobject _this, jobject displ EGLSurface sur = getSurface(_env, surface); if (sur) { - SkPixelRef* ref = (SkPixelRef*)(_env->GetIntField(surface, + SkPixelRef* ref = (SkPixelRef*)(_env->GetLongField(surface, gSurface_NativePixelRefFieldID)); if (ref) { ref->unlockPixels(); SkSafeUnref(ref); } } - return eglDestroySurface(dpy, sur); + return EglBoolToJBool(eglDestroySurface(dpy, sur)); } -static jint jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) { - return (jint)eglGetDisplay(EGL_DEFAULT_DISPLAY); +static jlong jni_eglGetDisplay(JNIEnv *_env, jobject _this, jobject native_display) { + return reinterpret_cast<jlong>(eglGetDisplay(EGL_DEFAULT_DISPLAY)); } static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, jobject draw, jobject read, jobject context) { @@ -471,7 +476,7 @@ static jboolean jni_eglMakeCurrent(JNIEnv *_env, jobject _this, jobject display, EGLSurface sdr = getSurface(_env, draw); EGLSurface srd = getSurface(_env, read); EGLContext ctx = getContext(_env, context); - return eglMakeCurrent(dpy, sdr, srd, ctx); + return EglBoolToJBool(eglMakeCurrent(dpy, sdr, srd, ctx)); } static jstring jni_eglQueryString(JNIEnv *_env, jobject _this, jobject display, jint name) { @@ -491,7 +496,7 @@ static jboolean jni_eglSwapBuffers(JNIEnv *_env, jobject _this, jobject display, } EGLDisplay dpy = getDisplay(_env, display); EGLSurface sur = getSurface(_env, surface); - return eglSwapBuffers(dpy, sur); + return EglBoolToJBool(eglSwapBuffers(dpy, sur)); } static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) { @@ -500,7 +505,7 @@ static jboolean jni_eglTerminate(JNIEnv *_env, jobject _this, jobject display) { return JNI_FALSE; } EGLDisplay dpy = getDisplay(_env, display); - return eglTerminate(dpy); + return EglBoolToJBool(eglTerminate(dpy)); } static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display, @@ -514,11 +519,11 @@ static jboolean jni_eglCopyBuffers(JNIEnv *_env, jobject _this, jobject display, } static jboolean jni_eglWaitGL(JNIEnv *_env, jobject _this) { - return eglWaitGL(); + return EglBoolToJBool(eglWaitGL()); } static jboolean jni_eglWaitNative(JNIEnv *_env, jobject _this, jint engine, jobject bindTarget) { - return eglWaitNative(engine); + return EglBoolToJBool(eglWaitNative(engine)); } @@ -540,21 +545,21 @@ static JNINativeMethod methods[] = { {"eglReleaseThread","()Z", (void*)jni_eglReleaseThread }, {"getInitCount", "(" DISPLAY ")I", (void*)jni_getInitCount }, {"eglChooseConfig", "(" DISPLAY "[I[" CONFIG "I[I)Z", (void*)jni_eglChooseConfig }, -{"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)I", (void*)jni_eglCreateContext }, +{"_eglCreateContext","(" DISPLAY CONFIG CONTEXT "[I)J", (void*)jni_eglCreateContext }, {"eglGetConfigs", "(" DISPLAY "[" CONFIG "I[I)Z", (void*)jni_eglGetConfigs }, {"eglTerminate", "(" DISPLAY ")Z", (void*)jni_eglTerminate }, {"eglCopyBuffers", "(" DISPLAY SURFACE OBJECT ")Z", (void*)jni_eglCopyBuffers }, {"eglWaitNative", "(I" OBJECT ")Z", (void*)jni_eglWaitNative }, {"eglGetError", "()I", (void*)jni_eglGetError }, {"eglGetConfigAttrib", "(" DISPLAY CONFIG "I[I)Z", (void*)jni_eglGetConfigAttrib }, -{"_eglGetDisplay", "(" OBJECT ")I", (void*)jni_eglGetDisplay }, -{"_eglGetCurrentContext", "()I", (void*)jni_eglGetCurrentContext }, -{"_eglGetCurrentDisplay", "()I", (void*)jni_eglGetCurrentDisplay }, -{"_eglGetCurrentSurface", "(I)I", (void*)jni_eglGetCurrentSurface }, -{"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)I", (void*)jni_eglCreatePbufferSurface }, +{"_eglGetDisplay", "(" OBJECT ")J", (void*)jni_eglGetDisplay }, +{"_eglGetCurrentContext", "()J", (void*)jni_eglGetCurrentContext }, +{"_eglGetCurrentDisplay", "()J", (void*)jni_eglGetCurrentDisplay }, +{"_eglGetCurrentSurface", "(I)J", (void*)jni_eglGetCurrentSurface }, +{"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)J", (void*)jni_eglCreatePbufferSurface }, {"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface }, -{"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurface }, -{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurfaceTexture }, +{"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurface }, +{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)J", (void*)jni_eglCreateWindowSurfaceTexture }, {"eglDestroyContext", "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext }, {"eglDestroySurface", "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface }, {"eglMakeCurrent", "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent }, diff --git a/core/jni/com_google_android_gles_jni_GLImpl.cpp b/core/jni/com_google_android_gles_jni_GLImpl.cpp index b3b0049..7975987 100644 --- a/core/jni/com_google_android_gles_jni_GLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_GLImpl.cpp @@ -129,7 +129,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o getBasePointerID, buffer); if (pointer != 0L) { *array = NULL; - return (void *) (jint) pointer; + return reinterpret_cast<void *>(pointer); } *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, @@ -4359,7 +4359,7 @@ android_glColorPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -4460,7 +4460,7 @@ android_glDrawElements__IIII (GLenum)mode, (GLsizei)count, (GLenum)type, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); @@ -6099,7 +6099,7 @@ android_glNormalPointer__III glNormalPointer( (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -6326,7 +6326,7 @@ android_glTexCoordPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -6756,7 +6756,7 @@ android_glVertexPointer__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -7196,7 +7196,7 @@ android_glMatrixIndexPointerOES__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } @@ -7232,7 +7232,7 @@ android_glWeightPointerOES__IIII (GLint)size, (GLenum)type, (GLsizei)stride, - (GLvoid *)offset + reinterpret_cast<GLvoid *>(offset) ); } |