Allow bytecode interpreter to make unsafe foreign calls

Authored by bgamari on May 29 2017, 11:12 PM.

Diff Detail

rGHC Glasgow Haskell Compiler
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
bgamari created this revision.May 29 2017, 11:12 PM
simonmar requested changes to this revision.Jun 1 2017, 3:31 AM

Are the test failures relevant?

Let's add a test case: the RTS should blow up with a fatal error if we try to re-enter it during an unsafe foreign call, so it should be possible to make a test case that will fail after this patch and succeed before it.

Otherwise, if it works I think we can go with this. We're doing more work than we need to to tidy up the stack, but speed is not the primary goal for the interpreter anyway.


I think you can expand this around the SAVE_THREAD_STATE() too.


same, extend it to cover LOAD_THREAD_STATE().

This revision now requires changes to proceed.Jun 1 2017, 3:31 AM
bgamari updated this revision to Diff 12885.Jun 19 2017, 9:31 AM
bgamari edited edge metadata.

Address some of comments

bgamari updated this revision to Diff 12886.Jun 19 2017, 9:31 AM


At the moment the UnsafeReenterGhci test hangs here,

#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007fffeee62209 in waitCondition (pCond=pCond@entry=0x754ea0, pMut=pMut@entry=0x754ed0) at rts/posix/OSThreads.c:117
#2  0x00007fffeee43c33 in waitForReturnCapability (task=task@entry=0x754e90) at rts/Capability.c:714
#3  0x00007fffeee444ac in waitForCapability (pCap=pCap@entry=0x7fffe77fdc28, task=0x754e90) at rts/Capability.c:806
#4  0x00007fffeee43248 in rts_lock () at rts/RtsAPI.c:597
#5  0x00007fffe65fba21 in zdmainzdMainzdMainzuwrapzzuf () from /tmp/ghc11809_0/
#6  0x00007fffec11d813 in hello () from /tmp/ghc11809_0/
#7  0x00007fffeec18914 in ffi_call_unix64 () from /opt/exp/ghc/ghc-landing/rts/dist/build/
#8  0x00007fffeec18336 in ffi_call () from /opt/exp/ghc/ghc-landing/rts/dist/build/
#9  0x00007fffeee460d6 in interpretBCO (cap=0x7fffef08ba40 <MainCapability>) at rts/Interpreter.c:1697
#10 0x00007fffeee3f3e2 in schedule (initialCapability=<optimized out>, task=task@entry=0x754e90) at rts/Schedule.c:471
#11 0x00007fffeee404fc in scheduleWorker (cap=<optimized out>, task=0x754e90) at rts/Schedule.c:2574
#12 0x00007fffee1bf494 in start_thread (arg=0x7fffe77fe700) at pthread_create.c:333
#13 0x00007fffed76faff in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

It seems that we never get to Schedule, where we would detect the unsafe reentrancy. Need to work out why.

bgamari marked 2 inline comments as done.Jun 19 2017, 9:35 AM
simonmar accepted this revision.Jun 21 2017, 2:48 AM

Ah, I think this will only work with the non-threaded RTS, and we can't easily test that because we'd have to relink GHCi. Sorry about that! Just remove the test and we're good to go.

This revision is now accepted and ready to land.Jun 21 2017, 2:48 AM
This revision was automatically updated to reflect the committed changes.