• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9set -ex
10cd "$(dirname "${BASH_SOURCE[0]}")/.."
11
12MINIJAIL_DIR=$(realpath "third_party/minijail")
13SECCOMP_DIR=$(realpath seccomp)
14
15export SRC="$MINIJAIL_DIR"
16
17# Create temporary directory for build artifacts and make sure it's cleaned up.
18TMP_DIR="$(mktemp -d)"
19cleanup() {
20    rm -rf "$TMP_DIR"
21}
22trap cleanup EXIT
23
24# Create bindings for each platform
25for arch in "x86_64" "arm" "aarch64"; 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" = "arm" ]; then
35        export CC="arm-linux-gnueabihf-gcc"
36        TARGET="armv7-unknown-linux-gnueabihf"
37    elif [ "$arch" = "aarch64" ]; then
38        export CC="aarch64-linux-gnu-gcc"
39        TARGET="aarch64-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"
57done
58