Commit Graph

237 Commits

Author SHA1 Message Date
nightstrike
2aea2526c2 Uglify function parameter names in public headers
For a long time, we have used unprefixed symbols like "a" in public
facing headers.  These are caught by the libstdc++ testsuite, so fix
them globally where possible.  The general technique applied is:

1) Default to just removing the parameter entirely if it provides no
additional information to the reader.  For instance:

  void f(struct timespec *t); // The letter 't' there is not helpful

2) In cases where the data type is generic and the parameter name has
added documentation value, replace it with a prefixed version, either
two underscores, or one underscore and an uppercase letter.  It seems
that much existing code uses the latter, so this patch does likewise.
For instance:

  void f(int signal);
  void f(int _Signal);
2021-08-25 19:12:52 -07:00
Liu Hao
ab0fa5ad3c winpthreads: Add __udivmoddi4()
Like 431ac2a912 but this is for GCC 11.
It is identical to `__qdivrem()`.

Reference: https://sourceforge.net/p/mingw-w64/mailman/message/37276246/
Signed-off-by: Liu Hao <lh_mouse@126.com>
2021-05-07 14:25:21 +08:00
Christian Franke
dcd990ed42 winpthreads: Increase precision of CLOCK_REALTIME, add CLOCK_REALTIME_COARSE.
Use GetSystemTimePreciseAsFileTime() for CLOCK_REALTIME if available.
Always use GetSystemTimeAsFileTime() for CLOCK_REALTIME_COARSE.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Liu Hao <lh_mouse@126.com>
2021-05-06 21:34:55 +08:00
Liu Hao
84c950bdab winpthreads: De-duplicate struct timespec by including <time.h>
Reference: https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/2d855f61-fd8e-9ccc-d110-934f58974906%40reactos.org/#msg37216256
Signed-off-by: Liu Hao <lh_mouse@126.com>
2021-02-11 21:03:02 +08:00
Biswapriyo Nath
841af0058c winstorecompat/Crypto: Use proper namespaced Release method.
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: Liu Hao <lh_mouse@126.com>
2021-02-06 10:10:20 +08:00
Steve Lhomme
9c5f624962 headers: update windows.security.cryptography.h 2020-12-14 22:24:52 +01:00
Biswapriyo Nath
172511d7d1 winpthreads: Add pthread_attr_getstack and pthread_attr_setstack.
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-10-13 16:00:23 +08:00
Liu Hao
295fafcf58 winpthreads: Call _fpreset() for new threads
This is necessary for math functions taking `long double` arguments to
work reliably, as by default, new threads have their x87 precision set
to 53 bits.

Note the x87 control word can't be set in the TLS callback. It gets
overwritten before the thread procedure begins execution. There is NO
workaround for the win32 thread model, other than requiring users to
call `_fpreset()` themselves.

Reference: https://sourceforge.net/p/mingw-w64/mailman/message/37084134/
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-08-17 21:46:41 +08:00
Liu Hao
1c302d2569 winpthreads: Regenerate Makefile.in
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-06-03 22:04:44 +08:00
Liu Hao
e82b4f5681 winpthreads: Always define __USE_MINGW_ANSI_STDIO to zero
In the x86 case, mingw-w64 stdio functions use 64-bit division, which
relies on certain routines in libgcc, and causes undefined references
under some circumstances.

Instead, the MS ones should be called, which are available immediately
and do not depend on libgcc. This was also the case prior to bfd33f6c.

Reference: https://github.com/msys2/MINGW-packages/pull/6539
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-06-03 22:00:08 +08:00
Biswapriyo Nath
87a4404cb5 libraries/winpthreads: remove unused dwFlags variable in sched.c
the usage of this variable was removed in 13c9e28c0e commit

Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-30 20:20:27 +08:00
Martin Storsjö
bb73d2e3a2 winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-20 09:23:13 +03:00
Steve Lhomme
cc10545a79 winstorecompat: provide GetFileInformationByHandle
It's forbidden in any UWP app but the same information can be gathered via
GetFileInformationByHandleEx.

