[PATCH 2/4] syscall.c: Add helpers for vector reallocation, syscall and errno finder

Nahim El Atmani nahim+dev at naam.me
Wed Jul 27 18:41:15 UTC 2016


From: Nahim El Atmani <naam at lse.epita.fr>

From: Nahim El Atmani <nahim+dev at naam.me>

* syscall.c (reallocate_vec): New function.
  (reallocate_qual): Use it.
  (find_errno_by_name): New function.
  (find_scno_by_name): Likewise.

Signed-off-by: Nahim El Atmani <nahim+dev at naam.me>
Reviewed-By: Gabriel Laskar <gabriel at lse.epita.fr>
---
 syscall.c | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/syscall.c b/syscall.c
index ca7e83d..cf087d6 100644
--- a/syscall.c
+++ b/syscall.c
@@ -387,19 +387,53 @@ static const struct qual_options {
 	{ 0,		NULL,		NULL,		NULL		},
 };
 
-static void
-reallocate_qual(const unsigned int n)
+static inline void
+reallocate_vec(void **vec, size_t size, size_t elt, int n)
 {
 	unsigned p;
-	qualbits_t *qp;
+	char *ptr;
+
 	for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
-		qp = qual_vec[p] = xreallocarray(qual_vec[p], n,
-						 sizeof(qualbits_t));
-		memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
+		ptr = vec[p] = xreallocarray(vec[p], n, elt);
+		memset(ptr + elt * size, 0, (n - size) * elt);
 	}
+}
+
+static inline void
+reallocate_qual(const unsigned int n)
+{
+	reallocate_vec((void **)qual_vec, num_quals, sizeof(qualbits_t), n);
 	num_quals = n;
 }
 
+static int
+find_errno_by_name(const char *name)
+{
+	unsigned int i;
+
+	for (i = 1; i < nerrnos; i++) {
+		if (errnoent[i] && (strcmp(name, errnoent[i]) == 0))
+			return i;
+	}
+
+	return -1;
+}
+
+static int
+find_scno_by_name(const char *name, unsigned personality)
+{
+	unsigned int i;
+
+	for (i = 0; i < nsyscall_vec[personality]; i++) {
+		if (sysent_vec[personality][i].sys_name
+		    && strcmp(name, sysent_vec[personality][i].sys_name) == 0) {
+			return i;
+		}
+	}
+
+	return -1;
+}
+
 static void
 qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int pers)
 {
-- 
Nahim El Atmani





More information about the Strace-devel mailing list