Commit Graph

7917 Commits

Author SHA1 Message Date
Pali Rohár
0edff2af86 crt: Fix _wctype definitions in def files
_wctype is global variable exported from DLL library, so mark it with
DATA and removes false-positive function stdcall @size decoration.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:24 +03:00
Pali Rohár
d1155764a0 headers: Fix _wctype declaration in header files
_wctype is a global variable exported from CRT library and therefore has to
be always accessed by the import symbol via __MINGW_IMP_SYMBOL(_wctype).

There is no CRT function which could return pointer to this variable.

_wctype variable is present since msvcr70.dll and also since Windows Server
2003 version of msvcrt.dll. It is present also in UCRT. For older versions
there is no fallback or emulation.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:24 +03:00
Martin Storsjö
75f5b92134 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:24 +03:00
Pali Rohár
387aaa6f08 crt: Fix definition for _pwctype to be available also for UCRT
Global variable _pwctype is not available in UCRT. Instead UCRT has only
__pwctype_func() function which returns value of _pwctype variable.

Function __pwctype_func() is available also in msvcrt since VC70. For
previous i386 msvcrt versions there is a __p__pwctype() function which
returns pointer to the _pwctype variable.

Like for _pctype changes, add fallback versions of __pwctype_func() and
__p__pwctype() functions suitable for older CRT versions. And change
definition of _pwctype in header file from the global variable to macro
which calls __pwctype_func() function.

This change allows to use _pwctype with all CRT libraries, including UCRT.

Fix also type of _pwctype. In msvc its type is wctype_t and not unsigned
short. Note that wctype_t is just typedef for unsigned short, so this
should be just a cosmetic change to align with msvc.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:24 +03:00
Martin Storsjö
42ed7c9a8c crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:24 +03:00
Pali Rohár
f00d6dbc9a crt: Provide __p__pctype and __pctype_func symbols for every import CRT library
__pctype_func is available in msvcrt since VC70. __p__pctype is available
in i386 msvcrt version since VC20. _pctype is available in all versions
except in UCRT.

Define fallback __pctype_func() function implementation via __p__pctype()
function. And define __p__pctype() via _pctype variable.

With this change every CRT import library provides __pctype_func()
function. So remove #ifdefs for _pctype declarations in header files and
unifies _pctype definitions between different CRT libraries.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:23 +03:00
Pali Rohár
47d0ec07cf headers: Fix _pctype, _pwctype, _wctype and __pctype_func() declarations
Global variables _pctype, _pwctype, _wctype and function __pctype_func() are constant.

See:
* https://learn.microsoft.com/en-us/cpp/c-runtime-library/pctype-pwctype-wctype-mbctype-mbcasemap
* https://learn.microsoft.com/en-us/cpp/c-runtime-library/pctype-func

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:23 +03:00
Martin Storsjö
e8a17fd911 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:23 +03:00
Pali Rohár
b805d02895 crt: Improve ___mb_cur_max_func() function support
Provide fallback ___mb_cur_max_func() implementation via __p___mb_cur_max()
function. __p___mb_cur_max() is available since VC20. For earlier version
import libraries provide fallback __p___mb_cur_max() implementation via
global variable __mb_cur_max.

With this change every CRT import library provides ___mb_cur_max_func()
function. So remove #ifdefs for __mb_cur_max declarations in header files.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:23 +03:00
Martin Storsjö
f6ebd653bc crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:23 +03:00
Pali Rohár
2072dbefde crt: Provide __iob_func function by every msvcrt import library
Both functions __iob_func() and __p__iob() returns same constant value -
pointer to the first member of _iob[] array. Symbol for _iob[] array is
present in every msvcrt DLL library.

Function __p__iob() is provided by every i386 version of msvcrt DLL library
since VC20. But it is not available in any non-i386 version. Function
__iob_func() is provided by every version of msvcrt DLL library since VC70
for every architecture. __iob_func() is provided also by every X64 and ARM
versions of OS system version msvcrt.dll.

Note that UCRT does not provide neither __iob_func(), nor __p__iob()
function.

So for all msvcrt versions before VC70 define __iob_func symbol as an alias
to __p__iob symbol. And for versions before VC20 provide custom mingw-w64
implementation of __iob_func() function which returns pointer to the first
member of _iob[] array.

