Skip to content

Commit a4510f8

Browse files
committed
Merge branch 'ma/windows-dynload-fix'
Fix calling dynamically loaded functions on Windows. * ma/windows-dynload-fix: lazyload: use correct calling conventions
2 parents cde28af + 4a9b204 commit a4510f8

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

compat/mingw.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "win32/lazyload.h"
99
#include "../config.h"
1010
#include "dir.h"
11+
#define SECURITY_WIN32
12+
#include <sspi.h>
1113

1214
#define HCAST(type, handle) ((type)(intptr_t)handle)
1315

@@ -1008,7 +1010,7 @@ size_t mingw_strftime(char *s, size_t max,
10081010
/* a pointer to the original strftime in case we can't find the UCRT version */
10091011
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
10101012
size_t ret;
1011-
DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,
1013+
DECLARE_PROC_ADDR(ucrtbase.dll, size_t, __cdecl, strftime, char *, size_t,
10121014
const char *, const struct tm *);
10131015

10141016
if (INIT_PROC_ADDR(strftime))
@@ -2185,7 +2187,7 @@ enum EXTENDED_NAME_FORMAT {
21852187

21862188
static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
21872189
{
2188-
DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,
2190+
DECLARE_PROC_ADDR(secur32.dll, BOOL, SEC_ENTRY, GetUserNameExW,
21892191
enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);
21902192
static wchar_t wbuffer[1024];
21912193
DWORD len;

compat/win32/lazyload.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
* A pair of macros to simplify loading of DLL functions. Example:
66
*
7-
* DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW,
7+
* DECLARE_PROC_ADDR(kernel32.dll, BOOL, WINAPI, CreateHardLinkW,
88
* LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
99
*
1010
* if (!INIT_PROC_ADDR(CreateHardLinkW))
@@ -25,10 +25,10 @@ struct proc_addr {
2525
};
2626

2727
/* Declares a function to be loaded dynamically from a DLL. */
28-
#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \
28+
#define DECLARE_PROC_ADDR(dll, rettype, convention, function, ...) \
2929
static struct proc_addr proc_addr_##function = \
3030
{ #dll, #function, NULL, 0 }; \
31-
typedef rettype (WINAPI *proc_type_##function)(__VA_ARGS__); \
31+
typedef rettype (convention *proc_type_##function)(__VA_ARGS__); \
3232
static proc_type_##function function
3333

3434
/*

compat/win32/trace2_win32_process_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ static void get_is_being_debugged(void)
143143
*/
144144
static void get_peak_memory_info(void)
145145
{
146-
DECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,
147-
PPROCESS_MEMORY_COUNTERS, DWORD);
146+
DECLARE_PROC_ADDR(psapi.dll, BOOL, WINAPI, GetProcessMemoryInfo,
147+
HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
148148

149149
if (INIT_PROC_ADDR(GetProcessMemoryInfo)) {
150150
PROCESS_MEMORY_COUNTERS pmc;

compat/winansi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ typedef struct _CONSOLE_FONT_INFOEX {
4545
static void warn_if_raster_font(void)
4646
{
4747
DWORD fontFamily = 0;
48-
DECLARE_PROC_ADDR(kernel32.dll, BOOL, GetCurrentConsoleFontEx,
49-
HANDLE, BOOL, PCONSOLE_FONT_INFOEX);
48+
DECLARE_PROC_ADDR(kernel32.dll, BOOL, WINAPI,
49+
GetCurrentConsoleFontEx, HANDLE, BOOL,
50+
PCONSOLE_FONT_INFOEX);
5051

5152
/* don't bother if output was ascii only */
5253
if (!non_ascii_used)

t/helper/test-drop-caches.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if defined(GIT_WINDOWS_NATIVE)
55
#include "lazyload.h"
6+
#include <winnt.h>
67

78
static int cmd_sync(void)
89
{
@@ -86,7 +87,8 @@ static int cmd_dropcaches(void)
8687
{
8788
HANDLE hProcess = GetCurrentProcess();
8889
HANDLE hToken;
89-
DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
90+
DECLARE_PROC_ADDR(ntdll.dll, DWORD, NTAPI, NtSetSystemInformation, INT, PVOID,
91+
ULONG);
9092
SYSTEM_MEMORY_LIST_COMMAND command;
9193
int status;
9294

0 commit comments

Comments
 (0)