ifeq ($(PLATFORM),windows)
CC := x86_64-w64-mingw32-clang
WINDRES := $(shell $(CC) $(CFLAGS) -print-prog-name=windres 2>/dev/null)
-CFLAGS += -Iwincompat/include -include wincompat/compat.h -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -flto
+CFLAGS += -Iwincompat/include -include wincompat/compat.h -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00 -flto
LDLIBS += -lws2_32 -lsetupapi -lole32 -ladvapi32 -lntdll -Lwincompat
LDFLAGS += -flto -Wl,--dynamicbase -Wl,--nxcompat -Wl,--tsaware -mconsole
-LDFLAGS += -Wl,--major-os-version=6 -Wl,--minor-os-version=1 -Wl,--major-subsystem-version=6 -Wl,--minor-subsystem-version=1
+LDFLAGS += -Wl,--major-os-version=10 -Wl,--minor-os-version=0 -Wl,--major-subsystem-version=10 -Wl,--minor-subsystem-version=0
# The use of -Wl,/delayload: here implies we're using llvm-mingw
LDFLAGS += -Wl,/delayload:ws2_32.dll -Wl,/delayload:setupapi.dll -Wl,/delayload:ole32.dll -Wl,/delayload:advapi32.dll
VERSION := $(patsubst "%",%,$(filter "%",$(file < version.h)))
-wg: wincompat/libc.o wincompat/init.o wincompat/loader.o wincompat/resources.o
+wg: wincompat/libc.o wincompat/init.o wincompat/load_config.o wincompat/loader.o wincompat/resources.o
wincompat/resources.o: wincompat/resources.rc wincompat/manifest.xml
$(WINDRES) -DVERSION_STR=$(VERSION) -O coff -c 65001 -i $< -o $@
endif
static bool have_cached_kernel_interfaces;
static struct hashtable cached_kernel_interfaces;
static const DEVPROPKEY devpkey_name = DEVPKEY_WG_NAME;
-extern bool is_win7;
static int kernel_get_wireguard_interfaces(struct string_list *list)
{
- HDEVINFO dev_info = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, is_win7 ? L"ROOT\\WIREGUARD" : L"SWD\\WireGuard", NULL, DIGCF_PRESENT, NULL, NULL, NULL);
+ HDEVINFO dev_info = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, L"SWD\\WireGuard", NULL, DIGCF_PRESENT, NULL, NULL, NULL);
bool will_have_cached_kernel_interfaces = true;
if (dev_info == INVALID_HANDLE_VALUE) {
}
}
- dev_info = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, is_win7 ? L"ROOT\\WIREGUARD" : L"SWD\\WireGuard", NULL, DIGCF_PRESENT, NULL, NULL, NULL);
+ dev_info = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, L"SWD\\WireGuard", NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (dev_info == INVALID_HANDLE_VALUE)
return NULL;
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4
#endif
-extern void NTAPI RtlGetNtVersionNumbers(DWORD *major, DWORD *minor, DWORD *build);
-bool is_win7 = false;
-
__attribute__((constructor)) static void init(void)
{
- char *colormode;
- DWORD console_mode, major, minor;
HANDLE stdout_handle;
+ DWORD console_mode;
WSADATA wsaData;
+ char *colormode;
if (!SetDllDirectoryA("") || !SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32))
abort();
- RtlGetNtVersionNumbers(&major, &minor, NULL);
- is_win7 = (major == 6 && minor <= 1) || major < 6;
-
WSAStartup(MAKEWORD(2, 2), &wsaData);
stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // We don't close this.
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015-2026 Jason A. Donenfeld. All Rights Reserved.
+ *
+ * This here is a bit of a hack. We're compiling with subsystem=10.0 in the PE
+ * header, and so the Windows loader expects to see either
+ * _load_config.SecurityCookie set to the initial magic value, or for
+ * IMAGE_GUARD_SECURITY_COOKIE_UNUSED to be set. libssp doesn't use
+ * SecurityCookie anyway; SecurityCookie is for MSVC's /GS protection. So it
+ * seems like the proper thing to do is signal to the OS that it doesn't need
+ * to initialize SecurityCookie.
+ */
+
+#include <windows.h>
+
+#define IMAGE_GUARD_SECURITY_COOKIE_UNUSED 0x00000800
+const IMAGE_LOAD_CONFIG_DIRECTORY _load_config_used = {
+ .Size = sizeof(_load_config_used),
+ .GuardFlags = IMAGE_GUARD_SECURITY_COOKIE_UNUSED
+};
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="wg" type="win32" />
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
- <!-- Windows 10 -->
+ <!-- Windows 10 and 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
- <!-- Windows 8.1 -->
- <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
- <!-- Windows 8 -->
- <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
- <!-- Windows 7 -->
- <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">