os.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifndef OS_H
  37. #define OS_H
  38. #include "misc.h"
  39. #include <X11/Xalloca.h>
  40. #include <stdarg.h>
  41. #define NullFID ((FID) 0)
  42. #define SCREEN_SAVER_OFF 0
  43. #define SCREEN_SAVER_ON 1
  44. #define SCREEN_SAVER_FORCER 2
  45. #define SCREEN_SAVER_CYCLE 3
  46. #ifndef MAX_REQUEST_SIZE
  47. #define MAX_REQUEST_SIZE 65535
  48. #endif
  49. #ifndef MAX_BIG_REQUEST_SIZE
  50. #define MAX_BIG_REQUEST_SIZE 4194303
  51. #endif
  52. // Need to mark a set of functions so LTO doesn't mangle them
  53. #if defined(__GNUC__) && __GNUC__ >= 4
  54. #define XFONT_LTO __attribute__((noinline)) __attribute__((used))
  55. #define XFONT_LTO_VAR __attribute__((used))
  56. #else
  57. #define XFONT_LTO
  58. #define XFONT_LTO_VAR
  59. #endif
  60. typedef pointer FID;
  61. typedef struct _FontPathRec *FontPathPtr;
  62. typedef struct _NewClientRec *NewClientPtr;
  63. #include <stdio.h>
  64. #include <stdarg.h>
  65. /* have to put $(SIGNAL_DEFINES) in DEFINES in Imakefile to get this right */
  66. #ifdef SIGNALRETURNSINT
  67. #define SIGVAL int
  68. #else
  69. #define SIGVAL void
  70. #endif
  71. void (*OsVendorVErrorFProc)(const char *, va_list args);
  72. int WaitForSomething(
  73. int* /*pClientsReady*/
  74. );
  75. int ReadRequestFromClient(ClientPtr /*client*/);
  76. Bool InsertFakeRequest(
  77. ClientPtr /*client*/,
  78. char* /*data*/,
  79. int /*count*/);
  80. void ResetCurrentRequest(ClientPtr /*client*/);
  81. void FlushAllOutput(void);
  82. void FlushIfCriticalOutputPending(void);
  83. void SetCriticalOutputPending(void);
  84. int WriteToClient(ClientPtr /*who*/, int /*count*/, const char* /*buf*/);
  85. void ResetOsBuffers(void);
  86. void InitConnectionLimits(void);
  87. void CreateWellKnownSockets(void);
  88. void ResetWellKnownSockets(void);
  89. void CloseWellKnownConnections(void);
  90. const char *ClientAuthorized(
  91. ClientPtr /*client*/,
  92. unsigned int /*proto_n*/,
  93. char* /*auth_proto*/,
  94. unsigned int /*string_n*/,
  95. char* /*auth_string*/);
  96. Bool EstablishNewConnections(
  97. ClientPtr /*clientUnused*/,
  98. pointer /*closure*/);
  99. void CheckConnections(void);
  100. void CloseDownConnection(ClientPtr /*client*/);
  101. void AddGeneralSocket(int /*fd*/);
  102. void RemoveGeneralSocket(int /*fd*/);
  103. void AddEnabledDevice(int /*fd*/);
  104. void RemoveEnabledDevice(int /*fd*/);
  105. void OnlyListenToOneClient(ClientPtr /*client*/);
  106. void ListenToAllClients(void);
  107. void IgnoreClient(ClientPtr /*client*/);
  108. void AttendClient(ClientPtr /*client*/);
  109. void MakeClientGrabImpervious(ClientPtr /*client*/);
  110. void MakeClientGrabPervious(ClientPtr /*client*/);
  111. void AvailableClientInput(ClientPtr /* client */);
  112. CARD32 XFONT_LTO GetTimeInMillis(void);
  113. void AdjustWaitForDelay(
  114. pointer /*waitTime*/,
  115. unsigned long /*newdelay*/);
  116. typedef struct _OsTimerRec *OsTimerPtr;
  117. typedef CARD32 (*OsTimerCallback)(
  118. OsTimerPtr /* timer */,
  119. CARD32 /* time */,
  120. pointer /* arg */);
  121. void TimerInit(void);
  122. Bool TimerForce(OsTimerPtr /* timer */);
  123. #define TimerAbsolute (1<<0)
  124. #define TimerForceOld (1<<1)
  125. OsTimerPtr TimerSet(
  126. OsTimerPtr /* timer */,
  127. int /* flags */,
  128. CARD32 /* millis */,
  129. OsTimerCallback /* func */,
  130. pointer /* arg */);
  131. void TimerCancel(OsTimerPtr /* pTimer */);
  132. void TimerFree(OsTimerPtr /* pTimer */);
  133. void SetScreenSaverTimer(void);
  134. void FreeScreenSaverTimer(void);
  135. SIGVAL AutoResetServer(int /*sig*/);
  136. SIGVAL GiveUp(int /*sig*/);
  137. void UseMsg(void);
  138. void ProcessCommandLine(int /*argc*/, char* /*argv*/[]);
  139. XFONT_LTO int set_font_authorizations(
  140. char ** /* authorizations */,
  141. int * /*authlen */,
  142. pointer /* client */);
  143. void OsInitAllocator(void);
  144. typedef SIGVAL (*OsSigHandlerPtr)(int /* sig */);
  145. OsSigHandlerPtr OsSignal(int /* sig */, OsSigHandlerPtr /* handler */);
  146. extern int auditTrailLevel;
  147. void LockServer(void);
  148. void UnlockServer(void);
  149. int OsLookupColor(
  150. int /*screen*/,
  151. char * /*name*/,
  152. unsigned /*len*/,
  153. unsigned short * /*pred*/,
  154. unsigned short * /*pgreen*/,
  155. unsigned short * /*pblue*/);
  156. void OsInit(void);
  157. void OsCleanup(Bool);
  158. void OsVendorFatalError(void);
  159. void OsVendorInit(void);
  160. void OsBlockSignals (void);
  161. void OsReleaseSignals (void);
  162. int System(char *);
  163. pointer Popen(char *, char *);
  164. int Pclose(pointer);
  165. pointer Fopen(char *, char *);
  166. int Fclose(pointer);
  167. void CheckUserParameters(int argc, char **argv, char **envp);
  168. void CheckUserAuthorization(void);
  169. int AddHost(
  170. ClientPtr /*client*/,
  171. int /*family*/,
  172. unsigned /*length*/,
  173. const void * /*pAddr*/);
  174. int RemoveHost(
  175. ClientPtr /*client*/,
  176. int /*family*/,
  177. unsigned /*length*/,
  178. pointer /*pAddr*/);
  179. int GetHosts(
  180. pointer * /*data*/,
  181. int * /*pnHosts*/,
  182. int * /*pLen*/,
  183. BOOL * /*pEnabled*/);
  184. typedef struct sockaddr * sockaddrPtr;
  185. int InvalidHost(sockaddrPtr /*saddr*/, int /*len*/, ClientPtr client);
  186. int LocalClient(ClientPtr /* client */);
  187. int LocalClientCred(ClientPtr, int *, int *);
  188. int ChangeAccessControl(ClientPtr /*client*/, int /*fEnabled*/);
  189. void AddLocalHosts(void);
  190. void ResetHosts(const char *display);
  191. void EnableLocalHost(void);
  192. void DisableLocalHost(void);
  193. void AccessUsingXdmcp(void);
  194. void DefineSelf(int /*fd*/);
  195. void AugmentSelf(pointer /*from*/, int /*len*/);
  196. void InitAuthorization(char * /*filename*/);
  197. /* int LoadAuthorization(void); */
  198. void RegisterAuthorizations(void);
  199. XID CheckAuthorization(
  200. unsigned int /*namelength*/,
  201. const char * /*name*/,
  202. unsigned int /*datalength*/,
  203. const char * /*data*/,
  204. ClientPtr /*client*/,
  205. const char ** /*reason*/
  206. );
  207. void ResetAuthorization(void);
  208. int AddAuthorization(
  209. unsigned int /*name_length*/,
  210. const char * /*name*/,
  211. unsigned int /*data_length*/,
  212. char * /*data*/);
  213. XID GenerateAuthorization(
  214. unsigned int /* name_length */,
  215. char * /* name */,
  216. unsigned int /* data_length */,
  217. char * /* data */,
  218. unsigned int * /* data_length_return */,
  219. char ** /* data_return */);
  220. int ddxProcessArgument(int /*argc*/, char * /*argv*/ [], int /*i*/);
  221. void ddxUseMsg(void);
  222. /* int ReqLen(xReq *req, ClientPtr client)
  223. * Given a pointer to a *complete* request, return its length in bytes.
  224. * Note that if the request is a big request (as defined in the Big
  225. * Requests extension), the macro lies by returning 4 less than the
  226. * length that it actually occupies in the request buffer. This is so you
  227. * can blindly compare the length with the various sz_<request> constants
  228. * in Xproto.h without having to know/care about big requests.
  229. */
  230. #define ReqLen(_pxReq, _client) \
  231. ((_pxReq->length ? \
  232. (_client->swapped ? lswaps(_pxReq->length) : _pxReq->length) \
  233. : ((_client->swapped ? \
  234. lswapl(((CARD32*)_pxReq)[1]) : ((CARD32*)_pxReq)[1])-1) \
  235. ) << 2)
  236. /* otherReqTypePtr CastxReq(xReq *req, otherReqTypePtr)
  237. * Cast the given request to one of type otherReqTypePtr to access
  238. * fields beyond the length field.
  239. */
  240. #define CastxReq(_pxReq, otherReqTypePtr) \
  241. (_pxReq->length ? (otherReqTypePtr)_pxReq \
  242. : (otherReqTypePtr)(((CARD32*)_pxReq)+1))
  243. typedef struct {
  244. xReqPtr req;
  245. ClientPtr client;
  246. int numskipped;
  247. } SkippedRequestInfoRec;
  248. /* stuff for ReplyCallback */
  249. extern CallbackListPtr ReplyCallback;
  250. typedef struct {
  251. ClientPtr client;
  252. const void * replyData;
  253. unsigned long dataLenBytes;
  254. unsigned long bytesRemaining;
  255. Bool startOfReply;
  256. } ReplyInfoRec;
  257. /* stuff for FlushCallback */
  258. extern CallbackListPtr FlushCallback;
  259. void AbortDDX(void);
  260. void ddxGiveUp(void);
  261. int TimeSinceLastInputEvent(void);
  262. /* Logging. */
  263. typedef enum _LogParameter {
  264. XLOG_FLUSH,
  265. XLOG_SYNC,
  266. XLOG_VERBOSITY,
  267. XLOG_FILE_VERBOSITY
  268. } LogParameter;
  269. /* Flags for log messages. */
  270. typedef enum {
  271. X_PROBED, /* Value was probed */
  272. X_CONFIG, /* Value was given in the config file */
  273. X_DEFAULT, /* Value is a default */
  274. X_CMDLINE, /* Value was given on the command line */
  275. X_NOTICE, /* Notice */
  276. X_ERROR, /* Error message */
  277. X_WARNING, /* Warning message */
  278. X_INFO, /* Informational message */
  279. X_NONE, /* No prefix */
  280. X_NOT_IMPLEMENTED, /* Not implemented */
  281. X_UNKNOWN = -1 /* unknown -- this must always be last */
  282. } MessageType;
  283. /* XXX Need to check which GCC versions have the format(printf) attribute. */
  284. #if defined(__GNUC__) && \
  285. ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4)))
  286. #define _printf_attribute(a,b) __attribute((format(__printf__,a,b)))
  287. #else
  288. #define _printf_attribute(a,b) /**/
  289. #endif
  290. void AuditF(const char *f, ...) _printf_attribute(1,2);
  291. void VAuditF(const char *f, va_list args);
  292. void FatalError(const char *f, ...) _printf_attribute(1,2) XFONT_LTO
  293. #if defined(__GNUC__) && \
  294. ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4)))
  295. __attribute((noreturn))
  296. #endif
  297. ;
  298. void VErrorF(const char *f, va_list args);
  299. void ErrorF(const char *f, ...) _printf_attribute(1,2) XFONT_LTO;
  300. #endif /* OS_H */