os.h revision 4202a189
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#include <stdarg.h>
54
55#define SCREEN_SAVER_ON   0
56#define SCREEN_SAVER_OFF  1
57#define SCREEN_SAVER_FORCER 2
58#define SCREEN_SAVER_CYCLE  3
59
60#ifndef MAX_REQUEST_SIZE
61#define MAX_REQUEST_SIZE 65535
62#endif
63#ifndef MAX_BIG_REQUEST_SIZE
64#define MAX_BIG_REQUEST_SIZE 4194303
65#endif
66
67typedef struct _FontPathRec *FontPathPtr;
68typedef struct _NewClientRec *NewClientPtr;
69
70#ifndef xalloc
71#define xnfalloc(size) XNFalloc((unsigned long)(size))
72#define xnfcalloc(_num, _size) XNFcalloc((unsigned long)(_num)*(unsigned long)(_size))
73#define xnfrealloc(ptr, size) XNFrealloc((pointer)(ptr), (unsigned long)(size))
74
75#define xalloc(size) Xalloc((unsigned long)(size))
76#define xcalloc(_num, _size) Xcalloc((unsigned long)(_num)*(unsigned long)(_size))
77#define xrealloc(ptr, size) Xrealloc((pointer)(ptr), (unsigned long)(size))
78#define xfree(ptr) Xfree((pointer)(ptr))
79#define xstrdup(s) Xstrdup(s)
80#define xnfstrdup(s) XNFstrdup(s)
81#endif
82
83#include <stdio.h>
84#include <stdarg.h>
85#include <string.h>
86#include <strings.h>
87
88
89#ifdef DDXBEFORERESET
90extern void ddxBeforeReset (void);
91#endif
92
93#ifdef DDXOSVERRORF
94extern _X_EXPORT void (*OsVendorVErrorFProc)(const char *, va_list args);
95#endif
96
97extern _X_EXPORT int WaitForSomething(
98    int* /*pClientsReady*/
99);
100
101extern _X_EXPORT int ReadRequestFromClient(ClientPtr /*client*/);
102
103extern _X_EXPORT Bool InsertFakeRequest(
104    ClientPtr /*client*/,
105    char* /*data*/,
106    int /*count*/);
107
108extern _X_EXPORT void ResetCurrentRequest(ClientPtr /*client*/);
109
110extern _X_EXPORT void FlushAllOutput(void);
111
112extern _X_EXPORT void FlushIfCriticalOutputPending(void);
113
114extern _X_EXPORT void SetCriticalOutputPending(void);
115
116extern _X_EXPORT int WriteToClient(ClientPtr /*who*/, int /*count*/, const void* /*buf*/);
117
118extern _X_EXPORT void ResetOsBuffers(void);
119
120extern _X_EXPORT void InitConnectionLimits(void);
121
122extern _X_EXPORT void NotifyParentProcess(void);
123
124extern _X_EXPORT void CreateWellKnownSockets(void);
125
126extern _X_EXPORT void ResetWellKnownSockets(void);
127
128extern _X_EXPORT void CloseWellKnownConnections(void);
129
130extern _X_EXPORT XID AuthorizationIDOfClient(ClientPtr /*client*/);
131
132extern _X_EXPORT char *ClientAuthorized(
133    ClientPtr /*client*/,
134    unsigned int /*proto_n*/,
135    char* /*auth_proto*/,
136    unsigned int /*string_n*/,
137    char* /*auth_string*/);
138
139extern _X_EXPORT Bool EstablishNewConnections(
140    ClientPtr /*clientUnused*/,
141    pointer /*closure*/);
142
143extern _X_EXPORT void CheckConnections(void);
144
145extern _X_EXPORT void CloseDownConnection(ClientPtr /*client*/);
146
147extern _X_EXPORT void AddGeneralSocket(int /*fd*/);
148
149extern _X_EXPORT void RemoveGeneralSocket(int /*fd*/);
150
151extern _X_EXPORT void AddEnabledDevice(int /*fd*/);
152
153extern _X_EXPORT void RemoveEnabledDevice(int /*fd*/);
154
155extern _X_EXPORT int OnlyListenToOneClient(ClientPtr /*client*/);
156
157extern _X_EXPORT void ListenToAllClients(void);
158
159extern _X_EXPORT void IgnoreClient(ClientPtr /*client*/);
160
161extern _X_EXPORT void AttendClient(ClientPtr /*client*/);
162
163extern _X_EXPORT void MakeClientGrabImpervious(ClientPtr /*client*/);
164
165extern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client*/);
166
167#ifdef XQUARTZ
168extern void ListenOnOpenFD(int /* fd */, int /* noxauth */);
169#endif
170
171extern _X_EXPORT CARD32 GetTimeInMillis(void);
172
173extern _X_EXPORT void AdjustWaitForDelay(
174    pointer /*waitTime*/,
175    unsigned long /*newdelay*/);
176
177typedef	struct _OsTimerRec *OsTimerPtr;
178
179typedef CARD32 (*OsTimerCallback)(
180    OsTimerPtr /* timer */,
181    CARD32 /* time */,
182    pointer /* arg */);
183
184extern _X_EXPORT void TimerInit(void);
185
186extern _X_EXPORT Bool TimerForce(OsTimerPtr /* timer */);
187
188#define TimerAbsolute (1<<0)
189#define TimerForceOld (1<<1)
190
191extern _X_EXPORT OsTimerPtr TimerSet(
192    OsTimerPtr /* timer */,
193    int /* flags */,
194    CARD32 /* millis */,
195    OsTimerCallback /* func */,
196    pointer /* arg */);
197
198extern _X_EXPORT void TimerCheck(void);
199extern _X_EXPORT void TimerCancel(OsTimerPtr /* pTimer */);
200extern _X_EXPORT void TimerFree(OsTimerPtr /* pTimer */);
201
202extern _X_EXPORT void SetScreenSaverTimer(void);
203extern _X_EXPORT void FreeScreenSaverTimer(void);
204
205extern _X_EXPORT void AutoResetServer(int /*sig*/);
206
207extern _X_EXPORT void GiveUp(int /*sig*/);
208
209extern _X_EXPORT void UseMsg(void);
210
211extern _X_EXPORT void ProcessCommandLine(int /*argc*/, char* /*argv*/[]);
212
213extern _X_EXPORT int set_font_authorizations(
214    char ** /* authorizations */,
215    int * /*authlen */,
216    pointer /* client */);
217
218#ifndef _HAVE_XALLOC_DECLS
219#define _HAVE_XALLOC_DECLS
220
221/*
222 * Use malloc(3) instead.
223 */
224extern _X_EXPORT void *Xalloc(unsigned long /*amount*/) _X_DEPRECATED;
225/*
226 * Use calloc(3) instead
227 */
228extern _X_EXPORT void *Xcalloc(unsigned long /*amount*/) _X_DEPRECATED;
229/*
230 * Use realloc(3) instead
231 */
232extern _X_EXPORT void *Xrealloc(void * /*ptr*/, unsigned long /*amount*/)
233    _X_DEPRECATED;
234/*
235 * Use free(3) instead
236 */
237extern _X_EXPORT void Xfree(void * /*ptr*/) _X_DEPRECATED;
238
239#endif
240
241/*
242 * This function malloc(3)s buffer, terminating the server if there is not
243 * enough memory.
244 */
245extern _X_EXPORT void *XNFalloc(unsigned long /*amount*/);
246/*
247 * This function calloc(3)s buffer, terminating the server if there is not
248 * enough memory.
249 */
250extern _X_EXPORT void *XNFcalloc(unsigned long /*amount*/);
251/*
252 * This function realloc(3)s passed buffer, terminating the server if there is
253 * not enough memory.
254 */
255extern _X_EXPORT void *XNFrealloc(void * /*ptr*/, unsigned long /*amount*/);
256
257/*
258 * This function strdup(3)s passed string. The only difference from the library
259 * function that it is safe to pass NULL, as NULL will be returned.
260 */
261extern _X_EXPORT char *Xstrdup(const char *s);
262
263/*
264 * This function strdup(3)s passed string, terminating the server if there is
265 * not enough memory. If NULL is passed to this function, NULL is returned.
266 */
267extern _X_EXPORT char *XNFstrdup(const char *s);
268
269extern _X_EXPORT char *Xprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2);
270extern _X_EXPORT char *Xvprintf(const char *fmt, va_list va);
271extern _X_EXPORT char *XNFprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2);
272extern _X_EXPORT char *XNFvprintf(const char *fmt, va_list va);
273
274typedef void (*OsSigHandlerPtr)(int /* sig */);
275typedef int (*OsSigWrapperPtr)(int /* sig */);
276
277extern _X_EXPORT OsSigHandlerPtr OsSignal(int /* sig */, OsSigHandlerPtr /* handler */);
278extern _X_EXPORT OsSigWrapperPtr OsRegisterSigWrapper(OsSigWrapperPtr newWrap);
279
280extern _X_EXPORT int auditTrailLevel;
281
282extern _X_EXPORT void LockServer(void);
283extern _X_EXPORT void UnlockServer(void);
284
285extern _X_EXPORT int OsLookupColor(
286    int	/*screen*/,
287    char * /*name*/,
288    unsigned /*len*/,
289    unsigned short * /*pred*/,
290    unsigned short * /*pgreen*/,
291    unsigned short * /*pblue*/);
292
293extern _X_EXPORT void OsInit(void);
294
295extern _X_EXPORT void OsCleanup(Bool);
296
297extern _X_EXPORT void OsVendorFatalError(void);
298
299extern _X_EXPORT void OsVendorInit(void);
300
301extern _X_EXPORT void OsBlockSignals (void);
302
303extern _X_EXPORT void OsReleaseSignals (void);
304
305extern _X_EXPORT void OsAbort (void) _X_NORETURN;
306
307#if !defined(WIN32)
308extern _X_EXPORT int System(char *);
309extern _X_EXPORT pointer Popen(char *, char *);
310extern _X_EXPORT int Pclose(pointer);
311extern _X_EXPORT pointer Fopen(char *, char *);
312extern _X_EXPORT int Fclose(pointer);
313#else
314#define System(a) system(a)
315#define Popen(a,b) popen(a,b)
316#define Pclose(a) pclose(a)
317#define Fopen(a,b) fopen(a,b)
318#define Fclose(a) fclose(a)
319#endif
320
321extern _X_EXPORT void CheckUserParameters(int argc, char **argv, char **envp);
322extern _X_EXPORT void CheckUserAuthorization(void);
323
324extern _X_EXPORT int AddHost(
325    ClientPtr	/*client*/,
326    int         /*family*/,
327    unsigned    /*length*/,
328    const void */*pAddr*/);
329
330extern _X_EXPORT Bool ForEachHostInFamily (
331    int	    /*family*/,
332    Bool    (* /*func*/ )(
333            unsigned char * /* addr */,
334            short           /* len */,
335            pointer         /* closure */),
336    pointer /*closure*/);
337
338extern _X_EXPORT int RemoveHost(
339    ClientPtr	/*client*/,
340    int         /*family*/,
341    unsigned    /*length*/,
342    pointer     /*pAddr*/);
343
344extern _X_EXPORT int GetHosts(
345    pointer * /*data*/,
346    int	    * /*pnHosts*/,
347    int	    * /*pLen*/,
348    BOOL    * /*pEnabled*/);
349
350typedef struct sockaddr * sockaddrPtr;
351
352extern _X_EXPORT int InvalidHost(sockaddrPtr /*saddr*/, int /*len*/, ClientPtr client);
353
354extern _X_EXPORT int LocalClient(ClientPtr /* client */);
355
356extern _X_EXPORT int LocalClientCred(ClientPtr, int *, int *);
357
358#define LCC_UID_SET	(1 << 0)
359#define LCC_GID_SET	(1 << 1)
360#define LCC_PID_SET	(1 << 2)
361#define LCC_ZID_SET	(1 << 3)
362
363typedef struct {
364    int fieldsSet;	/* Bit mask of fields set */
365    int	euid;		/* Effective uid */
366    int egid;		/* Primary effective group id */
367    int nSuppGids;	/* Number of supplementary group ids */
368    int *pSuppGids;	/* Array of supplementary group ids */
369    int pid;		/* Process id */
370    int zoneid;		/* Only set on Solaris 10 & later */
371} LocalClientCredRec;
372
373extern _X_EXPORT int GetLocalClientCreds(ClientPtr, LocalClientCredRec **);
374extern _X_EXPORT void FreeLocalClientCreds(LocalClientCredRec *);
375
376extern _X_EXPORT int ChangeAccessControl(ClientPtr /*client*/, int /*fEnabled*/);
377
378extern _X_EXPORT int GetAccessControl(void);
379
380
381extern _X_EXPORT void AddLocalHosts(void);
382
383extern _X_EXPORT void ResetHosts(char *display);
384
385extern _X_EXPORT void EnableLocalHost(void);
386
387extern _X_EXPORT void DisableLocalHost(void);
388
389extern _X_EXPORT void AccessUsingXdmcp(void);
390
391extern _X_EXPORT void DefineSelf(int /*fd*/);
392
393#if XDMCP
394extern _X_EXPORT void AugmentSelf(pointer /*from*/, int /*len*/);
395
396extern _X_EXPORT void RegisterAuthorizations(void);
397#endif
398
399extern _X_EXPORT void InitAuthorization(char * /*filename*/);
400
401/* extern int LoadAuthorization(void); */
402
403extern _X_EXPORT int AuthorizationFromID (
404	XID 		id,
405	unsigned short	*name_lenp,
406	char		**namep,
407	unsigned short	*data_lenp,
408	char		**datap);
409
410extern _X_EXPORT XID CheckAuthorization(
411    unsigned int /*namelength*/,
412    const char * /*name*/,
413    unsigned int /*datalength*/,
414    const char * /*data*/,
415    ClientPtr /*client*/,
416    char ** /*reason*/
417);
418
419extern _X_EXPORT void ResetAuthorization(void);
420
421extern _X_EXPORT int RemoveAuthorization (
422    unsigned short	name_length,
423    const char		*name,
424    unsigned short	data_length,
425    const char		*data);
426
427extern _X_EXPORT int AddAuthorization(
428    unsigned int	/*name_length*/,
429    const char *	/*name*/,
430    unsigned int	/*data_length*/,
431    char *		/*data*/);
432
433#ifdef XCSECURITY
434extern _X_EXPORT XID GenerateAuthorization(
435    unsigned int   /* name_length */,
436    const char	*  /* name */,
437    unsigned int   /* data_length */,
438    const char	*  /* data */,
439    unsigned int * /* data_length_return */,
440    char	** /* data_return */);
441#endif
442
443extern _X_EXPORT int ddxProcessArgument(int /*argc*/, char * /*argv*/ [], int /*i*/);
444
445extern _X_EXPORT void ddxUseMsg(void);
446
447/* int ReqLen(xReq *req, ClientPtr client)
448 * Given a pointer to a *complete* request, return its length in bytes.
449 * Note that if the request is a big request (as defined in the Big
450 * Requests extension), the macro lies by returning 4 less than the
451 * length that it actually occupies in the request buffer.  This is so you
452 * can blindly compare the length with the various sz_<request> constants
453 * in Xproto.h without having to know/care about big requests.
454 */
455#define ReqLen(_pxReq, _client) \
456 ((_pxReq->length ? \
457     (_client->swapped ? lswaps(_pxReq->length) : _pxReq->length) \
458  : ((_client->swapped ? \
459	lswapl(((CARD32*)_pxReq)[1]) : ((CARD32*)_pxReq)[1])-1) \
460  ) << 2)
461
462/* otherReqTypePtr CastxReq(xReq *req, otherReqTypePtr)
463 * Cast the given request to one of type otherReqTypePtr to access
464 * fields beyond the length field.
465 */
466#define CastxReq(_pxReq, otherReqTypePtr) \
467    (_pxReq->length ? (otherReqTypePtr)_pxReq \
468		    : (otherReqTypePtr)(((CARD32*)_pxReq)+1))
469
470/* stuff for ReplyCallback */
471extern _X_EXPORT CallbackListPtr ReplyCallback;
472typedef struct {
473    ClientPtr client;
474    const void *replyData;
475    unsigned long dataLenBytes;
476    unsigned long bytesRemaining;
477    Bool startOfReply;
478} ReplyInfoRec;
479
480/* stuff for FlushCallback */
481extern _X_EXPORT CallbackListPtr FlushCallback;
482
483extern _X_EXPORT void AbortDDX(void);
484extern _X_EXPORT void ddxGiveUp(void);
485extern _X_EXPORT int TimeSinceLastInputEvent(void);
486
487/* strcasecmp.c */
488#if NEED_STRCASECMP
489#define strcasecmp xstrcasecmp
490extern _X_EXPORT int xstrcasecmp(const char *s1, const char *s2);
491#endif
492
493#if NEED_STRNCASECMP
494#define strncasecmp xstrncasecmp
495extern _X_EXPORT int xstrncasecmp(const char *s1, const char *s2, size_t n);
496#endif
497
498#if NEED_STRCASESTR
499#define strcasestr xstrcasestr
500extern _X_EXPORT char *xstrcasestr(const char *s, const char *find);
501#endif
502
503#ifndef HAS_STRLCPY
504extern _X_EXPORT size_t strlcpy(char *dst, const char *src, size_t siz);
505extern _X_EXPORT size_t strlcat(char *dst, const char *src, size_t siz);
506#endif
507
508/* Logging. */
509typedef enum _LogParameter {
510    XLOG_FLUSH,
511    XLOG_SYNC,
512    XLOG_VERBOSITY,
513    XLOG_FILE_VERBOSITY
514} LogParameter;
515
516/* Flags for log messages. */
517typedef enum {
518    X_PROBED,			/* Value was probed */
519    X_CONFIG,			/* Value was given in the config file */
520    X_DEFAULT,			/* Value is a default */
521    X_CMDLINE,			/* Value was given on the command line */
522    X_NOTICE,			/* Notice */
523    X_ERROR,			/* Error message */
524    X_WARNING,			/* Warning message */
525    X_INFO,			/* Informational message */
526    X_NONE,			/* No prefix */
527    X_NOT_IMPLEMENTED,		/* Not implemented */
528    X_UNKNOWN = -1		/* unknown -- this must always be last */
529} MessageType;
530
531extern _X_EXPORT const char *LogInit(const char *fname, const char *backup);
532extern _X_EXPORT void LogClose(void);
533extern _X_EXPORT Bool LogSetParameter(LogParameter param, int value);
534extern _X_EXPORT void LogVWrite(int verb, const char *f, va_list args);
535extern _X_EXPORT void LogWrite(int verb, const char *f, ...) _X_ATTRIBUTE_PRINTF(2,3);
536extern _X_EXPORT void LogVMessageVerb(MessageType type, int verb, const char *format,
537			    va_list args);
538extern _X_EXPORT void LogMessageVerb(MessageType type, int verb, const char *format,
539			   ...) _X_ATTRIBUTE_PRINTF(3,4);
540extern _X_EXPORT void LogMessage(MessageType type, const char *format, ...)
541			_X_ATTRIBUTE_PRINTF(2,3);
542extern _X_EXPORT void FreeAuditTimer(void);
543extern _X_EXPORT void AuditF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
544extern _X_EXPORT void VAuditF(const char *f, va_list args);
545extern _X_EXPORT void FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_NORETURN;
546
547#ifdef DEBUG
548#define DebugF ErrorF
549#else
550#define DebugF(...) /* */
551#endif
552
553extern _X_EXPORT void VErrorF(const char *f, va_list args);
554extern _X_EXPORT void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
555extern _X_EXPORT void Error(char *str);
556extern _X_EXPORT void LogPrintMarkers(void);
557
558extern _X_EXPORT void xorg_backtrace(void);
559
560#endif /* OS_H */
561