1 /* 2 * Copyright 1993 Network Computing Devices, Inc. 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and 5 * its documentation for any purpose is hereby granted without fee, provided 6 * that the above copyright notice appear in all copies and that both that 7 * copyright notice and this permission notice appear in supporting 8 * documentation, and that the name Network Computing Devices, Inc. not be 9 * used in advertising or publicity pertaining to distribution of this 10 * software without specific, written prior permission. 11 * 12 * THIS SOFTWARE IS PROVIDED `AS-IS'. NETWORK COMPUTING DEVICES, INC., 13 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT 14 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK 16 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING 17 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, 18 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF 19 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN 20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * 22 * $NCDId: @(#)osdep.h,v 1.3 1994/05/27 03:10:46 greg Exp $ 23 */ 24 /*********************************************************** 25 Some portions derived from: 26 27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, 28 and the Massachusetts Institute of Technology, Cambridge, Massachusetts. 29 30 All Rights Reserved 31 32 Permission to use, copy, modify, and distribute this software and its 33 documentation for any purpose and without fee is hereby granted, 34 provided that the above copyright notice appear in all copies and that 35 both that copyright notice and this permission notice appear in 36 supporting documentation, and that the names of Digital or MIT not be 37 used in advertising or publicity pertaining to distribution of the 38 software without specific, written prior permission. 39 40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 46 SOFTWARE. 47 48 ******************************************************************/ 49 50 #ifdef AMOEBA 51 #include <stddef.h> 52 #include <amoeba.h> 53 #include <stdio.h> 54 #include <assert.h> 55 #include <semaphore.h> 56 #include <circbuf.h> 57 #include <exception.h> 58 #include <vc.h> 59 #include <fault.h> 60 #include <module/signals.h> 61 #include <server/x11/Xamoeba.h> 62 63 #include "X.h" 64 #include "misc.h" 65 #include "dixstruct.h" 66 #endif /* AMOEBA */ 67 68 #define BOTIMEOUT 200 /* in milliseconds */ 69 #define BUFSIZE 4096 70 #define BUFWATERMARK 8192 71 #ifndef MAXBUFSIZE 72 #define MAXBUFSIZE (1 << 22) 73 #endif 74 75 #ifndef sgi /* SGI defines OPEN_MAX in a useless way */ 76 #ifndef X_NOT_POSIX 77 #ifdef _POSIX_SOURCE 78 #include <limits.h> 79 #else 80 #define _POSIX_SOURCE 81 #include <limits.h> 82 #undef _POSIX_SOURCE 83 #endif 84 #endif 85 #endif 86 87 #ifdef AMOEBA 88 /* 89 * Some fundamental constants 90 */ 91 #define CONNECTOR_STACK 4000 /* stack for connector task */ 92 #define DEVREADER_STACK 4000 /* stack for device reader */ 93 #define CREATOR_STACK 4000 /* stack for connection creator */ 94 #define MAXTASKS 100 /* Maximum # clients */ 95 96 /* 97 * OsComm status bits 98 */ 99 #define CONN_KILLED 01 /* Connection being closed */ 100 #define REQ_PUSHBACK 02 /* Request pushed back */ 101 #define IGNORE 04 /* True if client ignored */ 102 #endif /* AMOEBA */ 103 104 /* 105 * Just to prevent confusion, I ifdef-ed it out 106 */ 107 #ifndef AMOEBA 108 109 #ifndef OPEN_MAX 110 #ifdef SVR4 111 #define OPEN_MAX 128 112 #else 113 #include <sys/param.h> 114 #ifndef OPEN_MAX 115 #if defined(NOFILE) && !defined(NOFILES_MAX) 116 #define OPEN_MAX NOFILE 117 #else 118 #if defined(_POSIX_OPEN_MAX) && !defined(SCO) 119 #define OPEN_MAX _POSIX_OPEN_MAX 120 #else 121 #define OPEN_MAX NOFILES_MAX 122 #endif 123 #endif 124 #endif 125 #endif 126 #endif 127 128 #if OPEN_MAX <= 128 129 #define MAXSOCKS (OPEN_MAX - 1) 130 #else 131 #define MAXSOCKS 128 132 #endif 133 134 #ifndef NULL 135 #define NULL 0 136 #endif 137 138 #ifndef _MINIX 139 140 #define mskcnt ((MAXSOCKS + 31) / 32) /* size of bit array */ 141 142 #if (mskcnt==1) 143 #define BITMASK(i) (1 << (i)) 144 #define MASKIDX(i) 0 145 #endif 146 #if (mskcnt>1) 147 #define BITMASK(i) (1 << ((i) & 31)) 148 #define MASKIDX(i) ((i) >> 5) 149 #endif 150 151 #define MASKWORD(buf, i) buf[MASKIDX(i)] 152 #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) 153 #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) 154 #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) 155 156 #if (mskcnt==1) 157 #define COPYBITS(src, dst) dst[0] = src[0] 158 #define CLEARBITS(buf) buf[0] = 0 159 #define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0]) 160 #define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0]) 161 #define UNSETBITS(dst, b1) (dst[0] &= ~b1[0]) 162 #define ANYSET(src) (src[0]) 163 #endif 164 #if (mskcnt==2) 165 #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1] 166 #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0 167 #define MASKANDSETBITS(dst, b1, b2) \ 168 dst[0] = (b1[0] & b2[0]);\ 169 dst[1] = (b1[1] & b2[1]) 170 #define ORBITS(dst, b1, b2) \ 171 dst[0] = (b1[0] | b2[0]);\ 172 dst[1] = (b1[1] | b2[1]) 173 #define UNSETBITS(dst, b1) \ 174 dst[0] &= ~b1[0]; \ 175 dst[1] &= ~b1[1] 176 #define ANYSET(src) (src[0] || src[1]) 177 #endif 178 #if (mskcnt==3) 179 #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; 180 #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0 181 #define MASKANDSETBITS(dst, b1, b2) \ 182 dst[0] = (b1[0] & b2[0]);\ 183 dst[1] = (b1[1] & b2[1]);\ 184 dst[2] = (b1[2] & b2[2]) 185 #define ORBITS(dst, b1, b2) \ 186 dst[0] = (b1[0] | b2[0]);\ 187 dst[1] = (b1[1] | b2[1]);\ 188 dst[2] = (b1[2] | b2[2]) 189 #define UNSETBITS(dst, b1) \ 190 dst[0] &= ~b1[0]; \ 191 dst[1] &= ~b1[1]; \ 192 dst[2] &= ~b1[2] 193 #define ANYSET(src) (src[0] || src[1] || src[2]) 194 #endif 195 #if (mskcnt==4) 196 #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2];\ 197 dst[3] = src[3] 198 #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0 199 #define MASKANDSETBITS(dst, b1, b2) \ 200 dst[0] = (b1[0] & b2[0]);\ 201 dst[1] = (b1[1] & b2[1]);\ 202 dst[2] = (b1[2] & b2[2]);\ 203 dst[3] = (b1[3] & b2[3]) 204 #define ORBITS(dst, b1, b2) \ 205 dst[0] = (b1[0] | b2[0]);\ 206 dst[1] = (b1[1] | b2[1]);\ 207 dst[2] = (b1[2] | b2[2]);\ 208 dst[3] = (b1[3] | b2[3]) 209 #define UNSETBITS(dst, b1) \ 210 dst[0] &= ~b1[0]; \ 211 dst[1] &= ~b1[1]; \ 212 dst[2] &= ~b1[2]; \ 213 dst[3] &= ~b1[3] 214 #define ANYSET(src) (src[0] || src[1] || src[2] || src[3]) 215 #endif 216 217 #if (mskcnt>4) 218 #define COPYBITS(src, dst) bcopy((caddr_t) src, (caddr_t) dst,\ 219 mskcnt*sizeof(long)) 220 #define CLEARBITS(buf) bzero((caddr_t) buf, mskcnt*sizeof(long)) 221 #define MASKANDSETBITS(dst, b1, b2) \ 222 { int cri; \ 223 for (cri=mskcnt; --cri>=0; ) \ 224 dst[cri] = (b1[cri] & b2[cri]); } 225 #define ORBITS(dst, b1, b2) \ 226 { int cri; \ 227 for (cri=mskcnt; --cri>=0; ) \ 228 dst[cri] = (b1[cri] | b2[cri]); } 229 #define UNSETBITS(dst, b1) \ 230 { int cri; \ 231 for (cri=mskcnt; --cri>=0; ) \ 232 dst[cri] &= ~b1[cri]; } 233 #if (mskcnt==8) 234 #define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || \ 235 src[4] || src[5] || src[6] || src[7]) 236 #endif 237 /* 238 * If mskcnt>4 and not 8, then ANYSET is a routine defined in WaitFor.c. 239 * 240 * #define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...) 241 */ 242 #endif 243 244 #endif /* !_MINIX */ 245 246 typedef struct _connectionInput { 247 struct _connectionInput *next; 248 char *buffer; /* contains current client input */ 249 char *bufptr; /* pointer to current start of data */ 250 int bufcnt; /* count of bytes in buffer */ 251 int lenLastReq; 252 int size; 253 } ConnectionInput, *ConnectionInputPtr; 254 255 typedef struct _connectionOutput { 256 struct _connectionOutput *next; 257 int size; 258 unsigned char *buf; 259 int count; 260 } ConnectionOutput, *ConnectionOutputPtr; 261 262 #endif /* AMOEBA */ 263 264 #ifdef AMOEBA 265 typedef struct _amTcpIpComm { 266 capability cap; /* connection capability */ 267 struct circbuf *cb; /* input buffer */ 268 signum signal; /* signal to kill reader thread */ 269 } AmTcpIpCommRec; 270 #endif 271 272 typedef struct _osComm { 273 #ifndef AMOEBA 274 int fd; 275 ConnectionInputPtr input; 276 ConnectionOutputPtr output; 277 #ifdef _MINIX 278 ConnectionInputPtr inputFake; 279 ConnectionOutputPtr outputNext; 280 #endif 281 #else 282 int family; /* connection family */ 283 int number; /* connection number */ 284 char status; /* connection status */ 285 int size; /* input buffer size */ 286 char *buffer; /* input buffer */ 287 union { 288 struct vc *vc; /* virtual circuit */ 289 AmTcpIpCommRec tcp; /* TCP/IP connection info */ 290 } conn; 291 #endif 292 AuID auth_id; /* authorization id */ 293 long conn_time; /* timestamp if not established, else 0 */ 294 } OsCommRec, *OsCommPtr; 295 296 #ifdef AMOEBA 297 #ifdef XDEBUG 298 extern Bool amDebug; /* amoeba debug toggle */ 299 #endif /* XDEBUG */ 300 extern char *AuServerHostName; /* audio server host name */ 301 extern char *AuTcpServerName; /* TCP/IP server name */ 302 extern ClientPtr grabClient; /* for grabs */ 303 extern ClientPtr Clients[MAXTASKS]; /* All clients */ 304 extern int maxClient; /* Highest client# */ 305 extern int nNewConns; /* # of new clients */ 306 307 extern semaphore init_sema; /* Initialize semaphore */ 308 #endif /* AMOEBA */ 309