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