aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2018-10-28 21:39:32 -0700
committerLuis Hector Chavez <lhchavez@google.com>2018-10-29 20:53:18 -0700
commitf7b201804bb5e285066b76c6804f498e4b77ea22 (patch)
tree485c110e57bfa64d3c69b71ec77d94f59e1aa176
parentd81f47f5b131ad086ceb542531813ec5c3e8eb47 (diff)
downloadminijail-f7b201804bb5e285066b76c6804f498e4b77ea22.tar.gz
dump_constants: Add a tool to generate a JSON file with all constants
This change adds a way to export all the necessary constants so that external tools can compile the policy files. Bug: chromium:856315 Test: make all Change-Id: I8637c63b9b09839616aa66ef1714444cb4e124ee
-rw-r--r--.gitignore3
-rw-r--r--Makefile13
-rw-r--r--dump_constants.cc46
3 files changed, 61 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index b500f2a..2414029 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@
*.o
*.a
+/constants.json
+
# Coverage-related files that appear when building with MODE=profiling.
*.gcno
*.gcda
@@ -17,6 +19,7 @@
*.so
# Executables when compiling in-tree.
+/dump_constants
/libminijail_unittest
/minijail0
/minijail0_cli_unittest
diff --git a/Makefile b/Makefile
index 54ee978..d58d2ad 100644
--- a/Makefile
+++ b/Makefile
@@ -55,9 +55,10 @@ CORE_OBJECT_FILES := libminijail.o syscall_filter.o signal_handler.o \
libconstants.gen.o libsyscalls.gen.o
all: CC_BINARY(minijail0) CC_LIBRARY(libminijail.so) \
- CC_LIBRARY(libminijailpreload.so)
+ CC_LIBRARY(libminijailpreload.so) constants.json
parse_seccomp_policy: CXX_BINARY(parse_seccomp_policy)
+dump_constants: CXX_BINARY(dump_constants)
tests: TEST(CXX_BINARY(libminijail_unittest)) \
TEST(CXX_BINARY(minijail0_cli_unittest)) \
@@ -141,6 +142,16 @@ CXX_BINARY(parse_seccomp_policy): parse_seccomp_policy.o syscall_filter.o \
clean: CLEAN(parse_seccomp_policy)
+CXX_BINARY(dump_constants): dump_constants.o \
+ libconstants.gen.o libsyscalls.gen.o
+clean: CLEAN(dump_constants)
+
+
+constants.json: CXX_BINARY(dump_constants)
+ ./dump_constants > $@
+clean: CLEANFILE(constants.json)
+
+
libsyscalls.gen.o: CPPFLAGS += -I$(SRC)
libsyscalls.gen.o.depends: libsyscalls.gen.c
diff --git a/dump_constants.cc b/dump_constants.cc
new file mode 100644
index 0000000..f33bd5b
--- /dev/null
+++ b/dump_constants.cc
@@ -0,0 +1,46 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// Generate a .json file with all the architecture-specific constants.
+
+#include <cstdint>
+#include <iomanip>
+#include <iostream>
+#include <string>
+
+#include "arch.h"
+#include "libconstants.h"
+#include "libsyscalls.h"
+
+int main() {
+ std::cout << "{\n";
+ std::cout << " \"arch_nr\": " << ARCH_NR << ",\n";
+ std::cout << " \"bits\": " << (sizeof(uintptr_t) * 8) << ",\n";
+ std::cout << " \"syscalls\": {\n";
+ bool first = true;
+ for (const struct syscall_entry* entry = syscall_table; entry->name;
+ ++entry) {
+ if (first)
+ first = false;
+ else
+ std::cout << ",\n";
+ std::cout << " \"" << entry->name << "\": " << entry->nr;
+ }
+ std::cout << "\n },\n";
+ std::cout << " \"constants\": {\n";
+ first = true;
+ for (const struct constant_entry* entry = constant_table; entry->name;
+ ++entry) {
+ if (first)
+ first = false;
+ else
+ std::cout << ",\n";
+ std::cout << " \"" << entry->name << "\": " << entry->value;
+ }
+ std::cout << "\n }\n";
+ std::cout << "}\n";
+
+ return 0;
+}