1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (c) 2017 Xiao yang <yangx.jy@cn.fujitsu.com> 3 */ 4 5 #ifndef TST_SAFE_SYSV_IPC_H__ 6 #define TST_SAFE_SYSV_IPC_H__ 7 8 #include <sys/types.h> 9 #include <sys/ipc.h> 10 #include <sys/msg.h> 11 #include <sys/shm.h> 12 13 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg); 14 #define SAFE_MSGGET(key, msgflg) \ 15 safe_msgget(__FILE__, __LINE__, (key), (msgflg)) 16 17 int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp, 18 size_t msgsz, int msgflg); 19 #define SAFE_MSGSND(msqid, msgp, msgsz, msgflg) \ 20 safe_msgsnd(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgflg)) 21 22 ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp, 23 size_t msgsz, long msgtyp, int msgflg); 24 #define SAFE_MSGRCV(msqid, msgp, msgsz, msgtyp, msgflg) \ 25 safe_msgrcv(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgtyp), (msgflg)) 26 27 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd, 28 struct msqid_ds *buf); 29 #define SAFE_MSGCTL(msqid, cmd, buf) ({ \ 30 int tst_ret_ = safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \ 31 (msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \ 32 tst_ret_;}) 33 34 int safe_shmget(const char *file, const int lineno, key_t key, size_t size, 35 int shmflg); 36 #define SAFE_SHMGET(key, size, shmflg) \ 37 safe_shmget(__FILE__, __LINE__, (key), (size), (shmflg)) 38 39 void *safe_shmat(const char *file, const int lineno, int shmid, 40 const void *shmaddr, int shmflg); 41 #define SAFE_SHMAT(shmid, shmaddr, shmflg) \ 42 safe_shmat(__FILE__, __LINE__, (shmid), (shmaddr), (shmflg)) 43 44 int safe_shmdt(const char *file, const int lineno, const void *shmaddr); 45 #define SAFE_SHMDT(shmaddr) safe_shmdt(__FILE__, __LINE__, (shmaddr)) 46 47 int safe_shmctl(const char *file, const int lineno, int shmid, int cmd, 48 struct shmid_ds *buf); 49 #define SAFE_SHMCTL(shmid, cmd, buf) ({ \ 50 int tst_ret_ = safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \ 51 (shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \ 52 tst_ret_;}) 53 54 #endif /* TST_SAFE_SYSV_IPC_H__ */ 55