]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/msg.h
xnu-344.12.2.tar.gz
[apple/xnu.git] / bsd / sys / msg.h
CommitLineData
1c79356b 1/*
9bccf70c 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */
23
24/*
25 * SVID compatible msg.h file
26 *
27 * Author: Daniel Boulet
28 *
29 * Copyright 1993 Daniel Boulet and RTMX Inc.
30 *
31 * This system call was implemented by Daniel Boulet under contract from RTMX.
32 *
33 * Redistribution and use in source forms, with and without modification,
34 * are permitted provided that this entire comment appears intact.
35 *
36 * Redistribution in binary form may occur without any restrictions.
37 * Obviously, it would be nice if you gave credit where credit is due
38 * but requiring it would be too onerous.
39 *
40 * This software is provided ``AS IS'' without any warranties of any kind.
41 */
42
43#ifndef _SYS_MSG_H_
44#define _SYS_MSG_H_
45
9bccf70c
A
46#include <sys/appleapiopts.h>
47
48#ifdef __APPLE_API_UNSTABLE
1c79356b
A
49#include <sys/ipc.h>
50
9bccf70c 51
1c79356b
A
52/*
53 * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
54 * are as defined by the SV API Intel 386 Processor Supplement.
55 */
56
57#define MSG_NOERROR 010000 /* don't complain about too long msgs */
58
59struct msqid_ds {
60 struct ipc_perm msg_perm; /* msg queue permission bits */
61 struct msg *msg_first; /* first message in the queue */
62 struct msg *msg_last; /* last message in the queue */
63 u_long msg_cbytes; /* number of bytes in use on the queue */
64 u_long msg_qnum; /* number of msgs in the queue */
65 u_long msg_qbytes; /* max # of bytes on the queue */
66 pid_t msg_lspid; /* pid of last msgsnd() */
67 pid_t msg_lrpid; /* pid of last msgrcv() */
68 time_t msg_stime; /* time of last msgsnd() */
69 long msg_pad1;
70 time_t msg_rtime; /* time of last msgrcv() */
71 long msg_pad2;
72 time_t msg_ctime; /* time of last msgctl() */
73 long msg_pad3;
74 long msg_pad4[4];
75};
76
77struct msg {
78 struct msg *msg_next; /* next msg in the chain */
79 long msg_type; /* type of this message */
80 /* >0 -> type of this message */
81 /* 0 -> free header */
82 u_short msg_ts; /* size of this message */
83 short msg_spot; /* location of start of msg in buffer */
84};
85
86/*
87 * Structure describing a message. The SVID doesn't suggest any
88 * particular name for this structure. There is a reference in the
89 * msgop man page that reads "The structure mymsg is an example of what
90 * this user defined buffer might look like, and includes the following
91 * members:". This sentence is followed by two lines equivalent
92 * to the mtype and mtext field declarations below. It isn't clear
93 * if "mymsg" refers to the naem of the structure type or the name of an
94 * instance of the structure...
95 */
96struct mymsg {
97 long mtype; /* message type (+ve integer) */
98 char mtext[1]; /* message body */
99};
100
101/*
102 * Based on the configuration parameters described in an SVR2 (yes, two)
103 * config(1m) man page.
104 *
105 * Each message is broken up and stored in segments that are msgssz bytes
106 * long. For efficiency reasons, this should be a power of two. Also,
107 * it doesn't make sense if it is less than 8 or greater than about 256.
108 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
109 * two between 8 and 1024 inclusive (and panic's if it isn't).
110 */
111struct msginfo {
112 int msgmax, /* max chars in a message */
113 msgmni, /* max message queue identifiers */
114 msgmnb, /* max chars in a queue */
115 msgtql, /* max messages in system */
116 msgssz, /* size of a message segment (see notes above) */
117 msgseg; /* number of message segments */
118};
119#ifdef KERNEL
120extern struct msginfo msginfo;
121
122#ifndef MSGSSZ
123#define MSGSSZ 8 /* Each segment must be 2^N long */
124#endif
125#ifndef MSGSEG
126#define MSGSEG 2048 /* must be less than 32767 */
127#endif
128#define MSGMAX (MSGSSZ*MSGSEG)
129#ifndef MSGMNB
130#define MSGMNB 2048 /* max # of bytes in a queue */
131#endif
132#ifndef MSGMNI
133#define MSGMNI 40
134#endif
135#ifndef MSGTQL
136#define MSGTQL 40
137#endif
138
139/*
140 * macros to convert between msqid_ds's and msqid's.
141 * (specific to this implementation)
142 */
143#define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
144#define MSQID_IX(id) ((id) & 0xffff)
145#define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
146
147/*
148 * The rest of this file is specific to this particular implementation.
149 */
150
151
152/*
153 * Stuff allocated in machdep.h
154 */
155struct msgmap {
156 short next; /* next segment in buffer */
157 /* -1 -> available */
158 /* 0..(MSGSEG-1) -> index of next segment */
159};
160
161extern char *msgpool; /* MSGMAX byte long msg buffer pool */
162extern struct msgmap *msgmaps; /* MSGSEG msgmap structures */
163extern struct msg *msghdrs; /* MSGTQL msg headers */
164extern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
165
166#define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
167
168#endif /* KERNEL */
169
170#ifndef KERNEL
171#include <sys/cdefs.h>
172
173__BEGIN_DECLS
174int msgsys __P((int, ...));
175int msgctl __P((int, int, struct msqid_ds *));
176int msgget __P((key_t, int));
177int msgsnd __P((int, void *, size_t, int));
178int msgrcv __P((int, void*, size_t, long, int));
179__END_DECLS
180#endif /* !KERNEL */
181
9bccf70c 182#endif /* __APPLE_API_UNSTABLE */
1c79356b 183#endif /* !_SYS_MSG_H_ */