]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/include/sys/cygwin.h
Cygwin: console: Fix clean up conditions in close()
[newlib-cygwin.git] / winsup / cygwin / include / sys / cygwin.h
CommitLineData
d89cc269 1
a887211b
CV
2/* sys/cygwin.h
3
a887211b
CV
4This file is part of Cygwin.
5
6This software is a copyrighted work licensed under the terms of the
7Cygwin license. Please consult the file "CYGWIN_LICENSE" for
8details. */
9
1fd5e000
CF
10#ifndef _SYS_CYGWIN_H
11#define _SYS_CYGWIN_H
12
13#include <sys/types.h>
041337fd 14#include <limits.h>
61522196 15#include <stdint.h>
1fd5e000
CF
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
b7bb9f5f
CF
21#define _CYGWIN_SIGNAL_STRING "cYgSiGw00f"
22
edab6053
CV
23/* Possible 'what' values in calls to cygwin_conv_path/cygwin_create_path. */
24enum
25{
26 CCP_POSIX_TO_WIN_A = 0, /* from is char*, to is char* */
27 CCP_POSIX_TO_WIN_W, /* from is char*, to is wchar_t* */
28 CCP_WIN_A_TO_POSIX, /* from is char*, to is char* */
29 CCP_WIN_W_TO_POSIX, /* from is wchar_t*, to is char* */
30
a887cf0e
CV
31 CCP_CONVTYPE_MASK = 3,
32
edab6053 33 /* Or these values to the above as needed. */
4afc52d5
CV
34 CCP_ABSOLUTE = 0, /* Request absolute path (default). */
35 CCP_RELATIVE = 0x100, /* Request to keep path relative. */
36 CCP_PROC_CYGDRIVE = 0x200, /* Request to return /proc/cygdrive
5aa8817e 37 path (only with CCP_*_TO_POSIX). */
8b83da2d
CV
38
39 CCP_CONVFLAGS_MASK = 0x300,
edab6053
CV
40};
41typedef unsigned int cygwin_conv_path_t;
42
43/* If size is 0, cygwin_conv_path returns the required buffer size in bytes.
44 Otherwise, it returns 0 on success, or -1 on error and errno is set to
45 one of the below values:
46
47 EINVAL what has an invalid value.
48 EFAULT from or to point into nirvana.
49 ENAMETOOLONG the resulting path is longer than 32K, or, in case
50 of what == CCP_POSIX_TO_WIN_A, longer than MAX_PATH.
51 ENOSPC size is less than required for the conversion.
52*/
53extern ssize_t cygwin_conv_path (cygwin_conv_path_t what, const void *from,
54 void *to, size_t size);
55/* Same, but handles path lists separated by colon or semicolon. */
56extern ssize_t cygwin_conv_path_list (cygwin_conv_path_t what, const void *from,
57 void *to, size_t size);
58/* Allocate a buffer for the conversion result using malloc(3), and return
59 a pointer to it. Returns NULL if something goes wrong with errno set
60 to one of the above values, or to ENOMEM if malloc fails. */
61extern void *cygwin_create_path (cygwin_conv_path_t what, const void *from);
1fd5e000
CF
62
63extern pid_t cygwin_winpid_to_pid (int);
1fd5e000
CF
64extern int cygwin_posix_path_list_p (const char *);
65extern void cygwin_split_path (const char *, char *, char *);
66
bd4ec496
CF
67struct __cygwin_perfile
68{
bb5d559a 69 const char *name;
bd4ec496
CF
70 unsigned flags;
71};
72
bd4ec496
CF
73/* External interface stuff */
74
b1d9a0bd 75/* Always add at the bottom. Do not add new values in the middle. */
9ee69121 76typedef enum
bd4ec496
CF
77 {
78 CW_LOCK_PINFO,
79 CW_UNLOCK_PINFO,
80 CW_GETTHREADNAME,
81 CW_GETPINFO,
82 CW_SETPINFO,
83 CW_SETTHREADNAME,
84 CW_GETVERSIONINFO,
85 CW_READ_V1_MOUNT_TABLES,
86 CW_USER_DATA,
637f5ce0 87 CW_PERFILE,
84c7d409 88 CW_GET_CYGDRIVE_PREFIXES,
239b06b8 89 CW_GETPINFO_FULL,
9bc846bd 90 CW_INIT_EXCEPTIONS,
a9f20457
CF
91 CW_GET_CYGDRIVE_INFO,
92 CW_SET_CYGWIN_REGISTRY_NAME,
494a66d9 93 CW_GET_CYGWIN_REGISTRY_NAME,
907dc7d0 94 CW_STRACE_TOGGLE,
3d456520 95 CW_STRACE_ACTIVE,
31b98a62 96 CW_CYGWIN_PID_TO_WINPID,
831d6fa5 97 CW_EXTRACT_DOMAIN_AND_USER,
732afede 98 CW_CMDLINE_ALLOC,
5ec9ea21 99 CW_CHECK_NTSEC,
bcd06214 100 CW_GET_ERRNO_FROM_WINERROR,
6ef3b76b 101 CW_GET_POSIX_SECURITY_ATTRIBUTE,
8e68687d
CV
102 CW_GET_SHMLBA,
103 CW_GET_UID_FROM_SID,
5ef9bbc8 104 CW_GET_GID_FROM_SID,
b1d9a0bd 105 CW_GET_BINMODE,
1cd8ccec
CF
106 CW_HOOK,
107 CW_ARGV,
5c8e6fbd 108 CW_ENVP,
6577c186 109 CW_DEBUG_SELF,
38229bcd 110 CW_SYNC_WINENV,
e7fd6e57 111 CW_CYGTLS_PADSIZE,
51303cbd 112 CW_SET_DOS_FILE_WARNING,
d95d8c53 113 CW_SET_PRIV_KEY,
c8ee587a 114 CW_SETERRNO,
0191627a 115 CW_EXIT_PROCESS,
526b0fbc 116 CW_SET_EXTERNAL_TOKEN,
f5a73638 117 CW_GET_INSTKEY,
a11a0723
CV
118 CW_INT_SETLOCALE,
119 CW_CVT_MNT_OPTS,
6259826e 120 CW_LST_MNT_OPTS,
8dfce03b 121 CW_STRERROR,
3a24189b
CV
122 CW_CVT_ENV_TO_WINENV,
123 CW_ALLOC_DRIVE_MAP,
124 CW_MAP_DRIVE_MAP,
036f56cf
CV
125 CW_FREE_DRIVE_MAP,
126 CW_SETENT,
127 CW_GETENT,
b211f4c1
CV
128 CW_ENDENT,
129 CW_GETNSSSEP,
130 CW_GETPWSID,
076a61f0 131 CW_GETGRSID,
dfc361da 132 CW_CYGNAME_FROM_WINNAME,
54f79f86
CV
133 CW_FIXED_ATEXIT,
134 CW_GETNSS_PWD_SRC,
d89cc269
JT
135 CW_GETNSS_GRP_SRC,
136 CW_EXCEPTION_RECORD_FROM_SIGINFO_T,
5807ba83 137 CW_CYGHEAP_PROFTHR_ALL,
658f9390 138 CW_WINPID_TO_CYGWIN_PID,
ae3370bb 139 CW_MAX_CYGWIN_PID,
bd4ec496
CF
140 } cygwin_getinfo_types;
141
c53c656b
CV
142#define CW_LOCK_PINFO CW_LOCK_PINFO
143#define CW_UNLOCK_PINFO CW_UNLOCK_PINFO
144#define CW_GETTHREADNAME CW_GETTHREADNAME
145#define CW_GETPINFO CW_GETPINFO
146#define CW_SETPINFO CW_SETPINFO
147#define CW_SETTHREADNAME CW_SETTHREADNAME
148#define CW_GETVERSIONINFO CW_GETVERSIONINFO
149#define CW_READ_V1_MOUNT_TABLES CW_READ_V1_MOUNT_TABLES
150#define CW_USER_DATA CW_USER_DATA
151#define CW_PERFILE CW_PERFILE
152#define CW_GET_CYGDRIVE_PREFIXES CW_GET_CYGDRIVE_PREFIXES
153#define CW_GETPINFO_FULL CW_GETPINFO_FULL
154#define CW_INIT_EXCEPTIONS CW_INIT_EXCEPTIONS
155#define CW_GET_CYGDRIVE_INFO CW_GET_CYGDRIVE_INFO
156#define CW_SET_CYGWIN_REGISTRY_NAME CW_SET_CYGWIN_REGISTRY_NAME
157#define CW_GET_CYGWIN_REGISTRY_NAME CW_GET_CYGWIN_REGISTRY_NAME
158#define CW_STRACE_TOGGLE CW_STRACE_TOGGLE
159#define CW_STRACE_ACTIVE CW_STRACE_ACTIVE
160#define CW_CYGWIN_PID_TO_WINPID CW_CYGWIN_PID_TO_WINPID
161#define CW_EXTRACT_DOMAIN_AND_USER CW_EXTRACT_DOMAIN_AND_USER
732afede 162#define CW_CMDLINE_ALLOC CW_CMDLINE_ALLOC
c53c656b
CV
163#define CW_CHECK_NTSEC CW_CHECK_NTSEC
164#define CW_GET_ERRNO_FROM_WINERROR CW_GET_ERRNO_FROM_WINERROR
165#define CW_GET_POSIX_SECURITY_ATTRIBUTE CW_GET_POSIX_SECURITY_ATTRIBUTE
166#define CW_GET_SHMLBA CW_GET_SHMLBA
167#define CW_GET_UID_FROM_SID CW_GET_UID_FROM_SID
168#define CW_GET_GID_FROM_SID CW_GET_GID_FROM_SID
169#define CW_GET_BINMODE CW_GET_BINMODE
170#define CW_HOOK CW_HOOK
171#define CW_ARGV CW_ARGV
172#define CW_ENVP CW_ENVP
173#define CW_DEBUG_SELF CW_DEBUG_SELF
174#define CW_SYNC_WINENV CW_SYNC_WINENV
175#define CW_CYGTLS_PADSIZE CW_CYGTLS_PADSIZE
176#define CW_SET_DOS_FILE_WARNING CW_SET_DOS_FILE_WARNING
177#define CW_SET_PRIV_KEY CW_SET_PRIV_KEY
178#define CW_SETERRNO CW_SETERRNO
179#define CW_EXIT_PROCESS CW_EXIT_PROCESS
180#define CW_SET_EXTERNAL_TOKEN CW_SET_EXTERNAL_TOKEN
181#define CW_GET_INSTKEY CW_GET_INSTKEY
182#define CW_INT_SETLOCALE CW_INT_SETLOCALE
183#define CW_CVT_MNT_OPTS CW_CVT_MNT_OPTS
184#define CW_LST_MNT_OPTS CW_LST_MNT_OPTS
185#define CW_STRERROR CW_STRERROR
186#define CW_CVT_ENV_TO_WINENV CW_CVT_ENV_TO_WINENV
b120088c
CV
187#define CW_ALLOC_DRIVE_MAP CW_ALLOC_DRIVE_MAP
188#define CW_MAP_DRIVE_MAP CW_MAP_DRIVE_MAP
189#define CW_FREE_DRIVE_MAP CW_FREE_DRIVE_MAP
036f56cf
CV
190#define CW_SETENT CW_SETENT
191#define CW_GETENT CW_GETENT
192#define CW_ENDENT CW_ENDENT
b211f4c1
CV
193#define CW_GETNSSSEP CW_GETNSSSEP
194#define CW_GETPWSID CW_GETPWSID
195#define CW_GETGRSID CW_GETGRSID
076a61f0 196#define CW_CYGNAME_FROM_WINNAME CW_CYGNAME_FROM_WINNAME
dfc361da 197#define CW_FIXED_ATEXIT CW_FIXED_ATEXIT
54f79f86
CV
198#define CW_GETNSS_PWD_SRC CW_GETNSS_PWD_SRC
199#define CW_GETNSS_GRP_SRC CW_GETNSS_GRP_SRC
d89cc269 200#define CW_EXCEPTION_RECORD_FROM_SIGINFO_T CW_EXCEPTION_RECORD_FROM_SIGINFO_T
5807ba83 201#define CW_CYGHEAP_PROFTHR_ALL CW_CYGHEAP_PROFTHR_ALL
658f9390 202#define CW_WINPID_TO_CYGWIN_PID CW_WINPID_TO_CYGWIN_PID
ae3370bb 203#define CW_MAX_CYGWIN_PID CW_MAX_CYGWIN_PID
c53c656b 204
0191627a
CV
205/* Token type for CW_SET_EXTERNAL_TOKEN */
206enum
207{
29b7313d
CV
208 CW_TOKEN_IMPERSONATION = 0,
209 CW_TOKEN_RESTRICTED = 1
0191627a
CV
210};
211
54f79f86
CV
212/* Source type for CW_GETNSS_PWD_SRC and CW_GETNSS_GRP_SRC. */
213enum
214{
215 NSS_SRC_FILES = 1,
216 NSS_SRC_DB = 2
217};
218
b211f4c1
CV
219/* Enumeration source constants for CW_SETENT called from mkpasswd/mkgroup. */
220enum nss_enum_t
221{
222 ENUM_NONE = 0x00,
223 ENUM_CACHE = 0x01,
224 ENUM_FILES = 0x02,
225 ENUM_BUILTIN = 0x04,
226 ENUM_LOCAL = 0x08,
227 ENUM_PRIMARY = 0x10,
228 ENUM_TDOMS = 0x20,
229 ENUM_TDOMS_ALL = 0x40,
230 ENUM_ALL = 0x7f
231};
232
cadd065b 233#define CW_NEXTPID 0x80000000 /* or with pid to get next one */
61522196 234uintptr_t cygwin_internal (cygwin_getinfo_types, ...);
bd4ec496
CF
235
236/* Flags associated with process_state */
237enum
238{
54dd79bb 239 PID_IN_USE = 0x00001, /* Entry in use. */
85b3fb96 240 PID_UNUSED = 0x00002, /* Available. */
54dd79bb
CF
241 PID_STOPPED = 0x00004, /* Waiting for SIGCONT. */
242 PID_TTYIN = 0x00008, /* Waiting for terminal input. */
243 PID_TTYOU = 0x00010, /* Waiting for terminal output. */
f95f18c9 244 PID_NOTCYGWIN = 0x00020, /* Set if process is not a cygwin app. */
54dd79bb
CF
245 PID_ACTIVE = 0x00040, /* Pid accepts signals. */
246 PID_CYGPARENT = 0x00080, /* Set if parent was a cygwin app. */
247 PID_MAP_RW = 0x00100, /* Flag to open map rw. */
248 PID_MYSELF = 0x00200, /* Flag that pid is me. */
249 PID_NOCLDSTOP = 0x00400, /* Set if no SIGCHLD signal on stop. */
250 PID_INITIALIZING = 0x00800, /* Set until ready to receive signals. */
13621d2e 251 PID_NEW = 0x01000, /* Available. */
54dd79bb 252 PID_ALLPIDS = 0x02000, /* used by pinfo scanner */
b5e10037 253 PID_PROCINFO = 0x08000, /* caller just asks for process info */
8d8724ee
TY
254 PID_NEW_PG = 0x10000, /* Process created with
255 CREATE_NEW_PROCESS_GROUOP flag */
15a35758 256 PID_DEBUGGED = 0x20000, /* Process being debugged */
5069a2b0
CF
257 PID_EXITED = 0x40000000, /* Free entry. */
258 PID_REAPED = 0x80000000 /* Reaped */
bd4ec496
CF
259};
260
00103b7f
CV
261#ifdef WINVER
262
14a3bc2f
CF
263/* This lives in the app and is initialized before jumping into the DLL.
264 It should only contain stuff which the user's process needs to see, or
265 which is needed before the user pointer is initialized, or is needed to
266 carry inheritance information from parent to child. Note that it cannot
267 be used to carry inheritance information across exec!
268
269 Remember, this structure is linked into the application's executable.
270 Changes to this can invalidate existing executables, so we go to extra
271 lengths to avoid having to do it.
272
273 When adding/deleting members, remember to adjust {public,internal}_reserved.
274 The size of the class shouldn't change [unless you really are prepared to
275 invalidate all existing executables]. The program does a check (using
276 SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment.
277*/
278
c19e7ba7 279#ifdef __cplusplus
d6483e83 280class MTinterface;
c19e7ba7 281#endif
d6483e83 282
b602bb90
DK
283struct per_process_cxx_malloc;
284
737a86d3 285struct per_process
14a3bc2f 286{
14a3bc2f
CF
287 char *initial_sp;
288
289 /* The offset of these 3 values can never change. */
290 /* magic_biscuit is the size of this class and should never change. */
61522196
CV
291 uint32_t magic_biscuit;
292 uint32_t dll_major;
293 uint32_t dll_minor;
14a3bc2f
CF
294
295 struct _reent **impure_ptr_ptr;
14a3bc2f
CF
296
297 /* Used to point to the memory machine we should use. Usually these
298 point back into the dll, but they can be overridden by the user. */
299 void *(*malloc)(size_t);
300 void (*free)(void *);
301 void *(*realloc)(void *, size_t);
302
303 int *fmode_ptr;
304
305 int (*main)(int, char **, char **);
306 void (**ctors)(void);
307 void (**dtors)(void);
308
309 /* For fork */
310 void *data_start;
311 void *data_end;
312 void *bss_start;
313 void *bss_end;
314
315 void *(*calloc)(size_t, size_t);
316 /* For future expansion of values set by the app. */
95a8465b 317 void (*premain[4]) (int, char **, struct per_process *);
14a3bc2f 318
61522196
CV
319 /* non-zero if ctors have been run. Inherited from parent. */
320 int32_t run_ctors_p;
14a3bc2f 321
61522196 322 DWORD_PTR unused[7];
14a3bc2f 323
b602bb90
DK
324 /* Pointers to real operator new/delete functions for forwarding. */
325 struct per_process_cxx_malloc *cxx_malloc;
14a3bc2f
CF
326
327 HMODULE hmodule;
328
329 DWORD api_major; /* API version that this program was */
330 DWORD api_minor; /* linked with */
331 /* For future expansion, so apps won't have to be relinked if we
332 add an item. */
ef23b0a6 333 DWORD_PTR unused2[4];
ef23b0a6
CV
334
335 int (*posix_memalign)(void **, size_t, size_t);
336
27f564e9
CF
337 void *pseudo_reloc_start;
338 void *pseudo_reloc_end;
339 void *image_base;
737a86d3 340
b1aae492 341#if defined (__INSIDE_CYGWIN__) && defined (__cplusplus)
14a3bc2f 342 MTinterface *threadinterface;
52cec10c 343#else
52cec10c
CV
344 void *threadinterface;
345#endif
737a86d3 346 struct _reent *impure_ptr;
14a3bc2f 347};
61522196 348#define per_process_overwrite offsetof (struct per_process, threadinterface)
14a3bc2f 349
7d5d232b
CV
350#ifdef _PATH_PASSWD
351extern HANDLE cygwin_logon_user (const struct passwd *, const char *);
352#endif
d7cea2d3
CF
353extern void cygwin_set_impersonation_token (const HANDLE);
354
1fd5e000 355/* included if <windows.h> is included */
d69257a1 356extern int cygwin_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
1fd5e000 357
92117cb2
CF
358extern void cygwin_premain0 (int, char **, struct per_process *);
359extern void cygwin_premain1 (int, char **, struct per_process *);
360extern void cygwin_premain2 (int, char **, struct per_process *);
361extern void cygwin_premain3 (int, char **, struct per_process *);
362
840fcfef 363#ifdef __CYGWIN__
2a6a56c2
CF
364#include <sys/resource.h>
365
b98ebf54
CF
366#define TTY_CONSOLE 0x40000000
367
3a571063
CV
368#define EXTERNAL_PINFO_VERSION_16_BIT 0
369#define EXTERNAL_PINFO_VERSION_32_BIT 1
36093cfb
CV
370#define EXTERNAL_PINFO_VERSION_32_LP 2
371#define EXTERNAL_PINFO_VERSION EXTERNAL_PINFO_VERSION_32_LP
9fef0139 372
61522196
CV
373typedef __uint16_t __uid16_t;
374typedef __uint16_t __gid16_t;
494a66d9 375
2a6a56c2
CF
376struct external_pinfo
377 {
378 pid_t pid;
379 pid_t ppid;
8cb359d9 380 DWORD exitcode;
2a6a56c2 381 DWORD dwProcessId, dwSpawnedProcessId;
52296b85
CV
382 __uid16_t uid;
383 __gid16_t gid;
2a6a56c2
CF
384 pid_t pgid;
385 pid_t sid;
386 int ctty;
387 mode_t umask;
388
389 long start_time;
390 struct rusage rusage_self;
391 struct rusage rusage_children;
392
393 char progname[MAX_PATH];
394
395 DWORD strace_mask;
9fef0139 396 DWORD version;
2a6a56c2
CF
397
398 DWORD process_state;
a8d7ae61 399
3a571063 400 /* Only available if version >= EXTERNAL_PINFO_VERSION_32_BIT */
61522196
CV
401 uid_t uid32;
402 gid_t gid32;
36093cfb
CV
403
404 /* Only available if version >= EXTERNAL_PINFO_VERSION_32_LP */
9d342d56 405 char *progname_long;
2a6a56c2 406};
840fcfef 407#endif /*__CYGWIN__*/
f33acdb8 408#endif /*WINVER*/
2a6a56c2 409
1fd5e000
CF
410#ifdef __cplusplus
411};
412#endif
1fd5e000 413#endif /* _SYS_CYGWIN_H */
This page took 0.636323 seconds and 6 git commands to generate.