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 #include <sys/sem.h> 13 14 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg); 15 #define SAFE_MSGGET(key, msgflg) \ 16 safe_msgget(__FILE__, __LINE__, (key), (msgflg)) 17 18 int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp, 19 size_t msgsz, int msgflg); 20 #define SAFE_MSGSND(msqid, msgp, msgsz, msgflg) \ 21 safe_msgsnd(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgflg)) 22 23 ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp, 24 size_t msgsz, long msgtyp, int msgflg); 25 #define SAFE_MSGRCV(msqid, msgp, msgsz, msgtyp, msgflg) \ 26 safe_msgrcv(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgtyp), (msgflg)) 27 28 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd, 29 struct msqid_ds *buf); 30 #define SAFE_MSGCTL(msqid, cmd, buf) ({ \ 31 int tst_ret_ = safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \ 32 (msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \ 33 tst_ret_;}) 34 35 int safe_shmget(const char *file, const int lineno, key_t key, size_t size, 36 int shmflg); 37 #define SAFE_SHMGET(key, size, shmflg) \ 38 safe_shmget(__FILE__, __LINE__, (key), (size), (shmflg)) 39 40 void *safe_shmat(const char *file, const int lineno, int shmid, 41 const void *shmaddr, int shmflg); 42 #define SAFE_SHMAT(shmid, shmaddr, shmflg) \ 43 safe_shmat(__FILE__, __LINE__, (shmid), (shmaddr), (shmflg)) 44 45 int safe_shmdt(const char *file, const int lineno, const void *shmaddr); 46 #define SAFE_SHMDT(shmaddr) safe_shmdt(__FILE__, __LINE__, (shmaddr)) 47 48 int safe_shmctl(const char *file, const int lineno, int shmid, int cmd, 49 struct shmid_ds *buf); 50 #define SAFE_SHMCTL(shmid, cmd, buf) ({ \ 51 int tst_ret_ = safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \ 52 (shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \ 53 tst_ret_;}) 54 55 int safe_semget(const char *file, const int lineno, key_t key, int nsems, 56 int semflg); 57 #define SAFE_SEMGET(key, nsems, semflg) \ 58 safe_semget(__FILE__, __LINE__, (key), (nsems), (semflg)) 59 60 int safe_semctl(const char *file, const int lineno, int semid, int semnum, 61 int cmd, ...); 62 #define SAFE_SEMCTL(semid, semnum, cmd, ...) ({ \ 63 int tst_ret_ = safe_semctl(__FILE__, __LINE__, (semid), (semnum), \ 64 (cmd), ##__VA_ARGS__); \ 65 (semid) = ((cmd) == IPC_RMID ? -1 : (semid)); \ 66 tst_ret_; }) 67 68 int safe_semop(const char *file, const int lineno, int semid, struct sembuf *sops, 69 size_t nsops); 70 #define SAFE_SEMOP(semid, sops, nsops) \ 71 safe_semop(__FILE__, __LINE__, (semid), (sops), (nsops)) 72 #endif /* TST_SAFE_SYSV_IPC_H__ */ 73