Don't clobber GetLastError in Win32 systhreads caml_leave_blocking_section_hook#10220
Don't clobber GetLastError in Win32 systhreads caml_leave_blocking_section_hook#10220shindere merged 1 commit intoocaml:trunkfrom
Conversation
|
|
||
| static void caml_thread_leave_blocking_section(void) | ||
| { | ||
| #ifdef _WIN32 |
There was a problem hiding this comment.
There are no other uses of #ifdef _WIN32 in this file (other than the initial include on L51). Perhaps it would be better to follow the existing convention and factor out the caml_thread_leave_blocking_section function itself into the st_posix.h and st_win32.h files?
EDIT: oh, is that the 'introducing other hooks'? Sorry, I just noticed you might have alluded to that...
There was a problem hiding this comment.
Indeed! My concern is that either it introduces two hooks, basically called do_windows_only_thing_before_lock_acquire and do_windows_only_thing_after_lock_acquire or the entire function logic is duplicated in both headers 🙂
|
In retrospect, I see no strong reason why Now, I understand that the opposite decision (save |
|
Two questions:
|
I'm not sure asynchronous signals exist at all under Windows... On the other hand, now that signal handling is clean and no longer runs arbitrary OCaml code, and assuming POSIX signal semantics, |
I suspect that in the old implementation of signal handling, part 1 could run nearly arbitrary code and therefore clobber With the new implementation of signals, part 1 could quite possibly preserves To summarize: maybe we need to rework |
Indeed, my first thought was to fix
As far as I'm aware, there's nothing as equivalently horrific! The Windows way of doing these things is to give a function pointer for your handler and then the caller (which may be the kernel) uses
However, we'd be removing the code which preserves |
|
As an alternative, could we consider removing I'm not aware of any platform that supports pthreads / Win32 threads but lacks static global TLS support. (Things are a little dicier if we want non- |
|
That appears to work on mingw32, mingw64 and msvc64. The disassembly of |
When this code was written, MSDN warned that declspec(thread) doesn't work within DLLs and the Tls API must be used instead. Remember that the systhreads library is built as a DLL so that it can be loaded dynamically in ocamlrun. I need to be convinced that MSVC, Mingw and Flexlink fully support thread-local storage in DLLs. |
|
Hmm, I see. I think I found the relevant bit of MSDN:
(see also this writeup) Are Server 2003 and XP still supported? |
It does not have to be done strictly before. It's just something that 1- we should consider, and 2- justifies your choice of preserving GetLastError at the level of the systhread hook, and not at the level of |
XP, apparently yes: The native ports require Windows XP or later. I'm also curious about Flexlink support for thread-local storage. |
I think this may already be out-of-date (I'm starting a list of OCaml 5.00 housekeeping, and minimum version of Windows and the compiler are already on it). It's not been easy to build OCaml on Windows XP for a while... I think programs compiled with it may still run (mostly), but I'm fairly sure we now have unguarded Vista-specific header use. Both are very much unsupported OSes. (Multicore requires completely dropping XP "support", incidentally)
I don't think flexlink is relevant here, because we're strictly talking about static variables, so flexlink won't "see" them. |
|
Windows XP is end-of-lifed for a while now: https://support.microsoft.com/en-us/windows/windows-xp-support-has-ended-47b944b8-f4d3-82f2-9acc-21c79ee6ef5e In fact everything below Windows 8 is out of even extended support period: https://www.google.ca/amp/s/www.zdnet.com/google-amp/article/when-will-microsoft-pull-the-plug-on-your-version-of-windows-or-office/ I think it would make sense for OCaml to follow suit. |
I have no strong opinion on which versions of Windows OCaml should support. But let's make our choice clear and document it. |
xavierleroy
left a comment
There was a problem hiding this comment.
This looks good to me as a quick fix for an irritating issue.
In an ideal world, we could access thread-local storage without clobbering LastError, and C stub code would be written in a way that captures LastError early. But this will do fine for now.
There are a few choices on how to do this:
#ifdef _WIN32inst_stubs.c, but it seems less convoluted than introducing additional hooksst_stubs.crather thanruntime/signals.cFixes #8857