Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash -e | |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 # Prepare Android device to run ASan application. | |
|
bulach
2014/01/24 05:51:22
nit: since this is going to be a standalone tool,
eugenis
2014/01/24 07:52:01
Done.
| |
| 7 | |
| 8 | |
| 9 HERE="$(cd "$(dirname "$0")" && pwd)" | |
| 10 | |
| 11 revert=no | |
| 12 extra_options= | |
| 13 device= | |
| 14 | |
| 15 function usage { | |
| 16 echo "usage: $0 [--revert] [--device device-id]" | |
| 17 echo " --revert: Uninstall ASan from the device." | |
| 18 echo " --extra_options: Extra ASAN_OPTIONS." | |
| 19 echo " --device: Install to the given device. Use 'adb devices' to find" | |
| 20 echo " device-id." | |
| 21 echo | |
| 22 exit 1 | |
| 23 } | |
| 24 | |
| 25 while [[ $# > 0 ]]; do | |
| 26 case $1 in | |
| 27 --revert) | |
| 28 revert=yes | |
| 29 ;; | |
| 30 --extra-options) | |
| 31 shift | |
| 32 if [[ $# == 0 ]]; then | |
| 33 echo "--extra-options requires an argument." | |
| 34 exit 1 | |
| 35 fi | |
| 36 extra_options="$1" | |
| 37 ;; | |
| 38 --device) | |
| 39 shift | |
| 40 if [[ $# == 0 ]]; then | |
| 41 echo "--device requires an argument." | |
| 42 exit 1 | |
| 43 fi | |
| 44 device="$1" | |
| 45 ;; | |
| 46 *) | |
| 47 usage | |
| 48 ;; | |
| 49 esac | |
| 50 shift | |
| 51 done | |
| 52 | |
| 53 ADB="adb" | |
| 54 if [[ x$device != x ]]; then | |
| 55 ADB="adb -s $device" | |
| 56 fi | |
| 57 | |
| 58 ASAN_RT_PATH="$HERE" | |
| 59 ASAN_RT="libclang_rt.asan-arm-android.so" | |
| 60 | |
| 61 if [[ x$revert == xyes ]]; then | |
| 62 echo '>> Uninstalling ASan' | |
| 63 $ADB remount | |
| 64 $ADB shell mv /system/bin/app_process.real /system/bin/app_process | |
| 65 $ADB shell rm /system/bin/asanwrapper | |
| 66 $ADB shell rm /system/lib/$ASAN_RT | |
| 67 | |
| 68 echo '>> Restarting shell' | |
| 69 $ADB shell stop | |
| 70 $ADB shell start | |
| 71 | |
| 72 echo '>> Done' | |
| 73 exit 0 | |
| 74 fi | |
| 75 | |
| 76 if ! [[ -f "$ASAN_RT_PATH/$ASAN_RT" ]]; then | |
| 77 echo "ASan runtime library not found at $ASAN_RT" | |
| 78 exit 1 | |
| 79 fi | |
| 80 | |
| 81 TMPDIRBASE=$(mktemp -d) | |
| 82 echo $TMPDIRBASE | |
| 83 TMPDIROLD="$TMPDIRBASE/old" | |
| 84 TMPDIR="$TMPDIRBASE/new" | |
| 85 mkdir "$TMPDIROLD" | |
| 86 | |
| 87 echo '>> Remounting /system rw' | |
| 88 $ADB remount | |
| 89 | |
| 90 echo '>> Copying files from the device' | |
| 91 $ADB pull /system/bin/app_process "$TMPDIROLD" | |
| 92 $ADB pull /system/bin/app_process.real "$TMPDIROLD" || true | |
| 93 $ADB pull /system/bin/asanwrapper "$TMPDIROLD" || true | |
| 94 $ADB pull /system/lib/libclang_rt.asan-arm-android.so "$TMPDIROLD" || true | |
| 95 cp -r "$TMPDIROLD" "$TMPDIR" | |
| 96 | |
| 97 if ! [[ -f "$TMPDIR/app_process" ]]; then | |
| 98 echo "app_process missing???" | |
| 99 exit 1 | |
| 100 fi | |
| 101 | |
| 102 if [[ -f "$TMPDIR/app_process.real" ]]; then | |
| 103 echo "app_process.real exists, updating the wrapper" | |
| 104 else | |
| 105 echo "app_process.real missing, new installation" | |
| 106 mv "$TMPDIR/app_process" "$TMPDIR/app_process.real" | |
| 107 fi | |
| 108 | |
| 109 echo '>> Generating wrappers' | |
| 110 | |
| 111 cp "$ASAN_RT_PATH/$ASAN_RT" "$TMPDIR/" | |
| 112 | |
| 113 # FIXME: alloc_dealloc_mismatch=0 prevents a failure in libdvm startup, | |
| 114 # which may or may not be a real bug (probably not). | |
| 115 ASAN_OPTIONS=start_deactivated=1,alloc_dealloc_mismatch=0 | |
| 116 if [[ x$extra_options != x ]] ; then | |
| 117 ASAN_OPTIONS="$ASAN_OPTIONS,$extra_options" | |
| 118 fi | |
| 119 | |
| 120 # Zygote wrapper. | |
| 121 cat <<EOF >"$TMPDIR/app_process" | |
| 122 #!/system/bin/sh | |
| 123 ASAN_OPTIONS=$ASAN_OPTIONS \\ | |
| 124 LD_PRELOAD=libclang_rt.asan-arm-android.so \\ | |
| 125 exec /system/bin/app_process.real \$@ | |
| 126 | |
| 127 EOF | |
| 128 | |
| 129 # General command-line tool wrapper (use for anything that's not started as | |
| 130 # zygote). | |
| 131 cat <<EOF >"$TMPDIR/asanwrapper" | |
| 132 #!/system/bin/sh | |
| 133 LD_PRELOAD=libclang_rt.asan-arm-android.so \\ | |
| 134 exec \$@ | |
| 135 | |
| 136 EOF | |
| 137 | |
| 138 if ! ( cd "$TMPDIRBASE" && diff -qr old/ new/ ) ; then | |
| 139 echo '>> Pushing files to the device' | |
| 140 $ADB push "$TMPDIR/$ASAN_RT" /system/lib/ | |
| 141 $ADB push "$TMPDIR/app_process" /system/bin/app_process | |
| 142 $ADB push "$TMPDIR/app_process.real" /system/bin/app_process.real | |
| 143 $ADB push "$TMPDIR/asanwrapper" /system/bin/asanwrapper | |
| 144 $ADB shell chown root.shell \ | |
| 145 /system/bin/app_process \ | |
| 146 /system/bin/app_process.real \ | |
| 147 /system/bin/asanwrapper | |
| 148 $ADB shell chmod 755 \ | |
| 149 /system/bin/app_process \ | |
| 150 /system/bin/app_process.real \ | |
| 151 /system/bin/asanwrapper | |
| 152 | |
| 153 echo '>> Restarting shell' | |
| 154 $ADB shell stop | |
| 155 $ADB shell start | |
| 156 else | |
| 157 echo '>> Device is up to date' | |
| 158 fi | |
| 159 | |
| 160 rm -r "$TMPDIRBASE" | |
| 161 | |
| 162 echo '>> Done' | |
| OLD | NEW |