Skip to contentSkip to conversation

dco-win: use proper calling convention on x86

PATCH Superseded Lev Stipakov 3 participants 4 messages Jan 31, 2023 – Feb 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dco-win: use proper calling convention on x86

From: Lev Stipakov <[email protected]...>

WinAPI uses __stdcall calling convention on x86. Wrong calling convention causes UB, which in this case breaks dco-win functionality.

---
 src/openvpn/dco_win.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/dco_win.c +1 -1
index 7594024c..da1e1fbc 100644
@@ -110,7 +110,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info
 {
     volatile int *signal_received = &sig_info->signal_received;
     /* GetOverlappedResultEx is available starting from Windows 8 */
-    typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
+    typedef BOOL (__stdcall *get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
     get_overlapped_result_ex_t get_overlapped_result_ex =
         (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"),
                                                    "GetOverlappedResultEx");
Signature · 1 line
2.38.1.windows.1
#1 lore raw
Quoted 16 lines · Lev Stipakov

From: Lev Stipakov <[email protected]...>

WinAPI uses __stdcall calling convention on x86. Wrong calling convention causes UB, which in this case breaks dco-win functionality.

---
  src/openvpn/dco_win.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/dco_win.c +0 -0
index 7594024c..da1e1fbc 100644

src/openvpn/dco_win.c dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info · line 113

Quoted 5 lines
src/openvpn/dco_win.c +1 -1
@@ -110,7 +110,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info
  {
      volatile int *signal_received = &sig_info->signal_received;
      /* GetOverlappedResultEx is available starting from Windows 8 */
-    typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
+    typedef BOOL (__stdcall *get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);

Wouldn't it be better to use the WINAPI Macro here, so it's the right calling convention no matter the arch?

Not sure what header it's defined in, but a quick search suggests it comes from minwindef.h.

Quoted 3 lines
src/openvpn/dco_win.c +0 -0
      get_overlapped_result_ex_t get_overlapped_result_ex =
          (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"),
                                                     "GetOverlappedResultEx");
#2 lore raw

PATCH v2 1/1 dco-win: use proper calling convention on x86

From: Lev Stipakov <[email protected]...>

WinAPI uses __stdcall calling convention on x86. Wrong calling convention causes UB, which in this case breaks dco-win functionality.

---
v2:
- use WINAPI instead of __stdcall
- replace another existing occurence of __stdcall with WINAPI
- uncrustify

 src/openvpn/dco_win.c | 2 +-
 src/openvpn/win32.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
src/openvpn/dco_win.c +1 -1
index 7594024c..0931fb30 100644
@@ -110,7 +110,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info
 {
     volatile int *signal_received = &sig_info->signal_received;
     /* GetOverlappedResultEx is available starting from Windows 8 */
-    typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
+    typedef BOOL (WINAPI *get_overlapped_result_ex_t)(HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
     get_overlapped_result_ex_t get_overlapped_result_ex =
         (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"),
                                                    "GetOverlappedResultEx");
src/openvpn/win32.c +1 -1
index 44176936..6d482ef8 100644
@@ -1352,7 +1352,7 @@ win32_get_arch(arch_t *process_arch, arch_t *host_arch)
     *process_arch = ARCH_UNKNOWN;
     *host_arch = ARCH_NATIVE;
 
-    typedef BOOL (__stdcall *is_wow64_process2_t)(HANDLE, USHORT *, USHORT *);
+    typedef BOOL (WINAPI *is_wow64_process2_t)(HANDLE, USHORT *, USHORT *);
     is_wow64_process2_t is_wow64_process2 = (is_wow64_process2_t)
                                             GetProcAddress(GetModuleHandle("Kernel32.dll"), "IsWow64Process2");
 
Signature · 1 line
2.38.1.windows.1
Acked-by on v2 1/1
#3 lore raw

I'm no windows expert, but googling says "this is what you do for windows function calls". MinGW compiles without complaints, as does GHA.

The GetOverlappedResultEx() can be cleaned up as soon as we drop Windows 7 support, not sure about the IsWow64Process2() thing.

Can we add windows/x64 tests to the GHA automated windows build/test thing? Or do we even have some, the errors just do not make it back?

Your patch has been applied to the master and release/2.6 branch.

commit b78360875cfe2f3ffc0d0aa0785ba3070b597da6 (master) commit 3c02417c95567dcbc3eafe25c28451fb39005f43 (release/2.6)

Author: Lev Stipakov
Date:   Tue Jan 31 14:54:48 2023 +0200
     dco-win: use proper calling convention on x86

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26113.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering