| 1 |
From f85366b1044fff7b4ea9162c3edcd8278c3e06ff Mon Sep 17 00:00:00 2001 |
| 2 |
From: Alwin Esch <[email protected]> |
| 3 |
Date: Thu, 22 Aug 2019 19:30:12 +0100 |
| 4 |
Subject: [PATCH] [win10] fixed uwp build |
| 5 |
|
| 6 |
--- |
| 7 |
dlfcn.c | 43 ++++++++++++++++++++++++++++++++++++++----- |
| 8 |
1 file changed, 38 insertions(+), 5 deletions(-) |
| 9 |
|
| 10 |
diff --git a/dlfcn.c b/dlfcn.c |
| 11 |
index 69670d1..2d77ca8 100644 |
| 12 |
--- a/dlfcn.c |
| 13 |
+++ b/dlfcn.c |
| 14 |
@@ -19,6 +19,7 @@ |
| 15 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 |
*/ |
| 17 |
|
| 18 |
+#define _CRT_SECURE_NO_WARNINGS |
| 19 |
#ifdef _DEBUG |
| 20 |
#define _CRTDBG_MAP_ALLOC |
| 21 |
#include <stdlib.h> |
| 22 |
@@ -193,6 +194,7 @@ static void save_err_ptr_str( const void *ptr ) |
| 23 |
/* Load Psapi.dll at runtime, this avoids linking caveat */ |
| 24 |
static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded ) |
| 25 |
{ |
| 26 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) |
| 27 |
static BOOL (WINAPI *EnumProcessModulesPtr)(HANDLE, HMODULE *, DWORD, LPDWORD); |
| 28 |
HMODULE psapi; |
| 29 |
|
| 30 |
@@ -206,20 +208,26 @@ static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb, |
| 31 |
} |
| 32 |
|
| 33 |
return EnumProcessModulesPtr( hProcess, lphModule, cb, lpcbNeeded ); |
| 34 |
+#else |
| 35 |
+ return 0; |
| 36 |
+#endif |
| 37 |
} |
| 38 |
|
| 39 |
void *dlopen( const char *file, int mode ) |
| 40 |
{ |
| 41 |
- HMODULE hModule; |
| 42 |
- UINT uMode; |
| 43 |
+ HMODULE hModule = NULL; |
| 44 |
+ UINT uMode = 0; |
| 45 |
|
| 46 |
current_error = NULL; |
| 47 |
|
| 48 |
/* Do not let Windows display the critical-error-handler message box */ |
| 49 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) |
| 50 |
uMode = SetErrorMode( SEM_FAILCRITICALERRORS ); |
| 51 |
+#endif |
| 52 |
|
| 53 |
if( file == 0 ) |
| 54 |
{ |
| 55 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) // what is replacement of GMH on UWP? |
| 56 |
/* POSIX says that if the value of file is 0, a handle on a global |
| 57 |
* symbol object must be provided. That object must be able to access |
| 58 |
* all symbols from the original program file, and any objects loaded |
| 59 |
@@ -234,6 +242,7 @@ void *dlopen( const char *file, int mode ) |
| 60 |
|
| 61 |
if( !hModule ) |
| 62 |
save_err_ptr_str( file ); |
| 63 |
+#endif |
| 64 |
} |
| 65 |
else |
| 66 |
{ |
| 67 |
@@ -264,11 +273,29 @@ void *dlopen( const char *file, int mode ) |
| 68 |
* to UNIX's search paths (start with system folders instead of current |
| 69 |
* folder). |
| 70 |
*/ |
| 71 |
+#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) |
| 72 |
+ int result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, lpFileName, strlen(lpFileName), NULL, 0); |
| 73 |
+ if (result == 0) |
| 74 |
+ return NULL; |
| 75 |
+ |
| 76 |
+ wchar_t* newStr = (wchar_t*)malloc(result*sizeof(wchar_t)); |
| 77 |
+ result = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, lpFileName, strlen(lpFileName), newStr, result ); |
| 78 |
+ if (result == 0) |
| 79 |
+ { |
| 80 |
+ free( newStr ); |
| 81 |
+ return NULL; |
| 82 |
+ } |
| 83 |
+ |
| 84 |
+ hModule = LoadPackagedLibrary( newStr, 0 ); |
| 85 |
+ free( newStr ); |
| 86 |
+ dwProcModsAfter = 0; |
| 87 |
+#else // WINAPI_PARTITION_DESKTOP |
| 88 |
hModule = LoadLibraryExA(lpFileName, NULL, |
| 89 |
LOAD_WITH_ALTERED_SEARCH_PATH ); |
| 90 |
|
| 91 |
if( MyEnumProcessModules( hCurrentProc, NULL, 0, &dwProcModsAfter ) == 0 ) |
| 92 |
dwProcModsAfter = 0; |
| 93 |
+#endif |
| 94 |
|
| 95 |
/* If the object was loaded with RTLD_LOCAL, add it to list of local |
| 96 |
* objects, so that its symbols cannot be retrieved even if the handle for |
| 97 |
@@ -288,7 +315,9 @@ void *dlopen( const char *file, int mode ) |
| 98 |
} |
| 99 |
|
| 100 |
/* Return to previous state of the error-mode bit flags. */ |
| 101 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) |
| 102 |
SetErrorMode( uMode ); |
| 103 |
+#endif |
| 104 |
|
| 105 |
return (void *) hModule; |
| 106 |
} |
| 107 |
@@ -321,12 +350,14 @@ void *dlsym( void *handle, const char *name ) |
| 108 |
{ |
| 109 |
FARPROC symbol; |
| 110 |
HMODULE hCaller; |
| 111 |
- HMODULE hModule; |
| 112 |
- HANDLE hCurrentProc; |
| 113 |
+ HMODULE hModule = 0; |
| 114 |
+ HANDLE hCurrentProc = 0; |
| 115 |
|
| 116 |
current_error = NULL; |
| 117 |
symbol = NULL; |
| 118 |
hCaller = NULL; |
| 119 |
+ |
| 120 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) // what is replacement of GMH on UWP? |
| 121 |
hModule = GetModuleHandle( NULL ); |
| 122 |
hCurrentProc = GetCurrentProcess( ); |
| 123 |
|
| 124 |
@@ -358,6 +389,7 @@ void *dlsym( void *handle, const char *name ) |
| 125 |
if(!hCaller) |
| 126 |
goto end; |
| 127 |
} |
| 128 |
+#endif |
| 129 |
|
| 130 |
if( handle != RTLD_NEXT ) |
| 131 |
{ |
| 132 |
@@ -370,7 +402,7 @@ void *dlsym( void *handle, const char *name ) |
| 133 |
/* If the handle for the original program file is passed, also search |
| 134 |
* in all globally loaded objects. |
| 135 |
*/ |
| 136 |
- |
| 137 |
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) |
| 138 |
if( hModule == handle || handle == RTLD_NEXT ) |
| 139 |
{ |
| 140 |
HMODULE *modules; |
| 141 |
@@ -410,6 +442,7 @@ void *dlsym( void *handle, const char *name ) |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
+#endif |
| 146 |
|
| 147 |
end: |
| 148 |
if( symbol == NULL ) |
| 149 |
-- |
| 150 |
2.19.2.windows.1 |
| 151 |
|