2009-07-14 Corinna Vinschen <corinna@vinschen.de>
+ Throughout avoid having to initialize constant UNICODE_STRINGs.
+ * globals.cc: Define constant UNICODE_STRINGs and store in .rdata
+ section.
+ * fhandler_disk_file.cc: Throughout, use readonly UNICODE_STRINGs
+ rather then initializing local UNICODE_STRING variable where
+ applicable.
+ * fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
+ * flock.cc (inode_t::inode_t): Ditto.
+ * mmap.cc: Ditto.
+ * syscalls.cc: Ditto.
+ * mount.cc (fs_info::update): Ditto.
+ * path.cc: Ditto.
+
+ * ntdll.h (RtlEqualUnicodePathPrefix): Redefine to take prefix as
+ UNICODE_STRING.
+ (RtlEqualUnicodePathSuffix): Redefine to take suffix as UNICODE_STRING.
+ * fhandler_disk_file.cc: Accommodate throughout.
+ * mount.cc (fs_info::update): Ditto.
+ * path.cc (cwdstuff::set): Ditto.
+ * syscalls.cc: Ditto.
+
+2009-07-14 Corinna Vinschen <corinna@vinschen.de>
+
* globals.cc (active_codepage): Remove.
2009-07-12 Christopher Faylor <me+cygwin@cgf.cx>
{
if (parent_dir_len == 1) /* root dir */
{
- UNICODE_STRING proc;
-
- RtlInitUnicodeString (&proc, L"proc");
- if (RtlEqualUnicodeString (fname, &proc, FALSE))
+ if (RtlEqualUnicodeString (fname, &ro_u_proc, FALSE))
{
found[__DIR_PROC] = true;
return 2;
{
PUNICODE_STRING path = pc.get_nt_native_path ();
- if (RtlEqualUnicodePathSuffix (path, L".exe", TRUE)
- || RtlEqualUnicodePathSuffix (path, L".bat", TRUE)
- || RtlEqualUnicodePathSuffix (path, L".com", TRUE))
+ if (RtlEqualUnicodePathSuffix (path, &ro_u_exe, TRUE)
+ || RtlEqualUnicodePathSuffix (path, &ro_u_lnk, TRUE)
+ || RtlEqualUnicodePathSuffix (path, &ro_u_com, TRUE))
pc.set_exec ();
}
/* No known sufix, check file header. This catches binaries and
shebang scripts. */
if (pc.exec_state () == dont_know_if_executable)
{
- UNICODE_STRING same;
OBJECT_ATTRIBUTES attr;
HANDLE h;
IO_STATUS_BLOCK io;
- RtlInitUnicodeString (&same, L"");
- InitializeObjectAttributes (&attr, &same, 0, get_handle (), NULL);
+ InitializeObjectAttributes (&attr, &ro_u_empty, 0, get_handle (),
+ NULL);
if (NT_SUCCESS (NtOpenFile (&h, FILE_READ_DATA, &attr, &io,
FILE_SHARE_VALID_FLAGS, 0)))
{
else if (!pc.isdir ()
&& pc.is_binary ()
&& RtlEqualUnicodePathSuffix (pc.get_nt_native_path (),
- L".exe", TRUE)
+ &ro_u_exe, TRUE)
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".exe", TRUE))
+ &ro_u_exe, TRUE))
{
/* Executable hack. */
stpcpy (stpcpy (new_buf, newpath), ".exe");
if ((attr & FILE_ATTRIBUTE_READONLY) && fname->Length > 4 * sizeof (WCHAR))
{
UNICODE_STRING uname;
- UNICODE_STRING lname;
RtlInitCountedUnicodeString (&uname,
fname->Buffer
+ fname->Length / sizeof (WCHAR) - 4,
4 * sizeof (WCHAR));
- RtlInitUnicodeString (&lname, (PWCHAR) L".lnk");
- if (RtlEqualUnicodeString (&uname, &lname, TRUE))
+ if (RtlEqualUnicodeString (&uname, &ro_u_lnk, TRUE))
{
tmp_pathbuf tp;
UNICODE_STRING fbuf;
to NtQueryDirectoryFile on remote shares is ignored, thus
resulting in not being able to rewind on remote shares. By
reopening the directory, we get a fresh new directory pointer. */
- UNICODE_STRING fname;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
IO_STATUS_BLOCK io;
HANDLE new_dir;
- RtlInitUnicodeString (&fname, L"");
- InitializeObjectAttributes (&attr, &fname, pc.objcaseinsensitive (),
+ InitializeObjectAttributes (&attr, &ro_u_empty, pc.objcaseinsensitive (),
get_handle (), NULL);
status = NtOpenFile (&new_dir, SYNCHRONIZE | FILE_LIST_DIRECTORY,
&attr, &io, FILE_SHARE_VALID_FLAGS,
return 0;
}
- UNICODE_STRING memstr;
- RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
-
OBJECT_ATTRIBUTES attr;
- InitializeObjectAttributes (&attr, &memstr,
+ InitializeObjectAttributes (&attr, &ro_u_pmem,
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
NULL, NULL);
api_fatal ("NtCreateDirectoryObject(inode): %p", status);
/* Create a mutex object in the file specific dir, which is used for
access synchronization on the dir and its objects. */
- RtlInitUnicodeString (&uname, L"mtx");
- InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF, i_dir,
+ InitializeObjectAttributes (&attr, &ro_u_mtx, OBJ_INHERIT | OBJ_OPENIF, i_dir,
everyone_sd (CYG_MUTANT_ACCESS));
status = NtCreateMutant (&i_mtx, CYG_MUTANT_ACCESS, &attr, FALSE);
if (!NT_SUCCESS (status))
char *old_title;
+/* Heavily-used const UNICODE_STRINGs are defined here once. */
+#define _ROU(_s) \
+ { Length: sizeof (_s) - sizeof (WCHAR), \
+ MaximumLength: sizeof (_s), \
+ Buffer: (PWSTR) (_s) }
+#define _RDATA __attribute__ ((section(".rdata")))
+UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
+UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
+UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
+UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
+UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
+UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
+UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
+UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
+UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
+UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
+UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
+UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
+UNICODE_STRING _RDATA ro_u_sunwnfs = _ROU (L"SUNWNFS");
+UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
+UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
+UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
+#undef _RDATA
+#undef _ROU
+
extern "C"
{
/* This is an exported copy of environ which can be used by DLLs
/* You can't create mappings with PAGE_EXECUTE protection if
the file isn't explicitely opened with EXECUTE access. */
- UNICODE_STRING fname;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
HANDLE h;
IO_STATUS_BLOCK io;
- RtlInitUnicodeString (&fname, L"");
- InitializeObjectAttributes (&attr, &fname, fh->pc.objcaseinsensitive (),
+ InitializeObjectAttributes (&attr, &ro_u_empty, fh->pc.objcaseinsensitive (),
fh->get_handle (), NULL);
status = NtOpenFile (&h,
fh->get_access () | GENERIC_EXECUTE | SYNCHRONIZE,
return INVALID_HANDLE_VALUE;
}
- UNICODE_STRING memstr;
- RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
-
OBJECT_ATTRIBUTES attr;
- InitializeObjectAttributes (&attr, &memstr,
+ InitializeObjectAttributes (&attr, &ro_u_pmem,
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
NULL, NULL);
FILE_FS_VOLUME_INFORMATION ffvi;
WCHAR buf[NAME_MAX + 1];
} ffvi_buf;
- UNICODE_STRING fsname, testname;
+ UNICODE_STRING fsname;
clear ();
if (in_vol)
if (ffdi.Characteristics & FILE_REMOTE_DEVICE
|| (!ffdi.DeviceType
- && RtlEqualUnicodePathPrefix (attr.ObjectName, L"\\??\\UNC\\", TRUE)))
+ && RtlEqualUnicodePathPrefix (attr.ObjectName, &ro_u_uncp, TRUE)))
is_remote_drive (true);
else
is_remote_drive (false);
| FILE_NAMED_STREAMS)
RtlInitCountedUnicodeString (&fsname, ffai_buf.ffai.FileSystemName,
ffai_buf.ffai.FileSystemNameLength);
- is_fat (RtlEqualUnicodePathPrefix (&fsname, L"FAT", TRUE));
- RtlInitUnicodeString (&testname, L"CSC-CACHE");
- is_csc_cache (RtlEqualUnicodeString (&fsname, &testname, FALSE));
- RtlInitUnicodeString (&testname, L"NTFS");
+ is_fat (RtlEqualUnicodePathPrefix (&fsname, &ro_u_fat, TRUE));
+ is_csc_cache (RtlEqualUnicodeString (&fsname, &ro_u_csc, FALSE));
if (is_remote_drive ())
{
/* This always fails on NT4. */
/* Test for Samba on NT4 or for older Samba releases not supporting
extended info. */
if (!is_samba ())
- is_samba (RtlEqualUnicodeString (&fsname, &testname, FALSE)
+ is_samba (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
&& FS_IS_SAMBA);
if (!is_samba ())
{
- is_netapp (RtlEqualUnicodeString (&fsname, &testname, FALSE)
+ is_netapp (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
&& FS_IS_NETAPP_DATAONTAP);
- RtlInitUnicodeString (&testname, L"NFS");
- is_nfs (RtlEqualUnicodeString (&fsname, &testname, FALSE));
+ is_nfs (RtlEqualUnicodeString (&fsname, &ro_u_nfs, FALSE));
if (!is_nfs ())
{
/* Known remote file systems which can't handle calls to
NtQueryDirectoryFile(FileIdBothDirectoryInformation) */
- RtlInitUnicodeString (&testname, L"UNIXFS");
has_buggy_fileid_dirinfo (RtlEqualUnicodeString (&fsname,
- &testname,
+ &ro_u_unixfs,
FALSE));
/* Known remote file systems with buggy open calls. Further
explanation in fhandler.cc (fhandler_disk_file::open). */
- RtlInitUnicodeString (&testname, L"SUNWNFS");
- has_buggy_open (RtlEqualUnicodeString (&fsname, &testname,
+ has_buggy_open (RtlEqualUnicodeString (&fsname, &ro_u_sunwnfs,
FALSE));
}
}
}
- is_ntfs (RtlEqualUnicodeString (&fsname, &testname, FALSE)
+ is_ntfs (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
&& !is_samba () && !is_netapp ());
has_acls (flags () & FS_PERSISTENT_ACLS);
is_cdrom (ffdi.DeviceType == FILE_DEVICE_CD_ROM);
if (is_cdrom ())
{
- RtlInitUnicodeString (&testname, L"UDF");
- is_udf (RtlEqualUnicodeString (&fsname, &testname, FALSE));
+ is_udf (RtlEqualUnicodeString (&fsname, &ro_u_udf, FALSE));
/* UDF on NT 5.x is broken (at least) in terms of case sensitivity. The
UDF driver reports the FILE_CASE_SENSITIVE_SEARCH capability but:
- Opening the root directory for query seems to work at first, but the
}
/* Check if prefix is a prefix of path. */
inline
- BOOLEAN NTAPI RtlEqualUnicodePathPrefix (PUNICODE_STRING path, PCWSTR prefix,
+ BOOLEAN NTAPI RtlEqualUnicodePathPrefix (PUNICODE_STRING path,
+ PUNICODE_STRING prefix,
BOOLEAN caseinsensitive)
{
- UNICODE_STRING p, pref;
+ UNICODE_STRING p;
- RtlInitUnicodeString (&pref, prefix);
RtlInitCountedUnicodeString (&p, path->Buffer,
- pref.Length < path->Length
- ? pref.Length : path->Length);
- return RtlEqualUnicodeString (&p, &pref, caseinsensitive);
+ prefix->Length < path->Length
+ ? prefix->Length : path->Length);
+ return RtlEqualUnicodeString (&p, prefix, caseinsensitive);
}
/* Check if sufffix is a sufffix of path. */
inline
- BOOL NTAPI RtlEqualUnicodePathSuffix (PUNICODE_STRING path, PCWSTR suffix,
+ BOOL NTAPI RtlEqualUnicodePathSuffix (PUNICODE_STRING path,
+ PUNICODE_STRING suffix,
BOOLEAN caseinsensitive)
{
- UNICODE_STRING p, suf;
+ UNICODE_STRING p;
- RtlInitUnicodeString (&suf, suffix);
- if (suf.Length < path->Length)
+ if (suffix->Length < path->Length)
RtlInitCountedUnicodeString (&p, (PWCHAR) ((PBYTE) path->Buffer
- + path->Length - suf.Length),
- suf.Length);
+ + path->Length - suffix->Length),
+ suffix->Length);
else
RtlInitCountedUnicodeString (&p, path->Buffer, path->Length);
- return RtlEqualUnicodeString (&p, &suf, caseinsensitive);
+ return RtlEqualUnicodeString (&p, suffix, caseinsensitive);
}
/* Implemented in strfuncs.cc. Create a Hex UNICODE_STRING from a given
64 bit integer value. If append is TRUE, append the hex string,
{
if (path[1] == ':') /* X:\... */
{
- RtlAppendUnicodeToString (&upath, L"\\??\\");
+ RtlAppendUnicodeStringToString (&upath, &ro_u_natp);
str2uni_cat (upath, path);
/* The drive letter must be upper case. */
upath.Buffer[4] = towupper (upath.Buffer[4]);
else if ((path[2] != '.' && path[2] != '?')
|| path[3] != '\\') /* \\server\share\... */
{
- RtlAppendUnicodeToString (&upath, L"\\??\\UNC\\");
+ RtlAppendUnicodeStringToString (&upath, &ro_u_uncp);
str2uni_cat (upath, path + 2);
transform_chars (&upath, 8);
}
else /* \\.\device or \\?\foo */
{
- RtlAppendUnicodeToString (&upath, L"\\??\\");
+ RtlAppendUnicodeStringToString (&upath, &ro_u_natp);
str2uni_cat (upath, path + 4);
}
return &upath;
else
{
len = upath.Length / sizeof (WCHAR) - 4;
- if (RtlEqualUnicodePathPrefix (&upath, L"\\??\\UNC\\", TRUE))
+ if (RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
len -= 2;
}
}
goto out;
/* Is the file a subdir of the recycler? */
RtlInitCountedUnicodeString(&fname, pfni->FileName, pfni->FileNameLength);
- if (RtlEqualUnicodePathPrefix (&fname, recycler.Buffer, TRUE))
+ if (RtlEqualUnicodePathPrefix (&fname, &recycler, TRUE))
goto out;
/* Is fname the recycler? Temporarily hide trailing backslash. */
recycler.Length -= sizeof (WCHAR);
if (status == STATUS_CANNOT_DELETE && !pc.isremote ())
{
HANDLE fh2;
- UNICODE_STRING fname;
/* Re-open from handle so we open the correct file no matter if it
has been moved to the bin or not. */
- RtlInitUnicodeString (&fname, L"");
- InitializeObjectAttributes (&attr, &fname, 0, fh, NULL);
+ InitializeObjectAttributes (&attr, &ro_u_empty, 0, fh, NULL);
status = NtOpenFile (&fh2, DELETE, &attr, &io,
bin_stat == move_to_bin ? FILE_SHARE_VALID_FLAGS
: FILE_SHARE_DELETE,
}
else if (oldpc.is_lnk_symlink ()
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".lnk", TRUE))
+ &ro_u_lnk, TRUE))
rename_append_suffix (newpc, newpath, nlen, ".lnk");
else if (oldpc.is_binary () && !old_explicit_suffix
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".exe", TRUE))
+ &ro_u_exe, TRUE))
/* To rename an executable foo.exe to bar-without-exe-suffix, the
.exe suffix must be given explicitly in oldpath. */
rename_append_suffix (newpc, newpath, nlen, ".exe");
{
if (!newpc.is_lnk_symlink ()
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".lnk", TRUE))
+ &ro_u_lnk, TRUE))
{
rename_append_suffix (new2pc, newpath, nlen, ".lnk");
removepc = &newpc;
else if (oldpc.is_binary ())
{
if (!RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".exe", TRUE))
+ &ro_u_exe, TRUE))
{
rename_append_suffix (new2pc, newpath, nlen, ".exe");
removepc = &newpc;
else
{
if ((RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".lnk", TRUE)
+ &ro_u_lnk, TRUE)
|| RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
- L".exe", TRUE))
+ &ro_u_exe, TRUE))
&& !new_explicit_suffix)
{
new2pc.check (newpath, PC_SYM_NOFOLLOW, stat_suffixes);