All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] tst_safe_sysv_ipc: add shared memory related macros
@ 2017-04-14 10:15 Xiao Yang
  2017-04-14 10:15 ` [LTP] [PATCH 2/3] syscalls/shmat0*: cleanup && convert to new API Xiao Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Xiao Yang @ 2017-04-14 10:15 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/tst_safe_sysv_ipc.h | 25 +++++++++++++++++++
 lib/tst_safe_sysv_ipc.c     | 58 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/include/tst_safe_sysv_ipc.h b/include/tst_safe_sysv_ipc.h
index cbdefb9..e01957f 100644
--- a/include/tst_safe_sysv_ipc.h
+++ b/include/tst_safe_sysv_ipc.h
@@ -18,6 +18,11 @@
 #ifndef TST_SAFE_SYSV_IPC_H__
 #define TST_SAFE_SYSV_IPC_H__
 
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/shm.h>
+
 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg);
 #define SAFE_MSGGET(key, msgflg) \
 	safe_msgget(__FILE__, __LINE__, (key), (msgflg))
@@ -39,4 +44,24 @@ int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
 	(msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \
 	} while (0)
 
+int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
+		int shmflg);
+#define SAFE_SHMGET(key, size, shmflg) \
+	safe_shmget(__FILE__, __LINE__, (key), (size), (shmflg))
+
+void *safe_shmat(const char *file, const int lineno, int shmid,
+		const void *shmaddr, int shmflg);
+#define SAFE_SHMAT(shmid, shmaddr, shmflg) \
+	safe_shmat(__FILE__, __LINE__, (shmid), (shmaddr), (shmflg))
+
+int safe_shmdt(const char *file, const int lineno, const void *shmaddr);
+#define SAFE_SHMDT(shmaddr)	safe_shmdt(__FILE__, __LINE__, (shmaddr))
+
+int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
+		struct shmid_ds *buf);
+#define SAFE_SHMCTL(shmid, cmd, buf) do { \
+	safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \
+	(shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \
+	} while (0)
+
 #endif /* TST_SAFE_SYSV_IPC_H__ */
diff --git a/lib/tst_safe_sysv_ipc.c b/lib/tst_safe_sysv_ipc.c
index cb2b304..b2b132b 100644
--- a/lib/tst_safe_sysv_ipc.c
+++ b/lib/tst_safe_sysv_ipc.c
@@ -18,6 +18,7 @@
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
+#include <sys/shm.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
@@ -68,7 +69,7 @@ ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
 		struct msqid_ds *buf)
 {
-	int  rval;
+	int rval;
 
 	rval = msgctl(msqid, cmd, buf);
 	if (rval == -1) {
@@ -78,3 +79,58 @@ int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
 
 	return rval;
 }
+
+int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
+		int shmflg)
+{
+	int rval;
+
+	rval = shmget(key, size, shmflg);
+	if (rval == -1) {
+		tst_brk(TBROK | TERRNO, "%s:%d: shmget(%i, %li, %x) failed",
+			file, lineno, (int)key, size, shmflg);
+	}
+
+	return rval;
+}
+
+void *safe_shmat(const char *file, const int lineno, int shmid,
+		const void *shmaddr, int shmflg)
+{
+	void *rval;
+
+	rval = shmat(shmid, shmaddr, shmflg);
+	if (rval == (void *)-1) {
+		tst_brk(TBROK | TERRNO, "%s:%d: shmat(%i, %p, %x) failed",
+			file, lineno, shmid, shmaddr, shmflg);
+	}
+
+	return rval;
+}
+
+int safe_shmdt(const char *file, const int lineno, const void *shmaddr)
+{
+	int rval;
+
+	rval = shmdt(shmaddr);
+	if (rval == -1) {
+		tst_brk(TBROK | TERRNO, "%s:%d: shmdt(%p) failed",
+			file, lineno, shmaddr);
+	}
+
+	return rval;
+}
+
+int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
+		struct shmid_ds *buf)
+{
+	int rval;
+
+	rval = shmctl(shmid, cmd, buf);
+	if (rval == -1) {
+		tst_brk(TBROK | TERRNO, "%s:%d: shmctl(%i, %i, %p) failed",
+			file, lineno, shmid, cmd, buf);
+	}
+
+	return rval;
+}
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2017-07-07 12:29 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-14 10:15 [LTP] [PATCH 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-04-14 10:15 ` [LTP] [PATCH 2/3] syscalls/shmat0*: cleanup && convert to new API Xiao Yang
2017-05-29 14:11   ` Cyril Hrubis
2017-06-01  9:03     ` Xiao Yang
2017-04-14 10:15 ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-05-29 14:57   ` Cyril Hrubis
2017-06-01 11:49     ` [LTP] [PATCH v2 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-06-01 11:49       ` [LTP] [PATCH v2 2/3] syscalls/shmat0*: cleanup && convert to new API Xiao Yang
2017-06-29 16:14         ` Cyril Hrubis
2017-06-30  2:30           ` [LTP] [PATCH v3] " Xiao Yang
2017-06-30 14:54             ` Cyril Hrubis
2017-07-03  3:09               ` [LTP] [PATCH v4] " Xiao Yang
2017-07-07 12:29                 ` Cyril Hrubis
2017-06-01 11:49       ` [LTP] [PATCH v2 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-22  9:41       ` [LTP] [PATCH v2 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-06-22 15:29       ` Cyril Hrubis
2017-06-01 11:53     ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-22 10:09       ` Xiao Yang
2017-06-22 11:08         ` Xiao Yang
2017-06-22 12:02           ` Jan Stancek
2017-06-22 15:11             ` [LTP] [PATCH v2 2/2] clone09: add a test for CLONE_NEWNET flag Cyril Hrubis
2017-06-23  7:22               ` Richard Palethorpe
2017-06-23  1:07             ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-20 13:40     ` Richard Palethorpe
2017-05-19  1:19 ` [LTP] [PATCH 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.