msg.h

Go to the documentation of this file.
00001 /* $FreeBSD: src/sys/sys/msg.h,v 1.20 2005/01/07 02:29:23 imp Exp $ */
00002 /*      $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $      */
00003 
00004 /*-
00005  * SVID compatible msg.h file
00006  *
00007  * Author:  Daniel Boulet
00008  *
00009  *© Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00010  * Copyright 1993 Daniel Boulet and RTMX Inc.
00011  *
00012  * This system call was implemented by Daniel Boulet under contract from RTMX.
00013  *
00014  * Redistribution and use in source forms, with and without modification,
00015  * are permitted provided that this entire comment appears intact.
00016  *
00017  * Redistribution in binary form may occur without any restrictions.
00018  * Obviously, it would be nice if you gave credit where credit is due
00019  * but requiring it would be too onerous.
00020  *
00021  * This software is provided ``AS IS'' without any warranties of any kind.
00022  */
00023 
00024 #ifndef _SYS_MSG_H_
00025 #define _SYS_MSG_H_
00026 
00027 #include <sys/cdefs.h>
00028 #include <sys/_types.h>
00029 #include <sys/ipc.h>
00030 
00031 /*
00032  * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
00033  * are as defined by the SV API Intel 386 Processor Supplement.
00034  */
00035 
00036 #define MSG_NOERROR     010000          /* don't complain about too long msgs */
00037 
00038 typedef unsigned long   msglen_t;
00039 typedef unsigned long   msgqnum_t;
00040 
00041 #ifndef _PID_T_DECLARED
00042 typedef __pid_t         pid_t;
00043 #define _PID_T_DECLARED
00044 #endif
00045 
00046 #ifndef _SIZE_T_DECLARED
00047 typedef __size_t        size_t;
00048 #define _SIZE_T_DECLARED
00049 #endif
00050 
00051 #ifndef _SSIZE_T_DECLARED
00052 typedef __ssize_t       ssize_t;
00053 #define _SSIZE_T_DECLARED
00054 #endif
00055 
00056 #ifndef _TIME_T_DECLARED
00057 typedef __time_t        time_t;
00058 #define _TIME_T_DECLARED
00059 #endif
00060 
00061 /*
00062  * XXX there seems to be no prefix reserved for this header, so the name
00063  * "msg" in "struct msg" and the names of all of the nonstandard members
00064  * (mainly "msg_pad*) are namespace pollution.
00065  */
00066 
00067 struct msqid_ds {
00068         struct  ipc_perm msg_perm;      /* msg queue permission bits */
00069         struct  msg *msg_first; /* first message in the queue */
00070         struct  msg *msg_last;  /* last message in the queue */
00071         msglen_t msg_cbytes;    /* number of bytes in use on the queue */
00072         msgqnum_t msg_qnum;     /* number of msgs in the queue */
00073         msglen_t msg_qbytes;    /* max # of bytes on the queue */
00074         pid_t   msg_lspid;      /* pid of last msgsnd() */
00075         pid_t   msg_lrpid;      /* pid of last msgrcv() */
00076         time_t  msg_stime;      /* time of last msgsnd() */
00077         long    msg_pad1;
00078         time_t  msg_rtime;      /* time of last msgrcv() */
00079         long    msg_pad2;
00080         time_t  msg_ctime;      /* time of last msgctl() */
00081         long    msg_pad3;
00082         long    msg_pad4[4];
00083 };
00084 
00085 #if __BSD_VISIBLE
00086 /*
00087  * Structure describing a message.  The SVID doesn't suggest any
00088  * particular name for this structure.  There is a reference in the
00089  * msgop man page that reads "The structure mymsg is an example of what
00090  * this user defined buffer might look like, and includes the following
00091  * members:".  This sentence is followed by two lines equivalent
00092  * to the mtype and mtext field declarations below.  It isn't clear
00093  * if "mymsg" refers to the name of the structure type or the name of an
00094  * instance of the structure...
00095  */
00096 struct mymsg {
00097         long    mtype;          /* message type (+ve integer) */
00098         char    mtext[1];       /* message body */
00099 };
00100 #endif
00101 
00102 #ifdef _KERNEL
00103 
00104 struct msg {
00105         struct  msg *msg_next;  /* next msg in the chain */
00106         long    msg_type;       /* type of this message */
00107                                 /* >0 -> type of this message */
00108                                 /* 0 -> free header */
00109         u_short msg_ts;         /* size of this message */
00110         short   msg_spot;       /* location of start of msg in buffer */
00111         struct  label *label;   /* MAC Framework label */
00112 };
00113 
00114 /*
00115  * Based on the configuration parameters described in an SVR2 (yes, two)
00116  * config(1m) man page.
00117  *
00118  * Each message is broken up and stored in segments that are msgssz bytes
00119  * long.  For efficiency reasons, this should be a power of two.  Also,
00120  * it doesn't make sense if it is less than 8 or greater than about 256.
00121  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
00122  * two between 8 and 1024 inclusive (and panic's if it isn't).
00123  */
00124 struct msginfo {
00125         int     msgmax,         /* max chars in a message */
00126                 msgmni,         /* max message queue identifiers */
00127                 msgmnb,         /* max chars in a queue */
00128                 msgtql,         /* max messages in system */
00129                 msgssz,         /* size of a message segment (see notes above) */
00130                 msgseg;         /* number of message segments */
00131 };
00132 extern struct msginfo   msginfo;
00133 
00134 /*
00135  * Kernel wrapper for the user-level structure.
00136  */
00137 struct msqid_kernel {
00138         /*
00139          * Data structure exposed to user space.
00140          */
00141         struct  msqid_ds u;
00142 
00143         /*
00144          * Kernel-private components of the message queue.
00145          */
00146         struct  label *label;   /* MAC label */
00147 };
00148 
00149 #else /* !_KERNEL */
00150 
00151 /* Template for struct to be used as argument for `msgsnd' and `msgrcv'.  */
00152 struct msgbuf
00153   {
00154     long int mtype;     /* type of received/sent message */
00155     char mtext[1];      /* text of the message */
00156   };
00157 
00158 // FUNCTION PROTOTYPES
00159 
00160 
00161 // FORWARD DECLARATIONS
00162 
00163 
00164 // CLASS/STRUCT/FUNCTION DECLARATION
00165 __BEGIN_DECLS
00166 
00167 /*
00168 * Get the message queue identifier using the IPC key generated by ftok.
00169 */
00170 
00171 IMPORT_C int msgget(key_t key, int msgflg);
00172 
00173 /*
00174 * Used to send a message to the queue associated with the message identifier specified by msqid.
00175 */
00176 
00177 IMPORT_C int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
00178 
00179 /*
00180 * Reads a message from the queue associated with the message queue identifier.
00181 */
00182 
00183 IMPORT_C ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg);
00184 
00185 /*
00186 * Provides an interface to control message queue and control operations as specified by cmd.
00187 */
00188 
00189 IMPORT_C int msgctl(int msqid, int cmd, struct msqid_ds* buf);
00190 
00191 
00192 __END_DECLS
00193 
00194 #endif /* !_KERNEL */
00195 
00196 // _SYS_MSG_H_
00197 #endif
00198 
00199 //  End of File

Copyright © Nokia Corporation 2001-2008
Back to top