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 bc5cec3..e8141ca 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 cdb8336..bd978dc 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 849da5c..2ca4ed6 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 e1d1113..f10a674 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 @@ #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 d262ec6..9c99e06 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 @@ * 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 c90c7b0..4af4e30 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 @@ * 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 a9c881f..c5c6cd6 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 @@ }; #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 3c5de4d..a727d20 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 d838f3c..07b6ff0 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 ab059bb..b1881da 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 9273995..3d8be85 100644 --- a/crypto/sleep.c +++ b/crypto/sleep.c
@@ -67,7 +67,6 @@ #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 b26a1d9..1026ed3 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 4fedf24..448c909 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 1da5369..8715ff0 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 d7fc08a..73e6e0d 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 63b523b..9b889e3 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