1 /* winsup.h: main Cygwin header file.
3 Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
15 #define __INSIDE_CYGWIN__
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
28 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
29 #define NEW_MACRO_VARARGS
32 #include <sys/types.h>
33 #include <sys/strace.h>
34 #include <sys/resource.h>
40 #define strchr cygwin_strchr
41 extern "C" inline __stdcall
char * strchr(const char * s
, int c
)
43 register char * __res
;
46 "1:\tmovb (%1),%%al\n\t"
54 :"=a" (__res
), "=r" (s
)
59 #define WIN32_LEAN_AND_MEAN 1
75 /* The one function we use from winuser.h most of the time */
76 extern "C" DWORD WINAPI
GetLastError (void);
78 /* Used for runtime OS check/decisions. */
79 enum os_type
{winNT
= 1, win95
, win98
, win32s
, unknown
};
80 extern os_type os_being_run
;
82 /* Used to check if Cygwin DLL is dynamically loaded. */
83 extern int dynamically_loaded
;
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))
90 #include <cygwin/version.h>
92 #define TITLESIZE 1024
93 #define MAX_USER_NAME 20
94 #define DEFAULT_UID 500
95 #define DEFAULT_GID 544
97 #define MAX_SID_LEN 40
98 #define MAX_HOST_NAME 256
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))
112 extern HANDLE hMainThread
;
113 extern HANDLE hMainProc
;
116 #include <sys/cygwin.h>
118 /********************** Application Interface **************************/
120 extern "C" per_process __cygwin_user_data
; /* Pointer into application's static data */
121 #define user_data (&__cygwin_user_data)
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)
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. */
134 class host_dependent_constants
139 /* Used by fhandler_disk_file::lock which needs a platform-specific
140 upper word value for locking entire files. */
143 /* fhandler_base::open requires host dependent file sharing
148 extern host_dependent_constants host_dependent
;
151 extern HANDLE title_mutex
;
153 /**************************** Convenience ******************************/
155 #define NO_COPY __attribute__((section(".data_cygwin_nocopy")))
157 /* Used when treating / and \ as equivalent. */
158 #define SLASH_P(ch) \
161 ((__c) == '/' || (__c) == '\\'); \
164 /* Convert a signal to a signal mask */
165 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
166 extern unsigned int signal_shift_subtract
;
171 #define MARK() mark (__FILE__,__LINE__)
174 #ifdef NEW_MACRO_VARARGS
175 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
177 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
181 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
183 #define isdirsep SLASH_P
184 #define isabspath(p) \
185 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
187 /******************** Initialization/Termination **********************/
189 /* cygwin .dll initialization */
190 void dll_crt0 (per_process
*);
191 extern "C" void __stdcall
_dll_crt0 ();
193 /* dynamically loaded dll initialization */
194 extern "C" int dll_dllcrt0 (HMODULE
, per_process
*);
196 /* dynamically loaded dll initialization for non-cygwin apps */
197 extern "C" int dll_noncygwin_dllcrt0 (HMODULE
, per_process
*);
199 /* exit the program */
200 extern "C" void __stdcall
do_exit (int) __attribute__ ((noreturn
));
202 /* Initialize the environment */
203 void environ_init (int);
205 /* Heap management. */
206 void heap_init (void);
207 void malloc_init (void);
210 void uinfo_init (void);
213 void events_init (void);
214 void events_terminate (void);
216 void __stdcall
close_all_files (void);
218 /* Invisible window initialization/termination. */
219 HWND __stdcall
gethwnd (void);
220 void __stdcall
window_terminate (void);
222 /* Globals that handle initialization of winsock in a child process. */
223 extern HANDLE wsock32_handle
;
225 /* Globals that handle initialization of netapi in a child process. */
226 extern HANDLE netapi32_handle
;
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 ();
232 extern int cygwin_finished_initializing
;
234 /**************************** Miscellaneous ******************************/
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
;
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
*);
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
);
259 void __stdcall
mark (const char *, int);
261 extern "C" int _spawnve (HANDLE hToken
, int mode
, const char *path
,
262 const char *const *argv
, const char *const *envp
);
264 extern void __stdcall
exec_fixup_after_fork ();
267 /* For mmaps across fork(). */
268 int __stdcall
recreate_mmaps_after_fork (void *);
269 void __stdcall
set_child_mmap_ptr (_pinfo
*);
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
);
278 void __stdcall
totimeval (struct timeval
*dst
, FILETIME
* src
, int sub
, int flag
);
279 long __stdcall
to_time_t (FILETIME
* ptr
);
281 /* pinfo table manipulation */
282 #ifndef lock_pinfo_for_update
283 int __stdcall
lock_pinfo_for_update (DWORD timeout
);
285 void unlock_pinfo (void);
287 /* Retrieve a security descriptor that allows all access */
288 SECURITY_DESCRIPTOR
*__stdcall
get_null_sd (void);
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
); }
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
);
297 void __stdcall
set_console_title (char *);
298 void set_console_handler ();
300 void __stdcall
fill_rusage (struct rusage
*, HANDLE
);
301 void __stdcall
add_rusage (struct rusage
*, struct rusage
*);
303 void set_winsock_errno ();
305 /**************************** Exports ******************************/
308 int cygwin_select (int , fd_set
*, fd_set
*, fd_set
*,
310 int cygwin_gethostname (char *__name
, size_t __len
);
312 int kill_pgrp (pid_t
, int);
313 int _kill (int, int);
314 int _raise (int sig
);
317 void setfdtabsize (int);
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);
325 /*************************** Unsorted ******************************/
327 #define WM_ASYNCIO 0x8000 // WM_APP
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.
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]. */
338 /* Initial and increment values for cygwin's fd table */
339 #define NOFILE_INCR 32
341 #include <sys/reent.h>
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)
347 #define O_NOSYMLINK 0x080000
348 #define O_DIROPEN 0x100000
350 /*************************** Environment ******************************/
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*
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
;}
372 win_env
* __stdcall
getwinenv (const char *name
, const char *posix
= NULL
);
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 ();
379 /* The title on program start. */
380 extern char *old_title
;
381 extern BOOL display_title
;
383 #endif /* defined __cplusplus */