]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/winsup.h
* dcrt0.cc (dll_crt0_1): Move exception list and constructor stuff earlier in
[newlib-cygwin.git] / winsup / cygwin / winsup.h
1 /* winsup.h: main Cygwin header file.
2
3 Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
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
17 #ifdef __cplusplus
18
19 #define alloca(x) __builtin_alloca (x)
20 #define strlen __builtin_strlen
21 #define strcpy __builtin_strcpy
22 #define memcpy __builtin_memcpy
23 #define memcmp __builtin_memcmp
24 #ifdef HAVE_BUILTIN_MEMSET
25 # define memset __builtin_memset
26 #endif
27
28 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
29 #define NEW_MACRO_VARARGS
30 #endif
31
32 #include <sys/types.h>
33 #include <sys/strace.h>
34 #include <sys/resource.h>
35 #include <setjmp.h>
36 #include <signal.h>
37 #include <string.h>
38
39 #undef strchr
40 #define strchr cygwin_strchr
41 extern "C" inline __stdcall char * strchr(const char * s, int c)
42 {
43 register char * __res;
44 __asm__ __volatile__(
45 "movb %%al,%%ah\n"
46 "1:\tmovb (%1),%%al\n\t"
47 "cmpb %%ah,%%al\n\t"
48 "je 2f\n\t"
49 "incl %1\n\t"
50 "testb %%al,%%al\n\t"
51 "jne 1b\n\t"
52 "xorl %1,%1\n"
53 "2:\tmovl %1,%0\n\t"
54 :"=a" (__res), "=r" (s)
55 :"0" (c), "1" (s));
56 return __res;
57 }
58
59 #define WIN32_LEAN_AND_MEAN 1
60 #define _WINGDI_H
61 #define _WINUSER_H
62 #define _WINNLS_H
63 #define _WINVER_H
64 #define _WINNETWK_H
65 #define _WINSVC_H
66 #include <windows.h>
67 #include <wincrypt.h>
68 #undef _WINGDI_H
69 #undef _WINUSER_H
70 #undef _WINNLS_H
71 #undef _WINVER_H
72 #undef _WINNETWK_H
73 #undef _WINSVC_H
74
75 /* The one function we use from winuser.h most of the time */
76 extern "C" DWORD WINAPI GetLastError (void);
77
78 /* Used for runtime OS check/decisions. */
79 enum os_type {winNT = 1, win95, win98, win32s, unknown};
80 extern os_type os_being_run;
81
82 /* Used to check if Cygwin DLL is dynamically loaded. */
83 extern int dynamically_loaded;
84
85 #define sys_wcstombs(tgt,src,len) \
86 WideCharToMultiByte(CP_ACP,0,(src),-1,(tgt),(len),NULL,NULL)
87 #define sys_mbstowcs(tgt,src,len) \
88 MultiByteToWideChar(CP_ACP,0,(src),-1,(tgt),(len))
89
90 #include <cygwin/version.h>
91
92 #define TITLESIZE 1024
93 #define MAX_USER_NAME 20
94 #define DEFAULT_UID 500
95 #define DEFAULT_GID 544
96
97 #define MAX_SID_LEN 40
98 #define MAX_HOST_NAME 256
99
100 /* status bit manipulation */
101 #define __ISSETF(what, x, prefix) \
102 ((what)->status & prefix##_##x)
103 #define __SETF(what, x, prefix) \
104 ((what)->status |= prefix##_##x)
105 #define __CLEARF(what, x, prefix) \
106 ((what)->status &= ~prefix##_##x)
107 #define __CONDSETF(n, what, x, prefix) \
108 ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
109
110 #include "shared.h"
111
112 extern HANDLE hMainThread;
113 extern HANDLE hMainProc;
114
115 #include "debug.h"
116 #include <sys/cygwin.h>
117
118 /********************** Application Interface **************************/
119
120 extern "C" per_process __cygwin_user_data; /* Pointer into application's static data */
121 #define user_data (&__cygwin_user_data)
122
123 /* We use the following to test that sizeof hasn't changed. When adding
124 or deleting members, insert fillers or use the reserved entries.
125 Do not change this value. */
126 #define SIZEOF_PER_PROCESS (42 * 4)
127
128 /******************* Host-dependent constants **********************/
129 /* Portions of the cygwin DLL require special constants whose values
130 are dependent on the host system. Rather than dynamically
131 determine those values whenever they are required, initialize these
132 values once at process start-up. */
133
134 class host_dependent_constants
135 {
136 public:
137 void init (void);
138
139 /* Used by fhandler_disk_file::lock which needs a platform-specific
140 upper word value for locking entire files. */
141 DWORD win32_upper;
142
143 /* fhandler_base::open requires host dependent file sharing
144 attributes. */
145 int shared;
146 };
147
148 extern host_dependent_constants host_dependent;
149
150 /* Events/mutexes */
151 extern HANDLE title_mutex;
152
153 /**************************** Convenience ******************************/
154
155 #define NO_COPY __attribute__((section(".data_cygwin_nocopy")))
156
157 /* Used when treating / and \ as equivalent. */
158 #define SLASH_P(ch) \
159 ({ \
160 char __c = (ch); \
161 ((__c) == '/' || (__c) == '\\'); \
162 })
163
164 /* Convert a signal to a signal mask */
165 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
166 extern unsigned int signal_shift_subtract;
167
168 #ifdef NOSTRACE
169 #define MARK() 0
170 #else
171 #define MARK() mark (__FILE__,__LINE__)
172 #endif
173
174 #ifdef NEW_MACRO_VARARGS
175 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
176 #else
177 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
178 #endif
179
180 #undef issep
181 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
182
183 #define isdirsep SLASH_P
184 #define isabspath(p) \
185 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
186
187 /******************** Initialization/Termination **********************/
188
189 /* cygwin .dll initialization */
190 void dll_crt0 (per_process *);
191 extern "C" void __stdcall _dll_crt0 ();
192
193 /* dynamically loaded dll initialization */
194 extern "C" int dll_dllcrt0 (HMODULE, per_process*);
195
196 /* dynamically loaded dll initialization for non-cygwin apps */
197 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
198
199 /* exit the program */
200 extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
201
202 /* Initialize the environment */
203 void environ_init (int);
204
205 /* Heap management. */
206 void heap_init (void);
207 void malloc_init (void);
208
209 /* UID/GID */
210 void uinfo_init (void);
211
212 /* various events */
213 void events_init (void);
214 void events_terminate (void);
215
216 void __stdcall close_all_files (void);
217
218 /* Invisible window initialization/termination. */
219 HWND __stdcall gethwnd (void);
220 void __stdcall window_terminate (void);
221
222 /* Globals that handle initialization of winsock in a child process. */
223 extern HANDLE wsock32_handle;
224
225 /* Globals that handle initialization of netapi in a child process. */
226 extern HANDLE netapi32_handle;
227
228 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
229 extern "C" void error_start_init (const char*);
230 extern "C" int try_to_debug ();
231
232 extern int cygwin_finished_initializing;
233
234 /**************************** Miscellaneous ******************************/
235
236 /* File manipulation */
237 int __stdcall set_process_privileges ();
238 int __stdcall get_file_attribute (int, const char *, int *,
239 uid_t * = NULL, gid_t * = NULL);
240 int __stdcall set_file_attribute (int, const char *, int);
241 int __stdcall set_file_attribute (int, const char *, uid_t, gid_t, int, const char *);
242 void __stdcall set_std_handle (int);
243 int __stdcall writable_directory (const char *file);
244 int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *);
245 extern BOOL allow_ntsec;
246
247 /* `lookup_name' should be called instead of LookupAccountName.
248 * logsrv may be NULL, in this case only the local system is used for lookup.
249 * The buffer for ret_sid (40 Bytes) has to be allocated by the caller! */
250 BOOL __stdcall lookup_name (const char *, const char *, PSID);
251 char *__stdcall convert_sid_to_string_sid (PSID, char *);
252 PSID __stdcall convert_string_sid_to_sid (PSID, const char *);
253 BOOL __stdcall get_pw_sid (PSID, struct passwd *);
254
255 unsigned long __stdcall hash_path_name (unsigned long hash, const char *name);
256 void __stdcall nofinalslash (const char *src, char *dst);
257 extern "C" char *__stdcall rootdir (char *full_path);
258
259 void __stdcall mark (const char *, int);
260
261 extern "C" int _spawnve (HANDLE hToken, int mode, const char *path,
262 const char *const *argv, const char *const *envp);
263
264 extern void __stdcall exec_fixup_after_fork ();
265
266 class _pinfo;
267 /* For mmaps across fork(). */
268 int __stdcall recreate_mmaps_after_fork (void *);
269 void __stdcall set_child_mmap_ptr (_pinfo *);
270
271 /* String manipulation */
272 char *__stdcall strccpy (char *s1, const char **s2, char c);
273 int __stdcall strcasematch (const char *s1, const char *s2);
274 int __stdcall strncasematch (const char *s1, const char *s2, size_t n);
275 char *__stdcall strcasestr (const char *searchee, const char *lookfor);
276
277 /* Time related */
278 void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
279 long __stdcall to_time_t (FILETIME * ptr);
280
281 /* pinfo table manipulation */
282 #ifndef lock_pinfo_for_update
283 int __stdcall lock_pinfo_for_update (DWORD timeout);
284 #endif
285 void unlock_pinfo (void);
286
287 /* Retrieve a security descriptor that allows all access */
288 SECURITY_DESCRIPTOR *__stdcall get_null_sd (void);
289
290 int __stdcall get_id_from_sid (PSID, BOOL);
291 extern inline int get_uid_from_sid (PSID psid) { return get_id_from_sid (psid, FALSE);}
292 extern inline int get_gid_from_sid (PSID psid) { return get_id_from_sid (psid, TRUE); }
293
294 int __stdcall NTReadEA (const char *file, const char *attrname, char *buf, int len);
295 BOOL __stdcall NTWriteEA (const char *file, const char *attrname, char *buf, int len);
296
297 void __stdcall set_console_title (char *);
298 void set_console_handler ();
299
300 void __stdcall fill_rusage (struct rusage *, HANDLE);
301 void __stdcall add_rusage (struct rusage *, struct rusage *);
302
303 void set_winsock_errno ();
304
305 /**************************** Exports ******************************/
306
307 extern "C" {
308 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
309 struct timeval *to);
310 int cygwin_gethostname (char *__name, size_t __len);
311
312 int kill_pgrp (pid_t, int);
313 int _kill (int, int);
314 int _raise (int sig);
315
316 int getfdtabsize ();
317 void setfdtabsize (int);
318
319 extern DWORD binmode;
320 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
321 extern void (*__CTOR_LIST__) (void);
322 extern void (*__DTOR_LIST__) (void);
323 };
324
325 /*************************** Unsorted ******************************/
326
327 #define WM_ASYNCIO 0x8000 // WM_APP
328
329 /* Note that MAX_PATH is defined in the windows headers */
330 /* There is also PATH_MAX and MAXPATHLEN.
331 PATH_MAX is from Posix and does *not* include the trailing NUL.
332 MAXPATHLEN is from Unix.
333
334 Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
335 issue and is neither of the Unixy ones [so we can punt on which
336 one is the right one to use]. */
337
338 /* Initial and increment values for cygwin's fd table */
339 #define NOFILE_INCR 32
340
341 #include <sys/reent.h>
342
343 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
344 #define STD_WBITS (S_IWUSR)
345 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
346
347 #define O_NOSYMLINK 0x080000
348 #define O_DIROPEN 0x100000
349
350 /*************************** Environment ******************************/
351
352 /* The structure below is used to control conversion to/from posix-style
353 * file specs. Currently, only PATH and HOME are converted, but PATH
354 * needs to use a "convert path list" function while HOME needs a simple
355 * "convert to posix/win32". For the simple case, where a calculated length
356 * is required, just return MAX_PATH. *FIXME*
357 */
358 struct win_env
359 {
360 const char *name;
361 size_t namelen;
362 char *posix;
363 char *native;
364 int (*toposix) (const char *, char *);
365 int (*towin32) (const char *, char *);
366 int (*posix_len) (const char *);
367 int (*win32_len) (const char *);
368 void add_cache (const char *in_posix, const char *in_native = NULL);
369 const char * get_native () {return native ? native + namelen : NULL;}
370 };
371
372 win_env * __stdcall getwinenv (const char *name, const char *posix = NULL);
373
374 void __stdcall update_envptrs ();
375 char * __stdcall winenv (const char * const *, int);
376 extern char **__cygwin_environ, ***main_environ;
377 extern "C" char __stdcall **cur_environ ();
378
379 /* The title on program start. */
380 extern char *old_title;
381 extern BOOL display_title;
382
383 #endif /* defined __cplusplus */
This page took 0.058262 seconds and 6 git commands to generate.