summaryrefslogtreecommitdiff
path: root/tools/scmp_sys_resolver.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/scmp_sys_resolver.c')
-rw-r--r--tools/scmp_sys_resolver.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/scmp_sys_resolver.c b/tools/scmp_sys_resolver.c
new file mode 100644
index 0000000..5bc593e
--- /dev/null
+++ b/tools/scmp_sys_resolver.c
@@ -0,0 +1,95 @@
+/**
+ * Syscall resolver
+ *
+ * Copyright (c) 2012 Red Hat <pmoore@redhat.com>
+ * Author: Paul Moore <pmoore@redhat.com>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../src/arch.h"
+#include "../src/arch-x86.h"
+#include "../src/arch-x86_64.h"
+#include "../src/arch-x32.h"
+#include "../src/arch-arm.h"
+
+/**
+ * Print the usage information to stderr and exit
+ * @param program the name of the current program being invoked
+ *
+ * Print the usage information and exit with EINVAL.
+ *
+ */
+static void exit_usage(const char *program)
+{
+ fprintf(stderr,
+ "usage: %s [-h] [-a <arch>] [-t] <syscall_name>\n",
+ program);
+ exit(EINVAL);
+}
+
+/**
+ * main
+ */
+int main(int argc, char *argv[])
+{
+ int opt;
+ int translate = 0;
+ const struct arch_def *arch = arch_def_native;
+ int sys_num;
+
+ /* parse the command line */
+ while ((opt = getopt(argc, argv, "a:ht"))> 0) {
+ switch (opt) {
+ case 'a':
+ if (strcmp(optarg, "x86") == 0)
+ arch = &arch_def_x86;
+ else if (strcmp(optarg, "x86_64") == 0)
+ arch = &arch_def_x86_64;
+ else if (strcmp(optarg, "x32") == 0)
+ arch = &arch_def_x32;
+ else if (strcmp(optarg, "arm") == 0)
+ arch = &arch_def_arm;
+ else
+ exit_usage(argv[0]);
+ break;
+ case 't':
+ translate = 1;
+ break;
+ case 'h':
+ default:
+ /* usage information */
+ exit_usage(argv[0]);
+ }
+ }
+
+ /* sanity checks */
+ if (optind >= argc)
+ exit_usage(argv[0]);
+
+ sys_num = arch_syscall_resolve_name(arch, argv[optind]);
+ if (translate != 0)
+ /* we ignore errors and just output the resolved number */
+ arch_syscall_rewrite(arch, 0, &sys_num);
+ printf("%d\n", sys_num);
+
+ return 0;
+}