Powered by Linux
[PATCH 1/2] host_data: export checking for host function name/param — Semantic Matching Tool

[PATCH 1/2] host_data: export checking for host function name/param

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is usable for patterns that need to check whenever
a certain function is an originator (source) of the host
input and also check what its params can be affected by
the host.

Signed-off-by: Elena Reshetova <elena.reshetova@xxxxxxxxx>
---
 smatch.h                     |  3 ++-
 smatch_kernel_host_data.c    | 19 +++++++++++++++++++
 smatch_points_to_host_data.c | 15 +++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/smatch.h b/smatch.h
index 009cefb1..8cab5b6a 100644
--- a/smatch.h
+++ b/smatch.h
@@ -1181,6 +1181,7 @@ void set_points_to_user_data(struct expression *expr, bool is_new);
 
 /* smatch_kernel_host_data.c */
 int is_host_macro(struct expression *expr);
+int get_host_data_fn_param(const char *fn);
 int is_capped_host_data(struct expression *expr);
 int implied_host_data(struct expression *expr, struct range_list **rl);
 struct stree *get_host_stree(void);
@@ -1194,7 +1195,7 @@ bool we_pass_host_data(struct expression *call);
 bool is_host_data_fn(struct symbol *fn);
 bool points_to_host_data(struct expression *expr);
 void set_points_to_host_data(struct expression *expr, bool is_new);
-
+bool is_fn_points_to_host_data(char* fn);
 /* check_locking.c */
 void print_held_locks();
 /* preempt */
diff --git a/smatch_kernel_host_data.c b/smatch_kernel_host_data.c
index fffe1d8e..a1637efc 100644
--- a/smatch_kernel_host_data.c
+++ b/smatch_kernel_host_data.c
@@ -147,6 +147,25 @@ static struct host_fn_info func_table[] = {
 	{ "cpuid_count", HOST_DATA, 5, "*$" },
 };
 
+int get_host_data_fn_param(const char *fn)
+{
+	int ret = 0;
+
+	if (!fn)
+		return ret;
+
+	for (int i = 0; i < ARRAY_SIZE(func_table); i++) {
+		if (strcmp(fn, func_table[i].name) == 0) {
+			ret = func_table[i].param;
+		}
+	}
+	if ((!ret) && (is_fn_points_to_host_data(fn))) {
+		ret = -1;
+	}
+
+	return ret;
+}
+
 static int my_id;
 static unsigned long func_gets_host_data;
 static struct stree *start_states;
diff --git a/smatch_points_to_host_data.c b/smatch_points_to_host_data.c
index 0383bff1..6b3d3a49 100644
--- a/smatch_points_to_host_data.c
+++ b/smatch_points_to_host_data.c
@@ -101,6 +101,21 @@ bool is_host_data_fn(struct symbol *fn)
 	return false;
 }
 
+bool is_fn_points_to_host_data(char* fn)
+{
+	int i;
+
+	if (!fn)
+		return false;
+
+	for (i = 0; i < ARRAY_SIZE(returns_pointer_to_host_data); i++) {
+		if (strcmp(fn, returns_pointer_to_host_data[i]) == 0) {
+			return true;
+		}
+	}
+	return false;
+}
+
 static bool is_points_to_host_data_fn(struct expression *expr)
 {
 	expr = strip_expr(expr);
-- 
2.34.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux