On Thu, 14 May 2020, Steve Lhomme wrote:
It's forbidden in any UWP app.
---
mingw-w64-headers/crt/process.h | 10 +++--
mingw-w64-headers/crt/unistd.h | 6 +--
.../winstorecompat/Makefile.am | 2 +
.../winstorecompat/src/getpid.c | 41 +++++++++++++++++++
4 files changed, 52 insertions(+), 7 deletions(-)
create mode 100644 mingw-w64-libraries/winstorecompat/src/getpid.c
diff --git a/mingw-w64-headers/crt/process.h b/mingw-w64-headers/crt/process.h
index 462a902d..e5ff9992 100644
--- a/mingw-w64-headers/crt/process.h
+++ b/mingw-w64-headers/crt/process.h
@@ -152,6 +152,12 @@ extern "C" {
#define WAIT_CHILD _WAIT_CHILD
#define WAIT_GRANDCHILD _WAIT_GRANDCHILD
+#if defined(_CRT_USE_WINAPI_FAMILY_DESKTOP_APP) || defined(WINSTORECOMPAT)
+#ifndef _CRT_GETPID_DEFINED
+#define _CRT_GETPID_DEFINED /* Also in unistd.h */
+ int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
+#endif
+#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP || WINSTORECOMPAT */
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
intptr_t __cdecl cwait(int *_TermStat,intptr_t _ProcHandle,int _Action)
__MINGW_ATTRIB_DEPRECATED_MSVC2005;
#ifdef __GNUC__
@@ -169,10 +175,6 @@ extern "C" {
intptr_t __cdecl spawnle(int,const char *_Filename,const char *_ArgList,...)
__MINGW_ATTRIB_DEPRECATED_MSVC2005;
intptr_t __cdecl spawnlp(int,const char *_Filename,const char *_ArgList,...)
__MINGW_ATTRIB_DEPRECATED_MSVC2005;
intptr_t __cdecl spawnlpe(int,const char *_Filename,const char *_ArgList,...)
__MINGW_ATTRIB_DEPRECATED_MSVC2005;
-#ifndef _CRT_GETPID_DEFINED
-#define _CRT_GETPID_DEFINED /* Also in unistd.h */
- int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
-#endif
#ifdef __GNUC__
/* Those methods are predefined by gcc builtins to return int. So to prevent
stupid warnings, define them in POSIX way. This is save, because those
diff --git a/mingw-w64-headers/crt/unistd.h b/mingw-w64-headers/crt/unistd.h
index 05512c53..af59cb96 100644
--- a/mingw-w64-headers/crt/unistd.h
+++ b/mingw-w64-headers/crt/unistd.h
@@ -93,12 +93,12 @@ __CRT_INLINE int ftruncate(int __fd, _off_t __length)
void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes)
__MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
-#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
+#if defined(_CRT_USE_WINAPI_FAMILY_DESKTOP_APP) || defined(WINSTORECOMPAT)
#ifndef _CRT_GETPID_DEFINED
-#define _CRT_GETPID_DEFINED /* Also in process.h */
+#define _CRT_GETPID_DEFINED /* Also in process.h */
int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
-#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
+#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP || WINSTORECOMPAT */
#ifdef __cplusplus
}
diff --git a/mingw-w64-libraries/winstorecompat/Makefile.am
b/mingw-w64-libraries/winstorecompat/Makefile.am
index 028ac147..e25359f6 100644
--- a/mingw-w64-libraries/winstorecompat/Makefile.am
+++ b/mingw-w64-libraries/winstorecompat/Makefile.am
@@ -43,6 +43,7 @@ libwinstorecompat_a_SOURCES = \
src/RtlVirtualUnwind.c \
src/RtlRestoreContext.c \
src/GetUserName.c \
+ src/getpid.c \
$(NULL)
libwindowsappcompat_a_SOURCES = \
@@ -64,5 +65,6 @@ libwindowsappcompat_a_SOURCES = \
src/RtlVirtualUnwind.c \
src/RtlRestoreContext.c \
src/GetUserName.c \
+ src/getpid.c \
$(NULL)
libwindowsappcompat_a_CFLAGS = $(AM_CFLAGS) -D_WIN32_WINNT=_WIN32_WINNT_WIN10
diff --git a/mingw-w64-libraries/winstorecompat/src/getpid.c
b/mingw-w64-libraries/winstorecompat/src/getpid.c
new file mode 100644
index 00000000..f269c81d
--- /dev/null
+++ b/mingw-w64-libraries/winstorecompat/src/getpid.c
@@ -0,0 +1,41 @@
+/*
+ Copyright (c) 2020 mingw-w64 project
+
+ Contributing authors: Steve Lhomme
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#define getpid __getpid
+#include <windows.h>
+#include <process.h>
+#undef getpid
+
+int getpid( void );
+
+int getpid( void );
+{
+ return (int)GetCurrentProcessId();
+}
+
+#ifdef _X86_
+int (__cdecl *__MINGW_IMP_SYMBOL(getpid))(void) __asm__("__imp__getpid@0") =
getpid;
+#else
+int (__cdecl *__MINGW_IMP_SYMBOL(getpid))(void) __asm__("__imp_getpid") =
getpid;
+#endif
--
2.26.2
LGTM, I can push this later
// Martin
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public