2009-01-03 13:12:22 +08:00
|
|
|
/* globals.cc - Define global variables here.
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2012-03-20 01:49:40 +08:00
|
|
|
#define NO_GLOBALS_H
|
2009-01-03 13:12:22 +08:00
|
|
|
#include "winsup.h"
|
|
|
|
#include "cygtls.h"
|
|
|
|
#include "perprocess.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <cygwin/version.h>
|
|
|
|
|
2009-12-21 17:38:25 +08:00
|
|
|
HANDLE NO_COPY hMainThread;
|
2009-01-03 13:12:22 +08:00
|
|
|
HANDLE NO_COPY hProcToken;
|
|
|
|
HANDLE NO_COPY hProcImpToken;
|
2012-03-20 23:07:30 +08:00
|
|
|
HANDLE my_wr_proc_pipe;
|
2009-01-03 13:12:22 +08:00
|
|
|
HMODULE NO_COPY cygwin_hmodule;
|
2013-12-10 04:32:24 +08:00
|
|
|
HMODULE NO_COPY hntdll;
|
2022-02-26 14:13:13 +08:00
|
|
|
LONG NO_COPY sigExeced;
|
2011-12-14 04:06:31 +08:00
|
|
|
WCHAR windows_system_directory[MAX_PATH];
|
|
|
|
UINT windows_system_directory_length;
|
2021-05-08 05:05:24 +08:00
|
|
|
WCHAR windows_directory_buf[MAX_PATH];
|
|
|
|
PWCHAR windows_directory = windows_directory_buf + 4;
|
2021-04-21 23:32:06 +08:00
|
|
|
UINT windows_directory_length;
|
2021-05-08 05:05:24 +08:00
|
|
|
UNICODE_STRING windows_directory_path;
|
2015-07-20 04:38:30 +08:00
|
|
|
WCHAR global_progname[NT_MAX_PATH];
|
2009-01-03 13:12:22 +08:00
|
|
|
|
|
|
|
/* program exit the program */
|
|
|
|
|
|
|
|
enum exit_states
|
2012-03-20 01:49:40 +08:00
|
|
|
{
|
|
|
|
ES_NOT_EXITING = 0,
|
|
|
|
ES_EXIT_STARTING,
|
2013-01-04 10:21:03 +08:00
|
|
|
ES_SIGNAL_EXIT,
|
2012-03-20 01:49:40 +08:00
|
|
|
ES_PROCESS_LOCKED,
|
|
|
|
ES_EVENTS_TERMINATE,
|
|
|
|
ES_SIGNAL,
|
|
|
|
ES_CLOSEALL,
|
|
|
|
ES_THREADTERM,
|
|
|
|
ES_HUP_PGRP,
|
|
|
|
ES_HUP_SID,
|
|
|
|
ES_TTY_TERMINATE,
|
|
|
|
ES_FINAL
|
|
|
|
};
|
2009-01-03 13:12:22 +08:00
|
|
|
|
2013-04-24 18:16:13 +08:00
|
|
|
/* The type of symlink to create. The value is set depending on the
|
|
|
|
"winsymlinks" setting of the CYGWIN environment variable. */
|
|
|
|
enum winsym_t
|
|
|
|
{
|
2021-07-17 22:47:34 +08:00
|
|
|
WSYM_default = 0,
|
2013-04-24 18:16:13 +08:00
|
|
|
WSYM_lnk,
|
|
|
|
WSYM_native,
|
2013-05-23 22:23:01 +08:00
|
|
|
WSYM_nativestrict,
|
2021-07-17 22:51:11 +08:00
|
|
|
WSYM_nfs,
|
|
|
|
WSYM_sysfile,
|
2013-04-24 18:16:13 +08:00
|
|
|
};
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
exit_states NO_COPY exit_state;
|
|
|
|
|
|
|
|
/* Set in init.cc. Used to check if Cygwin DLL is dynamically loaded. */
|
|
|
|
int NO_COPY dynamically_loaded;
|
|
|
|
|
2010-08-30 09:57:37 +08:00
|
|
|
/* Some CYGWIN environment variable variables. */
|
2009-01-03 13:12:22 +08:00
|
|
|
bool allow_glob = true;
|
2013-07-27 01:28:00 +08:00
|
|
|
bool ignore_case_with_glob;
|
2021-11-10 20:47:09 +08:00
|
|
|
bool pipe_byte = true; /* Default to byte mode so that C# programs work. */
|
2013-07-27 01:28:00 +08:00
|
|
|
bool reset_com;
|
|
|
|
bool wincmdln;
|
2021-07-17 22:47:34 +08:00
|
|
|
winsym_t allow_winsymlinks = WSYM_default;
|
2020-01-21 21:25:13 +08:00
|
|
|
bool disable_pcon;
|
2010-08-30 09:57:37 +08:00
|
|
|
|
2013-05-22 02:53:23 +08:00
|
|
|
/* Taken from BSD libc:
|
|
|
|
This variable is zero until a process has created a pthread. It is used
|
|
|
|
to avoid calling locking functions in libc when they are not required.
|
|
|
|
Note that this is moderately dangerous. Do not rely on it if the public
|
|
|
|
API is also used from a non-pthread thread like the signal thread. */
|
|
|
|
int NO_COPY __isthreaded = 0;
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
int __argc_safe;
|
|
|
|
int __argc;
|
|
|
|
char **__argv;
|
|
|
|
|
|
|
|
_cygtls NO_COPY *_main_tls /* !globals.h */;
|
|
|
|
|
|
|
|
bool NO_COPY cygwin_finished_initializing;
|
|
|
|
|
|
|
|
bool NO_COPY _cygwin_testing;
|
|
|
|
|
|
|
|
char NO_COPY almost_null[1];
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
/* Heavily-used const UNICODE_STRINGs are defined here once. The idea is a
|
|
|
|
speed improvement by not having to initialize a UNICODE_STRING every time
|
|
|
|
we make a string comparison. The _RDATA trick allows defining the strings
|
|
|
|
as const (so we get a SEGV if some code erroneously tries to overwrite
|
|
|
|
them), while declaring them as non-const in the auto-generated globals.h.
|
|
|
|
The strings are usually used in NT functions which don't take const
|
|
|
|
arguments. We avoid a lot of extra casts here...
|
|
|
|
Note: The "extern" is required, otherwise either the variables are dropped
|
|
|
|
entirely, or C++ name mangling is applied despite the extern "C"
|
|
|
|
bracket, depending on the compiler version */
|
|
|
|
#ifndef _RDATA
|
|
|
|
# define _RDATA const
|
|
|
|
#endif
|
|
|
|
|
2009-07-15 01:37:42 +08:00
|
|
|
#define _ROU(_s) \
|
2013-04-23 17:44:36 +08:00
|
|
|
{ Length: sizeof (_s) - sizeof (WCHAR), \
|
|
|
|
MaximumLength: sizeof (_s), \
|
|
|
|
Buffer: (PWSTR) (_s) }
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_scr = _ROU (L".scr");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_dev = _ROU (L"dev");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
|
2018-12-24 00:53:55 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_exfat = _ROU (L"exFAT");
|
2013-04-23 17:44:36 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_mvfs = _ROU (L"MVFS");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
|
2015-11-04 21:47:25 +08:00
|
|
|
/* No typo! It's actually "SF", not "FS", and the trailing NUL is counted
|
|
|
|
in the reply from the filesystem. */
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_prlfs = _ROU (L"PrlSF\0");
|
2013-04-23 17:44:36 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_refs = _ROU (L"ReFS");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_nwfs = _ROU (L"NWFS");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_ncfsd = _ROU (L"NcFsd");
|
2013-04-24 18:16:13 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_afs = _ROU (L"AFSRDRFsd");
|
2013-04-23 17:44:36 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_volume = _ROU (L"\\??\\Volume{");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_pipedir = _ROU (L"\\\\?\\PIPE\\");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_globalroot = _ROU (L"\\\\.\\GLOBALROOT");
|
2013-10-31 22:26:42 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_null = _ROU (L"\\Device\\Null");
|
2014-10-10 01:45:27 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_natdir = _ROU (L"Directory");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_natsyml = _ROU (L"SymbolicLink");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_natdev = _ROU (L"Device");
|
2018-03-07 22:48:21 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_npfs = _ROU (L"\\Device\\NamedPipe\\");
|
2021-05-25 22:49:04 +08:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_mq_suffix = _ROU (L":mqueue");
|
2013-04-23 17:44:36 +08:00
|
|
|
#undef _ROU
|
|
|
|
|
2022-07-29 04:00:40 +08:00
|
|
|
char **environ;
|
2024-01-31 22:21:31 +08:00
|
|
|
/* __progname used in getopt error message is an alias of
|
|
|
|
program_invocation_short_name. */
|
2010-12-27 05:11:38 +08:00
|
|
|
char *program_invocation_short_name;
|
2024-01-31 22:21:31 +08:00
|
|
|
char *program_invocation_name;
|
2009-01-03 13:12:22 +08:00
|
|
|
static MTinterface _mtinterf;
|
|
|
|
struct per_process __cygwin_user_data =
|
|
|
|
{/* initial_sp */ 0, /* magic_biscuit */ 0,
|
|
|
|
/* dll_major */ CYGWIN_VERSION_DLL_MAJOR,
|
|
|
|
/* dll_major */ CYGWIN_VERSION_DLL_MINOR,
|
2013-04-23 17:44:36 +08:00
|
|
|
/* impure_ptr_ptr */ NULL,
|
2009-01-03 13:12:22 +08:00
|
|
|
/* malloc */ malloc, /* free */ free,
|
|
|
|
/* realloc */ realloc,
|
|
|
|
/* fmode_ptr */ NULL, /* main */ NULL, /* ctors */ NULL,
|
|
|
|
/* dtors */ NULL, /* data_start */ NULL, /* data_end */ NULL,
|
|
|
|
/* bss_start */ NULL, /* bss_end */ NULL,
|
|
|
|
/* calloc */ calloc,
|
|
|
|
/* premain */ {NULL, NULL, NULL, NULL},
|
|
|
|
/* run_ctors_p */ 0,
|
2010-05-08 05:25:19 +08:00
|
|
|
/* unused */ {},
|
winsup/ChangeLog:
* Makefile.common (COMPILE_CXX): Add support for per-file overrides
to exclude $(nostdinc) and $(nostdincxx) from compiler flags.
(COMPILE_CC): Likewise for $(nostdinc).
winsup/cygwin/ChangeLog:
* Makefile.in (DLL_OFILES): Add libstdcxx_wrapper.o
(libstdcxx_wrapper_CFLAGS): Add flags for new module.
(_cygwin_crt0_common_STDINCFLAGS): Define per-file override.
(libstdcxx_wrapper_STDINCFLAGS, cxx_STDINCFLAGS): Likewise.
* cxx.cc: Include "cygwin-cxx.h".
(operator new): Tweak prototype for full standards compliance.
(operator new[]): Likewise.
(operator new (nothrow)): New fallback function.
(operator new[] (nothrow), operator delete (nothrow),
operator delete[] (nothrow)): Likewise.
(default_cygwin_cxx_malloc): New struct of pointers to the above,
for final last-resort fallback default.
* cygwin-cxx.h: New file.
(struct per_process_cxx_malloc): Define.
(default_cygwin_cxx_malloc): Declare extern.
* cygwin.din (__wrap__ZdaPv): Export new wrapper.
(__wrap__ZdaPvRKSt9nothrow_t, __wrap__ZdlPv,
__wrap__ZdlPvRKSt9nothrow_t, __wrap__Znaj,
__wrap__ZnajRKSt9nothrow_t, __wrap__Znwj,
__wrap__ZnwjRKSt9nothrow_t): Likewise.
* globals.cc (__cygwin_user_data): Init newly-repurposed 'forkee'
field (now 'cxx_malloc') to point to default_cygwin_cxx_malloc.
* libstdcxx_wrapper.cc: New file.
(__wrap__ZdaPv, __wrap__ZdaPvRKSt9nothrow_t, __wrap__ZdlPv,
__wrap__ZdlPvRKSt9nothrow_t, __wrap__Znaj,
__wrap__ZnajRKSt9nothrow_t, __wrap__Znwj,
__wrap__ZnwjRKSt9nothrow_t): Define wrapper functions for libstdc++
malloc operators and their overrides.
* winsup.h (default_cygwin_cxx_malloc): Declare extern.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* include/sys/cygwin.h (struct per_process_cxx_malloc): Forward
declare here.
(struct per_process::forkee): Rename and repurpose from this ...
(struct per_process::cxx_malloc): ... to this.
* lib/_cygwin_crt0_common.cc: Include cygwin-cxx.h.
(WEAK): Define shorthand helper macro.
(__cygwin_cxx_malloc): Define and populate with weak references
to whatever libstdc++ malloc operators will be visible at final
link time for Cygwin apps and dlls.
(_cygwin_crt0_common): Always look up cygwin DLL's internal
per_process data, and don't test for (impossible) failure. Inherit
any members of __cygwin_cxx_malloc that we don't have overrides
for from the DLL's default and store the resulting overall set of
overrides back into the DLL's global per_process data.
2009-07-08 04:12:44 +08:00
|
|
|
/* cxx_malloc */ &default_cygwin_cxx_malloc,
|
2009-01-03 13:12:22 +08:00
|
|
|
/* hmodule */ NULL,
|
2010-05-08 05:25:19 +08:00
|
|
|
/* api_major */ 0,
|
|
|
|
/* api_minor */ 0,
|
|
|
|
/* unused2 */ {},
|
2013-08-14 19:44:23 +08:00
|
|
|
/* posix_memalign */ posix_memalign,
|
2010-05-08 05:25:19 +08:00
|
|
|
/* pseudo_reloc_start */ NULL,
|
|
|
|
/* pseudo_reloc_end */ NULL,
|
|
|
|
/* image_base */ NULL,
|
2009-01-03 13:12:22 +08:00
|
|
|
/* threadinterface */ &_mtinterf,
|
|
|
|
/* impure_ptr */ _GLOBAL_REENT,
|
|
|
|
};
|
|
|
|
int _check_for_executable = true;
|
2024-01-29 20:33:05 +08:00
|
|
|
|
|
|
|
/* This was a bool initially, just indicating if we're in the forked
|
|
|
|
child during fork(2). However, we need an indicator accessible from
|
|
|
|
plain C we can ask if we're in a forked child even after fork(2)
|
|
|
|
finished. Therefore redefined how we use this variable. */
|
|
|
|
enum {
|
|
|
|
NOT_FORKED = 0,
|
|
|
|
FORKING = 1,
|
|
|
|
FORKED = 2
|
|
|
|
};
|
|
|
|
int NO_COPY __in_forkee;
|
2009-01-03 13:12:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int NO_COPY __api_fatal_exit_val = 1;
|
2024-01-31 22:21:31 +08:00
|
|
|
|
|
|
|
EXPORT_ALIAS (program_invocation_short_name, __progname)
|