• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 Xiao yang <yangx.jy@cn.fujitsu.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TST_SAFE_SYSV_IPC_H__
19 #define TST_SAFE_SYSV_IPC_H__
20 
21 #include <sys/types.h>
22 #include <sys/ipc.h>
23 #include <sys/msg.h>
24 #include <sys/shm.h>
25 
26 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg);
27 #define SAFE_MSGGET(key, msgflg) \
28 	safe_msgget(__FILE__, __LINE__, (key), (msgflg))
29 
30 int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
31 		size_t msgsz, int msgflg);
32 #define SAFE_MSGSND(msqid, msgp, msgsz, msgflg) \
33 	safe_msgsnd(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgflg))
34 
35 ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
36 		size_t msgsz, long msgtyp, int msgflg);
37 #define SAFE_MSGRCV(msqid, msgp, msgsz, msgtyp, msgflg) \
38 	safe_msgrcv(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgtyp), (msgflg))
39 
40 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
41 		struct msqid_ds *buf);
42 #define SAFE_MSGCTL(msqid, cmd, buf) ({ \
43 	int tst_ret_ = safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \
44 	(msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \
45 	tst_ret_;})
46 
47 int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
48 		int shmflg);
49 #define SAFE_SHMGET(key, size, shmflg) \
50 	safe_shmget(__FILE__, __LINE__, (key), (size), (shmflg))
51 
52 void *safe_shmat(const char *file, const int lineno, int shmid,
53 		const void *shmaddr, int shmflg);
54 #define SAFE_SHMAT(shmid, shmaddr, shmflg) \
55 	safe_shmat(__FILE__, __LINE__, (shmid), (shmaddr), (shmflg))
56 
57 int safe_shmdt(const char *file, const int lineno, const void *shmaddr);
58 #define SAFE_SHMDT(shmaddr)	safe_shmdt(__FILE__, __LINE__, (shmaddr))
59 
60 int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
61 		struct shmid_ds *buf);
62 #define SAFE_SHMCTL(shmid, cmd, buf) ({ \
63 	int tst_ret_ = safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \
64 	(shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \
65 	tst_ret_;})
66 
67 #endif /* TST_SAFE_SYSV_IPC_H__ */
68