]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/msg.h
   2  * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   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. 
  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 
  20  * @APPLE_LICENSE_HEADER_END@ 
  22 /*      $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $      */ 
  25  * SVID compatible msg.h file 
  27  * Author:  Daniel Boulet 
  29  * Copyright 1993 Daniel Boulet and RTMX Inc. 
  31  * This system call was implemented by Daniel Boulet under contract from RTMX. 
  33  * Redistribution and use in source forms, with and without modification, 
  34  * are permitted provided that this entire comment appears intact. 
  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. 
  40  * This software is provided ``AS IS'' without any warranties of any kind. 
  46 #include <sys/appleapiopts.h> 
  48 #include <sys/_types.h> 
  49 #include <sys/cdefs.h> 
  52  * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined when this 
  59  * [XSI] The pid_t, time_t, key_t, size_t, and ssize_t types shall be 
  60  * defined as described in <sys/types.h>. 
  62  * NOTE:        The definition of the key_t type is implicit from the 
  63  *              inclusion of <sys/ipc.h> 
  66 typedef __darwin_pid_t          pid_t
; 
  72 typedef __darwin_time_t         
time_t; 
  77 typedef __darwin_size_t         
size_t; 
  82 typedef __darwin_ssize_t        ssize_t
; 
  85 /* [XSI] Used for the number of messages in the message queue */ 
  86 typedef unsigned long           msgqnum_t
; 
  88 /* [XSI] Used for the number of bytes allowed in a message queue */ 
  89 typedef unsigned long           msglen_t