This change allows to remove #ifdef around _iob declaration in stdio.h and
wchar.h header files as now the __iob_func() function is provided by every
version of msvcrt import library.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-15 00:07:22 +03:00
Biswapriyo Nath
f5270c6d3f headers: Add new name in WHV_PROCESSOR_VENDOR in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:56:34 +08:00
Biswapriyo Nath
f7f39fb855 headers: Add aarch64 members in WHV_EXTENDED_VM_EXITS in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:56:34 +08:00
Biswapriyo Nath
51853d7d33 headers: Add aarch64 members in WHV_CAPABILITY_FEATURES in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:56:34 +08:00
Biswapriyo Nath
5fb9146b88 headers: Add new names in WHV_CAPABILITY_CODE in winhvplatformdefs.h
Existent enumerators have been updated a little to prevent a trailing comma.

Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:52:56 +08:00
Biswapriyo Nath
4a2b747dc3 headers: Add new members in WHV_REGISTER_VALUE in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:13:19 +08:00
LIU Hao
74875157b0 crt/math: Reveal more names
This commit reveals names in three categories:

1) Names that start with an underscore and a letter in uppercase are reserved
   for implementations. These can be revealed even with strict standard
   conformance.

2) Names that start with an underscore and a letter in lowercase are reserved
   for implementations in file scopes (i.e. they are not eligible for macros).
   These can be revealed even with strict standard conformance.

3) Some names reference POSIX functions. These are revealed when a POSIX, GNU
   or BSD feature test macro is defined.

Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-12 22:13:18 +08:00
Biswapriyo Nath
55ced9c1c9 headers: Add aarch64 condition in WHV_DELIVERABILITY_NOTIFICATIONS_REGISTER in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-10 17:17:06 +08:00
Biswapriyo Nath
ef7c648a02 headers: Add new names in WHV_X64_PENDING_EVENT_TYPE in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-10 17:17:03 +08:00
Biswapriyo Nath
95a72435e5 headers: Add WHV_REGISTER_NAME for aarch64 in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-10 17:17:01 +08:00
Biswapriyo Nath
56f2a58850 headers: Add new names in WHV_REGISTER_NAME in winhvplatformdefs.h
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-10 17:16:55 +08:00
LIU Hao
96a45e3196 crt: Regenerate Makefile.in
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-06 22:56:38 +08:00
Biswapriyo Nath
611e7b6fdd crt: Unify winhvplatform.def for lib64 and libarm64
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-06 22:55:45 +08:00
Martin Storsjö
f97814b960 headers: Add new constants for IsProcessorFeaturePresent from WinSDK 10.0.26100
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-06 10:47:10 +03:00
Biswapriyo Nath
f977e1c382 headers: Add missing NTDDI_WIN10* defines
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-05 21:55:44 +08:00
Martin Storsjö
386fc6b04a headers: Fix the order of asm() and attribute((deprecated())) in time.h
This fixes build errors with GCC, after
e5ac8c5509cd729b97065733cf4b0df0ec732797; GCC doesn't accept
__asm__(), expanded from __MINGW_ASM_CALL(), after
__attribute__((deprecated())), while Clang accepts both orders.

By default, __MINGW_ATTRIB_DEPRECATED_SEC_WARN doesn't expand
to anything, but if built with defines that makes this expand to
a deprecation attribute, the build would fail with GCC.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-05 10:44:42 +03:00
Biswapriyo Nath
921d142f8e crt: Add new symbols in hyperv compute import libs
From cdf0e097290c4ca4fa21c2a136281d2e3b38db36 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbappai@gmail.com>
Date: Mon, 3 Jun 2024 06:43:03 +0000
Subject: [PATCH 2/2] crt: Add new symbols in hyperv compute import libs

Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-04 22:07:12 +08:00
Biswapriyo Nath
4ad55c4393 headers: Add new symbols in hyperv compute headers
From 323e43aa70b0a3d7e8b1b42650b5a769337ab679 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbappai@gmail.com>
Date: Mon, 3 Jun 2024 06:40:09 +0000
Subject: [PATCH 1/2] headers: Add new symbols in hyperv compute headers

Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-06-04 22:07:12 +08:00
Pali Rohár
633a8340de crt: Add guards in func.def.in file
Add once-guard to ensure that the file is processed only once.

