]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/winsup.h
* Merge in cygwin-64bit-branch.
[newlib-cygwin.git] / winsup / cygwin / winsup.h
CommitLineData
1fd5e000
CF
1/* winsup.h: main Cygwin header file.
2
6e75c72b
CF
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc.
1fd5e000
CF
5
6This file is part of Cygwin.
7
8This software is a copyrighted work licensed under the terms of the
9Cygwin license. Please consult the file "CYGWIN_LICENSE" for
10details. */
11
4c36016b 12#include "config.h"
1fd5e000
CF
13
14#define __INSIDE_CYGWIN__
15
61522196 16#define NO_COPY_RO __attribute__((nocommon)) __attribute__((section(".rdata_cygwin_nocopy")))
60b68f0d 17#define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
066ca06f 18#define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
0a047e8f 19
4875a4b6
CV
20#define EXPORT_ALIAS(sym,symalias) extern "C" __typeof (sym) symalias __attribute__ ((alias(#sym)));
21
a0292494
CV
22/* Fun, fun, fun. On Mingw64, WINVER is set according to the value of
23 _WIN32_WINNT, on Mingw32 it's exactly the opposite... */
24#define _WIN32_WINNT 0x0602
25#define WINVER 0x0602
26
bf4875e4 27#define _NO_W32_PSEUDO_MODIFIERS
5c0469b4 28
1fd5e000
CF
29#include <sys/types.h>
30#include <sys/strace.h>
1fd5e000 31
932a40e8 32/* Declarations for functions used in C and C++ code. */
b1aae492
CV
33#ifdef __cplusplus
34extern "C" {
35#endif
61522196
CV
36uid_t getuid32 ();
37uid_t geteuid32 ();
38int seteuid32 (uid_t);
39gid_t getegid32 (void);
40struct passwd *getpwuid32 (uid_t);
66a83f3e
CF
41struct passwd *getpwnam (const char *);
42struct __sFILE64 *fopen64 (const char *, const char *);
43struct hostent *cygwin_gethostbyname (const char *name);
316d9cab 44/* Don't enforce definition of in_addr_t. */
66a83f3e
CF
45uint32_t cygwin_inet_addr (const char *cp);
46int fcntl64 (int fd, int cmd, ...);
b1aae492
CV
47#ifdef __cplusplus
48}
49#endif
50
95d02d5b
RC
51/* Note that MAX_PATH is defined in the windows headers */
52/* There is also PATH_MAX and MAXPATHLEN.
7b4b41ab 53 PATH_MAX is from Posix and does include the trailing NUL.
95d02d5b
RC
54 MAXPATHLEN is from Unix.
55
a66789a0
CV
56 Thou shalt *not* use CYG_MAX_PATH anymore. Use NT_MAX_PATH or
57 dynamic allocation instead when accessing real files. Use
58 MAX_PATH in case you need a convenient small buffer when creating
59 names for synchronization objects or named pipes. */
95d02d5b
RC
60#define CYG_MAX_PATH (MAX_PATH)
61
7b4b41ab
CV
62/* There's no define for the maximum path length the NT kernel can handle.
63 That's why we define our own to use in path length test and for path
64 buffer sizes. As MAX_PATH and PATH_MAX, this is defined including the
65 trailing 0. Internal buffers and internal path routines should use
66 NT_MAX_PATH. PATH_MAX as defined in limits.h is the maximum length of
edab6053
CV
67 application provided path strings we handle. */
68#define NT_MAX_PATH 32768
7b4b41ab 69
b18cb86b
CV
70/* This definition allows to define wide char strings using macros as
71 parameters. See the definition of __CONCAT in newlib's sys/cdefs.h
72 and accompanying comment. */
73#define __WIDE(a) L ## a
74#define _WIDE(a) __WIDE(a)
75
6902b88b
CV
76#include "winlean.h"
77
b1aae492
CV
78#ifdef __cplusplus
79
6902b88b 80#include "wincap.h"
61522196 81#include "regparm.h"
6902b88b 82
61522196
CV
83extern const unsigned char case_folded_lower[];
84#define cyg_tolower(c) ((char) case_folded_lower[(unsigned char)(c)])
85extern const unsigned char case_folded_upper[];
86#define cyg_toupper(c) ((char) case_folded_upper[(unsigned char)(c)])
2556e737 87
8db71e01 88#ifndef MALLOC_DEBUG
8dec7b03 89#define cfree newlib_cfree_dont_use
8db71e01 90#endif
8dec7b03 91
1597484c
CV
92/* Used as type by sys_wcstombs_alloc and sys_mbstowcs_alloc. For a
93 description see there. */
94#define HEAP_NOTHEAP -1
95
1fd5e000 96/* Used to check if Cygwin DLL is dynamically loaded. */
1fd5e000 97
f279e522 98extern int cygserver_running;
9fb628fc 99
6452eb1f 100#define _MT_SAFE // DELETEME someday
3872e9a4 101
1fd5e000 102#define TITLESIZE 1024
0c4d2abd 103
1fd5e000 104#include "debug.h"
1fd5e000 105
62755474
CV
106#include <wchar.h>
107
1fd5e000
CF
108/**************************** Convenience ******************************/
109
825b3882
CV
110/* Used to define status flag accessor methods */
111#define IMPLEMENT_STATUS_FLAG(type,flag) \
fc261e53 112 type flag (type val) { return (type) (status.flag = (val)); } \
825b3882
CV
113 type flag () const { return (type) status.flag; }
114
1fd5e000 115/* Used when treating / and \ as equivalent. */
855e63eb
CV
116#define iswdirsep(ch) \
117 ({ \
118 WCHAR __c = (ch); \
119 ((__c) == L'/' || (__c) == L'\\'); \
120 })
121
85ba109d 122#define isdirsep(ch) \
1fd5e000
CF
123 ({ \
124 char __c = (ch); \
125 ((__c) == '/' || (__c) == '\\'); \
126 })
127
128/* Convert a signal to a signal mask */
70300fdb 129#define SIGTOMASK(sig) (1 << ((sig) - 1))
1fd5e000 130
84d38174 131#define set_api_fatal_return(n) do {extern int __api_fatal_exit_val; __api_fatal_exit_val = (n);} while (0)
1fd5e000
CF
132
133#undef issep
134#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
135
855e63eb
CV
136/* Every path beginning with / or \, as well as every path being X:
137 or starting with X:/ or X:\ */
138#define isabspath_u(p) \
139 ((p)->Length && \
140 (iswdirsep ((p)->Buffer[0]) || \
141 ((p)->Length > sizeof (WCHAR) && iswalpha ((p)->Buffer[0]) \
142 && (p)->Buffer[1] == L':' && \
143 ((p)->Length == 2 * sizeof (WCHAR) || iswdirsep ((p)->Buffer[2])))))
144
145#define iswabspath(p) \
146 (iswdirsep (*(p)) || (iswalpha (*(p)) && (p)[1] == L':' && (!(p)[2] || iswdirsep ((p)[2]))))
147
1fd5e000 148#define isabspath(p) \
42867d69 149 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
1fd5e000
CF
150
151/******************** Initialization/Termination **********************/
152
f0338f54 153class per_process;
1fd5e000 154/* cygwin .dll initialization */
61522196 155void dll_crt0 (per_process *) __asm__ (_SYMSTR (dll_crt0__FP11per_process));
44cac411 156extern "C" void __stdcall _dll_crt0 ();
66a83f3e
CF
157void dll_crt0_1 (void *);
158void dll_dllcrt0_1 (void *);
1fd5e000
CF
159
160/* dynamically loaded dll initialization */
61522196 161extern "C" PVOID dll_dllcrt0 (HMODULE, per_process *);
1fd5e000 162
1809b65e 163extern "C" void _pei386_runtime_relocator (per_process *);
27f564e9 164
61522196 165#ifndef __x86_64__
1fd5e000
CF
166/* dynamically loaded dll initialization for non-cygwin apps */
167extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
61522196
CV
168#endif /* !__x86_64__ */
169
6e75c72b 170void __reg1 do_exit (int) __attribute__ ((noreturn));
1fd5e000 171
b602bb90
DK
172/* libstdc++ malloc operator wrapper support. */
173extern struct per_process_cxx_malloc default_cygwin_cxx_malloc;
174
1fd5e000 175/* UID/GID */
2f9ae2ed 176void uinfo_init ();
1fd5e000 177
61522196
CV
178#define ILLEGAL_UID ((uid_t)-1)
179#define ILLEGAL_GID ((gid_t)-1)
180#define ILLEGAL_SEEK ((off_t)-1)
181
182#ifndef __x86_64__
a8d7ae61 183#define ILLEGAL_UID16 ((__uid16_t)-1)
a8d7ae61 184#define ILLEGAL_GID16 ((__gid16_t)-1)
61522196
CV
185#define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(uid_t)(u16))
186#define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(gid_t)(g16))
187#endif
a8d7ae61 188
29acee40
CF
189/* Convert LARGE_INTEGER into long long */
190#define get_ll(pl) (((long long) (pl).HighPart << 32) | (pl).LowPart)
191
1fd5e000 192/* various events */
2f9ae2ed 193void events_init ();
1fd5e000 194
26edeb6a 195void __stdcall close_all_files (bool = false);
1fd5e000 196
1fd5e000
CF
197/* debug_on_trap support. see exceptions.cc:try_to_debug() */
198extern "C" void error_start_init (const char*);
8abeff1e 199extern "C" int try_to_debug (bool waitloop = 1);
1fd5e000 200
93d606f6
CF
201void ld_preload ();
202const char *find_first_notloaded_dll (class path_conv &);
b21413b3 203
1fd5e000
CF
204/**************************** Miscellaneous ******************************/
205
1fd5e000 206void __stdcall set_std_handle (int);
61522196 207int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *);
1fd5e000 208
61522196
CV
209ino_t __reg2 hash_path_name (ino_t hash, PUNICODE_STRING name);
210ino_t __reg2 hash_path_name (ino_t hash, PCWSTR name);
211ino_t __reg2 hash_path_name (ino_t hash, const char *name);
6e75c72b 212void __reg2 nofinalslash (const char *src, char *dst);
1fd5e000 213
6e75c72b 214void __reg3 *hook_or_detect_cygwin (const char *, const void *, WORD&, HANDLE h = NULL);
e8454a34 215
1fd5e000 216/* Time related */
2b09be25
CV
217void __stdcall totimeval (struct timeval *, FILETIME *, int, int);
218long __stdcall to_time_t (FILETIME *);
219void __stdcall to_timestruc_t (FILETIME *, timestruc_t *);
220void __stdcall time_as_timestruc_t (timestruc_t *);
eba32ec8 221void __stdcall timespec_to_filetime (const struct timespec *, FILETIME *);
2b09be25 222void __stdcall timeval_to_filetime (const struct timeval *, FILETIME *);
1fd5e000 223
b21413b3 224/* Console related */
1fd5e000 225void __stdcall set_console_title (char *);
974f27a5 226void init_console_handler (bool);
b21413b3 227
6e75c72b 228void __reg2 __set_winsock_errno (const char *fn, int ln);
ade47a34 229#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
1fd5e000 230
0a047e8f
CF
231extern bool wsock_started;
232
f0338f54 233/* Printf type functions */
44d2fc0a
CF
234extern "C" void vapi_fatal (const char *, va_list ap) __attribute__ ((noreturn));
235extern "C" void api_fatal (const char *, ...) __attribute__ ((noreturn));
6e75c72b
CF
236int __small_sprintf (char *dst, const char *fmt, ...);
237int __small_vsprintf (char *dst, const char *fmt, va_list ap);
238int __small_swprintf (PWCHAR dst, const WCHAR *fmt, ...);
239int __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap);
61522196 240void multiple_cygwin_problem (const char *, uintptr_t, uintptr_t);
f0338f54 241
13505ca8
CV
242extern "C" void vklog (int priority, const char *message, va_list ap);
243extern "C" void klog (int priority, const char *message, ...);
ad02bb70 244bool child_copy (HANDLE, bool, ...);
13505ca8 245
6e75c72b 246int __reg3 symlink_worker (const char *, const char *, bool, bool);
7ac61736 247
fad5aef8 248class path_conv;
fad5aef8 249
61522196 250int __reg2 stat_worker (path_conv &pc, struct stat *buf);
e2a39e2e 251
61522196 252ino_t __reg2 readdir_get_ino (const char *path, bool dot_dot);
9e5f45ed 253
5a101414 254/* mmap functions. */
70e476d2
CV
255enum mmap_region_status
256 {
257 MMAP_NONE,
258 MMAP_RAISE_SIGBUS,
259 MMAP_NORESERVE_COMMITED
260 };
261mmap_region_status mmap_is_attached_or_noreserve (void *addr, size_t len);
6d6cfa48 262bool is_mmapped_region (caddr_t start_addr, caddr_t end_address);
6ef3b76b 263
c3a46349 264extern inline bool flush_file_buffers (HANDLE h)
c5a3166f
CV
265{
266 return (GetFileType (h) != FILE_TYPE_PIPE) ? FlushFileBuffers (h) : true;
267}
56c07aa2 268#define FlushFileBuffers flush_file_buffers
babc4e54 269
c3a46349
CF
270/* Make sure that regular ExitThread is never called */
271#define ExitThread exit_thread
272
1fd5e000
CF
273/**************************** Exports ******************************/
274
275extern "C" {
276int cygwin_select (int , fd_set *, fd_set *, fd_set *,
277 struct timeval *to);
278int cygwin_gethostname (char *__name, size_t __len);
1fd5e000
CF
279};
280
281/*************************** Unsorted ******************************/
282
1fd5e000
CF
283#define WM_ASYNCIO 0x8000 // WM_APP
284
1fd5e000 285
0cda2f46
CF
286#define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
287#define STD_WBITS (S_IWUSR)
288#define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
291be307
CF
289#define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
290#define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
291#define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
1fd5e000 292
1fd5e000 293
61522196
CV
294#ifdef __x86_64__
295extern "C" char __data_start__, __data_end__, __bss_start__, __bss_end__;
296#else
66a83f3e 297extern "C" char _data_start__, _data_end__, _bss_start__, _bss_end__;
61522196 298#endif
66a83f3e
CF
299extern "C" void (*__CTOR_LIST__) (void);
300extern "C" void (*__DTOR_LIST__) (void);
5684cfeb 301
374d215c 302#ifndef NO_GLOBALS_H
61522196 303#define _RDATA /* See globals.h */
66a83f3e 304#include "globals.h"
374d215c
CF
305
306extern inline void clear_procimptoken ()
5684cfeb
CV
307{
308 if (hProcImpToken)
309 {
1fd82398 310 HANDLE old_procimp = hProcImpToken;
5684cfeb 311 hProcImpToken = NULL;
1fd82398 312 CloseHandle (old_procimp);
5684cfeb
CV
313 }
314}
374d215c 315#endif /*NO_GLOBALS_H*/
4c8d72de 316#endif /* defined __cplusplus */
This page took 0.522764 seconds and 5 git commands to generate.