Skip to content

Commit 4600b7b

Browse files
committed
Fix dlfcn-win32 build on UWP
1 parent d9679cb commit 4600b7b

File tree

3 files changed

+42
-128
lines changed

3 files changed

+42
-128
lines changed

azure-pipelines.yml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ jobs:
3737
ARCHITECTURE: x64
3838
CONFIGURATION: Release
3939
WINSTORE: -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0.22621.0"
40-
USE_PATCH_WRAPPER: 'true'
4140

4241
workspace:
4342
clean: all
@@ -54,68 +53,12 @@ jobs:
5453
echo $(app_id) . . > definition/$(app_id)/$(app_id).txt
5554
mklink /J "$(Pipeline.Workspace)/$(app_id)" "$(Build.SourcesDirectory)"
5655
57-
- powershell: |
58-
$patchDir = 'C:\Strawberry\c\bin'
59-
$patchExe = Join-Path $patchDir 'patch.exe'
60-
$realExe = Join-Path $patchDir 'patch-real.exe'
61-
$src = Join-Path $env:TEMP 'patch-wrapper.cs'
62-
$out = Join-Path $patchDir 'patch.exe'
63-
64-
if (-not (Test-Path $realExe)) {
65-
Rename-Item $patchExe 'patch-real.exe'
66-
}
67-
68-
@'
69-
using System;
70-
using System.Diagnostics;
71-
72-
class PatchWrapper
73-
{
74-
static int Main(string[] args)
75-
{
76-
var psi = new ProcessStartInfo();
77-
psi.FileName = @"C:\Strawberry\c\bin\patch-real.exe";
78-
psi.UseShellExecute = false;
79-
80-
var quoted = new string[args.Length];
81-
for (int i = 0; i < args.Length; i++)
82-
quoted[i] = "\"" + args[i].Replace("\"", "\\\"") + "\"";
83-
84-
bool useBinary = false;
85-
for (int i = 0; i < args.Length; i++)
86-
{
87-
if (args[i].IndexOf("dlfcn-win32", StringComparison.OrdinalIgnoreCase) >= 0)
88-
{
89-
useBinary = true;
90-
break;
91-
}
92-
}
93-
94-
psi.Arguments =
95-
(useBinary ? "--binary " : "") + string.Join(" ", quoted);
96-
97-
var p = Process.Start(psi);
98-
p.WaitForExit();
99-
return p.ExitCode;
100-
}
101-
}
102-
'@ | Set-Content $src -Encoding Ascii
103-
104-
& "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\csc.exe" `
105-
/nologo /target:exe /out:$out $src
106-
displayName: "Replace Strawberry patch.exe with --binary wrapper"
107-
condition: and(succeeded(), eq(variables['USE_PATCH_WRAPPER'], 'true'))
108-
10956
- task: CMake@1
110-
env:
111-
PATHEXT: $(PATHEXT)
11257
inputs:
11358
workingDirectory: 'build'
11459
cmakeArgs: '-T host=x64 -G "$(GENERATOR)" -A $(ARCHITECTURE) $(WINSTORE) -DADDONS_TO_BUILD=$(app_id) -DCMAKE_BUILD_TYPE=$(CONFIGURATION) -DADDONS_DEFINITION_DIR=$(Pipeline.Workspace)/$(app_id)/build/definition -DADDON_SRC_PREFIX=../.. -DCMAKE_INSTALL_PREFIX=../../kodi/addons -DPACKAGE_ZIP=1 ../../kodi/cmake/addons'
11560

11661
- task: CMake@1
117-
env:
118-
PATHEXT: $(PATHEXT)
11962
inputs:
12063
workingDirectory: 'build'
12164
cmakeArgs: '--build . --config $(CONFIGURATION) --target $(app_id)'
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
1-
From 262365e15599077a3a69da43078f1f5193aa3061 Mon Sep 17 00:00:00 2001
2-
From: Garrett Brown <themagnificentmrb@gmail.com>
3-
Date: Sun, 1 Mar 2026 00:15:29 -0800
4-
Subject: [PATCH] dlopen with widechar
5-
6-
---
7-
src/dlfcn.c | 14 +++++++++++++-
8-
1 file changed, 13 insertions(+), 1 deletion(-)
9-
101
diff --git a/src/dlfcn.c b/src/dlfcn.c
11-
index cb9f9bb..82e0c1e 100644
2+
index cb9f9bb..1b8808c 100644
123
--- a/src/dlfcn.c
134
+++ b/src/dlfcn.c
14-
@@ -415,7 +415,19 @@ void *dlopen( const char *file, int mode )
5+
@@ -415,7 +415,17 @@ void *dlopen( const char *file, int mode )
156
* to UNIX's search paths (start with system folders instead of current
167
* folder).
178
*/
189
- hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
1910
+ int wide_len = MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, 0, 0);
2011
+ if (wide_len > 0)
2112
+ {
22-
+ wchar_t* lpFileNameW = (wchar_t*)malloc(wide_len * sizeof(wchar_t));
23-
+ MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, lpFileNameW, wide_len);
13+
+ wchar_t* lpFileNameW = (wchar_t*)malloc(wide_len * sizeof(wchar_t));
14+
+ MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, lpFileNameW, wide_len);
2415
+
25-
+ hModule = LoadLibraryExW(lpFileNameW, NULL,
26-
+ LOAD_WITH_ALTERED_SEARCH_PATH );
27-
+
28-
+ free(lpFileNameW);
16+
+ hModule = LoadLibraryExW(lpFileNameW, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
17+
+ free(lpFileNameW);
2918
+ }
3019
+ else
31-
+ hModule = 0;
20+
+ hModule = 0;
3221

3322
if( !hModule )
3423
{
35-
--
36-
2.52.0
37-
Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
From 6944869021af1f4f5585d7e54aaf0e8d971d0afd Mon Sep 17 00:00:00 2001
2-
From: Alwin Esch <alwin.esch@web.de>
3-
Date: Thu, 22 Aug 2019 19:30:12 +0100
4-
Subject: [PATCH] [win10] fixed uwp build
5-
6-
---
7-
src/dlfcn.c | 47 +++++++++++++++++++++++++++++++++++++++++------
8-
1 file changed, 41 insertions(+), 6 deletions(-)
9-
10-
diff --git a/src/dlfcn.c b/src/dlfcn.c
11-
index cb9f9bb..ce43ae7 100644
12-
--- a/src/dlfcn.c
13-
+++ b/src/dlfcn.c
14-
@@ -24,6 +24,7 @@
1+
From f85366b1044fff7b4ea9162c3edcd8278c3e06ff Mon Sep 17 00:00:00 2001
2+
From: Alwin Esch <alwin.esch@web.de>
3+
Date: Thu, 22 Aug 2019 19:30:12 +0100
4+
Subject: [PATCH] [win10] fixed uwp build
5+
6+
---
7+
8+
diff --git a/src/dlfcn.c b/src/dlfcn.c
9+
index cb9f9bb..b26b404 100644
10+
--- a/src/dlfcn.c
11+
+++ b/src/dlfcn.c
12+
@@ -24,6 +24,7 @@
1513
* THE SOFTWARE.
1614
*/
1715

1816
+#define _CRT_SECURE_NO_WARNINGS
1917
#ifdef _DEBUG
2018
#define _CRTDBG_MAP_ALLOC
2119
#include <stdlib.h>
22-
@@ -311,6 +312,7 @@ static HMODULE MyGetModuleHandleFromAddress( const void *addr )
20+
@@ -311,6 +312,7 @@ static HMODULE MyGetModuleHandleFromAddress( const void *addr )
2321
/* Load Psapi.dll at runtime, this avoids linking caveat */
2422
static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded )
2523
{
2624
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
2725
static BOOL (WINAPI *EnumProcessModulesPtr)(HANDLE, HMODULE *, DWORD, LPDWORD) = NULL;
2826
static BOOL failed = FALSE;
2927
UINT uMode;
30-
@@ -349,21 +351,27 @@ static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb,
28+
@@ -349,21 +351,27 @@ static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb,
3129
}
3230

3331
return EnumProcessModulesPtr( hProcess, lphModule, cb, lpcbNeeded );
@@ -57,19 +55,18 @@ index cb9f9bb..ce43ae7 100644
5755
/* POSIX says that if the value of file is NULL, a handle on a global
5856
* symbol object must be provided. That object must be able to access
5957
* all symbols from the original program file, and any objects loaded
60-
@@ -378,6 +386,7 @@ void *dlopen( const char *file, int mode )
58+
@@ -378,6 +386,7 @@ void *dlopen( const char *file, int mode )
6159

6260
if( !hModule )
6361
save_err_str( "(null)", GetLastError( ) );
6462
+#endif
6563
}
6664
else
6765
{
68-
@@ -415,16 +424,35 @@ void *dlopen( const char *file, int mode )
66+
@@ -415,6 +424,23 @@ void *dlopen( const char *file, int mode )
6967
* to UNIX's search paths (start with system folders instead of current
7068
* folder).
7169
*/
72-
- hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
7370
+#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
7471
+ int result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, lpFileName, strlen(lpFileName), NULL, 0);
7572
+ if (result == 0)
@@ -82,27 +79,20 @@ index cb9f9bb..ce43ae7 100644
8279
+ free( newStr );
8380
+ return NULL;
8481
+ }
85-
82+
+
8683
+ hModule = LoadPackagedLibrary( newStr, 0 );
8784
+ free( newStr );
8885
+ dwProcModsAfter = 0;
8986
+#else // WINAPI_PARTITION_DESKTOP
90-
+ hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
91-
+#endif
87+
hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
88+
9289
if( !hModule )
93-
{
94-
save_err_str( lpFileName, GetLastError( ) );
90+
@@ -449,11 +475,14 @@ void *dlopen( const char *file, int mode )
91+
local_rem( hModule );
92+
}
9593
}
96-
else
97-
{
98-
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
99-
if( MyEnumProcessModules( hCurrentProc, NULL, 0, &dwProcModsAfter ) == 0 )
100-
dwProcModsAfter = 0;
10194
+#endif
102-
103-
/* If the object was loaded with RTLD_LOCAL, add it to list of local
104-
* objects, so that its symbols cannot be retrieved even if the handle for
105-
@@ -453,7 +481,9 @@ void *dlopen( const char *file, int mode )
95+
}
10696
}
10797

10898
/* Return to previous state of the error-mode bit flags. */
@@ -112,52 +102,47 @@ index cb9f9bb..ce43ae7 100644
112102

113103
return (void *) hModule;
114104
}
115-
@@ -488,13 +518,15 @@ void *dlsym( void *handle, const char *name )
105+
@@ -488,15 +517,16 @@ void *dlsym( void *handle, const char *name )
116106
{
117107
FARPROC symbol;
118108
HMODULE hCaller;
119109
- HMODULE hModule;
120-
- DWORD dwMessageId;
121110
+ HMODULE hModule = 0;
122-
+ DWORD dwMessageId = 0;
111+
DWORD dwMessageId;
123112

124113
error_occurred = FALSE;
125114

126115
symbol = NULL;
116+
+ dwMessageId = 0;
127117
hCaller = NULL;
128-
+
129118
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) // what is replacement of GMH on UWP?
130119
hModule = GetModuleHandle( NULL );
131-
dwMessageId = 0;
120+
- dwMessageId = 0;
132121

133-
@@ -525,6 +557,7 @@ void *dlsym( void *handle, const char *name )
122+
if( handle == RTLD_DEFAULT )
123+
{
124+
@@ -525,6 +555,7 @@ void *dlsym( void *handle, const char *name )
134125
goto end;
135126
}
136127
}
137128
+#endif
138129

139130
if( handle != RTLD_NEXT )
140131
{
141-
@@ -538,9 +571,10 @@ void *dlsym( void *handle, const char *name )
132+
@@ -537,7 +568,7 @@ void *dlsym( void *handle, const char *name )
133+
/* If the handle for the original program file is passed, also search
142134
* in all globally loaded objects.
143135
*/
144-
136+
-
145137
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
146138
if( hModule == handle || handle == RTLD_NEXT )
147139
{
148-
- HANDLE hCurrentProc;
149-
+ HANDLE hCurrentProc = 0;
150-
HMODULE *modules;
151-
DWORD cbNeeded;
152-
DWORD dwSize;
153-
@@ -588,6 +622,7 @@ void *dlsym( void *handle, const char *name )
140+
HANDLE hCurrentProc;
141+
@@ -588,6 +619,7 @@ void *dlsym( void *handle, const char *name )
154142
}
155143
}
156144
}
157145
+#endif
158146

159147
end:
160148
if( symbol == NULL )
161-
--
162-
2.53.0
163-

0 commit comments

Comments
 (0)