On Sunday 08 September 2024 11:43:01 Pali Rohár wrote: > Global variable _osplatform is provided in new x86 versions of msvcrt.dll > and then also in msvcr70.dll, msvcr71.dll and msvcr80.dll. Function > __p__osplatform() which returns pointer to global variable _osplatform is > provided only in msvcr80.dll. > > Provide missing function __p__osplatform() for x86 versions of msvcrt.dll, > msvcr70.dll and msvcr71.dll and change definition of _osplatform in header > file to use __p__osplatform() function. This aligns definition with msvc > and avoid referencing another global variable from mingw-w64 header files. > --- > mingw-w64-crt/Makefile.am | 4 +++ > mingw-w64-crt/misc/__p__osplatform.c | 48 ++++++++++++++++++++++++++++ > mingw-w64-headers/crt/stdlib.h | 9 +++--- > 3 files changed, 56 insertions(+), 5 deletions(-) > create mode 100644 mingw-w64-crt/misc/__p__osplatform.c > > diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am > index 01773f5696d3..adfc94578ad9 100644 > --- a/mingw-w64-crt/Makefile.am > +++ b/mingw-w64-crt/Makefile.am > @@ -453,6 +453,7 @@ src_msvcrt32=\ > $(src_msvcrt_add_x86) \ > math/x86/_copysignf.c \ > misc/___mb_cur_max_func.c \ > + misc/__p__osplatform.c \ > misc/__pctype_func.c \ > misc/__pwctype_func.c \ > misc/_create_locale.c \ > @@ -494,6 +495,7 @@ src_msvcrt64=\ > misc/__p__fmode.c \ > misc/__p__mbcasemap.c \ > misc/__p__mbctype.c \ > + misc/__p__osplatform.c \ > misc/__p__osver.c \ > misc/__p__pctype.c \ > misc/__p__pgmptr.c \ > @@ -870,6 +872,7 @@ src_msvcrt40=\ > stdio/mingw_lock.c > > src_msvcr70=\ > + misc/__p__osplatform.c \ > misc/__sys_errlist.c \ > misc/__sys_nerr.c \ > misc/_configthreadlocale.c \ > @@ -895,6 +898,7 @@ src_msvcr70=\ > stdio/mingw_lock.c > > src_msvcr71=\ > + misc/__p__osplatform.c \ > misc/__sys_errlist.c \ > misc/__sys_nerr.c \ > misc/_configthreadlocale.c \ > diff --git a/mingw-w64-crt/misc/__p__osplatform.c > b/mingw-w64-crt/misc/__p__osplatform.c > new file mode 100644 > index 000000000000..fe30ab963989 > --- /dev/null > +++ b/mingw-w64-crt/misc/__p__osplatform.c > @@ -0,0 +1,48 @@ > +/** > + * This file has no copyright assigned and is placed in the Public Domain. > + * This file is part of the mingw-w64 runtime package. > + * No warranty is given; refer to the file DISCLAIMER.PD within this package. > + */ > + > +#include <_mingw.h> > + > +unsigned int* __cdecl __p__osplatform(void); > +unsigned int* (__cdecl *__MINGW_IMP_SYMBOL(__p__osplatform))(void) = > __p__osplatform; > + > +/* older i386 versions of msvcrt.dll do not provide _osplatform symbol, so > resolve it at runtime */ > +#if defined(__LIBMSVCRT_OS__) && defined(__i386__) > + > +#include <windows.h> > +#include <msvcrt.h> > + > +static unsigned int* _osplatform_ptr; > +static unsigned int _osplatform_static; > + > +unsigned int* __cdecl __p__osplatform(void) > +{ > + if (!_osplatform_ptr) > + { > + HMODULE msvcrt = __mingw_get_msvcrt_handle(); > + if (msvcrt) > + _osplatform_ptr = (unsigned int*)GetProcAddress(msvcrt, > "_osplatform"); > + if (!_osplatform_ptr) > + { > + OSVERSIONINFOA osvi;
Ops. Here is missing one important line: osvi.dwOSVersionInfoSize = sizeof(&osvi); > + if (GetVersionExA(&osvi)) > + _osplatform_static = osvi.dwPlatformId; > + _osplatform_ptr = &_osplatform_static; > + } > + } > + return _osplatform_ptr; > +} > + > +#else > + > +extern unsigned int* __MINGW_IMP_SYMBOL(_osplatform); > + > +unsigned int* __cdecl __p__osplatform(void) > +{ > + return __MINGW_IMP_SYMBOL(_osplatform); > +} > + > +#endif > diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h > index a9069d556322..dabeb3cdb61a 100644 > --- a/mingw-w64-headers/crt/stdlib.h > +++ b/mingw-w64-headers/crt/stdlib.h > @@ -231,16 +231,15 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void); > #endif > #endif /* !_POSIX_ */ > > -#ifndef _osplatform > - extern unsigned int * __MINGW_IMP_SYMBOL(_osplatform); > -#define _osplatform (* __MINGW_IMP_SYMBOL(_osplatform)) > -#endif > - > + _CRTIMP unsigned int *__cdecl __p__osplatform(void); > _CRTIMP unsigned int *__cdecl __p__osver(void); > _CRTIMP unsigned int *__cdecl __p__winver(void); > _CRTIMP unsigned int *__cdecl __p__winmajor(void); > _CRTIMP unsigned int *__cdecl __p__winminor(void); > > +#ifndef _osplatform > +#define _osplatform (* __p__osplatform()) > +#endif > #ifndef _osver > #define _osver (* __p__osver()) > #endif > -- > 2.20.1 > _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public