Commit Graph

129 Commits (elevate-erg)

Author SHA1 Message Date
Alexander Iljin 526a995d64 VM: implement a ctrl-break handler thread (#1573) 2016-11-01 16:53:00 -07:00
Björn Lindqvist 78d9065db0 VM: UAP_SET_TOC_POINTER appears to be a noop on all platforms 2016-09-29 07:14:30 +02:00
Björn Lindqvist a0df88f20b VM: renaming verify_memory_protection_error to set_memory_protection_error
and sets the signal_fault_addr and signal_fault_pc in the function.
2016-09-22 13:12:59 +02:00
Alexander Iljin 0d57734dab vm: replace block comments /**/ with line comments // 2016-09-09 05:47:52 +02:00
Björn Lindqvist b5c6658ae5 VM: removing the safepoint_state class
The code reads better if the safepoint_state methods and
attributes (sample_counts and safepoint_fep_p) are moved to the vm
class.
2016-08-15 15:16:41 +02:00
Björn Lindqvist f99c684cc5 VM: set_border_locked is the same on windows and unix 2016-06-27 16:27:56 +02:00
Björn Lindqvist 10ac4da0f6 VM: fixes to make some if-else statements read better 2016-03-31 00:37:59 +02:00
Björn Lindqvist 7dfb352a7e VM: replaced calls to out_of_memory() with fatal_error()
No need for a special out of memory function -- it's just a kind of
fatal  error. Also make fatal_error() call dump_memory_layout() for
easier debugging.
2015-10-08 20:46:17 +02:00
Björn Lindqvist 2536b6cd93 VM: fix move_file called from save_image
save_image() shouldn't throw exceptions because if the 'then_die'
argument is t it would leave factor in an inconsistent state. So
therefore move_file() should be fixed and raw_fclose() called instead of
safe_fclose().
2015-09-29 23:13:10 +02:00
Björn Lindqvist 39c888230a VM: new function set_safepoint_guard to replace the functions (un)guard_safepoint 2015-08-24 07:23:40 -07:00
Björn Lindqvist 56ddb59b00 VM: new function set_memory_locked(true/false)
it wraps the mprotect/VirtualProtect platform differences and makes it
so you can unify some windows/unix code path forks
2015-08-24 07:23:40 -07:00
Björn Lindqvist 4efef7bfd9 VM: merge the compute_dlsym_toc_address() with the
compute_dlsym_address() method

it makes the code slightly more cluttered but you get rid of a lot of
special casing for the ppc platform
2015-08-23 18:36:31 -07:00
Björn Lindqvist a53d5be683 VM: make allot_alien() and ffi_dlsym() use cell instead of void*
this way we get rid of a bunch of superfluous casts
2015-08-23 18:36:31 -07:00
Björn Lindqvist b8aef640f9 VM: new method set_border_locked() in segment, so that you can remove
the protection of the guard pages
2015-08-14 20:19:56 -07:00
Björn Lindqvist 73956db33a VM: a bunch of methods on factor_vm that can be converted into free
functions

I think that makes it easier to see whats going on than having
everything added to factor_vm
2015-08-04 16:02:09 +02:00
Björn Lindqvist 3887b58c02 VM: cleanups, like removing redundant paranthesis and removing method
declarations that doesn't exist
2015-05-09 20:04:22 -07:00
Doug Coleman 53eac53626 vm: Fail with out_of_memory() if mprotect returns ENOMEM.
Add a message to out_of_memory(msg) calls so we know which call caused the OOM.
Fixes #664.
2014-11-11 06:26:55 +00:00
Doug Coleman 6244b925c7 vm: Simplify strerror code. 2014-07-05 18:58:24 -07:00
Doug Coleman 69262be4d8 vm: Add threadsafe_sterror to the vm. 2014-07-04 03:00:08 -07:00
Steven Stewart-Gallus e6dade3f94 Lower the stack usage of a few functions
In vm/compaction.cpp I rescoped some variables to lower the stack usage
from 592 to 560 bytes. I wasn't very successful with this. The stack
usage is larger than it looks because methods on the structures used
take an implicit this pointer and a reference to the data (so the data
has to live out it's full scope and can't be put in a register).

In vm/debug.cpp I made a large (1024 bytes) stack allocated buffer
simply dynamically allocated.

In vm/os-unix.cpp I rescoped signal handling structures to not coincide
with each other and reduced a very large (1024 bytes) amount of stack
usage to less than 500 bytes.
2014-06-19 14:55:57 -07:00
Björn Lindqvist 9780012f55 dlopen using RTLD_GLOBAL 2014-04-21 23:45:45 -07:00
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