Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/jail/seccomp/generate_constants.sh
5394 views
1
#!/usr/bin/env bash
2
# Copyright 2022 The ChromiumOS 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
# Run this script to re-generate the seccomp/*/constants.json files for
7
# each architecture.
8
9
set -ex
10
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
11
12
MINIJAIL_DIR=$(realpath "third_party/minijail")
13
SECCOMP_DIR=$(realpath "jail/seccomp")
14
15
export SRC="$MINIJAIL_DIR"
16
17
# Create temporary directory for build artifacts and make sure it's cleaned up.
18
TMP_DIR="$(mktemp -d)"
19
cleanup() {
20
rm -rf "$TMP_DIR"
21
}
22
trap cleanup EXIT
23
24
# Create bindings for each platform
25
for arch in "x86_64" "aarch64" "riscv64"; do
26
BUILD_DIR="$TMP_DIR/$arch"
27
mkdir -p "$BUILD_DIR"
28
cd "$BUILD_DIR"
29
30
# Pick the right cross-compiler
31
if [ "$arch" = "x86_64" ]; then
32
export CC="gcc"
33
TARGET="x86_64-unknown-linux-gnu"
34
elif [ "$arch" = "aarch64" ]; then
35
export CC="aarch64-linux-gnu-gcc"
36
TARGET="aarch64-unknown-linux-gnu"
37
elif [ "$arch" = "riscv64" ]; then
38
export CC="riscv64-linux-gnu-gcc"
39
TARGET="riscv64-unknown-linux-gnu"
40
fi
41
42
"$MINIJAIL_DIR/gen_constants.sh" "libconstants.gen.c"
43
"$MINIJAIL_DIR/gen_syscalls.sh" "libsyscalls.gen.c"
44
45
clang \
46
-target "$TARGET" \
47
-S \
48
-emit-llvm \
49
-I "$MINIJAIL_DIR" \
50
"libconstants.gen.c" \
51
"libsyscalls.gen.c"
52
53
"$MINIJAIL_DIR/tools/generate_constants_json.py" \
54
--output "$SECCOMP_DIR/$arch/constants.json" \
55
"libconstants.gen.ll" \
56
"libsyscalls.gen.ll"
57
done
58
59