authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-16 23:27:53+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-06-11 18:27:15+02:00
log879bc2e5cb614bdb1b7a2426c9746989089bccd3
tree9ce260ac4bb0f6658356e84432cea0627a2d76af
parent0979e56bd284adf161e1765200785a376fd7bb53
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

mingw: Update MinGW-w64 sources to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e.


145 files changed, 1820 insertions(+), 1511 deletions(-)

lib/libc/mingw/cfguard/mingw_cfguard_support.c-8
......@@ -17,14 +17,6 @@
1717// really matter here because this is a no-op anyway.
1818static void __guard_check_icall_dummy(void) {}
1919
20// When CFGuard is not active, directly tail-call the target address, which
21// is passed via %rax.
22__asm__(
23 ".globl __guard_dispatch_icall_dummy\n"
24 "__guard_dispatch_icall_dummy:\n"
25 " jmp *%rax\n"
26);
27
2820// This is intentionally declared as _not_ a function pointer, so that the
2921// jmp instruction is not included as a valid call target for CFGuard.
3022extern void *__guard_dispatch_icall_dummy;
lib/libc/mingw/crt/CRT_fp10.c-8
......@@ -8,19 +8,11 @@ void _fpreset (void);
88
99void _fpreset (void)
1010{
11#if defined(_ARM_) || defined(__arm__)
12 __asm__ __volatile__ (
13 "vmsr fpscr, %0\n\t" : : "r"(0 /* INITIAL_FPSCR */));
14#elif defined(_ARM64_) || defined(__aarch64__)
15 __asm__ __volatile__ (
16 "msr fpcr, %0\n\t" : : "r"(0LL /* INITIAL_FPSCR */));
17#else
1811#ifdef __GNUC__
1912 __asm__ ("fninit");
2013#else /* msvc: */
2114 __asm fninit;
2215#endif
23#endif
2416}
2517
2618#ifdef __GNUC__
lib/libc/mingw/crt/crtdll.c+47-80
......@@ -4,12 +4,6 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#ifdef CRTDLL
8#undef CRTDLL
9#ifndef _DLL
10#define _DLL
11#endif
12
137#include <oscalls.h>
148#include <internal.h>
159#include <stdlib.h>
......@@ -19,20 +13,14 @@
1913#include <crtdbg.h>
2014
2115#ifndef _CRTIMP
22#ifdef CRTDLL
23#define _CRTIMP __declspec(dllexport)
24#else
25#ifdef _DLL
2616#define _CRTIMP __declspec(dllimport)
27#else
28#define _CRTIMP
29#endif
30#endif
3117#endif
3218#include <sect_attribs.h>
3319#include <locale.h>
3420
35extern void __cdecl _initterm(_PVFV *,_PVFV *);
21#if defined(__x86_64__) && !defined(__SEH__)
22extern int __mingw_init_ehandler (void);
23#endif
3624extern void __main ();
3725extern void _pei386_runtime_relocator (void);
3826extern _PIFV __xi_a[];
......@@ -50,20 +38,6 @@ static _onexit_table_t atexit_table;
5038
5139extern int __mingw_app_type;
5240
53extern WINBOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved);
54
55extern WINBOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID);
56
57static int pre_c_init (void);
58
59_CRTALLOC(".CRT$XIAA") _PIFV pcinit = pre_c_init;
60
61static int
62pre_c_init (void)
63{
64 return _initialize_onexit_table(&atexit_table);
65}
66
6741WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
6842{
6943 if (dwReason == DLL_PROCESS_DETACH)
......@@ -77,10 +51,11 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
7751 {
7852 void *lock_free = NULL;
7953 void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
80 int nested = FALSE;
54 BOOL nested = FALSE;
55 int ret = 0;
8156
82 while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
83 fiberid, 0)) != 0)
57 while ((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock,
58 fiberid, NULL)) != 0)
8459 {
8560 if (lock_free == fiberid)
8661 {
......@@ -89,25 +64,37 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
8964 }
9065 Sleep(1000);
9166 }
92 if (__native_startup_state == __initializing)
67 if (__native_startup_state != __uninitialized)
9368 {
9469 _amsg_exit (31);
9570 }
96 else if (__native_startup_state == __uninitialized)
71 else
9772 {
9873 __native_startup_state = __initializing;
9974
100 if (_initterm_e (__xi_a, __xi_z) != 0)
101 return FALSE;
102 }
103 if (__native_startup_state == __initializing)
104 {
75 _pei386_runtime_relocator ();
76#if defined(__x86_64__) && !defined(__SEH__)
77 __mingw_init_ehandler ();
78#endif
79 ret = _initialize_onexit_table (&atexit_table);
80 if (ret != 0)
81 goto i__leave;
82 ret = _initterm_e (__xi_a, __xi_z);
83 if (ret != 0)
84 goto i__leave;
10585 _initterm (__xc_a, __xc_z);
86 __main ();
87
10688 __native_startup_state = __initialized;
10789 }
90i__leave:
10891 if (! nested)
10992 {
110 (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
93 (void) InterlockedExchangePointer (&__native_startup_lock, NULL);
94 }
95 if (ret != 0)
96 {
97 return FALSE;
11198 }
11299 if (__dyn_tls_init_callback != NULL)
113100 {
......@@ -118,8 +105,16 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
118105 else if (dwReason == DLL_PROCESS_DETACH)
119106 {
120107 void *lock_free = NULL;
121 while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,(PVOID) 1, 0)) != 0)
108 void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
109 BOOL nested = FALSE;
110
111 while ((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock, fiberid, NULL)) != 0)
122112 {
113 if (lock_free == fiberid)
114 {
115 nested = TRUE;
116 break;
117 }
123118 Sleep(1000);
124119 }
125120 if (__native_startup_state != __initialized)
......@@ -130,84 +125,56 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
130125 {
131126 _execute_onexit_table(&atexit_table);
132127 __native_startup_state = __uninitialized;
133 (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
128 }
129 if (! nested)
130 {
131 (void) InterlockedExchangePointer (&__native_startup_lock, NULL);
134132 }
135133 }
136134 return TRUE;
137135}
138136
139static WINBOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID);
140
141137WINBOOL WINAPI DllMainCRTStartup (HANDLE, DWORD, LPVOID);
142#if defined(__x86_64__) && !defined(__SEH__)
143int __mingw_init_ehandler (void);
144#endif
145138
146__attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */
147WINBOOL WINAPI
148DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
149{
150 __mingw_app_type = 0;
151 return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved);
152}
153
154static
155139#if defined(__i386__) || defined(_X86_)
156140/* We need to make sure that we align the stack to 16 bytes for the sake of SSE
157 opts in DllMain/DllEntryPoint or in functions called from DllMain/DllEntryPoint. */
141 opts in DllMain or in functions called from DllMain. */
158142__attribute__((force_align_arg_pointer))
159143#endif
160__declspec(noinline) WINBOOL
161__DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
144__attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */
145WINBOOL WINAPI
146DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
162147{
163148 WINBOOL retcode = TRUE;
164149
150 __mingw_app_type = 0;
165151 __native_dllmain_reason = dwReason;
166 if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0)
152 if (dwReason == DLL_PROCESS_DETACH && __proc_attached <= 0)
167153 {
168154 retcode = FALSE;
169155 goto i__leave;
170156 }
171 _pei386_runtime_relocator ();
172
173#if defined(__x86_64__) && !defined(__SEH__)
174 if (dwReason == DLL_PROCESS_ATTACH)
175 __mingw_init_ehandler ();
176#endif
177157
178158 if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
179159 {
180160 retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
181161 if (!retcode)
182162 goto i__leave;
183 retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
184 if (! retcode)
185 {
186 if (dwReason == DLL_PROCESS_ATTACH)
187 _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
188 goto i__leave;
189 }
190163 }
191 if (dwReason == DLL_PROCESS_ATTACH)
192 __main ();
193164 retcode = DllMain(hDllHandle,dwReason,lpreserved);
194165 if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
195166 {
196167 DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
197 DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
198168 _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
199169 }
200170 if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
201171 {
202 retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
203 if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
204 retcode = FALSE;
172 retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
205173 }
206174i__leave:
207175 __native_dllmain_reason = UINT_MAX;
208176 return retcode ;
209177}
210#endif
211178
212179int __cdecl atexit (_PVFV func)
213180{
lib/libc/mingw/crt/crtexe.c+4-11
......@@ -4,13 +4,6 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#undef CRTDLL
8#ifndef _DLL
9#define _DLL
10#endif
11
12#define SPECIAL_CRTEXE
13
147#include <oscalls.h>
158#include <internal.h>
169#include <process.h>
......@@ -211,9 +204,9 @@ __tmainCRTStartup (void)
211204{
212205 void *lock_free = NULL;
213206 void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
214 int nested = FALSE;
215 while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
216 fiberid, 0)) != 0)
207 BOOL nested = FALSE;
208 while((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock,
209 fiberid, NULL)) != 0)
217210 {
218211 if (lock_free == fiberid)
219212 {
......@@ -242,7 +235,7 @@ __tmainCRTStartup (void)
242235 }
243236 _ASSERTE(__native_startup_state == __initialized);
244237 if (! nested)
245 (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
238 (VOID)InterlockedExchangePointer (&__native_startup_lock, NULL);
246239
247240 if (__dyn_tls_init_callback != NULL)
248241 __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
lib/libc/mingw/crt/crtexewin.c-1
......@@ -56,7 +56,6 @@ int _tmain (int __UNUSED_PARAM(argc),
5656
5757 {
5858 STARTUPINFO StartupInfo;
59 memset (&StartupInfo, 0, sizeof (STARTUPINFO));
6059 GetStartupInfo (&StartupInfo);
6160 if (StartupInfo.dwFlags & STARTF_USESHOWWINDOW)
6261 nShowCmd = StartupInfo.wShowWindow;
lib/libc/mingw/crt/dll_argv.c-4
......@@ -4,10 +4,6 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#ifdef CRTDLL
8#undef CRTDLL
9#endif
10
117#include <internal.h>
128
139extern int _dowildcard;
lib/libc/mingw/crt/dllargv.c-4
......@@ -4,10 +4,6 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#ifdef CRTDLL
8#undef CRTDLL
9#endif
10
117#include <internal.h>
128
139int __CRTDECL
lib/libc/mingw/crt/natstart.c+2-2
......@@ -10,5 +10,5 @@
1010_PGLOBAL
1111volatile unsigned int __native_dllmain_reason = UINT_MAX;
1212volatile unsigned int __native_vcclrit_reason = UINT_MAX;
13volatile __enative_startup_state __native_startup_state;
14volatile void *__native_startup_lock;
13volatile __enative_startup_state __native_startup_state = __uninitialized;
14void *volatile __native_startup_lock = NULL;
lib/libc/mingw/crt/tlssup.c-4
......@@ -6,10 +6,6 @@
66 * Written by Kai Tietz <kai.tietz@onevision.com>
77 */
88
9#ifdef CRTDLL
10#undef CRTDLL
11#endif
12
139#include <sect_attribs.h>
1410
1511#ifndef WIN32_LEAN_AND_MEAN
lib/libc/mingw/gdtoa/strtodnrp.c+1-2
......@@ -85,8 +85,7 @@ double __cdecl
8585__mingw_strtod (const char * __restrict__ src, char ** __restrict__ endptr)
8686 __attribute__((alias("__strtod")));
8787
88#if !(defined(_AMD64_) || defined(__x86_64__) || \
89 defined(_X86_) || defined(__i386__))
88#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
9089/* For systems other than x86, where long double == double, provide the
9190 * long double functions as aliases to __strtod. */
9291
lib/libc/mingw/gdtoa/strtopx.c+12-11
......@@ -53,8 +53,19 @@ THIS SOFTWARE.
5353#define _4 0
5454#endif
5555
56#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
57/* For ARM, where long double == double, provide the long double function as
58 * an alias for __strtod. Do this in a separate object file from other
59 * functions, to avoid linker conflicts if object files import both 'strtold'
60 * from libucrt*.a and the object file providing '__strtod'. */
61long double __cdecl
62strtold (const char * __restrict__ src, char ** __restrict__ endptr)
63{
64 return __mingw_strtod(src, endptr);
65}
66
5667/* This is specific to the x86 80 bit long doubles. */
57#if defined(_AMD64_) || defined(__x86_64__) || \
68#elif defined(_AMD64_) || defined(__x86_64__) || \
5869 defined(_X86_) || defined(__i386__)
5970
6071typedef union lD {
......@@ -133,14 +144,4 @@ long double __cdecl
133144strtold (const char * __restrict__ src, char ** __restrict__ endptr)
134145 __attribute__((alias("__strtold")));
135146
136#elif defined(__arm__) || defined(__aarch64__) || defined(_ARM_) || defined(_ARM64_)
137/* For ARM, where long double == double, provide the long double function as
138 * an alias for __strtod. Do this in a separate object file from other
139 * functions, to avoid linker conflicts if object files import both 'strtold'
140 * from libucrt*.a and the object file providing '__strtod'. */
141long double __cdecl
142strtold (const char * __restrict__ src, char ** __restrict__ endptr)
143{
144 return __mingw_strtod(src, endptr);
145}
146147#endif
lib/libc/mingw/include/internal.h+155-1
......@@ -14,6 +14,7 @@ extern "C" {
1414#endif
1515
1616#include <limits.h>
17#include <fenv.h>
1718#include <windows.h>
1819
1920#pragma pack(push,_CRT_PACKING)
......@@ -130,7 +131,7 @@ extern "C" {
130131 } __enative_startup_state;
131132
132133 extern volatile __enative_startup_state __native_startup_state;
133 extern volatile void *__native_startup_lock;
134 extern void *volatile __native_startup_lock;
134135
135136 extern volatile unsigned int __native_dllmain_reason;
136137 extern volatile unsigned int __native_vcclrit_reason;
......@@ -154,6 +155,159 @@ extern "C" {
154155# define __mingw_has_sse() 0
155156#endif
156157
158#if defined(__i386__) || defined(__x86_64__)
159enum fenv_masks
160{
161 /* x87 encoding constants */
162 FENV_X_INVALID = 0x00100010,
163 FENV_X_DENORMAL = 0x00200020,
164 FENV_X_ZERODIVIDE = 0x00080008,
165 FENV_X_OVERFLOW = 0x00040004,
166 FENV_X_UNDERFLOW = 0x00020002,
167 FENV_X_INEXACT = 0x00010001,
168 FENV_X_AFFINE = 0x00004000,
169 FENV_X_UP = 0x00800200,
170 FENV_X_DOWN = 0x00400100,
171 FENV_X_24 = 0x00002000,
172 FENV_X_53 = 0x00001000,
173 /* SSE encoding constants: they share the same lower word as their x87 counterparts
174 * but differ in the upper word */
175 FENV_Y_INVALID = 0x10000010,
176 FENV_Y_DENORMAL = 0x20000020,
177 FENV_Y_ZERODIVIDE = 0x08000008,
178 FENV_Y_OVERFLOW = 0x04000004,
179 FENV_Y_UNDERFLOW = 0x02000002,
180 FENV_Y_INEXACT = 0x01000001,
181 FENV_Y_UP = 0x80000200,
182 FENV_Y_DOWN = 0x40000100,
183 FENV_Y_FLUSH = 0x00000400,
184 FENV_Y_FLUSH_SAVE = 0x00000800
185};
186
187/* encodes the x87 (represented as x) or SSE (represented as y) control/status word in a ulong */
188static inline unsigned long fenv_encode(unsigned int x, unsigned int y)
189{
190 unsigned long ret = 0;
191
192 if (x & _EM_INVALID) ret |= FENV_X_INVALID;
193 if (x & _EM_DENORMAL) ret |= FENV_X_DENORMAL;
194 if (x & _EM_ZERODIVIDE) ret |= FENV_X_ZERODIVIDE;
195 if (x & _EM_OVERFLOW) ret |= FENV_X_OVERFLOW;
196 if (x & _EM_UNDERFLOW) ret |= FENV_X_UNDERFLOW;
197 if (x & _EM_INEXACT) ret |= FENV_X_INEXACT;
198 if (x & _IC_AFFINE) ret |= FENV_X_AFFINE;
199 if (x & _RC_UP) ret |= FENV_X_UP;
200 if (x & _RC_DOWN) ret |= FENV_X_DOWN;
201 if (x & _PC_24) ret |= FENV_X_24;
202 if (x & _PC_53) ret |= FENV_X_53;
203
204 if (y & _EM_INVALID) ret |= FENV_Y_INVALID;
205 if (y & _EM_DENORMAL) ret |= FENV_Y_DENORMAL;
206 if (y & _EM_ZERODIVIDE) ret |= FENV_Y_ZERODIVIDE;
207 if (y & _EM_OVERFLOW) ret |= FENV_Y_OVERFLOW;
208 if (y & _EM_UNDERFLOW) ret |= FENV_Y_UNDERFLOW;
209 if (y & _EM_INEXACT) ret |= FENV_Y_INEXACT;
210 if (y & _RC_UP) ret |= FENV_Y_UP;
211 if (y & _RC_DOWN) ret |= FENV_Y_DOWN;
212 if (y & _DN_FLUSH) ret |= FENV_Y_FLUSH;
213 if (y & _DN_FLUSH_OPERANDS_SAVE_RESULTS) ret |= FENV_Y_FLUSH_SAVE;
214
215 return ret;
216}
217
218/* decodes the x87 (represented as x) or SSE (represented as y) control/status word in a ulong */
219static inline BOOL fenv_decode(unsigned long enc, unsigned int *x, unsigned int *y)
220{
221 *x = *y = 0;
222 if ((enc & FENV_X_INVALID) == FENV_X_INVALID) *x |= _EM_INVALID;
223 if ((enc & FENV_X_DENORMAL) == FENV_X_DENORMAL) *x |= _EM_DENORMAL;
224 if ((enc & FENV_X_ZERODIVIDE) == FENV_X_ZERODIVIDE) *x |= _EM_ZERODIVIDE;
225 if ((enc & FENV_X_OVERFLOW) == FENV_X_OVERFLOW) *x |= _EM_OVERFLOW;
226 if ((enc & FENV_X_UNDERFLOW) == FENV_X_UNDERFLOW) *x |= _EM_UNDERFLOW;
227 if ((enc & FENV_X_INEXACT) == FENV_X_INEXACT) *x |= _EM_INEXACT;
228 if ((enc & FENV_X_AFFINE) == FENV_X_AFFINE) *x |= _IC_AFFINE;
229 if ((enc & FENV_X_UP) == FENV_X_UP) *x |= _RC_UP;
230 if ((enc & FENV_X_DOWN) == FENV_X_DOWN) *x |= _RC_DOWN;
231 if ((enc & FENV_X_24) == FENV_X_24) *x |= _PC_24;
232 if ((enc & FENV_X_53) == FENV_X_53) *x |= _PC_53;
233
234 if ((enc & FENV_Y_INVALID) == FENV_Y_INVALID) *y |= _EM_INVALID;
235 if ((enc & FENV_Y_DENORMAL) == FENV_Y_DENORMAL) *y |= _EM_DENORMAL;
236 if ((enc & FENV_Y_ZERODIVIDE) == FENV_Y_ZERODIVIDE) *y |= _EM_ZERODIVIDE;
237 if ((enc & FENV_Y_OVERFLOW) == FENV_Y_OVERFLOW) *y |= _EM_OVERFLOW;
238 if ((enc & FENV_Y_UNDERFLOW) == FENV_Y_UNDERFLOW) *y |= _EM_UNDERFLOW;
239 if ((enc & FENV_Y_INEXACT) == FENV_Y_INEXACT) *y |= _EM_INEXACT;
240 if ((enc & FENV_Y_UP) == FENV_Y_UP) *y |= _RC_UP;
241 if ((enc & FENV_Y_DOWN) == FENV_Y_DOWN) *y |= _RC_DOWN;
242 if ((enc & FENV_Y_FLUSH) == FENV_Y_FLUSH) *y |= _DN_FLUSH;
243 if ((enc & FENV_Y_FLUSH_SAVE) == FENV_Y_FLUSH_SAVE) *y |= _DN_FLUSH_OPERANDS_SAVE_RESULTS;
244
245 return fenv_encode(*x, *y) == enc;
246}
247#else
248static inline unsigned long fenv_encode(unsigned int x, unsigned int y)
249{
250 /* Encode _EM_DENORMAL as 0x20 for Windows compatibility. */
251 if (y & _EM_DENORMAL)
252 y = (y & ~_EM_DENORMAL) | 0x20;
253
254 return x | y;
255}
256
257static inline BOOL fenv_decode(unsigned long enc, unsigned int *x, unsigned int *y)
258{
259 /* Decode 0x20 as _EM_DENORMAL. */
260 if (enc & 0x20)
261 enc = (enc & ~0x20) | _EM_DENORMAL;
262
263 *x = *y = enc;
264 return TRUE;
265}
266#endif
267
268void __mingw_setfp( unsigned int *cw, unsigned int cw_mask, unsigned int *sw, unsigned int sw_mask );
269void __mingw_setfp_sse( unsigned int *cw, unsigned int cw_mask, unsigned int *sw, unsigned int sw_mask );
270unsigned int __mingw_controlfp(unsigned int newval, unsigned int mask);
271#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
272int __mingw_control87_2(unsigned int, unsigned int, unsigned int *, unsigned int *);
273#endif
274
275static inline unsigned int __mingw_statusfp(void)
276{
277 unsigned int flags = 0;
278#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
279 unsigned int x86_sw, sse2_sw = 0;
280 __mingw_setfp(NULL, 0, &x86_sw, 0);
281 if (__mingw_has_sse())
282 __mingw_setfp_sse(NULL, 0, &sse2_sw, 0);
283 flags = x86_sw | sse2_sw;
284#else
285 __mingw_setfp(NULL, 0, &flags, 0);
286#endif
287 return flags;
288}
289
290/* Use naked functions only on Clang. GCC doesn’t support them on ARM targets and
291 * has broken behavior on x86_64 by emitting .seh_endprologue. */
292#ifndef __clang__
293
294#define __ASM_DEFINE_FUNC(rettype, name, args, code) \
295 asm(".text\n\t" \
296 ".p2align 2\n\t" \
297 ".globl " __MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) "\n\t" \
298 ".def " __MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) "; .scl 2; .type 32; .endef\n\t" \
299 __MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) ":\n\t" \
300 code "\n\t");
301
302#else
303
304#define __ASM_DEFINE_FUNC(rettype, name, args, code) \
305 rettype __attribute__((naked)) name args { \
306 asm(code "\n\t"); \
307 }
308
309#endif
310
157311#ifdef __cplusplus
158312}
159313#endif
lib/libc/mingw/intrincs/RtlSecureZeroMemory.c+1-1
......@@ -4,7 +4,7 @@
44PVOID WINAPI RtlSecureZeroMemory(PVOID ptr,SIZE_T cnt)
55{
66 volatile char *vptr = (volatile char *)ptr;
7#ifdef __x86_64
7#if defined(__x86_64__) && !defined(__arm64ec__)
88 __stosb ((PBYTE)((DWORD64)vptr),0,cnt);
99#else
1010 while (cnt != 0)
lib/libc/mingw/libsrc/uuid.c+1
......@@ -15,6 +15,7 @@
1515#include <basetyps.h>
1616
1717#include <credentialprovider.h>
18#include <httprequest.h>
1819#include <functiondiscoverykeys.h>
1920#include <textstor.h>
2021#include <shobjidl.h>
lib/libc/mingw/libsrc/ws2tcpip/in6_set_addr_loopback.c+1-1
......@@ -8,6 +8,6 @@
88
99void IN6_SET_ADDR_LOOPBACK(struct in6_addr *a)
1010{
11 memset(a->s6_bytes, 0, sizeof(struct in6_addr));
11 *a = (struct in6_addr){0};
1212 a->s6_bytes[15] = 1;
1313}
lib/libc/mingw/libsrc/ws2tcpip/in6_set_addr_unspecified.c+1-1
......@@ -8,5 +8,5 @@
88
99void IN6_SET_ADDR_UNSPECIFIED(struct in6_addr *a)
1010{
11 memset(a->s6_bytes, 0, sizeof(struct in6_addr));
11 *a = (struct in6_addr){0};
1212}
lib/libc/mingw/libsrc/ws2tcpip/in6addr_setany.c+1-4
......@@ -6,14 +6,11 @@
66#include <winsock2.h>
77#include <ws2tcpip.h>
88
9#undef IN6_SET_ADDR_UNSPECIFIED
10#define IN6_SET_ADDR_UNSPECIFIED(a) memset((a)->s6_bytes,0,sizeof(struct in6_addr))
11
129void IN6ADDR_SETANY(struct sockaddr_in6 *a)
1310{
1411 a->sin6_family = AF_INET6;
1512 a->sin6_port = 0;
1613 a->sin6_flowinfo = 0;
17 IN6_SET_ADDR_UNSPECIFIED(&a->sin6_addr);
14 a->sin6_addr = (struct in6_addr){0};
1815 a->sin6_scope_id = 0;
1916}
lib/libc/mingw/libsrc/ws2tcpip/in6addr_setloopback.c-7
......@@ -6,13 +6,6 @@
66#include <winsock2.h>
77#include <ws2tcpip.h>
88
9#undef IN6_SET_ADDR_LOOPBACK
10#define IN6_SET_ADDR_LOOPBACK(a) \
11 do { \
12 memset((a)->s6_bytes,0,sizeof(struct in6_addr));\
13 (a)->s6_bytes[15] = 1; \
14 } while (0)
15
169void IN6ADDR_SETLOOPBACK(struct sockaddr_in6 *a)
1710{
1811 a->sin6_family = AF_INET6;
lib/libc/mingw/math/arm-common/ldexpl.c-4
......@@ -8,9 +8,5 @@
88
99long double ldexpl(long double x, int n)
1010{
11#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
1211 return ldexp(x, n);
13#else
14#error Not supported on your platform yet
15#endif
1612}
lib/libc/mingw/math/arm-common/sincosl.c created+13
......@@ -0,0 +1,13 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <math.h>
8
9void sincosl(long double x, long double *s, long double *c)
10{
11 *s = sinl(x);
12 *c = cosl(x);
13}
lib/libc/mingw/math/arm/_chgsignl.S deleted-16
......@@ -1,16 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <_mingw_mac.h>
8
9 .file "_chgignl.S"
10 .text
11 .align 4
12 .globl __MINGW_USYMBOL(_chgsignl)
13 .def __MINGW_USYMBOL(_chgsignl); .scl 2; .type 32; .endef
14__MINGW_USYMBOL(_chgsignl):
15 vneg.f64 d0, d0
16 bx lr
lib/libc/mingw/math/arm64/_chgsignl.S deleted-16
......@@ -1,16 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <_mingw_mac.h>
8
9 .file "_chgignl.S"
10 .text
11 .align 2
12 .globl __MINGW_USYMBOL(_chgsignl)
13 .def __MINGW_USYMBOL(_chgsignl); .scl 2; .type 32; .endef
14__MINGW_USYMBOL(_chgsignl):
15 fneg d0, d0
16 ret
lib/libc/mingw/math/cephes_mconf.h+2-2
......@@ -66,7 +66,7 @@ extern double __QNAN;
6666#endif
6767
6868/*long double*/
69#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
69#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
7070#define MAXNUML 1.7976931348623158E308
7171#define MAXLOGL 7.09782712893383996843E2
7272#define MINLOGL -7.08396418532264106224E2
......@@ -84,7 +84,7 @@ extern double __QNAN;
8484#define PIL 3.1415926535897932384626L
8585#define PIO2L 1.5707963267948966192313L
8686#define PIO4L 7.8539816339744830961566E-1L
87#endif /* defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_) */
87#endif /* __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ */
8888
8989#define isfinitel isfinite
9090#define isinfl isinf
lib/libc/mingw/math/coshl.c+1-1
......@@ -5,7 +5,7 @@
55 */
66#include "cephes_mconf.h"
77
8#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
8#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
99#include <math.h>
1010
1111long double coshl(long double x)
lib/libc/mingw/math/erfl.c+1-1
......@@ -108,7 +108,7 @@ Copyright 1984, 1995 by Stephen L. Moshier
108108
109109long double erfl(long double x);
110110
111#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
111#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
112112long double erfcl(long double x)
113113{
114114 return erfc(x);
lib/libc/mingw/math/fmal.c+1-1
......@@ -5,7 +5,7 @@
55 */
66long double fmal(long double x, long double y, long double z);
77
8#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
8#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
99
1010double fma(double x, double y, double z);
1111
lib/libc/mingw/math/fp_constsl.c+1-1
......@@ -16,7 +16,7 @@ const union _ieee_rep __DENORML = { __LONG_DOUBLE_DENORM_REP };
1616long double nanl (const char *);
1717long double nanl (const char * tagp __attribute__((unused)) )
1818{
19#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
19#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
2020 return nan("");
2121#else
2222 return __QNANL.ldouble_val;
lib/libc/mingw/math/fpclassifyl.c+3-3
......@@ -6,7 +6,9 @@
66#include <math.h>
77
88int __fpclassifyl (long double _x){
9#if defined(__x86_64__) || defined(_AMD64_)
9#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
10 return __fpclassify(_x);
11#elif defined(_AMD64_) || defined(__x86_64__)
1012 __mingw_ldbl_type_t hlp;
1113 unsigned int e;
1214 hlp.x = _x;
......@@ -23,8 +25,6 @@ int __fpclassifyl (long double _x){
2325 return (((hlp.lh.high & 0x7fffffff) | hlp.lh.low) == 0 ?
2426 FP_INFINITE : FP_NAN);
2527 return FP_NORMAL;
26#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
27 return __fpclassify(_x);
2828#elif defined(__i386__) || defined(_X86_)
2929 unsigned short sw;
3030 __asm__ __volatile__ (
lib/libc/mingw/math/frexpl.c+1-1
......@@ -5,7 +5,7 @@
55 */
66long double frexpl(long double value, int* exp);
77
8#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
8#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
99
1010double frexp(double value, int* exp);
1111
lib/libc/mingw/math/isnanl.c+3-3
......@@ -8,7 +8,9 @@
88int
99__isnanl (long double _x)
1010{
11#if defined(__x86_64__) || defined(_AMD64_)
11#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
12 return __isnan(_x);
13#elif defined(__x86_64__) || defined(_AMD64_)
1214 __mingw_ldbl_type_t ld;
1315 int xx, signexp;
1416
......@@ -18,8 +20,6 @@ __isnanl (long double _x)
1820 signexp |= (unsigned int) (xx | (-xx)) >> 31;
1921 signexp = 0xfffe - signexp;
2022 return (int) ((unsigned int) signexp) >> 16;
21#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
22 return __isnan(_x);
2323#elif defined(__i386__) || defined(_X86_)
2424 unsigned short _sw;
2525 __asm__ __volatile__ ("fxam;"
lib/libc/mingw/math/lgammal.c+1-1
......@@ -5,7 +5,7 @@
55 */
66#include "cephes_mconf.h"
77
8#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
8#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
99double lgamma(double x);
1010
1111long double lgammal(long double x)
lib/libc/mingw/math/llrintl.c+2-1
......@@ -9,7 +9,8 @@
99long long llrintl (long double x)
1010{
1111 long long retval = 0ll;
12#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
12#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__)) || \
13 defined(_X86_) || defined(__i386__)
1314 __asm__ __volatile__ ("fistpll %0" : "=m" (retval) : "t" (x) : "st");
1415#else
1516 int mode = fegetround();
lib/libc/mingw/math/lrintl.c+3-3
......@@ -8,10 +8,10 @@
88long lrintl (long double x)
99{
1010 long retval = 0l;
11#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
12 __asm__ __volatile__ ("fistpl %0" : "=m" (retval) : "t" (x) : "st");
13#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
11#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
1412 retval = lrint(x);
13#elif defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
14 __asm__ __volatile__ ("fistpl %0" : "=m" (retval) : "t" (x) : "st");
1515#endif
1616 return retval;
1717}
lib/libc/mingw/math/modff.c+1-1
......@@ -13,7 +13,7 @@ modff (float value, float* iptr)
1313 float int_part = 0.0F;
1414 /* truncate */
1515 /* truncate */
16#if defined(_AMD64_) || defined(__x86_64__)
16#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__))
1717 asm volatile ("subq $8, %%rsp\n"
1818 "fnstcw 4(%%rsp)\n"
1919 "movzwl 4(%%rsp), %%eax\n"
lib/libc/mingw/math/modfl.c+1-1
......@@ -12,7 +12,7 @@ modfl (long double value, long double* iptr)
1212{
1313 long double int_part = 0.0L;
1414 /* truncate */
15#if defined(_AMD64_) || defined(__x86_64__)
15#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__))
1616 asm volatile ("subq $8, %%rsp\n"
1717 "fnstcw 4(%%rsp)\n"
1818 "movzwl 4(%%rsp), %%eax\n"
lib/libc/mingw/math/rintl.c+3-3
......@@ -7,10 +7,10 @@
77
88long double rintl (long double x) {
99 long double retval = 0.0L;
10#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
11 __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
12#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
10#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
1311 retval = rint(x);
12#elif defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
13 __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
1414#endif
1515 return retval;
1616}
lib/libc/mingw/math/signbitl.c+2-2
......@@ -9,11 +9,11 @@
99
1010
1111int __signbitl (long double x) {
12#if defined(__x86_64__) || defined(_AMD64_)
12#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__))
1313 __mingw_ldbl_type_t ld;
1414 ld.x = x;
1515 return ((ld.lh.sign_exponent & 0x8000) != 0);
16#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
16#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_) || defined(__arm64ec__) || defined(_ARM64EC_)
1717 return __signbit(x);
1818#elif defined(__i386__) || defined(_X86_)
1919 unsigned short sw;
lib/libc/mingw/math/sinhl.c+1-1
......@@ -6,7 +6,7 @@
66#include "cephes_mconf.h"
77#include <errno.h>
88
9#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
9#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
1010#include <math.h>
1111
1212long double sinhl(long double x)
lib/libc/mingw/math/sqrt.def.h+1-1
......@@ -77,7 +77,7 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
7777#else
7878 asm volatile ("fsqrtd %[dst], %[src];\n" : [dst] "=w" (res) : [src] "w" (x));
7979#endif
80#elif defined(__aarch64__) || defined(_ARM64_)
80#elif defined(__aarch64__) || defined(_ARM64_) || defined(__arm64ec__) || defined(_ARM64EC_)
8181#if _NEW_COMPLEX_FLOAT
8282 asm volatile ("fsqrt %s[dst], %s[src]\n" : [dst] "=w" (res) : [src] "w" (x));
8383#else
lib/libc/mingw/math/tanhl.c+1-1
......@@ -8,7 +8,7 @@
88#define _SET_ERRNO(x)
99#endif
1010
11#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
11#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
1212#include <math.h>
1313
1414long double tanhl(long double x)
lib/libc/mingw/math/tgammal.c+1-1
......@@ -5,7 +5,7 @@
55 */
66#include "cephes_mconf.h"
77
8#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
8#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
99double tgamma(double x);
1010
1111long double tgammal(long double x)
lib/libc/mingw/math/truncl.c+3-4
......@@ -3,21 +3,20 @@
33 * This file is part of the mingw-w64 runtime package.
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
6#include <fenv.h>
6
77#include <math.h>
88
99long double
1010truncl (long double _x)
1111{
12#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
12#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
1313 return trunc(_x);
1414#else
1515 long double retval = 0.0L;
1616 unsigned short saved_cw;
1717 unsigned short tmp_cw;
1818 __asm__ __volatile__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
19 tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
20 | FE_TOWARDZERO;
19 tmp_cw = saved_cw | 0xc00; /* round towards zero */
2120 __asm__ __volatile__ ("fldcw %0;" : : "m" (tmp_cw));
2221 __asm__ __volatile__ ("frndint;" : "=t" (retval) : "0" (_x)); /* round towards zero */
2322 __asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
lib/libc/mingw/math/x86/pow.def.h-3
......@@ -69,11 +69,8 @@
6969#include "../complex/complex_internal.h"
7070#include <errno.h>
7171#include <limits.h>
72#include <fenv.h>
7372#include <math.h>
7473#include <errno.h>
75#define FE_ROUNDING_MASK \
76 (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
7774
7875static __FLT_TYPE
7976internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr)
lib/libc/mingw/misc/dllentrypoint.c deleted-18
......@@ -1,18 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <oscalls.h>
8#define _DECL_DLLMAIN
9#include <process.h>
10
11BOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID);
12
13BOOL WINAPI DllEntryPoint (HANDLE __UNUSED_PARAM(hDllHandle),
14 DWORD __UNUSED_PARAM(dwReason),
15 LPVOID __UNUSED_PARAM(lpreserved))
16{
17 return TRUE;
18}
lib/libc/mingw/misc/feclearexcept.c+7-33
......@@ -4,44 +4,18 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#include <fenv.h>
87#include <internal.h>
98
109/* 7.6.2.1
1110 The feclearexcept function clears the supported exceptions
1211 represented by its argument. */
1312
14int feclearexcept (int excepts)
13int feclearexcept(int flags)
1514{
16 fenv_t _env;
17#if defined(_ARM_) || defined(__arm__)
18 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
19 _env.__cw &= ~(excepts & FE_ALL_EXCEPT);
20 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
21#elif defined(_ARM64_) || defined(__aarch64__)
22 unsigned __int64 fpcr;
23 (void) _env;
24 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
25 fpcr &= ~(excepts & FE_ALL_EXCEPT);
26 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
27#else
28 int _mxcsr;
29 if (excepts == FE_ALL_EXCEPT)
30 {
31 __asm__ volatile ("fnclex");
32 }
33 else
34 {
35 __asm__ volatile ("fnstenv %0" : "=m" (_env));
36 _env.__status_word &= ~(excepts & FE_ALL_EXCEPT);
37 __asm__ volatile ("fldenv %0" : : "m" (_env));
38 }
39 if (__mingw_has_sse ())
40 {
41 __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr));
42 _mxcsr &= ~(((excepts & FE_ALL_EXCEPT)));
43 __asm__ volatile ("ldmxcsr %0" : : "m" (_mxcsr));
44 }
45#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
46 return (0);
15 fenv_t env;
16
17 fegetenv(&env);
18 flags &= FE_ALL_EXCEPT;
19 env._Fe_stat &= ~fenv_encode(flags, flags);
20 return fesetenv(&env);
4721}
lib/libc/mingw/misc/fegetenv.c+11-20
......@@ -4,34 +4,25 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#include <fenv.h>
87#include <internal.h>
98
109/* 7.6.4.1
1110 The fegetenv function stores the current floating-point environment
1211 in the object pointed to by envp. */
1312
14int fegetenv (fenv_t * envp)
13int fegetenv(fenv_t *env)
1514{
16#if defined(_ARM_) || defined(__arm__)
17 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (*envp));
18#elif defined(_ARM64_) || defined(__aarch64__)
19 unsigned __int64 fpcr;
20 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
21 envp->__cw = fpcr;
15#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
16 unsigned int x87, sse;
17 __mingw_control87_2(0, 0, &x87, &sse);
18 env->_Fe_ctl = fenv_encode(x87, sse);
19 __mingw_setfp(NULL, 0, &x87, 0);
20 __mingw_setfp_sse(NULL, 0, &sse, 0);
21 env->_Fe_stat = fenv_encode(x87, sse);
2222#else
23 __asm__ __volatile__ ("fnstenv %0;": "=m" (*envp));
24 /* fnstenv sets control word to non-stop for all exceptions, so we
25 need to reload our env to restore the original mask. */
26 __asm__ __volatile__ ("fldenv %0" : : "m" (*envp));
27 if (__mingw_has_sse ())
28 {
29 int _mxcsr;
30 __asm__ __volatile__ ("stmxcsr %0" : "=m" (_mxcsr));
31 envp->__unused0 = (((unsigned int) _mxcsr) >> 16);
32 envp->__unused1 = (((unsigned int) _mxcsr) & 0xffff);
33 }
34#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
23 env->_Fe_ctl = fenv_encode(0, __mingw_controlfp(0, 0));
24 env->_Fe_stat = fenv_encode(0, __mingw_statusfp());
25#endif
3526 return 0;
3627}
3728
lib/libc/mingw/misc/fegetexceptflag.c+9-20
......@@ -12,26 +12,15 @@
1212 representation of the exception flags indicated by the argument
1313 excepts in the object pointed to by the argument flagp. */
1414
15int fegetexceptflag (fexcept_t * flagp, int excepts)
15int fegetexceptflag(fexcept_t *status, int excepts)
1616{
17#if defined(_ARM_) || defined(__arm__)
18 fenv_t _env;
19 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
20 *flagp = _env.__cw & excepts & FE_ALL_EXCEPT;
21#elif defined(_ARM64_) || defined(__aarch64__)
22 unsigned __int64 fpcr;
23 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
24 *flagp = fpcr & excepts & FE_ALL_EXCEPT;
17#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
18 unsigned int x87, sse;
19 __mingw_setfp(NULL, 0, &x87, 0);
20 __mingw_setfp_sse(NULL, 0, &sse, 0);
21 *status = fenv_encode(x87 & excepts, sse & excepts);
2522#else
26 int _mxcsr;
27 unsigned short _status;
28
29 __asm__ volatile ("fnstsw %0" : "=am" (_status));
30 _mxcsr = 0;
31 if (__mingw_has_sse ())
32 __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr));
33
34 *flagp = (_mxcsr | _status) & excepts & FE_ALL_EXCEPT;
35#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
36 return 0;
23 *status = fenv_encode(0, __mingw_statusfp() & excepts);
24#endif
25 return 0;
3726}
lib/libc/mingw/misc/fegetround.c+3-16
......@@ -3,26 +3,13 @@
33 * This file is part of the mingw-w64 runtime package.
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
6#include <fenv.h>
6#include <internal.h>
77
88/* 7.6.3.1
99 The fegetround function returns the value of the rounding direction
1010 macro representing the current rounding direction. */
1111
12int
13fegetround (void)
12int fegetround(void)
1413{
15#if defined(_ARM_) || defined(__arm__)
16 fenv_t _env;
17 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
18 return (_env.__cw & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
19#elif defined(_ARM64_) || defined(__aarch64__)
20 unsigned __int64 fpcr;
21 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
22 return (fpcr & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
23#else
24 int _control;
25 __asm__ volatile ("fnstcw %0" : "=m" (*&_control));
26 return (_control & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
27#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
14 return __mingw_controlfp(0, 0) & _MCW_RC;
2815}
lib/libc/mingw/misc/feholdexcept.c+3-20
......@@ -11,25 +11,8 @@
1111 flags, and then installs a non-stop (continue on exceptions) mode,
1212 if available, for all exceptions. */
1313
14int feholdexcept (fenv_t * envp)
14int feholdexcept(fenv_t *env)
1515{
16#if defined(_ARM_) || defined(__arm__)
17 fenv_t _env;
18 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
19 envp->__cw = _env.__cw;
20 _env.__cw &= ~(FE_ALL_EXCEPT);
21 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
22#elif defined(_ARM64_) || defined(__aarch64__)
23 unsigned __int64 fpcr;
24 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
25 envp->__cw = fpcr;
26 fpcr &= ~(FE_ALL_EXCEPT);
27 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
28#else
29 __asm__ __volatile__ ("fnstenv %0;" : "=m" (* envp)); /* save current into envp */
30 /* fnstenv sets control word to non-stop for all exceptions, so all we
31 need to do is clear the exception flags. */
32 __asm__ __volatile__ ("fnclex");
33#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
34 return 0;
16 fegetenv(env);
17 return feclearexcept(FE_ALL_EXCEPT);
3518}
lib/libc/mingw/misc/feraiseexcept.c+12-20
......@@ -3,7 +3,7 @@
33 * This file is part of the mingw-w64 runtime package.
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
6#include <fenv.h>
6#include <internal.h>
77
88/* 7.6.2.3
99 The feraiseexcept function raises the supported exceptions
......@@ -13,24 +13,16 @@
1313 the inexact exception whenever it raises the overflow
1414 or underflow exception is implementation-defined. */
1515
16int feraiseexcept (int excepts)
16int feraiseexcept(int flags)
1717{
18 fenv_t _env;
19#if defined(_ARM_) || defined(__arm__)
20 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
21 _env.__cw |= excepts & FE_ALL_EXCEPT;
22 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
23#elif defined(_ARM64_) || defined(__aarch64__)
24 unsigned __int64 fpcr;
25 (void) _env;
26 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
27 fpcr |= excepts & FE_ALL_EXCEPT;
28 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
29#else
30 __asm__ volatile ("fnstenv %0;" : "=m" (_env));
31 _env.__status_word |= excepts & FE_ALL_EXCEPT;
32 __asm__ volatile ("fldenv %0;"
33 "fwait;" : : "m" (_env));
34#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
35 return 0;
18 fenv_t env;
19
20 flags &= FE_ALL_EXCEPT;
21 fegetenv(&env);
22 env._Fe_stat |= fenv_encode(flags, flags);
23 fesetenv(&env);
24#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
25 __asm__ volatile ("fwait\n\t");
26#endif
27 return 0;
3628}
lib/libc/mingw/misc/fesetenv.c+35-56
......@@ -4,11 +4,24 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#include <_mingw.h>
8#include <fenv.h>
9#include <float.h>
107#include <internal.h>
118
9/* The FE_DFL_ENV macro is required by standard.
10 fesetenv will use the environment set at app startup.*/
11const fenv_t __mingw_fe_dfl_env = { 0, 0 };
12
13/* The C99 standard (7.6.9) allows us to define implementation-specific macros for
14 different fp environments */
15#if defined(__i386__) || defined(__x86_64__)
16
17/* The default Intel x87 floating point environment (64-bit mantissa) */
18const fenv_t __mingw_fe_pc64_env = { 0x3f3f003f, 0 };
19
20/* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
21const fenv_t __mingw_fe_pc53_env = { 0x3f3f103f, 0 };
22
23#endif
24
1225/* 7.6.4.3
1326 The fesetenv function establishes the floating-point environment
1427 represented by the object pointed to by envp. The argument envp
......@@ -22,61 +35,27 @@
2235extern void (* __MINGW_IMP_SYMBOL(_fpreset))(void);
2336extern void _fpreset(void);
2437
25int fesetenv (const fenv_t * envp)
38int fesetenv(const fenv_t *env)
2639{
27#if defined(_ARM_) || defined(__arm__)
28 if (envp == FE_DFL_ENV)
29 /* Use the choice made at app startup */
30 _fpreset();
31 else
32 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (*envp));
33#elif defined(_ARM64_) || defined(__aarch64__)
34 if (envp == FE_DFL_ENV) {
35 /* Use the choice made at app startup */
36 _fpreset();
37 } else {
38 unsigned __int64 fpcr = envp->__cw;
39 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
40 }
41#else
42 if (envp == FE_PC64_ENV)
43 /*
44 * fninit initializes the control register to 0x37f,
45 * the status register to zero and the tag word to 0FFFFh.
46 * The other registers are unaffected.
47 */
48 __asm__ __volatile__ ("fninit");
40 unsigned int x87_cw, cw, x87_stat, stat;
41 unsigned int mask = ~0u;
4942
50 else if (envp == FE_PC53_ENV)
51 /*
52 * MS _fpreset() does same *except* it sets control word
53 * to 0x27f (53-bit precision).
54 * We force calling _fpreset in msvcrt.dll
55 */
56
57 (* __MINGW_IMP_SYMBOL(_fpreset))();
58
59 else if (envp == FE_DFL_ENV)
60 /* Use the choice made at app startup */
61 _fpreset();
62
63 else
64 {
65 fenv_t env = *envp;
66 int has_sse = __mingw_has_sse ();
67 int _mxcsr;
68 /*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1; *//* mxcsr low and high */
69 if (has_sse)
70 __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
71 env.__unused0 = 0xffff;
72 env.__unused1 = 0xffff;
73 __asm__ volatile ("fldenv %0" : : "m" (env)
74 : "st", "st(1)", "st(2)", "st(3)", "st(4)",
75 "st(5)", "st(6)", "st(7)");
76 if (has_sse)
77 __asm__ volatile ("ldmxcsr %0" : : "m" (*&_mxcsr));
43 if (!env->_Fe_ctl && !env->_Fe_stat) {
44 _fpreset();
45 return 0;
7846 }
7947
80#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
81 return 0;
48 if (!fenv_decode(env->_Fe_ctl, &x87_cw, &cw))
49 return 1;
50 if (!fenv_decode(env->_Fe_stat, &x87_stat, &stat))
51 return 1;
52
53#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
54 __mingw_setfp(&x87_cw, mask, &x87_stat, ~0);
55 if (__mingw_has_sse())
56 __mingw_setfp_sse(&cw, mask, &stat, ~0);
57#else
58 __mingw_setfp(&cw, mask, &stat, ~0);
59#endif
60 return 0;
8261}
lib/libc/mingw/misc/fesetexceptflag.c+9-33
......@@ -4,7 +4,6 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#include <fenv.h>
87#include <internal.h>
98
109/* 7.6.2.4
......@@ -16,39 +15,16 @@
1615 represented by the argument excepts. This function does not raise
1716 exceptions, but only sets the state of the flags. */
1817
19int fesetexceptflag (const fexcept_t * flagp, int excepts)
18int fesetexceptflag(const fexcept_t *status, int excepts)
2019{
21 fenv_t _env;
20 fenv_t env;
2221
23 excepts &= FE_ALL_EXCEPT;
22 excepts &= FE_ALL_EXCEPT;
23 if(!excepts)
24 return 0;
2425
25#if defined(_ARM_) || defined(__arm__)
26 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
27 _env.__cw &= ~excepts;
28 _env.__cw |= (*flagp & excepts);
29 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
30#elif defined(_ARM64_) || defined(__aarch64__)
31 unsigned __int64 fpcr;
32 (void) _env;
33 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
34 fpcr &= ~excepts;
35 fpcr |= (*flagp & excepts);
36 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
37#else
38 __asm__ volatile ("fnstenv %0;" : "=m" (_env));
39 _env.__status_word &= ~excepts;
40 _env.__status_word |= (*flagp & excepts);
41 __asm__ volatile ("fldenv %0;" : : "m" (_env));
42
43 if (__mingw_has_sse ())
44 {
45 int sse_cw;
46 __asm__ volatile ("stmxcsr %0;" : "=m" (sse_cw));
47 sse_cw &= ~(excepts << 7);
48 sse_cw |= ((*flagp & excepts) << 7);
49 __asm__ volatile ("ldmxcsr %0" : : "m" (sse_cw));
50 }
51
52#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
53 return 0;
26 fegetenv(&env);
27 env._Fe_stat &= ~fenv_encode(excepts, excepts);
28 env._Fe_stat |= *status & fenv_encode(excepts, excepts);
29 return fesetenv(&env);
5430}
lib/libc/mingw/misc/fesetround.c+5-38
......@@ -13,43 +13,10 @@
1313 to the value of a rounding direction macro, the rounding direction
1414 is not changed. */
1515
16int fesetround (int mode)
16int fesetround(int round_mode)
1717{
18#if defined(_ARM_) || defined(__arm__)
19 fenv_t _env;
20 if ((mode & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)) != 0)
21 return -1;
22 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
23 _env.__cw &= ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO);
24 _env.__cw |= mode;
25 __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
26#elif defined(_ARM64_) || defined(__aarch64__)
27 unsigned __int64 fpcr;
28 if ((mode & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)) != 0)
29 return -1;
30 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
31 fpcr &= ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO);
32 fpcr |= mode;
33 __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
34#else
35 unsigned short _cw;
36 if ((mode & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
37 != 0)
38 return -1;
39 __asm__ volatile ("fnstcw %0;": "=m" (*&_cw));
40 _cw &= ~0xc00;
41 _cw |= mode;
42 __asm__ volatile ("fldcw %0;" : : "m" (*&_cw));
43
44 if (__mingw_has_sse ())
45 {
46 int mxcsr;
47
48 __asm__ volatile ("stmxcsr %0" : "=m" (*&mxcsr));
49 mxcsr &= ~0x6000;
50 mxcsr |= mode << 3;
51 __asm__ volatile ("ldmxcsr %0" : : "m" (*&mxcsr));
52 }
53#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
54 return 0;
18 if (round_mode & (~_MCW_RC))
19 return 1;
20 __mingw_controlfp(round_mode, _MCW_RC);
21 return 0;
5522}
lib/libc/mingw/misc/fetestexcept.c+2-21
......@@ -15,26 +15,7 @@
1515 exception macros corresponding to the currently set exceptions
1616 included in excepts. */
1717
18int fetestexcept (int excepts)
18int fetestexcept(int flags)
1919{
20#if defined(_ARM_) || defined(__arm__)
21 fenv_t _env;
22 __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
23 return _env.__cw & excepts & FE_ALL_EXCEPT;
24#elif defined(_ARM64_) || defined(__aarch64__)
25 unsigned __int64 fpcr;
26 __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
27 return fpcr & excepts & FE_ALL_EXCEPT;
28#else
29 unsigned short _sw;
30 __asm__ __volatile__ ("fnstsw %%ax" : "=a" (_sw));
31
32 if (__mingw_has_sse ())
33 {
34 int sse_sw;
35 __asm__ __volatile__ ("stmxcsr %0;" : "=m" (sse_sw));
36 _sw |= sse_sw;
37 }
38 return _sw & excepts & FE_ALL_EXCEPT;
39#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
20 return __mingw_statusfp() & flags;
4021}
lib/libc/mingw/misc/feupdateenv.c+3-7
......@@ -13,13 +13,9 @@
1313 set by a call to feholdexcept or fegetenv, or equal the macro
1414 FE_DFL_ENV or an implementation-defined environment macro. */
1515
16/* FIXME: this works but surely there must be a better way. */
17
18int feupdateenv (const fenv_t * envp)
16int feupdateenv(const fenv_t *env)
1917{
20 unsigned int _fexcept = fetestexcept (FE_ALL_EXCEPT); /*save excepts */
21 fesetenv (envp); /* install the env */
22 feraiseexcept (_fexcept); /* raise the except */
23 return 0;
18 int except = fetestexcept(FE_ALL_EXCEPT);
19 return fesetenv(env) || feraiseexcept(except);
2420}
2521
lib/libc/mingw/misc/ftw.c+18-16
......@@ -15,11 +15,9 @@
1515#include <dirent.h>
1616#include <ftw.h>
1717
18#ifdef IMPL_FTW64
19#define stat stat64
20#define nftw nftw64
21#define ftw ftw64
22#endif
18int __cdecl stat32(const char *_Filename, struct _stat32 *_Stat);
19int __cdecl stat32i64(const char *_Filename, struct _stat32i64 *_Stat);
20int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat);
2321
2422typedef struct dir_data_t {
2523 DIR *h;
......@@ -36,14 +34,14 @@ typedef struct ctx_t {
3634 dir_data_t **dirs;
3735 char *buf;
3836 struct FTW ftw;
39 int (*fcb) (const char *, const struct stat *, int , struct FTW *);
37 int (*fcb) (const char *, const STRUCT_STAT *, int , struct FTW *);
4038 size_t cur_dir, msz_dir, buf_sz;
4139 int flags;
4240 dev_t dev;
4341} ctx_t;
4442
4543static int add_object (ctx_t *);
46static int do_dir (ctx_t *, struct stat *, dir_data_t *);
44static int do_dir (ctx_t *, STRUCT_STAT *, dir_data_t *);
4745static int do_entity (ctx_t *, dir_data_t *, const char *, size_t);
4846static int do_it (const char *, int, void *, int, int);
4947
......@@ -225,7 +223,7 @@ open_directory (ctx_t *ctx, dir_data_t *dirp)
225223static int
226224do_entity (ctx_t *ctx, dir_data_t *dir, const char *name, size_t namlen)
227225{
228 struct stat st;
226 STRUCT_STAT st;
229227 char *h;
230228 size_t cnt_sz;
231229 int ret = 0, flag = 0;
......@@ -249,7 +247,7 @@ do_entity (ctx_t *ctx, dir_data_t *dir, const char *name, size_t namlen)
249247
250248 name = ctx->buf;
251249
252 if (stat (name, &st) < 0)
250 if (FUNC_STAT (name, &st) < 0)
253251 {
254252 if (errno != EACCES && errno != ENOENT)
255253 ret = -1;
......@@ -257,7 +255,7 @@ do_entity (ctx_t *ctx, dir_data_t *dir, const char *name, size_t namlen)
257255 flag = FTW_NS;
258256
259257 if (!(ctx->flags & FTW_PHYS))
260 stat (name, &st);
258 FUNC_STAT (name, &st);
261259 }
262260 else
263261 flag = (S_ISDIR (st.st_mode) ? FTW_D : FTW_F);
......@@ -281,7 +279,7 @@ do_entity (ctx_t *ctx, dir_data_t *dir, const char *name, size_t namlen)
281279
282280
283281static int
284do_dir (ctx_t *ctx, struct stat *st, __UNUSED_PARAM(dir_data_t *old_dir))
282do_dir (ctx_t *ctx, STRUCT_STAT *st, __UNUSED_PARAM(dir_data_t *old_dir))
285283{
286284 dir_data_t dir;
287285 struct dirent *d;
......@@ -378,7 +376,7 @@ static int
378376do_it (const char *dir, __UNUSED_PARAM(int is_nftw), void *fcb, int descriptors, int flags)
379377{
380378 struct ctx_t ctx;
381 struct stat st;
379 STRUCT_STAT st;
382380 int ret = 0;
383381 int sv_e;
384382 char *cp;
......@@ -417,12 +415,12 @@ do_it (const char *dir, __UNUSED_PARAM(int is_nftw), void *fcb, int descriptors,
417415 ctx.ftw.level = 0;
418416 ctx.ftw.base = cp - ctx.buf;
419417 ctx.flags = flags;
420 ctx.fcb = (int (*) (const char *, const struct stat *, int , struct FTW *)) fcb;
418 ctx.fcb = (int (*) (const char *, const STRUCT_STAT *, int , struct FTW *)) fcb;
421419 ctx.objs = NULL;
422420
423421 if (!ret)
424422 {
425 if (stat (ctx.buf, &st) < 0)
423 if (FUNC_STAT (ctx.buf, &st) < 0)
426424 ret = -1;
427425 else if (S_ISDIR (st.st_mode))
428426 {
......@@ -451,13 +449,17 @@ do_it (const char *dir, __UNUSED_PARAM(int is_nftw), void *fcb, int descriptors,
451449}
452450
453451int
454ftw (const char *path, int (*fcb) (const char *, const struct stat *, int), int descriptors)
452FUNC_FTW (const char *path, int (*fcb) (const char *, const STRUCT_STAT *, int), int descriptors);
453int
454FUNC_FTW (const char *path, int (*fcb) (const char *, const STRUCT_STAT *, int), int descriptors)
455455{
456456 return do_it (path, 0, fcb, descriptors, 0);
457457}
458458
459459int
460nftw (const char *path, int (*fcb) (const char *, const struct stat *, int , struct FTW *), int descriptors, int flags)
460FUNC_NFTW (const char *path, int (*fcb) (const char *, const STRUCT_STAT *, int , struct FTW *), int descriptors, int flags);
461int
462FUNC_NFTW (const char *path, int (*fcb) (const char *, const STRUCT_STAT *, int , struct FTW *), int descriptors, int flags)
461463{
462464 return do_it (path, 1, fcb, descriptors, flags);
463465}
lib/libc/mingw/misc/ftw32.c created+19
......@@ -0,0 +1,19 @@
1/**
2 * This file is part of the mingw-w64 runtime package.
3 * No warranty is given; refer to the file DISCLAIMER within this package.
4 */
5
6#define FUNC_FTW ftw32
7#define FUNC_NFTW nftw32
8#define FUNC_STAT stat32
9#define STRUCT_STAT struct _stat32
10#include "ftw.c"
11
12/* On 32-bit systems is stat ABI compatible with stat32 */
13#ifndef _WIN64
14#undef nftw
15#undef ftw
16struct stat;
17int __attribute__ ((alias ("nftw32"))) __cdecl nftw(const char *, int (*) (const char *, const struct stat *, int, struct FTW *), int, int);
18int __attribute__ ((alias ("ftw32"))) __cdecl ftw(const char *, int (*) (const char *, const struct stat *, int), int);
19#endif
lib/libc/mingw/misc/ftw32i64.c created+10
......@@ -0,0 +1,10 @@
1/**
2 * This file is part of the mingw-w64 runtime package.
3 * No warranty is given; refer to the file DISCLAIMER within this package.
4 */
5
6#define FUNC_FTW ftw32i64
7#define FUNC_NFTW nftw32i64
8#define FUNC_STAT stat32i64
9#define STRUCT_STAT struct _stat32i64
10#include "ftw.c"
lib/libc/mingw/misc/ftw64.c+4-2
......@@ -3,6 +3,8 @@
33 * No warranty is given; refer to the file DISCLAIMER within this package.
44 */
55
6#define IMPL_FTW64 1
7
6#define FUNC_FTW ftw64
7#define FUNC_NFTW nftw64
8#define FUNC_STAT stat64
9#define STRUCT_STAT struct stat64
810#include "ftw.c"
lib/libc/mingw/misc/ftw64i32.c created+19
......@@ -0,0 +1,19 @@
1/**
2 * This file is part of the mingw-w64 runtime package.
3 * No warranty is given; refer to the file DISCLAIMER within this package.
4 */
5
6#define FUNC_FTW ftw64i32
7#define FUNC_NFTW nftw64i32
8#define FUNC_STAT stat64i32
9#define STRUCT_STAT struct _stat64i32
10#include "ftw.c"
11
12/* On 64-bit systems is stat ABI compatible with stat64i32 */
13#ifdef _WIN64
14#undef nftw
15#undef ftw
16struct stat;
17int __attribute__ ((alias ("nftw64i32"))) __cdecl nftw(const char *, int (*) (const char *, const struct stat *, int, struct FTW *), int, int);
18int __attribute__ ((alias ("ftw64i32"))) __cdecl ftw(const char *, int (*) (const char *, const struct stat *, int), int);
19#endif
lib/libc/mingw/misc/mingw-aligned-malloc.c+33-7
......@@ -18,16 +18,14 @@
1818#include <stdint.h> /* uintptr_t */
1919#include <string.h> /* memmove */
2020
21/* Forward declarations: */
22void *__mingw_aligned_offset_malloc (size_t, size_t, size_t);
23
2421#define NOT_POWER_OF_TWO(n) (((n) & ((n) - 1)))
2522#define UI(p) ((uintptr_t) (p))
2623#define CP(p) ((char *) p)
2724
25#define GAP(offset) ((0 - offset) & (sizeof (void *) -1))
2826#define PTR_ALIGN(p0, alignment, offset) \
29 ((void *) (((UI(p0) + (alignment + sizeof(void*)) + offset) \
30 & (~UI(alignment - 1))) \
27 ((void *) (((UI(p0) + (alignment + GAP(offset) + sizeof(void*)) + offset) \
28 & (~UI(alignment))) \
3129 - offset))
3230
3331/* Pointer must sometimes be aligned; assume sizeof(void*) is a power of two. */
......@@ -47,12 +45,13 @@ __mingw_aligned_offset_malloc (size_t size, size_t alignment, size_t offset)
4745 return ((void *) 0);
4846 if (alignment < sizeof (void *))
4947 alignment = sizeof (void *);
48 alignment--;
5049
5150 /* Including the extra sizeof(void*) is overkill on a 32-bit
5251 machine, since malloc is already 8-byte aligned, as long
5352 as we enforce alignment >= 8 ...but oh well. */
5453
55 p0 = malloc (size + (alignment + sizeof (void *)));
54 p0 = malloc (size + (alignment + GAP (offset) + sizeof (void *)));
5655 if (!p0)
5756 return ((void *) 0);
5857 p = PTR_ALIGN (p0, alignment, offset);
......@@ -91,6 +90,7 @@ __mingw_aligned_offset_realloc (void *memblock, size_t size,
9190 }
9291 if (alignment < sizeof (void *))
9392 alignment = sizeof (void *);
93 alignment--;
9494
9595 p0 = ORIG_PTR (memblock);
9696 /* It is an error for the alignment to change. */
......@@ -98,7 +98,7 @@ __mingw_aligned_offset_realloc (void *memblock, size_t size,
9898 goto bad;
9999 shift = CP (memblock) - CP (p0);
100100
101 p0 = realloc (p0, size + (alignment + sizeof (void *)));
101 p0 = realloc (p0, size + (alignment + GAP (offset) + sizeof (void *)));
102102 if (!p0)
103103 return ((void *) 0);
104104 p = PTR_ALIGN (p0, alignment, offset);
......@@ -121,3 +121,29 @@ __mingw_aligned_realloc (void *memblock, size_t size, size_t alignment)
121121{
122122 return __mingw_aligned_offset_realloc (memblock, size, alignment, 0);
123123}
124
125size_t
126__mingw_aligned_msize (void *memblock, size_t alignment, size_t offset)
127{
128 void *p0;
129
130 if (!memblock || NOT_POWER_OF_TWO (alignment))
131 {
132 errno = EINVAL;
133 return (size_t)-1;
134 }
135 if (alignment < sizeof (void *))
136 alignment = sizeof (void *);
137 alignment--;
138
139 p0 = ORIG_PTR (memblock);
140
141 /* It is an error if the alignment or offset does not match. */
142 if (memblock != PTR_ALIGN (p0, alignment, offset))
143 {
144 errno = EINVAL;
145 return (size_t)-1;
146 }
147
148 return _msize (p0) - (alignment + GAP (offset) + sizeof (void *));
149}
lib/libc/mingw/misc/mingw_controlfp.c created+53
......@@ -0,0 +1,53 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include "internal.h"
8
9#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
10/* Internal MinGW version of _control87_2 */
11int __mingw_control87_2( unsigned int newval, unsigned int mask,
12 unsigned int *x86_cw, unsigned int *sse2_cw )
13{
14 if (x86_cw)
15 {
16 *x86_cw = newval;
17 __mingw_setfp(x86_cw, mask, NULL, 0);
18 }
19
20 if (!sse2_cw) return 1;
21
22 if (__mingw_has_sse())
23 {
24 *sse2_cw = newval;
25 __mingw_setfp_sse(sse2_cw, mask, NULL, 0);
26 }
27 else *sse2_cw = 0;
28
29 return 1;
30}
31#endif
32
33/* Internal MinGW version of _control87 */
34unsigned int __mingw_controlfp(unsigned int newval, unsigned int mask)
35{
36 unsigned int flags = 0;
37#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
38 unsigned int sse2_cw;
39
40 __mingw_control87_2( newval, mask, &flags, &sse2_cw );
41
42 if (__mingw_has_sse())
43 {
44 if ((flags ^ sse2_cw) & (_MCW_EM | _MCW_RC)) flags |= _EM_AMBIGUOUS;
45 flags |= sse2_cw;
46 }
47#else
48 flags = newval;
49 __mingw_setfp(&flags, mask, NULL, 0);
50#endif
51 return flags;
52}
53
lib/libc/mingw/misc/mingw_getsp.S+4-4
......@@ -15,7 +15,10 @@
1515 .globl __MINGW_USYMBOL(mingw_getsp)
1616 .def __MINGW_USYMBOL(mingw_getsp); .scl 2; .type 32; .endef
1717__MINGW_USYMBOL(mingw_getsp):
18#if defined(_AMD64_) || defined(__x86_64__)
18#if defined(_ARM64_) || defined(__aarch64__) || defined(__arm64ec__)
19 mov x0, sp
20 ret
21#elif defined(_AMD64_) || defined(__x86_64__)
1922 leaq 8(%rsp),%rax
2023 ret
2124#elif defined(_X86_) || defined(__i386__)
......@@ -24,7 +27,4 @@ __MINGW_USYMBOL(mingw_getsp):
2427#elif defined(_ARM_) || defined(__arm__)
2528 mov r0, sp
2629 bx lr
27#elif defined(_ARM64_) || defined(__aarch64__)
28 mov x0, sp
29 ret
3030#endif
lib/libc/mingw/misc/mingw_setfp.c created+373
......@@ -0,0 +1,373 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include "internal.h"
8
9#if defined(__i386__) || defined(__x86_64__)
10
11static unsigned int get_mxcsr(void)
12{
13 unsigned int ret;
14#ifdef __arm64ec__
15 extern NTSTATUS (*__os_arm64x_get_x64_information)(ULONG,void*,void*);
16 __os_arm64x_get_x64_information( 0, &ret, NULL );
17#else
18 __asm__ __volatile__( "stmxcsr %0" : "=m" (ret) );
19#endif
20 return ret;
21}
22
23static void set_mxcsr( unsigned int val )
24{
25#ifdef __arm64ec__
26 extern NTSTATUS (*__os_arm64x_set_x64_information)(ULONG,ULONG_PTR,void*);
27 __os_arm64x_set_x64_information( 0, val, NULL );
28#else
29 __asm__ __volatile__( "ldmxcsr %0" : : "m" (val) );
30#endif
31}
32
33void __mingw_setfp_sse( unsigned int *cw, unsigned int cw_mask, unsigned int *sw, unsigned int sw_mask )
34{
35 unsigned int old_fpword, fpword = get_mxcsr();
36 unsigned int flags;
37
38 old_fpword = fpword;
39
40 cw_mask &= _MCW_EM | _MCW_RC | _MCW_DN;
41 sw_mask &= _MCW_EM;
42
43 if (sw)
44 {
45 flags = 0;
46 if (fpword & 0x1) flags |= _SW_INVALID;
47 if (fpword & 0x2) flags |= _SW_DENORMAL;
48 if (fpword & 0x4) flags |= _SW_ZERODIVIDE;
49 if (fpword & 0x8) flags |= _SW_OVERFLOW;
50 if (fpword & 0x10) flags |= _SW_UNDERFLOW;
51 if (fpword & 0x20) flags |= _SW_INEXACT;
52
53 *sw = (flags & ~sw_mask) | (*sw & sw_mask);
54 fpword &= ~0x3f;
55 if (*sw & _SW_INVALID) fpword |= 0x1;
56 if (*sw & _SW_DENORMAL) fpword |= 0x2;
57 if (*sw & _SW_ZERODIVIDE) fpword |= 0x4;
58 if (*sw & _SW_OVERFLOW) fpword |= 0x8;
59 if (*sw & _SW_UNDERFLOW) fpword |= 0x10;
60 if (*sw & _SW_INEXACT) fpword |= 0x20;
61 *sw = flags;
62 }
63
64 if (cw)
65 {
66 flags = 0;
67 if (fpword & 0x80) flags |= _EM_INVALID;
68 if (fpword & 0x100) flags |= _EM_DENORMAL;
69 if (fpword & 0x200) flags |= _EM_ZERODIVIDE;
70 if (fpword & 0x400) flags |= _EM_OVERFLOW;
71 if (fpword & 0x800) flags |= _EM_UNDERFLOW;
72 if (fpword & 0x1000) flags |= _EM_INEXACT;
73 switch (fpword & 0x6000)
74 {
75 case 0x6000: flags |= _RC_UP|_RC_DOWN; break;
76 case 0x4000: flags |= _RC_UP; break;
77 case 0x2000: flags |= _RC_DOWN; break;
78 }
79 switch (fpword & 0x8040)
80 {
81 case 0x0040: flags |= _DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
82 case 0x8000: flags |= _DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
83 case 0x8040: flags |= _DN_FLUSH; break;
84 }
85
86 *cw = (flags & ~cw_mask) | (*cw & cw_mask);
87 fpword &= ~0xffc0;
88 if (*cw & _EM_INVALID) fpword |= 0x80;
89 if (*cw & _EM_DENORMAL) fpword |= 0x100;
90 if (*cw & _EM_ZERODIVIDE) fpword |= 0x200;
91 if (*cw & _EM_OVERFLOW) fpword |= 0x400;
92 if (*cw & _EM_UNDERFLOW) fpword |= 0x800;
93 if (*cw & _EM_INEXACT) fpword |= 0x1000;
94 switch (*cw & _MCW_RC)
95 {
96 case _RC_UP|_RC_DOWN: fpword |= 0x6000; break;
97 case _RC_UP: fpword |= 0x4000; break;
98 case _RC_DOWN: fpword |= 0x2000; break;
99 }
100 switch (*cw & _MCW_DN)
101 {
102 case _DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
103 case _DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
104 case _DN_FLUSH: fpword |= 0x8040; break;
105 }
106
107 /* clear status word if anything changes */
108 if (fpword != old_fpword && !sw) fpword &= ~0x3f;
109 }
110
111 if (fpword != old_fpword) set_mxcsr( fpword );
112}
113#endif
114
115void __mingw_setfp( unsigned int *cw, unsigned int cw_mask,
116 unsigned int *sw, unsigned int sw_mask )
117{
118#if defined(__arm64ec__)
119 __mingw_setfp_sse(cw, cw_mask, sw, sw_mask);
120#elif defined(__i386__) || defined(__x86_64__)
121 unsigned long oldcw = 0, newcw = 0;
122 unsigned long oldsw = 0, newsw = 0;
123 unsigned int flags;
124
125 cw_mask &= _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC;
126 sw_mask &= _MCW_EM;
127
128 if (sw)
129 {
130 __asm__ __volatile__( "fstsw %0" : "=m" (newsw) );
131 oldsw = newsw;
132
133 flags = 0;
134 if (newsw & 0x1) flags |= _SW_INVALID;
135 if (newsw & 0x2) flags |= _SW_DENORMAL;
136 if (newsw & 0x4) flags |= _SW_ZERODIVIDE;
137 if (newsw & 0x8) flags |= _SW_OVERFLOW;
138 if (newsw & 0x10) flags |= _SW_UNDERFLOW;
139 if (newsw & 0x20) flags |= _SW_INEXACT;
140
141 *sw = (flags & ~sw_mask) | (*sw & sw_mask);
142 newsw &= ~0x3f;
143 if (*sw & _SW_INVALID) newsw |= 0x1;
144 if (*sw & _SW_DENORMAL) newsw |= 0x2;
145 if (*sw & _SW_ZERODIVIDE) newsw |= 0x4;
146 if (*sw & _SW_OVERFLOW) newsw |= 0x8;
147 if (*sw & _SW_UNDERFLOW) newsw |= 0x10;
148 if (*sw & _SW_INEXACT) newsw |= 0x20;
149 *sw = flags;
150 }
151
152 if (cw)
153 {
154 __asm__ __volatile__( "fstcw %0" : "=m" (newcw) );
155 oldcw = newcw;
156
157 flags = 0;
158 if (newcw & 0x1) flags |= _EM_INVALID;
159 if (newcw & 0x2) flags |= _EM_DENORMAL;
160 if (newcw & 0x4) flags |= _EM_ZERODIVIDE;
161 if (newcw & 0x8) flags |= _EM_OVERFLOW;
162 if (newcw & 0x10) flags |= _EM_UNDERFLOW;
163 if (newcw & 0x20) flags |= _EM_INEXACT;
164 switch (newcw & 0xc00)
165 {
166 case 0xc00: flags |= _RC_UP|_RC_DOWN; break;
167 case 0x800: flags |= _RC_UP; break;
168 case 0x400: flags |= _RC_DOWN; break;
169 }
170 switch (newcw & 0x300)
171 {
172 case 0x0: flags |= _PC_24; break;
173 case 0x200: flags |= _PC_53; break;
174 case 0x300: flags |= _PC_64; break;
175 }
176 if (newcw & 0x1000) flags |= _IC_AFFINE;
177
178 *cw = (flags & ~cw_mask) | (*cw & cw_mask);
179 newcw &= ~0x1f3f;
180 if (*cw & _EM_INVALID) newcw |= 0x1;
181 if (*cw & _EM_DENORMAL) newcw |= 0x2;
182 if (*cw & _EM_ZERODIVIDE) newcw |= 0x4;
183 if (*cw & _EM_OVERFLOW) newcw |= 0x8;
184 if (*cw & _EM_UNDERFLOW) newcw |= 0x10;
185 if (*cw & _EM_INEXACT) newcw |= 0x20;
186 switch (*cw & _MCW_RC)
187 {
188 case _RC_UP|_RC_DOWN: newcw |= 0xc00; break;
189 case _RC_UP: newcw |= 0x800; break;
190 case _RC_DOWN: newcw |= 0x400; break;
191 }
192 switch (*cw & _MCW_PC)
193 {
194 case _PC_64: newcw |= 0x300; break;
195 case _PC_53: newcw |= 0x200; break;
196 case _PC_24: newcw |= 0x0; break;
197 }
198 if (*cw & _IC_AFFINE) newcw |= 0x1000;
199 }
200
201 if (oldsw != newsw && (newsw & 0x3f))
202 {
203 struct {
204 WORD control_word;
205 WORD unused1;
206 WORD status_word;
207 WORD unused2;
208 WORD tag_word;
209 WORD unused3;
210 DWORD instruction_pointer;
211 WORD code_segment;
212 WORD unused4;
213 DWORD operand_addr;
214 WORD data_segment;
215 WORD unused5;
216 } fenv;
217
218 __asm__ __volatile__( "fnstenv %0" : "=m" (fenv) );
219 fenv.control_word = newcw;
220 fenv.status_word = newsw;
221 __asm__ __volatile__( "fldenv %0" : : "m" (fenv) : "st", "st(1)",
222 "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
223 return;
224 }
225
226 if (oldsw != newsw)
227 __asm__ __volatile__( "fnclex" );
228 if (oldcw != newcw)
229 __asm__ __volatile__( "fldcw %0" : : "m" (newcw) );
230#elif defined(__aarch64__)
231 ULONG_PTR old_fpsr = 0, fpsr = 0, old_fpcr = 0, fpcr = 0;
232 unsigned int flags;
233
234 cw_mask &= _MCW_EM | _MCW_RC;
235 sw_mask &= _MCW_EM;
236
237 if (sw)
238 {
239 __asm__ __volatile__( "mrs %0, fpsr" : "=r" (fpsr) );
240 old_fpsr = fpsr;
241
242 flags = 0;
243 if (fpsr & 0x1) flags |= _SW_INVALID;
244 if (fpsr & 0x2) flags |= _SW_ZERODIVIDE;
245 if (fpsr & 0x4) flags |= _SW_OVERFLOW;
246 if (fpsr & 0x8) flags |= _SW_UNDERFLOW;
247 if (fpsr & 0x10) flags |= _SW_INEXACT;
248 if (fpsr & 0x80) flags |= _SW_DENORMAL;
249
250 *sw = (flags & ~sw_mask) | (*sw & sw_mask);
251 fpsr &= ~0x9f;
252 if (*sw & _SW_INVALID) fpsr |= 0x1;
253 if (*sw & _SW_ZERODIVIDE) fpsr |= 0x2;
254 if (*sw & _SW_OVERFLOW) fpsr |= 0x4;
255 if (*sw & _SW_UNDERFLOW) fpsr |= 0x8;
256 if (*sw & _SW_INEXACT) fpsr |= 0x10;
257 if (*sw & _SW_DENORMAL) fpsr |= 0x80;
258 *sw = flags;
259 }
260
261 if (cw)
262 {
263 __asm__ __volatile__( "mrs %0, fpcr" : "=r" (fpcr) );
264 old_fpcr = fpcr;
265
266 flags = 0;
267 if (!(fpcr & 0x100)) flags |= _EM_INVALID;
268 if (!(fpcr & 0x200)) flags |= _EM_ZERODIVIDE;
269 if (!(fpcr & 0x400)) flags |= _EM_OVERFLOW;
270 if (!(fpcr & 0x800)) flags |= _EM_UNDERFLOW;
271 if (!(fpcr & 0x1000)) flags |= _EM_INEXACT;
272 if (!(fpcr & 0x8000)) flags |= _EM_DENORMAL;
273 switch (fpcr & 0xc00000)
274 {
275 case 0x400000: flags |= _RC_UP; break;
276 case 0x800000: flags |= _RC_DOWN; break;
277 case 0xc00000: flags |= _RC_CHOP; break;
278 }
279
280 *cw = (flags & ~cw_mask) | (*cw & cw_mask);
281 fpcr &= ~0xc09f00ul;
282 if (!(*cw & _EM_INVALID)) fpcr |= 0x100;
283 if (!(*cw & _EM_ZERODIVIDE)) fpcr |= 0x200;
284 if (!(*cw & _EM_OVERFLOW)) fpcr |= 0x400;
285 if (!(*cw & _EM_UNDERFLOW)) fpcr |= 0x800;
286 if (!(*cw & _EM_INEXACT)) fpcr |= 0x1000;
287 if (!(*cw & _EM_DENORMAL)) fpcr |= 0x8000;
288 switch (*cw & _MCW_RC)
289 {
290 case _RC_CHOP: fpcr |= 0xc00000; break;
291 case _RC_UP: fpcr |= 0x400000; break;
292 case _RC_DOWN: fpcr |= 0x800000; break;
293 }
294 }
295
296 /* mask exceptions if needed */
297 if (old_fpcr != fpcr && ~(old_fpcr >> 8) & fpsr & 0x9f != fpsr & 0x9f)
298 {
299 ULONG_PTR mask = fpcr & ~0x9f00;
300 __asm__ __volatile__( "msr fpcr, %0" :: "r" (mask) );
301 }
302
303 if (old_fpsr != fpsr)
304 __asm__ __volatile__( "msr fpsr, %0" :: "r" (fpsr) );
305 if (old_fpcr != fpcr)
306 __asm__ __volatile__( "msr fpcr, %0" :: "r" (fpcr) );
307#elif defined(__arm__)
308 DWORD old_fpscr, fpscr;
309 unsigned int flags;
310
311 __asm__ __volatile__( "vmrs %0, fpscr" : "=r" (fpscr) );
312 old_fpscr = fpscr;
313
314 cw_mask &= _MCW_EM | _MCW_RC;
315 sw_mask &= _MCW_EM;
316
317 if (sw)
318 {
319 flags = 0;
320 if (fpscr & 0x1) flags |= _SW_INVALID;
321 if (fpscr & 0x2) flags |= _SW_ZERODIVIDE;
322 if (fpscr & 0x4) flags |= _SW_OVERFLOW;
323 if (fpscr & 0x8) flags |= _SW_UNDERFLOW;
324 if (fpscr & 0x10) flags |= _SW_INEXACT;
325 if (fpscr & 0x80) flags |= _SW_DENORMAL;
326
327 *sw = (flags & ~sw_mask) | (*sw & sw_mask);
328 fpscr &= ~0x9f;
329 if (*sw & _SW_INVALID) fpscr |= 0x1;
330 if (*sw & _SW_ZERODIVIDE) fpscr |= 0x2;
331 if (*sw & _SW_OVERFLOW) fpscr |= 0x4;
332 if (*sw & _SW_UNDERFLOW) fpscr |= 0x8;
333 if (*sw & _SW_INEXACT) fpscr |= 0x10;
334 if (*sw & _SW_DENORMAL) fpscr |= 0x80;
335 *sw = flags;
336 }
337
338 if (cw)
339 {
340 flags = 0;
341 if (!(fpscr & 0x100)) flags |= _EM_INVALID;
342 if (!(fpscr & 0x200)) flags |= _EM_ZERODIVIDE;
343 if (!(fpscr & 0x400)) flags |= _EM_OVERFLOW;
344 if (!(fpscr & 0x800)) flags |= _EM_UNDERFLOW;
345 if (!(fpscr & 0x1000)) flags |= _EM_INEXACT;
346 if (!(fpscr & 0x8000)) flags |= _EM_DENORMAL;
347 switch (fpscr & 0xc00000)
348 {
349 case 0x400000: flags |= _RC_UP; break;
350 case 0x800000: flags |= _RC_DOWN; break;
351 case 0xc00000: flags |= _RC_CHOP; break;
352 }
353
354 *cw = (flags & ~cw_mask) | (*cw & cw_mask);
355 fpscr &= ~0xc09f00ul;
356 if (!(*cw & _EM_INVALID)) fpscr |= 0x100;
357 if (!(*cw & _EM_ZERODIVIDE)) fpscr |= 0x200;
358 if (!(*cw & _EM_OVERFLOW)) fpscr |= 0x400;
359 if (!(*cw & _EM_UNDERFLOW)) fpscr |= 0x800;
360 if (!(*cw & _EM_INEXACT)) fpscr |= 0x1000;
361 if (!(*cw & _EM_DENORMAL)) fpscr |= 0x8000;
362 switch (*cw & _MCW_RC)
363 {
364 case _RC_CHOP: fpscr |= 0xc00000; break;
365 case _RC_UP: fpscr |= 0x400000; break;
366 case _RC_DOWN: fpscr |= 0x800000; break;
367 }
368 }
369
370 if (old_fpscr != fpscr)
371 __asm__ __volatile__( "vmsr fpscr, %0" :: "r" (fpscr) );
372#endif
373}
lib/libc/mingw/misc/setjmp.S+2
......@@ -6,6 +6,7 @@
66
77#include <_mingw_mac.h>
88
9#ifndef __arm64ec__
910 .globl __MINGW_USYMBOL(__intrinsic_setjmp)
1011 .def __MINGW_USYMBOL(__intrinsic_setjmp); .scl 2; .type 32; .endef
1112
......@@ -115,3 +116,4 @@ __MINGW_USYMBOL(__intrinsic_setjmpex):
115116 mov x0, #0
116117 ret
117118#endif
119#endif /* __arm64ec__ */
lib/libc/mingw/misc/ucrt_tzset.c-3
......@@ -40,6 +40,3 @@ void __cdecl tzset(void)
4040{
4141 _tzset();
4242}
43
44// Dummy/unused __imp_ wrappers, to make GNU ld not autoexport these symbols.
45void __cdecl (*__MINGW_IMP_SYMBOL(tzset))(void) = tzset;
lib/libc/mingw/misc/winbs_uint64.c+1-34
......@@ -2,38 +2,5 @@ unsigned long long __cdecl _byteswap_uint64(unsigned long long _Int64);
22
33unsigned long long __cdecl _byteswap_uint64(unsigned long long _Int64)
44{
5#if defined(_AMD64_) || defined(__x86_64__)
6 unsigned long long retval;
7 __asm__ __volatile__ ("bswapq %[retval]" : [retval] "=rm" (retval) : "[retval]" (_Int64));
8 return retval;
9#elif defined(_X86_) || defined(__i386__)
10 union {
11 long long int64part;
12 struct {
13 unsigned long lowpart;
14 unsigned long hipart;
15 };
16 } retval;
17 retval.int64part = _Int64;
18 __asm__ __volatile__ ("bswapl %[lowpart]\n"
19 "bswapl %[hipart]\n"
20 : [lowpart] "=rm" (retval.hipart), [hipart] "=rm" (retval.lowpart) : "[lowpart]" (retval.lowpart), "[hipart]" (retval.hipart));
21 return retval.int64part;
22#else
23 unsigned char *b = (void*)&_Int64;
24 unsigned char tmp;
25 tmp = b[0];
26 b[0] = b[7];
27 b[7] = tmp;
28 tmp = b[1];
29 b[1] = b[6];
30 b[6] = tmp;
31 tmp = b[2];
32 b[2] = b[5];
33 b[5] = tmp;
34 tmp = b[3];
35 b[3] = b[4];
36 b[4] = tmp;
37 return _Int64;
38#endif
5 return __builtin_bswap64(_Int64);
396}
lib/libc/mingw/misc/winbs_ulong.c+1-15
......@@ -2,19 +2,5 @@ unsigned long __cdecl _byteswap_ulong (unsigned long _Long);
22
33unsigned long __cdecl _byteswap_ulong (unsigned long _Long)
44{
5#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
6 unsigned long retval;
7 __asm__ __volatile__ ("bswapl %[retval]" : [retval] "=rm" (retval) : "[retval]" (_Long));
8 return retval;
9#else
10 unsigned char *b = (void*)&_Long;
11 unsigned char tmp;
12 tmp = b[0];
13 b[0] = b[3];
14 b[3] = tmp;
15 tmp = b[1];
16 b[1] = b[2];
17 b[2] = tmp;
18 return _Long;
19#endif /* defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__) */
5 return __builtin_bswap32(_Long);
206}
lib/libc/mingw/misc/winbs_ushort.c+1-12
......@@ -2,16 +2,5 @@ unsigned short __cdecl _byteswap_ushort(unsigned short _Short);
22
33unsigned short __cdecl _byteswap_ushort(unsigned short _Short)
44{
5#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
6 unsigned short retval;
7 __asm__ __volatile__ ("rorw $8, %w[retval]" : [retval] "=rm" (retval) : "[retval]" (_Short));
8 return retval;
9#else
10 unsigned char *b = (void*)&_Short;
11 unsigned char tmp;
12 tmp = b[0];
13 b[0] = b[1];
14 b[1] = tmp;
15 return _Short;
16#endif /* defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__) */
5 return __builtin_bswap16(_Short);
176}
lib/libc/mingw/stdio/__mingw_fix_stat_path.c created+64
......@@ -0,0 +1,64 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <sys/stat.h>
8#include <stdlib.h>
9
10/**
11 * Returns _path without trailing slash if any
12 *
13 * - if _path has no trailing slash, the function returns it
14 * - if _path has a trailing slash, but is of the form C:/, then it returns it
15 * - otherwise, the function creates a new string, which is a copy of _path
16 * without the trailing slash. It is then the responsibility of the caller
17 * to free it.
18 */
19
20char* __mingw_fix_stat_path (const char* _path);
21char* __mingw_fix_stat_path (const char* _path)
22{
23 int len;
24 char *p;
25
26 p = (char*)_path;
27
28 if (_path && *_path) {
29 len = strlen (_path);
30
31 /* Ignore X:\ */
32
33 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == ':'))
34 return p;
35
36 /* Check UNC \\abc\<name>\ */
37 if ((_path[0] == '\\' || _path[0] == '/')
38 && (_path[1] == '\\' || _path[1] == '/'))
39 {
40 const char *r = &_path[2];
41 while (*r != 0 && *r != '\\' && *r != '/')
42 ++r;
43 if (*r != 0)
44 ++r;
45 if (*r == 0)
46 return p;
47 while (*r != 0 && *r != '\\' && *r != '/')
48 ++r;
49 if (*r != 0)
50 ++r;
51 if (*r == 0)
52 return p;
53 }
54
55 if (_path[len - 1] == '/' || _path[len - 1] == '\\')
56 {
57 p = (char*)malloc (len);
58 memcpy (p, _path, len - 1);
59 p[len - 1] = '\0';
60 }
61 }
62
63 return p;
64}
lib/libc/mingw/stdio/__mingw_fix_wstat_path.c created+64
......@@ -0,0 +1,64 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <sys/stat.h>
8#include <stdlib.h>
9
10/**
11 * Returns _path without trailing slash if any
12 *
13 * - if _path has no trailing slash, the function returns it
14 * - if _path has a trailing slash, but is of the form C:/, then it returns it
15 * - otherwise, the function creates a new string, which is a copy of _path
16 * without the trailing slash. It is then the responsibility of the caller
17 * to free it.
18 */
19
20wchar_t* __mingw_fix_wstat_path (const wchar_t* _path);
21wchar_t* __mingw_fix_wstat_path (const wchar_t* _path)
22{
23 int len;
24 wchar_t *p;
25
26 p = (wchar_t*)_path;
27
28 if (_path && *_path) {
29 len = wcslen (_path);
30
31 /* Ignore X:\ */
32
33 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == L':'))
34 return p;
35
36 /* Check UNC \\abc\<name>\ */
37 if ((_path[0] == L'\\' || _path[0] == L'/')
38 && (_path[1] == L'\\' || _path[1] == L'/'))
39 {
40 const wchar_t *r = &_path[2];
41 while (*r != 0 && *r != L'\\' && *r != L'/')
42 ++r;
43 if (*r != 0)
44 ++r;
45 if (*r == 0)
46 return p;
47 while (*r != 0 && *r != L'\\' && *r != L'/')
48 ++r;
49 if (*r != 0)
50 ++r;
51 if (*r == 0)
52 return p;
53 }
54
55 if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
56 {
57 p = (wchar_t*)malloc (len * sizeof(wchar_t));
58 memcpy (p, _path, (len - 1) * sizeof(wchar_t));
59 p[len - 1] = L'\0';
60 }
61 }
62
63 return p;
64}
lib/libc/mingw/stdio/_findfirst64i32.c+1-1
......@@ -7,7 +7,7 @@ intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *
77 struct __finddata64_t fd;
88 intptr_t ret = _findfirst64(_Filename,&fd);
99 if (ret == -1) {
10 memset(_FindData,0,sizeof(struct _finddata64i32_t));
10 *_FindData = (struct _finddata64i32_t){0};
1111 return -1;
1212 }
1313 _FindData->attrib=fd.attrib;
lib/libc/mingw/stdio/_findnext64i32.c+1-1
......@@ -7,7 +7,7 @@ int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindDa
77 struct __finddata64_t fd;
88 int ret = _findnext64(_FindHandle,&fd);
99 if (ret == -1) {
10 memset(_FindData,0,sizeof(struct _finddata64i32_t));
10 *_FindData = (struct _finddata64i32_t){0};
1111 return -1;
1212 }
1313 _FindData->attrib=fd.attrib;
lib/libc/mingw/stdio/_fstat64i32.c+20-8
......@@ -1,14 +1,26 @@
1#define __CRT__NO_INLINE
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
27#include <sys/stat.h>
38
9/* When the file size does not fit into the st_size field:
10 * crtdll-msvcr90 msvcr100 msvcr110+
11 * st_size truncate 0 0
12 * errno no change no change EOVERFLOW
13 * returns 0 -1 -1
14 *
15 * This file is used only for pre-msvcr80 builds,
16 * So use the pre-msvcr80 behavior - truncate without error.
17 */
418int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat)
519{
620 struct _stat64 st;
721 int ret=_fstat64(_FileDes,&st);
8 if (ret == -1) {
9 memset(_Stat,0,sizeof(struct _stat64i32));
10 return -1;
11 }
22 if (ret != 0)
23 return ret;
1224 _Stat->st_dev=st.st_dev;
1325 _Stat->st_ino=st.st_ino;
1426 _Stat->st_mode=st.st_mode;
......@@ -16,10 +28,10 @@ int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat)
1628 _Stat->st_uid=st.st_uid;
1729 _Stat->st_gid=st.st_gid;
1830 _Stat->st_rdev=st.st_rdev;
19 _Stat->st_size=(_off_t) st.st_size; /* 32bit size */
31 _Stat->st_size=(_off_t) st.st_size; /* truncate 64-bit st_size to 32-bit */
2032 _Stat->st_atime=st.st_atime;
2133 _Stat->st_mtime=st.st_mtime;
2234 _Stat->st_ctime=st.st_ctime;
23 return ret;
35 return 0;
2436}
25
37int (__cdecl *__MINGW_IMP_SYMBOL(_fstat64i32))(int, struct _stat64i32 *) = _fstat64i32;
lib/libc/mingw/stdio/_stat.c deleted-120
......@@ -1,120 +0,0 @@
1#define __CRT__NO_INLINE
2#include <sys/stat.h>
3#include <stdlib.h>
4
5/**
6 * Returns _path without trailing slash if any
7 *
8 * - if _path has no trailing slash, the function returns it
9 * - if _path has a trailing slash, but is of the form C:/, then it returns it
10 * - otherwise, the function creates a new string, which is a copy of _path
11 * without the trailing slash. It is then the responsibility of the caller
12 * to free it.
13 */
14
15static char*
16_mingw_no_trailing_slash (const char* _path)
17{
18 int len;
19 char *p;
20
21 p = (char*)_path;
22
23 if (_path && *_path) {
24 len = strlen (_path);
25
26 /* Ignore X:\ */
27
28 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == ':'))
29 return p;
30
31 /* Check UNC \\abc\<name>\ */
32 if ((_path[0] == '\\' || _path[0] == '/')
33 && (_path[1] == '\\' || _path[1] == '/'))
34 {
35 const char *r = &_path[2];
36 while (*r != 0 && *r != '\\' && *r != '/')
37 ++r;
38 if (*r != 0)
39 ++r;
40 if (*r == 0)
41 return p;
42 while (*r != 0 && *r != '\\' && *r != '/')
43 ++r;
44 if (*r != 0)
45 ++r;
46 if (*r == 0)
47 return p;
48 }
49
50 if (_path[len - 1] == '/' || _path[len - 1] == '\\')
51 {
52 p = (char*)malloc (len);
53 memcpy (p, _path, len - 1);
54 p[len - 1] = '\0';
55 }
56 }
57
58 return p;
59}
60/* FIXME: Relying on _USE_32BIT_TIME_T, which is a user-macro,
61during CRT compilation is plainly broken. Need an appropriate
62implementation to provide users the ability of compiling the
63CRT only with 32-bit time_t behavior. */
64#if defined(_USE_32BIT_TIME_T)
65int __cdecl
66stat(const char *_Filename,struct stat *_Stat)
67{
68 struct _stat32 st;
69 char *_path = _mingw_no_trailing_slash(_Filename);
70
71 int ret=_stat32(_path,&st);
72
73 if (_path != _Filename)
74 free (_path);
75
76 if (ret == -1) {
77 memset(_Stat,0,sizeof(struct stat));
78 return -1;
79 }
80 /* struct stat and struct _stat32
81 are the same for this case. */
82 memcpy(_Stat, &st, sizeof(struct _stat32));
83 return ret;
84}
85#else
86int __cdecl
87stat(const char *_Filename,struct stat *_Stat)
88{
89 struct _stat64 st;
90 char *_path = _mingw_no_trailing_slash(_Filename);
91
92 int ret=_stat64(_path,&st);
93
94 if (_path != _Filename)
95 free (_path);
96
97 if (ret == -1) {
98 memset(_Stat,0,sizeof(struct stat));
99 return -1;
100 }
101 /* struct stat and struct _stat64i32
102 are the same for this case. */
103 _Stat->st_dev=st.st_dev;
104 _Stat->st_ino=st.st_ino;
105 _Stat->st_mode=st.st_mode;
106 _Stat->st_nlink=st.st_nlink;
107 _Stat->st_uid=st.st_uid;
108 _Stat->st_gid=st.st_gid;
109 _Stat->st_rdev=st.st_rdev;
110 _Stat->st_size=(_off_t) st.st_size;
111 _Stat->st_atime=st.st_atime;
112 _Stat->st_mtime=st.st_mtime;
113 _Stat->st_ctime=st.st_ctime;
114 return ret;
115}
116#endif
117
118/* Add __imp__fstat and __imp__stat symbols. */
119int (*__MINGW_IMP_SYMBOL(stat))(const char *,struct stat *) = &stat;
120
lib/libc/mingw/stdio/_stat64i32.c+19-70
......@@ -1,77 +1,26 @@
1#define __CRT__NO_INLINE
2#include <sys/stat.h>
3#include <stdlib.h>
4
51/**
6 * Returns _path without trailing slash if any
7 *
8 * - if _path has no trailing slash, the function returns it
9 * - if _path has a trailing slash, but is of the form C:/, then it returns it
10 * - otherwise, the function creates a new string, which is a copy of _path
11 * without the trailing slash. It is then the responsibility of the caller
12 * to free it.
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
135 */
146
15static char*
16_mingw_no_trailing_slash (const char* _path)
17{
18 int len;
19 char *p;
20
21 p = (char*)_path;
22
23 if (_path && *_path) {
24 len = strlen (_path);
25
26 /* Ignore X:\ */
27
28 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == ':'))
29 return p;
30
31 /* Check UNC \\abc\<name>\ */
32 if ((_path[0] == '\\' || _path[0] == '/')
33 && (_path[1] == '\\' || _path[1] == '/'))
34 {
35 const char *r = &_path[2];
36 while (*r != 0 && *r != '\\' && *r != '/')
37 ++r;
38 if (*r != 0)
39 ++r;
40 if (*r == 0)
41 return p;
42 while (*r != 0 && *r != '\\' && *r != '/')
43 ++r;
44 if (*r != 0)
45 ++r;
46 if (*r == 0)
47 return p;
48 }
49
50 if (_path[len - 1] == '/' || _path[len - 1] == '\\')
51 {
52 p = (char*)malloc (len);
53 memcpy (p, _path, len - 1);
54 p[len - 1] = '\0';
55 }
56 }
57
58 return p;
59}
7#include <sys/stat.h>
608
9/* When the file size does not fit into the st_size field:
10 * crtdll-msvcr90 msvcr100 msvcr110+
11 * st_size truncate 0 0
12 * errno no change no change EOVERFLOW
13 * returns 0 -1 -1
14 *
15 * This file is used only for pre-msvcr80 builds,
16 * So use the pre-msvcr80 behavior - truncate without error.
17 */
6118int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat)
6219{
6320 struct _stat64 st;
64 char *_path = _mingw_no_trailing_slash(_Name);
65
66 int ret=_stat64(_path,&st);
67
68 if (_path != _Name)
69 free(_path);
70
71 if (ret == -1) {
72 memset(_Stat,0,sizeof(struct _stat64i32));
73 return -1;
74 }
21 int ret=_stat64(_Name,&st);
22 if (ret != 0)
23 return ret;
7524 _Stat->st_dev=st.st_dev;
7625 _Stat->st_ino=st.st_ino;
7726 _Stat->st_mode=st.st_mode;
......@@ -79,10 +28,10 @@ int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat)
7928 _Stat->st_uid=st.st_uid;
8029 _Stat->st_gid=st.st_gid;
8130 _Stat->st_rdev=st.st_rdev;
82 _Stat->st_size=(_off_t) st.st_size;
31 _Stat->st_size=(_off_t) st.st_size; /* truncate 64-bit st_size to 32-bit */
8332 _Stat->st_atime=st.st_atime;
8433 _Stat->st_mtime=st.st_mtime;
8534 _Stat->st_ctime=st.st_ctime;
86 return ret;
35 return 0;
8736}
88
37int (__cdecl *__MINGW_IMP_SYMBOL(_stat64i32))(const char *, struct _stat64i32 *) = _stat64i32;
lib/libc/mingw/stdio/_wfindfirst64i32.c+1-1
......@@ -7,7 +7,7 @@ intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i3
77 struct _wfinddata64_t fd;
88 intptr_t ret = _wfindfirst64(_Filename,&fd);
99 if (ret == -1) {
10 memset(_FindData,0,sizeof(struct _wfinddata64i32_t));
10 *_FindData = (struct _wfinddata64i32_t){0};
1111 return -1;
1212 }
1313 _FindData->attrib=fd.attrib;
lib/libc/mingw/stdio/_wfindnext64i32.c+1-1
......@@ -7,7 +7,7 @@ int __cdecl _wfindnext64i32(intptr_t _FindHandle,struct _wfinddata64i32_t *_Find
77 struct _wfinddata64_t fd;
88 int ret = _wfindnext64(_FindHandle,&fd);
99 if (ret == -1) {
10 memset(_FindData,0,sizeof(struct _wfinddata64i32_t));
10 *_FindData = (struct _wfinddata64i32_t){0};
1111 return -1;
1212 }
1313 _FindData->attrib=fd.attrib;
lib/libc/mingw/stdio/_wstat.c deleted-119
......@@ -1,119 +0,0 @@
1#define __CRT__NO_INLINE
2#include <sys/stat.h>
3#include <stdlib.h>
4#include <malloc.h>
5
6/**
7 * Returns _path without trailing slash if any
8 *
9 * - if _path has no trailing slash, the function returns it
10 * - if _path has a trailing slash, but is of the form C:/, then it returns it
11 * - otherwise, the function creates a new string, which is a copy of _path
12 * without the trailing slash. It is then the responsibility of the caller
13 * to free it.
14 */
15
16static wchar_t*
17_mingw_no_trailing_slash (const wchar_t* _path)
18{
19 int len;
20 wchar_t *p;
21
22 p = (wchar_t*)_path;
23
24 if (_path && *_path) {
25 len = wcslen (_path);
26
27 /* Ignore X:\ */
28
29 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == L':'))
30 return p;
31
32 /* Check UNC \\abc\<name>\ */
33 if ((_path[0] == L'\\' || _path[0] == L'/')
34 && (_path[1] == L'\\' || _path[1] == L'/'))
35 {
36 const wchar_t *r = &_path[2];
37 while (*r != 0 && *r != L'\\' && *r != L'/')
38 ++r;
39 if (*r != 0)
40 ++r;
41 if (*r == 0)
42 return p;
43 while (*r != 0 && *r != L'\\' && *r != L'/')
44 ++r;
45 if (*r != 0)
46 ++r;
47 if (*r == 0)
48 return p;
49 }
50
51 if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
52 {
53 p = (wchar_t*)malloc (len * sizeof(wchar_t));
54 memcpy (p, _path, (len - 1) * sizeof(wchar_t));
55 p[len - 1] = L'\0';
56 }
57 }
58
59 return p;
60}
61
62/* FIXME: Relying on _USE_32BIT_TIME_T, which is a user-macro,
63during CRT compilation is plainly broken. Need an appropriate
64implementation to provide users the ability of compiling the
65CRT only with 32-bit time_t behavior. */
66#if defined(_USE_32BIT_TIME_T)
67int __cdecl
68wstat(const wchar_t *_Filename,struct stat *_Stat)
69{
70 struct _stat32 st;
71 wchar_t *_path = _mingw_no_trailing_slash(_Filename);
72
73 int ret=_wstat32(_path,&st);
74
75 if (_path != _Filename)
76 free (_path);
77
78 if (ret == -1) {
79 memset(_Stat,0,sizeof(struct stat));
80 return -1;
81 }
82 /* struct stat and struct _stat32
83 are the same for this case. */
84 memcpy(_Stat, &st, sizeof(struct _stat32));
85 return ret;
86}
87#else
88int __cdecl
89wstat(const wchar_t *_Filename,struct stat *_Stat)
90{
91 struct _stat64 st;
92 wchar_t *_path = _mingw_no_trailing_slash(_Filename);
93
94 int ret=_wstat64(_path,&st);
95
96 if (_path != _Filename)
97 free (_path);
98
99 if (ret == -1) {
100 memset(_Stat,0,sizeof(struct stat));
101 return -1;
102 }
103 /* struct stat and struct _stat64i32
104 are the same for this case. */
105 _Stat->st_dev=st.st_dev;
106 _Stat->st_ino=st.st_ino;
107 _Stat->st_mode=st.st_mode;
108 _Stat->st_nlink=st.st_nlink;
109 _Stat->st_uid=st.st_uid;
110 _Stat->st_gid=st.st_gid;
111 _Stat->st_rdev=st.st_rdev;
112 _Stat->st_size=(_off_t) st.st_size;
113 _Stat->st_atime=st.st_atime;
114 _Stat->st_mtime=st.st_mtime;
115 _Stat->st_ctime=st.st_ctime;
116 return ret;
117}
118#endif
119
lib/libc/mingw/stdio/_wstat64i32.c+19-70
......@@ -1,77 +1,26 @@
1#define __CRT__NO_INLINE
2#include <sys/stat.h>
3#include <stdlib.h>
4
51/**
6 * Returns _path without trailing slash if any
7 *
8 * - if _path has no trailing slash, the function returns it
9 * - if _path has a trailing slash, but is of the form C:/, then it returns it
10 * - otherwise, the function creates a new string, which is a copy of _path
11 * without the trailing slash. It is then the responsibility of the caller
12 * to free it.
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
135 */
146
15static wchar_t*
16_mingw_no_trailing_slash (const wchar_t* _path)
17{
18 int len;
19 wchar_t *p;
20
21 p = (wchar_t*)_path;
22
23 if (_path && *_path) {
24 len = wcslen (_path);
25
26 /* Ignore X:\ */
27
28 if (len <= 1 || ((len == 2 || len == 3) && _path[1] == L':'))
29 return p;
30
31 /* Check UNC \\abc\<name>\ */
32 if ((_path[0] == L'\\' || _path[0] == L'/')
33 && (_path[1] == L'\\' || _path[1] == L'/'))
34 {
35 const wchar_t *r = &_path[2];
36 while (*r != 0 && *r != L'\\' && *r != L'/')
37 ++r;
38 if (*r != 0)
39 ++r;
40 if (*r == 0)
41 return p;
42 while (*r != 0 && *r != L'\\' && *r != L'/')
43 ++r;
44 if (*r != 0)
45 ++r;
46 if (*r == 0)
47 return p;
48 }
49
50 if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
51 {
52 p = (wchar_t*)malloc (len * sizeof(wchar_t));
53 memcpy (p, _path, (len - 1) * sizeof(wchar_t));
54 p[len - 1] = L'\0';
55 }
56 }
57
58 return p;
59}
7#include <sys/stat.h>
608
9/* When the file size does not fit into the st_size field:
10 * crtdll-msvcr90 msvcr100 msvcr110+
11 * st_size truncate 0 0
12 * errno no change no change EOVERFLOW
13 * returns 0 -1 -1
14 *
15 * This file is used only for pre-msvcr80 builds,
16 * So use the pre-msvcr80 behavior - truncate without error.
17 */
6118int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat)
6219{
6320 struct _stat64 st;
64 wchar_t *_path = _mingw_no_trailing_slash(_Name);
65
66 int ret=_wstat64(_path,&st);
67
68 if (_path != _Name)
69 free(_path);
70
71 if (ret == -1) {
72 memset(_Stat,0,sizeof(struct _stat64i32));
73 return -1;
74 }
21 int ret=_wstat64(_Name,&st);
22 if (ret != 0)
23 return ret;
7524 _Stat->st_dev=st.st_dev;
7625 _Stat->st_ino=st.st_ino;
7726 _Stat->st_mode=st.st_mode;
......@@ -79,10 +28,10 @@ int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat)
7928 _Stat->st_uid=st.st_uid;
8029 _Stat->st_gid=st.st_gid;
8130 _Stat->st_rdev=st.st_rdev;
82 _Stat->st_size=(_off_t) st.st_size;
31 _Stat->st_size=(_off_t) st.st_size; /* truncate 64-bit st_size to 32-bit */
8332 _Stat->st_atime=st.st_atime;
8433 _Stat->st_mtime=st.st_mtime;
8534 _Stat->st_ctime=st.st_ctime;
86 return ret;
35 return 0;
8736}
88
37int (__cdecl *__MINGW_IMP_SYMBOL(_wstat64i32))(const wchar_t *, struct _stat64i32 *) = _wstat64i32;
lib/libc/mingw/stdio/mingw_pformat.c+7-14
......@@ -512,8 +512,7 @@ void __pformat_putchars( const char *s, int count, __pformat_t *stream )
512512 wchar_t w[12], *p;
513513 while( count > 0 )
514514 {
515 mbstate_t ps;
516 memset(&ps, 0, sizeof(ps) );
515 mbstate_t ps = {0};
517516 --count;
518517 p = &w[0];
519518 l = mbrtowc (p, s, strlen (s), &ps);
......@@ -1175,11 +1174,8 @@ void __pformat_emit_radix_point( __pformat_t *stream )
11751174 /* Radix point initialisation not yet completed;
11761175 * establish a multibyte to `wchar_t' converter...
11771176 */
1178 int len; wchar_t rpchr; mbstate_t state;
1179
1180 /* Initialise the conversion state...
1181 */
1182 memset( &state, 0, sizeof( state ) );
1177 int len; wchar_t rpchr;
1178 mbstate_t state = {0};
11831179
11841180 /* Fetch and convert the localised radix point representation...
11851181 */
......@@ -1203,11 +1199,8 @@ void __pformat_emit_radix_point( __pformat_t *stream )
12031199#ifdef __BUILD_WIDEAPI
12041200 __pformat_putc (stream->rpchr, stream);
12051201#else
1206 int len; char buf[len = stream->rplen]; mbstate_t state;
1207
1208 /* Initialise the conversion state...
1209 */
1210 memset( &state, 0, sizeof( state ) );
1202 int len; char buf[len = stream->rplen];
1203 mbstate_t state = {0};
12111204
12121205 /* Convert the `wchar_t' representation to multibyte...
12131206 */
......@@ -3123,8 +3116,8 @@ __pformat (int flags, void *dest, int max, const APICHAR *fmt, va_list argv)
31233116 if (state == PFORMAT_INIT)
31243117 {
31253118 stream.flags |= PFORMAT_GROUPED; /* $$$$ */
3126 int len; wchar_t rpchr; mbstate_t cstate;
3127 memset (&cstate, 0, sizeof(state));
3119 int len; wchar_t rpchr;
3120 mbstate_t cstate = {0};
31283121 if ((len = mbrtowc( &rpchr, localeconv()->thousands_sep, 16, &cstate)) > 0)
31293122 stream.thousands_chr = rpchr;
31303123 stream.thousands_chr_len = len;
lib/libc/mingw/stdio/mingw_sformat.c+4-6
......@@ -307,7 +307,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
307307 char seen_dot, seen_exp, is_neg, not_in;
308308 char *tmp_wbuf_ptr, buf[MB_LEN_MAX];
309309 const char *lc_decimal_point, *lc_thousands_sep;
310 mbstate_t state, cstate;
310 mbstate_t state = {0}, cstate;
311311 union {
312312 unsigned long long ull;
313313 unsigned long ul;
......@@ -323,8 +323,6 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
323323 return EOF;
324324 }
325325
326 memset (&state, 0, sizeof (state));
327
328326 lc_decimal_point = localeconv()->decimal_point;
329327 lc_thousands_sep = localeconv()->thousands_sep;
330328 if (lc_thousands_sep != NULL && *lc_thousands_sep == 0)
......@@ -682,7 +680,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
682680 if ((c = in_ch (s, &read_in)) == EOF)
683681 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
684682
685 memset (&cstate, 0, sizeof (cstate));
683 cstate = (mbstate_t){0};
686684
687685 do
688686 {
......@@ -854,7 +852,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
854852 if ((c = in_ch (s, &read_in)) == EOF)
855853 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
856854
857 memset (&cstate, 0, sizeof (cstate));
855 cstate = (mbstate_t){0};
858856
859857 do
860858 {
......@@ -1459,7 +1457,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
14591457 if ((c = in_ch (s, &read_in)) == EOF)
14601458 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
14611459
1462 memset (&cstate, 0, sizeof (cstate));
1460 cstate = (mbstate_t){0};
14631461
14641462 do
14651463 {
lib/libc/mingw/stdio/mingw_swformat.c+5-5
......@@ -332,10 +332,10 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
332332 return EOF;
333333 }
334334
335 memset (&state, 0, sizeof(state));
335 state = (mbstate_t){0};
336336 clen = mbrtowc( &wc, localeconv()->decimal_point, 16, &state);
337337 lc_decimal_point = (clen > 0 ? wc : '.');
338 memset( &state, 0, sizeof( state ) );
338 state = (mbstate_t){0};
339339 clen = mbrtowc( &wc, localeconv()->thousands_sep, 16, &state);
340340 lc_thousands_sep = (clen > 0 ? wc : 0);
341341
......@@ -596,7 +596,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
596596 if ((c = in_ch (s, &read_in)) == WEOF)
597597 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
598598
599 memset (&state, 0, sizeof (state));
599 state = (mbstate_t){0};
600600
601601 do
602602 {
......@@ -744,7 +744,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
744744 if ((c = in_ch (s, &read_in)) == WEOF)
745745 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
746746
747 memset (&state, 0, sizeof (state));
747 state = (mbstate_t){0};
748748
749749 do
750750 {
......@@ -1459,7 +1459,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
14591459 if ((c = in_ch (s, &read_in)) == WEOF)
14601460 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
14611461
1462 memset (&state, 0, sizeof (state));
1462 state = (mbstate_t){0};
14631463
14641464 do
14651465 {
lib/libc/mingw/stdio/mingw_vfscanf.c+1-3
......@@ -7,8 +7,6 @@
77int
88__mingw_vfscanf (FILE *s, const char *format, va_list argp)
99{
10 _IFP ifp;
11 memset (&ifp, 0, sizeof (_IFP));
12 ifp.fp = s;
10 _IFP ifp = { .fp = s };
1311 return __mingw_sformat (&ifp, format, argp);
1412}
lib/libc/mingw/stdio/mingw_vfwscanf.c+1-3
......@@ -7,8 +7,6 @@
77int
88__mingw_vfwscanf (FILE *s, const wchar_t *format, va_list argp)
99{
10 _IFPW ifp;
11 memset (&ifp, 0, sizeof (_IFPW));
12 ifp.fp = s;
10 _IFPW ifp = { .fp = s };
1311 return __mingw_swformat (&ifp, format, argp);
1412}
lib/libc/mingw/stdio/mingw_vsscanf.c+1-4
......@@ -7,9 +7,6 @@
77int
88__mingw_vsscanf (const char *s, const char *format, va_list argp)
99{
10 _IFP ifp;
11 memset (&ifp, 0, sizeof (_IFP));
12 ifp.str = s;
13 ifp.is_string = 1;
10 _IFP ifp = { .str = s, .is_string = 1 };
1411 return __mingw_sformat (&ifp, format, argp);
1512}
lib/libc/mingw/stdio/mingw_vswscanf.c+1-4
......@@ -7,9 +7,6 @@
77int
88__mingw_vswscanf (const wchar_t *s, const wchar_t *format, va_list argp)
99{
10 _IFPW ifp;
11 memset (&ifp, 0, sizeof (_IFPW));
12 ifp.str = s;
13 ifp.is_string = 1;
10 _IFPW ifp = { .str = s, .is_string = 1 };
1411 return __mingw_swformat (&ifp, format, argp);
1512}
lib/libc/mingw/stdio/ucrt___local_stdio_printf_options.c created+15
......@@ -0,0 +1,15 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <corecrt_stdio_config.h>
10
11static unsigned __int64 options = _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS | _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING;
12
13unsigned __int64* __local_stdio_printf_options(void) {
14 return &options;
15}
lib/libc/mingw/stdio/ucrt___local_stdio_scanf_options.c created+15
......@@ -0,0 +1,15 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <corecrt_stdio_config.h>
10
11static unsigned __int64 options = _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS;
12
13unsigned __int64* __local_stdio_scanf_options(void) {
14 return &options;
15}
lib/libc/mingw/stdio/ucrt__scprintf.c-1
......@@ -18,4 +18,3 @@ int __cdecl _scprintf(const char * __restrict__ _Format, ...)
1818 va_end(_ArgList);
1919 return ret;
2020}
21int __cdecl (*__MINGW_IMP_SYMBOL(_scprintf))(const char *__restrict__, ...) = _scprintf;
lib/libc/mingw/stdio/ucrt__snprintf.c-1
......@@ -18,4 +18,3 @@ int __cdecl _snprintf(char * __restrict__ _Dest, size_t _Count, const char * __r
1818 va_end(_Args);
1919 return ret;
2020}
21int __cdecl (*__MINGW_IMP_SYMBOL(_snprintf))(char *__restrict__, size_t, const char *__restrict__, ...) = _snprintf;
lib/libc/mingw/stdio/ucrt__snscanf.c+1-2
......@@ -14,8 +14,7 @@ int __cdecl _snscanf(const char * __restrict__ _Src, size_t _MaxCount, const cha
1414 int ret;
1515 va_list _ArgList;
1616 va_start(_ArgList, _Format);
17 ret = __stdio_common_vsscanf(0, _Src, _MaxCount, _Format, NULL, _ArgList);
17 ret = __stdio_common_vsscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _Src, _MaxCount, _Format, NULL, _ArgList);
1818 va_end(_ArgList);
1919 return ret;
2020}
21int __cdecl (*__MINGW_IMP_SYMBOL(_snscanf))(const char *__restrict__, size_t, const char * __restrict__, ...) = _snscanf;
lib/libc/mingw/stdio/ucrt__snwprintf.c-18
......@@ -4,25 +4,12 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7// For ucrt, this function normally is an inline function in stdio.h.
8// libmingwex doesn't use the ucrt version of headers, and wassert.c can
9// end up requiring a concrete version of it.
10
11#ifdef __GNUC__
12#pragma GCC diagnostic push
13#pragma GCC diagnostic ignored "-Winline"
14#endif
15
167#undef __MSVCRT_VERSION__
178#define _UCRT
189
19#define _snwprintf real__snwprintf
20
2110#include <stdarg.h>
2211#include <stdio.h>
2312
24#undef _snwprintf
25
2613int __cdecl _snwprintf(wchar_t * restrict _Dest, size_t _Count, const wchar_t * restrict _Format, ...);
2714
2815int __cdecl _snwprintf(wchar_t * restrict _Dest, size_t _Count, const wchar_t * restrict _Format, ...)
......@@ -34,8 +21,3 @@ int __cdecl _snwprintf(wchar_t * restrict _Dest, size_t _Count, const wchar_t *
3421 va_end(ap);
3522 return ret;
3623}
37
38int __cdecl (*__MINGW_IMP_SYMBOL(_snwprintf))(wchar_t *restrict, size_t, const wchar_t *restrict, ...) = _snwprintf;
39#ifdef __GNUC__
40#pragma GCC diagnostic pop
41#endif
lib/libc/mingw/stdio/ucrt__vsnprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __re
1212{
1313 return __stdio_common_vsprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(_vsnprintf))(char *__restrict__, size_t, const char *__restrict__, va_list) = _vsnprintf;
lib/libc/mingw/stdio/ucrt__vsnwprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl _vsnwprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t
1212{
1313 return __stdio_common_vswprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(_vsnwprintf))(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list) = _vsnwprintf;
lib/libc/mingw/stdio/ucrt_fprintf.c-1
......@@ -17,4 +17,3 @@ int __cdecl fprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,
1717 __builtin_va_end(ap);
1818 return ret;
1919}
20int __cdecl (*__MINGW_IMP_SYMBOL(fprintf))(FILE *__restrict__, const char *__restrict__, ...) = fprintf;
lib/libc/mingw/stdio/ucrt_fscanf.c+1-2
......@@ -12,8 +12,7 @@ int __cdecl fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,.
1212 __builtin_va_list __ap;
1313 int __ret;
1414 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vfscanf(0, _File, _Format, NULL, __ap);
15 __ret = __stdio_common_vfscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _File, _Format, NULL, __ap);
1616 __builtin_va_end(__ap);
1717 return __ret;
1818}
19int __cdecl (*__MINGW_IMP_SYMBOL(fscanf))(FILE *__restrict__, const char *__restrict__, ...) = fscanf;
lib/libc/mingw/stdio/ucrt_fwprintf.c+1-19
......@@ -4,25 +4,12 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7// For ucrt, this function normally is an inline function in stdio.h.
8// libmingwex doesn't use the ucrt version of headers, and wassert.c can
9// end up requiring a concrete version of it.
10
11#ifdef __GNUC__
12#pragma GCC diagnostic push
13#pragma GCC diagnostic ignored "-Winline"
14#endif
15
167#undef __MSVCRT_VERSION__
178#define _UCRT
189
19#define fwprintf real_fwprintf
20
2110#include <stdarg.h>
2211#include <stdio.h>
2312
24#undef fwprintf
25
2613int __cdecl fwprintf(FILE *ptr, const wchar_t *fmt, ...);
2714
2815int __cdecl fwprintf(FILE *ptr, const wchar_t *fmt, ...)
......@@ -30,12 +17,7 @@ int __cdecl fwprintf(FILE *ptr, const wchar_t *fmt, ...)
3017 va_list ap;
3118 int ret;
3219 va_start(ap, fmt);
33 ret = vfwprintf(ptr, fmt, ap);
20 ret = __stdio_common_vfwprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, ptr, fmt, NULL, ap);
3421 va_end(ap);
3522 return ret;
3623}
37
38int __cdecl (*__MINGW_IMP_SYMBOL(fwprintf))(FILE *, const wchar_t *, ...) = fwprintf;
39#ifdef __GNUC__
40#pragma GCC diagnostic pop
41#endif
lib/libc/mingw/stdio/ucrt_fwscanf.c created+18
......@@ -0,0 +1,18 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl fwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...) {
12 __builtin_va_list __ap;
13 int __ret;
14 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vfwscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _File, _Format, NULL, __ap);
16 __builtin_va_end(__ap);
17 return __ret;
18}
lib/libc/mingw/stdio/ucrt_ms_fprintf.c deleted-22
......@@ -1,22 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9
10#include <stdio.h>
11#include <stdarg.h>
12
13int __cdecl __ms_fprintf(FILE * restrict file, const char * restrict format, ...)
14{
15 va_list ap;
16 int ret;
17 va_start(ap, format);
18 ret = __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, file, format, NULL, ap);
19 va_end(ap);
20 return ret;
21}
22int __cdecl (*__MINGW_IMP_SYMBOL(__ms_fprintf))(FILE * restrict, const char * restrict, ...) = __ms_fprintf;
lib/libc/mingw/stdio/ucrt_ms_fwprintf.c+1-2
......@@ -17,8 +17,7 @@ int __cdecl __ms_fwprintf(FILE *file, const wchar_t *fmt, ...)
1717 va_list ap;
1818 int ret;
1919 va_start(ap, fmt);
20 ret = __stdio_common_vfwprintf(_CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS, file, fmt, NULL, ap);
20 ret = __stdio_common_vfwprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, file, fmt, NULL, ap);
2121 va_end(ap);
2222 return ret;
2323}
24int __cdecl (*__MINGW_IMP_SYMBOL(__ms_fwprintf))(FILE *, const wchar_t *, ...) = __ms_fwprintf;
lib/libc/mingw/stdio/ucrt_printf.c-1
......@@ -17,4 +17,3 @@ int __cdecl printf(const char * __restrict__ _Format,...)
1717 __builtin_va_end(ap);
1818 return ret;
1919}
20int __cdecl (*__MINGW_IMP_SYMBOL(printf))(const char *__restrict__, ...) = printf;
lib/libc/mingw/stdio/ucrt_scanf.c+1-2
......@@ -12,8 +12,7 @@ int __cdecl scanf(const char * __restrict__ _Format,...) {
1212 __builtin_va_list __ap;
1313 int __ret;
1414 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vfscanf(0, stdin, _Format, NULL, __ap);
15 __ret = __stdio_common_vfscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, stdin, _Format, NULL, __ap);
1616 __builtin_va_end(__ap);
1717 return __ret;
1818}
19int __cdecl (*__MINGW_IMP_SYMBOL(scanf))(const char *__restrict__, ...) = scanf;
lib/libc/mingw/stdio/ucrt_snprintf.c-1
......@@ -17,4 +17,3 @@ int __cdecl snprintf (char * __restrict__ __stream, size_t __n, const char * __r
1717 __builtin_va_end(ap);
1818 return ret;
1919}
20int __cdecl (*__MINGW_IMP_SYMBOL(snprintf))(char *__restrict__, size_t, const char *__restrict__, ...) = snprintf;
lib/libc/mingw/stdio/ucrt_snwprintf.c created+19
......@@ -0,0 +1,19 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl snwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, ...)
12{
13 __builtin_va_list __ap;
14 int __ret;
15 __builtin_va_start(__ap, format);
16 __ret = __stdio_common_vswprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, s, n, format, NULL, __ap);
17 __builtin_va_end(__ap);
18 return __ret;
19}
lib/libc/mingw/stdio/ucrt_sprintf.c-1
......@@ -17,4 +17,3 @@ int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,
1717 __builtin_va_end(ap);
1818 return ret;
1919}
20int __cdecl (*__MINGW_IMP_SYMBOL(sprintf))(char *__restrict__, const char *__restrict__, ...) = sprintf;
lib/libc/mingw/stdio/ucrt_sscanf.c+1-3
......@@ -12,9 +12,7 @@ int __cdecl sscanf(const char * __restrict__ _Src,const char * __restrict__ _For
1212 __builtin_va_list __ap;
1313 int __ret;
1414 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vsscanf(0, _Src, (size_t)-1, _Format, NULL, __ap);
15 __ret = __stdio_common_vsscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _Src, (size_t)-1, _Format, NULL, __ap);
1616 __builtin_va_end(__ap);
1717 return __ret;
1818}
19
20int __cdecl (*__MINGW_IMP_SYMBOL(sscanf))(const char *__restrict__, const char *__restrict__, ...) = sscanf;
lib/libc/mingw/stdio/ucrt_swprintf.c created+29
......@@ -0,0 +1,29 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl swprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,...)
12{
13 __builtin_va_list __ap;
14 int __ret;
15 /*
16 * __stdio_common_vswprintf() for case _Dest == NULL and _Count == 0 and
17 * without _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR option, is
18 * executed in "standard snprintf behavior" and returns number of (wide)
19 * chars required to allocate. For all other cases it is executed in a way
20 * that returns negative value on error. But C95+ compliant swprintf() for
21 * case _Count == 0 returns negative value, so handle this case specially.
22 */
23 if (_Dest == NULL && _Count == 0)
24 return -1;
25 __builtin_va_start(__ap, _Format);
26 __ret = __stdio_common_vswprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Dest, _Count, _Format, NULL, __ap);
27 __builtin_va_end(__ap);
28 return __ret < 0 ? -1 : __ret;
29}
lib/libc/mingw/stdio/ucrt_swscanf.c created+18
......@@ -0,0 +1,18 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl swscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,...) {
12 __builtin_va_list __ap;
13 int __ret;
14 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vswscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _Src, (size_t)-1, _Format, NULL, __ap);
16 __builtin_va_end(__ap);
17 return __ret;
18}
lib/libc/mingw/stdio/ucrt_vfprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl vfprintf(FILE * __restrict__ _File,const char * __restrict__ _Format
1212{
1313 return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _File, _Format, NULL, _ArgList);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(vfprintf))(FILE *__restrict__, const char *__restrict__, va_list) = vfprintf;
lib/libc/mingw/stdio/ucrt_vfscanf.c+1-2
......@@ -9,6 +9,5 @@
99#include <stdio.h>
1010
1111int __cdecl vfscanf (FILE *__stream, const char *__format, __builtin_va_list __local_argv) {
12 return __stdio_common_vfscanf(0, __stream, __format, NULL, __local_argv);
12 return __stdio_common_vfscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, __stream, __format, NULL, __local_argv);
1313}
14int __cdecl (*__MINGW_IMP_SYMBOL(vfscanf))(FILE *, const char *, __builtin_va_list) = vfscanf;
lib/libc/mingw/stdio/ucrt_vfwprintf.c created+14
......@@ -0,0 +1,14 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vfwprintf(FILE * __restrict__ _File, const wchar_t * __restrict__ _Format, va_list _ArgList)
12{
13 return __stdio_common_vfwprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _File, _Format, NULL, _ArgList);
14}
lib/libc/mingw/stdio/ucrt_vfwscanf.c created+13
......@@ -0,0 +1,13 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vfwscanf (FILE *__stream, const wchar_t *__format, __builtin_va_list __local_argv) {
12 return __stdio_common_vfwscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, __stream, __format, NULL, __local_argv);
13}
lib/libc/mingw/stdio/ucrt_vprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl vprintf(const char * __restrict__ _Format,va_list _ArgList)
1212{
1313 return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, stdout, _Format, NULL, _ArgList);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(vprintf))(const char *__restrict__, va_list) = vprintf;
lib/libc/mingw/stdio/ucrt_vscanf.c+1-2
......@@ -9,6 +9,5 @@
99#include <stdio.h>
1010
1111int __cdecl vscanf(const char *__format, __builtin_va_list __local_argv) {
12 return __stdio_common_vfscanf(0, stdin, __format, NULL, __local_argv);
12 return __stdio_common_vfscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, stdin, __format, NULL, __local_argv);
1313}
14int __cdecl (*__MINGW_IMP_SYMBOL(vscanf))(const char *, __builtin_va_list) = vscanf;
lib/libc/mingw/stdio/ucrt_vsnprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl vsnprintf (char * __restrict__ __stream, size_t __n, const char * __
1212{
1313 return __stdio_common_vsprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, __stream, __n, __format, NULL, __local_argv);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(vsnprintf))(char *__restrict__, size_t, const char *__restrict__, va_list) = vsnprintf;
lib/libc/mingw/stdio/ucrt_vsnwprintf.c created+14
......@@ -0,0 +1,14 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vsnwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, va_list arg)
12{
13 return __stdio_common_vswprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, s, n, format, NULL, arg);
14}
lib/libc/mingw/stdio/ucrt_vsprintf.c-1
......@@ -12,4 +12,3 @@ int __cdecl vsprintf(char * __restrict__ _Dest,const char * __restrict__ _Format
1212{
1313 return __stdio_common_vsprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, _Dest, (size_t)-1, _Format, NULL, _Args);
1414}
15int __cdecl (*__MINGW_IMP_SYMBOL(vsprintf))(char *__restrict__, const char *__restrict__, va_list) = vsprintf;
lib/libc/mingw/stdio/ucrt_vsscanf.c+1-2
......@@ -9,6 +9,5 @@
99#include <stdio.h>
1010
1111int __cdecl vsscanf (const char * __restrict__ __source, const char * __restrict__ __format, __builtin_va_list __local_argv) {
12 return __stdio_common_vsscanf(0, __source, (size_t)-1, __format, NULL, __local_argv);
12 return __stdio_common_vsscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, __source, (size_t)-1, __format, NULL, __local_argv);
1313}
14int __cdecl (*__MINGW_IMP_SYMBOL(vsscanf))(const char *__restrict, const char *__restrict__, __builtin_va_list) = vsscanf;
lib/libc/mingw/stdio/ucrt_vswprintf.c created+26
......@@ -0,0 +1,26 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vswprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,va_list _Args)
12{
13 int __ret;
14 /*
15 * __stdio_common_vswprintf() for case _Dest == NULL and _Count == 0 and
16 * without _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR option, is
17 * executed in "standard snprintf behavior" and returns number of (wide)
18 * chars required to allocate. For all other cases it is executed in a way
19 * that returns negative value on error. But C95+ compliant vswprintf() for
20 * case _Count == 0 returns negative value, so handle this case specially.
21 */
22 if (_Dest == NULL && _Count == 0)
23 return -1;
24 __ret = __stdio_common_vswprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Dest, _Count, _Format, NULL, _Args);
25 return __ret < 0 ? -1 : __ret;
26}
lib/libc/mingw/stdio/ucrt_vwprintf.c created+14
......@@ -0,0 +1,14 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vwprintf(const wchar_t * __restrict__ _Format, va_list _ArgList)
12{
13 return __stdio_common_vfwprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, stdout, _Format, NULL, _ArgList);
14}
lib/libc/mingw/stdio/ucrt_vwscanf.c created+13
......@@ -0,0 +1,13 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl vwscanf(const wchar_t *__format, __builtin_va_list __local_argv) {
12 return __stdio_common_vfwscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, stdin, __format, NULL, __local_argv);
13}
lib/libc/mingw/stdio/ucrt_wprintf.c created+23
......@@ -0,0 +1,23 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9
10#include <stdarg.h>
11#include <stdio.h>
12
13int __cdecl wprintf(const wchar_t *fmt, ...);
14
15int __cdecl wprintf(const wchar_t *fmt, ...)
16{
17 va_list ap;
18 int ret;
19 va_start(ap, fmt);
20 ret = __stdio_common_vfwprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, stdout, fmt, NULL, ap);
21 va_end(ap);
22 return ret;
23}
lib/libc/mingw/stdio/ucrt_wscanf.c created+18
......@@ -0,0 +1,18 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#undef __MSVCRT_VERSION__
8#define _UCRT
9#include <stdio.h>
10
11int __cdecl wscanf(const wchar_t * __restrict__ _Format,...) {
12 __builtin_va_list __ap;
13 int __ret;
14 __builtin_va_start(__ap, _Format);
15 __ret = __stdio_common_vfwscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, stdin, _Format, NULL, __ap);
16 __builtin_va_end(__ap);
17 return __ret;
18}
lib/libc/mingw/winpthreads/barrier.c+17-9
......@@ -20,12 +20,22 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#include <windows.h>
24#include <stdio.h>
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <assert.h>
2528#include <malloc.h>
29#include <stdio.h>
30
31#define WIN32_LEAN_AND_MEAN
32#include <windows.h>
33
34/* public header files */
2635#include "pthread.h"
36#include "semaphore.h"
37/* internal header files */
2738#include "barrier.h"
28#include "ref.h"
2939#include "misc.h"
3040
3141static pthread_spinlock_t barrier_global = PTHREAD_SPINLOCK_INITIALIZER;
......@@ -34,9 +44,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int
3444barrier_unref(volatile pthread_barrier_t *barrier, int res)
3545{
3646 pthread_spin_lock(&barrier_global);
37#ifdef WINPTHREAD_DBG
3847 assert((((barrier_t *)*barrier)->valid == LIFE_BARRIER) && (((barrier_t *)*barrier)->busy > 0));
39#endif
4048 ((barrier_t *)*barrier)->busy -= 1;
4149 pthread_spin_unlock(&barrier_global);
4250 return res;
......@@ -64,7 +72,7 @@ barrier_ref_destroy(volatile pthread_barrier_t *barrier, pthread_barrier_t *bDes
6472
6573 *bDestroy = NULL;
6674 pthread_spin_lock(&barrier_global);
67
75
6876 if (!barrier || !*barrier || ((barrier_t *)*barrier)->valid != LIFE_BARRIER) r = EINVAL;
6977 else {
7078 barrier_t *b_ = (barrier_t *)*barrier;
......@@ -92,15 +100,15 @@ int pthread_barrier_destroy(pthread_barrier_t *b_)
92100 pthread_barrier_t bDestroy;
93101 barrier_t *b;
94102 int r;
95
103
96104 while ((r = barrier_ref_destroy(b_,&bDestroy)) == EBUSY)
97105 Sleep(0);
98
106
99107 if (r)
100108 return r;
101109
102110 b = (barrier_t *)bDestroy;
103
111
104112 pthread_mutex_lock(&b->m);
105113
106114 if (sem_destroy(&b->sems[0]) != 0)
lib/libc/mingw/winpthreads/barrier.h-2
......@@ -34,8 +34,6 @@
3434 return EINVAL; \
3535 } while (0)
3636
37#include "semaphore.h"
38
3937typedef struct barrier_t barrier_t;
4038struct barrier_t
4139{
lib/libc/mingw/winpthreads/clock.c+112-15
......@@ -4,15 +4,23 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <assert.h>
712#include <errno.h>
813#include <stdint.h>
914#include <time.h>
15
16#define WIN32_LEAN_AND_MEAN
1017#include <windows.h>
11#ifndef IN_WINPTHREAD
12#define IN_WINPTHREAD 1
13#endif
14#include "pthread.h"
18
19#define WINPTHREAD_CLOCK_DECL WINPTHREAD_API
20
21/* public header files */
1522#include "pthread_time.h"
23/* internal header files */
1624#include "misc.h"
1725
1826#define POW10_7 10000000
......@@ -51,7 +59,7 @@ static WINPTHREADS_INLINE int lc_set_errno(int result)
5159 * If the function fails, the return value is -1,
5260 * with errno set to indicate the error.
5361 */
54int clock_getres(clockid_t clock_id, struct timespec *res)
62static int __clock_getres(clockid_t clock_id, struct _timespec64 *res)
5563{
5664 clockid_t id = clock_id;
5765
......@@ -113,7 +121,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
113121 * If the function fails, the return value is -1,
114122 * with errno set to indicate the error.
115123 */
116int clock_gettime(clockid_t clock_id, struct timespec *tp)
124static int __clock_gettime(clockid_t clock_id, struct _timespec64 *tp)
117125{
118126 unsigned __int64 t;
119127 LARGE_INTEGER pf, pc;
......@@ -172,7 +180,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
172180 return 0;
173181 }
174182
175 case CLOCK_THREAD_CPUTIME_ID:
183 case CLOCK_THREAD_CPUTIME_ID:
176184 {
177185 if(0 == GetThreadTimes(GetCurrentThread(), &ct.ft, &et.ft, &kt.ft, &ut.ft))
178186 return lc_set_errno(EINVAL);
......@@ -201,20 +209,20 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
201209 * If the function fails, the return value is -1,
202210 * with errno set to indicate the error.
203211 */
204int clock_nanosleep(clockid_t clock_id, int flags,
205 const struct timespec *request,
206 struct timespec *remain)
212static int __clock_nanosleep(clockid_t clock_id, int flags,
213 const struct _timespec64 *request,
214 struct _timespec64 *remain)
207215{
208 struct timespec tp;
216 struct _timespec64 tp;
209217
210218 if (clock_id != CLOCK_REALTIME)
211219 return lc_set_errno(EINVAL);
212220
213221 if (flags == 0)
214 return nanosleep(request, remain);
222 return nanosleep64(request, remain);
215223
216224 /* TIMER_ABSTIME = 1 */
217 clock_gettime(CLOCK_REALTIME, &tp);
225 __clock_gettime(CLOCK_REALTIME, &tp);
218226
219227 tp.tv_sec = request->tv_sec - tp.tv_sec;
220228 tp.tv_nsec = request->tv_nsec - tp.tv_nsec;
......@@ -223,7 +231,7 @@ int clock_nanosleep(clockid_t clock_id, int flags,
223231 tp.tv_sec --;
224232 }
225233
226 return nanosleep(&tp, remain);
234 return nanosleep64(&tp, remain);
227235}
228236
229237/**
......@@ -234,7 +242,7 @@ int clock_nanosleep(clockid_t clock_id, int flags,
234242 * If the function fails, the return value is -1,
235243 * with errno set to indicate the error.
236244 */
237int clock_settime(clockid_t clock_id, const struct timespec *tp)
245static int __clock_settime(clockid_t clock_id, const struct _timespec64 *tp)
238246{
239247 SYSTEMTIME st;
240248
......@@ -255,3 +263,92 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp)
255263
256264 return 0;
257265}
266
267/**
268 * Versions to use with 64-bit time_t (struct _timespec64)
269 */
270
271int clock_getres64 (clockid_t clock_id, struct _timespec64 *tp)
272{
273 return __clock_getres (clock_id, tp);
274}
275
276int clock_gettime64 (clockid_t clock_id, struct _timespec64 *tp)
277{
278 return __clock_gettime (clock_id, tp);
279}
280
281int clock_settime64 (clockid_t clock_id, const struct _timespec64 *tp)
282{
283 return __clock_settime (clock_id, tp);
284}
285
286int clock_nanosleep64 (clockid_t clock_id, int flags,
287 const struct _timespec64 *request, struct _timespec64 *remain)
288{
289 return __clock_nanosleep (clock_id, flags, request, remain);
290}
291
292/**
293 * Versions to use with 32-bit time_t (struct _timespec32)
294 */
295
296int clock_getres32 (clockid_t clock_id, struct _timespec32 *tp)
297{
298 struct _timespec64 tp64 = {0};
299
300 if (__clock_getres (clock_id, &tp64) == -1)
301 return -1;
302
303 tp->tv_sec = (__time32_t) tp64.tv_sec;
304 tp->tv_nsec = tp64.tv_nsec;
305
306 return 0;
307}
308
309int clock_gettime32 (clockid_t clock_id, struct _timespec32 *tp)
310{
311 struct _timespec64 tp64 = {0};
312
313 if (__clock_gettime (clock_id, &tp64) == -1)
314 return -1;
315
316 if (tp64.tv_sec > INT_MAX)
317 {
318 _set_errno (EOVERFLOW);
319 return -1;
320 }
321
322 tp->tv_sec = (__time32_t) tp64.tv_sec;
323 tp->tv_nsec = tp64.tv_nsec;
324
325 return 0;
326}
327
328int clock_settime32 (clockid_t clock_id, const struct _timespec32 *tp)
329{
330 struct _timespec64 tp64 = {.tv_sec = tp->tv_sec, .tv_nsec = tp->tv_nsec};
331 return __clock_settime (clock_id, &tp64);
332}
333
334int clock_nanosleep32 (clockid_t clock_id, int flags,
335 const struct _timespec32 *request, struct _timespec32 *remain)
336{
337 struct _timespec64 request64 = {
338 .tv_sec = request->tv_sec,
339 .tv_nsec = request->tv_nsec
340 };
341 struct _timespec64 remain64 = {0};
342
343 if (__clock_nanosleep (clock_id, flags, &request64, &remain64) == -1)
344 return -1;
345
346 assert (remain64.tv_sec <= INT_MAX);
347
348 if (remain != NULL) {
349 remain->tv_sec = (__time32_t)remain64.tv_sec;
350 remain->tv_nsec = remain64.tv_nsec;
351 }
352
353 return 0;
354}
lib/libc/mingw/winpthreads/cond.c+36-74
......@@ -24,17 +24,27 @@
2424 * Posix Condition Variables for Microsoft Windows.
2525 * 22-9-2010 Partly based on the ACE framework implementation.
2626 */
27#include <windows.h>
28#include <stdio.h>
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
2932#include <malloc.h>
33#include <stdio.h>
3034#include <time.h>
35
36#define WIN32_LEAN_AND_MEAN
37#include <windows.h>
38
39#define WINPTHREAD_COND_DECL WINPTHREAD_API
40
41/* public header files */
3142#include "pthread.h"
3243#include "pthread_time.h"
33#include "ref.h"
44/* internal header files */
3445#include "cond.h"
35#include "thread.h"
3646#include "misc.h"
37#include "winpthread_internal.h"
47#include "thread.h"
3848
3949#include "pthread_compat.h"
4050
......@@ -52,41 +62,13 @@ typedef struct sCondWaitHelper {
5262
5363int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout);
5464
55#ifdef WINPTHREAD_DBG
56static int print_state = 0;
57static FILE *fo;
58void cond_print_set(int state, FILE *f)
59{
60 if (f) fo = f;
61 if (!fo) fo = stdout;
62 print_state = state;
63}
64
65void cond_print(volatile pthread_cond_t *c, char *txt)
66{
67 if (!print_state) return;
68 cond_t *c_ = (cond_t *)*c;
69 if (c_ == NULL) {
70 fprintf(fo,"C%p %lu %s\n",(void *)*c,GetCurrentThreadId(),txt);
71 } else {
72 fprintf(fo,"C%p %lu V=%0X w=%ld %s\n",
73 (void *)*c,
74 GetCurrentThreadId(),
75 (int)c_->valid,
76 c_->waiters_count_,
77 txt
78 );
79 }
80}
81#endif
82
8365static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER;
8466
8567static int
8668cond_static_init (pthread_cond_t *c)
8769{
8870 int r = 0;
89
71
9072 pthread_spin_lock (&cond_locked);
9173 if (c == NULL)
9274 r = EINVAL;
......@@ -143,40 +125,6 @@ pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clock_id)
143125 return 0;
144126}
145127
146int
147__pthread_clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *rqtp,
148 struct timespec *rmtp)
149{
150 unsigned long long tick, tick2;
151 unsigned long long delay;
152 DWORD dw;
153
154 if (clock_id != CLOCK_REALTIME
155 && clock_id != CLOCK_MONOTONIC
156 && clock_id != CLOCK_PROCESS_CPUTIME_ID)
157 return EINVAL;
158 if ((flags & TIMER_ABSTIME) != 0)
159 delay = _pthread_rel_time_in_ms (rqtp);
160 else
161 delay = _pthread_time_in_ms_from_timespec (rqtp);
162 do
163 {
164 dw = (DWORD) (delay >= 99999ULL ? 99999ULL : delay);
165 tick = _pthread_time_in_ms ();
166 pthread_delay_np_ms (dw);
167 tick2 = _pthread_time_in_ms ();
168 tick2 -= tick;
169 if (tick2 >= delay)
170 delay = 0;
171 else
172 delay -= tick2;
173 }
174 while (delay != 0ULL);
175 if (rmtp)
176 memset (rmtp, 0, sizeof (*rmtp));
177 return 0;
178}
179
180128int
181129pthread_condattr_setpshared (pthread_condattr_t *a, int s)
182130{
......@@ -218,7 +166,7 @@ pthread_cond_init (pthread_cond_t *c, const pthread_condattr_t *a)
218166 _c->sema_b = CreateSemaphore (NULL, /* no security */
219167 0, /* initially 0 */
220168 0x7fffffff, /* max count */
221 NULL);
169 NULL);
222170 if (_c->sema_q == NULL || _c->sema_b == NULL) {
223171 if (_c->sema_q != NULL)
224172 CloseHandle (_c->sema_q);
......@@ -356,7 +304,7 @@ pthread_cond_broadcast (pthread_cond_t *c)
356304{
357305 cond_t *_c;
358306 int r;
359 int relCnt = 0;
307 int relCnt = 0;
360308
361309 if (!c || !*c)
362310 return EINVAL;
......@@ -465,7 +413,7 @@ tryagain:
465413}
466414
467415static int
468pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t *external_mutex, const struct timespec *t, int rel)
416pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t *external_mutex, const struct _timespec64 *t, int rel)
469417{
470418 sCondWaitHelper ch;
471419 DWORD dwr;
......@@ -531,17 +479,31 @@ tryagain:
531479}
532480
533481int
534pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *t)
482pthread_cond_timedwait64(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec64 *t)
535483{
536484 return pthread_cond_timedwait_impl(c, m, t, 0);
537485}
538486
539487int
540pthread_cond_timedwait_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *t)
488pthread_cond_timedwait32(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec32 *t)
489{
490 struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
491 return pthread_cond_timedwait_impl(c, m, &t64, 0);
492}
493
494int
495pthread_cond_timedwait64_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec64 *t)
541496{
542497 return pthread_cond_timedwait_impl(c, m, t, 1);
543498}
544499
500int
501pthread_cond_timedwait32_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec32 *t)
502{
503 struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
504 return pthread_cond_timedwait_impl(c, m, &t64, 1);
505}
506
545507static void
546508cleanup_wait (void *arg)
547509{
......@@ -751,5 +713,5 @@ do_sema_b_release(HANDLE sema, LONG count,CRITICAL_SECTION *cs, LONG *val)
751713 }
752714 InterlockedExchangeAdd(val, -count);
753715 LeaveCriticalSection(cs);
754 return EINVAL;
716 return EINVAL;
755717}
lib/libc/mingw/winpthreads/cond.h+1-7
......@@ -23,8 +23,6 @@
2323#ifndef WIN_PTHREADS_COND_H
2424#define WIN_PTHREADS_COND_H
2525
26#include <windows.h>
27
2826#define CHECK_COND(c) \
2927 do { \
3028 if (!(c) || !*c || (*c == PTHREAD_COND_INITIALIZER) \
......@@ -40,7 +38,7 @@
4038typedef struct cond_t cond_t;
4139struct cond_t
4240{
43 unsigned int valid;
41 unsigned int valid;
4442 int busy;
4543 LONG waiters_count_; /* Number of waiting threads. */
4644 LONG waiters_count_unblock_; /* Number of waiting threads whitch can be unblocked. */
......@@ -56,8 +54,4 @@ struct cond_t
5654 became signaled. */
5755};
5856
59void cond_print_set(int state, FILE *f);
60
61void cond_print(volatile pthread_cond_t *c, char *txt);
62
6357#endif
lib/libc/mingw/winpthreads/misc.c+15-2
......@@ -20,8 +20,16 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#define WIN32_LEAN_AND_MEAN
2328#include <windows.h>
29
30/* public header files */
2431#include "pthread.h"
32/* internal header files */
2533#include "misc.h"
2634
2735void (WINAPI *_pthread_get_system_time_best_as_file_time) (LPFILETIME) = NULL;
......@@ -29,6 +37,8 @@ static ULONGLONG (WINAPI *_pthread_get_tick_count_64) (VOID);
2937HRESULT (WINAPI *_pthread_set_thread_description) (HANDLE, PCWSTR) = NULL;
3038
3139#if defined(__GNUC__) || defined(__clang__)
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
3242__attribute__((constructor(0)))
3343#endif
3444static void winpthreads_init(void)
......@@ -55,6 +65,9 @@ static void winpthreads_init(void)
5565 (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) GetProcAddress(mod, "SetThreadDescription");
5666 }
5767}
68#if defined(__GNUC__) || defined(__clang__)
69#pragma GCC diagnostic pop
70#endif
5871
5972#if defined(_MSC_VER) && !defined(__clang__)
6073/* Force a reference to __xc_t to prevent whole program optimization
......@@ -82,7 +95,7 @@ unsigned long long _pthread_time_in_ms(void)
8295 - 0x19DB1DED53E8000ULL) / 10000ULL;
8396}
8497
85unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts)
98unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 *ts)
8699{
87100 unsigned long long t = (unsigned long long) ts->tv_sec * 1000LL;
88101 /* The +999999 is here to ensure that the division always rounds up */
......@@ -91,7 +104,7 @@ unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts)
91104 return t;
92105}
93106
94unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts)
107unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts)
95108{
96109 unsigned long long t1 = _pthread_time_in_ms_from_timespec(ts);
97110 unsigned long long t2 = _pthread_time_in_ms();
lib/libc/mingw/winpthreads/misc.h+4-31
......@@ -23,37 +23,10 @@
2323#ifndef WIN_PTHREADS_MISC_H
2424#define WIN_PTHREADS_MISC_H
2525
26#include <limits.h>
27/* public header files */
2628#include "pthread_compat.h"
2729
28#ifndef assert
29
30#ifndef ASSERT_TRACE
31# define ASSERT_TRACE 0
32#else
33# undef ASSERT_TRACE
34# define ASSERT_TRACE 0
35#endif
36
37# define assert(e) \
38 ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
39 "Assertion succeeded: (%s), file %s, line %d\n", \
40 #e, __FILE__, (int) __LINE__), \
41 fflush(stderr) : \
42 0) : \
43 (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \
44 #e, __FILE__, (int) __LINE__), exit(1), 0))
45
46# define fixme(e) \
47 ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
48 "Assertion succeeded: (%s), file %s, line %d\n", \
49 #e, __FILE__, (int) __LINE__), \
50 fflush(stderr) : \
51 0) : \
52 (fprintf(stderr, "FIXME: (%s), file %s, line %d\n", \
53 #e, __FILE__, (int) __LINE__), 0, 0))
54
55#endif
56
5730#define PTR2INT(x) ((int)(uintptr_t)(x))
5831
5932#if SIZE_MAX>UINT_MAX
......@@ -102,8 +75,8 @@ static WINPTHREADS_INLINE unsigned long dwMilliSecs(unsigned long long ms)
10275}
10376
10477unsigned long long _pthread_time_in_ms(void);
105unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts);
106unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts);
78unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 *ts);
79unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts);
10780unsigned long _pthread_wait_for_single_object (void *handle, unsigned long timeout);
10881unsigned long _pthread_wait_for_multiple_objects (unsigned long count, void **handles, unsigned int all, unsigned long timeout);
10982
lib/libc/mingw/winpthreads/mutex.c+29-6
......@@ -21,11 +21,22 @@
2121 DEALINGS IN THE SOFTWARE.
2222*/
2323
24#include <windows.h>
25#include <stdio.h>
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
2628#include <malloc.h>
2729#include <stdbool.h>
30#include <stdio.h>
31
32#define WIN32_LEAN_AND_MEAN
33#include <windows.h>
34
35#define WINPTHREAD_MUTEX_DECL WINPTHREAD_API
36
37/* public header files */
2838#include "pthread.h"
39/* internal header files */
2940#include "misc.h"
3041
3142typedef enum {
......@@ -184,7 +195,8 @@ pthread_mutex_lock (pthread_mutex_t *m)
184195 return pthread_mutex_lock_intern (m, INFINITE);
185196}
186197
187int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts)
198/* Internal version which always uses `struct _timespec64`. */
199static int __pthread_mutex_timedlock(pthread_mutex_t *m, const struct _timespec64 *ts)
188200{
189201 unsigned long long patience;
190202 if (ts != NULL) {
......@@ -199,8 +211,19 @@ int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts)
199211 return pthread_mutex_lock_intern(m, patience);
200212}
201213
214int pthread_mutex_timedlock64(pthread_mutex_t *m, const struct _timespec64 *ts)
215{
216 return __pthread_mutex_timedlock (m, ts);
217}
218
219int pthread_mutex_timedlock32(pthread_mutex_t *m, const struct _timespec32 *ts)
220{
221 struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
222 return __pthread_mutex_timedlock (m, &ts64);
223}
224
202225int pthread_mutex_unlock(pthread_mutex_t *m)
203{
226{
204227 /* Here m might an initialiser of an error-checking or recursive mutex, in
205228 which case the behaviour is well-defined, so we can't skip this check. */
206229 mutex_impl_t *mi = mutex_impl(m);
......@@ -305,9 +328,9 @@ int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type)
305328{
306329 if (!a || !type)
307330 return EINVAL;
308
331
309332 *type = *a & 3;
310
333
311334 return 0;
312335}
313336
lib/libc/mingw/winpthreads/nanosleep.c+41-3
......@@ -4,12 +4,24 @@
44 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
55 */
66
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <assert.h>
712#include <errno.h>
813#include <time.h>
14
15#define WIN32_LEAN_AND_MEAN
916#include <windows.h>
17
18#define WINPTHREAD_NANOSLEEP_DECL WINPTHREAD_API
19
20/* public header files */
1021#include "pthread.h"
1122#include "pthread_time.h"
12#include "winpthread_internal.h"
23/* internal header files */
24#include "thread.h"
1325
1426#define POW10_3 1000
1527#define POW10_4 10000
......@@ -25,7 +37,7 @@
2537 * If the function fails, the return value is -1,
2638 * with errno set to indicate the error.
2739 */
28int nanosleep(const struct timespec *request, struct timespec *remain)
40static int __nanosleep(const struct _timespec64 *request, struct _timespec64 *remain)
2941{
3042 unsigned long ms, rc = 0;
3143 unsigned __int64 u64, want, real;
......@@ -48,7 +60,7 @@ int nanosleep(const struct timespec *request, struct timespec *remain)
4860 else ms = (unsigned long) u64;
4961
5062 u64 -= ms;
51 rc = pthread_delay_np_ms(ms);
63 rc = _pthread_delay_np_ms(ms);
5264 }
5365
5466 if (rc != 0) { /* WAIT_IO_COMPLETION (192) */
......@@ -69,3 +81,29 @@ int nanosleep(const struct timespec *request, struct timespec *remain)
6981
7082 return 0;
7183}
84
85int nanosleep64(const struct _timespec64 *request, struct _timespec64 *remain)
86{
87 return __nanosleep (request, remain);
88}
89
90int nanosleep32(const struct _timespec32 *request, struct _timespec32 *remain)
91{
92 struct _timespec64 request64 = {
93 .tv_sec = request->tv_sec,
94 .tv_nsec = request->tv_nsec
95 };
96 struct _timespec64 remain64 = {0};
97
98 if (__nanosleep (&request64, &remain64) == -1)
99 return -1;
100
101 assert (remain64.tv_sec <= INT_MAX);
102
103 if (remain != NULL) {
104 remain->tv_sec = (__time32_t)remain64.tv_sec;
105 remain->tv_nsec = remain64.tv_nsec;
106 }
107
108 return 0;
109}
lib/libc/mingw/winpthreads/ref.c deleted-34
......@@ -1,34 +0,0 @@
1/*
2 Copyright (c) 2011-2016 mingw-w64 project
3
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 DEALINGS IN THE SOFTWARE.
21*/
22
23#include <windows.h>
24#include <winternl.h>
25#include <stdio.h>
26#include "pthread.h"
27#include "semaphore.h"
28#include "rwlock.h"
29#include "cond.h"
30#include "barrier.h"
31#include "sem.h"
32#include "ref.h"
33#include "misc.h"
34
lib/libc/mingw/winpthreads/ref.h deleted-29
......@@ -1,29 +0,0 @@
1/*
2 Copyright (c) 2011-2016 mingw-w64 project
3
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 DEALINGS IN THE SOFTWARE.
21*/
22
23#ifndef WIN_PTHREADS_REF_H
24#define WIN_PTHREADS_REF_H
25#include "pthread.h"
26#include "semaphore.h"
27
28#endif
29
lib/libc/mingw/winpthreads/rwlock.c+57-48
......@@ -20,14 +20,25 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#include <windows.h>
24#include <stdio.h>
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <assert.h>
2528#include <malloc.h>
29#include <stdio.h>
30
31#define WIN32_LEAN_AND_MEAN
32#include <windows.h>
33
34#define WINPTHREAD_RWLOCK_DECL WINPTHREAD_API
35
36/* public header files */
2637#include "pthread.h"
27#include "thread.h"
28#include "ref.h"
29#include "rwlock.h"
38/* internal header files */
3039#include "misc.h"
40#include "rwlock.h"
41#include "thread.h"
3142
3243static pthread_spinlock_t rwl_global = PTHREAD_SPINLOCK_INITIALIZER;
3344
......@@ -36,9 +47,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t
3647static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_unref(volatile pthread_rwlock_t *rwl, int res)
3748{
3849 pthread_spin_lock(&rwl_global);
39#ifdef WINPTHREAD_DBG
4050 assert((((rwlock_t *)*rwl)->valid == LIFE_RWLOCK) && (((rwlock_t *)*rwl)->busy > 0));
41#endif
4251 ((rwlock_t *)*rwl)->busy--;
4352 pthread_spin_unlock(&rwl_global);
4453 return res;
......@@ -87,7 +96,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_ref_destroy(pthread_rwlock_t *r
8796
8897 *rDestroy = (pthread_rwlock_t)NULL;
8998 pthread_spin_lock(&rwl_global);
90
99
91100 if (!rwl || !*rwl) r = EINVAL;
92101 else {
93102 rwlock_t *r_ = (rwlock_t *)*rwl;
......@@ -128,30 +137,6 @@ static int rwlock_free_both_locks(rwlock_t *rwlock, int last_fail)
128137 return ret;
129138}
130139
131#ifdef WINPTHREAD_DBG
132static int print_state = 0;
133void rwl_print_set(int state)
134{
135 print_state = state;
136}
137
138void rwl_print(volatile pthread_rwlock_t *rwl, char *txt)
139{
140 if (!print_state) return;
141 rwlock_t *r = (rwlock_t *)*rwl;
142 if (r == NULL) {
143 printf("RWL%p %lu %s\n",(void *)*rwl,GetCurrentThreadId(),txt);
144 } else {
145 printf("RWL%p %lu V=%0X B=%d r=%ld w=%ld L=%p %s\n",
146 (void *)*rwl,
147 GetCurrentThreadId(),
148 (int)r->valid,
149 (int)r->busy,
150 0L,0L,NULL,txt);
151 }
152}
153#endif
154
155140static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER;
156141
157142static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t *rw)
......@@ -165,7 +150,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t
165150 }
166151 r = pthread_rwlock_init (rw, NULL);
167152 pthread_spin_unlock(&cond_locked);
168
153
169154 return r;
170155}
171156
......@@ -178,7 +163,7 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const pthread_rwlockattr_t *
178163 return EINVAL;
179164 *rwlock_ = (pthread_rwlock_t)NULL;
180165 if ((rwlock = calloc(1, sizeof(*rwlock))) == NULL)
181 return ENOMEM;
166 return ENOMEM;
182167 rwlock->valid = DEAD_RWLOCK;
183168
184169 rwlock->nex_count = rwlock->nsh_count = rwlock->ncomplete = 0;
......@@ -203,18 +188,18 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const pthread_rwlockattr_t *
203188 rwlock->valid = LIFE_RWLOCK;
204189 *rwlock_ = (pthread_rwlock_t)rwlock;
205190 return r;
206}
191}
207192
208193int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_)
209194{
210195 rwlock_t *rwlock;
211196 pthread_rwlock_t rDestroy;
212197 int r, r2;
213
198
214199 pthread_spin_lock(&cond_locked);
215200 r = rwl_ref_destroy(rwlock_,&rDestroy);
216201 pthread_spin_unlock(&cond_locked);
217
202
218203 if(r) return r;
219204 if(!rDestroy) return 0; /* destroyed a (still) static initialized rwl */
220205
......@@ -245,7 +230,7 @@ int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_)
245230 rwlock->valid = DEAD_RWLOCK;
246231 free((void *)rDestroy);
247232 return 0;
248}
233}
249234
250235int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_)
251236{
......@@ -279,7 +264,8 @@ int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_)
279264 return rwl_unref(rwlock_, ret);
280265}
281266
282int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec *ts)
267/* Internal version which always uses `struct _timespec64`. */
268static int __pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct _timespec64 *ts)
283269{
284270 rwlock_t *rwlock;
285271 int ret;
......@@ -290,12 +276,12 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec
290276 if(ret != 0) return ret;
291277
292278 rwlock = (rwlock_t *)*rwlock_;
293 if ((ret = pthread_mutex_timedlock (&rwlock->mex, ts)) != 0)
279 if ((ret = pthread_mutex_timedlock64 (&rwlock->mex, ts)) != 0)
294280 return rwl_unref(rwlock_, ret);
295281 InterlockedIncrement(&rwlock->nsh_count);
296282 if (rwlock->nsh_count == INT_MAX)
297283 {
298 ret = pthread_mutex_timedlock(&rwlock->mcomplete, ts);
284 ret = pthread_mutex_timedlock64(&rwlock->mcomplete, ts);
299285 if (ret != 0)
300286 {
301287 if (ret == ETIMEDOUT)
......@@ -312,6 +298,17 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec
312298 return rwl_unref(rwlock_, ret);
313299}
314300
301int pthread_rwlock_timedrdlock64(pthread_rwlock_t *l, const struct _timespec64 *ts)
302{
303 return __pthread_rwlock_timedrdlock (l, ts);
304}
305
306int pthread_rwlock_timedrdlock32(pthread_rwlock_t *l, const struct _timespec32 *ts)
307{
308 struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
309 return __pthread_rwlock_timedrdlock (l, &ts64);
310}
311
315312int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_)
316313{
317314 rwlock_t *rwlock;
......@@ -340,7 +337,7 @@ int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_)
340337 }
341338 ret = pthread_mutex_unlock(&rwlock->mex);
342339 return rwl_unref(rwlock_,ret);
343}
340}
344341
345342int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_)
346343{
......@@ -378,7 +375,7 @@ int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_)
378375 }
379376 rwlock->nex_count = 1;
380377 return rwl_unref(rwlock_, 0);
381}
378}
382379
383380int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_)
384381{
......@@ -409,7 +406,7 @@ int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_)
409406 ret = rwlock_free_both_locks(rwlock, 0);
410407 }
411408 return rwl_unref(rwlock_, ret);
412}
409}
413410
414411static void st_cancelwrite (void *arg)
415412{
......@@ -459,7 +456,8 @@ int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock_)
459456 return rwl_unref(rwlock_,ret);
460457}
461458
462int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec *ts)
459/* Internal version which always uses `struct _timespec64`. */
460static int __pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct _timespec64 *ts)
463461{
464462 int ret;
465463 rwlock_t *rwlock;
......@@ -471,10 +469,10 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec
471469 return ret;
472470 rwlock = (rwlock_t *)*rwlock_;
473471
474 ret = pthread_mutex_timedlock(&rwlock->mex, ts);
472 ret = pthread_mutex_timedlock64(&rwlock->mex, ts);
475473 if (ret != 0)
476474 return rwl_unref(rwlock_,ret);
477 ret = pthread_mutex_timedlock (&rwlock->mcomplete, ts);
475 ret = pthread_mutex_timedlock64(&rwlock->mcomplete, ts);
478476 if (ret != 0)
479477 {
480478 pthread_mutex_unlock(&rwlock->mex);
......@@ -492,7 +490,7 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec
492490 rwlock->ncomplete = -rwlock->nsh_count;
493491 pthread_cleanup_push(st_cancelwrite, (void *) rwlock);
494492 do {
495 ret = pthread_cond_timedwait(&rwlock->ccomplete, &rwlock->mcomplete, ts);
493 ret = pthread_cond_timedwait64(&rwlock->ccomplete, &rwlock->mcomplete, ts);
496494 } while (rwlock->ncomplete < 0 && !ret);
497495 pthread_cleanup_pop(!ret ? 0 : 1);
498496
......@@ -505,6 +503,17 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec
505503 return rwl_unref(rwlock_,ret);
506504}
507505
506int pthread_rwlock_timedwrlock64(pthread_rwlock_t *rwlock, const struct _timespec64 *ts)
507{
508 return __pthread_rwlock_timedwrlock (rwlock, ts);
509}
510
511int pthread_rwlock_timedwrlock32(pthread_rwlock_t *rwlock, const struct _timespec32 *ts)
512{
513 struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
514 return __pthread_rwlock_timedwrlock (rwlock, &ts64);
515}
516
508517int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a)
509518{
510519 if (!a)
lib/libc/mingw/winpthreads/rwlock.h-3
......@@ -43,7 +43,4 @@ struct rwlock_t {
4343#define RWL_SET 0x01
4444#define RWL_TRY 0x02
4545
46void rwl_print(volatile pthread_rwlock_t *rwl, char *txt);
47void rwl_print_set(int state);
48
4946#endif
lib/libc/mingw/winpthreads/sched.c+11-3
......@@ -20,12 +20,20 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#include <windows.h>
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
2427#include <stdio.h>
25#include "pthread.h"
26#include "thread.h"
2728
29#define WIN32_LEAN_AND_MEAN
30#include <windows.h>
31
32/* public header files */
33#include "pthread.h"
34/* internal header files */
2835#include "misc.h"
36#include "thread.h"
2937
3038int sched_get_priority_min(int pol)
3139{
lib/libc/mingw/winpthreads/sem.c+28-8
......@@ -20,15 +20,23 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#include <windows.h>
24#include <stdio.h>
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
2527#include <malloc.h>
28#include <stdio.h>
29
30#define WIN32_LEAN_AND_MEAN
31#include <windows.h>
32
33/* public header files */
2634#include "pthread.h"
27#include "thread.h"
28#include "misc.h"
2935#include "semaphore.h"
36/* internal header files */
37#include "misc.h"
3038#include "sem.h"
31#include "ref.h"
39#include "thread.h"
3240
3341int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout);
3442
......@@ -212,8 +220,9 @@ sem_wait (sem_t *sem)
212220 return sem_result (ret);
213221}
214222
215int
216sem_timedwait (sem_t *sem, const struct timespec *t)
223/* Internal version which always uses `struct _timespec64`. */
224static int
225__sem_timedwait (sem_t *sem, const struct _timespec64 *t)
217226{
218227 int cur_v, ret = 0;
219228 DWORD dwr;
......@@ -251,6 +260,17 @@ sem_timedwait (sem_t *sem, const struct timespec *t)
251260 return sem_result (ret);
252261}
253262
263int sem_timedwait64(sem_t *sem, const struct _timespec64 *t)
264{
265 return __sem_timedwait (sem, t);
266}
267
268int sem_timedwait32(sem_t *sem, const struct _timespec32 *t)
269{
270 struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
271 return __sem_timedwait (sem, &t64);
272}
273
254274int
255275sem_post (sem_t *sem)
256276{
......@@ -350,5 +370,5 @@ sem_getvalue (sem_t *sem, int *sval)
350370
351371 *sval = (int) sv->value;
352372 pthread_mutex_unlock (&sv->vlock);
353 return 0;
373 return 0;
354374}
lib/libc/mingw/winpthreads/sem.h-2
......@@ -23,8 +23,6 @@
2323#ifndef WIN_SEM
2424#define WIN_SEM
2525
26#include <windows.h>
27
2826#define LIFE_SEM 0xBAB1F00D
2927#define DEAD_SEM 0xDEADBEEF
3028
lib/libc/mingw/winpthreads/spinlock.c+9-1
......@@ -21,8 +21,16 @@
2121 DEALINGS IN THE SOFTWARE.
2222*/
2323
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#define WIN32_LEAN_AND_MEAN
2429#include <windows.h>
30
31/* public header files */
2532#include "pthread.h"
33/* internal header files */
2634#include "misc.h"
2735
2836/* We use the pthread_spinlock_t itself as a lock:
......@@ -56,7 +64,7 @@ pthread_spin_lock (pthread_spinlock_t *lock)
5664 } while (*lk == 0);
5765 return 0;
5866}
59
67
6068int
6169pthread_spin_trylock (pthread_spinlock_t *lock)
6270{
lib/libc/mingw/winpthreads/thread.c+55-57
......@@ -20,16 +20,27 @@
2020 DEALINGS IN THE SOFTWARE.
2121*/
2222
23#include <windows.h>
24#include <strsafe.h>
25#include <stdio.h>
26#include <stdlib.h>
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
2727#include <malloc.h>
2828#include <signal.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <wchar.h>
32
33#define WIN32_LEAN_AND_MEAN
34#include <windows.h>
35#include <strsafe.h>
36
37#define WINPTHREAD_THREAD_DECL WINPTHREAD_API
38
39/* public header files */
2940#include "pthread.h"
30#include "thread.h"
41/* internal header files */
3142#include "misc.h"
32#include "winpthread_internal.h"
43#include "thread.h"
3344
3445static _pthread_v *__pthread_self_lite (void);
3546
......@@ -537,34 +548,6 @@ WINPTHREADS_ATTRIBUTE((WINPTHREADS_SECTION(".CRT$XLF")))
537548extern const PIMAGE_TLS_CALLBACK __xl_f;
538549const PIMAGE_TLS_CALLBACK __xl_f = __dyn_tls_pthread;
539550
540
541#ifdef WINPTHREAD_DBG
542static int print_state = 0;
543void thread_print_set (int state)
544{
545 print_state = state;
546}
547
548void
549thread_print (volatile pthread_t t, char *txt)
550{
551 if (!print_state)
552 return;
553 if (!t)
554 printf("T%p %lu %s\n",NULL,GetCurrentThreadId(),txt);
555 else
556 {
557 printf("T%p %lu V=%0X H=%p %s\n",
558 (void *) __pth_gpointer_locked (t),
559 GetCurrentThreadId(),
560 (__pth_gpointer_locked (t))->valid,
561 (__pth_gpointer_locked (t))->h,
562 txt
563 );
564 }
565}
566#endif
567
568551/* Internal collect-once structure. */
569552typedef struct collect_once_t {
570553 pthread_once_t *o;
......@@ -677,8 +660,8 @@ pthread_timechange_handler_np(void *dummy)
677660
678661/* Compatibility routine for pthread-win32. It waits for ellapse of
679662 interval and additionally checks for possible thread-cancelation. */
680int
681pthread_delay_np (const struct timespec *interval)
663static int
664__pthread_delay_np (const struct _timespec64 *interval)
682665{
683666 DWORD to = (!interval ? 0 : dwMilliSecs (_pthread_time_in_ms_from_timespec (interval)));
684667 struct _pthread_v *s = __pthread_self_lite ();
......@@ -699,10 +682,21 @@ pthread_delay_np (const struct timespec *interval)
699682 return 0;
700683}
701684
702int pthread_delay_np_ms (DWORD to);
685int
686pthread_delay64_np (const struct _timespec64 *interval)
687{
688 return __pthread_delay_np(interval);
689}
690
691int
692pthread_delay32_np (const struct _timespec32 *interval)
693{
694 struct _timespec64 interval64 = {.tv_sec = interval->tv_sec, .tv_nsec = interval->tv_nsec};
695 return __pthread_delay_np(&interval64);
696}
703697
704698int
705pthread_delay_np_ms (DWORD to)
699_pthread_delay_np_ms (DWORD to)
706700{
707701 struct _pthread_v *s = __pthread_self_lite ();
708702
......@@ -725,7 +719,7 @@ pthread_delay_np_ms (DWORD to)
725719/* Compatibility routine for pthread-win32. It returns the
726720 amount of available CPUs on system. */
727721int
728pthread_num_processors_np(void)
722pthread_num_processors_np(void)
729723{
730724 int r = 0;
731725 DWORD_PTR ProcessAffinityMask, SystemAffinityMask;
......@@ -742,10 +736,10 @@ pthread_num_processors_np(void)
742736/* Compatiblity routine for pthread-win32. Allows to set amount of used
743737 CPUs for process. */
744738int
745pthread_set_num_processors_np(int n)
739pthread_set_num_processors_np(int n)
746740{
747741 DWORD_PTR ProcessAffinityMask, ProcessNewAffinityMask = 0, SystemAffinityMask;
748 int r = 0;
742 int r = 0;
749743 /* need at least 1 */
750744 n = n ? n : 1;
751745 if (GetProcessAffinityMask (GetCurrentProcess (), &ProcessAffinityMask, &SystemAffinityMask))
......@@ -878,7 +872,7 @@ pthread_key_delete (pthread_key_t key)
878872 return EINVAL;
879873
880874 pthread_rwlock_wrlock (&_pthread_key_lock);
881
875
882876 _pthread_key_dest[key] = NULL;
883877
884878 /* Start next search from our location */
......@@ -910,7 +904,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
910904{
911905 DWORD lasterr = GetLastError ();
912906 _pthread_v *t = __pthread_self_lite ();
913
907
914908 pthread_spin_lock (&t->spin_keys);
915909
916910 if (key >= t->keymax)
......@@ -1522,7 +1516,7 @@ void _fpreset (void);
15221516
15231517#if defined(__i386__)
15241518/* Align ESP on 16-byte boundaries. */
1525# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
1519# if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
15261520__attribute__((force_align_arg_pointer))
15271521# endif
15281522#endif
......@@ -1553,17 +1547,7 @@ pthread_create_wrapper (void *args)
15531547 if (tv->func)
15541548 trslt = (intptr_t) tv->func(tv->ret_arg);
15551549 #ifdef __SEH__
1556 asm ("\tnop\n\t.tl_end: nop\n"
1557#ifdef __arm__
1558 "\t.seh_handler __C_specific_handler, %except\n"
1559#else
1560 "\t.seh_handler __C_specific_handler, @except\n"
1561#endif
1562 "\t.seh_handlerdata\n"
1563 "\t.long 1\n"
1564 "\t.rva .tl_start, .tl_end, _gnu_exception_handler ,.tl_end\n"
1565 "\t.text"
1566 );
1550 asm ("\tnop\n\t.tl_end: nop\n");
15671551 #endif
15681552 pthread_mutex_lock (&mtx_pthr_locked);
15691553 tv->ret_arg = (void*) trslt;
......@@ -1601,6 +1585,19 @@ pthread_create_wrapper (void *args)
16011585 Sleep (0);
16021586 _endthreadex (rslt);
16031587 return rslt;
1588
1589#if defined(__SEH__)
1590 asm(
1591#ifdef __arm__
1592 "\t.seh_handler __C_specific_handler, %except\n"
1593#else
1594 "\t.seh_handler __C_specific_handler, @except\n"
1595#endif
1596 "\t.seh_handlerdata\n"
1597 "\t.long 1\n"
1598 "\t.rva .tl_start, .tl_end, _gnu_exception_handler ,.tl_end\n"
1599 "\t.text\n");
1600#endif
16041601}
16051602
16061603int
......@@ -1881,13 +1878,14 @@ pthread_setname_np (pthread_t thread, const char *name)
18811878
18821879 if (_pthread_set_thread_description != NULL)
18831880 {
1884 size_t required_size = mbstowcs(NULL, name, 0);
1881 mbstate_t mbs = {0};
1882 size_t required_size = mbsrtowcs(NULL, &name, 0, &mbs);
18851883 if (required_size != (size_t)-1)
18861884 {
18871885 wchar_t *wname = malloc((required_size + 1) * sizeof(wchar_t));
18881886 if (wname != NULL)
18891887 {
1890 mbstowcs(wname, name, required_size + 1);
1888 mbsrtowcs(wname, &name, required_size + 1, &mbs);
18911889 _pthread_set_thread_description(tv->h, wname);
18921890 free(wname);
18931891 }
lib/libc/mingw/winpthreads/thread.h+2-5
......@@ -23,8 +23,8 @@
2323#ifndef WIN_PTHREAD_H
2424#define WIN_PTHREAD_H
2525
26#include <windows.h>
2726#include <setjmp.h>
27/* internal header files */
2828#include "rwlock.h"
2929
3030#define LIFE_THREAD 0xBAB1F00D
......@@ -69,11 +69,8 @@ typedef struct __pthread_idlist {
6969
7070int _pthread_tryjoin(pthread_t t, void **res);
7171void _pthread_setnobreak(int);
72#ifdef WINPTHREAD_DBG
73void thread_print_set(int state);
74void thread_print(volatile pthread_t t, char *txt);
75#endif
7672int __pthread_shallcancel(void);
7773WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id);
74int _pthread_delay_np_ms (DWORD to);
7875
7976#endif
lib/libc/mingw/winpthreads/winpthread_internal.h deleted-27
......@@ -1,27 +0,0 @@
1/*
2 Copyright (c) 2011-2016 mingw-w64 project
3
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 DEALINGS IN THE SOFTWARE.
21*/
22
23#ifndef WINPTHREAD_INTERNAL_H
24#define WINPTHREAD_INTERNAL_H
25WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id);
26int pthread_delay_np_ms (DWORD to);
27#endif /*WINPTHREAD_INTERNAL_H*/
src/libs/mingw.zig+26-10
......@@ -154,7 +154,8 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
154154 try addCcArgs(comp, arena, &winpthreads_args);
155155 try winpthreads_args.appendSlice(&[_][]const u8{
156156 "-DIN_WINPTHREAD",
157 "-DWIN32_LEAN_AND_MEAN",
157 // winpthreads incorrectly assumes that Clang has `-Wprio-ctor-dtor`.
158 "-Wno-unknown-warning-option",
158159 });
159160
160161 switch (comp.compilerRtOptMode()) {
......@@ -485,7 +486,6 @@ const mingw32_generic_src = [_][]const u8{
485486 "crt" ++ path.sep_str ++ "pesect.c",
486487 "crt" ++ path.sep_str ++ "udllargc.c",
487488 "crt" ++ path.sep_str ++ "xthdloc.c",
488 "crt" ++ path.sep_str ++ "CRT_fp10.c",
489489 "crt" ++ path.sep_str ++ "mingw_helpers.c",
490490 "crt" ++ path.sep_str ++ "pseudo-reloc.c",
491491 "crt" ++ path.sep_str ++ "udll_argv.c",
......@@ -609,7 +609,6 @@ const mingw32_generic_src = [_][]const u8{
609609 "misc" ++ path.sep_str ++ "delayimp.c",
610610 "misc" ++ path.sep_str ++ "dirent.c",
611611 "misc" ++ path.sep_str ++ "dirname.c",
612 "misc" ++ path.sep_str ++ "dllentrypoint.c",
613612 "misc" ++ path.sep_str ++ "dllmain.c",
614613 "misc" ++ path.sep_str ++ "feclearexcept.c",
615614 "misc" ++ path.sep_str ++ "fegetenv.c",
......@@ -621,10 +620,14 @@ const mingw32_generic_src = [_][]const u8{
621620 "misc" ++ path.sep_str ++ "fesetexceptflag.c",
622621 "misc" ++ path.sep_str ++ "fesetround.c",
623622 "misc" ++ path.sep_str ++ "fetestexcept.c",
623 "misc" ++ path.sep_str ++ "mingw_controlfp.c",
624 "misc" ++ path.sep_str ++ "mingw_setfp.c",
624625 "misc" ++ path.sep_str ++ "feupdateenv.c",
625626 "misc" ++ path.sep_str ++ "ftruncate.c",
626 "misc" ++ path.sep_str ++ "ftw.c",
627 "misc" ++ path.sep_str ++ "ftw32.c",
628 "misc" ++ path.sep_str ++ "ftw32i64.c",
627629 "misc" ++ path.sep_str ++ "ftw64.c",
630 "misc" ++ path.sep_str ++ "ftw64i32.c",
628631 "misc" ++ path.sep_str ++ "fwide.c",
629632 "misc" ++ path.sep_str ++ "getlogin.c",
630633 "misc" ++ path.sep_str ++ "getopt.c",
......@@ -669,12 +672,12 @@ const mingw32_generic_src = [_][]const u8{
669672 "stdio" ++ path.sep_str ++ "_findfirst64i32.c",
670673 "stdio" ++ path.sep_str ++ "_findnext64i32.c",
671674 "stdio" ++ path.sep_str ++ "_fstat64i32.c",
672 "stdio" ++ path.sep_str ++ "_stat.c",
673675 "stdio" ++ path.sep_str ++ "_stat64i32.c",
674676 "stdio" ++ path.sep_str ++ "_wfindfirst64i32.c",
675677 "stdio" ++ path.sep_str ++ "_wfindnext64i32.c",
676 "stdio" ++ path.sep_str ++ "_wstat.c",
677678 "stdio" ++ path.sep_str ++ "_wstat64i32.c",
679 "stdio" ++ path.sep_str ++ "__mingw_fix_stat_path.c",
680 "stdio" ++ path.sep_str ++ "__mingw_fix_wstat_path.c",
678681 "stdio" ++ path.sep_str ++ "asprintf.c",
679682 "stdio" ++ path.sep_str ++ "fopen64.c",
680683 "stdio" ++ path.sep_str ++ "fseeko32.c",
......@@ -749,23 +752,36 @@ const mingw32_generic_src = [_][]const u8{
749752 "stdio" ++ path.sep_str ++ "ucrt__vscprintf.c",
750753 "stdio" ++ path.sep_str ++ "ucrt__vsnprintf.c",
751754 "stdio" ++ path.sep_str ++ "ucrt__vsnwprintf.c",
755 "stdio" ++ path.sep_str ++ "ucrt___local_stdio_printf_options.c",
756 "stdio" ++ path.sep_str ++ "ucrt___local_stdio_scanf_options.c",
752757 "stdio" ++ path.sep_str ++ "ucrt_fprintf.c",
753758 "stdio" ++ path.sep_str ++ "ucrt_fscanf.c",
754759 "stdio" ++ path.sep_str ++ "ucrt_fwprintf.c",
755 "stdio" ++ path.sep_str ++ "ucrt_ms_fprintf.c",
760 "stdio" ++ path.sep_str ++ "ucrt_fwscanf.c",
756761 "stdio" ++ path.sep_str ++ "ucrt_ms_fwprintf.c",
757762 "stdio" ++ path.sep_str ++ "ucrt_printf.c",
758763 "stdio" ++ path.sep_str ++ "ucrt_scanf.c",
759764 "stdio" ++ path.sep_str ++ "ucrt_snprintf.c",
765 "stdio" ++ path.sep_str ++ "ucrt_snwprintf.c",
760766 "stdio" ++ path.sep_str ++ "ucrt_sprintf.c",
761767 "stdio" ++ path.sep_str ++ "ucrt_sscanf.c",
768 "stdio" ++ path.sep_str ++ "ucrt_swscanf.c",
769 "stdio" ++ path.sep_str ++ "ucrt_swprintf.c",
762770 "stdio" ++ path.sep_str ++ "ucrt_vfprintf.c",
763771 "stdio" ++ path.sep_str ++ "ucrt_vfscanf.c",
772 "stdio" ++ path.sep_str ++ "ucrt_vfwscanf.c",
773 "stdio" ++ path.sep_str ++ "ucrt_vfwprintf.c",
764774 "stdio" ++ path.sep_str ++ "ucrt_vprintf.c",
765775 "stdio" ++ path.sep_str ++ "ucrt_vscanf.c",
766776 "stdio" ++ path.sep_str ++ "ucrt_vsnprintf.c",
777 "stdio" ++ path.sep_str ++ "ucrt_vsnwprintf.c",
767778 "stdio" ++ path.sep_str ++ "ucrt_vsprintf.c",
779 "stdio" ++ path.sep_str ++ "ucrt_vswprintf.c",
768780 "stdio" ++ path.sep_str ++ "ucrt_vsscanf.c",
781 "stdio" ++ path.sep_str ++ "ucrt_vwscanf.c",
782 "stdio" ++ path.sep_str ++ "ucrt_wscanf.c",
783 "stdio" ++ path.sep_str ++ "ucrt_vwprintf.c",
784 "stdio" ++ path.sep_str ++ "ucrt_wprintf.c",
769785 "string" ++ path.sep_str ++ "ucrt__wcstok.c",
770786 // uuid
771787 "libsrc" ++ path.sep_str ++ "ativscp-uuid.c",
......@@ -889,6 +905,8 @@ const mingw32_generic_src = [_][]const u8{
889905};
890906
891907const mingw32_x86_src = [_][]const u8{
908 // mingw32
909 "crt" ++ path.sep_str ++ "CRT_fp10.c",
892910 // mingwex
893911 "math" ++ path.sep_str ++ "cbrtl.c",
894912 "math" ++ path.sep_str ++ "erfl.c",
......@@ -971,11 +989,11 @@ const mingw32_x86_32_src = [_][]const u8{
971989const mingw32_arm_src = [_][]const u8{
972990 // mingwex
973991 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "ldexpl.c",
992 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "sincosl.c",
974993};
975994
976995const mingw32_arm32_src = [_][]const u8{
977996 // mingwex
978 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "_chgsignl.S",
979997 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rint.c",
980998 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rintf.c",
981999 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincos.S",
......@@ -983,7 +1001,6 @@ const mingw32_arm32_src = [_][]const u8{
9831001
9841002const mingw32_arm64_src = [_][]const u8{
9851003 // mingwex
986 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "_chgsignl.S",
9871004 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rint.c",
9881005 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rintf.c",
9891006 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincos.S",
......@@ -997,7 +1014,6 @@ const mingw32_winpthreads_src = [_][]const u8{
9971014 "winpthreads" ++ path.sep_str ++ "misc.c",
9981015 "winpthreads" ++ path.sep_str ++ "mutex.c",
9991016 "winpthreads" ++ path.sep_str ++ "nanosleep.c",
1000 "winpthreads" ++ path.sep_str ++ "ref.c",
10011017 "winpthreads" ++ path.sep_str ++ "rwlock.c",
10021018 "winpthreads" ++ path.sep_str ++ "sched.c",
10031019 "winpthreads" ++ path.sep_str ++ "sem.c",