; 
  93  * Possible values for the fifth parameter to msgrcv(), in addition to the 
  94  * IPC_NOWAIT flag, which is permitted. 
  96 #define MSG_NOERROR     010000          /* [XSI] No error if big message */ 
 100  * Technically, we should force all code references to the new structure 
 101  * definition, not in just the standards conformance case, and leave the 
 102  * legacy interface there for binary compatibility only.  Currently, we 
 103  * are only forcing this for programs requesting standards conformance. 
 105 #if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__) 
 107  * Structure used internally. 
 109  * Structure whose address is passed as the third parameter to msgctl() 
 110  * when the second parameter is IPC_SET or IPC_STAT.  In the case of the 
 111  * IPC_SET command, only the msg_perm.{uid|gid|perm} and msg_qbytes are 
 112  * honored.  In the case of IPC_STAT, only the fields indicated as [XSI] 
 113  * mandated fields are guaranteed to meaningful: DO NOT depend on the 
 114  * contents of the other fields. 
 116  * NOTES:       Reserved fields are not preserved across IPC_SET/IPC_STAT. 
 118 struct __msqid_ds_new 
{ 
 119         struct __ipc_perm_new   msg_perm
; /* [XSI] msg queue permissions */ 
 120         __int32_t       msg_first
;      /* RESERVED: kernel use only */ 
 121         __int32_t       msg_last
;       /* RESERVED: kernel use only */ 
 122         msglen_t        msg_cbytes
;     /* # of bytes on the queue */ 
 123         msgqnum_t       msg_qnum
;       /* [XSI] number of msgs on the queue */ 
 124         msglen_t        msg_qbytes
;     /* [XSI] max bytes on the queue */ 
 125         pid_t           msg_lspid
;      /* [XSI] pid of last msgsnd() */ 
 126         pid_t           msg_lrpid
;      /* [XSI] pid of last msgrcv() */ 
 127         time_t          msg_stime
;      /* [XSI] time of last msgsnd() */ 
 128         __int32_t       msg_pad1
;       /* RESERVED: DO NOT USE */ 
 129         time_t          msg_rtime
;      /* [XSI] time of last msgrcv() */ 
 130         __int32_t       msg_pad2
;       /* RESERVED: DO NOT USE */ 
 131         time_t          msg_ctime
;      /* [XSI] time of last msgctl() */ 
 132         __int32_t       msg_pad3
;       /* RESERVED: DO NOT USE */ 
 133         __int32_t       msg_pad4
[4];    /* RESERVED: DO NOT USE */ 
 135 #define msqid_ds        __msqid_ds_new 
 136 #else   /* !_POSIX_C_SOURCE */ 
 137 #define msqid_ds        __msqid_ds_old 
 138 #endif  /* !_POSIX_C_SOURCE */ 
 140 #if !defined(__POSIX_C_SOURCE) && !defined(__LP64__) 
 141 struct __msqid_ds_old 
{ 
 142         struct __ipc_perm_old   msg_perm
; /* [XSI] msg queue permissions */ 
 143         __int32_t       msg_first
;      /* RESERVED: kernel use only */ 
 144         __int32_t       msg_last
;       /* RESERVED: kernel use only */ 
 145         msglen_t        msg_cbytes
;     /* # of bytes on the queue */ 
 146         msgqnum_t       msg_qnum
;       /* [XSI] number of msgs on the queue */ 
 147         msglen_t        msg_qbytes
;     /* [XSI] max bytes on the queue */ 
 148         pid_t           msg_lspid
;      /* [XSI] pid of last msgsnd() */ 
 149         pid_t           msg_lrpid
;      /* [XSI] pid of last msgrcv() */ 
 150         time_t          msg_stime
;      /* [XSI] time of last msgsnd() */ 
 151         __int32_t       msg_pad1
;       /* RESERVED: DO NOT USE */ 
 152         time_t          msg_rtime
;      /* [XSI] time of last msgrcv() */ 
 153         __int32_t       msg_pad2
;       /* RESERVED: DO NOT USE */ 
 154         time_t          msg_ctime
;      /* [XSI] time of last msgctl() */ 
 155         __int32_t       msg_pad3
;       /* RESERVED: DO NOT USE */ 
 156         __int32_t       msg_pad4
[4];    /* RESERVED: DO NOT USE */ 
 158 #endif  /* !_POSIX_C_SOURCE */ 
 161 #ifdef __APPLE_API_PRIVATE 
 162 #include <machine/types.h> 
 164 // LP64todo - should this move? 
 166 #if __DARWIN_ALIGN_NATURAL 
 167 #pragma options align=natural 
 170 struct user_msqid_ds 
{ 
 171         struct ipc_perm msg_perm
;       /* [XSI] msg queue permissions */ 
 172         struct msg      
*msg_first
;     /* first message in the queue */ 
 173         struct msg      
*msg_last
;      /* last message in the queue */ 
 174         msglen_t        msg_cbytes
;     /* # of bytes on the queue */ 
 175         msgqnum_t       msg_qnum
;       /* [XSI] number of msgs on the queue */ 
 176         msglen_t        msg_qbytes
;     /* [XSI] max bytes on the queue */ 
 177         pid_t           msg_lspid
;      /* [XSI] pid of last msgsnd() */ 
 178         pid_t           msg_lrpid
;      /* [XSI] pid of last msgrcv() */ 
 179         user_time_t     msg_stime
;      /* [XSI] time of last msgsnd() */ 
 180         __int32_t       msg_pad1
;       /* RESERVED: DO NOT USE */ 
 181         user_time_t     msg_rtime
;      /* [XSI] time of last msgrcv() */ 
 182         __int32_t       msg_pad2
;       /* RESERVED: DO NOT USE */ 
 183         user_time_t     msg_ctime
;      /* [XSI] time of last msgctl() */ 
 184         __int32_t       msg_pad3
;       /* RESERVED: DO NOT USE */ 
 185         __int32_t       msg_pad4
[4]; 
 188 #if __DARWIN_ALIGN_NATURAL 
 189 #pragma options align=reset 
 192 #endif  /* __APPLE_API_PRIVATE */ 
 196 #ifndef _POSIX_C_SOURCE 
 197 #ifdef __APPLE_API_UNSTABLE 
 198 /* XXX kernel only; protect with macro later */ 
 201         struct msg      
*msg_next
;      /* next msg in the chain */ 
 202         long            msg_type
;       /* type of this message */ 
 203                                         /* >0 -> type of this message */ 
 204                                         /* 0 -> free header */ 
 205         unsigned short  msg_ts
;         /* size of this message */ 
 206         short           msg_spot
;       /* location of msg start in buffer */ 
 210  * Example structure describing a message whose address is to be passed as 
 211  * the second argument to the functions msgrcv() and msgsnd().  The only 
 212  * actual hard requirement is that the first field be of type long, and 
 213  * contain the message type.  The user is encouraged to define their own 
 214  * application specific structure; this definition is included solely for 
 215  * backward compatability with existing source code. 
 218         long    mtype
;          /* message type (+ve integer) */ 
 219         char    mtext
[1];       /* message body */ 
 223  * Based on the configuration parameters described in an SVR2 (yes, two) 
 224  * config(1m) man page. 
 226  * Each message is broken up and stored in segments that are msgssz bytes 
 227  * long.  For efficiency reasons, this should be a power of two.  Also, 
 228  * it doesn't make sense if it is less than 8 or greater than about 256. 
 229  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of 
 230  * two between 8 and 1024 inclusive (and panic's if it isn't). 
 233         int     msgmax
,         /* max chars in a message */ 
 234                 msgmni
,         /* max message queue identifiers */ 
 235                 msgmnb
,         /* max chars in a queue */ 
 236                 msgtql
,         /* max messages in system */ 
 237                 msgssz
,         /* size of a message segment (see notes above) */ 
 238                 msgseg
;         /* number of message segments */ 
 241 extern struct msginfo   msginfo
; 
 244 #define MSGSSZ  8               /* Each segment must be 2^N long */ 
 247 #define MSGSEG  2048            /* must be less than 32767 */ 
 249 #define MSGMAX  (MSGSSZ*MSGSEG) 
 251 #define MSGMNB  2048            /* max # of bytes in a queue */ 
 261  * macros to convert between msqid_ds's and msqid's. 
 262  * (specific to this implementation) 
 264 #define MSQID(ix,ds)    ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000)) 
 265 #define MSQID_IX(id)    ((id) & 0xffff) 
 266 #define MSQID_SEQ(id)   (((id) >> 16) & 0xffff) 
 269  * The rest of this file is specific to this particular implementation. 
 274  * Stuff allocated in machdep.h 
 277         short   next
;           /* next segment in buffer */ 
 278                                 /* -1 -> available */ 
 279                                 /* 0..(MSGSEG-1) -> index of next segment */ 
 282 /* The following four externs really, really need to die; should be static */ 
 283 extern char *msgpool
;           /* MSGMAX byte long msg buffer pool */ 
 284 extern struct msgmap 
*msgmaps
;  /* MSGSEG msgmap structures */ 
 285 extern struct msg 
*msghdrs
;     /* MSGTQL msg headers */ 
 286 extern struct user_msqid_ds     
*msqids
; /* MSGMNI user_msqid_ds struct's */ 
 288 #define MSG_LOCKED      01000   /* Is this msqid_ds locked? */ 
 291 #endif  /* __APPLE_API_UNSTABLE */ 
 292 #endif  /* !_POSIX_C_SOURCE */ 
 297 #ifndef _POSIX_C_SOURCE 
 298 int msgsys(int, ...); 
 299 #endif  /* !_POSIX_C_SOURCE */ 
 300 int msgctl(int, int, struct msqid_ds 
*) __DARWIN_ALIAS(msgctl
); 
 301 int msgget(key_t
, int); 
 302 ssize_t 
msgrcv(int, void *, size_t, long, int); 
 303 int msgsnd(int, const void *, size_t, int); 
 308 #endif /* !_SYS_MSG_H_ */