* Makefile.in (DLL_IMPORTS): Add libntdll.a.

* autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and
	ntdll.dll available on all platforms since NT4.

	Throughout remove all usage of wincap.is_winnt.
	* dcrt0.cc (dll_crt0_0): Remove call to mmap_init.
	* fhandler.h (class fhandler_base): Remove has_changed flag.
	(fhandler_disk_file::touch_ctime): Remove declaration.
	(fhandler_disk_file::readdir_9x): Ditto.
	(fhandler_disk_file::touch_ctime): Remove.
	(fhandler_disk_file::readdir_9x): Remove.
	(fhandler_disk_file::closedir): Call NtClose instead of CloseHandle.
	* mmap.cc: Throughout call CreateMapping and MapView directly.
	(VirtualProt9x): Remove.
	(VirtualProtNT): Remove.
	(VirtualProtEx9x): Remove.
	(VirtualProtExNT): Remove.
	(VirtualProtect): Remove define.
	(VirtualProtectEx): Remove define.
	(CreateMapping9x): Remove.
	(CreateMappingNT): Rename to CreateMapping.
	(MapView9x): Remove.
	(MapViewNT): Rename to MapView.
	(struct mmap_func_t): Remove definition.
	(mmap_funcs_9x): Remove.
	(mmap_funcs_nt): Remove.
	(mmap_func): Remove.
	(mmap_init): Remove.
	* net.cc (getdomainname): Drop comment. Use NT4 registry key only.
	(get_95_ifconf): Remove.
	* pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes.
	(winpids::enum9x): Remove.
	(winpids::set): Just call enum_processes directly.
	(winpids::enum_init): Ditto.
	* pinfo.h (class winpids): Drop enum_processes pointer.  Rename
	enumNT to enum_processes.  Drop enum9x declaration.  Drop initialization
	of enum_processes throughout.
	* registry.cc (get_registry_hive_path): Just create NT key.
	(load_registry_hive): Only load NT specific file.
	* syscalls.cc (unlink_9x): Remove.
	(unlink): Just call unlink_nt.
	* wincap.cc: Remove is_winnt flag throughout.
	* wincap.h: Ditto.
	* winsup.h: Remove mmap_init declaration.
This commit is contained in:
Corinna Vinschen
2007-02-22 10:54:47 +00:00
parent 8782b2a2af
commit 570858c30f
24 changed files with 485 additions and 1252 deletions

View File

@ -1,3 +1,50 @@
2007-02-22 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_IMPORTS): Add libntdll.a.
* autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and
ntdll.dll available on all platforms since NT4.
Throughout remove all usage of wincap.is_winnt.
* dcrt0.cc (dll_crt0_0): Remove call to mmap_init.
* fhandler.h (class fhandler_base): Remove has_changed flag.
(fhandler_disk_file::touch_ctime): Remove declaration.
(fhandler_disk_file::readdir_9x): Ditto.
(fhandler_disk_file::touch_ctime): Remove.
(fhandler_disk_file::readdir_9x): Remove.
(fhandler_disk_file::closedir): Call NtClose instead of CloseHandle.
* mmap.cc: Throughout call CreateMapping and MapView directly.
(VirtualProt9x): Remove.
(VirtualProtNT): Remove.
(VirtualProtEx9x): Remove.
(VirtualProtExNT): Remove.
(VirtualProtect): Remove define.
(VirtualProtectEx): Remove define.
(CreateMapping9x): Remove.
(CreateMappingNT): Rename to CreateMapping.
(MapView9x): Remove.
(MapViewNT): Rename to MapView.
(struct mmap_func_t): Remove definition.
(mmap_funcs_9x): Remove.
(mmap_funcs_nt): Remove.
(mmap_func): Remove.
(mmap_init): Remove.
* net.cc (getdomainname): Drop comment. Use NT4 registry key only.
(get_95_ifconf): Remove.
* pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes.
(winpids::enum9x): Remove.
(winpids::set): Just call enum_processes directly.
(winpids::enum_init): Ditto.
* pinfo.h (class winpids): Drop enum_processes pointer. Rename
enumNT to enum_processes. Drop enum9x declaration. Drop initialization
of enum_processes throughout.
* registry.cc (get_registry_hive_path): Just create NT key.
(load_registry_hive): Only load NT specific file.
* syscalls.cc (unlink_9x): Remove.
(unlink): Just call unlink_nt.
* wincap.cc: Remove is_winnt flag throughout.
* wincap.h: Ditto.
* winsup.h: Remove mmap_init declaration.
2007-02-21 Corinna Vinschen <corinna@vinschen.de> 2007-02-21 Corinna Vinschen <corinna@vinschen.de>
* wincap.cc (wincap_unknown): Change settings for unknown to reflect * wincap.cc (wincap_unknown): Change settings for unknown to reflect

View File

@ -119,7 +119,7 @@ EXTRA_OFILES=$(bupdir1)/libiberty/random.o
MALLOC_OFILES=@MALLOC_OFILES@ MALLOC_OFILES=@MALLOC_OFILES@
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libadvapi32.a DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libadvapi32.a $(w32api_lib)/libntdll.a
MT_SAFE_OBJECTS:= MT_SAFE_OBJECTS:=
# Please maintain this list in sorted order, with maximum files per 86 col line # Please maintain this list in sorted order, with maximum files per 86 col line

View File

@ -298,78 +298,7 @@ wsock_init ()
LoadDLLprime (ws2_32, _wsock_init) LoadDLLprime (ws2_32, _wsock_init)
LoadDLLfunc (AccessCheck, 32, advapi32)
LoadDLLfunc (AddAccessAllowedAce, 16, advapi32)
LoadDLLfunc (AddAccessDeniedAce, 16, advapi32)
LoadDLLfunc (AddAce, 20, advapi32)
LoadDLLfunc (AdjustTokenPrivileges, 24, advapi32)
LoadDLLfuncEx (AllocateLocallyUniqueId, 4, advapi32, 1)
LoadDLLfunc (CopySid, 12, advapi32)
LoadDLLfunc (CreateProcessAsUserA, 44, advapi32)
LoadDLLfuncEx (CryptAcquireContextA, 20, advapi32, 1)
LoadDLLfuncEx (CryptGenRandom, 12, advapi32, 1)
LoadDLLfuncEx (CryptReleaseContext, 8, advapi32, 1)
LoadDLLfunc (DeregisterEventSource, 4, advapi32)
LoadDLLfunc (DuplicateToken, 12, advapi32)
LoadDLLfuncEx (DuplicateTokenEx, 24, advapi32, 1)
LoadDLLfunc (EqualPrefixSid, 8, advapi32)
LoadDLLfunc (EqualSid, 8, advapi32)
LoadDLLfunc (FindFirstFreeAce, 8, advapi32)
LoadDLLfunc (GetAce, 12, advapi32)
LoadDLLfunc (GetFileSecurityA, 20, advapi32)
LoadDLLfunc (GetKernelObjectSecurity, 20, advapi32)
LoadDLLfunc (GetLengthSid, 4, advapi32)
LoadDLLfunc (GetSecurityDescriptorDacl, 16, advapi32)
LoadDLLfunc (GetSecurityDescriptorGroup, 12, advapi32)
LoadDLLfunc (GetSecurityDescriptorOwner, 12, advapi32)
LoadDLLfunc (GetSecurityInfo, 32, advapi32)
LoadDLLfunc (GetSidIdentifierAuthority, 4, advapi32)
LoadDLLfunc (GetSidSubAuthority, 8, advapi32)
LoadDLLfunc (GetSidSubAuthorityCount, 4, advapi32)
LoadDLLfunc (GetTokenInformation, 20, advapi32)
LoadDLLfunc (GetUserNameA, 8, advapi32)
LoadDLLfunc (ImpersonateLoggedOnUser, 4, advapi32)
LoadDLLfunc (ImpersonateNamedPipeClient, 4, advapi32)
LoadDLLfunc (InitializeAcl, 12, advapi32)
LoadDLLfunc (InitializeSecurityDescriptor, 8, advapi32)
LoadDLLfunc (InitializeSid, 12, advapi32)
LoadDLLfunc (IsValidSid, 4, advapi32)
LoadDLLfunc (LogonUserA, 24, advapi32)
LoadDLLfunc (LookupAccountNameA, 28, advapi32)
LoadDLLfunc (LookupAccountNameW, 28, advapi32)
LoadDLLfunc (LookupAccountSidA, 28, advapi32)
LoadDLLfunc (LookupPrivilegeValueA, 12, advapi32)
LoadDLLfunc (LsaClose, 4, advapi32)
LoadDLLfunc (LsaEnumerateAccountRights, 16, advapi32)
LoadDLLfunc (LsaFreeMemory, 4, advapi32)
LoadDLLfunc (LsaNtStatusToWinError, 4, advapi32)
LoadDLLfunc (LsaOpenPolicy, 16, advapi32)
LoadDLLfunc (LsaQueryInformationPolicy, 12, advapi32)
LoadDLLfunc (MakeSelfRelativeSD, 12, advapi32)
LoadDLLfunc (OpenProcessToken, 12, advapi32)
LoadDLLfunc (OpenThreadToken, 16, advapi32)
LoadDLLfunc (PrivilegeCheck, 12, advapi32)
// LoadDLLfunc (RegCloseKey, 4, advapi32)
LoadDLLfunc (RegCreateKeyExA, 36, advapi32)
LoadDLLfunc (RegDeleteKeyA, 8, advapi32)
LoadDLLfunc (RegDeleteValueA, 8, advapi32)
LoadDLLfunc (RegLoadKeyA, 12, advapi32)
LoadDLLfunc (RegEnumKeyExA, 32, advapi32)
LoadDLLfunc (RegEnumValueA, 32, advapi32)
LoadDLLfunc (RegOpenKeyExA, 20, advapi32)
LoadDLLfunc (RegQueryInfoKeyA, 48, advapi32)
LoadDLLfunc (RegQueryValueExA, 24, advapi32)
LoadDLLfunc (RegSetValueExA, 24, advapi32)
LoadDLLfunc (RegisterEventSourceA, 8, advapi32)
LoadDLLfunc (ReportEventA, 36, advapi32)
LoadDLLfunc (RevertToSelf, 0, advapi32)
LoadDLLfunc (SetKernelObjectSecurity, 12, advapi32)
LoadDLLfunc (SetSecurityDescriptorControl, 12, advapi32) LoadDLLfunc (SetSecurityDescriptorControl, 12, advapi32)
LoadDLLfunc (SetSecurityDescriptorDacl, 16, advapi32)
LoadDLLfunc (SetSecurityDescriptorGroup, 12, advapi32)
LoadDLLfunc (SetSecurityDescriptorOwner, 12, advapi32)
LoadDLLfunc (SetTokenInformation, 16, advapi32)
LoadDLLfunc (RegGetKeySecurity, 16, advapi32)
/* 127 == ERROR_PROC_NOT_FOUND */ /* 127 == ERROR_PROC_NOT_FOUND */
LoadDLLfuncEx2 (DsGetDcNameA, 24, netapi32, 1, 127) LoadDLLfuncEx2 (DsGetDcNameA, 24, netapi32, 1, 127)
@ -382,39 +311,6 @@ LoadDLLfunc (NetUserGetGroups, 28, netapi32)
LoadDLLfunc (NetUserGetInfo, 16, netapi32) LoadDLLfunc (NetUserGetInfo, 16, netapi32)
LoadDLLfunc (NetWkstaUserGetInfo, 12, netapi32) LoadDLLfunc (NetWkstaUserGetInfo, 12, netapi32)
/* 0xc000007a == STATUS_PROCEDURE_NOT_FOUND */
#define LoadDLLfuncNt(name, n, dllname) \
LoadDLLfuncEx2(name, n, dllname, 1, 0xc000007a)
LoadDLLfuncNt (NtClose, 4, ntdll)
LoadDLLfuncNt (NtCreateFile, 44, ntdll)
LoadDLLfuncNt (NtCreateSection, 28, ntdll)
LoadDLLfuncNt (NtCreateToken, 52, ntdll)
LoadDLLfuncNt (NtLockVirtualMemory, 16, ntdll)
LoadDLLfuncNt (NtMapViewOfSection, 40, ntdll)
LoadDLLfuncNt (NtOpenDirectoryObject, 12, ntdll)
LoadDLLfuncNt (NtOpenFile, 24, ntdll)
LoadDLLfuncNt (NtOpenSection, 12, ntdll)
LoadDLLfuncNt (NtQueryDirectoryObject, 28, ntdll)
LoadDLLfuncNt (NtQueryDirectoryFile, 44, ntdll)
LoadDLLfuncNt (NtQueryEaFile, 36, ntdll)
LoadDLLfuncNt (NtQueryInformationFile, 20, ntdll)
LoadDLLfuncNt (NtQueryInformationProcess, 20, ntdll)
LoadDLLfuncNt (NtQueryObject, 20, ntdll)
LoadDLLfuncNt (NtQuerySystemInformation, 16, ntdll)
LoadDLLfuncNt (NtQuerySecurityObject, 20, ntdll)
LoadDLLfuncNt (NtQueryVirtualMemory, 24, ntdll)
LoadDLLfuncNt (NtQueryVolumeInformationFile, 20, ntdll)
LoadDLLfuncNt (NtSetEaFile, 16, ntdll)
LoadDLLfuncNt (NtSetInformationFile, 20, ntdll)
LoadDLLfuncNt (NtSetSecurityObject, 12, ntdll)
LoadDLLfuncNt (NtUnlockVirtualMemory, 16, ntdll)
LoadDLLfuncNt (NtUnmapViewOfSection, 8, ntdll)
LoadDLLfuncNt (RtlAnsiStringToUnicodeString, 12, ntdll)
LoadDLLfuncNt (RtlInitUnicodeString, 8, ntdll)
LoadDLLfuncNt (RtlIsDosDeviceName_U, 4, ntdll)
LoadDLLfuncNt (RtlNtStatusToDosError, 4, ntdll)
LoadDLLfuncNt (RtlOemStringToUnicodeString, 12, ntdll)
LoadDLLfuncEx (EnumProcessModules, 16, psapi, 1) LoadDLLfuncEx (EnumProcessModules, 16, psapi, 1)
LoadDLLfuncEx (GetModuleFileNameExA, 16, psapi, 1) LoadDLLfuncEx (GetModuleFileNameExA, 16, psapi, 1)
LoadDLLfuncEx (GetModuleInformation, 16, psapi, 1) LoadDLLfuncEx (GetModuleInformation, 16, psapi, 1)
@ -505,29 +401,16 @@ LoadDLLfuncEx2 (SendARP, 16, iphlpapi, 1, 50)
LoadDLLfunc (CoTaskMemFree, 4, ole32) LoadDLLfunc (CoTaskMemFree, 4, ole32)
LoadDLLfuncEx (CancelIo, 4, kernel32, 1)
LoadDLLfuncEx (CreateHardLinkA, 12, kernel32, 1) LoadDLLfuncEx (CreateHardLinkA, 12, kernel32, 1)
LoadDLLfuncEx (CreateToolhelp32Snapshot, 8, kernel32, 1) LoadDLLfuncEx (CreateToolhelp32Snapshot, 8, kernel32, 1)
LoadDLLfuncEx (FindFirstVolumeA, 8, kernel32, 1) LoadDLLfuncEx (FindFirstVolumeA, 8, kernel32, 1)
LoadDLLfuncEx (FindNextVolumeA, 12, kernel32, 1) LoadDLLfuncEx (FindNextVolumeA, 12, kernel32, 1)
LoadDLLfuncEx (FindVolumeClose, 4, kernel32, 1) LoadDLLfuncEx (FindVolumeClose, 4, kernel32, 1)
LoadDLLfuncEx2 (GetCompressedFileSizeA, 8, kernel32, 1, 0xffffffff)
LoadDLLfuncEx (GetConsoleWindow, 0, kernel32, 1) LoadDLLfuncEx (GetConsoleWindow, 0, kernel32, 1)
LoadDLLfuncEx (GetDiskFreeSpaceEx, 16, kernel32, 1)
LoadDLLfuncEx (GetHandleInformation, 8, kernel32, 1)
LoadDLLfuncEx (GetNativeSystemInfo, 4, kernel32, 1)
LoadDLLfuncEx (GetProcessWorkingSetSize, 12, kernel32, 1)
LoadDLLfuncEx (GetVolumeNameForVolumeMountPointA, 12, kernel32, 1) LoadDLLfuncEx (GetVolumeNameForVolumeMountPointA, 12, kernel32, 1)
LoadDLLfuncEx2 (IsDebuggerPresent, 0, kernel32, 1, 1)
LoadDLLfunc (IsProcessorFeaturePresent, 4, kernel32);
LoadDLLfuncEx (IsWow64Process, 8, kernel32, 1); LoadDLLfuncEx (IsWow64Process, 8, kernel32, 1);
LoadDLLfuncEx (Process32First, 8, kernel32, 1) LoadDLLfuncEx (Process32First, 8, kernel32, 1)
LoadDLLfuncEx (Process32Next, 8, kernel32, 1) LoadDLLfuncEx (Process32Next, 8, kernel32, 1)
LoadDLLfuncEx (RegisterServiceProcess, 8, kernel32, 1)
LoadDLLfuncEx (SetHandleInformation, 12, kernel32, 1)
LoadDLLfuncEx (SetProcessWorkingSetSize, 12, kernel32, 1)
LoadDLLfuncEx (SignalObjectAndWait, 16, kernel32, 1)
LoadDLLfuncEx (SwitchToThread, 0, kernel32, 1)
LoadDLLfuncEx (Wow64DisableWow64FsRedirection, 4, kernel32, 1) LoadDLLfuncEx (Wow64DisableWow64FsRedirection, 4, kernel32, 1)
LoadDLLfuncEx (Wow64RevertWow64FsRedirection, 4, kernel32, 1) LoadDLLfuncEx (Wow64RevertWow64FsRedirection, 4, kernel32, 1)

