os.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file win32/os.h
  18. * @brief This file in included in all Apache source code. It contains definitions
  19. * of facilities available on _this_ operating system (HAVE_* macros),
  20. * and prototypes of OS specific functions defined in os.c or os-inline.c
  21. *
  22. * @defgroup APACHE_OS_WIN32 win32
  23. * @ingroup APACHE_OS
  24. * @{
  25. */
  26. #ifdef WIN32
  27. #ifndef AP_OS_H
  28. #define AP_OS_H
  29. /* Delegate windows include to the apr.h header, if USER or GDI declarations
  30. * are required (for a window rather than console application), include
  31. * windows.h prior to any other Apache header files.
  32. */
  33. #include "apr_pools.h"
  34. #include <io.h>
  35. #include <fcntl.h>
  36. #ifdef _WIN64
  37. #define PLATFORM "Win64"
  38. #else
  39. #define PLATFORM "Win32"
  40. #endif
  41. /* Define command-line rewriting for this platform, handled by core.
  42. * For Windows, this is currently handled inside the WinNT MPM.
  43. * XXX To support a choice of MPMs, extract common platform behavior
  44. * into a function specified here.
  45. */
  46. #define AP_PLATFORM_REWRITE_ARGS_HOOK NULL
  47. /* going away shortly... */
  48. #define HAVE_DRIVE_LETTERS
  49. #define HAVE_UNC_PATHS
  50. #define CASE_BLIND_FILESYSTEM
  51. #include <stddef.h>
  52. #include <stdlib.h> /* for exit() */
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /* BIG RED WARNING: exit() is mapped to allow us to capture the exit
  57. * status. This header must only be included from modules linked into
  58. * the ApacheCore.dll - since it's a horrible behavior to exit() from
  59. * any module outside the main() block, and we -will- assume it's a
  60. * fatal error.
  61. */
  62. AP_DECLARE_DATA extern int ap_real_exit_code;
  63. #define exit(status) ((exit)((ap_real_exit_code==2) \
  64. ? (ap_real_exit_code = (status)) \
  65. : ((ap_real_exit_code = 0), (status))))
  66. #ifdef AP_DECLARE_EXPORT
  67. /* Defined in util_win32.c and available only to the core module for
  68. * win32 MPM design.
  69. */
  70. AP_DECLARE(apr_status_t) ap_os_proc_filepath(char **binpath, apr_pool_t *p);
  71. typedef enum {
  72. AP_DLL_WINBASEAPI = 0, /* kernel32 From WinBase.h */
  73. AP_DLL_WINADVAPI = 1, /* advapi32 From WinBase.h */
  74. AP_DLL_WINSOCKAPI = 2, /* mswsock From WinSock.h */
  75. AP_DLL_WINSOCK2API = 3, /* ws2_32 From WinSock2.h */
  76. AP_DLL_defined = 4 /* must define as last idx_ + 1 */
  77. } ap_dlltoken_e;
  78. FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal);
  79. PSECURITY_ATTRIBUTES GetNullACL(void);
  80. void CleanNullACL(void *sa);
  81. #define AP_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
  82. typedef rettype (calltype *ap_winapi_fpt_##fn) args; \
  83. static ap_winapi_fpt_##fn ap_winapi_pfn_##fn = NULL; \
  84. static APR_INLINE rettype ap_winapi_##fn args \
  85. { if (!ap_winapi_pfn_##fn) \
  86. ap_winapi_pfn_##fn = (ap_winapi_fpt_##fn) ap_load_dll_func(lib, #fn, ord); \
  87. return (*(ap_winapi_pfn_##fn)) names; }; \
  88. /* Win2K kernel only */
  89. AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINADVAPI, BOOL, WINAPI, ChangeServiceConfig2A, 0, (
  90. SC_HANDLE hService,
  91. DWORD dwInfoLevel,
  92. LPVOID lpInfo),
  93. (hService, dwInfoLevel, lpInfo));
  94. #undef ChangeServiceConfig2
  95. #define ChangeServiceConfig2 ap_winapi_ChangeServiceConfig2A
  96. /* WinNT kernel only */
  97. AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
  98. IN HANDLE hFile),
  99. (hFile));
  100. #undef CancelIo
  101. #define CancelIo ap_winapi_CancelIo
  102. /* Win9x kernel only */
  103. AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, DWORD, WINAPI, RegisterServiceProcess, 0, (
  104. DWORD dwProcessId,
  105. DWORD dwType),
  106. (dwProcessId, dwType));
  107. #define RegisterServiceProcess ap_winapi_RegisterServiceProcess
  108. #endif /* def AP_DECLARE_EXPORT */
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif /* ndef AP_OS_H */
  113. #endif /* def WIN32 */
  114. /** @} */