bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] do not call GetHandleInformation() in Winstore apps


From: Steve Lhomme
Subject: Re: [PATCH] do not call GetHandleInformation() in Winstore apps
Date: Wed, 17 May 2023 07:57:04 +0200

On 2023-05-16 16:48, Bruno Haible wrote:
Hi,

This thread is obviously related to what we discussed three years ago:
https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00376.html

It is.

For the same reason as the previous email, I think winstorecompat/windowsappcompat is not the right solution for gnulib (extra global define, picking the right lib to link with). I even think it's not a good solution in general, even though I contributed to it heavily. It it good to be able to compile unmaintained projects. In general the code returns an error or try more or less to do what the original code did.

GetHandleInformation() is trickier to implement because it won't be the same between winstorecompat and windowsappcompat. It even depends on the actual Windows 10 the code is running on as CreateProcess() was only allowed since 10.0.16299 [1]. In all cases before that should it return FALSE (code failed as we can't tell the properties of the HANDLE) or TRUE (we can't tell the properties, we just assume it doesn't have what you want) ? For the gnulib usage, it's OK to return TRUE and the code go through, assuming HANDLE_FLAG_INHERIT is not set.

In other cases, where knowing about HANDLE_FLAG_PROTECT_FROM_CLOSE for example, it can't be simulated properly. And if the HANDLE is invalid or became unusable/closed it needs some extra checks that may even be impossible.

So not only winstorecompat is cumbersome, but it may not be reliable enough. In this case it's much better to go with local assumptions.

[1] https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-processthreads-l1-1-0dll

At that time, we discussed the function GetFileInformationByHandle,
and it is implemented in mingw's winstorecompat library:
https://github.com/mirror/mingw-w64/blob/master/mingw-w64-libraries/winstorecompat/src/GetFileInformationByHandle.c

Steve Lhomme wrote:
The API is forbidden [1] and HANDLE_FLAG_INHERIT would never be set as exec()
is not allowed either [2].

[1] 
https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-gethandleinformation

Ah, you mean the marker "[desktop apps only]" in that page?

+# if defined WINAPI_FAMILY && 
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+/* GetHandleInformation is not available in UWP, the flags it would provide
+   are also not available, so we just return 0.
+   
<https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-gethandleinformation>
+   <https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis> */
+static inline BOOL GetHandleInformation(HANDLE h, DWORD *pf)
+{
+  *pf = 0;
+  return TRUE;
+}

I think the proper place for such code is mingw's winstorecompat library,
not Gnulib. Can you try to submit it there?

Bruno






reply via email to

[Prev in Thread] Current Thread [Next in Thread]