root/sys/msg.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


    1 /*      $OpenBSD: msg.h,v 1.13 2004/07/15 11:24:46 millert Exp $        */
    2 /*      $NetBSD: msg.h,v 1.9 1996/02/09 18:25:18 christos Exp $ */
    3 
    4 /*
    5  * SVID compatible msg.h file
    6  *
    7  * Author:  Daniel Boulet
    8  *
    9  * Copyright 1993 Daniel Boulet and RTMX Inc.
   10  *
   11  * This system call was implemented by Daniel Boulet under contract from RTMX.
   12  *
   13  * Redistribution and use in source forms, with and without modification,
   14  * are permitted provided that this entire comment appears intact.
   15  *
   16  * Redistribution in binary form may occur without any restrictions.
   17  * Obviously, it would be nice if you gave credit where credit is due
   18  * but requiring it would be too onerous.
   19  *
   20  * This software is provided ``AS IS'' without any warranties of any kind.
   21  */
   22 
   23 #ifndef _SYS_MSG_H_
   24 #define _SYS_MSG_H_
   25 
   26 #include <sys/ipc.h>
   27 
   28 /*
   29  * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
   30  * are as defined by the SV API Intel 386 Processor Supplement.
   31  */
   32 
   33 #define MSG_NOERROR     010000          /* don't complain about too long msgs */
   34 
   35 struct msqid_ds {
   36         struct ipc_perm msg_perm;       /* msg queue permission bits */
   37         struct msg      *msg_first;     /* first message in the queue */
   38         struct msg      *msg_last;      /* last message in the queue */
   39         unsigned long   msg_cbytes;     /* number of bytes in use on the queue */
   40         unsigned long   msg_qnum;       /* number of msgs in the queue */
   41         unsigned long   msg_qbytes;     /* max # of bytes on the queue */
   42         pid_t           msg_lspid;      /* pid of last msgsnd() */
   43         pid_t           msg_lrpid;      /* pid of last msgrcv() */
   44         time_t          msg_stime;      /* time of last msgsnd() */
   45         long            msg_pad1;
   46         time_t          msg_rtime;      /* time of last msgrcv() */
   47         long            msg_pad2;
   48         time_t          msg_ctime;      /* time of last msgctl() */
   49         long            msg_pad3;
   50         long            msg_pad4[4];
   51 };
   52 
   53 #ifdef _KERNEL
   54 struct msqid_ds23 {
   55         struct ipc_perm23 msg_perm;     /* msg queue permission bits */
   56         struct msg      *msg_first;     /* first message in the queue */
   57         struct msg      *msg_last;      /* last message in the queue */
   58         unsigned long   msg_cbytes;     /* number of bytes in use on the queue */
   59         unsigned long   msg_qnum;       /* number of msgs in the queue */
   60         unsigned long   msg_qbytes;     /* max # of bytes on the queue */
   61         pid_t           msg_lspid;      /* pid of last msgsnd() */
   62         pid_t           msg_lrpid;      /* pid of last msgrcv() */
   63         time_t          msg_stime;      /* time of last msgsnd() */
   64         long            msg_pad1;
   65         time_t          msg_rtime;      /* time of last msgrcv() */
   66         long            msg_pad2;
   67         time_t          msg_ctime;      /* time of last msgctl() */
   68         long            msg_pad3;
   69         long            msg_pad4[4];
   70 };
   71 
   72 struct msqid_ds35 {
   73         struct ipc_perm35 msg_perm;     /* msg queue permission bits */
   74         struct msg        *msg_first;   /* first message in the queue */
   75         struct msg        *msg_last;    /* last message in the queue */
   76         unsigned long     msg_cbytes;   /* number of bytes in use on queue */
   77         unsigned long     msg_qnum;     /* number of msgs in the queue */
   78         unsigned long     msg_qbytes;   /* max # of bytes on the queue */
   79         pid_t             msg_lspid;    /* pid of last msgsnd() */
   80         pid_t             msg_lrpid;    /* pid of last msgrcv() */
   81         time_t            msg_stime;    /* time of last msgsnd() */
   82         long              msg_pad1;
   83         time_t            msg_rtime;    /* time of last msgrcv() */
   84         long              msg_pad2;
   85         time_t            msg_ctime;    /* time of last msgctl() */
   86         long              msg_pad3;
   87         long              msg_pad4[4];
   88 };
   89 #endif
   90 
   91 struct msg {
   92         struct msg      *msg_next;      /* next msg in the chain */
   93         long            msg_type;       /* type of this message */
   94                                         /* >0 -> type of this message */
   95                                         /* 0 -> free header */
   96         unsigned short  msg_ts;         /* size of this message */
   97         short           msg_spot;       /* location of start of msg in buffer */
   98 };
   99 
  100 /*
  101  * Structure describing a message.  The SVID doesn't suggest any
  102  * particular name for this structure.  There is a reference in the
  103  * msgop man page that reads "The structure mymsg is an example of what
  104  * this user defined buffer might look like, and includes the following
  105  * members:".  This sentence is followed by two lines equivalent
  106  * to the mtype and mtext field declarations below.  It isn't clear
  107  * if "mymsg" refers to the naem of the structure type or the name of an
  108  * instance of the structure...
  109  */
  110 struct mymsg {
  111         long    mtype;          /* message type (+ve integer) */
  112         char    mtext[1];       /* message body */
  113 };
  114 
  115 
  116 #ifdef _KERNEL
  117 /*
  118  * Based on the configuration parameters described in an SVR2 (yes, two)
  119  * config(1m) man page.
  120  *
  121  * Each message is broken up and stored in segments that are msgssz bytes
  122  * long.  For efficiency reasons, this should be a power of two.  Also,
  123  * it doesn't make sense if it is less than 8 or greater than about 256.
  124  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
  125  * two between 8 and 1024 inclusive (and panic's if it isn't).
  126  */
  127 struct msginfo {
  128         int     msgmax,         /* max chars in a message */
  129                 msgmni,         /* max message queue identifiers */
  130                 msgmnb,         /* max chars in a queue */
  131                 msgtql,         /* max messages in system */
  132                 msgssz,         /* size of a message segment (see notes above) */
  133                 msgseg;         /* number of message segments */
  134 };
  135 #ifdef SYSVMSG
  136 extern struct msginfo   msginfo;
  137 #endif
  138 
  139 struct msg_sysctl_info {
  140         struct msginfo msginfo;
  141         struct msqid_ds msgids[1];
  142 };
  143 
  144 #ifndef MSGSSZ
  145 #define MSGSSZ  8               /* Each segment must be 2^N long */
  146 #endif
  147 #ifndef MSGSEG
  148 #define MSGSEG  2048            /* must be less than 32767 */
  149 #endif
  150 #undef MSGMAX                   /* ALWAYS compute MSGMAX! */
  151 #define MSGMAX  (MSGSSZ*MSGSEG)
  152 #ifndef MSGMNB
  153 #define MSGMNB  2048            /* max # of bytes in a queue */
  154 #endif
  155 #ifndef MSGMNI
  156 #define MSGMNI  40
  157 #endif
  158 #ifndef MSGTQL
  159 #define MSGTQL  40
  160 #endif
  161 
  162 /*
  163  * macros to convert between msqid_ds's and msqid's.
  164  * (specific to this implementation)
  165  */
  166 #define MSQID(ix,ds)    ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
  167 #define MSQID_IX(id)    ((id) & 0xffff)
  168 #define MSQID_SEQ(id)   (((id) >> 16) & 0xffff)
  169 #endif
  170 
  171 /*
  172  * The rest of this file is specific to this particular implementation.
  173  */
  174 
  175 #ifdef _KERNEL
  176 
  177 /*
  178  * Stuff allocated in machdep.h
  179  */
  180 struct msgmap {
  181         short   next;           /* next segment in buffer */
  182                                 /* -1 -> available */
  183                                 /* 0..(MSGSEG-1) -> index of next segment */
  184 };
  185 
  186 extern char *msgpool;           /* MSGMAX byte long msg buffer pool */
  187 extern struct msgmap *msgmaps;  /* MSGSEG msgmap structures */
  188 extern struct msg *msghdrs;     /* MSGTQL msg headers */
  189 extern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
  190 
  191 #define MSG_LOCKED      01000   /* Is this msqid_ds locked? */
  192 
  193 #endif
  194 
  195 #ifndef _KERNEL
  196 #include <sys/cdefs.h>
  197 
  198 __BEGIN_DECLS
  199 int msgctl(int, int, struct msqid_ds *);
  200 int msgget(key_t, int);
  201 int msgsnd(int, const void *, size_t, int);
  202 int msgrcv(int, void *, size_t, long, int);
  203 __END_DECLS
  204 #else
  205 struct proc;
  206 
  207 void    msginit(void);
  208 int     msgctl1(struct proc *, int, int, caddr_t,
  209             int (*)(const void *, void *, size_t),
  210             int (*)(const void *, void *, size_t));
  211 #endif /* !_KERNEL */
  212 
  213 #endif /* !_SYS_MSG_H_ */

/* [<][>][^][v][top][bottom][index][help] */