Add arch-guard to ensure that DEF_<ARCH> is always defined to prevent an
issue that symbols defined via F32() macro completely disappeared and which
was fixed in previous change.

This change applied before the previous change cause compile errors.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-04 15:36:43 +03:00
Martin Storsjö
a94d694161 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-04 15:36:43 +03:00
Pali Rohár
93f81148ec crt: Preprocess all .def.in files with -DDEF_<ARCH>
Having -DDEF_<ARCH> is required by func.def.in which is used either
directly or indirectly by crt-aliases.def.in in all CRT def.in files.
Some symbols in crt-aliases.def.in are defined via F* macros and these
symbols are currently missing in versioned non-os msvcrt import libraries.

This change is fixing missing symbols in all CRT import libraries.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-04 15:35:37 +03:00
Pali Rohár
297146f1b7 crt: Declare aliased __MINGW_IMP_SYMBOL symbols via __attribute__((alias))
Currently __MINGW_IMP_SYMBOL symbols for aliased functions are defined as
a new plain global variable, just like for an original function.

GCC supports declaring global variable as an alias to other global
variable.

Change all aliases of import __MINGW_IMP_SYMBOL symbols via alias
attribute. This reduce memory usage as original symbol and aliased symbol
will share same global variable. Also it makes it clear that the aliased
import symbol is an alias to another import symbol.

Note that aliased symbol has to be declared with "extern" keyword even it
is not extern and gcc will emit this symbol (as described in documentation).

So for example:

  int var_non_alias = 1;
  int var_target = 2;
  extern int __attribute__ ((alias ("var_target"))) var_alias;