It's used by gnutls (via gnulib).

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-20 09:20:56 +03:00
Steve Lhomme
a32b622261 winpthreads: don't call SetThreadContext in winstore builds
The call is forbidden.

Hopefully the deferred Canceling mechanism below will work and this is not
needed.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:42:58 +08:00
Steve Lhomme
7cb7071978 winpthreads: do not call GetHandleInformation in winstore build
The call is forbidden on non-desktop apps.

The check on INVALID_HANDLE_VALUE should be good enough.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:42:56 +08:00
Steve Lhomme
13c9e28c0e winpthreads: simplify the handle validity in pthread_check()
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:42:25 +08:00
Steve Lhomme
58f92b0fae winpthreads: always return 0 in pthread_check() if the thread ended is 0
The code does the same but in a cleaner way, making room for the next patch.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:41:51 +08:00
Steve Lhomme
01385c6aaa winpthreads: do not use the XXXExceptionHandler API in winstore builds
Calling RemoveVectoredExceptionHandler()/AddVectoredExceptionHandler() is
forbidden in non-desktop apps.
https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-addvectoredexceptionhandler
https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-removevectoredexceptionhandler

If USE_VEH_FOR_MSC_SETTHREADNAME is set in winstore builds, RaiseException is
only called if there's a debugger attached. In non-winstore builds it can also
be called if the SetThreadName_VEH_handle was set succesfully.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:41:49 +08:00
Steve Lhomme
d58069b138 winpthreads: simplify the USE_VEH_FOR_MSC_SETTHREADNAME check
When compiling with other compilers than MSVC, we always use the code
relying on USE_VEH_FOR_MSC_SETTHREADNAME.

The __try/__except check code is not modified as it relies on internal MSVC
dialect. With MSVC either USE_VEH_FOR_MSC_SETTHREADNAME was set but that code
wasn't use anyway (unchanged) or it wasn't set and we use the code (unchanged).
Without MSVC we always define USE_VEH_FOR_MSC_SETTHREADNAME so the other
variant of the code is used (unchanged).

Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-05-19 22:39:04 +08:00
Martin Storsjö
7df01ff1f8 winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-15 00:10:53 +03:00
Steve Lhomme
16d5b3e3d5 winstorecompat: provide getpid
It's forbidden in any UWP app.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-15 00:10:53 +03:00
Steve Lhomme
8f078a2567 winstorecompat: Forward VirtualProtect to VirtualProtectFromApp on windows 10
VirtualProtectFromApp is a fully functional replacement for cases when
not needing to touch code sections, and for other cases, the call
should fail - just like the previous stub that failed unconditionally.

This should be enough for fixing up runtime pseudo relocations for
code generated by LLVM (and possibly by GCC on x86_64), where all
fixed up references either are in normal data sections, or in .refptr
stubs.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-14 13:31:32 +03:00
Martin Storsjö
04eb1d4f49 winstorecompat: Avoid warnings about redefining _WIN32_WINNT in the Win10 library
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 20:59:18 +03:00
Martin Storsjö
43f2d5cafb winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 20:52:11 +03:00
Steve Lhomme
b5da811f73 winstorecompat: add libwindowsappcompat to use with libwindowsapp
The original libwinstorecompat is designed to be used with libmincore.

- CreateEventW is allowed
- CreateMutexW is allowed
- CreateSemaphoreW is allowed
- InitializeCriticalSection is allowed
- GetFileAttributes is allowed
- WaitForSingleObject is allowed
- GetTickCount is allowed
- SetUnhandledExceptionFilter is allowed
- TerminateProcess is allowed
- IsDBCSLeadByteEx is allowed
- SetErrorMode is allowed
- GetACP is allowed
- LocalAlloc/LocalFree are allowed
- Sleep/SleepEx are allowed
- SetFilePointer is allowed
- Tls functions are allowed
- GetConsoleOutputCP is allowed

