Bug 12800 – Fibers are broken on Win64

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2014-05-25T10:06:00Z
Last change time
2015-02-18T03:38:14Z
Keywords
pull
Assigned to
nobody
Creator
sludwig

Comments

Comment #0 by sludwig — 2014-05-25T10:06:23Z
The following program crashes when entering the fiber. Compiled on Windows with -m64. --- import std.stdio; import core.thread; void main() { auto f = new Fiber({ writeln("Hello, World!"); }); f.call(false); } --- Related comment: http://issues.dlang.org/show_bug.cgi?id=7954
Comment #1 by jblume — 2014-05-25T14:54:08Z
This should be fixed by https://github.com/D-Programming-Language/druntime/pull/809 . I didn't fix the related bug yet because the obvious solution of pushing all the floating-point registers on the stack more than doubles the cost of a context switch.
Comment #2 by github-bugzilla — 2014-05-25T17:33:08Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/02f4267adc9ab60a61aacc0aae4def9499c626ad fix Issue 12800 - Fibers are broken on Win64 Win64 version of the context switch used the wrong registers for parameters https://github.com/D-Programming-Language/druntime/commit/591b8d474c94161c749ee1800876e7f65ca0e634 Merge pull request #809 from jblume/master fix Issue 12800 - Fibers are broken on Win64
Comment #3 by sludwig — 2014-06-10T10:33:38Z
It looks like there is still something wrong. The unit test for the FiberScheduler of the new std.concurrency additions crashes with an access violation inside Fiber.call(). https://github.com/D-Programming-Language/phobos/pull/1910 I didn't have a chance to investigate this deeper, yet. Reopening for now.
Comment #4 by sludwig — 2014-09-22T15:08:06Z
A simple vibe.d application also crashes here because RAX is null: --- 00007FF7F0FA2E07 call fiber_switchContext (07FF7F0FC6790h) 00007FF7F0FA2E0C add rsp,20h 00007FF7F0FA2E10 mov rax,qword ptr [rsi+80h] 00007FF7F0FA2E17 mov rbx,qword ptr [rax+10h] <- RAX==0 --- This was the first `Fiber.call()` call of the program.
Comment #5 by sludwig — 2014-09-22T15:15:05Z
Correction: It's the first call to yield() that crashes. --- import core.thread, std.stdio; void fun() { writeln("A"); Fiber.yield(); writeln("B"); } void main() { auto f = new Fiber(&fun); writeln("call.."); f.call(false); writeln("call again.."); f.call(false); writeln("exit"); } --- Output: call.. A (crash)
Comment #6 by code — 2014-11-07T04:36:10Z
Looks like we're missing to save RSI and RDI. All the callee saved registers need to be stored on the fiber stack. http://msdn.microsoft.com/en-us/library/6t169e9c.aspx
Comment #7 by code — 2014-11-10T15:16:46Z
Comment #8 by github-bugzilla — 2014-11-10T17:51:01Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/fc887f3a41f850c266812b56a4cd770acef7b044 fix Issue 12800 - Fibers are broken on Win64 - save non-volatile registers RSI and RDI https://github.com/D-Programming-Language/druntime/commit/d30668171d145d9c31f47e47717d0787845ff58f Merge pull request #1012 from MartinNowak/fix12800 fix Issue 12800 - Fibers are broken on Win64
Comment #9 by github-bugzilla — 2015-02-18T03:38:14Z