Emits symbols:

  SYMBOL TABLE:
  [  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000000 test.c
  File
  [  2](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
  AUX scnlen 0x0 nreloc 0 nlnno 0
  [  4](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
  AUX scnlen 0x8 nreloc 0 nlnno 0
  [  6](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
  AUX scnlen 0x0 nreloc 0 nlnno 0
  [  8](sec  4)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .rdata$zzz
  AUX scnlen 0x1e nreloc 0 nlnno 0
  [ 10](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _var_non_alias
  [ 11](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000004 _var_target
  [ 12](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000004 _var_alias

  Contents of section .data:
   0000 01000000 02000000                    ........

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-04 15:32:59 +03:00
Pali Rohár
1e141bf8a1 crt: Move __uncaught_exception symbol out of the C++ mangled symbol section in all .def.in files
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:29:52 +03:00
Martin Storsjö
efbc4ffa51 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:28:28 +03:00
Pali Rohár
69a9944aef crt: Add import library for msvcr80d.dll
msvcr80d.dll is debug version of the msvcr80.dll and provides additional
debugging functions.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:27:29 +03:00
Martin Storsjö
1983edeafe crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:20 +03:00
Pali Rohár
fd242b3ae4 crt: crtdll.dll and msvcrt10.dll: Fix linking of the WinMain() function
WinMain() entry point provided by the application is called by mingw-w64
startup code, more precisely by function main() from crtexewin.c file.

mingw-w64 startup code in file crtexewin.c calls _ismbblead() function.
Function _ismbblead() is not available in some versions of crtdll.dll
and is completely missing in msvcrt10.dll library.

Version of crtdll.dll library stored in its PE resource directory is not
meaningful as two different libraries, one with _ismbblead symbol and one
without _ismbblead symbol has same version.

Seems that there are MBCS aware crtdll.dll versions with _ismbblead symbol
and versions which are not MBCS aware without _ismbblead symbol.

All checked msvcrt10.dll files do not have _ismbblead symbols, so
msvcrt10.dll is not MBCS awre.

For msvcrt10.dll import library provides simple dummy _ismbblead() function
which always returns false to satisfy mingw-w64 startup file crtexewin.c.

For crtdll.dll import library provides _ismbblead() wrapper function and
disable the real function in the def file to prevent symbol conflicts. The
wrapper function via GetProcAddress() checks if the real crtdll.dll
provides _ismbblead() function. If real function exists then it is called.
If not then wrapper function returns false like the msvcrt10.dll one.

This fixes linking WinMain() entry point with msvcrt10.dll.

  ld: /usr/local/lib/libmingw32.a(lib32_libmingw32_a-crtexewin.o): in function `main':
  mingw-w64/mingw-w64-crt/crt/crtexewin.c:43: undefined reference to `_ismbblead'
  collect2: error: ld returned 1 exit status

And fixes runtime error about missing _ismbblead symbol with some versions of crtdll.dll.

  Entry Point Not Found
  The procedure entry point _ismbblead could not be located in the
  dynamic link library CRTDLL.dll.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Martin Storsjö
6bddd5f9f1 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Pali Rohár
dace1a16b2 crt: msvcrt20: Fix calling __getmainargs() and __wgetmainargs() functions
API for __getmainargs() and __wgetmainargs() functions in msvcrt20.dll is
slightly different than in new msvcrt versions. In msvcrt20.dll these
functions return void and take new_mode parameter instead of the pointer to
the _startupinfo structure.

So for compatibility with mingw-w64 startup code, in msvcrt20 import
library rename exported __getmainargs/__wgetmainargs symbols to
__msvcrt20_getmainargs/__msvcrt20_wgetmainargs and provide mingw-w64
compatible wrappers named __getmainargs/__wgetmainargs around the
renamed symbols __msvcrt20_getmainargs/__msvcrt20_wgetmainargs.

See wine implementation for details:
https://gitlab.winehq.org/wine/wine/-/blob/wine-9.8/dlls/msvcrt20/msvcrt20.c
7f1e74a97a

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Martin Storsjö
afb559847d crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Pali Rohár
81557b004b crt: msvcrt10: Fix calling __getmainargs() function
API for __getmainargs() function in msvcrt10.dll is same as __GetMainArgs()
function in crtdll.dll. It is slightly different than in any other msvcrt
versions. It returns void and does not the pointer to the _startupinfo
structure as a last argument.

So for compatibility with mingw-w64 startup code, in msvcrt10 import
library rename the real __getmainargs symbol to __GetMainArgs and use
mingw-w64 crtdll.dll's wrapper __getmainargs around the __GetMainArgs for
providing the compatible __getmainargs() function.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Martin Storsjö
2b4df01c65 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:19 +03:00
Pali Rohár
3a3dd8d178 crt: crtdll.dll: Rename crtdll_compat.c to crtdll_getmainargs.c
Filename crtdll_getmainargs.c better describe which function it provides.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:18 +03:00
Pali Rohár
db856f3073 crt: crtdll.dll: Define __GetMainArgs with _CRTIMP as the function is being imported
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:19:18 +03:00
Pali Rohár
18eb7fc2fa crt: Add missing __cdecl decoration for functions: mbrtowc mbsrtowcs mbrlen wcrtomb wcsrtombs
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-06-03 14:14:16 +03:00
Pali Rohár
561a057ceb crt: Document why the stat symbol alias is not used
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-05-30 15:52:48 +03:00
Martin Storsjö
f571c7f6d1 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-05-30 15:52:48 +03:00
Pali Rohár
c0f0630982 crt: Provide fstat function symbol via alias
For 32-bit time_t (detected by _USE_32BIT_TIME_T), functions _fstat32(),
_fstat() and fstat() are same. So fstat() can be defined as simple alias
in def file.

Same applies for functions _fstat64i32(), _fstat() and fstat() when time_t
is 64-bit.

Simplify fstat() function, remove it from mingw-w64-crt/stdio/_fstat.c file
and provide it via aliases in api-ms-win-crt-filesystem-l1-1-0.def.in and
crt-aliases.def.in for all CRT import libraries.

This fixes FIXME issue described in the fstat.c.

This change also ensures that fstat and _fstat symbols would results in the
same function calls.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-05-30 15:52:48 +03:00
Pali Rohár
4f9685299a headers: Fix *stat* macros in _mingw_stat64.h header file
All CRT import libraries provides UCRT-compatible *stat* symbols since
commit b463875615.

So define all stat* macros consistently with definitions of aliases in def
files based on UCRT. There is no need to have ifdef for non-UCRT version
anymore.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-05-30 15:52:48 +03:00
Martin Storsjö
cc6afd4919 crt: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-05-29 23:49:08 +03:00