From b277c8ee982648a58118b5941664ed80557efe67 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Tue, 7 Oct 2025 16:48:58 +0200 Subject: [PATCH] Core: CPU_Cores refactored to support >64, Ignoring leaks in new OpenSSL, Stream::Put(const char *s) now allows and ignores nullptr --- uppbox/Scripts/updateinfo.txt | 39 ++++++++++++++++++++++++++++++----- uppsrc/Core/Cpu.cpp | 16 ++++---------- uppsrc/Core/SSL/InitExit.cpp | 2 ++ uppsrc/Core/SSL/SSL.h | 4 ++-- uppsrc/Core/SSL/Socket.cpp | 15 ++++++++++++++ uppsrc/Core/Stream.cpp | 4 +++- upptst/Https/Https.cpp | 2 +- 7 files changed, 61 insertions(+), 21 deletions(-) diff --git a/uppbox/Scripts/updateinfo.txt b/uppbox/Scripts/updateinfo.txt index bc42a1d23..e55ca6432 100644 --- a/uppbox/Scripts/updateinfo.txt +++ b/uppbox/Scripts/updateinfo.txt @@ -23,9 +23,17 @@ delete aarch and arm7 folders and .exe from bin 2024-05-12 CLANG-18 +/* BUILDING start MSYS2 MINGW64 $ pacman -S --needed git wget mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja mingw-w64-x86_64-cmake make mingw-w64-x86_64-python3 autoconf libtool +*/ + +After updating CLANG, make sure libclang.dll is the same or later version, download here: + +https://github.com/llvm/llvm-project/releases + +(check with theide about) ------------------------------------------------------------------ @@ -33,16 +41,22 @@ OpenSSL ==== Building openssl for win32 clang/mingw: +cxl is a placeholder for actual user + Install msys2 into c:/msys64, user cxl Install pacman -S perl - + pacman -S mc Start msys2 mingw 64 ~ is C:\msys64\home\cxl Copy current clang to ~ -download openssl, unpack to ~ +download openssl + +https://github.com/openssl/openssl/releases, + +unpack to ~ edit .bashrc, add @@ -55,6 +69,8 @@ in openssl dir ./config CC=clang CXX=clang++ make +(errors are fine as long as libcrypto.a and libssl.a are created) + copy ./include/openssl to C:\upp\bin\clang\include copy ./libcrypto.a and ./libssl.a to C:\upp\bin\clang\x86_64-w64-mingw32\lib @@ -63,7 +79,18 @@ test upptst/Https with CLANGx64, release, debug close msys2 ---- -start msys2 mingw 32 +start c:/msys2/mingw32.exe + +(if missing: + +pacman -Syu + +# Reopen MSYS2 terminal and run the following command +pacman -Syu +pacman -S --needed base-devel mingw-w64-i686-toolchain +pacman -S pkgconf + +) check that i686-w64-mingw32-clang works cd openssl... @@ -76,12 +103,14 @@ test upptst/Https with CLANG, release, debug ==== MSC static versions -netasm, strawberry perl +nasm, strawberry perl -make sure Scripts folder is on windows path +make sure Scripts folder is on windows path (needs restart) from perl prompt run +check echo %PATH% + vc32.bat unpack openssl into new dir (it seems there is a problem reusing it in mingw64) diff --git a/uppsrc/Core/Cpu.cpp b/uppsrc/Core/Cpu.cpp index 4db93b2bd..48faf53f2 100644 --- a/uppsrc/Core/Cpu.cpp +++ b/uppsrc/Core/Cpu.cpp @@ -89,17 +89,9 @@ int CPU_Cores() static int n; ONCELOCK { #ifdef PLATFORM_WIN32 -#ifdef CPU_64 - uint64 pa, sa; - GetProcessAffinityMask(GetCurrentProcess(), &pa, &sa); - for(int i = 0; i < 64; i++) - n += !!(sa & ((uint64)1 << i)); -#else - DWORD pa, sa; - GetProcessAffinityMask(GetCurrentProcess(), &pa, &sa); - for(int i = 0; i < 32; i++) - n += !!(sa & (1 << i)); -#endif + SYSTEM_INFO info; + GetSystemInfo(&info); + n = info.dwNumberOfProcessors; #elif defined(PLATFORM_POSIX) #ifdef PLATFORM_BSD int mib[2]; @@ -111,7 +103,7 @@ int CPU_Cores() #elif defined(PLATFORM_SOLARIS) n = minmax((int)sysconf(_SC_NPROCESSORS_ONLN), 1, 256); #else - n = minmax(get_nprocs(), 1, 256); + n = get_nprocs(); #endif #else n = 1; diff --git a/uppsrc/Core/SSL/InitExit.cpp b/uppsrc/Core/SSL/InitExit.cpp index a384eb89a..19911f950 100644 --- a/uppsrc/Core/SSL/InitExit.cpp +++ b/uppsrc/Core/SSL/InitExit.cpp @@ -131,11 +131,13 @@ static void sslExitThread() void SslInitThread() { + DLOG("+++ SslInitThread"); MemoryIgnoreLeaksBlock __; if(sThreadInit || Thread::IsMain()) return; sThreadInit = true; sPrevExit = Thread::AtExit(sslExitThread); + DLOG("--- SslInitThread"); } } diff --git a/uppsrc/Core/SSL/SSL.h b/uppsrc/Core/SSL/SSL.h index 22edb0da6..1c14a4478 100644 --- a/uppsrc/Core/SSL/SSL.h +++ b/uppsrc/Core/SSL/SSL.h @@ -124,8 +124,8 @@ public: bool IsEmpty() const { return !ssl_ctx; } bool Set(SSL_CTX *c) { Clear(); return !!(ssl_ctx = c); } - bool Create(SSL_METHOD *meth) { return Set(SSL_CTX_new(meth)); } - void Clear() { if(ssl_ctx) { SSL_CTX_free(ssl_ctx); ssl_ctx = NULL; } } + bool Create(SSL_METHOD *meth); + void Clear(); SSL_CTX *Detach() { SSL_CTX *c = ssl_ctx; ssl_ctx = NULL; return c; } operator SSL_CTX * () const { return ssl_ctx; } diff --git a/uppsrc/Core/SSL/Socket.cpp b/uppsrc/Core/SSL/Socket.cpp index bb1ae918f..ea4fed685 100644 --- a/uppsrc/Core/SSL/Socket.cpp +++ b/uppsrc/Core/SSL/Socket.cpp @@ -108,6 +108,20 @@ bool TcpSocket::SSLImp::IsAgain(int res) const res == SSL_ERROR_WANT_ACCEPT; } +bool SslContext::Create(SSL_METHOD *meth) +{ + MemoryIgnoreLeaksBlock __; // as of OpenSSL 3.6.0, SSL_CTX_new has harmless leaks + return Set(SSL_CTX_new(meth)); +} + +void SslContext::Clear() +{ + if(ssl_ctx) { + SSL_CTX_free(ssl_ctx); + ssl_ctx = NULL; + } +} + bool TcpSocket::SSLImp::Start() { LLOG("SSL Start"); @@ -126,6 +140,7 @@ bool TcpSocket::SSLImp::Start() SetSSLError("Start: SSL context."); return false; } + if(socket.cert.GetCount()) context.UseCertificate(socket.cert, socket.pkey, socket.asn1); if(!(ssl = SSL_new(context))) { diff --git a/uppsrc/Core/Stream.cpp b/uppsrc/Core/Stream.cpp index adaf742d2..5a4dd8e67 100644 --- a/uppsrc/Core/Stream.cpp +++ b/uppsrc/Core/Stream.cpp @@ -324,7 +324,9 @@ void Stream::PutUtf8(int c) void Stream::Put(const char *s) { - while(*s) Put(*s++); + if(s) + while(*s) + Put(*s++); } void Stream::Put(int c, int count) { diff --git a/upptst/Https/Https.cpp b/upptst/Https/Https.cpp index 888f3f78a..570335cd8 100644 --- a/upptst/Https/Https.cpp +++ b/upptst/Https/Https.cpp @@ -4,7 +4,7 @@ using namespace Upp; CONSOLE_APP_MAIN { - StdLogSetup(LOG_COUT|LOG_FILE); +// StdLogSetup(LOG_COUT|LOG_FILE); HttpRequest::Trace(); RLOG(HttpRequest("https://www.ultimatepp.org").Execute());