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 <[email protected]>
---
 tools/sys_resolver.c |   17 ++++++++++++++---
 1 file 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;
 }


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
libseccomp-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libseccomp-discuss

Reply via email to