OSDN Git Service

* autoload.cc (dll_load): Only perform DONT_RESOLVE_DLL_REFERENCES hack on
[pf3gnuchains/sourceware.git] / winsup / cygwin / wincap.cc
1 /* wincap.cc -- figure out on which OS we're running. Set the
2                 capability class to the appropriate values.
3
4    Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
5    2009, 2010, 2011 Red Hat, Inc.
6
7 This file is part of Cygwin.
8
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
11 details. */
12
13 #include "winsup.h"
14 #include "security.h"
15 #include "ntdll.h"
16
17 /* CV, 2008-10-23: All wincapc's have to be in the .cygwin_dll_common section,
18    same as wincap itself.  Otherwise the capability changes made in
19    wincapc::init() are not propagated to any subsequently started process
20    in the same session.  I'm only writing this longish comment because I'm
21    puzzled that this has never been noticed before... */
22
23 /* Minimal set of capabilities required to run Cygwin. */
24 #define wincap_minimal wincap_nt4sp4
25
26 wincaps wincap_nt4sp4 __attribute__((section (".cygwin_dll_common"), shared)) = {
27   chunksize:0,
28   heapslop:0x0,
29   max_sys_priv:SE_CHANGE_NOTIFY_PRIVILEGE,
30   is_server:false,
31   has_dacl_protect:false,
32   has_broken_if_oper_status:true,
33   has_physical_mem_access:true,
34   has_process_io_counters:false,
35   has_terminal_services:false,
36   has_create_global_privilege:false,
37   has_ioctl_storage_get_media_types_ex:false,
38   has_extended_priority_class:false,
39   has_guid_volumes:false,
40   has_disk_ex_ioctls:false,
41   has_fileid_dirinfo:false,
42   has_buggy_restart_scan:false,
43   has_mandatory_integrity_control:false,
44   needs_logon_sid_in_sid_list:true,
45   needs_count_in_si_lpres2:false,
46   has_recycle_dot_bin:false,
47   has_gaa_prefixes:false,
48   has_gaa_on_link_prefix:false,
49   supports_all_posix_ai_flags:false,
50   has_restricted_stack_args:false,
51   has_transactions:false,
52   ts_has_dep_problem:false,
53   has_recvmsg:false,
54   has_sendmsg:false,
55   has_broken_udf:false,
56   has_console_handle_problem:false,
57   has_broken_alloc_console:false,
58   has_always_all_codepages:false,
59   has_localenames:false,
60   has_mwmo_inputavailable:false,
61   has_buggy_thread_startup:false,
62   has_fast_cwd:false,
63   has_restricted_raw_disk_access:false,
64   use_dont_resolve_hack:false,
65 };
66
67 wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = {
68   chunksize:0,
69   heapslop:0x0,
70   max_sys_priv:SE_MANAGE_VOLUME_PRIVILEGE,
71   is_server:false,
72   has_dacl_protect:true,
73   has_broken_if_oper_status:false,
74   has_physical_mem_access:true,
75   has_process_io_counters:true,
76   has_terminal_services:true,
77   has_create_global_privilege:false,
78   has_ioctl_storage_get_media_types_ex:false,
79   has_extended_priority_class:true,
80   has_guid_volumes:true,
81   has_disk_ex_ioctls:false,
82   has_fileid_dirinfo:true,
83   has_buggy_restart_scan:true,
84   has_mandatory_integrity_control:false,
85   needs_logon_sid_in_sid_list:true,
86   needs_count_in_si_lpres2:false,
87   has_recycle_dot_bin:false,
88   has_gaa_prefixes:false,
89   has_gaa_on_link_prefix:false,
90   supports_all_posix_ai_flags:false,
91   has_restricted_stack_args:false,
92   has_transactions:false,
93   ts_has_dep_problem:false,
94   has_recvmsg:false,
95   has_sendmsg:false,
96   has_broken_udf:true,
97   has_console_handle_problem:false,
98   has_broken_alloc_console:false,
99   has_always_all_codepages:false,
100   has_localenames:false,
101   has_mwmo_inputavailable:true,
102   has_buggy_thread_startup:false,
103   has_fast_cwd:false,
104   has_restricted_raw_disk_access:false,
105   use_dont_resolve_hack:false,
106 };
107
108 wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = {
109   chunksize:0,
110   heapslop:0x0,
111   max_sys_priv:SE_CREATE_GLOBAL_PRIVILEGE,
112   is_server:false,
113   has_dacl_protect:true,
114   has_broken_if_oper_status:false,
115   has_physical_mem_access:true,
116   has_process_io_counters:true,
117   has_terminal_services:true,
118   has_create_global_privilege:true,
119   has_ioctl_storage_get_media_types_ex:false,
120   has_extended_priority_class:true,
121   has_guid_volumes:true,
122   has_disk_ex_ioctls:false,
123   has_fileid_dirinfo:true,
124   has_buggy_restart_scan:true,
125   has_mandatory_integrity_control:false,
126   needs_logon_sid_in_sid_list:true,
127   needs_count_in_si_lpres2:false,
128   has_recycle_dot_bin:false,
129   has_gaa_prefixes:false,
130   has_gaa_on_link_prefix:false,
131   supports_all_posix_ai_flags:false,
132   has_restricted_stack_args:false,
133   has_transactions:false,
134   ts_has_dep_problem:false,
135   has_recvmsg:false,
136   has_sendmsg:false,
137   has_broken_udf:true,
138   has_console_handle_problem:false,
139   has_broken_alloc_console:false,
140   has_always_all_codepages:false,
141   has_localenames:false,
142   has_mwmo_inputavailable:true,
143   has_buggy_thread_startup:false,
144   has_fast_cwd:false,
145   has_restricted_raw_disk_access:false,
146   use_dont_resolve_hack:false,
147 };
148
149 wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = {
150   chunksize:0,
151   heapslop:0x0,
152   max_sys_priv:SE_MANAGE_VOLUME_PRIVILEGE,
153   is_server:false,
154   has_dacl_protect:true,
155   has_broken_if_oper_status:false,
156   has_physical_mem_access:true,
157   has_process_io_counters:true,
158   has_terminal_services:true,
159   has_create_global_privilege:false,
160   has_ioctl_storage_get_media_types_ex:true,
161   has_extended_priority_class:true,
162   has_guid_volumes:true,
163   has_disk_ex_ioctls:true,
164   has_fileid_dirinfo:true,
165   has_buggy_restart_scan:false,
166   has_mandatory_integrity_control:false,
167   needs_logon_sid_in_sid_list:false,
168   needs_count_in_si_lpres2:false,
169   has_recycle_dot_bin:false,
170   has_gaa_prefixes:false,
171   has_gaa_on_link_prefix:false,
172   supports_all_posix_ai_flags:false,
173   has_restricted_stack_args:false,
174   has_transactions:false,
175   ts_has_dep_problem:false,
176   has_recvmsg:true,
177   has_sendmsg:false,
178   has_broken_udf:true,
179   has_console_handle_problem:false,
180   has_broken_alloc_console:false,
181   has_always_all_codepages:false,
182   has_localenames:false,
183   has_mwmo_inputavailable:true,
184   has_buggy_thread_startup:false,
185   has_fast_cwd:false,
186   has_restricted_raw_disk_access:false,
187   use_dont_resolve_hack:true,
188 };
189
190 wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = {
191   chunksize:0,
192   heapslop:0x0,
193   max_sys_priv:SE_MANAGE_VOLUME_PRIVILEGE,
194   is_server:false,
195   has_dacl_protect:true,
196   has_broken_if_oper_status:false,
197   has_physical_mem_access:true,
198   has_process_io_counters:true,
199   has_terminal_services:true,
200   has_create_global_privilege:false,
201   has_ioctl_storage_get_media_types_ex:true,
202   has_extended_priority_class:true,
203   has_guid_volumes:true,
204   has_disk_ex_ioctls:true,
205   has_fileid_dirinfo:true,
206   has_buggy_restart_scan:false,
207   has_mandatory_integrity_control:false,
208   needs_logon_sid_in_sid_list:false,
209   needs_count_in_si_lpres2:false,
210   has_recycle_dot_bin:false,
211   has_gaa_prefixes:true,
212   has_gaa_on_link_prefix:false,
213   supports_all_posix_ai_flags:false,
214   has_restricted_stack_args:false,
215   has_transactions:false,
216   ts_has_dep_problem:false,
217   has_recvmsg:true,
218   has_sendmsg:false,
219   has_broken_udf:true,
220   has_console_handle_problem:false,
221   has_broken_alloc_console:false,
222   has_always_all_codepages:false,
223   has_localenames:false,
224   has_mwmo_inputavailable:true,
225   has_buggy_thread_startup:false,
226   has_fast_cwd:false,
227   has_restricted_raw_disk_access:false,
228   use_dont_resolve_hack:true,
229 };
230
231 wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = {
232   chunksize:0,
233   heapslop:0x0,
234   max_sys_priv:SE_CREATE_GLOBAL_PRIVILEGE,
235   is_server:false,
236   has_dacl_protect:true,
237   has_broken_if_oper_status:false,
238   has_physical_mem_access:true,
239   has_process_io_counters:true,
240   has_terminal_services:true,
241   has_create_global_privilege:true,
242   has_ioctl_storage_get_media_types_ex:true,
243   has_extended_priority_class:true,
244   has_guid_volumes:true,
245   has_disk_ex_ioctls:true,
246   has_fileid_dirinfo:true,
247   has_buggy_restart_scan:false,
248   has_mandatory_integrity_control:false,
249   needs_logon_sid_in_sid_list:false,
250   needs_count_in_si_lpres2:false,
251   has_recycle_dot_bin:false,
252   has_gaa_prefixes:true,
253   has_gaa_on_link_prefix:false,
254   supports_all_posix_ai_flags:false,
255   has_restricted_stack_args:false,
256   has_transactions:false,
257   ts_has_dep_problem:false,
258   has_recvmsg:true,
259   has_sendmsg:false,
260   has_broken_udf:true,
261   has_console_handle_problem:false,
262   has_broken_alloc_console:false,
263   has_always_all_codepages:false,
264   has_localenames:false,
265   has_mwmo_inputavailable:true,
266   has_buggy_thread_startup:false,
267   has_fast_cwd:false,
268   has_restricted_raw_disk_access:false,
269   use_dont_resolve_hack:true,
270 };
271
272 wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = {
273   chunksize:0,
274   heapslop:0x4,
275   max_sys_priv:SE_CREATE_GLOBAL_PRIVILEGE,
276   is_server:true,
277   has_dacl_protect:true,
278   has_broken_if_oper_status:false,
279   has_physical_mem_access:false,
280   has_process_io_counters:true,
281   has_terminal_services:true,
282   has_create_global_privilege:true,
283   has_ioctl_storage_get_media_types_ex:true,
284   has_extended_priority_class:true,
285   has_guid_volumes:true,
286   has_disk_ex_ioctls:true,
287   has_fileid_dirinfo:true,
288   has_buggy_restart_scan:false,
289   has_mandatory_integrity_control:false,
290   needs_logon_sid_in_sid_list:false,
291   needs_count_in_si_lpres2:false,
292   has_recycle_dot_bin:false,
293   has_gaa_prefixes:true,
294   has_gaa_on_link_prefix:false,
295   supports_all_posix_ai_flags:false,
296   has_restricted_stack_args:true,
297   has_transactions:false,
298   ts_has_dep_problem:false,
299   has_recvmsg:true,
300   has_sendmsg:false,
301   has_broken_udf:true,
302   has_console_handle_problem:false,
303   has_broken_alloc_console:false,
304   has_always_all_codepages:false,
305   has_localenames:false,
306   has_mwmo_inputavailable:true,
307   has_buggy_thread_startup:false,
308   has_fast_cwd:false,
309   has_restricted_raw_disk_access:false,
310   use_dont_resolve_hack:false,
311 };
312
313 wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
314   chunksize:0,
315   heapslop:0x4,
316   max_sys_priv:SE_CREATE_SYMBOLIC_LINK_PRIVILEGE,
317   is_server:false,
318   has_dacl_protect:true,
319   has_broken_if_oper_status:false,
320   has_physical_mem_access:false,
321   has_process_io_counters:true,
322   has_terminal_services:true,
323   has_create_global_privilege:true,
324   has_ioctl_storage_get_media_types_ex:true,
325   has_extended_priority_class:true,
326   has_guid_volumes:true,
327   has_disk_ex_ioctls:true,
328   has_fileid_dirinfo:true,
329   has_buggy_restart_scan:false,
330   has_mandatory_integrity_control:true,
331   needs_logon_sid_in_sid_list:false,
332   needs_count_in_si_lpres2:true,
333   has_recycle_dot_bin:true,
334   has_gaa_prefixes:true,
335   has_gaa_on_link_prefix:true,
336   supports_all_posix_ai_flags:true,
337   has_restricted_stack_args:false,
338   has_transactions:true,
339   ts_has_dep_problem:false,
340   has_recvmsg:true,
341   has_sendmsg:true,
342   has_broken_udf:false,
343   has_console_handle_problem:false,
344   has_broken_alloc_console:false,
345   has_always_all_codepages:true,
346   has_localenames:true,
347   has_mwmo_inputavailable:true,
348   has_buggy_thread_startup:true,
349   has_fast_cwd:true,
350   has_restricted_raw_disk_access:true,
351   use_dont_resolve_hack:false,
352 };
353
354 wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
355   chunksize:0,
356   heapslop:0x4,
357   max_sys_priv:SE_CREATE_SYMBOLIC_LINK_PRIVILEGE,
358   is_server:false,
359   has_dacl_protect:true,
360   has_broken_if_oper_status:false,
361   has_physical_mem_access:false,
362   has_process_io_counters:true,
363   has_terminal_services:true,
364   has_create_global_privilege:true,
365   has_ioctl_storage_get_media_types_ex:true,
366   has_extended_priority_class:true,
367   has_guid_volumes:true,
368   has_disk_ex_ioctls:true,
369   has_fileid_dirinfo:true,
370   has_buggy_restart_scan:false,
371   has_mandatory_integrity_control:true,
372   needs_logon_sid_in_sid_list:false,
373   needs_count_in_si_lpres2:false,
374   has_recycle_dot_bin:true,
375   has_gaa_prefixes:true,
376   has_gaa_on_link_prefix:true,
377   supports_all_posix_ai_flags:true,
378   has_restricted_stack_args:false,
379   has_transactions:true,
380   ts_has_dep_problem:false,
381   has_recvmsg:true,
382   has_sendmsg:true,
383   has_broken_udf:false,
384   has_console_handle_problem:true,
385   has_broken_alloc_console:true,
386   has_always_all_codepages:true,
387   has_localenames:true,
388   has_mwmo_inputavailable:true,
389   has_buggy_thread_startup:false,
390   has_fast_cwd:true,
391   has_restricted_raw_disk_access:true,
392   use_dont_resolve_hack:false,
393 };
394
395 wincapc wincap __attribute__((section (".cygwin_dll_common"), shared));
396
397 void
398 wincapc::init ()
399 {
400   bool has_osversioninfoex = true;
401
402   if (caps)
403     return;             // already initialized
404
405   memset (&version, 0, sizeof version);
406   /* Request versionex info first, which is available on all systems since
407      NT4 SP6 anyway.  If that fails, call the simple version. */
408   version.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
409   if (!GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&version)))
410     {
411       has_osversioninfoex = false;
412       version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
413       GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&version));
414     }
415
416   switch (version.dwPlatformId)
417     {
418       case VER_PLATFORM_WIN32_NT:
419         switch (version.dwMajorVersion)
420           {
421             case 4:
422               /* No mercy.  We require at least NT4 SP4. */
423               caps = &wincap_nt4sp4;
424               break;
425             case 5:
426               switch (version.dwMinorVersion)
427                 {
428                   case 0:
429                     if (version.wServicePackMajor < 4)
430                       caps = &wincap_2000;
431                     else
432                       caps = &wincap_2000sp4;
433                     break;
434
435                   case 1:
436                     caps = &wincap_xp;
437                     switch (version.wServicePackMajor)
438                       {
439                       case 0:
440                         caps = &wincap_xp;
441                       case 1:
442                         caps = &wincap_xpsp1;
443                       default:
444                         caps = &wincap_xpsp2;
445                       }
446                     break;
447
448                   default:
449                     caps = &wincap_2003;
450                 }
451               break;
452             case 6:
453               switch (version.dwMinorVersion)
454                 {
455                   case 0:
456                     caps = &wincap_vista;
457                     break;
458                   default:
459                     caps = &wincap_7;
460                     break;
461                 }
462               break;
463             default:
464               caps = &wincap_minimal;
465               break;
466           }
467         break;
468       case VER_PLATFORM_WIN32_WINDOWS:
469         /* I'd be very surprised if this code is ever hit, but it doesn't
470            hurt to keep it. */
471         api_fatal ("Windows 95/98/Me are not supported.");
472         break;
473       default:
474         caps = &wincap_minimal;
475         break;
476     }
477
478   if (has_osversioninfoex && version.wProductType != VER_NT_WORKSTATION)
479     {
480       ((wincaps *)caps)->is_server = true;
481       if (version.dwMajorVersion >= 6
482           && (version.wSuiteMask
483               & (VER_SUITE_TERMINAL | VER_SUITE_SINGLEUSERTS))
484              == VER_SUITE_TERMINAL)
485         ((wincaps *)caps)->ts_has_dep_problem = true;
486     }
487   if (NT_SUCCESS (NtQueryInformationProcess (NtCurrentProcess (),
488                                              ProcessWow64Information,
489                                              &wow64, sizeof wow64, NULL))
490       && !wow64)
491     {
492       ((wincaps *)caps)->needs_count_in_si_lpres2 = false;
493       ((wincaps *)caps)->has_restricted_stack_args = false;
494     }
495
496   if (!wow64)
497     ((wincaps *) caps)->has_buggy_thread_startup = false;
498   __small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion,
499                    version.dwMinorVersion);
500 }
501
502 void
503 wincapc::set_chunksize (DWORD nchunksize)
504 {
505   ((wincaps *)caps)->chunksize = nchunksize;
506 }