basic_filters.c: introduce scno_by_name
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 1 Feb 2018 12:49:54 +0000 (13:49 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 10 Feb 2018 13:52:42 +0000 (13:52 +0000)
As it will be used elsewhere.

* basic_filters.c (scno_by_name): New function.
(qualify_syscall_name): Use it.
* defs.h (scno_by_name): New declaration.

basic_filters.c
defs.h

index 50e50dd4329426d8c9c72809eed9332045caad37..5aed1601c0534fd2e276202ad0d4560e0d4e809b 100644 (file)
@@ -148,18 +148,32 @@ qualify_syscall_class(const char *s, struct number_set *set)
        return true;
 }
 
+kernel_long_t
+scno_by_name(const char *s, unsigned int p, kernel_long_t start)
+{
+       if (p >= SUPPORTED_PERSONALITIES)
+               return -1;
+
+       for (kernel_ulong_t i = start; i < nsyscall_vec[p]; ++i) {
+               if (sysent_vec[p][i].sys_name &&
+                   strcmp(s, sysent_vec[p][i].sys_name) == 0)
+                       return i;
+       }
+
+       return -1;
+}
+
 static bool
 qualify_syscall_name(const char *s, struct number_set *set)
 {
        bool found = false;
 
        for (unsigned int p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
-               for (unsigned int i = 0; i < nsyscall_vec[p]; ++i) {
-                       if (sysent_vec[p][i].sys_name &&
-                           strcmp(s, sysent_vec[p][i].sys_name) == 0) {
-                               add_number_to_set_array(i, set, p);
-                               found = true;
-                       }
+               for (kernel_long_t scno = 0;
+                    (scno = scno_by_name(s, p, scno)) >= 0;
+                    ++scno) {
+                       add_number_to_set_array(scno, set, p);
+                       found = true;
                }
        }
 
diff --git a/defs.h b/defs.h
index 742db9a90aab6403dcd5e034a5e8d63c49591003..7bcee2d15cc90d0e0a9850b6c0834416ee12bc33 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -407,6 +407,17 @@ extern kernel_ulong_t get_rt_sigframe_addr(struct tcb *);
  *             is valid; NULL otherwise.
  */
 extern const char *syscall_name(kernel_ulong_t scno);
+/**
+ * Convert a syscall name to the corresponding (shuffled) syscall number.
+ *
+ * @param s     Syscall name.
+ * @param p     Personality.
+ * @param start From which position in syscall entry table resume the search.
+ * @return      Shuffled syscall number (ready to use against sysent_vec)
+ *              if syscall name is found; -1 otherwise.
+ */
+extern kernel_long_t scno_by_name(const char *s, unsigned p,
+                                 kernel_long_t start);
 /**
  * Shuffle syscall numbers so that we don't have huge gaps in syscall table.
  * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n.