Skip to content

Commit 7188d15

Browse files
authored
Merge pull request #136 from garbear/update-dlfcn
Update dlfcn-win32 to v1.4.2
2 parents 27f0a6b + 80790b3 commit 7188d15

File tree

8 files changed

+166
-97
lines changed

8 files changed

+166
-97
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# dlfcn-win32 patches: keep exact bytes (prevents LF/CRLF munging)
2+
depends/windows/dlfcn-win32/*.patch -text
3+
depends/windowsstore/dlfcn-win32/*.patch -text

azure-pipelines.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ 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'
4041

4142
workspace:
4243
clean: all
@@ -53,12 +54,68 @@ jobs:
5354
echo $(app_id) . . > definition/$(app_id)/$(app_id).txt
5455
mklink /J "$(Pipeline.Workspace)/$(app_id)" "$(Build.SourcesDirectory)"
5556
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+
56109
- task: CMake@1
110+
env:
111+
PATHEXT: $(PATHEXT)
57112
inputs:
58113
workingDirectory: 'build'
59114
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'
60115

61116
- task: CMake@1
117+
env:
118+
PATHEXT: $(PATHEXT)
62119
inputs:
63120
workingDirectory: 'build'
64121
cmakeArgs: '--build . --config $(CONFIGURATION) --target $(app_id)'
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
diff --git a/dlfcn.c b/dlfcn.c
2-
index 69670d1..8d2dbc0 100644
3-
--- a/dlfcn.c
4-
+++ b/dlfcn.c
5-
@@ -264,8 +264,19 @@ void *dlopen( const char *file, int mode )
6-
* to UNIX's search paths (start with system folders instead of current
7-
* folder).
8-
*/
9-
- hModule = LoadLibraryExA(lpFileName, NULL,
10-
- LOAD_WITH_ALTERED_SEARCH_PATH );
11-
+ int wide_len = MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, 0, 0);
12-
+ if (wide_len > 0)
13-
+ {
14-
+ wchar_t* lpFileNameW = (wchar_t*)malloc(wide_len * sizeof(wchar_t));
15-
+ MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, lpFileNameW, wide_len);
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+
10+
diff --git a/src/dlfcn.c b/src/dlfcn.c
11+
index cb9f9bb..82e0c1e 100644
12+
--- a/src/dlfcn.c
13+
+++ b/src/dlfcn.c
14+
@@ -415,7 +415,19 @@ void *dlopen( const char *file, int mode )
15+
* to UNIX's search paths (start with system folders instead of current
16+
* folder).
17+
*/
18+
- hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
19+
+ int wide_len = MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, 0, 0);
20+
+ if (wide_len > 0)
21+
+ {
22+
+ wchar_t* lpFileNameW = (wchar_t*)malloc(wide_len * sizeof(wchar_t));
23+
+ MultiByteToWideChar(CP_UTF8, 0, lpFileName, -1, lpFileNameW, wide_len);
1624
+
17-
+ hModule = LoadLibraryExW(lpFileNameW, NULL,
18-
+ LOAD_WITH_ALTERED_SEARCH_PATH );
25+
+ hModule = LoadLibraryExW(lpFileNameW, NULL,
26+
+ LOAD_WITH_ALTERED_SEARCH_PATH );
1927
+
20-
+ free(lpFileNameW);
21-
+ }
22-
+ else
23-
+ hModule = 0;
28+
+ free(lpFileNameW);
29+
+ }
30+
+ else
31+
+ hModule = 0;
2432

25-
if( MyEnumProcessModules( hCurrentProc, NULL, 0, &dwProcModsAfter ) == 0 )
26-
dwProcModsAfter = 0;
33+
if( !hModule )
34+
{
35+
--
36+
2.52.0
37+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f18a412e84d8b701e61a78252411fe8c72587f52417c1ef21ca93604de1b9c55
1+
f61a874bc9163ab488accb364fd681d109870c86e8071f4710cbcdcbaf9f2565
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dlfcn-win32 https://github.com/dlfcn-win32/dlfcn-win32/archive/v1.2.0.tar.gz
1+
dlfcn-win32 https://github.com/dlfcn-win32/dlfcn-win32/archive/v1.4.2.tar.gz
Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,149 @@
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-
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
1+
From 4a4ba9ce9f666a66d027d84a26bb49bd6f92205a 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 | 43 ++++++++++++++++++++++++++++++++++++++-----
8+
1 file changed, 38 insertions(+), 5 deletions(-)
9+
10+
diff --git a/src/dlfcn.c b/src/dlfcn.c
11+
index cb9f9bb..74cac34 100644
12+
--- a/src/dlfcn.c
13+
+++ b/src/dlfcn.c
14+
@@ -24,6 +24,7 @@
15+
* THE SOFTWARE.
1616
*/
1717

1818
+#define _CRT_SECURE_NO_WARNINGS
1919
#ifdef _DEBUG
2020
#define _CRTDBG_MAP_ALLOC
2121
#include <stdlib.h>
22-
@@ -193,6 +194,7 @@ static void save_err_ptr_str( const void *ptr )
22+
@@ -311,6 +312,7 @@ static HMODULE MyGetModuleHandleFromAddress( const void *addr )
2323
/* Load Psapi.dll at runtime, this avoids linking caveat */
2424
static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded )
2525
{
2626
+#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,
27+
static BOOL (WINAPI *EnumProcessModulesPtr)(HANDLE, HMODULE *, DWORD, LPDWORD) = NULL;
28+
static BOOL failed = FALSE;
29+
UINT uMode;
30+
@@ -349,21 +351,27 @@ static BOOL MyEnumProcessModules( HANDLE hProcess, HMODULE *lphModule, DWORD cb,
3131
}
3232

3333
return EnumProcessModulesPtr( hProcess, lphModule, cb, lpcbNeeded );
3434
+#else
35-
+ return 0;
35+
+ return 0;
3636
+#endif
3737
}
3838

