Commit 1eaf29ef6c for openssl.org
commit 1eaf29ef6c49ff5c98430c143acf79b7e4d3630e
Author: Tomas Mraz <tomas@openssl.foundation>
Date: Thu Jun 18 15:51:58 2026 +0200
Remove direct includes of windows.h where possible
It should be included via e_os.h instead.
Reviewed-by: Milan Broz <mbroz@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
MergeDate: Sat Jun 20 11:00:42 2026
(Merged from https://github.com/openssl/openssl/pull/31587)
diff --git a/crypto/LPdir_win.c b/crypto/LPdir_win.c
index bc5cec35d9..e8141cab86 100644
--- a/crypto/LPdir_win.c
+++ b/crypto/LPdir_win.c
@@ -36,8 +36,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <windows.h>
#include <tchar.h>
+#include "internal/e_os.h"
#include "internal/numbers.h"
#ifndef LPDIR_H
#include "LPdir.h"
diff --git a/crypto/armcap.c b/crypto/armcap.c
index cdb8336b13..bd978dc86d 100644
--- a/crypto/armcap.c
+++ b/crypto/armcap.c
@@ -19,7 +19,7 @@
#endif
#include "internal/cryptlib.h"
#ifdef _WIN32
-#include <windows.h>
+#include "internal/e_os.h"
#else
#include <unistd.h>
#endif
diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c
index 849da5c3c4..2ca4ed6a93 100644
--- a/crypto/async/arch/async_win.c
+++ b/crypto/async/arch/async_win.c
@@ -12,7 +12,7 @@
#ifdef ASYNC_WIN
-#include <windows.h>
+#include "internal/e_os.h"
#include "internal/cryptlib.h"
int ASYNC_is_capable(void)
diff --git a/crypto/async/async_local.h b/crypto/async/async_local.h
index e1d1113464..f10a6745f8 100644
--- a/crypto/async/async_local.h
+++ b/crypto/async/async_local.h
@@ -21,6 +21,7 @@
#include <openssl/crypto.h>
#include <openssl/e_os2.h>
+#include <internal/e_os.h>
typedef struct async_ctx_st async_ctx;
typedef struct async_pool_st async_pool;
@@ -29,7 +30,6 @@ typedef struct async_pool_st async_pool;
#define ASYNC_WIN
#define ASYNC_ARCH
-#include <windows.h>
#include "internal/cryptlib.h"
typedef struct async_fibre_st {
diff --git a/crypto/comp/c_brotli.c b/crypto/comp/c_brotli.c
index d262ec6a4e..9c99e066b7 100644
--- a/crypto/comp/c_brotli.c
+++ b/crypto/comp/c_brotli.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <openssl/objects.h>
+#include "internal/e_os.h"
#include "internal/comp.h"
#include <openssl/err.h>
#include "crypto/cryptlib.h"
@@ -46,10 +47,6 @@ static void brotli_free(void *opaque, void *address)
* work. Therefore, all BROTLI routines are loaded at run time
* and we do not link to a .LIB file when BROTLI_SHARED is set.
*/
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-#include <windows.h>
-#endif
-
#ifdef BROTLI_SHARED
#include "internal/dso.h"
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c
index c90c7b090d..4af4e30b64 100644
--- a/crypto/comp/c_zlib.c
+++ b/crypto/comp/c_zlib.c
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <openssl/objects.h>
+#include "internal/e_os.h"
#include "internal/comp.h"
#include <openssl/err.h>
#include "crypto/cryptlib.h"
@@ -64,10 +65,6 @@ static COMP_METHOD zlib_stateful_method = {
* work. Therefore, all ZLIB routines are loaded at run time
* and we do not link to a .LIB file when ZLIB_SHARED is set.
*/
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-#include <windows.h>
-#endif /* !(OPENSSL_SYS_WINDOWS || \
- * OPENSSL_SYS_WIN32) */
#ifdef ZLIB_SHARED
#include "internal/dso.h"
diff --git a/crypto/comp/c_zstd.c b/crypto/comp/c_zstd.c
index a9c881f8f9..c5c6cd6eef 100644
--- a/crypto/comp/c_zstd.c
+++ b/crypto/comp/c_zstd.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <string.h>
#include <openssl/objects.h>
+#include "internal/e_os.h"
#include "internal/comp.h"
#include <openssl/err.h>
#include "crypto/cryptlib.h"
@@ -62,16 +63,6 @@ static ZSTD_customMem zstd_mem_funcs = {
};
#endif
-/*
- * When OpenSSL is built on Windows, we do not want to require that
- * the LIBZSTD.DLL be available in order for the OpenSSL DLLs to
- * work. Therefore, all ZSTD routines are loaded at run time
- * and we do not link to a .LIB file when ZSTD_SHARED is set.
- */
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-#include <windows.h>
-#endif
-
#ifdef ZSTD_SHARED
#include "internal/dso.h"
diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c
index 3c5de4de8f..a727d2008d 100644
--- a/crypto/mem_sec.c
+++ b/crypto/mem_sec.c
@@ -23,7 +23,6 @@
#ifndef OPENSSL_NO_SECURE_MEMORY
#if defined(_WIN32)
-#include <windows.h>
#if defined(WINAPI_FAMILY_PARTITION)
#if !defined(WINAPI_PARTITION_SYSTEM)
#define WINAPI_PARTITION_SYSTEM 0
diff --git a/crypto/rand/rand_deprecated.c b/crypto/rand/rand_deprecated.c
index d838f3cd70..07b6ff04e8 100644
--- a/crypto/rand/rand_deprecated.c
+++ b/crypto/rand/rand_deprecated.c
@@ -12,7 +12,6 @@
#include <openssl/rand.h>
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-#include <windows.h>
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
#define DEPRECATED_RAND_FUNCTIONS_DEFINED
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c
index ab059bb5e8..b1881dac97 100644
--- a/crypto/rand/randfile.c
+++ b/crypto/rand/randfile.c
@@ -36,7 +36,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#if defined(_WIN32) && !defined(_WIN32_WCE)
-#include <windows.h>
#include <io.h>
#define stat _stat
#define chmod _chmod
diff --git a/crypto/sleep.c b/crypto/sleep.c
index 9273995be6..3d8be852c9 100644
--- a/crypto/sleep.c
+++ b/crypto/sleep.c
@@ -67,7 +67,6 @@ static void ossl_sleep_millis(uint64_t millis)
#endif
#elif defined(_WIN32) && !defined(OPENSSL_SYS_UEFI)
-#include <windows.h>
static void ossl_sleep_millis(uint64_t millis)
{
diff --git a/crypto/thread/arch/thread_win.c b/crypto/thread/arch/thread_win.c
index b26a1d917a..1026ed3de3 100644
--- a/crypto/thread/arch/thread_win.c
+++ b/crypto/thread/arch/thread_win.c
@@ -7,11 +7,11 @@
* https://www.openssl.org/source/license.html
*/
-#include <internal/thread_arch.h>
+#include "internal/thread_arch.h"
+#include "internal/e_os.h"
#if defined(OPENSSL_THREADS_WINNT)
#include <process.h>
-#include <windows.h>
static unsigned __stdcall thread_start_thunk(LPVOID vthread)
{
diff --git a/crypto/threads_win.c b/crypto/threads_win.c
index 4fedf24e90..448c909630 100644
--- a/crypto/threads_win.c
+++ b/crypto/threads_win.c
@@ -7,14 +7,13 @@
* https://www.openssl.org/source/license.html
*/
-#if defined(_WIN32)
-#include <windows.h>
+#include "internal/e_os.h"
+
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
#define USE_RWLOCK
#endif
-#endif
-#include <assert.h>
+#include <assert.h>
#include <openssl/crypto.h>
#include <crypto/cryptlib.h>
#include "internal/common.h"
diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c
index 1da5369287..8715ff068e 100644
--- a/crypto/ui/ui_openssl.c
+++ b/crypto/ui/ui_openssl.c
@@ -60,7 +60,6 @@
#endif
#ifdef WIN_CONSOLE_BUG
-#include <windows.h>
#ifndef OPENSSL_SYS_WINCE
#include <wincon.h>
#endif
diff --git a/include/internal/thread_arch.h b/include/internal/thread_arch.h
index d7fc08a8af..73e6e0d1e7 100644
--- a/include/internal/thread_arch.h
+++ b/include/internal/thread_arch.h
@@ -11,12 +11,9 @@
#define OSSL_INTERNAL_THREAD_ARCH_H
#include <openssl/configuration.h>
#include <openssl/e_os2.h>
+#include "internal/e_os.h"
#include "internal/time.h"
-#if defined(_WIN32)
-#include <windows.h>
-#endif
-
#if defined(OPENSSL_THREADS) && defined(OPENSSL_SYS_UNIX)
#define OPENSSL_THREADS_POSIX
#elif defined(OPENSSL_THREADS) && defined(OPENSSL_SYS_VMS)
diff --git a/providers/implementations/rands/seeding/rand_win.c b/providers/implementations/rands/seeding/rand_win.c
index 63b523b729..9b889e38bc 100644
--- a/providers/implementations/rands/seeding/rand_win.c
+++ b/providers/implementations/rands/seeding/rand_win.c
@@ -7,6 +7,7 @@
* https://www.openssl.org/source/license.html
*/
+#include "internal/e_os.h" /* For windows.h */
#include "internal/cryptlib.h"
#include <openssl/rand.h>
#include "crypto/rand_pool.h"
@@ -19,7 +20,6 @@
#error "Unsupported seeding method configured; must be os"
#endif
-#include <windows.h>
/* On Windows Vista or higher use BCrypt instead of the legacy CryptoAPI */
#if defined(_MSC_VER) && _MSC_VER > 1500 /* 1500 = Visual Studio 2008 */ \
&& defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600