Commit Graph

103 Commits (8981fccbe86ce5e23a40d5444279f145b90a5778)

Author SHA1 Message Date
Joe Groff cb8c01faec vm: don't die if foreign thread gets async signal
Fixes #425
2011-11-23 11:26:42 -08:00
Joe Groff 00f00663ad vm: replace assert with FACTOR_ASSERT
Factor is finally a real C++ project and has a custom assert macro. Assertion failures were still getting caught as exceptions and causing failure loops. Write our own macro that calls factor::abort on failure.
2011-11-23 11:11:26 -08:00
Joe Groff ba88cbbe51 vm: charge samples collected in prolog to parent
Fixes #379
2011-11-23 11:11:26 -08:00
Joe Groff ab9088e7ba vm: disable SIGINT handler while in factorbug
Fixes #410
2011-11-15 18:50:42 -08:00
Joe Groff 0b45e809c7 vm: fashion police 2011-11-12 23:05:44 -08:00
Joe Groff 076d710256 vm: set stdin_loop cancellation state
Make it asynchronous so it doesn't wait till the next syscall to cancel.
2011-11-12 23:05:44 -08:00
Joe Groff 05da199174 vm: close_console before exiting anywhere
Add a factor_vm::exit function that does close_console() before ::exit-ing
2011-11-12 23:05:44 -08:00
Philipp Brüschweiler 4dd1f3297e vm: close the console when exiting
This prevents an endless loop caused by the nvidia drivers on linux.
See http://www.nvnews.net/vbulletin/showthread.php?t=164619
2011-11-12 23:05:43 -08:00
Joe Groff beb0f48da9 vm: more defense against multi-faulting
* Clear faulting_p from a safepoint rather than inside general_error, because jumping into unwind-native-frames could blow up.
* Handle multiple faults from fatal_error by breakpointing. Is there anything else we can safely do at that point?
* Verify memory protection faults in the top half of the signal handlers because signal dispatch could fault. Treat memory faults during gc or fep as fatal errors.
* Add a function factor_vm::abort() that restores the default SIGABRT handler and ::abort()s. Use it from fatal_error() so we get useful context from gdb and so the user gets feedback from the system crash reporter that Factor blew up and didn't just disappear.
* In factorbug(), don't proceed with .s .r .c if it would be unsafe to do so.
* Don't pile on signals if we've already called fatal_error().
2011-11-12 13:02:57 -08:00
Joe Groff 7e7607306c vm: don't SIGQUIT on unix or Ctrl-Break on windows
This gives us an escape hatch for when things go way south and ^C can't be handled. Also unmask SIGQUIT and SIGTERM from the stdin_loop thread so the thread doesn't keep the process alive after those signals.
2011-11-10 16:01:07 -08:00
Joe Groff 5f47dd85f4 vm: hand SIGALRM to signal pipe if not sampling 2011-11-08 23:37:22 -08:00
Joe Groff 5d81e6e2f0 vm: make signal pipe nonblocking
On the off chance the Factor end of the signal handler mechanism isn't listening, we don't want to tie up the VM because the pipe's buffer got full.
2011-11-08 22:07:22 -08:00
Joe Groff 2f0efb62e8 vm: don't send foreign samples to outer space 2011-11-08 14:00:33 -08:00
Joe Groff fca09f21ed vm: don't pass this to safepoint constructor
It's bad juju and MSVC calls us out on it.
2011-11-08 11:06:00 -08:00
Joe Groff 37494b301b new module unix.signals: app-level signal handlers
example:

