Index: tools/android/asan/asan_device_setup.sh |
diff --git a/tools/android/asan/asan_device_setup.sh b/tools/android/asan/asan_device_setup.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..98adc190ee0af96e0cf21839b8a71c59622fdf42 |
--- /dev/null |
+++ b/tools/android/asan/asan_device_setup.sh |
@@ -0,0 +1,82 @@ |
+#!/bin/bash |
+# Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+# Prepare Android device to run ASan application. |
+# |
+# To revert this setup, |
+# adb remount |
+# adb shell mv /system/bin/app_process.real /system/bin/app_process |
+# adb shell rm /system/bin/asanwrapper |
+# adb shell rm /system/lib/libclang_rt.asan-arm-android.so |
+ |
+HERE="$(cd "$(dirname "$0")" && pwd)" |
+ |
+ADB=adb |
+if [[ x$1 != x ]]; then |
Alexander Potapenko
2014/01/17 12:43:50
Better quote both operands.
|
+ ADB="adb -s $1" |
+fi |
+ |
+TMPDIR=$(mktemp -d) |
+echo $TMPDIR |
+ |
+ASAN_RT_PATH="$HERE" |
+ASAN_RT="$ASAN_RT_PATH/libclang_rt.asan-arm-android.so" |
+ |
+if ! [[ -f "$ASAN_RT" ]]; then |
+ echo "ASan runtime library not found at $ASAN_RT" |
+ exit 1 |
+fi |
+ |
+echo '>> Remounting /system rw' |
+$ADB remount |
+ |
+echo '>> Copying files from the device' |
+$ADB pull /system/bin/app_process "$TMPDIR/app_process" |
+$ADB pull /system/bin/app_process.real "$TMPDIR/app_process.real" |
+ |
+if ! [[ -f "$TMPDIR/app_process" ]]; then |
+ echo "app_process missing???" |
+ exit 1 |
+fi |
+ |
+if [[ -f "$TMPDIR/app_process.real" ]]; then |
+ echo "app_process.real exists, updating the wrapper" |
+else |
+ echo "app_process.real missing, new installation" |
+ mv "$TMPDIR/app_process" "$TMPDIR/app_process.real" |
+fi |
+ |
+echo '>> Generating wrappers' |
+cat <<EOF >"$TMPDIR/app_process" |
+#!/system/bin/sh |
+ASAN_OPTIONS=strict_memcmp=0,malloc_context_size=3,start_deactivated=1 \\ |
+LD_PRELOAD=libclang_rt.asan-arm-android.so \\ |
+exec /system/bin/app_process.real \$@ |
+ |
+EOF |
+ |
+cat <<EOF >"$TMPDIR/asanwrapper" |
+#!/system/bin/sh |
+ASAN_OPTIONS=strict_memcmp=0 \ |
+LD_PRELOAD=libclang_rt.asan-arm-android.so \ |
+exec \$@ |
+ |
+EOF |
+ |
+echo '>> Pushing files to the device' |
+$ADB push "$ASAN_RT" /system/lib/ |
+$ADB push "$TMPDIR/app_process" /system/bin/app_process |
+$ADB push "$TMPDIR/app_process.real" /system/bin/app_process.real |
+$ADB push "$TMPDIR/asanwrapper" /system/bin/asanwrapper |
+$ADB shell chown root.shell \ |
+ /system/bin/app_process \ |
+ /system/bin/app_process.real \ |
+ /system/bin/asanwrapper |
+$ADB shell chmod 755 \ |
+ /system/bin/app_process \ |
+ /system/bin/app_process.real \ |
+ /system/bin/asanwrapper |
+ |
+rm -r "$TMPDIR" |