https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis

To select the set of API's allowed by this library, define WINSTORECOMPAT
and build with _WIN32_WINNT >= _WIN32_WINNT_WIN10.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 20:52:05 +03:00
Steve Lhomme
90ed4deda4 winstorecompat: handle LoadLibraryA alongside LoadLibraryW
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 00:17:26 +03:00
Martin Storsjö
4c8a7f3e0e winstorecompat: Add missing WINAPI in the GetUserName function pointer declaration
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 00:00:42 +03:00
Martin Storsjö
b0d8fcd140 winstorecompat: Fix the return type of the non-i386 version of __imp__beginthreadex
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 00:00:42 +03:00
Martin Storsjö
64619464db winstorecompat: Add a cast to silence a warning about conversion between void pointer and function pointer
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 00:00:42 +03:00
Martin Storsjö
814f527066 winstorecompat: Use __asm__() instead of asm() for setting symbol names
The previous form caused compiler warnings like "warning: extension used
[-Wlanguage-extension-token]" when built with clang.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-11 00:00:42 +03:00
Martin Storsjö
bc1ff01f98 winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-07 21:42:38 +03:00
Steve Lhomme
b8a6ea236b winstorecompat: provide GetUserName
It's needed by:
- getlogin() in mingwex

GetEnvironmentVariableA("USERNAME") gives the same information (tested on
win10 in cmd.exe and PowerShell).

No implementation provided when building winstorecompat for win8 as
GetEnvironmentVariableA is not allowed and GetUserNameEx requires -lsecur32.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-07 21:42:38 +03:00
xnor
330025c54b Wait on sema_b again to ensure pthread_cond_wait() functions atomically as required by POSIX.
Since holding sema_b before aquiring waiters_count_lock_ can lead to deadlocks try to aquire waiters_count_lock_ opportunistically. If it fails then release sema_b and sched_yield() to give the other thread (which has aquired waiters_count_lock_ and is now waiting on sema_b) a chance to aquire sema_b before we retry the whole procedure.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2019-09-02 22:40:29 +08:00
Liu Hao
1ebdd63cff Revert "winpthreads/cond.c: Remove waits for sema_b from wait functions."
This reverts commit b2302cd60b.
2019-09-02 22:37:33 +08:00
Liu Hao
b2302cd60b winpthreads/cond.c: Remove waits for sema_b from wait functions.
All other functions wait for `sema_b` with `waiters_count_lock_` locked.
The order of acquisition of these two things must happen in the same order
in all functions, otherwise deadlocks may happen.

The obvious fix is to make wait functions wait for the semaphore after
having locked `waiters_count_lock_`. However, before the wait, the critical
seciton must be unlocked, otherwise all the other threads will be blocked
on signal/broadcast functions. The now consequent wait and signal operations
on the semaphore have no other effect and can be removed.

From now on, waiting threads will update `waiters_count_` without attempting
to lock `sema_b`. If a wait function is called under the protection of the
external mutex, this was unnecessary; otherwise, scheduling behavior might be
unpredictable, which nevertheless still conforms to POSIX.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2019-05-06 01:10:54 +08:00
Liu Hao
2a439e13bc winpthreads/cond.c: Only update waiters_count_ with waiters_count_lock_ locked.
Signed-off-by: Liu Hao <lh_mouse@126.com>
2019-05-06 01:10:01 +08:00
Martin Storsjö
1b7754a42a winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2019-04-15 22:55:45 +03:00
Martin Storsjö
a99578e9bf winstorecompat: Remove the getpid fallback
All CRT variants should provide getpid in some form now.

