os.h revision 05b261ec
1/*********************************************************** 2 3Copyright 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 27 28 All Rights Reserved 29 30Permission to use, copy, modify, and distribute this software and its 31documentation for any purpose and without fee is hereby granted, 32provided that the above copyright notice appear in all copies and that 33both that copyright notice and this permission notice appear in 34supporting documentation, and that the name of Digital not be 35used in advertising or publicity pertaining to distribution of the 36software without specific, written prior permission. 37 38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 44SOFTWARE. 45 46******************************************************************/ 47 48 49#ifndef OS_H 50#define OS_H 51 52#include "misc.h" 53#define ALLOCATE_LOCAL_FALLBACK(_size) Xalloc((unsigned long)(_size)) 54#define DEALLOCATE_LOCAL_FALLBACK(_ptr) Xfree((pointer)(_ptr)) 55#include <X11/Xalloca.h> 56#include <stdarg.h> 57 58#define NullFID ((FID) 0) 59 60#define SCREEN_SAVER_ON 0 61#define SCREEN_SAVER_OFF 1 62#define SCREEN_SAVER_FORCER 2 63#define SCREEN_SAVER_CYCLE 3 64 65#ifndef MAX_REQUEST_SIZE 66#define MAX_REQUEST_SIZE 65535 67#endif 68#ifndef MAX_BIG_REQUEST_SIZE 69#define MAX_BIG_REQUEST_SIZE 4194303 70#endif 71 72typedef pointer FID; 73typedef struct _FontPathRec *FontPathPtr; 74typedef struct _NewClientRec *NewClientPtr; 75 76#ifndef xalloc 77#define xnfalloc(size) XNFalloc((unsigned long)(size)) 78#define xnfcalloc(_num, _size) XNFcalloc((unsigned long)(_num)*(unsigned long)(_size)) 79#define xnfrealloc(ptr, size) XNFrealloc((pointer)(ptr), (unsigned long)(size)) 80 81#define xalloc(size) Xalloc((unsigned long)(size)) 82#define xcalloc(_num, _size) Xcalloc((unsigned long)(_num)*(unsigned long)(_size)) 83#define xrealloc(ptr, size) Xrealloc((pointer)(ptr), (unsigned long)(size)) 84#define xfree(ptr) Xfree((pointer)(ptr)) 85#define xstrdup(s) Xstrdup(s) 86#define xnfstrdup(s) XNFstrdup(s) 87#endif 88 89#include <stdio.h> 90#include <stdarg.h> 91 92/* have to put $(SIGNAL_DEFINES) in DEFINES in Imakefile to get this right */ 93#ifdef SIGNALRETURNSINT 94#define SIGVAL int 95#else 96#define SIGVAL void 97#endif 98 99extern Bool OsDelayInitColors; 100extern void (*OsVendorVErrorFProc)(const char *, va_list args); 101 102extern int WaitForSomething( 103 int* /*pClientsReady*/ 104); 105 106extern int ReadRequestFromClient(ClientPtr /*client*/); 107 108extern Bool InsertFakeRequest( 109 ClientPtr /*client*/, 110 char* /*data*/, 111 int /*count*/); 112 113extern void ResetCurrentRequest(ClientPtr /*client*/); 114 115extern void FlushAllOutput(void); 116 117extern void FlushIfCriticalOutputPending(void); 118 119extern void SetCriticalOutputPending(void); 120 121extern int WriteToClient(ClientPtr /*who*/, int /*count*/, char* /*buf*/); 122 123extern void ResetOsBuffers(void); 124 125extern void InitConnectionLimits(void); 126 127extern void CreateWellKnownSockets(void); 128 129extern void ResetWellKnownSockets(void); 130 131extern void CloseWellKnownConnections(void); 132 133extern XID AuthorizationIDOfClient(ClientPtr /*client*/); 134 135extern char *ClientAuthorized( 136 ClientPtr /*client*/, 137 unsigned int /*proto_n*/, 138 char* /*auth_proto*/, 139 unsigned int /*string_n*/, 140 char* /*auth_string*/); 141 142extern Bool EstablishNewConnections( 143 ClientPtr /*clientUnused*/, 144 pointer /*closure*/); 145 146extern void CheckConnections(void); 147 148extern void CloseDownConnection(ClientPtr /*client*/); 149 150extern void AddGeneralSocket(int /*fd*/); 151 152extern void RemoveGeneralSocket(int /*fd*/); 153 154extern void AddEnabledDevice(int /*fd*/); 155 156extern void RemoveEnabledDevice(int /*fd*/); 157 158extern void OnlyListenToOneClient(ClientPtr /*client*/); 159 160extern void ListenToAllClients(void); 161 162extern void IgnoreClient(ClientPtr /*client*/); 163 164extern void AttendClient(ClientPtr /*client*/); 165 166extern void MakeClientGrabImpervious(ClientPtr /*client*/); 167 168extern void MakeClientGrabPervious(ClientPtr /*client*/); 169 170extern void AvailableClientInput(ClientPtr /* client */); 171 172extern CARD32 GetTimeInMillis(void); 173 174extern void AdjustWaitForDelay( 175 pointer /*waitTime*/, 176 unsigned long /*newdelay*/); 177 178typedef struct _OsTimerRec *OsTimerPtr; 179 180typedef CARD32 (*OsTimerCallback)( 181 OsTimerPtr /* timer */, 182 CARD32 /* time */, 183 pointer /* arg */); 184 185extern void TimerInit(void); 186 187extern Bool TimerForce(OsTimerPtr /* timer */); 188 189#define TimerAbsolute (1<<0) 190#define TimerForceOld (1<<1) 191 192extern OsTimerPtr TimerSet( 193 OsTimerPtr /* timer */, 194 int /* flags */, 195 CARD32 /* millis */, 196 OsTimerCallback /* func */, 197 pointer /* arg */); 198 199extern void TimerCheck(void); 200extern void TimerCancel(OsTimerPtr /* pTimer */); 201extern void TimerFree(OsTimerPtr /* pTimer */); 202 203extern void SetScreenSaverTimer(void); 204extern void FreeScreenSaverTimer(void); 205 206extern SIGVAL AutoResetServer(int /*sig*/); 207 208extern SIGVAL GiveUp(int /*sig*/); 209 210extern void UseMsg(void); 211 212extern void InitGlobals(void); 213 214extern void ProcessCommandLine(int /*argc*/, char* /*argv*/[]); 215 216extern int set_font_authorizations( 217 char ** /* authorizations */, 218 int * /*authlen */, 219 pointer /* client */); 220 221#ifndef _HAVE_XALLOC_DECLS 222#define _HAVE_XALLOC_DECLS 223extern pointer Xalloc(unsigned long /*amount*/); 224extern pointer Xcalloc(unsigned long /*amount*/); 225extern pointer Xrealloc(pointer /*ptr*/, unsigned long /*amount*/); 226extern void Xfree(pointer /*ptr*/); 227#endif 228 229extern pointer XNFalloc(unsigned long /*amount*/); 230extern pointer XNFcalloc(unsigned long /*amount*/); 231extern pointer XNFrealloc(pointer /*ptr*/, unsigned long /*amount*/); 232 233extern void OsInitAllocator(void); 234 235extern char *Xstrdup(const char *s); 236extern char *XNFstrdup(const char *s); 237extern char *Xprintf(const char *fmt, ...); 238extern char *Xvprintf(const char *fmt, va_list va); 239extern char *XNFprintf(const char *fmt, ...); 240extern char *XNFvprintf(const char *fmt, va_list va); 241 242typedef SIGVAL (*OsSigHandlerPtr)(int /* sig */); 243 244extern OsSigHandlerPtr OsSignal(int /* sig */, OsSigHandlerPtr /* handler */); 245 246extern int auditTrailLevel; 247 248#ifdef SERVER_LOCK 249extern void LockServer(void); 250extern void UnlockServer(void); 251#endif 252 253extern int OsLookupColor( 254 int /*screen*/, 255 char * /*name*/, 256 unsigned /*len*/, 257 unsigned short * /*pred*/, 258 unsigned short * /*pgreen*/, 259 unsigned short * /*pblue*/); 260 261extern void OsInit(void); 262 263extern void OsCleanup(Bool); 264 265extern void OsVendorFatalError(void); 266 267extern void OsVendorInit(void); 268 269extern int OsInitColors(void); 270 271void OsBlockSignals (void); 272 273void OsReleaseSignals (void); 274 275#if !defined(WIN32) 276extern int System(char *); 277extern pointer Popen(char *, char *); 278extern int Pclose(pointer); 279extern pointer Fopen(char *, char *); 280extern int Fclose(pointer); 281#else 282#define System(a) system(a) 283#define Popen(a,b) popen(a,b) 284#define Pclose(a) pclose(a) 285#define Fopen(a,b) fopen(a,b) 286#define Fclose(a) fclose(a) 287#endif 288 289extern void CheckUserParameters(int argc, char **argv, char **envp); 290extern void CheckUserAuthorization(void); 291 292extern int AddHost( 293 ClientPtr /*client*/, 294 int /*family*/, 295 unsigned /*length*/, 296 pointer /*pAddr*/); 297 298extern Bool ForEachHostInFamily ( 299 int /*family*/, 300 Bool (* /*func*/ )( 301 unsigned char * /* addr */, 302 short /* len */, 303 pointer /* closure */), 304 pointer /*closure*/); 305 306extern int RemoveHost( 307 ClientPtr /*client*/, 308 int /*family*/, 309 unsigned /*length*/, 310 pointer /*pAddr*/); 311 312extern int GetHosts( 313 pointer * /*data*/, 314 int * /*pnHosts*/, 315 int * /*pLen*/, 316 BOOL * /*pEnabled*/); 317 318typedef struct sockaddr * sockaddrPtr; 319 320extern int InvalidHost(sockaddrPtr /*saddr*/, int /*len*/, ClientPtr client); 321 322extern int LocalClient(ClientPtr /* client */); 323 324extern int LocalClientCred(ClientPtr, int *, int *); 325 326extern int ChangeAccessControl(ClientPtr /*client*/, int /*fEnabled*/); 327 328extern int GetAccessControl(void); 329 330 331extern void AddLocalHosts(void); 332 333extern void ResetHosts(char *display); 334 335extern void EnableLocalHost(void); 336 337extern void DisableLocalHost(void); 338 339extern void AccessUsingXdmcp(void); 340 341extern void DefineSelf(int /*fd*/); 342 343extern void AugmentSelf(pointer /*from*/, int /*len*/); 344 345extern void InitAuthorization(char * /*filename*/); 346 347/* extern int LoadAuthorization(void); */ 348 349extern void RegisterAuthorizations(void); 350 351extern int AuthorizationFromID ( 352 XID id, 353 unsigned short *name_lenp, 354 char **namep, 355 unsigned short *data_lenp, 356 char **datap); 357 358extern XID CheckAuthorization( 359 unsigned int /*namelength*/, 360 char * /*name*/, 361 unsigned int /*datalength*/, 362 char * /*data*/, 363 ClientPtr /*client*/, 364 char ** /*reason*/ 365); 366 367extern void ResetAuthorization(void); 368 369extern int RemoveAuthorization ( 370 unsigned short name_length, 371 char *name, 372 unsigned short data_length, 373 char *data); 374 375extern int AddAuthorization( 376 unsigned int /*name_length*/, 377 char * /*name*/, 378 unsigned int /*data_length*/, 379 char * /*data*/); 380 381extern XID GenerateAuthorization( 382 unsigned int /* name_length */, 383 char * /* name */, 384 unsigned int /* data_length */, 385 char * /* data */, 386 unsigned int * /* data_length_return */, 387 char ** /* data_return */); 388 389#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS 390extern void ExpandCommandLine(int * /*pargc*/, char *** /*pargv*/); 391#endif 392 393extern void ddxInitGlobals(void); 394 395extern int ddxProcessArgument(int /*argc*/, char * /*argv*/ [], int /*i*/); 396 397extern void ddxUseMsg(void); 398 399/* int ReqLen(xReq *req, ClientPtr client) 400 * Given a pointer to a *complete* request, return its length in bytes. 401 * Note that if the request is a big request (as defined in the Big 402 * Requests extension), the macro lies by returning 4 less than the 403 * length that it actually occupies in the request buffer. This is so you 404 * can blindly compare the length with the various sz_<request> constants 405 * in Xproto.h without having to know/care about big requests. 406 */ 407#define ReqLen(_pxReq, _client) \ 408 ((_pxReq->length ? \ 409 (_client->swapped ? lswaps(_pxReq->length) : _pxReq->length) \ 410 : ((_client->swapped ? \ 411 lswapl(((CARD32*)_pxReq)[1]) : ((CARD32*)_pxReq)[1])-1) \ 412 ) << 2) 413 414/* otherReqTypePtr CastxReq(xReq *req, otherReqTypePtr) 415 * Cast the given request to one of type otherReqTypePtr to access 416 * fields beyond the length field. 417 */ 418#define CastxReq(_pxReq, otherReqTypePtr) \ 419 (_pxReq->length ? (otherReqTypePtr)_pxReq \ 420 : (otherReqTypePtr)(((CARD32*)_pxReq)+1)) 421 422/* stuff for SkippedRequestsCallback */ 423extern CallbackListPtr SkippedRequestsCallback; 424typedef struct { 425 xReqPtr req; 426 ClientPtr client; 427 int numskipped; 428} SkippedRequestInfoRec; 429 430/* stuff for ReplyCallback */ 431extern CallbackListPtr ReplyCallback; 432typedef struct { 433 ClientPtr client; 434 pointer replyData; 435 unsigned long dataLenBytes; 436 unsigned long bytesRemaining; 437 Bool startOfReply; 438} ReplyInfoRec; 439 440/* stuff for FlushCallback */ 441extern CallbackListPtr FlushCallback; 442 443extern void AbortDDX(void); 444extern void ddxGiveUp(void); 445extern int TimeSinceLastInputEvent(void); 446 447/* Logging. */ 448typedef enum _LogParameter { 449 XLOG_FLUSH, 450 XLOG_SYNC, 451 XLOG_VERBOSITY, 452 XLOG_FILE_VERBOSITY 453} LogParameter; 454 455/* Flags for log messages. */ 456typedef enum { 457 X_PROBED, /* Value was probed */ 458 X_CONFIG, /* Value was given in the config file */ 459 X_DEFAULT, /* Value is a default */ 460 X_CMDLINE, /* Value was given on the command line */ 461 X_NOTICE, /* Notice */ 462 X_ERROR, /* Error message */ 463 X_WARNING, /* Warning message */ 464 X_INFO, /* Informational message */ 465 X_NONE, /* No prefix */ 466 X_NOT_IMPLEMENTED, /* Not implemented */ 467 X_UNKNOWN = -1 /* unknown -- this must always be last */ 468} MessageType; 469 470/* XXX Need to check which GCC versions have the format(printf) attribute. */ 471#if defined(__GNUC__) && \ 472 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4))) 473#define _printf_attribute(a,b) __attribute((format(__printf__,a,b))) 474#else 475#define _printf_attribute(a,b) /**/ 476#endif 477 478extern const char *LogInit(const char *fname, const char *backup); 479extern void LogClose(void); 480extern Bool LogSetParameter(LogParameter param, int value); 481extern void LogVWrite(int verb, const char *f, va_list args); 482extern void LogWrite(int verb, const char *f, ...) _printf_attribute(2,3); 483extern void LogVMessageVerb(MessageType type, int verb, const char *format, 484 va_list args); 485extern void LogMessageVerb(MessageType type, int verb, const char *format, 486 ...) _printf_attribute(3,4); 487extern void LogMessage(MessageType type, const char *format, ...) 488 _printf_attribute(2,3); 489extern void FreeAuditTimer(void); 490extern void AuditF(const char *f, ...) _printf_attribute(1,2); 491extern void VAuditF(const char *f, va_list args); 492extern void FatalError(const char *f, ...) _printf_attribute(1,2) 493#if defined(__GNUC__) && \ 494 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4))) 495__attribute((noreturn)) 496#endif 497; 498 499#ifdef DEBUG 500#define DebugF ErrorF 501#else 502#define DebugF(x, ...) /* */ 503#endif 504 505extern void VErrorF(const char *f, va_list args); 506extern void ErrorF(const char *f, ...) _printf_attribute(1,2); 507extern void Error(char *str); 508extern void LogPrintMarkers(void); 509 510#endif /* OS_H */ 511