From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 15DB63890426; Fri, 7 May 2021 21:05:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15DB63890426 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fetch Windows directory on all platforms and use throughout X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 19d59ce75d5301ae167b421111d77615eb307aa7 X-Git-Newrev: 44eb4163234089e8830b018dbcf6a08333eab202 Message-Id: <20210507210547.15DB63890426@sourceware.org> Date: Fri, 7 May 2021 21:05:47 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2021 21:05:47 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=44eb4163234089e8830b018dbcf6a08333eab202 commit 44eb4163234089e8830b018dbcf6a08333eab202 Author: Corinna Vinschen Date: Fri May 7 23:05:24 2021 +0200 Cygwin: fetch Windows directory on all platforms and use throughout Rather than fetching the system Windows directory at dll init time only on 32 bit, fetch it on all platforms. Store as WCHAR and UNICODE_STRING. Use where appropriate to simplify code. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/dcrt0.cc | 17 ++++++++++------- winsup/cygwin/fhandler_console.cc | 11 +++++------ winsup/cygwin/globals.cc | 6 +++--- winsup/cygwin/path.cc | 18 +++++------------- winsup/cygwin/uinfo.cc | 13 +------------ 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 3bbee4d5a..6f4723bb0 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -722,20 +722,23 @@ init_windows_system_directory () api_fatal ("can't find windows system directory"); windows_system_directory[windows_system_directory_length++] = L'\\'; windows_system_directory[windows_system_directory_length] = L'\0'; + /* We need the Windows dir with NT prefix in path.cc. Note that we + don't append a backslash, because we need the dir without backslash + for the environment. */ + wcpcpy (windows_directory_buf, L"\\??\\"); + windows_directory_length = + GetSystemWindowsDirectoryW (windows_directory, MAX_PATH - 4); + RtlInitCountedUnicodeString (&windows_directory_path, + windows_directory_buf, + (windows_directory_length + 4) * sizeof (WCHAR)); #ifdef __i386__ system_wow64_directory_length = - GetSystemWow64DirectoryW (system_wow64_directory, MAX_PATH); + GetSystemWow64DirectoryW (system_wow64_directory, MAX_PATH); if (system_wow64_directory_length) { system_wow64_directory[system_wow64_directory_length++] = L'\\'; system_wow64_directory[system_wow64_directory_length] = L'\0'; } - /* We need the Windows dir in path.cc. */ - wcscpy (windows_directory, windows_system_directory); - windows_directory_length = windows_system_directory_length - 1; - windows_directory[windows_directory_length] = L'\0'; - while (windows_directory[windows_directory_length - 1] != L'\\') - windows_directory[--windows_directory_length] = L'\0'; #endif /* __i386__ */ } } diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index ebe89fc9f..b3eae6a5a 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -112,12 +112,11 @@ beep () L"Apps", L".Default", L".Default", L".Current", NULL); if (r.created ()) { - PWCHAR buf = NULL; - UINT len = GetSystemWindowsDirectoryW (buf, 0) * sizeof (WCHAR); - buf = (PWCHAR) alloca (len += sizeof (ding)); - UINT res = GetSystemWindowsDirectoryW (buf, len); - if (res && res <= len) - r.set_string (L"", wcscat (buf, ding)); + tmp_pathbuf tp; + + PWCHAR ding_path = tp.w_get (); + wcpcpy (wcpcpy (ding_path, windows_directory), ding); + r.set_string (L"", ding_path); } MessageBeep (MB_OK); } diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index 0b9559ea7..d0c6046a5 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -23,12 +23,12 @@ HMODULE NO_COPY hntdll; int NO_COPY sigExeced; WCHAR windows_system_directory[MAX_PATH]; UINT windows_system_directory_length; -#ifdef __i386__ WCHAR system_wow64_directory[MAX_PATH]; UINT system_wow64_directory_length; -WCHAR windows_directory[MAX_PATH]; +WCHAR windows_directory_buf[MAX_PATH]; +PWCHAR windows_directory = windows_directory_buf + 4; UINT windows_directory_length; -#endif /* __i386__ */ +UNICODE_STRING windows_directory_path; WCHAR global_progname[NT_MAX_PATH]; /* program exit the program */ diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index b13377a48..dd7048486 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3462,19 +3462,11 @@ restart: file than the final path. Oh well... */ if (!fs.is_remote_drive () && wincap.is_wow64 ()) { - static UNICODE_STRING wpath; - UNICODE_STRING udpath; - - /* Create UNICODE_STRING for Windows dir. */ - RtlInitCountedUnicodeString (&wpath, windows_directory, - windows_directory_length * sizeof (WCHAR)); - /* Create a UNICODE_STRING from incoming path, splitting - off the leading "\\??\\" */ - RtlInitCountedUnicodeString (&udpath, upath.Buffer + 4, - upath.Length - 4 * sizeof (WCHAR)); - /* Are we below Windows dir? Skip the check for inner - symlinks. */ - if (RtlEqualUnicodePathPrefix (&udpath, &wpath, TRUE)) + /* windows_directory_path is stored without trailing backslash, + so we have to check this explicitely. */ + if (RtlEqualUnicodePathPrefix (&upath, &windows_directory_path, TRUE) + && upath.Buffer[windows_directory_path.Length / sizeof (WCHAR)] + == L'\\') goto file_not_symlink; } #endif /* __i386__ */ diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index c0a0f6163..6aae33c92 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -564,18 +564,7 @@ const char * cygheap_user::env_systemroot (const char *name, size_t namelen) { if (!psystemroot) - { - int size = GetSystemWindowsDirectoryW (NULL, 0); - if (size > 0) - { - WCHAR wsystemroot[size]; - size = GetSystemWindowsDirectoryW (wsystemroot, size); - if (size > 0) - sys_wcstombs_alloc (&psystemroot, HEAP_STR, wsystemroot); - } - if (size <= 0) - debug_printf ("GetSystemWindowsDirectoryW(), %E"); - } + sys_wcstombs_alloc (&psystemroot, HEAP_STR, windows_directory); return psystemroot; }