xref: /dragonfly/lib/libc/sysvipc/sysvipc_ipc.h (revision ff86f40163b90743b832c47e55fc6ca83aa45121)
1 /**
2  * Copyright (c) 2013 Larisa Grigore<larisagrigore@gmail.com>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _SYSVIPC_IPC_H_
29 #define _SYSVIPC_IPC_H_
30 
31 #define MAXSIZE               100
32 
33 #define IPC_INITIALIZED       1
34 
35 #define SHMGET                1
36 #define SEMGET                2
37 #define MSGGET                3
38 #define UNDOGET               4
39 
40 #define SHMAT                 5
41 #define SHMDT                 6
42 #define SHMCTL                7
43 
44 #define SEMOP                 8
45 #define SEMCTL                9
46 
47 #define PIPE_READ   0
48 #define PIPE_WRITE  1
49 
50 #define   IPCID_TO_IX(id)               ((id) & 0xffff)
51 #define   IPCID_TO_SEQ(id)    (((id) >> 16) & 0xffff)
52 #define   IXSEQ_TO_IPCID(ix,perm)       (((perm.seq) << 16) | (ix & 0xffff))
53 
54 #include <sys/shm.h>
55 #include "sysvipc_utils.h"
56 
57 /* Structures used to send/receive
58  * messages to/from daemon.
59  */
60 struct shmget_msg {
61           key_t key;
62           size_t size;
63           int shmflg;
64           int type;
65 };
66 
67 struct shmat_msg {
68           int shmid;
69           const void *shmaddr;
70           int shmflg;
71           size_t size;
72 };
73 
74 struct shmdt_msg {
75           const void *shmaddr;
76 };
77 
78 struct shmctl_msg {
79           int shmid;
80           int cmd;
81           struct shmid_ds buf;
82 };
83 
84 struct sysvipc_msg {
85           int type;
86           char data[0];
87 };
88 
89 struct semget_msg {
90           key_t key;
91           int nsems;
92           int shmflg;
93 };
94 
95 /* Send/receive messages. */
96 int send_message(int, int, char *, int);
97 int receive_type_message(int);
98 int receive_message(int, char *, int);
99 
100 /* sysv ipc structures initialization. */
101 int is_sysvinit(void);
102 int sysvinit(void);
103 int sysvexit(void);
104 
105 #endif /* !_SYSVIPC_IPC_H_ */
106