summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <pmoore@redhat.com>2013-01-18 15:15:08 -0500
committerPaul Moore <pmoore@redhat.com>2013-01-18 15:15:08 -0500
commitfc8d50b97fd391deccaed932d07df26959e81f1b (patch)
tree2c86c1a89215f06fdeb6b9708ba8f1875be5db9f
parent69fc22101affc5defe9bd52b34384d63f09f41ec (diff)
downloadlibseccomp-fc8d50b97fd391deccaed932d07df26959e81f1b.tar.gz
tools: allow sys_resolver to translate syscalls
Normally sys_resolver does not translate syscalls which means that in some cases, e.g. socket() on x86, the returned syscall number could be a negative number (__PNR_socket). This patch adds a new option, '-t', which causes sys_resolver to attempt to do the translation and return the translated syscall number instead, e.g. socketcall() for socket() on x86. Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r--tools/sys_resolver.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/sys_resolver.c b/tools/sys_resolver.c
index b7ebab6..9fc6065 100644
--- a/tools/sys_resolver.c
+++ b/tools/sys_resolver.c
@@ -39,7 +39,8 @@
static void exit_usage(const char *program)
{
fprintf(stderr,
- "usage: %s [-h] [-a x86|x86_64] <syscall_name>\n", program);
+ "usage: %s [-h] [-a x86|x86_64] [-t] <syscall_name>\n",
+ program);
exit(EINVAL);
}
@@ -49,10 +50,12 @@ static void exit_usage(const char *program)
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:h"))> 0) {
+ while ((opt = getopt(argc, argv, "a:ht"))> 0) {
switch (opt) {
case 'a':
if (strcmp(optarg, "x86") == 0)
@@ -62,6 +65,9 @@ int main(int argc, char *argv[])
else
exit_usage(argv[0]);
break;
+ case 't':
+ translate = 1;
+ break;
case 'h':
default:
/* usage information */
@@ -73,6 +79,11 @@ int main(int argc, char *argv[])
if (optind >= argc)
exit_usage(argv[0]);
- printf("%d\n", arch_syscall_resolve_name(arch, argv[optind]));
+ 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, &sys_num);
+ printf("%d\n", sys_num);
+
return 0;
}