OSDN Git Service

* path.cc (path_conv::check): Move fs-specific settings to a point where we
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / include / sys / cygwin.h
1 /* sys/cygwin.h
2
3    Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4    2007, 2008, 2009, 2010 Red Hat, Inc.
5
6 This file is part of Cygwin.
7
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
10 details. */
11
12 #ifndef _SYS_CYGWIN_H
13 #define _SYS_CYGWIN_H
14
15 #include <sys/types.h>
16 #include <limits.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define _CYGWIN_SIGNAL_STRING "cYgSiGw00f"
23
24 #if 0 /* ENTIRELY DEPRECATED INTERFACES. */
25 extern pid_t cygwin32_winpid_to_pid (int);
26 extern void cygwin32_win32_to_posix_path_list (const char *, char *);
27 extern int cygwin32_win32_to_posix_path_list_buf_size (const char *);
28 extern void cygwin32_posix_to_win32_path_list (const char *, char *);
29 extern int cygwin32_posix_to_win32_path_list_buf_size (const char *);
30 extern int cygwin32_conv_to_win32_path (const char *, char *);
31 extern int cygwin32_conv_to_full_win32_path (const char *, char *);
32 extern void cygwin32_conv_to_posix_path (const char *, char *);
33 extern void cygwin32_conv_to_full_posix_path (const char *, char *);
34 extern int cygwin32_posix_path_list_p (const char *);
35 extern void cygwin32_split_path (const char *, char *, char *);
36 extern int cygwin32_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
37 #endif
38
39 /* DEPRECATED INTERFACES.  These are restricted to MAX_PATH length.
40    Don't use in modern applications. */
41 extern int cygwin_win32_to_posix_path_list (const char *, char *)
42   __attribute__ ((deprecated));
43 extern int cygwin_win32_to_posix_path_list_buf_size (const char *)
44   __attribute__ ((deprecated));
45 extern int cygwin_posix_to_win32_path_list (const char *, char *)
46   __attribute__ ((deprecated));
47 extern int cygwin_posix_to_win32_path_list_buf_size (const char *)
48   __attribute__ ((deprecated));
49 extern int cygwin_conv_to_win32_path (const char *, char *)
50   __attribute__ ((deprecated));
51 extern int cygwin_conv_to_full_win32_path (const char *, char *)
52   __attribute__ ((deprecated));
53 extern int cygwin_conv_to_posix_path (const char *, char *)
54   __attribute__ ((deprecated));
55 extern int cygwin_conv_to_full_posix_path (const char *, char *)
56   __attribute__ ((deprecated));
57
58 /* Use these interfaces in favor of the above. */
59
60 /* Possible 'what' values in calls to cygwin_conv_path/cygwin_create_path. */
61 enum
62 {
63   CCP_POSIX_TO_WIN_A = 0, /* from is char*, to is char*       */
64   CCP_POSIX_TO_WIN_W,     /* from is char*, to is wchar_t*    */
65   CCP_WIN_A_TO_POSIX,     /* from is char*, to is char*       */
66   CCP_WIN_W_TO_POSIX,     /* from is wchar_t*, to is char*    */
67
68   /* Or these values to the above as needed. */
69   CCP_ABSOLUTE = 0,       /* Request absolute path (default). */
70   CCP_RELATIVE = 0x100    /* Request to keep path relative.   */
71 };
72 typedef unsigned int cygwin_conv_path_t;
73
74 /* If size is 0, cygwin_conv_path returns the required buffer size in bytes.
75    Otherwise, it returns 0 on success, or -1 on error and errno is set to
76    one of the below values:
77
78     EINVAL        what has an invalid value.
79     EFAULT        from or to point into nirvana.
80     ENAMETOOLONG  the resulting path is longer than 32K, or, in case
81                   of what == CCP_POSIX_TO_WIN_A, longer than MAX_PATH.
82     ENOSPC        size is less than required for the conversion.
83 */
84 extern ssize_t cygwin_conv_path (cygwin_conv_path_t what, const void *from,
85                                  void *to, size_t size);
86 /* Same, but handles path lists separated by colon or semicolon. */
87 extern ssize_t cygwin_conv_path_list (cygwin_conv_path_t what, const void *from,
88                                  void *to, size_t size);
89 /* Allocate a buffer for the conversion result using malloc(3), and return
90    a pointer to it.  Returns NULL if something goes wrong with errno set
91    to one of the above values, or to ENOMEM if malloc fails. */
92 extern void *cygwin_create_path (cygwin_conv_path_t what, const void *from);
93
94 extern pid_t cygwin_winpid_to_pid (int);
95 extern int cygwin_posix_path_list_p (const char *);
96 extern void cygwin_split_path (const char *, char *, char *);
97
98 struct __cygwin_perfile
99 {
100   const char *name;
101   unsigned flags;
102 };
103
104 /* External interface stuff */
105
106 /* Always add at the bottom.  Do not add new values in the middle. */
107 typedef enum
108   {
109     CW_LOCK_PINFO,
110     CW_UNLOCK_PINFO,
111     CW_GETTHREADNAME,
112     CW_GETPINFO,
113     CW_SETPINFO,
114     CW_SETTHREADNAME,
115     CW_GETVERSIONINFO,
116     CW_READ_V1_MOUNT_TABLES,
117     CW_USER_DATA,
118     CW_PERFILE,
119     CW_GET_CYGDRIVE_PREFIXES,
120     CW_GETPINFO_FULL,
121     CW_INIT_EXCEPTIONS,
122     CW_GET_CYGDRIVE_INFO,
123     CW_SET_CYGWIN_REGISTRY_NAME,
124     CW_GET_CYGWIN_REGISTRY_NAME,
125     CW_STRACE_TOGGLE,
126     CW_STRACE_ACTIVE,
127     CW_CYGWIN_PID_TO_WINPID,
128     CW_EXTRACT_DOMAIN_AND_USER,
129     CW_CMDLINE,
130     CW_CHECK_NTSEC,
131     CW_GET_ERRNO_FROM_WINERROR,
132     CW_GET_POSIX_SECURITY_ATTRIBUTE,
133     CW_GET_SHMLBA,
134     CW_GET_UID_FROM_SID,
135     CW_GET_GID_FROM_SID,
136     CW_GET_BINMODE,
137     CW_HOOK,
138     CW_ARGV,
139     CW_ENVP,
140     CW_DEBUG_SELF,
141     CW_SYNC_WINENV,
142     CW_CYGTLS_PADSIZE,
143     CW_SET_DOS_FILE_WARNING,
144     CW_SET_PRIV_KEY,
145     CW_SETERRNO,
146     CW_EXIT_PROCESS,
147     CW_SET_EXTERNAL_TOKEN,
148     CW_GET_INSTKEY,
149     CW_INT_SETLOCALE,
150     CW_CVT_MNT_OPTS,
151     CW_LST_MNT_OPTS,
152     CW_STRERROR
153   } cygwin_getinfo_types;
154
155 /* Token type for CW_SET_EXTERNAL_TOKEN */
156 enum
157 {
158   CW_TOKEN_IMPERSONATION = 0,
159   CW_TOKEN_RESTRICTED    = 1
160 };
161
162 #define CW_NEXTPID      0x80000000      /* or with pid to get next one */
163 unsigned long cygwin_internal (cygwin_getinfo_types, ...);
164
165 /* Flags associated with process_state */
166 enum
167 {
168   PID_IN_USE           = 0x00001, /* Entry in use. */
169   PID_UNUSED           = 0x00002, /* Available. */
170   PID_STOPPED          = 0x00004, /* Waiting for SIGCONT. */
171   PID_TTYIN            = 0x00008, /* Waiting for terminal input. */
172   PID_TTYOU            = 0x00010, /* Waiting for terminal output. */
173   PID_ORPHANED         = 0x00020, /* Member of an orphaned process group. */
174   PID_ACTIVE           = 0x00040, /* Pid accepts signals. */
175   PID_CYGPARENT        = 0x00080, /* Set if parent was a cygwin app. */
176   PID_MAP_RW           = 0x00100, /* Flag to open map rw. */
177   PID_MYSELF           = 0x00200, /* Flag that pid is me. */
178   PID_NOCLDSTOP        = 0x00400, /* Set if no SIGCHLD signal on stop. */
179   PID_INITIALIZING     = 0x00800, /* Set until ready to receive signals. */
180   PID_USETTY           = 0x01000, /* Setting this enables or disables cygwin's
181                                      tty support.  This is inherited by
182                                      all execed or forked processes. */
183   PID_ALLPIDS          = 0x02000, /* used by pinfo scanner */
184   PID_EXECED           = 0x04000, /* redirect to original pid info block */
185   PID_NOREDIR          = 0x08000, /* don't redirect if execed */
186   PID_EXITED           = 0x80000000 /* Free entry. */
187 };
188
189 #ifdef WINVER
190
191 /* This lives in the app and is initialized before jumping into the DLL.
192    It should only contain stuff which the user's process needs to see, or
193    which is needed before the user pointer is initialized, or is needed to
194    carry inheritance information from parent to child.  Note that it cannot
195    be used to carry inheritance information across exec!
196
197    Remember, this structure is linked into the application's executable.
198    Changes to this can invalidate existing executables, so we go to extra
199    lengths to avoid having to do it.
200
201    When adding/deleting members, remember to adjust {public,internal}_reserved.
202    The size of the class shouldn't change [unless you really are prepared to
203    invalidate all existing executables].  The program does a check (using
204    SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment.
205 */
206
207 #ifdef __cplusplus
208 class MTinterface;
209 #endif
210
211 struct per_process_cxx_malloc;
212
213 struct per_process
214 {
215   char *initial_sp;
216
217   /* The offset of these 3 values can never change. */
218   /* magic_biscuit is the size of this class and should never change. */
219   unsigned long magic_biscuit;
220   unsigned long dll_major;
221   unsigned long dll_minor;
222
223   struct _reent **impure_ptr_ptr;
224   char ***envptr;
225
226   /* Used to point to the memory machine we should use.  Usually these
227      point back into the dll, but they can be overridden by the user. */
228   void *(*malloc)(size_t);
229   void (*free)(void *);
230   void *(*realloc)(void *, size_t);
231
232   int *fmode_ptr;
233
234   int (*main)(int, char **, char **);
235   void (**ctors)(void);
236   void (**dtors)(void);
237
238   /* For fork */
239   void *data_start;
240   void *data_end;
241   void *bss_start;
242   void *bss_end;
243
244   void *(*calloc)(size_t, size_t);
245   /* For future expansion of values set by the app. */
246   void (*premain[4]) (int, char **, struct per_process *);
247
248   /* non-zero of ctors have been run.  Inherited from parent. */
249   int run_ctors_p;
250
251   DWORD unused[7];
252
253   /* Pointers to real operator new/delete functions for forwarding.  */
254   struct per_process_cxx_malloc *cxx_malloc;
255
256   HMODULE hmodule;
257
258   DWORD api_major;              /* API version that this program was */
259   DWORD api_minor;              /*  linked with */
260   /* For future expansion, so apps won't have to be relinked if we
261      add an item. */
262   DWORD unused2[3];
263   void *pseudo_reloc_start;
264   void *pseudo_reloc_end;
265   void *image_base;
266
267 #if defined (__INSIDE_CYGWIN__) && defined (__cplusplus)
268   MTinterface *threadinterface;
269 #else
270   void *threadinterface;
271 #endif
272   struct _reent *impure_ptr;
273 };
274 #define per_process_overwrite ((unsigned) &(((struct per_process *) NULL)->threadinterface))
275
276 extern void cygwin_premain0 (int argc, char **argv, struct per_process *);
277 extern void cygwin_premain1 (int argc, char **argv, struct per_process *);
278 extern void cygwin_premain2 (int argc, char **argv, struct per_process *);
279 extern void cygwin_premain3 (int argc, char **argv, struct per_process *);
280
281 #ifdef _PATH_PASSWD
282 extern HANDLE cygwin_logon_user (const struct passwd *, const char *);
283 #endif
284 extern void cygwin_set_impersonation_token (const HANDLE);
285
286 /* included if <windows.h> is included */
287 extern int cygwin_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
288
289 #ifdef __CYGWIN__
290 #include <sys/resource.h>
291
292 #define TTY_CONSOLE     0x40000000
293
294 #define EXTERNAL_PINFO_VERSION_16_BIT 0
295 #define EXTERNAL_PINFO_VERSION_32_BIT 1
296 #define EXTERNAL_PINFO_VERSION_32_LP  2
297 #define EXTERNAL_PINFO_VERSION EXTERNAL_PINFO_VERSION_32_LP
298
299 #ifndef _SYS_TYPES_H
300 typedef unsigned short __uid16_t;
301 typedef unsigned short __gid16_t;
302 typedef unsigned long __uid32_t;
303 typedef unsigned long __gid32_t;
304 #endif
305
306 struct external_pinfo
307   {
308   pid_t pid;
309   pid_t ppid;
310   DWORD exitcode;
311   DWORD dwProcessId, dwSpawnedProcessId;
312   __uid16_t uid;
313   __gid16_t gid;
314   pid_t pgid;
315   pid_t sid;
316   int ctty;
317   mode_t umask;
318
319   long start_time;
320   struct rusage rusage_self;
321   struct rusage rusage_children;
322
323   char progname[MAX_PATH];
324
325   DWORD strace_mask;
326   DWORD version;
327
328   DWORD process_state;
329
330   /* Only available if version >= EXTERNAL_PINFO_VERSION_32_BIT */
331   __uid32_t uid32;
332   __gid32_t gid32;
333
334   /* Only available if version >= EXTERNAL_PINFO_VERSION_32_LP */
335   char *progname_long;
336 };
337 #endif /*__CYGWIN__*/
338 #endif /*WINVER*/
339
340 #ifdef __cplusplus
341 };
342 #endif
343 #endif /* _SYS_CYGWIN_H */