From 5a4d0b7a4d3ff30521d04594139786c35846a63a Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sun, 8 Oct 2023 07:31:07 +0300 Subject: [PATCH 1/2] fix undefined behaviours and jpeg crash on non-windows platforms --- common/imageutils.cpp | 5 ++++- filesystem/basefilesystem.cpp | 2 +- vgui2/vgui_controls/FileOpenDialog.cpp | 3 +++ wscript | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/imageutils.cpp b/common/imageutils.cpp index 7c690aefe..5bb0b7415 100644 --- a/common/imageutils.cpp +++ b/common/imageutils.cpp @@ -65,9 +65,12 @@ extern void longjmp( jmp_buf, int ) __attribute__((noreturn)); #define JPEGLIB_USE_STDIO #if ANDROID #include "android/jpeglib/jpeglib.h" -#else +#elif defined WIN32 #include "jpeglib/jpeglib.h" +#else +#include #endif + #undef JPEGLIB_USE_STDIO diff --git a/filesystem/basefilesystem.cpp b/filesystem/basefilesystem.cpp index 26bb8372a..aad384349 100644 --- a/filesystem/basefilesystem.cpp +++ b/filesystem/basefilesystem.cpp @@ -4203,7 +4203,7 @@ bool CBaseFileSystem::FindNextFileInVPKOrPakHelper( FindData_t *pFindData ) { V_strncpy( pFindData->findData.cFileName, V_UnqualifiedFileName( pFindData->m_fileMatchesFromVPKOrPak[0] ), sizeof( pFindData->findData.cFileName ) ); pFindData->findData.dwFileAttributes = 0; - delete pFindData->m_fileMatchesFromVPKOrPak.Head(); + delete[] pFindData->m_fileMatchesFromVPKOrPak.Head(); pFindData->m_fileMatchesFromVPKOrPak.RemoveMultipleFromHead( 1 ); return true; diff --git a/vgui2/vgui_controls/FileOpenDialog.cpp b/vgui2/vgui_controls/FileOpenDialog.cpp index d4a098fcb..aa481da0d 100644 --- a/vgui2/vgui_controls/FileOpenDialog.cpp +++ b/vgui2/vgui_controls/FileOpenDialog.cpp @@ -1500,6 +1500,9 @@ void FileOpenDialog::OnOpen() char pFileName[MAX_PATH]; GetSelectedFileName( pFileName, sizeof( pFileName ) ); + if( !pFileName[0] ) + return; + int nLen = Q_strlen( pFileName ); bool bSpecifiedDirectory = ( pFileName[nLen-1] == '/' || pFileName[nLen-1] == '\\' ) && (!IsOSX() || ( IsOSX() && !Q_stristr( pFileName, ".app" ) ) ); Q_StripTrailingSlash( pFileName ); diff --git a/wscript b/wscript index 9910b29a4..7f760500b 100644 --- a/wscript +++ b/wscript @@ -239,9 +239,9 @@ def define_platform(conf): '_DLL_EXT=.so' ]) -# if conf.env.DEST_OS != 'win32': + if conf.env.DEST_OS != 'win32': + conf.define('NO_MEMOVERRIDE_NEW_DELETE', 1) # conf.define('NO_MALLOC_OVERRIDE', 1) -# conf.define('NO_MEMOVERRIDE_NEW_DELETE', 1) if conf.options.DEBUG_ENGINE: conf.env.append_unique('DEFINES', [ From 0d5f7a1916ddd709d7bfb4dd48084e51e23af19b Mon Sep 17 00:00:00 2001 From: r-a-sattarov Date: Sat, 14 Oct 2023 01:32:54 +0300 Subject: [PATCH 2/2] E2K: added initial support of MCST Elbrus 2000 CPU architecture --- mathlib/mathlib_base.cpp | 2 +- mathlib/sse.cpp | 4 ++++ public/materialsystem/imesh.h | 4 ++-- public/mathlib/mathlib.h | 4 ++-- public/steam/steamtypes.h | 8 ++------ public/tier0/platform.h | 13 +++++++++---- scripts/waifulib/compiler_optimizations.py | 8 +++++++- tier0/cpu.cpp | 4 +++- tier0/cpu_posix.cpp | 5 ++--- tier1/processor_detect_linux.cpp | 2 +- tier1/reliabletimer.cpp | 2 ++ vtf/vtf.cpp | 4 +++- wscript | 3 +++ 13 files changed, 41 insertions(+), 22 deletions(-) diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 872ffec5e..9f5aef32d 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -3281,7 +3281,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright { s_bSSEEnabled = true; -#ifndef PLATFORM_WINDOWS_PC64 +#if !defined(PLATFORM_WINDOWS_PC64) && (defined(__i386__) || defined(__amd64__)) // These are not yet available. // Select the SSE specific routines if available pfVectorNormalize = _VectorNormalize; diff --git a/mathlib/sse.cpp b/mathlib/sse.cpp index 6122b6648..f8567e5f8 100644 --- a/mathlib/sse.cpp +++ b/mathlib/sse.cpp @@ -15,6 +15,8 @@ #include "sse2neon.h" #endif +#if !defined(__e2k__) + #include "sse.h" // memdbgon must be the last include file in a .cpp file!!! @@ -1127,3 +1129,5 @@ vec_t DotProduct (const vec_t *a, const vec_t *c) */ #endif // COMPILER_MSVC64 + +#endif // !defined(__e2k__) diff --git a/public/materialsystem/imesh.h b/public/materialsystem/imesh.h index 6a952e009..5e19d4cb5 100644 --- a/public/materialsystem/imesh.h +++ b/public/materialsystem/imesh.h @@ -1152,7 +1152,7 @@ inline void CVertexBuilder::FastAdvanceNVertices( int n ) //----------------------------------------------------------------------------- inline void CVertexBuilder::FastVertex( const ModelVertexDX7_t &vertex ) { -#if defined(__arm__) || defined(__aarch64__) || defined(PLATFORM_WINDOWS_PC64) +#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) || defined(PLATFORM_WINDOWS_PC64) FastVertexSSE( vertex ); #else Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed @@ -1354,7 +1354,7 @@ inline void CVertexBuilder::Fast4VerticesSSE( inline void CVertexBuilder::FastVertex( const ModelVertexDX8_t &vertex ) { -#if defined(__arm__) || defined(__aarch64__) || defined(PLATFORM_WINDOWS_PC64) +#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) || defined(PLATFORM_WINDOWS_PC64) FastVertexSSE( vertex ); #else Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index 6503da0f5..805b7cefb 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -1201,7 +1201,7 @@ FORCEINLINE int RoundFloatToInt(float f) }; flResult = __fctiw( f ); return pResult[1]; -#elif defined (__arm__) || defined (__aarch64__) +#elif defined (__arm__) || defined (__aarch64__) || defined(__e2k__) return (int)(f + 0.5f); #else #error Unknown architecture @@ -1233,7 +1233,7 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f) Assert( pIntResult[1] >= 0 ); return pResult[1]; #else // !X360 -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) return (unsigned long)(f + 0.5f); #elif defined( PLATFORM_WINDOWS_PC64 ) uint nRet = ( uint ) f; diff --git a/public/steam/steamtypes.h b/public/steam/steamtypes.h index c32150e2b..7d7546536 100644 --- a/public/steam/steamtypes.h +++ b/public/steam/steamtypes.h @@ -24,10 +24,6 @@ typedef unsigned char uint8; #define POSIX 1 #endif -#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) -#define X64BITS -#endif - // Make sure VALVE_BIG_ENDIAN gets set on PS3, may already be set previously in Valve internal code. #if !defined(VALVE_BIG_ENDIAN) && defined(_PS3) #define VALVE_BIG_ENDIAN @@ -48,7 +44,7 @@ typedef unsigned __int64 uint64; typedef int64 lint64; typedef uint64 ulint64; -#ifdef X64BITS +#ifdef PLATFORM_64BITS typedef __int64 intp; // intp is an integer that can accomodate a pointer typedef unsigned __int64 uintp; // (ie, sizeof(intp) >= sizeof(int) && sizeof(intp) >= sizeof(void *) #else @@ -74,7 +70,7 @@ typedef unsigned long long uint64; typedef long int lint64; typedef unsigned long int ulint64; -#ifdef X64BITS +#ifdef PLATFORM_64BITS typedef long long intp; typedef unsigned long long uintp; #else diff --git a/public/tier0/platform.h b/public/tier0/platform.h index a8ad1b02b..aa87ad654 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -9,7 +9,7 @@ #ifndef PLATFORM_H #define PLATFORM_H -#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) +#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || defined(__e2k__) #define PLATFORM_64BITS 1 #endif @@ -17,6 +17,11 @@ #define COMPILER_GCC 1 #endif +#if defined(__LCC__) && defined(__MCST__) +// MCST LCC (eLbrus Compiler Collection) +#define COMPILER_MCST_LCC 1 +#endif + #ifdef __GLIBC__ #define PLATFORM_GLIBC 1 #endif @@ -898,7 +903,7 @@ static FORCEINLINE double fsel(double fComparand, double fValGE, double fLT) #endif #endif -#elif defined (__arm__) || defined (__aarch64__) +#elif defined (__arm__) || defined (__aarch64__) || defined(__e2k__) inline void SetupFPUControlWord() {} #else inline void SetupFPUControlWord() @@ -1069,7 +1074,7 @@ inline T QWordSwapC( T dw ) // The typically used methods. //------------------------------------- -#if (defined(__i386__) || defined(__amd64__) || defined(__arm__) || defined(__aarch64__)) && !defined(VALVE_LITTLE_ENDIAN) +#if (defined(__i386__) || defined(__amd64__) || defined(__arm__) || defined(__aarch64__) || defined(__e2k__)) && !defined(VALVE_LITTLE_ENDIAN) #define VALVE_LITTLE_ENDIAN 1 #endif @@ -1235,7 +1240,7 @@ PLATFORM_INTERFACE struct tm * Plat_localtime( const time_t *timep, struct tm * inline uint64 Plat_Rdtsc() { -#if (defined( __arm__ ) || defined( __aarch64__ )) && defined (POSIX) +#if (defined( __arm__ ) || defined( __aarch64__ ) || defined(__e2k__)) && defined (POSIX) struct timespec t; clock_gettime( CLOCK_REALTIME, &t); return t.tv_sec * 1000000000ULL + t.tv_nsec; diff --git a/scripts/waifulib/compiler_optimizations.py b/scripts/waifulib/compiler_optimizations.py index fe64efc3a..dff044d3f 100644 --- a/scripts/waifulib/compiler_optimizations.py +++ b/scripts/waifulib/compiler_optimizations.py @@ -30,7 +30,7 @@ } ''' -VALID_BUILD_TYPES = ['fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none'] +VALID_BUILD_TYPES = ['native','fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none'] LINKFLAGS = { 'common': { @@ -65,6 +65,12 @@ 'clang': ['-O2', '-march=native'], 'default': ['-O3'] }, + 'native': { + 'msvc': ['/O2', '/Oy', '/MT'], + 'gcc': ['-O2', '-march=native'], + 'clang': ['-O2', '-march=native'], + 'default': ['-O3'] + }, 'release': { 'msvc': ['/O2', '/MT'], 'owcc': ['-O3', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-finline-functions', '-finline-limit=512'], diff --git a/tier0/cpu.cpp b/tier0/cpu.cpp index 0a1d84be0..c9d9945dd 100644 --- a/tier0/cpu.cpp +++ b/tier0/cpu.cpp @@ -22,7 +22,7 @@ const tchar* GetProcessorVendorId(); static bool cpuid(uint32 function, uint32& out_eax, uint32& out_ebx, uint32& out_ecx, uint32& out_edx) { -#if defined (__arm__) || defined (__aarch64__) || defined( _X360 ) +#if defined (__arm__) || defined (__aarch64__) || defined(__e2k__) || defined( _X360 ) return false; #elif defined(GNUC) @@ -376,6 +376,8 @@ const tchar* GetProcessorArchName() return "aarch64"; #elif defined __arm__ || defined _M_ARM return "arm"; +#elif defined(__e2k__) + return "e2k"; #else #error "Unknown architecture" #endif diff --git a/tier0/cpu_posix.cpp b/tier0/cpu_posix.cpp index a86f40a77..9800e8bf2 100644 --- a/tier0/cpu_posix.cpp +++ b/tier0/cpu_posix.cpp @@ -124,7 +124,7 @@ uint64 CalculateCPUFreq() } } -#if !defined(__arm__) && !defined(__aarch64__) +#if defined(__i386__) || defined(_M_IX86) // fallback mechanism to calculate when failed // Compute the period. Loop until we get 3 consecutive periods that // are the same to within a small error. The error is chosen @@ -178,7 +178,6 @@ uint64 CalculateCPUFreq() #else // ARM hard-coded frequency return (uint64)2000000000; -#endif // if !ARM +#endif // if i386 #endif // if APPLE } - diff --git a/tier1/processor_detect_linux.cpp b/tier1/processor_detect_linux.cpp index 64d771a24..0e46ceb85 100644 --- a/tier1/processor_detect_linux.cpp +++ b/tier1/processor_detect_linux.cpp @@ -13,7 +13,7 @@ bool CheckMMXTechnology(void) { return false; } bool CheckSSETechnology(void) { return false; } bool CheckSSE2Technology(void) { return false; } bool Check3DNowTechnology(void) { return false; } -#elif defined (__arm__) || defined (__aarch64__) +#elif defined (__arm__) || defined (__aarch64__) || defined(__e2k__) bool CheckMMXTechnology(void) { return false; } bool CheckSSETechnology(void) { return false; } bool CheckSSE2Technology(void) { return false; } diff --git a/tier1/reliabletimer.cpp b/tier1/reliabletimer.cpp index f575a6798..7a09466df 100644 --- a/tier1/reliabletimer.cpp +++ b/tier1/reliabletimer.cpp @@ -91,6 +91,8 @@ int64 CReliableTimer::GetPerformanceCountNow() struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return ts.tv_sec * 1000000000ULL + ts.tv_nsec; +#elif defined(__e2k__) + return (int64)Plat_Rdtsc(); #else uint64 un64; __asm__ __volatile__ ( diff --git a/vtf/vtf.cpp b/vtf/vtf.cpp index 0dad47223..f8ad13e86 100644 --- a/vtf/vtf.cpp +++ b/vtf/vtf.cpp @@ -951,7 +951,8 @@ static bool ReadHeaderFromBufferPastBaseHeader( CUtlBuffer &buf, VTFFileHeader_t bool CVTFTexture::ReadHeader( CUtlBuffer &buf, VTFFileHeader_t &header ) { - if ( IsX360() && SetupByteSwap( buf ) ) +#ifdef _X360 + if ( SetupByteSwap( buf ) ) { VTFFileBaseHeader_t baseHeader; m_Swap.SwapFieldsToTargetEndian( &baseHeader, (VTFFileBaseHeader_t*)buf.PeekGet() ); @@ -979,6 +980,7 @@ bool CVTFTexture::ReadHeader( CUtlBuffer &buf, VTFFileHeader_t &header ) } } } +#endif memset( &header, 0, sizeof(VTFFileHeader_t) ); buf.Get( &header, sizeof(VTFFileBaseHeader_t) ); diff --git a/wscript b/wscript index 7f760500b..941ce7b80 100644 --- a/wscript +++ b/wscript @@ -502,6 +502,9 @@ def configure(conf): if conf.env.DEST_OS == 'freebsd': linkflags += ['-lexecinfo'] + if conf.env.DEST_OS != 'darwin': + linkflags += ['-latomic'] + if conf.env.DEST_OS != 'win32': cflags += flags linkflags += flags