2009-01-03 13:12:22 +08:00
|
|
|
/* globals.cc - Define global variables here.
|
|
|
|
|
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
2011-02-15 23:25:59 +08:00
|
|
|
2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
|
2009-01-03 13:12:22 +08:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#define _GLOBALS_H 1
|
|
|
|
#include "winsup.h"
|
|
|
|
#include "cygtls.h"
|
|
|
|
#include "perprocess.h"
|
2009-10-31 21:24:06 +08:00
|
|
|
#include "cygprops.h"
|
2009-01-03 13:12:22 +08:00
|
|
|
#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;
|
|
|
|
HMODULE NO_COPY cygwin_hmodule;
|
|
|
|
HANDLE hExeced;
|
2009-10-06 11:39:38 +08:00
|
|
|
int NO_COPY sigExeced;
|
2010-08-28 16:51:21 +08:00
|
|
|
WCHAR NO_COPY windows_system_directory[MAX_PATH];
|
|
|
|
UINT NO_COPY windows_system_directory_length;
|
2009-01-03 13:12:22 +08:00
|
|
|
|
|
|
|
/* program exit the program */
|
|
|
|
|
|
|
|
enum exit_states
|
|
|
|
{
|
|
|
|
ES_NOT_EXITING = 0,
|
2010-03-29 01:27:52 +08:00
|
|
|
ES_EXIT_STARTING,
|
2009-01-03 13:12:22 +08:00
|
|
|
ES_PROCESS_LOCKED,
|
|
|
|
ES_EVENTS_TERMINATE,
|
|
|
|
ES_SIGNAL,
|
|
|
|
ES_CLOSEALL,
|
2010-10-25 02:50:57 +08:00
|
|
|
ES_THREADTERM,
|
2009-01-03 13:12:22 +08:00
|
|
|
ES_HUP_PGRP,
|
|
|
|
ES_HUP_SID,
|
|
|
|
ES_EXEC_EXIT,
|
|
|
|
ES_TITLE,
|
|
|
|
ES_TTY_TERMINATE,
|
|
|
|
ES_FINAL
|
|
|
|
};
|
|
|
|
|
|
|
|
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 display_title;
|
|
|
|
bool strip_title_path;
|
|
|
|
bool allow_glob = true;
|
2010-08-30 09:57:37 +08:00
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
bool NO_COPY in_forkee;
|
|
|
|
|
|
|
|
int __argc_safe;
|
|
|
|
int __argc;
|
|
|
|
char **__argv;
|
|
|
|
#ifdef NEWVFORK
|
|
|
|
vfork_save NO_COPY *main_vfork;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_cygtls NO_COPY *_main_tls /* !globals.h */;
|
|
|
|
|
|
|
|
bool NO_COPY cygwin_finished_initializing;
|
|
|
|
|
|
|
|
bool NO_COPY _cygwin_testing;
|
|
|
|
|
|
|
|
char NO_COPY almost_null[1];
|
|
|
|
|
|
|
|
char *old_title;
|
|
|
|
|
2009-10-31 21:24:06 +08:00
|
|
|
/* Define globally used, but readonly variables using the _RDATA attribute. */
|
|
|
|
#define _RDATA __attribute__ ((section(".rdata")))
|
|
|
|
|
2009-07-17 17:00:19 +08: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 strings are not defined as const,
|
|
|
|
because the respective NT functions are not taking const arguments
|
|
|
|
and doing so here results in lots of extra casts for no good reason.
|
|
|
|
Rather, the strings are placed in the R/O section .rdata, so we get
|
|
|
|
a SEGV if some code erroneously tries to overwrite these strings. */
|
2009-07-15 01:37:42 +08:00
|
|
|
#define _ROU(_s) \
|
|
|
|
{ Length: sizeof (_s) - sizeof (WCHAR), \
|
|
|
|
MaximumLength: sizeof (_s), \
|
|
|
|
Buffer: (PWSTR) (_s) }
|
|
|
|
UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
|
|
|
|
UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
|
|
|
|
UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
|
2009-11-21 20:44:13 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_dll = _ROU (L".dll");
|
2009-07-15 01:37:42 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
|
2009-11-07 04:51:03 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_scr = _ROU (L".scr");
|
|
|
|
UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
|
2009-07-15 01:37:42 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
|
2011-02-15 23:25:59 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\Device\\PhysicalMemory");
|
2009-07-16 17:56:25 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
|
|
|
|
UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
|
2009-07-15 01:37:42 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
|
|
|
|
UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
|
2009-07-16 17:56:25 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
|
|
|
|
UNICODE_STRING _RDATA ro_u_mvfs = _ROU (L"MVFS");
|
2009-07-15 01:37:42 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
|
2009-07-16 17:56:25 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
|
2009-07-15 01:37:42 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_sunwnfs = _ROU (L"SUNWNFS");
|
|
|
|
UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
|
2009-07-16 17:56:25 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
|
2010-01-12 22:47:46 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_nwfs = _ROU (L"NWFS");
|
2009-08-24 19:14:30 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_volume = _ROU (L"\\??\\Volume{");
|
2010-08-28 01:58:45 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_pipedir = _ROU (L"\\\\?\\PIPE\\");
|
2011-02-15 23:25:59 +08:00
|
|
|
UNICODE_STRING _RDATA ro_u_globalroot = _ROU (L"\\\\.\\GLOBALROOT");
|
2009-07-15 01:37:42 +08:00
|
|
|
#undef _ROU
|
|
|
|
|
2009-10-31 21:24:06 +08:00
|
|
|
/* Cygwin properties are meant to be readonly data placed in the DLL, but
|
|
|
|
which can be changed by external tools to make adjustments to the
|
|
|
|
behaviour of a DLL based on the binary of the DLL itself. This is
|
|
|
|
different from $CYGWIN since it only affects that very DLL, not all
|
|
|
|
DLLs which have access to the $CYGWIN environment variable. */
|
|
|
|
cygwin_props_t _RDATA cygwin_props =
|
|
|
|
{
|
|
|
|
CYGWIN_PROPS_MAGIC,
|
|
|
|
sizeof (cygwin_props_t),
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef _RDATA
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
/* This is an exported copy of environ which can be used by DLLs
|
|
|
|
which use cygwin.dll. */
|
|
|
|
char **__cygwin_environ;
|
|
|
|
char ***main_environ = &__cygwin_environ;
|
|
|
|
/* __progname used in getopt error message */
|
|
|
|
char *__progname;
|
2010-12-27 05:11:38 +08:00
|
|
|
char *program_invocation_name;
|
|
|
|
char *program_invocation_short_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,
|
|
|
|
/* impure_ptr_ptr */ NULL, /* envptr */ NULL,
|
|
|
|
/* 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 */ {},
|
|
|
|
/* 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,
|
|
|
|
};
|
|
|
|
bool ignore_case_with_glob;
|
|
|
|
int _check_for_executable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
int NO_COPY __api_fatal_exit_val = 1;
|