pal_loader 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. while :
  3. do
  4. case "$1" in
  5. "SGX")
  6. SGX=1
  7. export SGX
  8. ;;
  9. "GDB")
  10. GDB=1
  11. ;;
  12. *)
  13. break
  14. ;;
  15. esac
  16. shift
  17. done
  18. RUNTIME_DIR=$(/usr/bin/dirname "$(readlink -f "${BASH_SOURCE[0]}")")
  19. if [ -z "$PAL_HOST" ]; then
  20. if [ ! -f /usr/bin/make ]; then
  21. libpal="$RUNTIME_DIR/libpal-*.so"
  22. libpal="$(echo -n "$libpal")"
  23. libpal="${libpal//$RUNTIME_DIR\//}"
  24. if [ "$libpal" = 'libpal-*.so' ]; then
  25. echo "Unable to detect PAL_HOST. Please install the make program."
  26. exit 1
  27. fi
  28. array=("$libpal")
  29. if [ ${#array[@]} -ne 1 ]; then
  30. echo "Multiple libpal detected ($libpal). Please explicitly set the environment variable PAL_HOST."
  31. exit 1
  32. fi
  33. PAL_HOST="${libpal%.so}"
  34. PAL_HOST="${PAL_HOST#libpal-}"
  35. else
  36. PAL_HOST=$(/usr/bin/make --no-print-directory --quiet -f "$RUNTIME_DIR/../Scripts/Makefile.configs" print_host 2>&1)
  37. fi
  38. fi
  39. MANIFEST=
  40. PREFIX=()
  41. PAL_CMD=$RUNTIME_DIR/pal-$PAL_HOST
  42. if [ "$GDB" == "1" ]; then
  43. GDB=$RUNTIME_DIR/pal_gdb-$PAL_HOST
  44. if [ ! -f "$GDB" ]; then
  45. GDB="/usr/bin/gdb"
  46. fi
  47. fi
  48. if [ "$GDB" != "" ] && [ "$GDB" != "0" ]; then
  49. PREFIX=("$GDB")
  50. if [ -n "$INSIDE_EMACS" ]; then
  51. PREFIX+=("-i=mi")
  52. fi
  53. PREFIX+=("--args")
  54. fi
  55. if [ "$PERF" == "1" ]; then
  56. PREFIX=(perf stat)
  57. fi
  58. if [ "$MEMUSG" == "1" ]; then
  59. PREFIX=("$RUNTIME_DIR/../Scripts/memusg")
  60. fi
  61. while [ "$1" != "" ];
  62. do
  63. if [ "$MANIFEST" == "" ]; then
  64. MANIFEST=$1
  65. shift
  66. continue
  67. fi
  68. break
  69. done
  70. if [ ! -f "$PAL_CMD" ]; then
  71. echo "$PAL_CMD is not built, or security mode is not supported"
  72. exit 1
  73. fi
  74. if [ ${#PREFIX[@]} -eq 0 ]; then
  75. exec "$PAL_CMD" "$MANIFEST" "$@"
  76. else
  77. exec "${PREFIX[@]}" "$PAL_CMD" "$MANIFEST" "$@"
  78. fi