[LTP] [PATCH 04/10] Add SAFE_PRCTL macro
Andrea Cervesato
andrea.cervesato@suse.de
Mon Jul 1 17:42:09 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_macros.h | 6 ++++++
lib/tst_safe_macros.c | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 7748bd34f..733a2506e 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -504,6 +504,12 @@ int safe_sscanf(const char *file, const int lineno, const char *restrict buffer,
#define SAFE_SSCANF(buffer, format, ...) \
safe_sscanf(__FILE__, __LINE__, (buffer), (format), ##__VA_ARGS__)
+int safe_prctl(const char *file, const int lineno,
+ int option, unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5);
+#define SAFE_PRCTL(option, arg2, arg3, arg4, arg5) \
+ safe_prctl(__FILE__, __LINE__, (option), (arg2), (arg3), (arg4), (arg5))
+
int safe_landlock_create_ruleset(const char *file, const int lineno,
const struct landlock_ruleset_attr *attr,
size_t size , uint32_t flags);
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index ba997eb7c..a81037161 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -10,6 +10,7 @@
#include <errno.h>
#include <sched.h>
#include <sys/ptrace.h>
+#include <sys/prctl.h>
#include "config.h"
#ifdef HAVE_SYS_FANOTIFY_H
# include <sys/fanotify.h>
@@ -711,6 +712,21 @@ int safe_mprotect(const char *file, const int lineno,
return rval;
}
+int safe_prctl(const char *file, const int lineno,
+ int option, unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5)
+{
+ int rval;
+
+ rval = prctl(option, arg2, arg3, arg4, arg5);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "prctl(%d, %lu, %lu, %lu, %lu)",
+ option, arg2, arg3, arg4, arg5);
+ }
+
+ return rval;
+}
int safe_landlock_create_ruleset(const char *file, const int lineno,
const struct landlock_ruleset_attr *attr,
--
2.43.0
More information about the ltp
mailing list