]>
Commit | Line | Data |
---|---|---|
1fd5e000 CF |
1 | /* winsup.h: main Cygwin header file. |
2 | ||
077ec4cb | 3 | Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. |
1fd5e000 CF |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
7 | This software is a copyrighted work licensed under the terms of the | |
8 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
9 | details. */ | |
10 | ||
11 | #ifdef HAVE_CONFIG_H | |
12 | # include "config.h" | |
13 | #endif | |
14 | ||
15 | #define __INSIDE_CYGWIN__ | |
16 | ||
ac944e37 | 17 | #define alloca __builtin_alloca |
1fd5e000 | 18 | #define strlen __builtin_strlen |
ac944e37 | 19 | #define strcmp __builtin_strcmp |
1fd5e000 CF |
20 | #define strcpy __builtin_strcpy |
21 | #define memcpy __builtin_memcpy | |
22 | #define memcmp __builtin_memcmp | |
23 | #ifdef HAVE_BUILTIN_MEMSET | |
24 | # define memset __builtin_memset | |
25 | #endif | |
26 | ||
5ac73dfe | 27 | #define NO_COPY __attribute__((section(".data_cygwin_nocopy"))) |
0a047e8f | 28 | |
95a8465b CF |
29 | #ifdef __cplusplus |
30 | ||
a5a965ff CF |
31 | #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L |
32 | #define NEW_MACRO_VARARGS | |
33 | #endif | |
34 | ||
1fd5e000 CF |
35 | #include <sys/types.h> |
36 | #include <sys/strace.h> | |
1fd5e000 | 37 | |
57c89867 | 38 | extern const char case_folded_lower[]; |
2556e737 | 39 | #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)]) |
57c89867 | 40 | extern const char case_folded_upper[]; |
2556e737 DD |
41 | #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)]) |
42 | ||
8db71e01 | 43 | #ifndef MALLOC_DEBUG |
8dec7b03 | 44 | #define cfree newlib_cfree_dont_use |
8db71e01 | 45 | #endif |
8dec7b03 | 46 | |
d0b178fe DD |
47 | #define WIN32_LEAN_AND_MEAN 1 |
48 | #define _WINGDI_H | |
49 | #define _WINUSER_H | |
50 | #define _WINNLS_H | |
51 | #define _WINVER_H | |
52 | #define _WINNETWK_H | |
53 | #define _WINSVC_H | |
1fd5e000 | 54 | #include <windows.h> |
1c0c369b | 55 | #include <wincrypt.h> |
17db1105 | 56 | #include <lmcons.h> |
d0b178fe DD |
57 | #undef _WINGDI_H |
58 | #undef _WINUSER_H | |
59 | #undef _WINNLS_H | |
60 | #undef _WINVER_H | |
61 | #undef _WINNETWK_H | |
62 | #undef _WINSVC_H | |
63 | ||
64 | /* The one function we use from winuser.h most of the time */ | |
65 | extern "C" DWORD WINAPI GetLastError (void); | |
1fd5e000 CF |
66 | |
67 | /* Used for runtime OS check/decisions. */ | |
84ecbb38 | 68 | enum os_type {winNT = 1, win95, win98, winME, win32s, unknown}; |
1fd5e000 | 69 | extern os_type os_being_run; |
e5ba4c06 | 70 | extern bool iswinnt; |
1fd5e000 | 71 | |
ee1d77e4 CF |
72 | enum codepage_type {ansi_cp, oem_cp}; |
73 | extern codepage_type current_codepage; | |
74 | ||
1fd5e000 CF |
75 | /* Used to check if Cygwin DLL is dynamically loaded. */ |
76 | extern int dynamically_loaded; | |
77 | ||
9fb628fc | 78 | #define sys_wcstombs(tgt,src,len) \ |
ee1d77e4 | 79 | WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL) |
9fb628fc | 80 | #define sys_mbstowcs(tgt,src,len) \ |
ee1d77e4 | 81 | MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len)) |
9fb628fc | 82 | |
1fd5e000 | 83 | #define TITLESIZE 1024 |
0c4d2abd | 84 | |
1fd5e000 CF |
85 | /* status bit manipulation */ |
86 | #define __ISSETF(what, x, prefix) \ | |
87 | ((what)->status & prefix##_##x) | |
88 | #define __SETF(what, x, prefix) \ | |
89 | ((what)->status |= prefix##_##x) | |
90 | #define __CLEARF(what, x, prefix) \ | |
91 | ((what)->status &= ~prefix##_##x) | |
92 | #define __CONDSETF(n, what, x, prefix) \ | |
93 | ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix)) | |
94 | ||
1fd5e000 | 95 | #include "debug.h" |
1fd5e000 CF |
96 | |
97 | /* Events/mutexes */ | |
1fd5e000 CF |
98 | extern HANDLE title_mutex; |
99 | ||
1fd5e000 CF |
100 | /**************************** Convenience ******************************/ |
101 | ||
1fd5e000 CF |
102 | /* Used when treating / and \ as equivalent. */ |
103 | #define SLASH_P(ch) \ | |
104 | ({ \ | |
105 | char __c = (ch); \ | |
106 | ((__c) == '/' || (__c) == '\\'); \ | |
107 | }) | |
108 | ||
109 | /* Convert a signal to a signal mask */ | |
110 | #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract)) | |
111 | extern unsigned int signal_shift_subtract; | |
112 | ||
a5a965ff CF |
113 | #ifdef NEW_MACRO_VARARGS |
114 | # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__) | |
115 | #else | |
116 | # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args) | |
117 | #endif | |
1fd5e000 CF |
118 | |
119 | #undef issep | |
120 | #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL) | |
121 | ||
122 | #define isdirsep SLASH_P | |
123 | #define isabspath(p) \ | |
42867d69 | 124 | (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2])))) |
1fd5e000 CF |
125 | |
126 | /******************** Initialization/Termination **********************/ | |
127 | ||
f0338f54 | 128 | class per_process; |
1fd5e000 | 129 | /* cygwin .dll initialization */ |
82c8d7ef | 130 | void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process"); |
44cac411 | 131 | extern "C" void __stdcall _dll_crt0 (); |
1fd5e000 CF |
132 | |
133 | /* dynamically loaded dll initialization */ | |
f0338f54 | 134 | extern "C" int dll_dllcrt0 (HMODULE, per_process *); |
1fd5e000 CF |
135 | |
136 | /* dynamically loaded dll initialization for non-cygwin apps */ | |
137 | extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *); | |
138 | ||
139 | /* exit the program */ | |
140 | extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn)); | |
141 | ||
1fd5e000 CF |
142 | /* UID/GID */ |
143 | void uinfo_init (void); | |
144 | ||
145 | /* various events */ | |
146 | void events_init (void); | |
147 | void events_terminate (void); | |
148 | ||
149 | void __stdcall close_all_files (void); | |
150 | ||
1fd5e000 CF |
151 | /* Invisible window initialization/termination. */ |
152 | HWND __stdcall gethwnd (void); | |
153 | void __stdcall window_terminate (void); | |
154 | ||
155 | /* Globals that handle initialization of winsock in a child process. */ | |
156 | extern HANDLE wsock32_handle; | |
afd5033d | 157 | extern HANDLE ws2_32_handle; |
1fd5e000 CF |
158 | |
159 | /* Globals that handle initialization of netapi in a child process. */ | |
160 | extern HANDLE netapi32_handle; | |
161 | ||
162 | /* debug_on_trap support. see exceptions.cc:try_to_debug() */ | |
163 | extern "C" void error_start_init (const char*); | |
8abeff1e | 164 | extern "C" int try_to_debug (bool waitloop = 1); |
1fd5e000 | 165 | |
4c15b7ab ED |
166 | void set_file_api_mode (codepage_type); |
167 | ||
2eb392bd CF |
168 | extern int cygwin_finished_initializing; |
169 | ||
1fd5e000 CF |
170 | /**************************** Miscellaneous ******************************/ |
171 | ||
1fd5e000 CF |
172 | void __stdcall set_std_handle (int); |
173 | int __stdcall writable_directory (const char *file); | |
174 | int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *); | |
175 | extern BOOL allow_ntsec; | |
176 | ||
166b2571 CF |
177 | unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2))); |
178 | void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2))); | |
179 | extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1))); | |
1fd5e000 | 180 | |
1fd5e000 | 181 | /* String manipulation */ |
166b2571 CF |
182 | extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c); |
183 | extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2))); | |
184 | extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3))); | |
185 | extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2))); | |
1fd5e000 CF |
186 | |
187 | /* Time related */ | |
188 | void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag); | |
189 | long __stdcall to_time_t (FILETIME * ptr); | |
190 | ||
1fd5e000 CF |
191 | void __stdcall set_console_title (char *); |
192 | void set_console_handler (); | |
193 | ||
7a4078ee CF |
194 | int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1))); |
195 | int __stdcall check_null_empty_str_errno (const char *name) __attribute__ ((regparm(1))); | |
196 | int __stdcall __check_null_invalid_struct (const void *s, unsigned sz) __attribute__ ((regparm(1))); | |
197 | int __stdcall __check_null_invalid_struct_errno (const void *s, unsigned sz) __attribute__ ((regparm(1))); | |
198 | ||
199 | #define check_null_invalid_struct(s) \ | |
200 | __check_null_invalid ((s), sizeof (*(s))) | |
201 | #define check_null_invalid_struct_errno(s) \ | |
202 | __check_null_invalid_struct_errno ((s), sizeof (*(s))) | |
203 | ||
829425c9 | 204 | #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__) |
c90e420d | 205 | void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2))); |
1fd5e000 | 206 | |
0a047e8f CF |
207 | extern bool wsock_started; |
208 | ||
f0338f54 CF |
209 | /* Printf type functions */ |
210 | extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn)); | |
c90e420d CF |
211 | extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/; |
212 | extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/; | |
f0338f54 | 213 | |
e2ea684e CF |
214 | extern "C" void __malloc_lock (struct _reent *); |
215 | extern "C" void __malloc_unlock (struct _reent *); | |
216 | ||
49eef6d5 CV |
217 | extern "C" void __malloc_lock (struct _reent *); |
218 | extern "C" void __malloc_unlock (struct _reent *); | |
219 | ||
1fd5e000 CF |
220 | /**************************** Exports ******************************/ |
221 | ||
222 | extern "C" { | |
223 | int cygwin_select (int , fd_set *, fd_set *, fd_set *, | |
224 | struct timeval *to); | |
225 | int cygwin_gethostname (char *__name, size_t __len); | |
226 | ||
227 | int kill_pgrp (pid_t, int); | |
228 | int _kill (int, int); | |
229 | int _raise (int sig); | |
230 | ||
53211514 | 231 | extern DWORD binmode; |
1fd5e000 CF |
232 | extern char _data_start__, _data_end__, _bss_start__, _bss_end__; |
233 | extern void (*__CTOR_LIST__) (void); | |
234 | extern void (*__DTOR_LIST__) (void); | |
2a6fc028 | 235 | extern SYSTEM_INFO system_info; |
1fd5e000 CF |
236 | }; |
237 | ||
238 | /*************************** Unsorted ******************************/ | |
239 | ||
1fd5e000 CF |
240 | #define WM_ASYNCIO 0x8000 // WM_APP |
241 | ||
242 | /* Note that MAX_PATH is defined in the windows headers */ | |
243 | /* There is also PATH_MAX and MAXPATHLEN. | |
244 | PATH_MAX is from Posix and does *not* include the trailing NUL. | |
245 | MAXPATHLEN is from Unix. | |
246 | ||
247 | Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL | |
248 | issue and is neither of the Unixy ones [so we can punt on which | |
249 | one is the right one to use]. */ | |
250 | ||
0cda2f46 CF |
251 | #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH) |
252 | #define STD_WBITS (S_IWUSR) | |
253 | #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH) | |
1fd5e000 | 254 | |
1fd5e000 CF |
255 | /* The title on program start. */ |
256 | extern char *old_title; | |
257 | extern BOOL display_title; | |
258 | ||
f0338f54 CF |
259 | extern HANDLE hMainThread; |
260 | extern HANDLE hMainProc; | |
261 | ||
4c8d72de | 262 | #endif /* defined __cplusplus */ |