tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate_wrap_sh.py (1903B)


      1 #! /usr/bin/env python3
      2 # Copyright 2024 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import argparse
      7 import pathlib
      8 
      9 
     10 def _generate(arch, is_hwasan):
     11  if is_hwasan:
     12    return """\
     13 #!/system/bin/sh
     14 # https://developer.android.com/ndk/guides/hwasan#wrapsh
     15 
     16 # import options file
     17 _HWASAN_OPTIONS=$(cat /data/local/tmp/hwasan.options 2> /dev/null || true)
     18 
     19 log -t cr_wrap.sh -- "Launching with HWASAN enabled."
     20 log -t cr_wrap.sh -- "HWASAN_OPTIONS=$_HWASAN_OPTIONS"
     21 log -t cr_wrap.sh -- "LD_HWASAN=1"
     22 log -t cr_wrap.sh -- "Command: $0 $@"
     23 
     24 export HWASAN_OPTIONS=$_HWASAN_OPTIONS
     25 export LD_HWASAN=1
     26 exec "$@"
     27 """
     28  return f"""\
     29 #!/system/bin/sh
     30 # See: https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid/\
     31 01f8df1ac1a447a8475cdfcb03e8b13140042dbd#running-with-wrapsh-recommended
     32 HERE="$(cd "$(dirname "$0")" && pwd)"
     33 # Options suggested by wiki docs:
     34 _ASAN_OPTIONS="log_to_syslog=false,allow_user_segv_handler=1"
     35 # Chromium-specific option (supposedly for graphics drivers):
     36 _ASAN_OPTIONS="$_ASAN_OPTIONS,strict_memcmp=0,use_sigaltstack=1"
     37 _LD_PRELOAD="$HERE/libclang_rt.asan-{arch}-android.so"
     38 log -t cr_wrap.sh -- "Launching with ASAN enabled."
     39 log -t cr_wrap.sh -- "LD_PRELOAD=$_LD_PRELOAD"
     40 log -t cr_wrap.sh -- "ASAN_OPTIONS=$_ASAN_OPTIONS"
     41 log -t cr_wrap.sh -- "Command: $0 $@"
     42 # Export LD_PRELOAD after running "log" commands to not risk it affecting
     43 # them.
     44 export LD_PRELOAD=$_LD_PRELOAD
     45 export ASAN_OPTIONS=$_ASAN_OPTIONS
     46 exec "$@"
     47 """
     48 
     49 
     50 def main():
     51  parser = argparse.ArgumentParser()
     52  parser.add_argument('--arch', required=True)
     53  parser.add_argument('--output', required=True)
     54  parser.add_argument('--is_hwasan', action='store_true', default=False)
     55  args = parser.parse_args()
     56 
     57  pathlib.Path(args.output).write_text(_generate(args.arch, args.is_hwasan))
     58 
     59 
     60 if __name__ == '__main__':
     61  main()