View File

@ -1,6 +1,6 @@
/* cygheap.h: Cygwin heap manager. /* cygheap.h: Cygwin heap manager.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc. Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -208,10 +208,7 @@ public:
} }
char * get_windows_id (char * buf) char * get_windows_id (char * buf)
{ {
if (wincap.is_winnt ()) return effec_cygsid.string (buf);
return effec_cygsid.string (buf);
else
return strcpy (buf, name ());
} }
const char *test_uid (char *&, const char *, size_t) const char *test_uid (char *&, const char *, size_t)

View File

@ -1,7 +1,7 @@
/* dcrt0.cc -- essentially the main() for the Cygwin dll /* dcrt0.cc -- essentially the main() for the Cygwin dll
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006 Red Hat, Inc. 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -726,7 +726,6 @@ dll_crt0_0 ()
_impure_ptr->_current_locale = "C"; _impure_ptr->_current_locale = "C";
user_data->impure_ptr = _impure_ptr; user_data->impure_ptr = _impure_ptr;
user_data->impure_ptr_ptr = &_impure_ptr; user_data->impure_ptr_ptr = &_impure_ptr;
mmap_init ();
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (),
GetCurrentProcess (), &hMainProc, 0, FALSE, GetCurrentProcess (), &hMainProc, 0, FALSE,

View File

@ -579,9 +579,6 @@ done:
int int
fhandler_base::open (int flags, mode_t mode) fhandler_base::open (int flags, mode_t mode)
{ {
if (!wincap.is_winnt ())
return fhandler_base::open_9x (flags, mode);
WCHAR wpath[CYG_MAX_PATH + 10]; WCHAR wpath[CYG_MAX_PATH + 10];
UNICODE_STRING upath = {0, sizeof (wpath), wpath}; UNICODE_STRING upath = {0, sizeof (wpath), wpath};
pc.get_nt_native_path (upath); pc.get_nt_native_path (upath);

View File

@ -109,14 +109,12 @@ class fhandler_base
read or write access */ read or write access */
unsigned close_on_exec : 1; /* close-on-exec */ unsigned close_on_exec : 1; /* close-on-exec */
unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */ unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
unsigned has_changed : 1; /* Flag used to set ctime on close. */
public: public:
status_flags () : status_flags () :
rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0), rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0),
uninterruptible_io (0), append_mode (0), did_lseek (0), uninterruptible_io (0), append_mode (0), did_lseek (0),
query_open (no_query), close_on_exec (0), need_fork_fixup (0), query_open (no_query), close_on_exec (0), need_fork_fixup (0)
has_changed (0)
{} {}
} status, open_status; } status, open_status;
@ -197,7 +195,6 @@ class fhandler_base
IMPLEMENT_STATUS_FLAG (query_state, query_open) IMPLEMENT_STATUS_FLAG (query_state, query_open)
IMPLEMENT_STATUS_FLAG (bool, close_on_exec) IMPLEMENT_STATUS_FLAG (bool, close_on_exec)
IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup) IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup)
IMPLEMENT_STATUS_FLAG (bool, has_changed)
int get_default_fmode (int flags); int get_default_fmode (int flags);
@ -681,9 +678,7 @@ class fhandler_dev_tape: public fhandler_dev_raw
class fhandler_disk_file: public fhandler_base class fhandler_disk_file: public fhandler_base
{ {
void touch_ctime ();
int readdir_helper (DIR *, dirent *, DWORD, DWORD, char *) __attribute__ ((regparm (3))); int readdir_helper (DIR *, dirent *, DWORD, DWORD, char *) __attribute__ ((regparm (3)));
int readdir_9x (DIR *, dirent *) __attribute__ ((regparm (3)));
public: public:
fhandler_disk_file (); fhandler_disk_file ();

View File

@ -210,90 +210,61 @@ path_conv::isgood_inode (__ino64_t ino) const
int __stdcall int __stdcall
fhandler_base::fstat_by_handle (struct __stat64 *buf) fhandler_base::fstat_by_handle (struct __stat64 *buf)
{ {
BY_HANDLE_FILE_INFORMATION local; NTSTATUS status;
IO_STATUS_BLOCK io;
/* The entries potentially contain a name of MAX_PATH wide characters. */
const DWORD fvi_size = 2 * CYG_MAX_PATH
+ sizeof (FILE_FS_VOLUME_INFORMATION);
const DWORD fai_size = 2 * CYG_MAX_PATH + sizeof (FILE_ALL_INFORMATION);
if (wincap.is_winnt ()) PFILE_FS_VOLUME_INFORMATION pfvi = (PFILE_FS_VOLUME_INFORMATION)
alloca (fvi_size);
PFILE_ALL_INFORMATION pfai = (PFILE_ALL_INFORMATION) alloca (fai_size);
status = NtQueryVolumeInformationFile (get_handle (), &io, pfvi, fvi_size,
FileFsVolumeInformation);
if (!NT_SUCCESS (status))
{ {
NTSTATUS status; debug_printf ("%u = NtQueryVolumeInformationFile)",
IO_STATUS_BLOCK io;
/* The entries potentially contain a name of MAX_PATH wide characters. */
const DWORD fvi_size = 2 * CYG_MAX_PATH
+ sizeof (FILE_FS_VOLUME_INFORMATION);
const DWORD fai_size = 2 * CYG_MAX_PATH + sizeof (FILE_ALL_INFORMATION);
PFILE_FS_VOLUME_INFORMATION pfvi = (PFILE_FS_VOLUME_INFORMATION)
alloca (fvi_size);
PFILE_ALL_INFORMATION pfai = (PFILE_ALL_INFORMATION) alloca (fai_size);
status = NtQueryVolumeInformationFile (get_handle (), &io, pfvi, fvi_size,
FileFsVolumeInformation);
if (!NT_SUCCESS (status))
{
debug_printf ("%u = NtQueryVolumeInformationFile)",
RtlNtStatusToDosError (status));
pfvi->VolumeSerialNumber = 0; /* Set to pc.volser () in helper. */
}
status = NtQueryInformationFile (get_handle (), &io, pfai, fai_size,
FileAllInformation);
if (NT_SUCCESS (status))
{
/* If the change time is 0, it's a file system which doesn't
support a change timestamp. In that case use the LastWriteTime
entry, as in other calls to fstat_helper. */
if (pc.is_rep_symlink ())
pfai->BasicInformation.FileAttributes &= ~FILE_ATTRIBUTE_DIRECTORY;
pc.file_attributes (pfai->BasicInformation.FileAttributes);
return fstat_helper (buf,
pfai->BasicInformation.ChangeTime.QuadPart ?
*(FILETIME *) &pfai->BasicInformation.ChangeTime :
*(FILETIME *) &pfai->BasicInformation.LastWriteTime,
*(FILETIME *) &pfai->BasicInformation.LastAccessTime,
*(FILETIME *) &pfai->BasicInformation.LastWriteTime,
pfvi->VolumeSerialNumber,
pfai->StandardInformation.EndOfFile.QuadPart,
pfai->StandardInformation.AllocationSize.QuadPart,
pfai->InternalInformation.FileId.QuadPart,
pfai->StandardInformation.NumberOfLinks,
pfai->BasicInformation.FileAttributes);
}
debug_printf ("%u = NtQueryInformationFile)",
RtlNtStatusToDosError (status)); RtlNtStatusToDosError (status));
pfvi->VolumeSerialNumber = 0; /* Set to pc.volser () in helper. */
}
status = NtQueryInformationFile (get_handle (), &io, pfai, fai_size,
FileAllInformation);
if (NT_SUCCESS (status))
{
/* If the change time is 0, it's a file system which doesn't
support a change timestamp. In that case use the LastWriteTime
entry, as in other calls to fstat_helper. */
if (pc.is_rep_symlink ())
pfai->BasicInformation.FileAttributes &= ~FILE_ATTRIBUTE_DIRECTORY;
pc.file_attributes (pfai->BasicInformation.FileAttributes);
return fstat_helper (buf,
pfai->BasicInformation.ChangeTime.QuadPart ?
*(FILETIME *) &pfai->BasicInformation.ChangeTime :
*(FILETIME *) &pfai->BasicInformation.LastWriteTime,
*(FILETIME *) &pfai->BasicInformation.LastAccessTime,
*(FILETIME *) &pfai->BasicInformation.LastWriteTime,
pfvi->VolumeSerialNumber,
pfai->StandardInformation.EndOfFile.QuadPart,
pfai->StandardInformation.AllocationSize.QuadPart,
pfai->InternalInformation.FileId.QuadPart,
pfai->StandardInformation.NumberOfLinks,
pfai->BasicInformation.FileAttributes);
} }
BOOL res = GetFileInformationByHandle (get_handle (), &local); debug_printf ("%u = NtQueryInformationFile)",
debug_printf ("%d = GetFileInformationByHandle (%s, %d)", RtlNtStatusToDosError (status));
res, get_win32_name (), get_handle ());
/* GetFileInformationByHandle will fail if it's given stdio handle or pipe. /* Last resort */
It also fails on 9x when trying to access directories on shares. */ FILETIME ft = { 0, 0 };
if (!res) DWORD lowfs, highfs;
{
memset (&local, 0, sizeof (local)); lowfs = GetFileSize (get_handle (), &highfs);
local.nFileSizeLow = GetFileSize (get_handle (), &local.nFileSizeHigh); if (lowfs == 0xffffffff && GetLastError ())
/* Even GetFileSize fails on 9x when trying to access directories lowfs = highfs = 0;
on shares. In this case reset filesize to 0. */ return fstat_helper (buf, ft, ft, ft, 0, (ULONGLONG) highfs << 32 | lowfs,
if (local.nFileSizeLow == 0xffffffff && GetLastError ()) -1LL, 0ULL, 1, DWORD (pc));
local.nFileSizeLow = 0;
local.dwFileAttributes = DWORD (pc);
}
else
{
if (pc.is_rep_symlink ())
local.dwFileAttributes &= ~FILE_ATTRIBUTE_DIRECTORY;
pc.file_attributes (local.dwFileAttributes);
}
return fstat_helper (buf,
local.ftLastWriteTime, /* see fstat_helper comment */
local.ftLastAccessTime,
local.ftLastWriteTime,
local.dwVolumeSerialNumber,
(ULONGLONG) local.nFileSizeHigh << 32
| local.nFileSizeLow,
-1LL,
(ULONGLONG) local.nFileIndexHigh << 32
| local.nFileIndexLow,
local.nNumberOfLinks,
local.dwFileAttributes);
} }
int __stdcall int __stdcall
@ -556,26 +527,9 @@ fhandler_base::fstat_helper (struct __stat64 *buf,
int __stdcall int __stdcall
fhandler_disk_file::fstat (struct __stat64 *buf) fhandler_disk_file::fstat (struct __stat64 *buf)
{ {
/* Changing inode data requires setting ctime (only 9x). */
if (has_changed ())
touch_ctime ();
return fstat_fs (buf); return fstat_fs (buf);
} }
void
fhandler_disk_file::touch_ctime ()
{
FILETIME ft;
GetSystemTimeAsFileTime (&ft);
/* Modification time is touched if the file data has changed as well.
This happens for instance on write() or ftruncate(). */
if (!SetFileTime (get_io_handle (), NULL, NULL, &ft))
debug_printf ("SetFileTime (%s) failed, %E", get_win32_name ());
else
has_changed (false);
}
int __stdcall int __stdcall
fhandler_disk_file::fchmod (mode_t mode) fhandler_disk_file::fchmod (mode_t mode)
{ {
@ -623,10 +577,6 @@ fhandler_disk_file::fchmod (mode_t mode)
/* Correct NTFS security attributes have higher priority */ /* Correct NTFS security attributes have higher priority */
res = 0; res = 0;
/* Set ctime on success. */
if (!res && !wincap.is_winnt ())
has_changed (true);
if (oret) if (oret)
close (); close ();
@ -783,9 +733,6 @@ fhandler_disk_file::fadvise (_off64_t offset, _off64_t length, int advice)
return -1; return -1;
} }
if (!wincap.is_winnt ())
return 0;
/* Windows only supports advice flags for the whole file. We're using /* Windows only supports advice flags for the whole file. We're using
a simplified test here so that we don't have to ask for the actual a simplified test here so that we don't have to ask for the actual
file size. Length == 0 means all bytes starting at offset anyway. file size. Length == 0 means all bytes starting at offset anyway.
@ -835,6 +782,10 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate)
{ {
_off64_t actual_length; _off64_t actual_length;
DWORD size_high = 0; DWORD size_high = 0;
NTSTATUS status;
IO_STATUS_BLOCK io;
FILE_END_OF_FILE_INFORMATION feofi;
actual_length = GetFileSize (get_handle (), &size_high); actual_length = GetFileSize (get_handle (), &size_high);
actual_length += ((_off64_t) size_high) << 32; actual_length += ((_off64_t) size_high) << 32;
@ -843,49 +794,27 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate)
if (!allow_truncate && length < actual_length) if (!allow_truncate && length < actual_length)
return 0; return 0;
if (wincap.is_winnt ()) feofi.EndOfFile.QuadPart = length;
/* Create sparse files only when called through ftruncate, not when
called through posix_fallocate. */
if (allow_truncate
&& get_fs_flags (FILE_SUPPORTS_SPARSE_FILES)
&& length >= actual_length + (128 * 1024))
{ {
NTSTATUS status; DWORD dw;
IO_STATUS_BLOCK io; BOOL r = DeviceIoControl (get_handle (),
FILE_END_OF_FILE_INFORMATION feofi; FSCTL_SET_SPARSE, NULL, 0, NULL,
0, &dw, NULL);
feofi.EndOfFile.QuadPart = length; syscall_printf ("%d = DeviceIoControl(%p, FSCTL_SET_SPARSE)",
/* Create sparse files only when called through ftruncate, not when r, get_handle ());
called through posix_fallocate. */
if (allow_truncate
&& get_fs_flags (FILE_SUPPORTS_SPARSE_FILES)
&& length >= actual_length + (128 * 1024))
{
DWORD dw;
BOOL r = DeviceIoControl (get_handle (),
FSCTL_SET_SPARSE, NULL, 0, NULL,
0, &dw, NULL);
syscall_printf ("%d = DeviceIoControl(%p, FSCTL_SET_SPARSE)",
r, get_handle ());
}
status = NtSetInformationFile (get_handle (), &io,
&feofi, sizeof feofi,
FileEndOfFileInformation);
if (!NT_SUCCESS (status))
__seterrno_from_nt_status (status);
else
res = 0;
} }
status = NtSetInformationFile (get_handle (), &io,
&feofi, sizeof feofi,
FileEndOfFileInformation);
if (!NT_SUCCESS (status))
__seterrno_from_nt_status (status);
else else
{ res = 0;
_off64_t prev_loc = lseek (0, SEEK_CUR);
if (lseek (length, SEEK_SET) >= 0)
{
int res_bug = write (&res, 0);
if (!SetEndOfFile (get_handle ()))
__seterrno ();
else
res = res_bug;
/* restore original file pointer location */
lseek (prev_loc, SEEK_SET);
}
}
} }
return res; return res;
} }
@ -1050,9 +979,6 @@ docopy:
__seterrno (); __seterrno ();
return -1; return -1;
} }
/* Set ctime on success (copy gets it automatically). */
if (!wincap.is_winnt ())
has_changed (true);
close (); close ();
fhandler_disk_file fh (newpc); fhandler_disk_file fh (newpc);
fh.query_open (query_write_attributes); fh.query_open (query_write_attributes);
@ -1200,12 +1126,6 @@ out:
int int
fhandler_disk_file::close () fhandler_disk_file::close ()
{ {
if (!hExeced)
{
/* Changing inode data requires setting ctime (only 9x). */
if (has_changed ())
touch_ctime ();
}
return close_fs (); return close_fs ();
} }
@ -1462,16 +1382,10 @@ fhandler_disk_file::rmdir ()
(DWORD) pc & ~FILE_ATTRIBUTE_READONLY); (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
DWORD err, att = 0; DWORD err, att = 0;
int rc;
if (wincap.is_winnt ()) int rc = !(err = unlink_nt (pc, pc.has_attribute (FILE_ATTRIBUTE_READONLY)));
{ if (err)
rc = !(err = unlink_nt (pc, pc.has_attribute (FILE_ATTRIBUTE_READONLY))); SetLastError (err);
if (err)
SetLastError (err);
}
else
rc = RemoveDirectory (get_win32_name ());
if (isremote () && exists ()) if (isremote () && exists ())
att = GetFileAttributes (get_win32_name ()); att = GetFileAttributes (get_win32_name ());
@ -1503,10 +1417,6 @@ fhandler_disk_file::rmdir ()
__seterrno_from_win_error (err); __seterrno_from_win_error (err);
/* Directory still exists, restore its characteristics. */
if (!wincap.is_winnt () && pc.has_attribute (FILE_ATTRIBUTE_READONLY))
SetFileAttributes (get_win32_name (), (DWORD) pc);
return res; return res;
} }
@ -1547,9 +1457,8 @@ fhandler_disk_file::opendir ()
set_errno (ENAMETOOLONG); set_errno (ENAMETOOLONG);
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL) else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
set_errno (ENOMEM); set_errno (ENOMEM);
else if ((dir->__d_dirname = (char *) malloc (wincap.is_winnt () else if ((dir->__d_dirname = (char *) malloc ( sizeof (struct __DIR_cache)))
? sizeof (struct __DIR_cache) == NULL)
: len + 3)) == NULL)
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
goto free_dir; goto free_dir;
@ -1586,47 +1495,45 @@ fhandler_disk_file::opendir ()
&& pc.normalized_path[1] == '\0') && pc.normalized_path[1] == '\0')
? dirent_isroot : 0; ? dirent_isroot : 0;
dir->__d_internal = (unsigned) new __DIR_mounts (pc.normalized_path); dir->__d_internal = (unsigned) new __DIR_mounts (pc.normalized_path);
if (wincap.is_winnt ()) d_cachepos (dir) = 0;
{
d_cachepos (dir) = 0;
if (!pc.iscygdrive ())
{
OBJECT_ATTRIBUTES attr;
WCHAR wpath[CYG_MAX_PATH + 10];
UNICODE_STRING upath = {0, sizeof (wpath), wpath};
IO_STATUS_BLOCK io;
NTSTATUS status;
SECURITY_ATTRIBUTES sa = sec_none;
pc.get_nt_native_path (upath);
InitializeObjectAttributes (&attr, &upath,
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
NULL, sa.lpSecurityDescriptor);
status = NtOpenFile (&dir->__handle,
SYNCHRONIZE | FILE_LIST_DIRECTORY,
&attr, &io, wincap.shared (),
FILE_SYNCHRONOUS_IO_NONALERT
| FILE_OPEN_FOR_BACKUP_INTENT
| FILE_DIRECTORY_FILE);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
goto free_mounts;
}
/* FileIdBothDirectoryInformation is apparently unsupported on if (!pc.iscygdrive ())
XP when accessing directories on UDF. When trying to use it {
so, NtQueryDirectoryFile returns with STATUS_ACCESS_VIOLATION. OBJECT_ATTRIBUTES attr;
It's not clear if the call isn't also unsupported on other WCHAR wpath[CYG_MAX_PATH + 10];
OS/FS combinations (say, Win2K/CDFS or so). Instead of UNICODE_STRING upath = {0, sizeof (wpath), wpath};
testing in readdir for yet another error code, let's use IO_STATUS_BLOCK io;
FileIdBothDirectoryInformation only on filesystems supporting NTSTATUS status;
persistent ACLs, FileBothDirectoryInformation otherwise. */ SECURITY_ATTRIBUTES sa = sec_none;
if (pc.hasgood_inode ()) pc.get_nt_native_path (upath);
{ InitializeObjectAttributes (&attr, &upath,
dir->__flags |= dirent_set_d_ino; OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
if (wincap.has_fileid_dirinfo ()) NULL, sa.lpSecurityDescriptor);
dir->__flags |= dirent_get_d_ino; status = NtOpenFile (&dir->__handle,
} SYNCHRONIZE | FILE_LIST_DIRECTORY,
&attr, &io, wincap.shared (),
FILE_SYNCHRONOUS_IO_NONALERT
| FILE_OPEN_FOR_BACKUP_INTENT
| FILE_DIRECTORY_FILE);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
goto free_mounts;
}
/* FileIdBothDirectoryInformation is apparently unsupported on
XP when accessing directories on UDF. When trying to use it
so, NtQueryDirectoryFile returns with STATUS_ACCESS_VIOLATION.
It's not clear if the call isn't also unsupported on other
OS/FS combinations (say, Win2K/CDFS or so). Instead of
testing in readdir for yet another error code, let's use
FileIdBothDirectoryInformation only on filesystems supporting
persistent ACLs, FileBothDirectoryInformation otherwise. */
if (pc.hasgood_inode ())
{
dir->__flags |= dirent_set_d_ino;
if (wincap.has_fileid_dirinfo ())
dir->__flags |= dirent_get_d_ino;
} }
} }
/* Filling fd with `this' (aka storing this in the file descriptor table /* Filling fd with `this' (aka storing this in the file descriptor table
@ -1755,9 +1662,6 @@ fhandler_disk_file::readdir (DIR *dir, dirent *de)
char fname[CYG_MAX_PATH]; char fname[CYG_MAX_PATH];
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
if (!wincap.is_winnt ())
return readdir_9x (dir, de);
/* d_cachepos always refers to the next cache entry to use. If it's 0 /* d_cachepos always refers to the next cache entry to use. If it's 0
we must reload the cache. */ we must reload the cache. */
if (d_cachepos (dir) == 0) if (d_cachepos (dir) == 0)
@ -1911,55 +1815,6 @@ go_ahead:
return res; return res;
} }
int
fhandler_disk_file::readdir_9x (DIR *dir, dirent *de)
{
WIN32_FIND_DATA buf;
int res = 0;
if (!dir->__handle)
{
res = ENMFILE;
goto out;
}
DWORD lasterr;
if (dir->__d_position != 0)
lasterr = FindNextFileA (dir->__handle, &buf) ? 0 : GetLastError ();
else if (dir->__handle != INVALID_HANDLE_VALUE)
{
res = EBADF;
goto out;
}
else
{
int len = strlen (dir->__d_dirname);
strcpy (dir->__d_dirname + len, "*");
dir->__handle = FindFirstFile (dir->__d_dirname, &buf);
dir->__d_dirname[len] = '\0';
if (dir->__handle != INVALID_HANDLE_VALUE)
lasterr = 0;
else if ((lasterr = GetLastError ()) != ERROR_NO_MORE_FILES)
{
res = geterrno_from_win_error (lasterr);
goto out;
}
}
if (!lasterr)
de->d_ino = d_mounts (dir)->check_mount (buf.cFileName, de->d_ino);
if (!(res = readdir_helper (dir, de, lasterr, buf.dwFileAttributes,
buf.cFileName)))
dir->__d_position++;
else
{
FindClose (dir->__handle);
dir->__handle = NULL;
}
out:
syscall_printf ("%d = readdir (%p, %p) (%s)", res, dir, &de, res ? "***" : de->d_name);
return res;
}
_off64_t _off64_t
fhandler_disk_file::telldir (DIR *dir) fhandler_disk_file::telldir (DIR *dir)
{ {
@ -1978,45 +1833,36 @@ fhandler_disk_file::seekdir (DIR *dir, _off64_t loc)
void void
fhandler_disk_file::rewinddir (DIR *dir) fhandler_disk_file::rewinddir (DIR *dir)
{ {
if (wincap.is_winnt ()) d_cachepos (dir) = 0;
if (wincap.has_buggy_restart_scan () && isremote ())
{ {
d_cachepos (dir) = 0; /* This works around a W2K bug. The RestartScan parameter in calls
if (wincap.has_buggy_restart_scan () && isremote ()) to NtQueryDirectoryFile on remote shares is ignored, thus
{ resulting in not being able to rewind on remote shares. By
/* This works around a W2K bug. The RestartScan parameter in calls reopening the directory, we get a fresh new directory pointer. */
to NtQueryDirectoryFile on remote shares is ignored, thus UNICODE_STRING fname = {0, CYG_MAX_PATH * 2, (WCHAR *) L""};
resulting in not being able to rewind on remote shares. By OBJECT_ATTRIBUTES attr;
reopening the directory, we get a fresh new directory pointer. */ NTSTATUS status;
UNICODE_STRING fname = {0, CYG_MAX_PATH * 2, (WCHAR *) L""}; IO_STATUS_BLOCK io;
OBJECT_ATTRIBUTES attr; HANDLE new_dir;
NTSTATUS status;
IO_STATUS_BLOCK io;
HANDLE new_dir;
InitializeObjectAttributes (&attr, &fname, OBJ_CASE_INSENSITIVE, InitializeObjectAttributes (&attr, &fname, OBJ_CASE_INSENSITIVE,
dir->__handle, NULL); dir->__handle, NULL);
status = NtOpenFile (&new_dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, status = NtOpenFile (&new_dir, SYNCHRONIZE | FILE_LIST_DIRECTORY,
&attr, &io, wincap.shared (), &attr, &io, wincap.shared (),
FILE_SYNCHRONOUS_IO_NONALERT FILE_SYNCHRONOUS_IO_NONALERT
| FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_FOR_BACKUP_INTENT
| FILE_DIRECTORY_FILE); | FILE_DIRECTORY_FILE);
if (!NT_SUCCESS (stat)) if (!NT_SUCCESS (stat))
debug_printf ("Unable to reopen dir %s, NT error: 0x%08x, " debug_printf ("Unable to reopen dir %s, NT error: 0x%08x, "
"win32: %lu", get_name (), status, "win32: %lu", get_name (), status,
RtlNtStatusToDosError (status)); RtlNtStatusToDosError (status));
else else
{ {
CloseHandle (dir->__handle); CloseHandle (dir->__handle);
dir->__handle = new_dir; dir->__handle = new_dir;
}
} }
} }
else if (dir->__handle != INVALID_HANDLE_VALUE)
{
if (dir->__handle)
FindClose (dir->__handle);
dir->__handle = INVALID_HANDLE_VALUE;
}
dir->__d_position = 0; dir->__d_position = 0;
d_mounts (dir)->rewind (); d_mounts (dir)->rewind ();
} }
@ -2033,18 +1879,10 @@ fhandler_disk_file::closedir (DIR *dir)
set_errno (EBADF); set_errno (EBADF);
res = -1; res = -1;
} }
else else if (!NtClose (dir->__handle))
{ {
BOOL winres; __seterrno ();
if (wincap.is_winnt ()) res = -1;
winres = CloseHandle (dir->__handle);
else
winres = FindClose (dir->__handle);
if (!winres)
{
__seterrno ();
res = -1;
}
} }
syscall_printf ("%d = closedir (%p, %s)", res, dir, get_name ()); syscall_printf ("%d = closedir (%p, %s)", res, dir, get_name ());
return res; return res;

