williamr@2: /* $FreeBSD: src/sys/sys/msg.h,v 1.20 2005/01/07 02:29:23 imp Exp $ */ williamr@2: /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ williamr@2: williamr@2: /*- williamr@2: * SVID compatible msg.h file williamr@2: * williamr@2: * Author: Daniel Boulet williamr@2: * williamr@2: *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved. williamr@2: * Copyright 1993 Daniel Boulet and RTMX Inc. williamr@2: * williamr@2: * This system call was implemented by Daniel Boulet under contract from RTMX. williamr@2: * williamr@2: * Redistribution and use in source forms, with and without modification, williamr@2: * are permitted provided that this entire comment appears intact. williamr@2: * williamr@2: * Redistribution in binary form may occur without any restrictions. williamr@2: * Obviously, it would be nice if you gave credit where credit is due williamr@2: * but requiring it would be too onerous. williamr@2: * williamr@2: * This software is provided ``AS IS'' without any warranties of any kind. williamr@2: */ williamr@2: williamr@2: #ifndef _SYS_MSG_H_ williamr@2: #define _SYS_MSG_H_ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: /* williamr@2: * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct williamr@2: * are as defined by the SV API Intel 386 Processor Supplement. williamr@2: */ williamr@2: williamr@2: #define MSG_NOERROR 010000 /* don't complain about too long msgs */ williamr@2: williamr@2: typedef unsigned long msglen_t; williamr@2: typedef unsigned long msgqnum_t; williamr@2: williamr@2: #ifndef _PID_T_DECLARED williamr@2: typedef __pid_t pid_t; williamr@2: #define _PID_T_DECLARED williamr@2: #endif williamr@2: williamr@2: #ifndef _SIZE_T_DECLARED williamr@2: typedef __size_t size_t; williamr@2: #define _SIZE_T_DECLARED williamr@2: #endif williamr@2: williamr@2: #ifndef _SSIZE_T_DECLARED williamr@2: typedef __ssize_t ssize_t; williamr@2: #define _SSIZE_T_DECLARED williamr@2: #endif williamr@2: williamr@2: #ifndef _TIME_T_DECLARED williamr@2: typedef __time_t time_t; williamr@2: #define _TIME_T_DECLARED williamr@2: #endif williamr@2: williamr@2: /* williamr@2: * XXX there seems to be no prefix reserved for this header, so the name williamr@2: * "msg" in "struct msg" and the names of all of the nonstandard members williamr@2: * (mainly "msg_pad*) are namespace pollution. williamr@2: */ williamr@2: williamr@2: struct msqid_ds { williamr@2: struct ipc_perm msg_perm; /* msg queue permission bits */ williamr@2: struct msg *msg_first; /* first message in the queue */ williamr@2: struct msg *msg_last; /* last message in the queue */ williamr@2: msglen_t msg_cbytes; /* number of bytes in use on the queue */ williamr@2: msgqnum_t msg_qnum; /* number of msgs in the queue */ williamr@2: msglen_t msg_qbytes; /* max # of bytes on the queue */ williamr@2: pid_t msg_lspid; /* pid of last msgsnd() */ williamr@2: pid_t msg_lrpid; /* pid of last msgrcv() */ williamr@2: time_t msg_stime; /* time of last msgsnd() */ williamr@2: long msg_pad1; williamr@2: time_t msg_rtime; /* time of last msgrcv() */ williamr@2: long msg_pad2; williamr@2: time_t msg_ctime; /* time of last msgctl() */ williamr@2: long msg_pad3; williamr@2: long msg_pad4[4]; williamr@2: }; williamr@2: williamr@2: #if __BSD_VISIBLE williamr@2: /* williamr@2: * Structure describing a message. The SVID doesn't suggest any williamr@2: * particular name for this structure. There is a reference in the williamr@2: * msgop man page that reads "The structure mymsg is an example of what williamr@2: * this user defined buffer might look like, and includes the following williamr@2: * members:". This sentence is followed by two lines equivalent williamr@2: * to the mtype and mtext field declarations below. It isn't clear williamr@2: * if "mymsg" refers to the name of the structure type or the name of an williamr@2: * instance of the structure... williamr@2: */ williamr@2: struct mymsg { williamr@2: long mtype; /* message type (+ve integer) */ williamr@2: char mtext[1]; /* message body */ williamr@2: }; williamr@2: #endif williamr@2: williamr@2: #ifdef _KERNEL williamr@2: williamr@2: struct msg { williamr@2: struct msg *msg_next; /* next msg in the chain */ williamr@2: long msg_type; /* type of this message */ williamr@2: /* >0 -> type of this message */ williamr@2: /* 0 -> free header */ williamr@2: u_short msg_ts; /* size of this message */ williamr@2: short msg_spot; /* location of start of msg in buffer */ williamr@2: struct label *label; /* MAC Framework label */ williamr@2: }; williamr@2: williamr@2: /* williamr@2: * Based on the configuration parameters described in an SVR2 (yes, two) williamr@2: * config(1m) man page. williamr@2: * williamr@2: * Each message is broken up and stored in segments that are msgssz bytes williamr@2: * long. For efficiency reasons, this should be a power of two. Also, williamr@2: * it doesn't make sense if it is less than 8 or greater than about 256. williamr@2: * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of williamr@2: * two between 8 and 1024 inclusive (and panic's if it isn't). williamr@2: */ williamr@2: struct msginfo { williamr@2: int msgmax, /* max chars in a message */ williamr@2: msgmni, /* max message queue identifiers */ williamr@2: msgmnb, /* max chars in a queue */ williamr@2: msgtql, /* max messages in system */ williamr@2: msgssz, /* size of a message segment (see notes above) */ williamr@2: msgseg; /* number of message segments */ williamr@2: }; williamr@2: extern struct msginfo msginfo; williamr@2: williamr@2: /* williamr@2: * Kernel wrapper for the user-level structure. williamr@2: */ williamr@2: struct msqid_kernel { williamr@2: /* williamr@2: * Data structure exposed to user space. williamr@2: */ williamr@2: struct msqid_ds u; williamr@2: williamr@2: /* williamr@2: * Kernel-private components of the message queue. williamr@2: */ williamr@2: struct label *label; /* MAC label */ williamr@2: }; williamr@2: williamr@2: #else /* !_KERNEL */ williamr@2: williamr@2: /* Template for struct to be used as argument for `msgsnd' and `msgrcv'. */ williamr@2: struct msgbuf williamr@2: { williamr@2: long int mtype; /* type of received/sent message */ williamr@2: char mtext[1]; /* text of the message */ williamr@2: }; williamr@2: williamr@2: // FUNCTION PROTOTYPES williamr@2: williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: williamr@2: williamr@2: // CLASS/STRUCT/FUNCTION DECLARATION williamr@2: __BEGIN_DECLS williamr@2: williamr@2: /* williamr@2: * Get the message queue identifier using the IPC key generated by ftok. williamr@2: */ williamr@2: williamr@2: IMPORT_C int msgget(key_t key, int msgflg); williamr@2: williamr@2: /* williamr@2: * Used to send a message to the queue associated with the message identifier specified by msqid. williamr@2: */ williamr@2: williamr@2: IMPORT_C int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); williamr@2: williamr@2: /* williamr@2: * Reads a message from the queue associated with the message queue identifier. williamr@2: */ williamr@2: williamr@2: IMPORT_C ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg); williamr@2: williamr@2: /* williamr@2: * Provides an interface to control message queue and control operations as specified by cmd. williamr@2: */ williamr@2: williamr@2: IMPORT_C int msgctl(int msqid, int cmd, struct msqid_ds* buf); williamr@2: williamr@2: williamr@2: __END_DECLS williamr@2: williamr@2: #endif /* !_KERNEL */ williamr@2: williamr@2: #endif // _SYS_MSG_H_ williamr@2: williamr@2: // End of File