OSDN Git Service

b50bf8460081f1814becd498780355b70d5a63b8
[pf3gnuchains/pf3gnuchains3x.git] / winsup / cygwin / globals.cc
1 /* globals.cc - Define global variables here.
2
3    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4    2006, 2007, 2008, 2009 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 #define _GLOBALS_H 1
13 #include "winsup.h"
14 #include "cygtls.h"
15 #include "perprocess.h"
16 #include "thread.h"
17 #include <malloc.h>
18 #include <cygwin/version.h>
19
20 HANDLE NO_COPY hMainProc = (HANDLE) -1;
21 HANDLE NO_COPY hMainThread;
22 HANDLE NO_COPY hProcToken;
23 HANDLE NO_COPY hProcImpToken;
24 HMODULE NO_COPY cygwin_hmodule;
25 HANDLE hExeced;
26
27 /* program exit the program */
28
29 enum exit_states
30   {
31     ES_NOT_EXITING = 0,
32     ES_PROCESS_LOCKED,
33     ES_EVENTS_TERMINATE,
34     ES_THREADTERM,
35     ES_SIGNAL,
36     ES_CLOSEALL,
37     ES_HUP_PGRP,
38     ES_HUP_SID,
39     ES_EXEC_EXIT,
40     ES_TITLE,
41     ES_TTY_TERMINATE,
42     ES_FINAL
43   };
44
45 exit_states NO_COPY exit_state;
46
47 SYSTEM_INFO system_info;
48
49 /* Set in init.cc.  Used to check if Cygwin DLL is dynamically loaded. */
50 int NO_COPY dynamically_loaded;
51
52 bool display_title;
53 bool strip_title_path;
54 bool allow_glob = true;
55 bool NO_COPY in_forkee;
56
57 int __argc_safe;
58 int __argc;
59 char **__argv;
60 #ifdef NEWVFORK
61 vfork_save NO_COPY *main_vfork;
62 #endif
63
64 _cygtls NO_COPY *_main_tls /* !globals.h */;
65
66 bool NO_COPY cygwin_finished_initializing;
67
68 bool NO_COPY _cygwin_testing;
69
70 char NO_COPY almost_null[1];
71
72 char *old_title;
73
74 /* Heavily-used const UNICODE_STRINGs are defined here once.  The idea is a
75    speed improvement by not having to initialize a UNICODE_STRING every time
76    we make a string comparison.  The strings are not defined as const,
77    because the respective NT functions are not taking const arguments
78    and doing so here results in lots of extra casts for no good reason.
79    Rather, the strings are placed in the R/O section .rdata, so we get
80    a SEGV if some code erroneously tries to overwrite these strings. */
81 #define _ROU(_s) \
82         { Length: sizeof (_s) - sizeof (WCHAR), \
83           MaximumLength: sizeof (_s), \
84           Buffer: (PWSTR) (_s) }
85 #define _RDATA __attribute__ ((section(".rdata")))
86 UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
87 UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
88 UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
89 UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
90 UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
91 UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
92 UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
93 UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
94 UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
95 UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
96 UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
97 UNICODE_STRING _RDATA ro_u_mvfs = _ROU (L"MVFS");
98 UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
99 UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
100 UNICODE_STRING _RDATA ro_u_sunwnfs = _ROU (L"SUNWNFS");
101 UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
102 UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
103 #undef _RDATA
104 #undef _ROU
105
106 extern "C"
107 {
108   /* This is an exported copy of environ which can be used by DLLs
109      which use cygwin.dll.  */
110   char **__cygwin_environ;
111   char ***main_environ = &__cygwin_environ;
112   /* __progname used in getopt error message */
113   char *__progname;
114   static MTinterface _mtinterf;
115   struct per_process __cygwin_user_data =
116   {/* initial_sp */ 0, /* magic_biscuit */ 0,
117    /* dll_major */ CYGWIN_VERSION_DLL_MAJOR,
118    /* dll_major */ CYGWIN_VERSION_DLL_MINOR,
119    /* impure_ptr_ptr */ NULL, /* envptr */ NULL,
120    /* malloc */ malloc, /* free */ free,
121    /* realloc */ realloc,
122    /* fmode_ptr */ NULL, /* main */ NULL, /* ctors */ NULL,
123    /* dtors */ NULL, /* data_start */ NULL, /* data_end */ NULL,
124    /* bss_start */ NULL, /* bss_end */ NULL,
125    /* calloc */ calloc,
126    /* premain */ {NULL, NULL, NULL, NULL},
127    /* run_ctors_p */ 0,
128    /* unused */ {0, 0, 0, 0, 0, 0, 0},
129    /* cxx_malloc */ &default_cygwin_cxx_malloc,
130    /* hmodule */ NULL,
131    /* api_major */ CYGWIN_VERSION_API_MAJOR,
132    /* api_minor */ CYGWIN_VERSION_API_MINOR,
133    /* unused2 */ {0, 0, 0, 0, 0, 0},
134    /* threadinterface */ &_mtinterf,
135    /* impure_ptr */ _GLOBAL_REENT,
136   };
137   bool ignore_case_with_glob;
138   int _check_for_executable = true;
139 };
140
141 int NO_COPY __api_fatal_exit_val = 1;