View File

@ -479,34 +479,32 @@ format_proc_uptime (char *destbuf, size_t maxsize)
{ {
unsigned long long uptime = 0ULL, idle_time = 0ULL; unsigned long long uptime = 0ULL, idle_time = 0ULL;
if (wincap.is_winnt ()) NTSTATUS ret;
SYSTEM_BASIC_INFORMATION sbi;
ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL);
if (!NT_SUCCESS (ret))
{ {
NTSTATUS ret; __seterrno_from_nt_status (ret);
SYSTEM_BASIC_INFORMATION sbi; debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
sbi.NumberProcessors = 1;
ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL);
if (!NT_SUCCESS (ret))
{
__seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
sbi.NumberProcessors = 1;
}
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
sizeof spt[0] * sbi.NumberProcessors,
NULL);
if (NT_SUCCESS (ret))
for (int i = 0; i < sbi.NumberProcessors; i++)
{
uptime += (spt[i].KernelTime.QuadPart + spt[i].UserTime.QuadPart)
/ 100000ULL;
idle_time += spt[i].IdleTime.QuadPart / 100000ULL;
}
uptime /= sbi.NumberProcessors;
idle_time /= sbi.NumberProcessors;
} }
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
sizeof spt[0] * sbi.NumberProcessors,
NULL);
if (NT_SUCCESS (ret))
for (int i = 0; i < sbi.NumberProcessors; i++)
{
uptime += (spt[i].KernelTime.QuadPart + spt[i].UserTime.QuadPart)
/ 100000ULL;
idle_time += spt[i].IdleTime.QuadPart / 100000ULL;
}
uptime /= sbi.NumberProcessors;
idle_time /= sbi.NumberProcessors;
if (!uptime) if (!uptime)
uptime = GetTickCount () / 10; uptime = GetTickCount () / 10;
@ -523,86 +521,75 @@ format_proc_stat (char *destbuf, size_t maxsize)
time_t boot_time = 0; time_t boot_time = 0;
char *eobuf = destbuf; char *eobuf = destbuf;
if (!wincap.is_winnt ()) NTSTATUS ret;
eobuf += __small_sprintf (destbuf, "cpu %U %U %U %U\n", 0ULL, 0ULL, 0ULL, 0ULL); SYSTEM_PERFORMANCE_INFORMATION spi;
else SYSTEM_TIME_OF_DAY_INFORMATION stodi;
SYSTEM_BASIC_INFORMATION sbi;
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
(PVOID) &sbi, sizeof sbi, NULL))
!= STATUS_SUCCESS)
{ {
NTSTATUS ret; __seterrno_from_nt_status (ret);
SYSTEM_PERFORMANCE_INFORMATION spi; debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
SYSTEM_TIME_OF_DAY_INFORMATION stodi; sbi.NumberProcessors = 1;
SYSTEM_BASIC_INFORMATION sbi;
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
(PVOID) &sbi, sizeof sbi, NULL))
!= STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
sbi.NumberProcessors = 1;
}
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
sizeof spt[0] * sbi.NumberProcessors, NULL);
interrupt_count = 0;
if (ret == STATUS_SUCCESS)
{
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
for (int i = 0; i < sbi.NumberProcessors; i++)
{
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
user_time += spt[i].UserTime.QuadPart * HZ / 10000000ULL;
idle_time += spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
}
eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
user_time, 0ULL, kernel_time, idle_time);
user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
for (int i = 0; i < sbi.NumberProcessors; i++)
{
interrupt_count += spt[i].InterruptCount;
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
user_time = spt[i].UserTime.QuadPart * HZ / 10000000ULL;
idle_time = spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
user_time, 0ULL, kernel_time, idle_time);
}
ret = NtQuerySystemInformation (SystemPerformanceInformation,
(PVOID) &spi, sizeof spi, NULL);
}
if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
(PVOID) &stodi,
sizeof stodi, NULL);
if (ret != STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
return 0;
}
pages_in = spi.PagesRead;
pages_out = spi.PagefilePagesWritten + spi.MappedFilePagesWritten;
/*
* Note: there is no distinction made in this structure between pages
* read from the page file and pages read from mapped files, but there
* is such a distinction made when it comes to writing. Goodness knows
* why. The value of swap_in, then, will obviously be wrong but its our
* best guess.
*/
swap_in = spi.PagesRead;
swap_out = spi.PagefilePagesWritten;
context_switches = spi.ContextSwitches;
boot_time = to_time_t ((FILETIME *) &stodi.BootTime.QuadPart);
} }
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
sizeof spt[0] * sbi.NumberProcessors, NULL);
interrupt_count = 0;
if (ret == STATUS_SUCCESS)
{
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
for (int i = 0; i < sbi.NumberProcessors; i++)
{
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
* HZ / 10000000ULL;
user_time += spt[i].UserTime.QuadPart * HZ / 10000000ULL;
idle_time += spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
}
eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
user_time, 0ULL, kernel_time, idle_time);
user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
for (int i = 0; i < sbi.NumberProcessors; i++)
{
interrupt_count += spt[i].InterruptCount;
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
user_time = spt[i].UserTime.QuadPart * HZ / 10000000ULL;
idle_time = spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
user_time, 0ULL, kernel_time, idle_time);
}
ret = NtQuerySystemInformation (SystemPerformanceInformation,
(PVOID) &spi, sizeof spi, NULL);
}
if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
(PVOID) &stodi,
sizeof stodi, NULL);
if (ret != STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
return 0;
}
pages_in = spi.PagesRead;
pages_out = spi.PagefilePagesWritten + spi.MappedFilePagesWritten;
/* /*
* else * Note: there is no distinction made in this structure between pages
* { * read from the page file and pages read from mapped files, but there
* There are only two relevant performance counters on Windows 95/98/me, * is such a distinction made when it comes to writing. Goodness knows
* VMM/cPageIns and VMM/cPageOuts. The extra effort needed to read these * why. The value of swap_in, then, will obviously be wrong but its our
* counters is by no means worth it. * best guess.
* }
*/ */
swap_in = spi.PagesRead;
swap_out = spi.PagefilePagesWritten;
context_switches = spi.ContextSwitches;
boot_time = to_time_t ((FILETIME *) &stodi.BootTime.QuadPart);
eobuf += __small_sprintf (eobuf, "page %u %u\n" eobuf += __small_sprintf (eobuf, "page %u %u\n"
"swap %u %u\n" "swap %u %u\n"
"intr %u\n" "intr %u\n"
@ -697,29 +684,26 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer); bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer);
read_value ("Identifier", REG_SZ); read_value ("Identifier", REG_SZ);
bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer); bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer);
if (wincap.is_winnt ()) read_value ("~Mhz", REG_DWORD);
{ bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer);
read_value ("~Mhz", REG_DWORD);
bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer);
print ("flags :"); print ("flags :");
if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE))
print (" 3dnow"); print (" 3dnow");
if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE)) if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE))
print (" cx8"); print (" cx8");
if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED)) if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED))
print (" fpu"); print (" fpu");
if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE))
print (" mmx"); print (" mmx");
if (IsProcessorFeaturePresent (PF_PAE_ENABLED)) if (IsProcessorFeaturePresent (PF_PAE_ENABLED))
print (" pae"); print (" pae");
if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE)) if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE))
print (" tsc"); print (" tsc");
if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE))
print (" sse"); print (" sse");
if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE))
print (" sse2"); print (" sse2");
}
} }
else else
{ {
@ -736,13 +720,10 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
else if (!strcmp ((char*)vendor_id, "GenuineIntel")) else if (!strcmp ((char*)vendor_id, "GenuineIntel"))
is_intel = true; is_intel = true;
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", (char *)vendor_id); bufptr += __small_sprintf (bufptr, "vendor_id : %s\n",
unsigned cpu_mhz = 0; (char *)vendor_id);
if (wincap.is_winnt ()) read_value ("~Mhz", REG_DWORD);
{ unsigned cpu_mhz = *(DWORD *)szBuffer;
read_value ("~Mhz", REG_DWORD);
cpu_mhz = *(DWORD *)szBuffer;
}
if (maxf >= 1) if (maxf >= 1)
{ {
unsigned features2, features1, extra_info, cpuid_sig; unsigned features2, features1, extra_info, cpuid_sig;
@ -778,9 +759,12 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
if (maxe >= 0x80000004) if (maxe >= 0x80000004)
{ {
unsigned *model_name = (unsigned *) szBuffer; unsigned *model_name = (unsigned *) szBuffer;
cpuid (&model_name[0], &model_name[1], &model_name[2], &model_name[3], 0x80000002); cpuid (&model_name[0], &model_name[1], &model_name[2],
cpuid (&model_name[4], &model_name[5], &model_name[6], &model_name[7], 0x80000003); &model_name[3], 0x80000002);
cpuid (&model_name[8], &model_name[9], &model_name[10], &model_name[11], 0x80000004); cpuid (&model_name[4], &model_name[5], &model_name[6],
&model_name[7], 0x80000003);
cpuid (&model_name[8], &model_name[9], &model_name[10],
&model_name[11], 0x80000004);
model_name[12] = 0; model_name[12] = 0;
} }
else else
@ -788,50 +772,26 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
// could implement a lookup table here if someone needs it // could implement a lookup table here if someone needs it
strcpy (szBuffer, "unknown"); strcpy (szBuffer, "unknown");
} }
if (wincap.is_winnt ()) bufptr += __small_sprintf (bufptr, "type : %s\n"
{ "cpu family : %d\n"
bufptr += __small_sprintf (bufptr, "type : %s\n" "model : %d\n"
"cpu family : %d\n" "model name : %s\n"
"model : %d\n" "stepping : %d\n"
"model name : %s\n" "brand id : %d\n"
"stepping : %d\n" "cpu count : %d\n"
"brand id : %d\n" "apic id : %d\n"
"cpu count : %d\n" "cpu MHz : %d\n"
"apic id : %d\n" "fpu : %s\n",
"cpu MHz : %d\n" type_str,
"fpu : %s\n", family,
type_str, model,
family, szBuffer + strspn (szBuffer, " "),
model, stepping,
szBuffer + strspn (szBuffer, " "), brand_id,
stepping, cpu_count,
brand_id, apic_id,
cpu_count, cpu_mhz,
apic_id, (features1 & (1 << 0)) ? "yes" : "no");
cpu_mhz,
(features1 & (1 << 0)) ? "yes" : "no");
}
else
{
bufptr += __small_sprintf (bufptr, "type : %s\n"
"cpu family : %d\n"
"model : %d\n"
"model name : %s\n"
"stepping : %d\n"
"brand id : %d\n"
"cpu count : %d\n"
"apic id : %d\n"
"fpu : %s\n",
type_str,
family,
model,
szBuffer,
stepping,
brand_id,
cpu_count,
apic_id,
(features1 & (1 << 0)) ? "yes" : "no");
}
print ("flags :"); print ("flags :");
if (features1 & (1 << 0)) if (features1 & (1 << 0))
print (" fpu"); print (" fpu");
@ -935,7 +895,7 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
} }
} }
} }
else if (wincap.is_winnt ()) else
{ {
bufptr += __small_sprintf (bufptr, "cpu MHz : %d\n" bufptr += __small_sprintf (bufptr, "cpu MHz : %d\n"
"fpu : %s\n", "fpu : %s\n",
@ -961,9 +921,6 @@ format_proc_partitions (char *destbuf, size_t maxsize)
char *bufptr = destbuf; char *bufptr = destbuf;
print ("major minor #blocks name\n\n"); print ("major minor #blocks name\n\n");
if (!wincap.is_winnt ())
return bufptr - destbuf;
char devname[CYG_MAX_PATH]; char devname[CYG_MAX_PATH];
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
HANDLE dirhdl, devhdl; HANDLE dirhdl, devhdl;

View File

@ -1,6 +1,6 @@
/* fhandler_process.cc: fhandler for /proc/<pid> virtual filesystem /* fhandler_process.cc: fhandler for /proc/<pid> virtual filesystem
Copyright 2002, 2003, 2004, 2005, 2006 Red Hat, Inc. Copyright 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -515,9 +515,6 @@ fhandler_process::fill_filebuf ()
static _off64_t static _off64_t
format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize) format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize)
{ {
if (!wincap.is_winnt ())
return 0;
HANDLE proc = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, HANDLE proc = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, FALSE,
p->dwProcessId); p->dwProcessId);
@ -637,86 +634,84 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
state = 'Z'; state = 'Z';
else if (p->process_state & PID_STOPPED) else if (p->process_state & PID_STOPPED)
state = 'T'; state = 'T';
else if (wincap.is_winnt ()) else
state = get_process_state (p->dwProcessId); state = get_process_state (p->dwProcessId);
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ; start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
if (wincap.is_winnt ())
NTSTATUS ret;
HANDLE hProcess;
VM_COUNTERS vmc;
KERNEL_USER_TIMES put;
PROCESS_BASIC_INFORMATION pbi;
QUOTA_LIMITS ql;
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
SYSTEM_PROCESSOR_TIMES spt;
hProcess = OpenProcess (PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,
FALSE, p->dwProcessId);
if (hProcess != NULL)
{ {
NTSTATUS ret; ret = NtQueryInformationProcess (hProcess,
HANDLE hProcess; ProcessVmCounters,
VM_COUNTERS vmc; (PVOID) &vmc,
KERNEL_USER_TIMES put; sizeof vmc, NULL);
PROCESS_BASIC_INFORMATION pbi;
QUOTA_LIMITS ql;
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
SYSTEM_PROCESSOR_TIMES spt;
hProcess = OpenProcess (PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,
FALSE, p->dwProcessId);
if (hProcess != NULL)
{
ret = NtQueryInformationProcess (hProcess,
ProcessVmCounters,
(PVOID) &vmc,
sizeof vmc, NULL);
if (ret == STATUS_SUCCESS)
ret = NtQueryInformationProcess (hProcess,
ProcessTimes,
(PVOID) &put,
sizeof put, NULL);
if (ret == STATUS_SUCCESS)
ret = NtQueryInformationProcess (hProcess,
ProcessBasicInformation,
(PVOID) &pbi,
sizeof pbi, NULL);
if (ret == STATUS_SUCCESS)
ret = NtQueryInformationProcess (hProcess,
ProcessQuotaLimits,
(PVOID) &ql,
sizeof ql, NULL);
CloseHandle (hProcess);
}
else
{
DWORD error = GetLastError ();
__seterrno_from_win_error (error);
debug_printf ("OpenProcess: ret %d", error);
return 0;
}
if (ret == STATUS_SUCCESS) if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemTimeOfDayInformation, ret = NtQueryInformationProcess (hProcess,
(PVOID) &stodi, ProcessTimes,
sizeof stodi, NULL); (PVOID) &put,
sizeof put, NULL);
if (ret == STATUS_SUCCESS) if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemProcessorTimes, ret = NtQueryInformationProcess (hProcess,
(PVOID) &spt, ProcessBasicInformation,
sizeof spt, NULL); (PVOID) &pbi,
if (ret != STATUS_SUCCESS) sizeof pbi, NULL);
{ if (ret == STATUS_SUCCESS)
__seterrno_from_nt_status (ret); ret = NtQueryInformationProcess (hProcess,
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret); ProcessQuotaLimits,
return 0; (PVOID) &ql,
} sizeof ql, NULL);
fault_count = vmc.PageFaultCount; CloseHandle (hProcess);
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
#if 0
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
else
/*
* sometimes stodi.CurrentTime is a bit behind
* Note: some older versions of procps are broken and can't cope
* with process start times > time(NULL).
*/
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
#endif
priority = pbi.BasePriority;
unsigned page_size = getsystempagesize ();
vmsize = vmc.PagefileUsage;
vmrss = vmc.WorkingSetSize / page_size;
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
} }
else
{
DWORD error = GetLastError ();
__seterrno_from_win_error (error);
debug_printf ("OpenProcess: ret %d", error);
return 0;
}
if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
(PVOID) &stodi,
sizeof stodi, NULL);
if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemProcessorTimes,
(PVOID) &spt,
sizeof spt, NULL);
if (ret != STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret);
return 0;
}
fault_count = vmc.PageFaultCount;
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
#if 0
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
else
/*
* sometimes stodi.CurrentTime is a bit behind
* Note: some older versions of procps are broken and can't cope
* with process start times > time(NULL).
*/
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
#endif
priority = pbi.BasePriority;
unsigned page_size = getsystempagesize ();
vmsize = vmc.PagefileUsage;
vmrss = vmc.WorkingSetSize / page_size;
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
return __small_sprintf (destbuf, "%d (%s) %c " return __small_sprintf (destbuf, "%d (%s) %c "
"%d %d %d %d %d " "%d %d %d %d %d "
@ -767,7 +762,7 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize)
state = 'Z'; state = 'Z';
else if (p->process_state & PID_STOPPED) else if (p->process_state & PID_STOPPED)
state = 'T'; state = 'T';
else if (wincap.is_winnt ()) else
state = get_process_state (p->dwProcessId); state = get_process_state (p->dwProcessId);
switch (state) switch (state)
{ {
@ -788,14 +783,12 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize)
state_str = "stopped"; state_str = "stopped";
break; break;
} }
if (wincap.is_winnt ()) if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
{ &vmlib, &vmshare))
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, &vmlib, &vmshare)) return 0;
return 0; unsigned page_size = getsystempagesize ();
unsigned page_size = getsystempagesize (); vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
vmsize *= page_size; vmrss *= page_size; vmdata *= page_size; vmtext *= page_size; vmlib *= page_size;
vmtext *= page_size; vmlib *= page_size;
}
// The real uid value for *this* process is stored at cygheap->user.real_uid // The real uid value for *this* process is stored at cygheap->user.real_uid
// but we can't get at the real uid value for any other process, so // but we can't get at the real uid value for any other process, so
// just fake it as p->uid. Similar for p->gid. // just fake it as p->uid. Similar for p->gid.
@ -823,7 +816,8 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize)
p->ppid, p->ppid,
p->uid, p->uid, p->uid, p->uid, p->uid, p->uid, p->uid, p->uid,
p->gid, p->gid, p->gid, p->gid, p->gid, p->gid, p->gid, p->gid,
vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0, vmtext >> 10, vmlib >> 10, vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0,
vmtext >> 10, vmlib >> 10,
0, 0, p->getsigmask () 0, 0, p->getsigmask ()
); );
} }
@ -833,15 +827,11 @@ format_process_statm (_pinfo *p, char *destbuf, size_t maxsize)
{ {
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL, unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
vmlib = 0UL, vmshare = 0UL; vmlib = 0UL, vmshare = 0UL;
if (wincap.is_winnt ()) if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
{ &vmlib, &vmshare))
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, return 0;
&vmlib, &vmshare))
return 0;
}
return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld", return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld",
vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0 vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0);
);
} }
static int static int

