[LTP] [PATCH] lib: Add SAFE_MSYNC() macro to LTP library

Avinesh Kumar
2023-09-14T11:45:38Z

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
include/tst_safe_macros.h | 6 ++++++
lib/tst_safe_macros.c | 19 +++++++++++++++++++
2 files changed, 25 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 0cf3d7878..c899c4f2c 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -86,6 +86,12 @@ void *safe_realloc(const char *file, const int lineno, void *ptr, size_t size);
#define SAFE_MUNMAP(addr, length) \
safe_munmap(__FILE__, __LINE__, NULL, (addr), (length))

+int safe_msync(const char *file, const int lineno, void *addr,
+ size_t length, int flags);
+
+#define SAFE_MSYNC(addr, length, flags) \
+ safe_msync(__FILE__, __LINE__, (addr), (length), (flags))
+
#define SAFE_OPEN(pathname, oflags, ...) \
safe_open(__FILE__, __LINE__, NULL, (pathname), (oflags), \
##__VA_ARGS__)
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index c4cdc87e7..7f28d43e5 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -591,3 +591,22 @@ void safe_cmd(const char *file, const int lineno, const char *const argv[],
tst_brk_(file, lineno, TBROK, "%s failed (%d)", argv[0], rval);
}
}
+
+int safe_msync(const char *file, const int lineno, void *addr,
+ size_t length, int flags)
+{
+ int rval;
+
+ rval = msync(addr, length, flags);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "msync(%p, %zu, %d) failed", addr, length, flags);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid msync(%p, %zu, %d) return value %d",
+ addr, length, flags, rval);
+ }
+
+ return rval;
+}
--
2.42.0