1 /* winsup.h: main Cygwin header file.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006 Red Hat, Inc.
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #define spf(a, b, c) small_printf (a, b, c)
15 #define spf(a, b, c) do {} while (0)
22 #define __INSIDE_CYGWIN__
24 #define strlen __builtin_strlen
25 #define strcmp __builtin_strcmp
26 #define strcpy __builtin_strcpy
27 #define memcpy __builtin_memcpy
28 #define memcmp __builtin_memcmp
29 #ifdef HAVE_BUILTIN_MEMSET
30 # define memset __builtin_memset
33 #define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
34 #define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
36 #define EXPORT_ALIAS(sym,symalias) extern "C" __typeof (sym) symalias __attribute__ ((alias(#sym)));
39 #define _NO_W32_PSEUDO_MODIFIERS
41 #include <sys/types.h>
42 #include <sys/strace.h>
44 /* Declarations for functions used in C and C++ code. */
48 extern __uid32_t getuid32 (void);
49 extern __uid32_t geteuid32 (void);
50 extern int seteuid32 (__uid32_t);
51 extern __gid32_t getegid32 (void);
52 extern struct passwd *getpwuid32 (__uid32_t);
53 extern struct passwd *getpwnam (const char *);
54 extern struct __sFILE64 *fopen64 (const char *, const char *);
55 extern struct hostent *cygwin_gethostbyname (const char *name);
56 extern unsigned long cygwin_inet_addr (const char *cp);
62 /* Note that MAX_PATH is defined in the windows headers */
63 /* There is also PATH_MAX and MAXPATHLEN.
64 PATH_MAX is from Posix and does *not* include the trailing NUL.
65 MAXPATHLEN is from Unix.
67 Thou shalt use CYG_MAX_PATH throughout. It avoids the NUL vs no-NUL
68 issue and is neither of the Unixy ones [so we can punt on which
69 one is the right one to use].
71 Windows ANSI calls are limited to MAX_PATH in length. Cygwin calls that
72 thunk through to Windows Wide calls are limited to 32K. We define
73 CYG_MAX_PATH as a convenient, not to short, not too long 'happy medium'.
77 #define CYG_MAX_PATH (MAX_PATH)
81 extern const char case_folded_lower[];
82 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
83 extern const char case_folded_upper[];
84 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
87 #define cfree newlib_cfree_dont_use
90 #define WIN32_LEAN_AND_MEAN 1
109 /* The one function we use from winuser.h most of the time */
110 extern "C" DWORD WINAPI GetLastError (void);
112 enum codepage_type {ansi_cp, oem_cp};
113 extern codepage_type current_codepage;
117 int __stdcall sys_wcstombs(char *, int, const WCHAR *, int = -1)
118 __attribute__ ((regparm(3)));
120 int __stdcall sys_mbstowcs(WCHAR *, const char *, int)
121 __attribute__ ((regparm(3)));
123 /* Used to check if Cygwin DLL is dynamically loaded. */
124 extern int dynamically_loaded;
126 extern int cygserver_running;
128 #define _MT_SAFE // DELTEME someday
130 #define TITLESIZE 1024
135 extern HANDLE tty_mutex;
137 /**************************** Convenience ******************************/
139 /* Used to define status flag accessor methods */
140 #define IMPLEMENT_STATUS_FLAG(type,flag) \
141 void flag (type val) { status.flag = (val); } \
142 type flag () const { return (type) status.flag; }
144 /* Used when treating / and \ as equivalent. */
145 #define isdirsep(ch) \
148 ((__c) == '/' || (__c) == '\\'); \
151 /* Convert a signal to a signal mask */
152 #define SIGTOMASK(sig) (1 << ((sig) - signal_shift_subtract))
153 extern unsigned int signal_shift_subtract;
155 extern int __api_fatal_exit_val;
156 #define set_api_fatal_return(n) do {extern int __api_fatal_exit_val; __api_fatal_exit_val = (n);} while (0)
157 #define api_fatal(fmt, args...) __api_fatal (fmt,## args)
160 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
162 #define isabspath(p) \
163 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
165 /******************** Initialization/Termination **********************/
168 /* cygwin .dll initialization */
169 void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
170 extern "C" void __stdcall _dll_crt0 ();
171 extern void dll_crt0_1 (void *);
172 extern void dll_dllcrt0_1 (void *);
174 /* dynamically loaded dll initialization */
175 extern "C" int dll_dllcrt0 (HMODULE, per_process *);
177 /* dynamically loaded dll initialization for non-cygwin apps */
178 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
180 /* exit the program */
199 extern exit_states exit_state;
200 void __stdcall do_exit (int) __attribute__ ((regparm (1), noreturn));
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)
211 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
212 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
214 /* Convert LARGE_INTEGER into long long */
215 #define get_ll(pl) (((long long) (pl).HighPart << 32) | (pl).LowPart)
219 void events_terminate ();
221 void __stdcall close_all_files (bool = false);
223 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
224 extern "C" void error_start_init (const char*);
225 extern "C" int try_to_debug (bool waitloop = 1);
227 extern void ld_preload ();
229 void set_file_api_mode (codepage_type);
231 extern bool cygwin_finished_initializing;
233 /**************************** Miscellaneous ******************************/
235 void __stdcall set_std_handle (int);
236 int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
238 __ino64_t __stdcall hash_path_name (__ino64_t hash, const char *name) __attribute__ ((regparm(2)));
239 void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
240 extern "C" char *__stdcall rootdir (const char *full_path, char *root_path) __attribute__ ((regparm(2)));
242 /* String manipulation */
243 extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
244 extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
245 extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
246 extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
248 void *hook_or_detect_cygwin (const char *, const void *, WORD&) __attribute__ ((regparm (3)));
251 void __stdcall totimeval (struct timeval *, FILETIME *, int, int);
252 long __stdcall to_time_t (FILETIME *);
253 void __stdcall to_timestruc_t (FILETIME *, timestruc_t *);
254 void __stdcall time_as_timestruc_t (timestruc_t *);
255 void __stdcall timeval_to_filetime (const struct timeval *, FILETIME *);
257 /* Console related */
258 void __stdcall set_console_title (char *);
259 void init_console_handler (bool);
261 void init_global_security ();
263 int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
265 ssize_t check_iovec (const struct iovec *, int, bool) __attribute__ ((regparm(3)));
266 #define check_iovec_for_read(a, b) check_iovec ((a), (b), false)
267 #define check_iovec_for_write(a, b) check_iovec ((a), (b), true)
269 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
270 void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
272 extern bool wsock_started;
274 /* Printf type functions */
275 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
276 extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
277 extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
278 extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
280 extern "C" void vklog (int priority, const char *message, va_list ap);
281 extern "C" void klog (int priority, const char *message, ...);
282 bool child_copy (HANDLE, bool, ...);
284 int symlink_worker (const char *, const char *, bool, bool)
285 __attribute__ ((regparm (3)));
289 int fcntl_worker (int fd, int cmd, void *arg);
291 __ino64_t __stdcall readdir_get_ino (struct __DIR *dir, const char *path, bool dot_dot) __attribute__ ((regparm (3)));
293 extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
294 #define SLEEP_0_STAY_LOW INFINITE
296 /* Returns the real page size, not the allocation size. */
297 size_t getsystempagesize ();
299 /* mmap functions. */
301 enum mmap_region_status
305 MMAP_NORESERVE_COMMITED
307 mmap_region_status mmap_is_attached_or_noreserve (void *addr, size_t len);
309 int winprio_to_nice (DWORD) __attribute__ ((regparm (1)));
310 DWORD nice_to_winprio (int &) __attribute__ ((regparm (1)));
312 bool __stdcall create_pipe (PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD)
313 __attribute__ ((regparm (3)));
314 #define CreatePipe create_pipe
316 inline bool flush_file_buffers (HANDLE h)
318 return (GetFileType (h) != FILE_TYPE_PIPE) ? FlushFileBuffers (h) : true;
320 #define FlushFileBuffers flush_file_buffers
322 /**************************** Exports ******************************/
325 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
327 int cygwin_gethostname (char *__name, size_t __len);
329 extern DWORD binmode;
330 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
331 extern void (*__CTOR_LIST__) (void);
332 extern void (*__DTOR_LIST__) (void);
333 extern SYSTEM_INFO system_info;
336 /*************************** Unsorted ******************************/
338 #define WM_ASYNCIO 0x8000 // WM_APP
341 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
342 #define STD_WBITS (S_IWUSR)
343 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
344 #define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
345 #define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
346 #define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
348 /* The title on program start. */
349 extern char *old_title;
350 extern bool display_title;
351 extern bool transparent_exe;
353 extern bool in_forkee;
354 extern bool in_dllentry;
356 extern HANDLE hMainThread;
357 extern HANDLE hMainProc;
358 extern HANDLE hProcToken;
359 extern HANDLE hProcImpToken;
360 extern HANDLE hExeced;
361 extern HMODULE cygwin_hmodule;
363 extern bool cygwin_testing;
365 extern char almost_null[];
367 #endif /* defined __cplusplus */