View File

@ -53,15 +53,6 @@ daemon (int nochdir, int noclose)
case -1: case -1:
return -1; return -1;
case 0: case 0:
if (!wincap.is_winnt ())
{
/* Register as service under 9x/Me which allows to close
the parent window with the daemon still running.
This function only exists on 9x/Me and is autoloaded
so it fails silently on NT. */
DWORD WINAPI RegisterServiceProcess (DWORD, DWORD);
RegisterServiceProcess (0, 1);
}
break; break;
default: default:
/* This sleep avoids a race condition which kills the /* This sleep avoids a race condition which kills the

View File

@ -152,121 +152,9 @@ gen_access (DWORD openflags, int flags)
return ret; return ret;
} }
/* OS specific wrapper functions for map/section functions. */
static BOOL
VirtualProt9x (PVOID addr, SIZE_T len, DWORD prot, PDWORD oldprot)
{
if (addr >= (caddr_t)0x80000000 && addr <= (caddr_t)0xBFFFFFFF)
return TRUE; /* FAKEALARM! */
return VirtualProtect (addr, len, prot, oldprot);
}
static BOOL
VirtualProtNT (PVOID addr, SIZE_T len, DWORD prot, PDWORD oldprot)
{
return VirtualProtect (addr, len, prot, oldprot);
}
static BOOL
VirtualProtEx9x (HANDLE parent, PVOID addr, SIZE_T len, DWORD prot,
PDWORD oldprot)
{
if (addr >= (caddr_t)0x80000000 && addr <= (caddr_t)0xBFFFFFFF)
return TRUE; /* FAKEALARM! */
return VirtualProtectEx (parent, addr, len, prot, oldprot);
}
static BOOL
VirtualProtExNT (HANDLE parent, PVOID addr, SIZE_T len, DWORD prot,
PDWORD oldprot)
{
return VirtualProtectEx (parent, addr, len, prot, oldprot);
}
/* This allows to stay lazy about VirtualProtect usage in subsequent code. */
#define VirtualProtect(a,l,p,o) (mmap_func->VirtualProt((a),(l),(p),(o)))
#define VirtualProtectEx(h,a,l,p,o) (mmap_func->VirtualProtEx((h),(a),(l),(p),(o)))
static HANDLE static HANDLE
CreateMapping9x (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags, CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
int prot, int flags, const char *name) int prot, int flags, const char *)
{
HANDLE h;
DWORD high, low;
DWORD protect = gen_create_protect (openflags, flags);
/* copy-on-write doesn't work properly on 9x with real files. While the
changes are not propagated to the file, they are visible to other
processes sharing the same file mapping object. Workaround: Don't
use named file mapping. That should work since sharing file
mappings only works reliable using named file mapping on 9x.
On 9x/ME try first to open the mapping by name when opening a
shared file object. This is needed since 9x/ME only shares objects
between processes by name. What a mess... */
if (fhdl != INVALID_HANDLE_VALUE && !priv (flags))
{
/* Grrr, the whole stuff is just needed to try to get a reliable
mapping of the same file. Even that uprising isn't bullet
proof but it does it's best... */
char namebuf[CYG_MAX_PATH];
cygwin_conv_to_full_posix_path (name, namebuf);
for (int i = strlen (namebuf) - 1; i >= 0; --i)
namebuf[i] = cyg_tolower (namebuf [i]);
debug_printf ("named sharing");
DWORD access = gen_access (openflags, flags);
/* Different access modes result in incompatible mappings. So we
create different maps per access mode by using different names. */
switch (access)
{
case FILE_MAP_READ:
namebuf[0] = 'R';
break;
case FILE_MAP_WRITE:
namebuf[0] = 'W';
break;
case FILE_MAP_COPY:
namebuf[0] = 'C';
break;
}
if (!(h = OpenFileMapping (access, TRUE, namebuf)))
h = CreateFileMapping (fhdl, &sec_none, protect, 0, 0, namebuf);
}
else if (fhdl == INVALID_HANDLE_VALUE)
{
/* Standard anonymous mapping needs non-zero len. */
h = CreateFileMapping (fhdl, &sec_none, protect, 0, len, NULL);
}
else if (autogrow (flags))
{
high = (off + len) >> 32;
low = (off + len) & UINT32_MAX;
/* Auto-grow only works if the protection is PAGE_READWRITE. So,
first we call CreateFileMapping with PAGE_READWRITE, then, if the
requested protection is different, we close the mapping and
reopen it again with the correct protection, if auto-grow worked. */
h = CreateFileMapping (fhdl, &sec_none, PAGE_READWRITE,
high, low, NULL);
if (h && protect != PAGE_READWRITE)
{
CloseHandle (h);
h = CreateFileMapping (fhdl, &sec_none, protect,
high, low, NULL);
}
}
else
{
/* Zero len creates mapping for whole file. */
h = CreateFileMapping (fhdl, &sec_none, protect, 0, 0, NULL);
}
return h;
}
static HANDLE
CreateMappingNT (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
int prot, int flags, const char *)
{ {
HANDLE h; HANDLE h;
NTSTATUS ret; NTSTATUS ret;
@ -318,36 +206,8 @@ CreateMappingNT (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
} }
void * void *
MapView9x (HANDLE h, void *addr, size_t len, DWORD openflags, MapView (HANDLE h, void *addr, size_t len, DWORD openflags,
int prot, int flags, _off64_t off) int prot, int flags, _off64_t off)
{
DWORD high = off >> 32;
DWORD low = off & UINT32_MAX;
DWORD access = gen_access (openflags, flags);
void *base;
/* Try mapping using the given address first, even if it's NULL.
If it failed, and addr was not NULL and flags is not MAP_FIXED,
try again with NULL address.
Note: Retrying the mapping might be unnecessary, now that mmap64 checks
for a valid memory area first. */
if (!addr)
base = MapViewOfFile (h, access, high, low, len);
else
{
base = MapViewOfFileEx (h, access, high, low, len, addr);
if (!base && !fixed (flags))
base = MapViewOfFile (h, access, high, low, len);
}
debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%D, "
"len:%u, addr:%x)", base, h, access, off, len, addr);
return base;
}
void *
MapViewNT (HANDLE h, void *addr, size_t len, DWORD openflags,
int prot, int flags, _off64_t off)
{ {
NTSTATUS ret; NTSTATUS ret;
LARGE_INTEGER offset = { QuadPart:off }; LARGE_INTEGER offset = { QuadPart:off };
@ -382,39 +242,6 @@ MapViewNT (HANDLE h, void *addr, size_t len, DWORD openflags,
return base; return base;
} }
struct mmap_func_t
{
HANDLE (*CreateMapping)(HANDLE, size_t, _off64_t, DWORD, int, int,
const char *);
void * (*MapView)(HANDLE, void *, size_t, DWORD, int, int, _off64_t);
BOOL (*VirtualProt)(PVOID, SIZE_T, DWORD, PDWORD);
BOOL (*VirtualProtEx)(HANDLE, PVOID, SIZE_T, DWORD, PDWORD);
};
mmap_func_t mmap_funcs_9x =
{
CreateMapping9x,
MapView9x,
VirtualProt9x,
VirtualProtEx9x
};
mmap_func_t mmap_funcs_nt =
{
CreateMappingNT,
MapViewNT,
VirtualProtNT,
VirtualProtExNT
};
mmap_func_t *mmap_func;
void
mmap_init ()
{
mmap_func = wincap.is_winnt () ? &mmap_funcs_nt : &mmap_funcs_9x;
}
/* Class structure used to keep a record of all current mmap areas /* Class structure used to keep a record of all current mmap areas
in a process. Needed for bookkeeping all mmaps in a process and in a process. Needed for bookkeeping all mmaps in a process and
for duplicating all mmaps after fork() since mmaps are not propagated for duplicating all mmaps after fork() since mmaps are not propagated
@ -1082,50 +909,25 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
goto out; goto out;
} }
/* On 9x you can't create mappings with PAGE_WRITECOPY protection if /* You can't create mappings with PAGE_EXECUTE protection if
the file isn't explicitely opened with WRITE access. */ the file isn't explicitely opened with EXECUTE access. */
if (!wincap.is_winnt () && priv (flags) HANDLE h = CreateFile (fh->get_win32_name (),
&& !(fh->get_access () & GENERIC_WRITE)) fh->get_access () | GENERIC_EXECUTE,
wincap.shared (), &sec_none_nih,
OPEN_EXISTING, 0, NULL);
if (h != INVALID_HANDLE_VALUE)
{ {
HANDLE h = CreateFile (fh->get_win32_name (),
fh->get_access () | GENERIC_WRITE,
wincap.shared (), &sec_none_nih,
OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE)
{
set_errno (EACCES);
goto out;
}
fh_disk_file.set_io_handle (h); fh_disk_file.set_io_handle (h);
fh_disk_file.set_access (fh->get_access () | GENERIC_WRITE); fh_disk_file.set_access (fh->get_access () | GENERIC_EXECUTE);
path_conv pc;
pc.set_name (fh->get_win32_name (), "");
fh_disk_file.set_name (pc);
fh = &fh_disk_file; fh = &fh_disk_file;
} }
else if (prot & PROT_EXEC)
/* On NT you can't create mappings with PAGE_EXECUTE protection if
the file isn't explicitely opened with EXECUTE access. */
if (wincap.is_winnt ())
{ {
HANDLE h = CreateFile (fh->get_win32_name (), /* TODO: To be or not to be... I'm opting for refusing this
fh->get_access () | GENERIC_EXECUTE, mmap request rather than faking it, but that might break
wincap.shared (), &sec_none_nih, some non-portable code. */
OPEN_EXISTING, 0, NULL); set_errno (EACCES);
if (h != INVALID_HANDLE_VALUE) goto out;
{
fh_disk_file.set_io_handle (h);
fh_disk_file.set_access (fh->get_access () | GENERIC_EXECUTE);
fh = &fh_disk_file;
}
else if (prot & PROT_EXEC)
{
/* TODO: To be or not to be... I'm opting for refusing this
mmap request rather than faking it, but that might break
some non-portable code. */
set_errno (EACCES);
goto out;
}
} }
if (fh->fstat (&st)) if (fh->fstat (&st))
@ -1759,8 +1561,8 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
} }
else else
{ {
h = mmap_func->CreateMapping (get_handle (), len, off, get_access (), h = CreateMapping (get_handle (), len, off, get_access (),
prot, flags, get_win32_name ()); prot, flags, get_win32_name ());
if (!h) if (!h)
{ {
__seterrno (); __seterrno ();
@ -1768,7 +1570,7 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
base = mmap_func->MapView (h, *addr, len, get_access(), prot, flags, off); base = MapView (h, *addr, len, get_access(), prot, flags, off);
if (!base || (fixed (flags) && base != *addr)) if (!base || (fixed (flags) && base != *addr))
{ {
if (!base) if (!base)
@ -1822,8 +1624,7 @@ fhandler_dev_zero::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
base = VirtualAlloc (address, size, alloc_type, PAGE_READWRITE); base = VirtualAlloc (address, size, alloc_type, PAGE_READWRITE);
} }
else else
base = mmap_func->MapView (h, address, size, get_access (), base = MapView (h, address, size, get_access (), prot, flags, offset);
prot, flags, offset);
if (base != address) if (base != address)
{ {
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;
@ -1840,8 +1641,8 @@ HANDLE
fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot, fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
int flags, _off64_t off) int flags, _off64_t off)
{ {
HANDLE h = mmap_func->CreateMapping (get_handle (), len, off, get_access (), HANDLE h = CreateMapping (get_handle (), len, off, get_access (),
prot, flags, get_win32_name ()); prot, flags, get_win32_name ());
if (!h) if (!h)
{ {
__seterrno (); __seterrno ();
@ -1849,8 +1650,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
void *base = mmap_func->MapView (h, *addr, len, get_access (), void *base = MapView (h, *addr, len, get_access (), prot, flags, off);
prot, flags, off);
if (!base || (fixed (flags) && base != *addr)) if (!base || (fixed (flags) && base != *addr))
{ {
if (!base) if (!base)
@ -1894,8 +1694,7 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
void *address) void *address)
{ {
/* Re-create the map */ /* Re-create the map */
void *base = mmap_func->MapView (h, address, size, get_access (), void *base = MapView (h, address, size, get_access (), prot, flags, offset);
prot, flags, offset);
if (base != address) if (base != address)
{ {
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;
@ -1947,8 +1746,8 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
void *base = MapViewNT (h, *addr, len, get_access (), void *base = MapView (h, *addr, len, get_access (), prot,
prot, flags | MAP_ANONYMOUS, off); flags | MAP_ANONYMOUS, off);
if (!base || (fixed (flags) && base != *addr)) if (!base || (fixed (flags) && base != *addr))
{ {
if (!base) if (!base)
@ -1991,8 +1790,8 @@ fhandler_dev_mem::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
_off64_t offset, DWORD size, _off64_t offset, DWORD size,
void *address) void *address)
{ {
void *base = MapViewNT (h, address, size, get_access (), prot, void *base = MapView (h, address, size, get_access (), prot,
flags | MAP_ANONYMOUS, offset); flags | MAP_ANONYMOUS, offset);
if (base != address) if (base != address)
{ {
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;

View File

@ -1076,13 +1076,6 @@ cygwin_send (int fd, const void *buf, size_t len, int flags)
extern "C" int extern "C" int
getdomainname (char *domain, size_t len) getdomainname (char *domain, size_t len)
{ {
/*
* This works for Win95 only if the machine is configured to use MS-TCP.
* If a third-party TCP is being used this will fail.
* FIXME: On Win95, is there a way to portably check the TCP stack
* in use and include paths for the Domain name in each ?
* Punt for now and assume MS-TCP on Win95.
*/
sig_dispatch_pending (); sig_dispatch_pending ();
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
@ -1099,16 +1092,11 @@ getdomainname (char *domain, size_t len)
return 0; return 0;
} }
/* This is only used by Win95 and NT <= 4.0. /* This is only used by NT4.
The registry names are language independent. The registry names are language independent. */
FIXME: Handle DHCP on Win95. The DhcpDomain(s) may be available
in ..VxD\DHCP\DhcpInfoXX\OptionInfo, RFC 1533 format */
reg_key r (HKEY_LOCAL_MACHINE, KEY_READ, reg_key r (HKEY_LOCAL_MACHINE, KEY_READ,
(!wincap.is_winnt ()) ? "System" : "SYSTEM", "SYSTEM", "CurrentControlSet", "Services",
"CurrentControlSet", "Services", "Tcpip", "Parameters", NULL);
(!wincap.is_winnt ()) ? "VxD" : "Tcpip",
(!wincap.is_winnt ()) ? "MSTCP" : "Parameters", NULL);
if (!r.error ()) if (!r.error ())
{ {
@ -1834,177 +1822,6 @@ get_nt_ifconf (struct ifconf *ifc, int what)
ifc->ifc_len = cnt * sizeof (struct ifreq); ifc->ifc_len = cnt * sizeof (struct ifreq);
} }
/*
* IFCONF Windows 95:
* HKLM/Enum/Network/MSTCP/"*"
* -> Value "Driver" enth<74>lt Subkey relativ zu
* HKLM/System/CurrentControlSet/Class/
* -> In Subkey "Bindings" die Values aufz<66>hlen
* -> Enth<74>lt Subkeys der Form "VREDIR\*"
* Das * ist ein Subkey relativ zu
* HKLM/System/CurrentControlSet/Class/Net/
* HKLM/System/CurrentControlSet/Class/"Driver"
* -> Value "IPAddress"
* -> Value "IPMask"
* HKLM/System/CurrentControlSet/Class/Net/"*"(aus "VREDIR\*")
* -> Wenn Value "AdapterName" == "MS$PPP" -> ppp interface
* -> Value "DriverDesc" enth<74>lt den Namen
*
*/
static void
get_95_ifconf (struct ifconf *ifc, int what)
{
HKEY key;
unsigned long lip, lnp;
struct sockaddr_in *sa = NULL;
struct sockaddr *so = NULL;
FILETIME update;
LONG res;
DWORD size;
int cnt = 1;
char ifname[256];
char eth[2] = "/";
char ppp[2] = "/";
/* Union maps buffer to correct struct */
struct ifreq *ifr = ifc->ifc_req;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Enum\\Network\\MSTCP",
0, KEY_READ, &key) != ERROR_SUCCESS)
{
/* Set the correct length */
ifc->ifc_len = cnt * sizeof (struct ifreq);
return;
}
for (int i = 0;
(res = RegEnumKeyEx (key, i, ifname,
(size = sizeof ifname, &size),
0, 0, 0, &update)) != ERROR_NO_MORE_ITEMS;
++i)
{
HKEY ifkey, subkey;
char driver[256], classname[256], netname[256];
char adapter[256], ip[256], np[256];
if (res != ERROR_SUCCESS
|| RegOpenKeyEx (key, ifname, 0, KEY_READ, &ifkey) != ERROR_SUCCESS)
continue;
if (RegQueryValueEx (ifkey, "Driver", 0,
NULL, (unsigned char *) driver,
(size = sizeof driver, &size)) != ERROR_SUCCESS)
{
RegCloseKey (ifkey);
continue;
}
strcpy (classname, "System\\CurrentControlSet\\Services\\Class\\");
strcat (classname, driver);
if ((res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, classname,
0, KEY_READ, &subkey)) != ERROR_SUCCESS)
{
RegCloseKey (ifkey);
continue;
}
if (RegQueryValueEx (subkey, "IPAddress", 0,
NULL, (unsigned char *) ip,
(size = sizeof ip, &size)) == ERROR_SUCCESS
&& RegQueryValueEx (subkey, "IPMask", 0,
NULL, (unsigned char *) np,
(size = sizeof np, &size)) == ERROR_SUCCESS)
{
if ((caddr_t) ++ifr > ifc->ifc_buf
+ ifc->ifc_len - sizeof (struct ifreq))
goto out;
switch (what)
{
case SIOCGIFFLAGS:
ifr->ifr_flags = IFF_UP | IFF_RUNNING | IFF_BROADCAST;
break;
case SIOCGIFCONF:
case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = cygwin_inet_addr (ip);
sa->sin_family = AF_INET;
sa->sin_port = 0;
break;
case SIOCGIFBRDADDR:
lip = cygwin_inet_addr (ip);
lnp = cygwin_inet_addr (np);
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
sa->sin_addr.s_addr = lip & lnp | ~lnp;
sa->sin_family = AF_INET;
sa->sin_port = 0;
break;
case SIOCGIFNETMASK:
sa = (struct sockaddr_in *) &ifr->ifr_netmask;
sa->sin_addr.s_addr = cygwin_inet_addr (np);
sa->sin_family = AF_INET;
sa->sin_port = 0;
break;
case SIOCGIFHWADDR:
so = &ifr->ifr_hwaddr;
memset (so->sa_data, 0, IFHWADDRLEN);
so->sa_family = AF_INET;
break;
case SIOCGIFMETRIC:
ifr->ifr_metric = 1;
break;
case SIOCGIFMTU:
ifr->ifr_mtu = 1500;
break;
case SIOCGIFINDEX:
ifr->ifr_ifindex = -1;
break;
}
}
RegCloseKey (subkey);
strcpy (netname, "System\\CurrentControlSet\\Services\\Class\\Net\\");
strcat (netname, ifname);
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, netname,
0, KEY_READ, &subkey) != ERROR_SUCCESS)
{
RegCloseKey (ifkey);
--ifr;
continue;
}
if (RegQueryValueEx (subkey, "AdapterName", 0,
NULL, (unsigned char *) adapter,
(size = sizeof adapter, &size)) == ERROR_SUCCESS
&& strcasematch (adapter, "MS$PPP"))
{
++*ppp;
strcpy (ifr->ifr_name, "ppp");
strcat (ifr->ifr_name, ppp);
}
else
{
++*eth;
strcpy (ifr->ifr_name, "eth");
strcat (ifr->ifr_name, eth);
}
RegCloseKey (subkey);
RegCloseKey (ifkey);
++cnt;
}
out:
RegCloseKey (key);
/* Set the correct length */
ifc->ifc_len = cnt * sizeof (struct ifreq);
}
int int
get_ifconf (SOCKET s, struct ifconf *ifc, int what) get_ifconf (SOCKET s, struct ifconf *ifc, int what)
{ {
@ -2081,10 +1898,8 @@ get_ifconf (SOCKET s, struct ifconf *ifc, int what)
get_xp_ifconf (s, ifc, what); get_xp_ifconf (s, ifc, what);
else if (wincap.has_ip_helper_lib ()) else if (wincap.has_ip_helper_lib ())
get_2k_ifconf (ifc, what); get_2k_ifconf (ifc, what);
else if (wincap.is_winnt ())
get_nt_ifconf (ifc, what);
else else
get_95_ifconf (ifc, what); get_nt_ifconf (ifc, what);
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
/* netdb.cc: network database related routines. /* netdb.cc: network database related routines.
Copyright 2002 Red Hat, Inc. Copyright 2002, 2003, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -32,18 +32,10 @@ open_system_file (const char *relative_path)
{ {
char win32_name[CYG_MAX_PATH]; char win32_name[CYG_MAX_PATH];
char posix_name[CYG_MAX_PATH]; char posix_name[CYG_MAX_PATH];
if (wincap.is_winnt ())
{ if (!GetSystemDirectory (win32_name, CYG_MAX_PATH))
if (!GetSystemDirectory (win32_name, CYG_MAX_PATH)) return NULL;
return NULL; strcat (win32_name, "\\drivers\\etc\\");
strcat (win32_name, "\\drivers\\etc\\");
}
else
{
if (!GetWindowsDirectory (win32_name, CYG_MAX_PATH))
return NULL;
strcat (win32_name, "\\");
}
strcat (win32_name, relative_path); strcat (win32_name, relative_path);
cygwin_conv_to_full_posix_path (win32_name, posix_name); cygwin_conv_to_full_posix_path (win32_name, posix_name);
debug_printf ("netdb file to open %s", win32_name); debug_printf ("netdb file to open %s", win32_name);

View File

@ -1,7 +1,7 @@
/* pinfo.cc: process table support /* pinfo.cc: process table support
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
2006 Red Hat, Inc. 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -1204,7 +1204,7 @@ out:
} }
DWORD DWORD
winpids::enumNT (bool winpid) winpids::enum_processes (bool winpid)
{ {
static DWORD szprocs; static DWORD szprocs;
static SYSTEM_PROCESSES *procs; static SYSTEM_PROCESSES *procs;
@ -1243,38 +1243,11 @@ winpids::enumNT (bool winpid)
return nelem; return nelem;
} }
DWORD
winpids::enum9x (bool winpid)
{
DWORD nelem = 0;
HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
if (!h)
{
system_printf ("Couldn't create process snapshot, %E");
return 0;
}
PROCESSENTRY32 proc;
proc.dwSize = sizeof (proc);
if (Process32First (h, &proc))
do
{
if (proc.th32ProcessID)
add (nelem, winpid, proc.th32ProcessID);
}
while (Process32Next (h, &proc));
CloseHandle (h);
return nelem;
}
void void
winpids::set (bool winpid) winpids::set (bool winpid)
{ {
__malloc_lock (); __malloc_lock ();
npids = (this->*enum_processes) (winpid); npids = enum_processes (winpid);
if (pidlist) if (pidlist)
pidlist[npids] = 0; pidlist[npids] = 0;
__malloc_unlock (); __malloc_unlock ();
@ -1283,12 +1256,7 @@ winpids::set (bool winpid)
DWORD DWORD
winpids::enum_init (bool winpid) winpids::enum_init (bool winpid)
{ {
if (wincap.is_winnt ()) return enum_processes (winpid);
enum_processes = &winpids::enumNT;
else
enum_processes = &winpids::enum9x;
return (this->*enum_processes) (winpid);
} }
void void

View File

@ -1,6 +1,6 @@
/* pinfo.h: process table info /* pinfo.h: process table info
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc. Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -207,21 +207,18 @@ class winpids
DWORD *pidlist; DWORD *pidlist;
pinfo *pinfolist; pinfo *pinfolist;
DWORD pinfo_access; // access type for pinfo open DWORD pinfo_access; // access type for pinfo open
DWORD (winpids::* enum_processes) (bool winpid); DWORD enum_processes (bool winpid);
DWORD enum_init (bool winpid); DWORD enum_init (bool winpid);
DWORD enumNT (bool winpid);
DWORD enum9x (bool winpid);
void add (DWORD& nelem, bool, DWORD pid); void add (DWORD& nelem, bool, DWORD pid);
public: public:
DWORD npids; DWORD npids;
inline void reset () { release (); npids = 0;} inline void reset () { release (); npids = 0;}
void set (bool winpid); void set (bool winpid);
winpids (): make_copy (true), enum_processes (&winpids::enum_init) {} winpids (): make_copy (true) {}
winpids (int): make_copy (false), npidlist (0), pidlist (NULL), pinfolist (NULL), winpids (int): make_copy (false), npidlist (0), pidlist (NULL),
pinfo_access (0), enum_processes (&winpids::enum_init), npids (0) {} pinfolist (NULL), pinfo_access (0), npids (0) {}
winpids (DWORD acc): make_copy (false), npidlist (0), pidlist (NULL), pinfolist (NULL), winpids (DWORD acc): make_copy (false), npidlist (0), pidlist (NULL),
pinfo_access (acc), enum_processes (&winpids::enum_init), pinfolist (NULL), pinfo_access (acc), npids (0)
npids (0)
{ {
set (0); set (0);
} }

View File

@ -1,7 +1,7 @@
/* registry.cc: registry interface /* registry.cc: registry interface
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006 Red Hat, Inc. 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -215,9 +215,8 @@ get_registry_hive_path (const char *name, char *path)
if (!name || !path) if (!name || !path)
return NULL; return NULL;
__small_sprintf (key, "SOFTWARE\\Microsoft\\Windows%s\\CurrentVersion\\ProfileList\\", __small_sprintf (key, "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\"
wincap.is_winnt ()?" NT":""); "ProfileList\\%s", name);
strcat (key, name);
if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey)) if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
{ {
char buf[256]; char buf[256];
@ -253,10 +252,7 @@ load_registry_hive (const char * name)
} }
if (get_registry_hive_path (name, path)) if (get_registry_hive_path (name, path))
{ {
if (wincap.is_winnt ()) strcat (path, "\\NTUSER.DAT");
strcat (path, "\\NTUSER.DAT");
else
strcat (path, "\\USER.DAT");
if ((ret = RegLoadKeyA (HKEY_USERS, name, path)) != ERROR_SUCCESS) if ((ret = RegLoadKeyA (HKEY_USERS, name, path)) != ERROR_SUCCESS)
debug_printf ("Loading user registry hive for %s failed: %d", name, ret); debug_printf ("Loading user registry hive for %s failed: %d", name, ret);
} }

View File

@ -1,6 +1,6 @@
/* sched.cc: scheduler interface for Cygwin /* sched.cc: scheduler interface for Cygwin
Copyright 2001, 2002, 2006 Red Hat, Inc. Copyright 2001, 2002, 2006, 2007 Red Hat, Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -270,12 +270,6 @@ sched_rr_get_interval (pid_t pid, struct timespec *interval)
int vfindex, slindex, qindex, prisep; int vfindex, slindex, qindex, prisep;
long nsec; long nsec;
if (!wincap.is_winnt ())
{
set_errno (ESRCH);
return -1;
}
forwin = GetForegroundWindow (); forwin = GetForegroundWindow ();
if (!forwin) if (!forwin)
GetWindowThreadProcessId (forwin, &forprocid); GetWindowThreadProcessId (forwin, &forprocid);

View File

@ -1,7 +1,7 @@
/* shared.cc: shared data area support. /* shared.cc: shared data area support.
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006 Red Hat, Inc. 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -114,8 +114,7 @@ open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
FILE_MAP_READ|FILE_MAP_WRITE, FILE_MAP_READ|FILE_MAP_WRITE,
0, 0, 0, NULL); 0, 0, 0, NULL);
#ifdef DEBUGGING #ifdef DEBUGGING
if (wincap.is_winnt ()) system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared);
system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared);
#endif #endif
offsets[0] = 0; offsets[0] = 0;
} }

View File

@ -507,8 +507,7 @@ loop:
TRUE, /* inherit handles from parent */ TRUE, /* inherit handles from parent */
c_flags, c_flags,
envblock, /* environment */ envblock, /* environment */
wincap.is_winnt () || real_path.iscygexec () ? NULL,
NULL : cygheap->cwd.win32,
&si, &si,
&pi); &pi);
} }
@ -543,8 +542,7 @@ loop:
TRUE, /* inherit handles from parent */ TRUE, /* inherit handles from parent */
c_flags, c_flags,
envblock, /* environment */ envblock, /* environment */
wincap.is_winnt () || real_path.iscygexec () ? NULL,
NULL : cygheap->cwd.win32,
&si, &si,
&pi); &pi);
} }

View File

@ -231,14 +231,6 @@ try_to_bin (path_conv &win32_path, HANDLE h)
recycler, status); recycler, status);
} }
static DWORD
unlink_9x (path_conv &win32_name)
{
BOOL ret = DeleteFile (win32_name);
syscall_printf ("DeleteFile %s", ret ? "succeeded" : "failed");
return GetLastError ();
}
DWORD DWORD
unlink_nt (path_conv &win32_name, bool setattrs) unlink_nt (path_conv &win32_name, bool setattrs)
{ {
@ -344,6 +336,7 @@ unlink (const char *ourname)
{ {
int res = -1; int res = -1;
DWORD devn; DWORD devn;
DWORD lasterr;
path_conv win32_name (ourname, PC_SYM_NOFOLLOW, path_conv win32_name (ourname, PC_SYM_NOFOLLOW,
transparent_exe ? stat_suffixes : NULL); transparent_exe ? stat_suffixes : NULL);
@ -391,9 +384,7 @@ unlink (const char *ourname)
| FILE_ATTRIBUTE_HIDDEN)); | FILE_ATTRIBUTE_HIDDEN));
} }
DWORD lasterr; lasterr = unlink_nt (win32_name, setattrs);
lasterr = wincap.is_winnt () ? unlink_nt (win32_name, setattrs)
: unlink_9x (win32_name);
if (!lasterr) if (!lasterr)
res = 0; res = 0;
else else
@ -1172,7 +1163,7 @@ sync ()
FindVolumeClose (sh); FindVolumeClose (sh);
} }
} }
else if (wincap.is_winnt ()) /* 9x has no concept for opening volumes */ else
{ {
DWORD drives = GetLogicalDrives (); DWORD drives = GetLogicalDrives ();
DWORD mask = 1; DWORD mask = 1;

View File

@ -17,7 +17,6 @@ static NO_COPY wincaps wincap_unknown = {
chunksize:0, chunksize:0,
heapslop:0x0, heapslop:0x0,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -83,7 +82,6 @@ static NO_COPY wincaps wincap_nt4 = {
chunksize:0, chunksize:0,
heapslop:0x0, heapslop:0x0,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -149,7 +147,6 @@ static NO_COPY wincaps wincap_nt4sp4 = {
chunksize:0, chunksize:0,
heapslop:0x0, heapslop:0x0,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -215,7 +212,6 @@ static NO_COPY wincaps wincap_2000 = {
chunksize:0, chunksize:0,
heapslop:0x0, heapslop:0x0,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -281,7 +277,6 @@ static NO_COPY wincaps wincap_xp = {
chunksize:0, chunksize:0,
heapslop:0x0, heapslop:0x0,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -347,7 +342,6 @@ static NO_COPY wincaps wincap_2003 = {
chunksize:0, chunksize:0,
heapslop:0x4, heapslop:0x4,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:true, is_server:true,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,
@ -413,7 +407,6 @@ static NO_COPY wincaps wincap_vista = {
chunksize:0, chunksize:0,
heapslop:0x4, heapslop:0x4,
shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, shared:FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
is_winnt:true,
is_server:false, is_server:false,
access_denied_on_delete:false, access_denied_on_delete:false,
has_delete_on_close:true, has_delete_on_close:true,

View File

@ -17,7 +17,6 @@ struct wincaps
DWORD chunksize; DWORD chunksize;
DWORD heapslop; DWORD heapslop;
int shared; int shared;
unsigned is_winnt : 1;
unsigned is_server : 1; unsigned is_server : 1;
unsigned access_denied_on_delete : 1; unsigned access_denied_on_delete : 1;
unsigned has_delete_on_close : 1; unsigned has_delete_on_close : 1;
@ -99,7 +98,6 @@ public:
DWORD IMPLEMENT (chunksize) DWORD IMPLEMENT (chunksize)
DWORD IMPLEMENT (heapslop) DWORD IMPLEMENT (heapslop)
int IMPLEMENT (shared) int IMPLEMENT (shared)
bool IMPLEMENT (is_winnt)
bool IMPLEMENT (is_server) bool IMPLEMENT (is_server)
bool IMPLEMENT (access_denied_on_delete) bool IMPLEMENT (access_denied_on_delete)
bool IMPLEMENT (has_delete_on_close) bool IMPLEMENT (has_delete_on_close)

View File

@ -1,7 +1,7 @@
/* winsup.h: main Cygwin header file. /* winsup.h: main Cygwin header file.
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006 Red Hat, Inc. 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -300,7 +300,6 @@ extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
size_t getsystempagesize (); size_t getsystempagesize ();
/* mmap functions. */ /* mmap functions. */
void mmap_init ();
enum mmap_region_status enum mmap_region_status
{ {
MMAP_NONE, MMAP_NONE,