| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import os, signal, sys, subprocess, tempfile |
| 4 |
from android_common import * |
| 5 |
|
| 6 |
ANDROID_TMPDIR = "/data/local/tmp/Output" |
| 7 |
|
| 8 |
device_binary = host_to_device_path(sys.argv[0]) |
| 9 |
|
| 10 |
|
| 11 |
def build_env(): |
| 12 |
args = [] |
| 13 |
# Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir. |
| 14 |
args.append("LD_LIBRARY_PATH=%s" % (ANDROID_TMPDIR,)) |
| 15 |
for key, value in list(os.environ.items()): |
| 16 |
if key in [ |
| 17 |
"ASAN_ACTIVATION_OPTIONS", |
| 18 |
"SCUDO_OPTIONS", |
| 19 |
"HOME", |
| 20 |
"TMPDIR", |
| 21 |
] or key.endswith("SAN_OPTIONS"): |
| 22 |
args.append('%s="%s"' % (key, value.replace('"', '\\"'))) |
| 23 |
return " ".join(args) |
| 24 |
|
| 25 |
|
| 26 |
is_64bit = ( |
| 27 |
str(subprocess.check_output(["file", sys.argv[0] + ".real"])).find("64-bit") != -1 |
| 28 |
) |
| 29 |
|
| 30 |
device_env = build_env() |
| 31 |
device_args = " ".join(sys.argv[1:]) # FIXME: escape? |
| 32 |
device_stdout = device_binary + ".stdout" |
| 33 |
device_stderr = device_binary + ".stderr" |
| 34 |
device_exitcode = device_binary + ".exitcode" |
| 35 |
ret = adb( |
| 36 |
[ |
| 37 |
"shell", |
| 38 |
"cd %s && %s %s %s >%s 2>%s ; echo $? >%s" |
| 39 |
% ( |
| 40 |
ANDROID_TMPDIR, |
| 41 |
device_env, |
| 42 |
device_binary, |
| 43 |
device_args, |
| 44 |
device_stdout, |
| 45 |
device_stderr, |
| 46 |
device_exitcode, |
| 47 |
), |
| 48 |
] |
| 49 |
) |
| 50 |
if ret != 0: |
| 51 |
sys.exit(ret) |
| 52 |
|
| 53 |
sys.stdout.write(pull_from_device(device_stdout)) |
| 54 |
sys.stderr.write(pull_from_device(device_stderr)) |
| 55 |
retcode = int(pull_from_device(device_exitcode)) |
| 56 |
# If the device process died with a signal, do abort(). |
| 57 |
# Not exactly the same, but good enough to fool "not --crash". |
| 58 |
if retcode > 128: |
| 59 |
os.kill(os.getpid(), signal.SIGABRT) |
| 60 |
sys.exit(retcode) |