os.h revision de0a7c19
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#include <string.h>
92#include <strings.h>
93
94
95/* have to put $(SIGNAL_DEFINES) in DEFINES in Imakefile to get this right */
96#ifdef SIGNALRETURNSINT
97#define SIGVAL int
98#else
99#define SIGVAL void
100#endif
101
102extern Bool OsDelayInitColors;
103extern void (*OsVendorVErrorFProc)(const char *, va_list args);
104
105extern int WaitForSomething(
106    int* /*pClientsReady*/
107);
108
109extern int ReadRequestFromClient(ClientPtr /*client*/);
110
111extern Bool InsertFakeRequest(
112    ClientPtr /*client*/,
113    char* /*data*/,
114    int /*count*/);
115
116extern void ResetCurrentRequest(ClientPtr /*client*/);
117
118extern void FlushAllOutput(void);
119
120extern void FlushIfCriticalOutputPending(void);
121
122extern void SetCriticalOutputPending(void);
123
124extern int WriteToClient(ClientPtr /*who*/, int /*count*/, char* /*buf*/);
125
126extern void ResetOsBuffers(void);
127
128extern void InitConnectionLimits(void);
129
130extern void CreateWellKnownSockets(void);
131
132extern void ResetWellKnownSockets(void);
133
134extern void CloseWellKnownConnections(void);
135
136extern XID AuthorizationIDOfClient(ClientPtr /*client*/);
137
138extern char *ClientAuthorized(
139    ClientPtr /*client*/,
140    unsigned int /*proto_n*/,
141    char* /*auth_proto*/,
142    unsigned int /*string_n*/,
143    char* /*auth_string*/);
144
145extern Bool EstablishNewConnections(
146    ClientPtr /*clientUnused*/,
147    pointer /*closure*/);
148
149extern void CheckConnections(void);
150
151extern void CloseDownConnection(ClientPtr /*client*/);
152
153extern void AddGeneralSocket(int /*fd*/);
154
155extern void RemoveGeneralSocket(int /*fd*/);
156
157extern void AddEnabledDevice(int /*fd*/);
158
159extern void RemoveEnabledDevice(int /*fd*/);
160
161extern void OnlyListenToOneClient(ClientPtr /*client*/);
162
163extern void ListenToAllClients(void);
164
165extern void IgnoreClient(ClientPtr /*client*/);
166
167extern void AttendClient(ClientPtr /*client*/);
168
169extern void MakeClientGrabImpervious(ClientPtr /*client*/);
170
171extern void MakeClientGrabPervious(ClientPtr /*client*/);
172
173extern void AvailableClientInput(ClientPtr /* client */);
174
175extern CARD32 GetTimeInMillis(void);
176
177extern void AdjustWaitForDelay(
178    pointer /*waitTime*/,
179    unsigned long /*newdelay*/);
180
181typedef	struct _OsTimerRec *OsTimerPtr;
182
183typedef CARD32 (*OsTimerCallback)(
184    OsTimerPtr /* timer */,
185    CARD32 /* time */,
186    pointer /* arg */);
187
188extern void TimerInit(void);
189
190extern Bool TimerForce(OsTimerPtr /* timer */);
191
192#define TimerAbsolute (1<<0)
193#define TimerForceOld (1<<1)
194
195extern OsTimerPtr TimerSet(
196    OsTimerPtr /* timer */,
197    int /* flags */,
198    CARD32 /* millis */,
199    OsTimerCallback /* func */,
200    pointer /* arg */);
201
202extern void TimerCheck(void);
203extern void TimerCancel(OsTimerPtr /* pTimer */);
204extern void TimerFree(OsTimerPtr /* pTimer */);
205
206extern void SetScreenSaverTimer(void);
207extern void FreeScreenSaverTimer(void);
208
209extern SIGVAL AutoResetServer(int /*sig*/);
210
211extern SIGVAL GiveUp(int /*sig*/);
212
213extern void UseMsg(void);
214
215extern void InitGlobals(void);
216
217extern void ProcessCommandLine(int /*argc*/, char* /*argv*/[]);
218
219extern int set_font_authorizations(
220    char ** /* authorizations */,
221    int * /*authlen */,
222    pointer /* client */);
223
224#ifndef _HAVE_XALLOC_DECLS
225#define _HAVE_XALLOC_DECLS
226extern pointer Xalloc(unsigned long /*amount*/);
227extern pointer Xcalloc(unsigned long /*amount*/);
228extern pointer Xrealloc(pointer /*ptr*/, unsigned long /*amount*/);
229extern void Xfree(pointer /*ptr*/);
230#endif
231
232extern pointer XNFalloc(unsigned long /*amount*/);
233extern pointer XNFcalloc(unsigned long /*amount*/);
234extern pointer XNFrealloc(pointer /*ptr*/, unsigned long /*amount*/);
235
236extern void OsInitAllocator(void);
237
238extern char *Xstrdup(const char *s);
239extern char *XNFstrdup(const char *s);
240extern char *Xprintf(const char *fmt, ...);
241extern char *Xvprintf(const char *fmt, va_list va);
242extern char *XNFprintf(const char *fmt, ...);
243extern char *XNFvprintf(const char *fmt, va_list va);
244
245typedef SIGVAL (*OsSigHandlerPtr)(int /* sig */);
246
247extern OsSigHandlerPtr OsSignal(int /* sig */, OsSigHandlerPtr /* handler */);
248
249extern int auditTrailLevel;
250
251#ifdef SERVER_LOCK
252extern void LockServer(void);
253extern void UnlockServer(void);
254#endif
255
256extern int OsLookupColor(
257    int	/*screen*/,
258    char * /*name*/,
259    unsigned /*len*/,
260    unsigned short * /*pred*/,
261    unsigned short * /*pgreen*/,
262    unsigned short * /*pblue*/);
263
264extern void OsInit(void);
265
266extern void OsCleanup(Bool);
267
268extern void OsVendorFatalError(void);
269
270extern void OsVendorInit(void);
271
272extern int OsInitColors(void);
273
274void OsBlockSignals (void);
275
276void OsReleaseSignals (void);
277
278#if !defined(WIN32)
279extern int System(char *);
280extern pointer Popen(char *, char *);
281extern int Pclose(pointer);
282extern pointer Fopen(char *, char *);
283extern int Fclose(pointer);
284#else
285#define System(a) system(a)
286#define Popen(a,b) popen(a,b)
287#define Pclose(a) pclose(a)
288#define Fopen(a,b) fopen(a,b)
289#define Fclose(a) fclose(a)
290#endif
291
292extern void CheckUserParameters(int argc, char **argv, char **envp);
293extern void CheckUserAuthorization(void);
294
295extern int AddHost(
296    ClientPtr	/*client*/,
297    int         /*family*/,
298    unsigned    /*length*/,
299    pointer     /*pAddr*/);
300
301extern Bool ForEachHostInFamily (
302    int	    /*family*/,
303    Bool    (* /*func*/ )(
304            unsigned char * /* addr */,
305            short           /* len */,
306            pointer         /* closure */),
307    pointer /*closure*/);
308
309extern int RemoveHost(
310    ClientPtr	/*client*/,
311    int         /*family*/,
312    unsigned    /*length*/,
313    pointer     /*pAddr*/);
314
315extern int GetHosts(
316    pointer * /*data*/,
317    int	    * /*pnHosts*/,
318    int	    * /*pLen*/,
319    BOOL    * /*pEnabled*/);
320
321typedef struct sockaddr * sockaddrPtr;
322
323extern int InvalidHost(sockaddrPtr /*saddr*/, int /*len*/, ClientPtr client);
324
325extern int LocalClient(ClientPtr /* client */);
326
327extern int LocalClientCred(ClientPtr, int *, int *);
328
329extern int ChangeAccessControl(ClientPtr /*client*/, int /*fEnabled*/);
330
331extern int GetAccessControl(void);
332
333
334extern void AddLocalHosts(void);
335
336extern void ResetHosts(char *display);
337
338extern void EnableLocalHost(void);
339
340extern void DisableLocalHost(void);
341
342extern void AccessUsingXdmcp(void);
343
344extern void DefineSelf(int /*fd*/);
345
346extern void AugmentSelf(pointer /*from*/, int /*len*/);
347
348extern void InitAuthorization(char * /*filename*/);
349
350/* extern int LoadAuthorization(void); */
351
352extern void RegisterAuthorizations(void);
353
354extern int AuthorizationFromID (
355	XID 		id,
356	unsigned short	*name_lenp,
357	char		**namep,
358	unsigned short	*data_lenp,
359	char		**datap);
360
361extern XID CheckAuthorization(
362    unsigned int /*namelength*/,
363    char * /*name*/,
364    unsigned int /*datalength*/,
365    char * /*data*/,
366    ClientPtr /*client*/,
367    char ** /*reason*/
368);
369
370extern void ResetAuthorization(void);
371
372extern int RemoveAuthorization (
373    unsigned short	name_length,
374    char		*name,
375    unsigned short	data_length,
376    char		*data);
377
378extern int AddAuthorization(
379    unsigned int	/*name_length*/,
380    char *		/*name*/,
381    unsigned int	/*data_length*/,
382    char *		/*data*/);
383
384extern XID GenerateAuthorization(
385    unsigned int   /* name_length */,
386    char	*  /* name */,
387    unsigned int   /* data_length */,
388    char	*  /* data */,
389    unsigned int * /* data_length_return */,
390    char	** /* data_return */);
391
392#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS
393extern void ExpandCommandLine(int * /*pargc*/, char *** /*pargv*/);
394#endif
395
396extern void ddxInitGlobals(void);
397
398extern int ddxProcessArgument(int /*argc*/, char * /*argv*/ [], int /*i*/);
399
400extern void ddxUseMsg(void);
401
402/* int ReqLen(xReq *req, ClientPtr client)
403 * Given a pointer to a *complete* request, return its length in bytes.
404 * Note that if the request is a big request (as defined in the Big
405 * Requests extension), the macro lies by returning 4 less than the
406 * length that it actually occupies in the request buffer.  This is so you
407 * can blindly compare the length with the various sz_<request> constants
408 * in Xproto.h without having to know/care about big requests.
409 */
410#define ReqLen(_pxReq, _client) \
411 ((_pxReq->length ? \
412     (_client->swapped ? lswaps(_pxReq->length) : _pxReq->length) \
413  : ((_client->swapped ? \
414	lswapl(((CARD32*)_pxReq)[1]) : ((CARD32*)_pxReq)[1])-1) \
415  ) << 2)
416
417/* otherReqTypePtr CastxReq(xReq *req, otherReqTypePtr)
418 * Cast the given request to one of type otherReqTypePtr to access
419 * fields beyond the length field.
420 */
421#define CastxReq(_pxReq, otherReqTypePtr) \
422    (_pxReq->length ? (otherReqTypePtr)_pxReq \
423		    : (otherReqTypePtr)(((CARD32*)_pxReq)+1))
424
425/* stuff for SkippedRequestsCallback */
426extern CallbackListPtr SkippedRequestsCallback;
427typedef struct {
428    xReqPtr req;
429    ClientPtr client;
430    int numskipped;
431} SkippedRequestInfoRec;
432
433/* stuff for ReplyCallback */
434extern CallbackListPtr ReplyCallback;
435typedef struct {
436    ClientPtr client;
437    pointer replyData;
438    unsigned long dataLenBytes;
439    unsigned long bytesRemaining;
440    Bool startOfReply;
441} ReplyInfoRec;
442
443/* stuff for FlushCallback */
444extern CallbackListPtr FlushCallback;
445
446extern void AbortDDX(void);
447extern void ddxGiveUp(void);
448extern int TimeSinceLastInputEvent(void);
449
450/* Logging. */
451typedef enum _LogParameter {
452    XLOG_FLUSH,
453    XLOG_SYNC,
454    XLOG_VERBOSITY,
455    XLOG_FILE_VERBOSITY
456} LogParameter;
457
458/* Flags for log messages. */
459typedef enum {
460    X_PROBED,			/* Value was probed */
461    X_CONFIG,			/* Value was given in the config file */
462    X_DEFAULT,			/* Value is a default */
463    X_CMDLINE,			/* Value was given on the command line */
464    X_NOTICE,			/* Notice */
465    X_ERROR,			/* Error message */
466    X_WARNING,			/* Warning message */
467    X_INFO,			/* Informational message */
468    X_NONE,			/* No prefix */
469    X_NOT_IMPLEMENTED,		/* Not implemented */
470    X_UNKNOWN = -1		/* unknown -- this must always be last */
471} MessageType;
472
473/* XXX Need to check which GCC versions have the format(printf) attribute. */
474#if defined(__GNUC__) && \
475    ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4)))
476#define _printf_attribute(a,b) __attribute((format(__printf__,a,b)))
477#else
478#define _printf_attribute(a,b) /**/
479#endif
480
481extern const char *LogInit(const char *fname, const char *backup);
482extern void LogClose(void);
483extern Bool LogSetParameter(LogParameter param, int value);
484extern void LogVWrite(int verb, const char *f, va_list args);
485extern void LogWrite(int verb, const char *f, ...) _printf_attribute(2,3);
486extern void LogVMessageVerb(MessageType type, int verb, const char *format,
487			    va_list args);
488extern void LogMessageVerb(MessageType type, int verb, const char *format,
489			   ...) _printf_attribute(3,4);
490extern void LogMessage(MessageType type, const char *format, ...)
491			_printf_attribute(2,3);
492extern void FreeAuditTimer(void);
493extern void AuditF(const char *f, ...) _printf_attribute(1,2);
494extern void VAuditF(const char *f, va_list args);
495extern void FatalError(const char *f, ...) _printf_attribute(1,2)
496#if defined(__GNUC__) && \
497    ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4)))
498__attribute((noreturn))
499#endif
500;
501
502#ifdef DEBUG
503#define DebugF ErrorF
504#else
505#define DebugF(x, ...) /* */
506#endif
507
508extern void VErrorF(const char *f, va_list args);
509extern void ErrorF(const char *f, ...) _printf_attribute(1,2);
510extern void Error(char *str);
511extern void LogPrintMarkers(void);
512
513#endif /* OS_H */
514