Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / globals.cc
blobd8e058f1915d5a1f38964ab6a89158eef84ac2f7
1 /* globals.cc - Define global variables here.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #define NO_GLOBALS_H
10 #include "winsup.h"
11 #include "cygtls.h"
12 #include "perprocess.h"
13 #include "thread.h"
14 #include <malloc.h>
15 #include <cygwin/version.h>
17 HANDLE NO_COPY hMainThread;
18 HANDLE NO_COPY hProcToken;
19 HANDLE NO_COPY hProcImpToken;
20 HANDLE my_wr_proc_pipe;
21 HMODULE NO_COPY cygwin_hmodule;
22 HMODULE NO_COPY hntdll;
23 LONG NO_COPY sigExeced;
24 WCHAR windows_system_directory[MAX_PATH];
25 UINT windows_system_directory_length;
26 WCHAR windows_directory_buf[MAX_PATH];
27 PWCHAR windows_directory = windows_directory_buf + 4;
28 UINT windows_directory_length;
29 UNICODE_STRING windows_directory_path;
30 WCHAR global_progname[NT_MAX_PATH];
32 /* program exit the program */
34 enum exit_states
36 ES_NOT_EXITING = 0,
37 ES_EXIT_STARTING,
38 ES_SIGNAL_EXIT,
39 ES_PROCESS_LOCKED,
40 ES_EVENTS_TERMINATE,
41 ES_SIGNAL,
42 ES_CLOSEALL,
43 ES_THREADTERM,
44 ES_HUP_PGRP,
45 ES_HUP_SID,
46 ES_TTY_TERMINATE,
47 ES_FINAL
50 /* The type of symlink to create. The value is set depending on the
51 "winsymlinks" setting of the CYGWIN environment variable. */
52 enum winsym_t
54 WSYM_default = 0,
55 WSYM_lnk,
56 WSYM_native,
57 WSYM_nativestrict,
58 WSYM_nfs,
59 WSYM_sysfile,
62 exit_states NO_COPY exit_state;
64 /* Set in init.cc. Used to check if Cygwin DLL is dynamically loaded. */
65 int NO_COPY dynamically_loaded;
67 /* Some CYGWIN environment variable variables. */
68 bool allow_glob = true;
69 bool ignore_case_with_glob;
70 bool pipe_byte = true; /* Default to byte mode so that C# programs work. */
71 bool reset_com;
72 bool wincmdln;
73 winsym_t allow_winsymlinks = WSYM_default;
74 bool disable_pcon;
75 bool winjitdebug = false;
77 /* Taken from BSD libc:
78 This variable is zero until a process has created a pthread. It is used
79 to avoid calling locking functions in libc when they are not required.
80 Note that this is moderately dangerous. Do not rely on it if the public
81 API is also used from a non-pthread thread like the signal thread. */
82 int NO_COPY __isthreaded = 0;
84 int __argc_safe;
85 int __argc;
86 char **__argv;
87 /* Set via setproctitle */
88 char *__argv0_orig;
90 _cygtls NO_COPY *_main_tls /* !globals.h */;
92 bool NO_COPY cygwin_finished_initializing;
94 bool NO_COPY _cygwin_testing;
96 char NO_COPY almost_null[1];
98 extern "C" {
100 /* Heavily-used const UNICODE_STRINGs are defined here once. The idea is a
101 speed improvement by not having to initialize a UNICODE_STRING every time
102 we make a string comparison. The _RDATA trick allows defining the strings
103 as const (so we get a SEGV if some code erroneously tries to overwrite
104 them), while declaring them as non-const in the auto-generated globals.h.
105 The strings are usually used in NT functions which don't take const
106 arguments. We avoid a lot of extra casts here...
107 Note: The "extern" is required, otherwise either the variables are dropped
108 entirely, or C++ name mangling is applied despite the extern "C"
109 bracket, depending on the compiler version */
110 #ifndef _RDATA
111 # define _RDATA const
112 #endif
114 #define _ROU(_s) \
115 { Length: sizeof (_s) - sizeof (WCHAR), \
116 MaximumLength: sizeof (_s), \
117 Buffer: (PWSTR) (_s) }
118 extern UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
119 extern UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
120 extern UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
121 extern UNICODE_STRING _RDATA ro_u_scr = _ROU (L".scr");
122 extern UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
123 extern UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
124 extern UNICODE_STRING _RDATA ro_u_dev = _ROU (L"dev");
125 extern UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
126 extern UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
127 extern UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
128 extern UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
129 extern UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
130 extern UNICODE_STRING _RDATA ro_u_exfat = _ROU (L"exFAT");
131 extern UNICODE_STRING _RDATA ro_u_mvfs = _ROU (L"MVFS");
132 extern UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
133 extern UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
134 /* No typo! It's actually "SF", not "FS", and the trailing NUL is counted
135 in the reply from the filesystem. */
136 extern UNICODE_STRING _RDATA ro_u_prlfs = _ROU (L"PrlSF\0");
137 extern UNICODE_STRING _RDATA ro_u_refs = _ROU (L"ReFS");
138 extern UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
139 extern UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
140 extern UNICODE_STRING _RDATA ro_u_nwfs = _ROU (L"NWFS");
141 extern UNICODE_STRING _RDATA ro_u_ncfsd = _ROU (L"NcFsd");
142 extern UNICODE_STRING _RDATA ro_u_afs = _ROU (L"AFSRDRFsd");
143 extern UNICODE_STRING _RDATA ro_u_volume = _ROU (L"\\??\\Volume{");
144 extern UNICODE_STRING _RDATA ro_u_pipedir = _ROU (L"\\\\?\\PIPE\\");
145 extern UNICODE_STRING _RDATA ro_u_globalroot = _ROU (L"\\\\.\\GLOBALROOT");
146 extern UNICODE_STRING _RDATA ro_u_null = _ROU (L"\\Device\\Null");
147 extern UNICODE_STRING _RDATA ro_u_natdir = _ROU (L"Directory");
148 extern UNICODE_STRING _RDATA ro_u_natsyml = _ROU (L"SymbolicLink");
149 extern UNICODE_STRING _RDATA ro_u_natdev = _ROU (L"Device");
150 extern UNICODE_STRING _RDATA ro_u_npfs = _ROU (L"\\Device\\NamedPipe\\");
151 extern UNICODE_STRING _RDATA ro_u_mq_suffix = _ROU (L":mqueue");
152 #undef _ROU
154 char **environ;
155 /* __progname used in getopt error message is an alias of
156 program_invocation_short_name. */
157 char *program_invocation_short_name;
158 char *program_invocation_name;
159 static MTinterface _mtinterf;
160 struct per_process __cygwin_user_data =
161 {/* initial_sp */ 0, /* magic_biscuit */ 0,
162 /* dll_major */ CYGWIN_VERSION_DLL_MAJOR,
163 /* dll_major */ CYGWIN_VERSION_DLL_MINOR,
164 /* impure_ptr_ptr */ NULL,
165 /* malloc */ malloc, /* free */ free,
166 /* realloc */ realloc,
167 /* fmode_ptr */ NULL, /* main */ NULL, /* ctors */ NULL,
168 /* dtors */ NULL, /* data_start */ NULL, /* data_end */ NULL,
169 /* bss_start */ NULL, /* bss_end */ NULL,
170 /* calloc */ calloc,
171 /* premain */ {NULL, NULL, NULL, NULL},
172 /* run_ctors_p */ 0,
173 /* unused */ {},
174 /* cxx_malloc */ &default_cygwin_cxx_malloc,
175 /* hmodule */ NULL,
176 /* api_major */ 0,
177 /* api_minor */ 0,
178 /* unused2 */ {},
179 /* posix_memalign */ posix_memalign,
180 /* pseudo_reloc_start */ NULL,
181 /* pseudo_reloc_end */ NULL,
182 /* image_base */ NULL,
183 /* threadinterface */ &_mtinterf,
184 /* impure_ptr */ _GLOBAL_REENT,
186 int _check_for_executable = true;
188 /* This was a bool initially, just indicating if we're in the forked
189 child during fork(2). However, we need an indicator accessible from
190 plain C we can ask if we're in a forked child even after fork(2)
191 finished. Therefore redefined how we use this variable. */
192 enum {
193 NOT_FORKED = 0,
194 FORKING = 1,
195 FORKED = 2
197 int NO_COPY __in_forkee;
200 int NO_COPY __api_fatal_exit_val = 1;
202 EXPORT_ALIAS (program_invocation_short_name, __progname)