Commit Graph

108 Commits (876b430ec970c1a14bed926f107008ce0828cf5b)

Author SHA1 Message Date
Erik Charlebois ffe41b3d7f VM: Fixup cast formatting after clang-format
clang-format doesn't recognize casts to non-pointer/non-template types
so it winds up adding a space between the right paren and the expression
and then failing to recognize prefix operators in the process
(e.g. foo = (cell) & bar; should be foo = (cell)&bar;). This commit
manually fixes up the major cases (fixnum, cell, all types ending in _t).
2013-05-13 14:59:24 -04:00
Erik Charlebois 88d7c10d03 VM: Replace u8-64, s8-64, cell, fixnum with stdint.h equivalents 2013-05-13 00:28:25 -04:00
Erik Charlebois 37b15012e6 VM: Refactor os-* to Factor style 2013-05-12 13:24:46 -04:00
Erik Charlebois ca2ea548be VM: Remove exec bit from VM source files 2013-05-11 17:04:23 -04:00
Doug Coleman 1cdd080445 os-unix: Actually call pthread_join() to avoid an infinite loop and 100% cpu usage. It happens randomly. Fixes #738. Thanks to kkrev or frankfranks. 2012-10-26 10:36:01 -07:00
Joe Groff 88d31b166b vm: don't die if foreign thread gets async signal
Fixes #425
2011-11-23 11:26:42 -08:00
Joe Groff 0a1a252cdb 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 6c0ecf631a vm: charge samples collected in prolog to parent
Fixes #379
2011-11-23 11:11:26 -08:00
Joe Groff 5e99a7bbbf vm: disable SIGINT handler while in factorbug
Fixes #410
2011-11-15 18:50:42 -08:00
Joe Groff c4885ac082 vm: fashion police 2011-11-12 23:05:44 -08:00
Joe Groff c0a44000cc 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 3fc82282f7 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 db19efe1b3 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 e24400679f 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 9e4a51c55f 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 2e9552d98a vm: hand SIGALRM to signal pipe if not sampling 2011-11-08 23:37:22 -08:00
Joe Groff 5f3cd4079c 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 820fd6417d vm: don't send foreign samples to outer space 2011-11-08 14:00:33 -08:00
Joe Groff 90609cc5d8 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 fc7c175c9f 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 0c58fd5c26 vm: more commentary on lock_console() stuff 2011-11-08 08:52:52 -08:00
Joe Groff 5f811c0573 vm: don't mask SIGTTIN from stdin_loop
Fixes #360
2011-11-08 08:42:48 -08:00
Joe Groff f9aa0419c4 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 04c6b2c393 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 18e01f7770 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 72d335f2b5 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 92445d77e2 vm: restore sigaltstack setup on unix
#ifdef __OpenBSD__ is different from #ifndef __OpenBSD
2011-11-03 11:57:43 -07:00
Joe Groff 30ed9b535b vm: parameterize sampling rate 2011-11-02 13:23:15 -07:00
Joe Groff 1351e30e52 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 f5cdfaeb2a 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 80fb7788d9 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 2d5360778f cleanups from code review 2011-10-27 21:18:23 -07:00
Joe Groff 9eee44ce4a vm: remove half-assed signal queueing scaffolding
Should implement it right later. See #297.
2011-10-27 21:18:22 -07:00
Joe Groff 6d57eb4f59 vm: update windows for resumable signals 2011-10-27 21:18:21 -07:00
Joe Groff 5d59faa7d1 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 dca0fd3487 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 c3f007ce0a 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 6e4117035e vm: factor out dispatch_signal_handler logic 2011-10-27 21:14:49 -07:00
Joe Groff dc42365007 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 1dc31d133b 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 3726f61c70 vm: fatal_error if VM-less thread gets a signal 2011-10-27 21:14:48 -07:00
Joe Groff 552711e903 vm: block all signals from unix stdin_loop thread 2011-10-27 21:14:47 -07:00
Joe Groff b3e5f75c9e 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 99804d5e3f vm: code_heap::(un)guard_safepoint methods 2011-10-27 21:14:44 -07:00
Erik Charlebois 64252dbdbc 32 and 64 bit Linux PPC support 2011-05-23 23:36:14 -04:00
Slava Pestov 8ccaa417ab vm/os-unix.cpp: remove dead code 2010-09-20 21:36:19 -07:00
Slava Pestov 5378f2a0c7 vm/os-unix.cpp: set pipe file descriptors to close on exec 2010-09-15 22:20:24 -07:00
Slava Pestov 7374d868e7 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 d74817cedf vm: Remove signal_callstack_top nonsense 2010-09-02 22:57:17 -05:00
Slava Pestov 1818bcb780 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