diff options
author | Ben Cheng <bccheng@google.com> | 2013-09-16 12:12:51 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2013-09-16 12:12:51 -0700 |
commit | f9e0f5b7cf88b3853bc9638e7eaa44ced72601bb (patch) | |
tree | cfcfda5010e6f3c56aa54debb3f01714e89bfe15 /tutorials | |
parent | 6fa1156b3b98e72952e1281b66af9867205e1954 (diff) | |
download | android_development-f9e0f5b7cf88b3853bc9638e7eaa44ced72601bb.tar.gz android_development-f9e0f5b7cf88b3853bc9638e7eaa44ced72601bb.tar.bz2 android_development-f9e0f5b7cf88b3853bc9638e7eaa44ced72601bb.zip |
Add "Force a Double Free" button to stress test the tools.
Change-Id: I52bf2f42c9a6040ac345248473d7184b7266f511
Diffstat (limited to 'tutorials')
-rw-r--r-- | tutorials/MoarRam/README.txt | 3 | ||||
-rw-r--r-- | tutorials/MoarRam/jni/Android.mk | 9 | ||||
-rw-r--r-- | tutorials/MoarRam/jni/df.c | 36 | ||||
-rw-r--r-- | tutorials/MoarRam/res/layout/activity_main.xml | 15 | ||||
-rw-r--r-- | tutorials/MoarRam/res/values/strings.xml | 1 | ||||
-rw-r--r-- | tutorials/MoarRam/src/com/android/benchmark/moarram/MainActivity.java | 6 |
6 files changed, 70 insertions, 0 deletions
diff --git a/tutorials/MoarRam/README.txt b/tutorials/MoarRam/README.txt index 028389b2b..8f1a48784 100644 --- a/tutorials/MoarRam/README.txt +++ b/tutorials/MoarRam/README.txt @@ -12,3 +12,6 @@ unique paths to allocate heap chunks: Each allocation can be freed by clicking the corresponding free button in the UI. + +NOTE 09/16/2013 +A new feature is added to force a double free. Both debug libc and Valgrind can capture it. diff --git a/tutorials/MoarRam/jni/Android.mk b/tutorials/MoarRam/jni/Android.mk index 933cbdf3c..b1eec37a1 100644 --- a/tutorials/MoarRam/jni/Android.mk +++ b/tutorials/MoarRam/jni/Android.mk @@ -41,3 +41,12 @@ LOCAL_SRC_FILES := baz.c LOCAL_SHARED_LIBRARIES += liblog include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmoarram-doublefree +LOCAL_SRC_FILES := df.c +LOCAL_SHARED_LIBRARIES += liblog + +include $(BUILD_SHARED_LIBRARY) diff --git a/tutorials/MoarRam/jni/df.c b/tutorials/MoarRam/jni/df.c new file mode 100644 index 000000000..bfea6b8e4 --- /dev/null +++ b/tutorials/MoarRam/jni/df.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2013 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 <jni.h> +#include <cutils/log.h> + +#if defined(LOG_TAG) +#undef LOG_TAG +#define LOG_TAG "MOARRAM" +#endif + +void +Java_com_android_benchmark_moarram_MainActivity_forceDoubleFreeNative( + JNIEnv* env, + jobject this) +{ + char *ptr = (char *) malloc(4); + *ptr = 0; + ALOGW("About to double free %p", ptr); + free(ptr); + free(ptr); +} diff --git a/tutorials/MoarRam/res/layout/activity_main.xml b/tutorials/MoarRam/res/layout/activity_main.xml index 8319bd76e..50b674593 100644 --- a/tutorials/MoarRam/res/layout/activity_main.xml +++ b/tutorials/MoarRam/res/layout/activity_main.xml @@ -101,4 +101,19 @@ android:layout_weight="1" android:onClick="freeVariableSizedBlocks" /> </LinearLayout> + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="horizontal"> + + <Button + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:text="@string/force_double_free" + android:layout_weight="1" + android:onClick="forceDoubleFree" /> + </LinearLayout> + </LinearLayout> diff --git a/tutorials/MoarRam/res/values/strings.xml b/tutorials/MoarRam/res/values/strings.xml index 0c0031dea..e289fd847 100644 --- a/tutorials/MoarRam/res/values/strings.xml +++ b/tutorials/MoarRam/res/values/strings.xml @@ -13,4 +13,5 @@ <string name="free_variable">Free 17 or 71 bytes</string> <string name="_17byte">17 bytes</string> <string name="_71byte">71 bytes</string> + <string name="force_double_free">Force a Double Free</string> </resources> diff --git a/tutorials/MoarRam/src/com/android/benchmark/moarram/MainActivity.java b/tutorials/MoarRam/src/com/android/benchmark/moarram/MainActivity.java index aa83b8cbd..0b7dcbc19 100644 --- a/tutorials/MoarRam/src/com/android/benchmark/moarram/MainActivity.java +++ b/tutorials/MoarRam/src/com/android/benchmark/moarram/MainActivity.java @@ -14,6 +14,7 @@ public class MainActivity extends Activity { System.loadLibrary("moarram-32"); System.loadLibrary("moarram-2M"); System.loadLibrary("moarram-17_71"); + System.loadLibrary("moarram-doublefree"); setContentView(R.layout.activity_main); } @@ -55,10 +56,15 @@ public class MainActivity extends Activity { freeVariableSizedBlocksNative(sizeId == R.id.radio17 ? 0 : 1); } + public void forceDoubleFree(View view) { + forceDoubleFreeNative(); + } + public native void add32ByteBlocksNative(); public native void free32ByteBlocksNative(); public native void add2MByteBlocksNative(); public native void free2MByteBlocksNative(); public native void addVariableSizedBlocksNative(int sizeId); public native void freeVariableSizedBlocksNative(int sizeId); + public native void forceDoubleFreeNative(); } |