This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathpal_loader
executable file
·103 lines (88 loc) · 2.94 KB
/
pal_loader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-3.0-or-later */
# Copyright (C) 2014 Stony Brook University
# Copyright (C) 2019 Invisible Things Lab
# Copyright (C) 2020-2021 Intel Corporation
# Michał Kowalczyk <[email protected]>
# Wojtek Porczyk <[email protected]>
# This is how we detect whether we're installed or running from inside git repo.
# If unchanged (i.e., if this reads IN_GIT between "at" characters), this is an
# ordinary string and test -n "$IN_GIT" is true. But when installing, this is
# rewritten using meson's configure_file() function to an empty string and the
# else branch is taken. See also: ./meson.build and
# https://mesonbuild.com/Reference-manual.html#configure_file.
IN_GIT=@IN_GIT@
if test -n "$IN_GIT"
then
echo "Running from repository is broken. Please install Graphene using Meson." >&2
echo "See https://graphene.readthedocs.io/en/latest/building.html for details." >&2
exit 1
fi
if [ "00" -eq "0$(id -u 2>/dev/null)" ]
then
if tail /proc/kallsyms 2>/dev/null | grep -q ffff
then
echo "Please don't run Graphene as root!" >&2
exit 1
fi
fi
PAL_CMD=@PAL_CMD@
LIBPAL_PATH=@LIBPAL_PATH@
HOST_PAL_PATH=@HOST_PAL_PATH@
SGX=@SGX@
APPLICATION=
ENVS=()
PREFIX=()
if [ "$GDB" == "1" ]; then
PREFIX=("gdb" "-q")
if [ -n "$INSIDE_EMACS" ]; then
PREFIX+=("-i=mi")
fi
if [ 0"$SGX" -gt 0 ]; then
PREFIX+=("-x" "$HOST_PAL_PATH/gdb_integration/graphene_sgx_gdb.py")
ENVS+=("LD_PRELOAD=$HOST_PAL_PATH/gdb_integration/sgx_gdb.so:$LD_PRELOAD")
else
PREFIX+=("-x" "$HOST_PAL_PATH/gdb_integration/graphene_linux_gdb.py")
fi
if [ "$GDB_SCRIPT" != "" ]; then
# Run a script in batch mode, and without TTY (so that it can be piped, redirected etc.)
PREFIX+=("-x" "$GDB_SCRIPT" "-batch" "-tty=/dev/null")
fi
PREFIX+=("--args")
fi
if [ "$PERF" == "1" ]; then
PREFIX=(perf stat)
fi
while [ "$1" != "" ];
do
if [ "$APPLICATION" == "" ]; then
APPLICATION=$1
shift
continue
fi
break
done
if [ "$APPLICATION" == "" ]; then
echo "Usage: $0 [<application>] <args>..."
exit 2
fi
if [ "$SGX" == "1" ] && [ ! -e "$APPLICATION.manifest.sgx" ]; then
echo "Invalid application path specified ($APPLICATION.manifest.sgx does not exist)." >&2
echo "The path should point to application configuration files, so that they can be" >&2
echo "found after appending corresponding extensions." >&2
exit 2
fi
if [ ! "$SGX" == "1" ] && [ ! -e "$APPLICATION.manifest" ]; then
echo "Invalid application path specified ($APPLICATION.manifest does not exist)." >&2
echo "The path should point to application configuration files, so that they can be" >&2
echo "found after appending corresponding extensions." >&2
exit 2
fi
if [ ! -f "$PAL_CMD" ]; then
echo "$PAL_CMD not found"
exit 1
fi
CMD=("${ENVS[@]}")
CMD+=("${PREFIX[@]}")
CMD+=("$PAL_CMD" "$LIBPAL_PATH" init "$APPLICATION" "$@")
exec env "${CMD[@]}"