Signed-off-by: Martin Storsjö <martin@martin.st>
2019-04-15 22:55:45 +03:00
Jacek Caban
69effce769 pthread_unistd.h: Don't define _POSIX_THREAD_SAFE_FUNCTIONS.
Leave it up to time.h.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
2019-04-12 15:26:12 +02:00
Jacek Caban
28a1ea215f winstorecompat: Remove no longer needed _wassert. 2019-04-11 22:38:32 +02:00
Руслан Ижбулатов
52f2ce12c6 Ensure wait timeouts are respected
WaitFor*() functions may time out earlier than requested
or later than requested. The "later" part is generally OK.
The "earlier" part is not.

Fix this by running the wait functions in a loop until the
time actually runs out, or the function returns a non-timeout
code.

This does not apply to cases where timeout is 0 or INFINITE.
Those still use plain WaitFor*() calls (the wrappers, obviously,
still support these important corner-cases, but why call them
when we know that the timeout is 0 or INFINITE?).

This wouldn't have worked for handles that auto-reset
(i.e. where WaitFor*() call wakes up on handle activation, and immediately
resets the handle, preventing further WaitFor*() calls from waking up
until the handle is activated again), but winpthreads does not use those.

The timeout checker uses the coarse GetTickCount64() because it's fast
and doesn't wrap around every 49 days.
Though it might not be accurate enough, let's go with it first.

On pre-Vista systems QueryPerformanceCounter() is used instead.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2019-03-02 22:18:41 +08:00
Руслан Ижбулатов
6c32da398d Round up when converting nanoseconds to milliseconds
If the caller provides ts_nsec in struct timespec,
we lose precision when converting that time to milliseconds
for our WaitFor*() calls. Make sure we round *up* when doing that
conversion, as otherwise the wait time will be *less* than the caller
expects. Users of pthreads on non-realtime systems are generally
OK with functions returning a bit later than requested. But timing out
*earlier* than the requested time is completely unexpected.

Signed-off-by: Liu Hao <lh_mouse@126.com>
2019-03-01 22:10:05 +08:00
Hugo Beauzée-Luyssen
f7b2feb36b winstorecompat: Regenerate Makefile.in
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
2018-12-13 09:57:54 +01:00
Hugo Beauzée-Luyssen
d67540ce71 winstorecompat: Add RtlRestoreContext stub
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
2018-12-13 09:57:47 +01:00
SquallATF
8bba2a9f5f winpthreads: make winpthreads compatible with libcxx __attribute__((__require_constant_initialization__))
libcxx defined `_LIBCPP_SAFE_STATIC` for static variable, if use winpthreads need `PTHREAD_*_INITIALIZER` constant, but current version have `reinterpret_cast` to convert integer initial value to pointer, `__attribute__((__require_constant_initialization__))` not allowed this define and causing compilation error..

Signed-off-by: SquallATF <squallatf@gmail.com>
Signed-off-by: Liu Hao <lh_mouse@126.com>
2018-10-26 12:54:18 +08:00
Hugo Beauzée-Luyssen
710b8e0091 winstorecompat: Don't build RtlAddFunctionTable on IA-32
The function isn't available on IA-32, and neither are some of the types it
uses.

Signed-off-by: Martin Storsjö <martin@martin.st>
2018-07-12 12:34:12 +03:00
Hugo Beauzée-Luyssen
d0607afb0c winstorecompat: Fix EnumProcessModule
Return the correct size if the buffer isn't big enough, and don't
reference mods as it is undeclared.

Signed-off-by: Martin Storsjö <martin@martin.st>
2018-07-11 20:50:00 +03:00
Martin Storsjö
51fa2e2b59 winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2018-07-10 23:26:10 +03:00
Martin Storsjö
39a534aad8 winstorecompat: Add stubs for Rtl functions used by the mingw-w64 crt wrapping
Signed-off-by: Martin Storsjö <martin@martin.st>
2018-07-10 23:26:10 +03:00
Martin Storsjö
38646ba452 winstorecompat: Regenerate Makefile.in
Signed-off-by: Martin Storsjö <martin@martin.st>
2018-07-10 23:26:10 +03:00