msg.h revision 50477
150477Speter/* $FreeBSD: head/sys/sys/msg.h 50477 1999-08-28 01:08:13Z peter $ */ 22729Sdfr/* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ 32729Sdfr 42729Sdfr/* 52729Sdfr * SVID compatible msg.h file 62729Sdfr * 72729Sdfr * Author: Daniel Boulet 82729Sdfr * 92729Sdfr * Copyright 1993 Daniel Boulet and RTMX Inc. 102729Sdfr * 112729Sdfr * This system call was implemented by Daniel Boulet under contract from RTMX. 122729Sdfr * 132729Sdfr * Redistribution and use in source forms, with and without modification, 142729Sdfr * are permitted provided that this entire comment appears intact. 152729Sdfr * 162729Sdfr * Redistribution in binary form may occur without any restrictions. 172729Sdfr * Obviously, it would be nice if you gave credit where credit is due 182729Sdfr * but requiring it would be too onerous. 192729Sdfr * 202729Sdfr * This software is provided ``AS IS'' without any warranties of any kind. 212729Sdfr */ 222729Sdfr 232729Sdfr#ifndef _SYS_MSG_H_ 242729Sdfr#define _SYS_MSG_H_ 252729Sdfr 262729Sdfr#include <sys/ipc.h> 272729Sdfr 282729Sdfr/* 292729Sdfr * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct 302729Sdfr * are as defined by the SV API Intel 386 Processor Supplement. 312729Sdfr */ 322729Sdfr 332729Sdfr#define MSG_NOERROR 010000 /* don't complain about too long msgs */ 342729Sdfr 352729Sdfrstruct msqid_ds { 362729Sdfr struct ipc_perm msg_perm; /* msg queue permission bits */ 372729Sdfr struct msg *msg_first; /* first message in the queue */ 382729Sdfr struct msg *msg_last; /* last message in the queue */ 392729Sdfr u_long msg_cbytes; /* number of bytes in use on the queue */ 402729Sdfr u_long msg_qnum; /* number of msgs in the queue */ 412729Sdfr u_long msg_qbytes; /* max # of bytes on the queue */ 422729Sdfr pid_t msg_lspid; /* pid of last msgsnd() */ 432729Sdfr pid_t msg_lrpid; /* pid of last msgrcv() */ 442729Sdfr time_t msg_stime; /* time of last msgsnd() */ 452729Sdfr long msg_pad1; 462729Sdfr time_t msg_rtime; /* time of last msgrcv() */ 472729Sdfr long msg_pad2; 482729Sdfr time_t msg_ctime; /* time of last msgctl() */ 492729Sdfr long msg_pad3; 502729Sdfr long msg_pad4[4]; 512729Sdfr}; 522729Sdfr 532729Sdfrstruct msg { 542729Sdfr struct msg *msg_next; /* next msg in the chain */ 552729Sdfr long msg_type; /* type of this message */ 562729Sdfr /* >0 -> type of this message */ 572729Sdfr /* 0 -> free header */ 582729Sdfr u_short msg_ts; /* size of this message */ 592729Sdfr short msg_spot; /* location of start of msg in buffer */ 602729Sdfr}; 612729Sdfr 622729Sdfr/* 632729Sdfr * Structure describing a message. The SVID doesn't suggest any 642729Sdfr * particular name for this structure. There is a reference in the 652729Sdfr * msgop man page that reads "The structure mymsg is an example of what 662729Sdfr * this user defined buffer might look like, and includes the following 672729Sdfr * members:". This sentence is followed by two lines equivalent 682729Sdfr * to the mtype and mtext field declarations below. It isn't clear 692729Sdfr * if "mymsg" refers to the naem of the structure type or the name of an 702729Sdfr * instance of the structure... 712729Sdfr */ 722729Sdfrstruct mymsg { 732729Sdfr long mtype; /* message type (+ve integer) */ 742729Sdfr char mtext[1]; /* message body */ 752729Sdfr}; 762729Sdfr 772729Sdfr/* 782729Sdfr * Based on the configuration parameters described in an SVR2 (yes, two) 792729Sdfr * config(1m) man page. 802729Sdfr * 812729Sdfr * Each message is broken up and stored in segments that are msgssz bytes 822729Sdfr * long. For efficiency reasons, this should be a power of two. Also, 832729Sdfr * it doesn't make sense if it is less than 8 or greater than about 256. 842729Sdfr * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of 852729Sdfr * two between 8 and 1024 inclusive (and panic's if it isn't). 862729Sdfr */ 872729Sdfrstruct msginfo { 882729Sdfr int msgmax, /* max chars in a message */ 892729Sdfr msgmni, /* max message queue identifiers */ 902729Sdfr msgmnb, /* max chars in a queue */ 912729Sdfr msgtql, /* max messages in system */ 922729Sdfr msgssz, /* size of a message segment (see notes above) */ 932729Sdfr msgseg; /* number of message segments */ 942729Sdfr}; 952836Sdg#ifdef KERNEL 962836Sdgextern struct msginfo msginfo; 972729Sdfr 982729Sdfr#ifndef MSGSSZ 992729Sdfr#define MSGSSZ 8 /* Each segment must be 2^N long */ 1002729Sdfr#endif 1012729Sdfr#ifndef MSGSEG 1022729Sdfr#define MSGSEG 2048 /* must be less than 32767 */ 1032729Sdfr#endif 1042729Sdfr#define MSGMAX (MSGSSZ*MSGSEG) 1052729Sdfr#ifndef MSGMNB 1062729Sdfr#define MSGMNB 2048 /* max # of bytes in a queue */ 1072729Sdfr#endif 1082729Sdfr#ifndef MSGMNI 1092729Sdfr#define MSGMNI 40 1102729Sdfr#endif 1112729Sdfr#ifndef MSGTQL 1122729Sdfr#define MSGTQL 40 1132729Sdfr#endif 1142729Sdfr 1152729Sdfr/* 1162729Sdfr * macros to convert between msqid_ds's and msqid's. 1172729Sdfr * (specific to this implementation) 1182729Sdfr */ 1192729Sdfr#define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000)) 1202729Sdfr#define MSQID_IX(id) ((id) & 0xffff) 1212729Sdfr#define MSQID_SEQ(id) (((id) >> 16) & 0xffff) 1222729Sdfr 1232729Sdfr/* 1242729Sdfr * The rest of this file is specific to this particular implementation. 1252729Sdfr */ 1262729Sdfr 1272729Sdfr 1282729Sdfr/* 1292729Sdfr * Stuff allocated in machdep.h 1302729Sdfr */ 1312729Sdfrstruct msgmap { 1322729Sdfr short next; /* next segment in buffer */ 1332729Sdfr /* -1 -> available */ 1342729Sdfr /* 0..(MSGSEG-1) -> index of next segment */ 1352729Sdfr}; 1362729Sdfr 1379759Sbdeextern char *msgpool; /* MSGMAX byte long msg buffer pool */ 1389759Sbdeextern struct msgmap *msgmaps; /* MSGSEG msgmap structures */ 1399759Sbdeextern struct msg *msghdrs; /* MSGTQL msg headers */ 1409759Sbdeextern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */ 1412729Sdfr 1422729Sdfr#define MSG_LOCKED 01000 /* Is this msqid_ds locked? */ 1432729Sdfr 1442836Sdg#endif /* KERNEL */ 1452729Sdfr 1462729Sdfr#ifndef KERNEL 1472729Sdfr#include <sys/cdefs.h> 1482729Sdfr 1492729Sdfr__BEGIN_DECLS 1502729Sdfrint msgsys __P((int, ...)); 1512729Sdfrint msgctl __P((int, int, struct msqid_ds *)); 1522729Sdfrint msgget __P((key_t, int)); 1532729Sdfrint msgsnd __P((int, void *, size_t, int)); 1542729Sdfrint msgrcv __P((int, void*, size_t, long, int)); 1552729Sdfr__END_DECLS 1562729Sdfr#endif /* !KERNEL */ 1572729Sdfr 1582729Sdfr#endif /* !_SYS_MSG_H_ */ 159