IN: scratchpad USING: unix.ffi unix.signals ;
Loading resource:basis/unix/signals/signals.factor
IN: scratchpad [ V{ "Me not that kind of orc!" "Me busy, leave me alone!" "Work work" "Zug zug" } pop print flush ] SIGINFO add-signal-handler
IN: scratchpad load: 0.60  cmd: factor 41541 running 0.28u 0.16s
Zug zug
load: 0.71  cmd: factor 41541 running 0.28u 0.16s
Work work
load: 0.71  cmd: factor 41541 running 0.28u 0.16s
Me busy, leave me alone!
load: 0.73  cmd: factor 41541 running 0.28u 0.16s
Me not that kind of orc!
2011-11-08 10:21:49 -08:00
Joe Groff 7a7b19a8fd vm: more commentary on lock_console() stuff 2011-11-08 08:52:52 -08:00
Joe Groff 7df1c228bd vm: don't mask SIGTTIN from stdin_loop
Fixes #360
2011-11-08 08:42:48 -08:00
Joe Groff 75f9904c40 vm: interrupt stdin_loop when entering fep
The stdin_loop thread will keep trying to consume input unless we stop it by sending it a signal. Use SIGUSR2 to stop the read syscall and a mutex to hold up the loop while the fep is active.
2011-11-08 08:42:48 -08:00
Joe Groff 0c132cf861 vm: write signals to pipe immediately
The whole point is to wake up the mx without waiting for the next safepoint derp
2011-11-08 08:42:47 -08:00
Joe Groff 06bb122b6e vm: enqueue signals for FEP signals too
Although SIGINT still can't interrupt the current Factor thread in a sane way, this will at least wake up the run loop when waiting for input and fix #348 when implemented at the application level.
2011-11-08 08:42:47 -08:00
Joe Groff ceeb9f36d8 vm: write async signals to pipe for multiplexer
also factor out safepoint logic into its own file
2011-11-08 08:42:46 -08:00
Joe Groff eb55863292 vm: restore sigaltstack setup on unix
#ifdef __OpenBSD__ is different from #ifndef __OpenBSD
2011-11-03 11:57:43 -07:00
Joe Groff d7bc7ae4bf vm: parameterize sampling rate 2011-11-02 13:23:15 -07:00
Joe Groff bec71e9ae2 vm: sampling profiler timer for windows
Spawn a thread and have it spin on the performance counter, triggering safepoints on the main thread every sample time
2011-11-02 13:23:11 -07:00
Joe Groff 1c68bbf8a6 vm: count samples from foreign threads
On OS X it appears the mach exception thread and libdispatch queue threads occasionally get the SIGALRM from the itimer. Count those as foreign_thread_samples instead of letting the signal kill the process.
2011-11-02 13:23:10 -07:00
Joe Groff 2ddfdda7b5 vm: groundwork for sampling profiler
Set up the state necessary to collect samples. We still need to add GC support for walking the sample set, and the compiler needs to register GC roots before safepoints as well. We also need primitives to expose the data to Factor for reporting.
2011-11-02 13:23:06 -07:00
Joe Groff 09088ec3ce cleanups from code review 2011-10-27 21:18:23 -07:00
Joe Groff b1094e0e5f vm: remove half-assed signal queueing scaffolding
Should implement it right later. See #297.
2011-10-27 21:18:22 -07:00
Joe Groff ad9b90f23b vm: update windows for resumable signals 2011-10-27 21:18:21 -07:00
Joe Groff e431cef96b vm: move dispatch_signal_handler to cpu-x86.cpp
The new signal handler dispatch is logic is CISC-centric; defer fixing it until we find someone who cares
2011-10-27 21:18:20 -07:00
Joe Groff 011ce33068 vm: Revert extra canary page before callstack
This reverts commit 7d5c8d6990385b94569116a23163d7e75ae21f49. We pretty much can't avoid unwinding frames without some more drastic redesign.
2011-10-27 21:14:50 -07:00
Joe Groff ed72d57c1a vm: allocate an extra canary page before callstack
This will let us safely unguard the callstack overflow guard page as a grace page so the callstack overflow handler can do its business without discarding frames.
2011-10-27 21:14:49 -07:00
Joe Groff f759575ddd vm: factor out dispatch_signal_handler logic 2011-10-27 21:14:49 -07:00
Joe Groff 91d8bcd4f8 vm: fep on SIGINT or SIGQUIT instead of exception
It's not robust currently to raise an exception because a lot of our code that isn't already written with exceptions in mind breaks. Also, a signal is likely to be received by an FFI callback installed on the IO multiplexer, which will cause Factor to die since the callback cannot handle the exception. We need a more robust solution to dealing with SIGINT.

Also lay some groundwork for counting profile samples and reporting non-interrupting asynchronous signals.
2011-10-27 21:14:49 -07:00
Joe Groff 01b782e6c4 vm: clean up signal handler dispatch
Remove the weird and broken functions fix_callstack_top and scrub_return_address. Instead, simply decrement the SP and store the PC from the front end of the signal handler so that the back end can return back into the original context normally. Currently aborts for leaf procedure frames pending a more robust solution.
2011-10-27 21:14:48 -07:00
Joe Groff 675cd246ad vm: fatal_error if VM-less thread gets a signal 2011-10-27 21:14:48 -07:00
Joe Groff 6f831c4f95 vm: block all signals from unix stdin_loop thread 2011-10-27 21:14:47 -07:00
Joe Groff e9309a425a vm: handle async signals at safepoints on unix
Factor now supports the new 4.0BSD feature of "signals".
2011-10-27 21:14:46 -07:00
Joe Groff e6f65d81e4 vm: code_heap::(un)guard_safepoint methods 2011-10-27 21:14:44 -07:00
Erik Charlebois 1ed2bc6231 32 and 64 bit Linux PPC support 2011-05-23 23:36:14 -04:00
Slava Pestov a6386f6e7d vm/os-unix.cpp: remove dead code 2010-09-20 21:36:19 -07:00
Slava Pestov e5921ab55b vm/os-unix.cpp: set pipe file descriptors to close on exec 2010-09-15 22:20:24 -07:00
Slava Pestov 087b451dc1 Change how SIGPIPE is ignored, and add a unit test to io.launcher.unix to ensure that this ignoredness is not inherited by child processes 2010-09-02 22:11:45 -07:00
Slava Pestov 55ac874eb2 vm: Remove signal_callstack_top nonsense 2010-09-02 22:57:17 -05:00
Slava Pestov 6617eca683 Fix three problems discovered by running math.floats.env tests in a loop:
- Crash if allocating error triggers a GC from a signal/SEH handler
- Crash if GC runs with floating point traps enabled on Windows
- Floating point traps didn't prettyprint properly
2010-09-02 22:57:14 -05:00
Doug Coleman 97c3450427 Remove system_micros from vm, implement gmt hook on windows 2010-06-16 23:39:16 -05:00
Slava Pestov 295de47038 vm: don't try loading Factor VM DLL anymore 2010-04-02 00:03:26 -04:00
Joe Groff 7bb82e0c1b statically link factor executable to VM so dylib is only needed for embedding 2010-04-01 14:25:02 -07:00
Slava Pestov a1caf9edb3 vm: split up TLS code and add a dummy implementation for a dummy OS known as NetBSD 2010-03-29 02:23:21 -04:00
Doug Coleman d915b1a401 vm: don't use sigaltstack() on OpenBSD because OpenBSD sucks 2010-03-28 18:26:39 -05:00