2009-01-03 06:12:22 +01: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-19 18:49:40 +01:00
|
|
|
#define NO_GLOBALS_H
|
2009-01-03 06:12:22 +01:00
|
|
|
#include "winsup.h"
|
|
|
|
#include "cygtls.h"
|
|
|
|
#include "perprocess.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <cygwin/version.h>
|
|
|
|
|
2009-12-21 10:38:25 +01:00
|
|
|
HANDLE NO_COPY hMainThread;
|
2009-01-03 06:12:22 +01:00
|
|
|
HANDLE NO_COPY hProcToken;
|
|
|
|
HANDLE NO_COPY hProcImpToken;
|
2012-03-20 16:07:30 +01:00
|
|
|
HANDLE my_wr_proc_pipe;
|
2009-01-03 06:12:22 +01:00
|
|
|
HMODULE NO_COPY cygwin_hmodule;
|
2013-12-09 21:32:24 +01:00
|
|
|
HMODULE NO_COPY hntdll;
|
2009-10-06 05:39:38 +02:00
|
|
|
int NO_COPY sigExeced;
|
2011-12-13 21:06:31 +01:00
|
|
|
WCHAR windows_system_directory[MAX_PATH];
|
|
|
|
UINT windows_system_directory_length;
|
2017-11-27 14:36:06 +01:00
|
|
|
#ifdef __i386__
|
2011-12-13 21:06:31 +01:00
|
|
|
WCHAR system_wow64_directory[MAX_PATH];
|
|
|
|
UINT system_wow64_directory_length;
|
2017-11-27 14:36:06 +01:00
|
|
|
#endif /* __i386__ */
|
2015-07-19 22:38:30 +02:00
|
|
|
WCHAR global_progname[NT_MAX_PATH];
|
2009-01-03 06:12:22 +01:00
|
|
|
|
|
|
|
/* program exit the program */
|
|
|
|
|
|
|
|
enum exit_states
|
2012-03-19 18:49:40 +01:00
|
|
|
{
|
|
|
|
ES_NOT_EXITING = 0,
|
|
|
|
ES_EXIT_STARTING,
|
2013-01-04 03:21:03 +01:00
|
|
|
ES_SIGNAL_EXIT,
|
2012-03-19 18:49:40 +01: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 06:12:22 +01:00
|
|
|
|
2013-04-24 12:16:13 +02:00
|
|
|
/* The type of symlink to create. The value is set depending on the
|
|
|
|
"winsymlinks" setting of the CYGWIN environment variable. */
|
|
|
|
enum winsym_t
|
|
|
|
{
|
|
|
|
WSYM_sysfile = 0,
|
|
|
|
WSYM_lnk,
|
|
|
|
WSYM_native,
|
2013-05-23 16:23:01 +02:00
|
|
|
WSYM_nativestrict,
|
2013-04-24 12:16:13 +02:00
|
|
|
WSYM_nfs
|
|
|
|
};
|
|
|
|
|
2009-01-03 06:12:22 +01: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 03:57:37 +02:00
|
|
|
/* Some CYGWIN environment variable variables. */
|
2009-01-03 06:12:22 +01:00
|
|
|
bool allow_glob = true;
|
2014-10-28 11:44:49 +01:00
|
|
|
bool dos_file_warning;
|
2013-07-26 19:28:00 +02:00
|
|
|
bool ignore_case_with_glob;
|
|
|
|
bool pipe_byte;
|
|
|
|
bool reset_com;
|
|
|
|
bool wincmdln;
|
2013-04-24 12:16:13 +02:00
|
|
|
winsym_t allow_winsymlinks = WSYM_sysfile;
|
2010-08-30 03:57:37 +02:00
|
|
|
|
2009-01-03 06:12:22 +01:00
|
|
|
bool NO_COPY in_forkee;
|
|
|
|
|
2013-05-21 20:53:23 +02: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 06:12:22 +01: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 11:44:36 +02:00
|
|
|
extern "C" {
|
|
|
|
|
2015-11-18 20:51:12 +01:00
|
|
|
/* We never have a collate load error. */
|
|
|
|
const int __collate_load_error = 0;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
/* 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-14 19:37:42 +02:00
|
|
|
#define _ROU(_s) \
|
2013-04-23 11:44:36 +02: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_dll = _ROU (L".dll");
|
|
|
|
extern UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
|
|
|
|
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-23 17:53:55 +01:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_exfat = _ROU (L"exFAT");
|
2013-04-23 11:44:36 +02: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 14:47:25 +01: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 11:44:36 +02: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 12:16:13 +02:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_afs = _ROU (L"AFSRDRFsd");
|
2013-04-23 11:44:36 +02: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 15:26:42 +01:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_null = _ROU (L"\\Device\\Null");
|
2014-10-09 19:45:27 +02: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 15:48:21 +01:00
|
|
|
extern UNICODE_STRING _RDATA ro_u_npfs = _ROU (L"\\Device\\NamedPipe\\");
|
2013-04-23 11:44:36 +02:00
|
|
|
#undef _ROU
|
|
|
|
|
2009-01-03 06:12:22 +01:00
|
|
|
/* This is an exported copy of environ which can be used by DLLs
|
|
|
|
which use cygwin.dll. */
|
|
|
|
char **__cygwin_environ;
|
2017-11-27 14:36:06 +01:00
|
|
|
#ifdef __i386__
|
2009-01-03 06:12:22 +01:00
|
|
|
char ***main_environ = &__cygwin_environ;
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2009-01-03 06:12:22 +01:00
|
|
|
/* __progname used in getopt error message */
|
|
|
|
char *__progname;
|
2010-12-26 22:11:38 +01:00
|
|
|
char *program_invocation_name;
|
|
|
|
char *program_invocation_short_name;
|
2009-01-03 06:12:22 +01: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 11:44:36 +02:00
|
|
|
/* impure_ptr_ptr */ NULL,
|
2017-11-27 14:36:06 +01:00
|
|
|
#ifdef __i386__
|
2013-04-23 11:44:36 +02:00
|
|
|
/* envptr */ NULL,
|
|
|
|
#endif
|
2009-01-03 06:12:22 +01: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-07 23:25:19 +02: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-07 22:12:44 +02:00
|
|
|
/* cxx_malloc */ &default_cygwin_cxx_malloc,
|
2009-01-03 06:12:22 +01:00
|
|
|
/* hmodule */ NULL,
|
2010-05-07 23:25:19 +02:00
|
|
|
/* api_major */ 0,
|
|
|
|
/* api_minor */ 0,
|
|
|
|
/* unused2 */ {},
|
2013-08-14 13:44:23 +02:00
|
|
|
/* posix_memalign */ posix_memalign,
|
2010-05-07 23:25:19 +02:00
|
|
|
/* pseudo_reloc_start */ NULL,
|
|
|
|
/* pseudo_reloc_end */ NULL,
|
|
|
|
/* image_base */ NULL,
|
2009-01-03 06:12:22 +01:00
|
|
|
/* threadinterface */ &_mtinterf,
|
|
|
|
/* impure_ptr */ _GLOBAL_REENT,
|
|
|
|
};
|
|
|
|
int _check_for_executable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
int NO_COPY __api_fatal_exit_val = 1;
|