39+
DLFCN_EXPORT
3940
void *dlopen( const char *file, int mode )
4041
{
4142
- HMODULE hModule;
4243
- UINT uMode;
4344
+ HMODULE hModule = NULL;
4445
+ UINT uMode = 0;
4546

46-
current_error = NULL;
47+
error_occurred = FALSE;
4748

4849
/* Do not let Windows display the critical-error-handler message box */
4950
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
50-
uMode = SetErrorMode( SEM_FAILCRITICALERRORS );
51+
uMode = MySetErrorMode( SEM_FAILCRITICALERRORS );
5152
+#endif
5253

53-
if( file == 0 )
54+
if( file == NULL )
5455
{
5556
+#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+
/* POSIX says that if the value of file is NULL, a handle on a global
5758
* symbol object must be provided. That object must be able to access
5859
* all symbols from the original program file, and any objects loaded
59-
@@ -234,6 +242,7 @@ void *dlopen( const char *file, int mode )
60+
@@ -378,6 +386,7 @@ void *dlopen( const char *file, int mode )
6061

6162
if( !hModule )
62-
save_err_ptr_str( file );
63+
save_err_str( "(null)", GetLastError( ) );
6364
+#endif
6465
}
6566
else
6667
{
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-
*/
68+
@@ -415,8 +424,25 @@ void *dlopen( const char *file, int mode )
69+
* to UNIX's search paths (start with system folders instead of current
70+
* folder).
71+
*/
72+
- hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
7173
+#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-
+ }
74+
+ int result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, lpFileName, strlen(lpFileName), NULL, 0);
75+
+ if (result == 0)
76+
+ return NULL;
8377
+
84-
+ hModule = LoadPackagedLibrary( newStr, 0 );
85-
+ free( newStr );
86-
+ dwProcModsAfter = 0;
78+
+ wchar_t* newStr = (wchar_t*)malloc(result*sizeof(wchar_t));
79+
+ result = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, lpFileName, strlen(lpFileName), newStr, result );
80+
+ if (result == 0)
81+
+ {
82+
+ free( newStr );
83+
+ return NULL;
84+
+ }
85+
86+
+ hModule = LoadPackagedLibrary( newStr, 0 );
87+
+ free( newStr );
88+
+ dwProcModsAfter = 0;
8789
+#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;
90+
+ hModule = LoadLibraryExA( lpFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
9391
+#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 )
92+
if( !hModule )
93+
{
94+
save_err_str( lpFileName, GetLastError( ) );
95+
@@ -453,7 +479,9 @@ void *dlopen( const char *file, int mode )
9896
}
9997

10098
/* Return to previous state of the error-mode bit flags. */
10199
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
102-
SetErrorMode( uMode );
100+
MySetErrorMode( uMode );
103101
+#endif
104102

105103
return (void *) hModule;
106104
}
107-
@@ -321,12 +350,14 @@ void *dlsym( void *handle, const char *name )
105+
@@ -488,13 +516,15 @@ void *dlsym( void *handle, const char *name )
108106
{
109107
FARPROC symbol;
110108
HMODULE hCaller;
111109
- HMODULE hModule;
112-
- HANDLE hCurrentProc;
110+
- DWORD dwMessageId;
113111
+ HMODULE hModule = 0;
114-
+ HANDLE hCurrentProc = 0;
112+
+ DWORD dwMessageId = 0;
113+
114+
error_occurred = FALSE;
115115

116-
current_error = NULL;
117116
symbol = NULL;
118117
hCaller = NULL;
119118
+
120119
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP) // what is replacement of GMH on UWP?
121120
hModule = GetModuleHandle( NULL );
122-
hCurrentProc = GetCurrentProcess( );
121+
dwMessageId = 0;
123122

124-
@@ -358,6 +389,7 @@ void *dlsym( void *handle, const char *name )
125-
if(!hCaller)
123+
@@ -525,6 +555,7 @@ void *dlsym( void *handle, const char *name )
126124
goto end;
125+
}
127126
}
128127
+#endif
129128

130129
if( handle != RTLD_NEXT )
131130
{
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
131+
@@ -538,6 +569,7 @@ void *dlsym( void *handle, const char *name )
134132
* in all globally loaded objects.
135133
*/
136-
-
134+
137135
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)
138136
if( hModule == handle || handle == RTLD_NEXT )
139137
{
140-
HMODULE *modules;
141-
@@ -410,6 +442,7 @@ void *dlsym( void *handle, const char *name )
138+
HANDLE hCurrentProc;
139+
@@ -588,6 +620,7 @@ void *dlsym( void *handle, const char *name )
142140
}
143141
}
144142
}
145143
+#endif
146144

147145
end:
148146
if( symbol == NULL )
149-
--
150-
2.19.2.windows.1
151-
147+
--
148+
2.47.1.windows.1
149+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f18a412e84d8b701e61a78252411fe8c72587f52417c1ef21ca93604de1b9c55
1+
f61a874bc9163ab488accb364fd681d109870c86e8071f4710cbcdcbaf9f2565
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dlfcn-win32 https://github.com/dlfcn-win32/dlfcn-win32/archive/v1.2.0.tar.gz
1+
dlfcn-win32 https://github.com/dlfcn-win32/dlfcn-win32/archive/v1.4.2.tar.gz

0 commit comments

Comments
 (0)