-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libnative: main task has bad thread local data on windows #13259
Comments
What happens if you add this to the top of the unsafe { ::std::rt::stack::record_sp_limit(0); } |
Wow, that one fixed all problems! |
See this comment for how I discovered that. It sounds like this modification to the TIB is causing something to fail when some initial library is loaded. At this point, I think we need to figure out the minimal set of things that need to be done to "get things loaded". This minimal set of things can be done whenever libnative starts up, but I'm not sure what the minimal set of things are. The minimal set of things includes "boot libgreen and spawn a task" because that's what using libgreen will do, but it would be nice to narrow it down more than that! Does that make sense? |
The behavior seems to suggest that it's not a good idea to modify fs:0x14 is known as "ArbitraryUserPointer", but Raymond Chen said that it's "arbitrary" for internals, not for application. (it's safe to believe what Raymond says!) #include <windows.h>
int main() {
asm("movl $1234, %fs:0x14");
MessageBoxA(0, "abc", "abc", 0);
} So I want to investigate if LLVM can use TIB's stack bounds instead of ArbitraryUserPointer for segmented stack. We use them in |
I've replaced all occurrence (including llvm) of |
Are we sure that the kernel won't modify those TIB values to some other internal stack limit? (just a mild concern of mine) |
Hmm, BTW, the librand issue ( |
Hm, interestingly your C code example works for me. I think I'm on a windows 7 VM. The |
How about using the actual TLS API for this? TlsGetValue() and TlsSetValue() are both like 10 instructions long. Is this enough overhead to bother messing with undocumented TIB fields? And if it is, maybe we could write directly into TLS slots (after allocating one via TlsAlloc(), of course). |
It may be possible to do that, although this is an extra bit of overhead an all function calls made in rust (each function is preceded with this information). I also fear that the root cause is still unknown so it's too soon to move away from the current implementation (which seems like it should work). |
Actually, function prologues could use current bottom of stack (fs:[8]) for quick comparison, and only check the hard stack limit when kicked off of the fast path. The latter would happen only when stack commit limit is about to grow anyway, so it wouldn't matter for perf. |
I tend to believe Raymond, when he says that "ArbitraryUserPointer" is reserved for OS use. Looks like you've discovered this yourself too. |
There's a good long comment explaining why. The tl;dr; is that I have no idea why this is necessary, but it gets --test to work on windows which is something, right? cc rust-lang#13259 cc rust-lang#16275 cc rust-lang/cargo#302
Nominating, I just spent an hour tracking this down for what feels like the 10th time. This causes syscalls to fail at random for no apparent reason, and the errors are often quite misleading. |
P-backcompat-libs, 1.0 milestone. |
@Zoxc what's the state of your stack probe patch? |
Ah, so this is why |
@brson: AFAIK, we already have stack probes on Windows via |
@brson The error message reporting (#16388) is mostly working. I suspect there's some unrelated error breaking it on Windows). I've yet to find someone who will commit my x86 LLVM patches (which adds support for stack probes on non-Windows x86 systems), but you could just adapt my code (Zoxc@ecec992) to use stack probes on Windows only. Since fixing this error is more important than nice stack overflow messages (which will added later anyway). |
Just FYI: this also appears to break |
Working on adapting @Zoxc's patch now. |
Win32 backtrace also broken! |
@klutzy I can't reproduce the problem on either 64-bit win8 or 32-bit win 2008 using your test case in the op. FormatMessage succeeds producing 'Incorrect function.'. |
This is the bare minimum to stop using split stacks on Windows, fixing #13259 and #14742, by turning on stack probes for all functions and disabling compiler and runtime support for split stacks on Windows. It does not restore the out-of-stack error message, which requires more runtime work. This includes a test that the Windows TCB is no longer being clobbered, but the out-of-stack test itself is pretty weak, only testing that the program exits abnormally, not that it isn't writing to bogus memory, so I haven't truly verified that this is providing the safety we claim. A more complete solution is in #16388, which has some unresolved issues yet. cc @Zoxc @klutzy @vadimcn
Simplify feature representation in CargoConfig
More investigation from #13073.
If the code is bulit with
--cfg green
,--cfg raw
or--cfg spawn
, it works as expected. However, if it is built with no cfg, it behaves strangely:FormatMessageW()
fails to get system locale mssage, andMessageBoxA()
shows gui message box with non-system-themed border.I guess the main task has bad thread-local data due to
libnative::start()
.cc @alexcrichton
The text was updated successfully, but these errors were encountered: