]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/winsup.h
cd698ba56da0d4cfb9960ae7f1910da63e229855
[newlib-cygwin.git] / winsup / cygwin / winsup.h
1 /* winsup.h: main Cygwin header file.
2
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
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 DEBUGIT
12 #define spf(a, b, c) small_printf (a, b, c)
13 #else
14 #define spf(a, b, c) do {} while (0)
15 #endif
16
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
20
21 #define __INSIDE_CYGWIN__
22
23 #define strlen __builtin_strlen
24 #define strcmp __builtin_strcmp
25 #define strcpy __builtin_strcpy
26 #define memcpy __builtin_memcpy
27 #define memcmp __builtin_memcmp
28 #ifdef HAVE_BUILTIN_MEMSET
29 # define memset __builtin_memset
30 #endif
31
32 #define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
33 #define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
34
35 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
36 #define NEW_MACRO_VARARGS
37 #endif
38
39 #ifndef _WIN32_WINNT
40 #define _WIN32_WINNT 0x0500
41 #endif
42
43 #include <sys/types.h>
44 #include <sys/strace.h>
45
46 /* Declarations for functions used in C and C++ code. */
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 extern __uid32_t getuid32 (void);
51 extern __uid32_t geteuid32 (void);
52 extern int seteuid32 (__uid32_t);
53 extern __gid32_t getegid32 (void);
54 extern struct passwd *getpwuid32 (__uid32_t);
55 extern struct passwd *getpwnam (const char *);
56 extern struct __sFILE64 *fopen64 (const char *, const char *);
57 extern struct hostent *cygwin_gethostbyname (const char *name);
58 extern unsigned long cygwin_inet_addr (const char *cp);
59
60 #ifdef __cplusplus
61 }
62 #endif
63
64 /* Note that MAX_PATH is defined in the windows headers */
65 /* There is also PATH_MAX and MAXPATHLEN.
66 PATH_MAX is from Posix and does *not* include the trailing NUL.
67 MAXPATHLEN is from Unix.
68
69 Thou shalt use CYG_MAX_PATH throughout. It avoids the NUL vs no-NUL
70 issue and is neither of the Unixy ones [so we can punt on which
71 one is the right one to use].
72
73 Windows ANSI calls are limited to MAX_PATH in length. Cygwin calls that
74 thunk through to Windows Wide calls are limited to 32K. We define
75 CYG_MAX_PATH as a convenient, not to short, not too long 'happy medium'.
76
77 */
78
79 #define CYG_MAX_PATH (MAX_PATH)
80
81 #ifdef __cplusplus
82
83 extern const char case_folded_lower[];
84 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
85 extern const char case_folded_upper[];
86 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
87
88 #ifndef MALLOC_DEBUG
89 #define cfree newlib_cfree_dont_use
90 #endif
91
92 #define WIN32_LEAN_AND_MEAN 1
93 #define _WINGDI_H
94 #define _WINUSER_H
95 #define _WINNLS_H
96 #define _WINVER_H
97 #define _WINNETWK_H
98 #define _WINSVC_H
99 #include <windows.h>
100 #include <wincrypt.h>
101 #include <lmcons.h>
102 #undef _WINGDI_H
103 #undef _WINUSER_H
104 #undef _WINNLS_H
105 #undef _WINVER_H
106 #undef _WINNETWK_H
107 #undef _WINSVC_H
108
109 #include "wincap.h"
110
111 /* The one function we use from winuser.h most of the time */
112 extern "C" DWORD WINAPI GetLastError (void);
113
114 enum codepage_type {ansi_cp, oem_cp};
115 extern codepage_type current_codepage;
116
117 UINT get_cp ();
118
119 int __stdcall sys_wcstombs(char *, const WCHAR *, int)
120 __attribute__ ((regparm(3)));
121
122 int __stdcall sys_mbstowcs(WCHAR *, const char *, int)
123 __attribute__ ((regparm(3)));
124
125 /* Used to check if Cygwin DLL is dynamically loaded. */
126 extern int dynamically_loaded;
127
128 extern int cygserver_running;
129
130 #define _MT_SAFE // DELTEME someday
131
132 #define TITLESIZE 1024
133
134 #include "debug.h"
135
136 /* Events/mutexes */
137 extern HANDLE title_mutex;
138
139 /**************************** Convenience ******************************/
140
141 /* Used to define status flag accessor methods */
142 #define IMPLEMENT_STATUS_FLAG(type,flag) \
143 void flag (type val) { status.flag = (val); } \
144 type flag () const { return (type) status.flag; }
145
146 /* Used when treating / and \ as equivalent. */
147 #define isdirsep(ch) \
148 ({ \
149 char __c = (ch); \
150 ((__c) == '/' || (__c) == '\\'); \
151 })
152
153 /* Convert a signal to a signal mask */
154 #define SIGTOMASK(sig) (1 << ((sig) - signal_shift_subtract))
155 extern unsigned int signal_shift_subtract;
156
157 #ifdef NEW_MACRO_VARARGS
158 # define api_fatal(...) __api_fatal (__VA_ARGS__)
159 #else
160 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
161 #endif
162
163 #undef issep
164 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
165
166 #define isabspath(p) \
167 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
168
169 /******************** Initialization/Termination **********************/
170
171 class per_process;
172 /* cygwin .dll initialization */
173 void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
174 extern "C" void __stdcall _dll_crt0 ();
175
176 /* dynamically loaded dll initialization */
177 extern "C" int dll_dllcrt0 (HMODULE, per_process *);
178
179 /* dynamically loaded dll initialization for non-cygwin apps */
180 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
181
182 /* exit the program */
183
184 enum exit_states
185 {
186 ES_NOT_EXITING = 0,
187 ES_EVENTS_TERMINATE,
188 ES_THREADTERM,
189 ES_SIGNAL,
190 ES_CLOSEALL,
191 ES_SIGPROCTERMINATE,
192 ES_TITLE,
193 ES_HUP_PGRP,
194 ES_HUP_SID,
195 ES_TTY_TERMINATE,
196 ES_FINAL
197 };
198
199 extern exit_states exit_state;
200 void __stdcall do_exit (int) __attribute__ ((regparm (1), noreturn));
201
202 /* UID/GID */
203 void uinfo_init (void);
204
205 #define ILLEGAL_UID16 ((__uid16_t)-1)
206 #define ILLEGAL_UID ((__uid32_t)-1)
207 #define ILLEGAL_GID16 ((__gid16_t)-1)
208 #define ILLEGAL_GID ((__gid32_t)-1)
209 #define ILLEGAL_SEEK ((_off64_t)-1)
210
211 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
212 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
213
214 /* various events */
215 void events_init (void);
216 void events_terminate (void);
217
218 void __stdcall close_all_files ();
219
220 /* Check if running in a visible window station. */
221 extern bool has_visible_window_station (void);
222
223 /* Globals that handle initialization of winsock in a child process. */
224 extern HANDLE wsock32_handle;
225 extern HANDLE ws2_32_handle;
226
227 /* Globals that handle initialization of netapi in a child process. */
228 extern HANDLE netapi32_handle;
229
230 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
231 extern "C" void error_start_init (const char*);
232 extern "C" int try_to_debug (bool waitloop = 1);
233
234 void set_file_api_mode (codepage_type);
235
236 extern bool cygwin_finished_initializing;
237
238 /**************************** Miscellaneous ******************************/
239
240 void __stdcall set_std_handle (int);
241 int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
242
243 __ino64_t __stdcall hash_path_name (__ino64_t hash, const char *name) __attribute__ ((regparm(2)));
244 void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
245 extern "C" char *__stdcall rootdir (const char *full_path, char *root_path) __attribute__ ((regparm(2)));
246
247 /* String manipulation */
248 extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
249 extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
250 extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
251 extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
252
253 /* Time related */
254 void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
255 long __stdcall to_time_t (FILETIME * ptr);
256 void __stdcall to_timestruc_t (FILETIME * ptr, timestruc_t * out);
257 void __stdcall time_as_timestruc_t (timestruc_t * out);
258
259 void __stdcall set_console_title (char *);
260 void init_console_handler ();
261 void init_global_security ();
262
263 int __stdcall check_null_str (const char *name) __attribute__ ((regparm(1)));
264 int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1)));
265 int __stdcall check_null_empty_str_errno (const char *name) __attribute__ ((regparm(1)));
266 int __stdcall check_null_str_errno (const char *name) __attribute__ ((regparm(1)));
267 int __stdcall __check_null_invalid_struct (void *s, unsigned sz) __attribute__ ((regparm(2)));
268 int __stdcall __check_null_invalid_struct_errno (void *s, unsigned sz) __attribute__ ((regparm(2)));
269 int __stdcall __check_invalid_read_ptr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
270 int __stdcall __check_invalid_read_ptr_errno (const void *s, unsigned sz) __attribute__ ((regparm(2)));
271 int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
272
273 #define check_null_invalid_struct(s) \
274 __check_null_invalid_struct ((s), sizeof (*(s)))
275 #define check_null_invalid_struct_errno(s) \
276 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
277 #define check_invalid_read_struct_errno(s) \
278 __check_invalid_read_ptr_errno ((s), sizeof (*(s)))
279
280 struct iovec;
281 ssize_t check_iovec_for_read (const struct iovec *, int) __attribute__ ((regparm(2)));
282 ssize_t check_iovec_for_write (const struct iovec *, int) __attribute__ ((regparm(2)));
283
284 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
285 void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
286
287 extern bool wsock_started;
288
289 /* Printf type functions */
290 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
291 extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
292 extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
293 extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
294
295 int symlink_worker (const char *, const char *, bool, bool)
296 __attribute__ ((regparm (3)));
297
298 class path_conv;
299
300 int fcntl_worker (int fd, int cmd, void *arg);
301
302 extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
303 #define SLEEP_0_STAY_LOW INFINITE
304
305 size_t getshmlba (void);
306
307 /**************************** Exports ******************************/
308
309 extern "C" {
310 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
311 struct timeval *to);
312 int cygwin_gethostname (char *__name, size_t __len);
313
314 extern DWORD binmode;
315 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
316 extern void (*__CTOR_LIST__) (void);
317 extern void (*__DTOR_LIST__) (void);
318 extern SYSTEM_INFO system_info;
319 };
320
321 /*************************** Unsorted ******************************/
322
323 #define WM_ASYNCIO 0x8000 // WM_APP
324
325
326 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
327 #define STD_WBITS (S_IWUSR)
328 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
329 #define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
330 #define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
331 #define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
332
333 /* The title on program start. */
334 extern char *old_title;
335 extern bool display_title;
336
337 extern HANDLE hMainThread;
338 extern HANDLE hMainProc;
339
340 extern bool cygwin_testing;
341
342 extern char almost_null[];
343
344 #define winsock2_active (wsadata.wVersion >= 512)
345 extern struct WSAData wsadata;
346
347 #endif /* defined __cplusplus */
This page took 0.055009 seconds and 5 git commands to generate.