Commit graph

6574 commits

Author SHA1 Message Date
Marius Gerbershagen
7b5361613b fix memory leak with bignums
Letting the gmp library use uncollectable allocations leads to
    leaks, if the bignums are not freed with mpz_clear. Since this
    can't be done without a finalizer, we have to use the standard
    allocation mechanism. Fixes #433.
2018-03-26 22:00:55 +02:00
Marius Gerbershagen
1b0ffbe6cc threading: fix race condition in mp_process_enable
Local variables were not declared volatile, so they could be
    changed by the setjmp call in ECL_UNWIND_PROTECT_BEGIN. This could
    lead to execution of the cleanup statements even though the thread
    creation was successfull and thus to segmentation faults.
2018-03-26 22:00:55 +02:00
Marius Gerbershagen
b9c4c3fc90 tests: add stress test suite 2018-03-26 21:11:30 +02:00
Marius Gerbershagen
146b4a6ae1 cosmetic: fixed some typos and style issues 2018-03-26 21:11:11 +02:00
Marius Gerbershagen
9fe9334538 fix rounding error in ecl_stack_set_size
The size of the arguments stack would grow quadratically, instead
    of being rounded to the nearest bigger page size.
2018-03-23 21:57:45 +01:00
Daniel Kochmański
7bfa7e37b6 Merge branch 'develop' into 'develop'
docs: fix a typo in a code example

See merge request embeddable-common-lisp/ecl!101
2018-03-16 15:09:02 +00:00
Daniel Kochmański
c09256866f Merge branch 'threading-fixes' into 'develop'
Threading fixes

Closes #419

See merge request embeddable-common-lisp/ecl!100
2018-03-16 15:08:27 +00:00
Kris Katterjohn
ae2d5e98a3 new-doc: fix a typo in a sffi code example
This changes the incorrect keyword :on-liner to the
correct :one-liner
2018-03-12 15:25:28 -05:00
Marius Gerbershagen
eca39581a5 fix build failures with --disable-threads 2018-03-02 18:56:23 +01:00
Marius Gerbershagen
d87c5b2c5a threading: fix resource leak on windows
Thread handles were never closed. Also fixed the ugly hack in
    process->thread, where a pthread_t object was used on windows instead
    of the correct HANDLE object.
2018-02-28 21:20:06 +01:00
Marius Gerbershagen
fd900d9c64 threading: fix race conditions in ecl_unlist_process/thread_cleanup
ecl_unlist_process is called in thread_cleanup after interrupts have
    been disabled, however it uses unwind-protect, which will disenable and
    then reenable interrupts. Since on windows, we don't have an equivalent
    of sigmask, we can't use unwind-protect and instead rely on disabled
    interrupts to make sure, that the spinlock is always released.
2018-02-28 20:55:49 +01:00
Marius Gerbershagen
47029db7b2 threading: fix race conditions on windows
ecl_check_pending_interrupts is used in ecl_enable_interrupts_env,
    which may not always be in a place where we can handle signals without
    safety measures. _ecl_w32_exception_filter needs to be protected too. Here,
    the switch statement could also fall through to EXCEPTION_INT_DIVIDE_BY_ZERO,
    leading to wrong errors being displayed.
2018-02-24 14:31:44 +01:00
Marius Gerbershagen
2ccc5de365 rename function arguments to avoid collision with identically named define
Fixes mingw build error.
2018-02-23 20:33:51 +01:00
Marius Gerbershagen
a8d7305fb6 threading: fix race condition in stacks_scanner
The garbage collector can call stacks_scanner in a thread before
    pthread_setspecific, leading to a wrong error message. The
    solution is simply not to mark the environment, if
    pthread_setspecific has not yet been called.
2018-02-20 21:40:04 +01:00
Marius Gerbershagen
f9630fa8b3 threading: fix race conditions in CLOS cache
If a thread is interrupted after a call to fill_spec_vector, but
    before it can call ecl_search_cache, the cache may change during
    the interrupt, leading to crashes. We can't use
    env->disable_interrupts since fill_spec_vector calls methods which
    write in the thread-local environment. Disabling interrupts in
    ecl_search_cache and clear_list_from_cache is now redundant and
    has been removed.
2018-02-20 20:24:08 +01:00
Marius Gerbershagen
25ec43b498 fix typo in stacks.h 2018-02-20 20:15:31 +01:00
Marius Gerbershagen
7d6112d0e8 threading: fix race condition in pop_signal
The pending interrupts list may be modified after we have checked
    whether it is nil, but before we aquire the spinlock, leading to
    segmentation faults.
2018-02-18 21:03:07 +01:00
Marius Gerbershagen
24e4c13d58 threading: block interrupts during execution of cleanup forms in unwind-protect
If we don't do this, execution of the cleanup forms may be
    interrupted or they may not be executed at all. This behaviour
    would probably be acceptable for external code, however the
    unwind-protect mechanism is also used internally to protect
    against deadlocks (e.g. in ECL_WITH_(SPIN)LOCK).
2018-02-18 21:02:26 +01:00
Marius Gerbershagen
3f0fc4f855 threading: fix race conditions in ECL_WITH_GLOBAL_ENV_RD/WRLOCK
We can't use ecl_disable_interrupts, because often writes in the
    thread local environment happen while we hold the locks (e.g.
    env->packages_to_be_created is written in find_pending_package
    while the lock is held in ecl_make_package). Therefore we use the
    lisp interrupt blocking mechanism. For this, the order of
    operations in cl_boot has to be modified a bit.
2018-02-18 21:01:44 +01:00
Marius Gerbershagen
e5281a4685 threading: add explanation about stack interrupt safety 2018-02-17 20:58:49 +01:00
Marius Gerbershagen
2193e4b55d fix typo in frs_set_size 2018-02-17 19:13:34 +01:00
Marius Gerbershagen
f0506f511e threading: fix possible race conditions in ecl_wakeup_waiters
Checking process.phase without holding the start_stop_spinlock
    looks dangerous, the thread may exit after the check but before we
    interrupt it. Also, we can't call mp_process_kill while interrupts
    are disabled, so we have to use the lower level ecl_interrupt_process.
2018-02-17 16:24:38 +01:00
Marius Gerbershagen
0ecea9487c move ECL_STACK_RESIZE_DIS/ENABLE_INTERRUPTS in a separate header file
Compilation of lisp files will sometimes fail otherwise, since
    .eclh files can include internal.h
2018-02-16 20:53:59 +01:00
Marius Gerbershagen
bad90d0f65 threading: safer handling of overflows in frame and binding stacks
Previously, the dummy tag was written behind the stack
    boundary. Also added race condition protection to non-inlined
    ecl_bds_bind/push. The memory barriers have been reworked,
    too. AO_store_full has been replaced by AO_full_nop. This is
    sufficient to insert the required memory barrier instructions and
    is implemented in a simpler way by libatomic_ops in some cases.
2018-02-16 19:58:20 +01:00
Marius Gerbershagen
fc29c08d93 threading: use safer method to disable interrupts when resizing stacks
Due to the use of mprotect() for fast interrupt dispatch it is
    not possible to write in the thread local environment when
    interrupts are disabled. We need to use sigprocmask to block
    interrupts in this case.
2018-02-16 19:07:27 +01:00
Daniel Kochmanski
17645d703e bytecodes cosmetic cleanup 2018-02-15 13:50:51 +01:00
Daniel Kochmanski
e92cfdf437 Unify compilation environment markers
In both bytecmp and c compiler we use si:function-boundary and
si:unwind-protect-boundary where appropriate. Previously bytecmp used an ad-hoc
special variable for function-boundary and didn't mark unwind-protect at all.

Remove recently-introduced ECI package (maybe we will reintroduce it later when
we'll have a common frontend for compilers).
2018-02-15 12:44:49 +01:00
Marius Gerbershagen
8a68a5c225 threading: fix race condition in ecl_unwind
If ecl_unwind is interrupted with another call to ecl_unwind
    before it has decremented env->frs_top, the second call of
    ecl_unwind may stop too early with its unwinding, leading to
    potential segfaults.
2018-02-14 22:52:22 +01:00
Marius Gerbershagen
e7838e4b86 threading: fix race conditions in CLOS cache
Writes in the cache were not protected against interrupts, leading
    to segfaults when clear_list_from_cache or ecl_search_cache were
    interrupted.
2018-02-14 20:41:58 +01:00
Daniel Kochmanski
c94784ac77 Add semaphore helpdoc's and latest changes to changelog. 2018-02-14 17:10:44 +01:00
Daniel Kochmanski
c2209e5a53 minor documentation improvements 2018-02-14 16:29:26 +01:00
Daniel Kochmanski
289ef6e37b Add help entry for si::eval-with-env. 2018-02-13 14:38:14 +01:00
Daniel Kochmanski
50fb814fd1 Accept all valid function names in c::compile
Previously we accepted only symbols, now we use si:valid-funciton-name-p
predicate to allow (setf foo) as well.
2018-02-13 13:22:12 +01:00
Daniel Kochmanski
2862fc611d Add regression tests for non-lambda exprs and (setf fun) names 2018-02-13 12:44:52 +01:00
Daniel Kochmanski
fd183e575f Better error messages, bc-compile improvements
bc-compile is more conforming now (we validate definition and name, also our
closure compilation is a bit better, still broken though).

Also improve some error messages and add periods at the end.
2018-02-13 12:43:32 +01:00
Daniel Kochmanski
2f01e576a2 Add regression tests for recent bugs / problems.
Bug with bclosure is not fixed yet.
2018-02-13 10:07:44 +01:00
Daniel Kochmanski
d9da8648cd Look up a lexical macro before a compiler macro.
Fixes #83. Fixes #237.
2018-02-12 16:02:00 +01:00
Daniel Kochmanski
857ea3d928 interpreter: don't create closures for null lexenv
We have created empty closure for instance when flet was in null lexenv. Check
for Null in close_over and create t_bclosure only for non-null lexical
environments.
2018-02-12 16:01:26 +01:00
Daniel Kochmanski
67e9c5bef0 Cosmetic fixes to bytecodes compiler. 2018-02-12 16:01:02 +01:00
Marius Gerbershagen
3c7085798d threading: only save/restore thread local variables in handle_all_queued when actually needed
We don't need to save/restore outside of signal handlers. Also,
    bignum_registers were not saved. Allocation of the values array
    has been changed to heap allocation, since this array is quite
    large and we may overflow the C stack, if we allocate it there.
2018-02-11 23:22:43 +01:00
Marius Gerbershagen
6ce7ebc19f threading: fix race conditions when interrupted while pushing in the bindings stack
If ecl_bds_push or ecl_bds_bind were interrupted by a call to
    ecl_bds_unwind, segementation faults could occur, because
    env->bds_top->symbol may not have pointed to a valid symbol.
    Also, memory corruption was possible if the functions were
    interrupted after setting slot->symbol but before setting
    slot->value.
2018-02-11 22:20:24 +01:00
Marius Gerbershagen
fac5f3f7fc documentation: add a few sentences to the description of ecl_disable_interrupts
A few typos were also fixed
2018-02-11 22:04:55 +01:00
Marius Gerbershagen
59a6d0ae44 threading: ensure that we don't get interrupted during setjmp
Interrupting a thread during setjmp with a call to ecl_unwind
    leads to segmentation faults, since we try to call longjmp
    before the corresponding setjmp has finished. Thus, we also need
    to wait until setjmp has finished before we can set frs_val of
    the frame.
2018-02-10 21:47:39 +01:00
Daniel Kochmanski
7ec2f4a939 Major cleanup for environment mark interpretation
Code was previously written with an assumption, that we know whenever function
crosses lexical for closure boundaries before it is compiled (and env-mark for
such boundries was LB and CB appropriately). Later it has changed, but code was
ready to work with LB and CB marks.

Fix these parts of code and replace it with a single mark ECI:FUNCTION. Also
replace CL:UNWIND-PROTECT boundry mark with ECI:UNWIND-PROTECT so we are less
dependent on use-ing CL package. Adjust comments to have this change.
2018-02-10 20:21:11 +01:00
Daniel Kochmanski
82efbab4c0 cmp: update comments in cmptypes
It contained some information which is no longer valid (and makes it hard to
grok a code if the programmer doesn't know what it does already).
2018-02-10 18:14:51 +01:00
Daniel Kochmanski
cae6f0004d cmp: simplify return-from c1form
Now it accepts 3 arguments (not 4) because variable is taken from blk-var.
2018-02-10 18:14:17 +01:00
Marius Gerbershagen
ca5ef0f977 threading: fix race condition when _ecl_frs_push is interrupted with a call to ecl_unwind
If by chance env->frs_top->frs_val has the value ECL_PROTECT_TAG,
    ecl_unwind will stop and call longjmp. However, at this point
    setjmp has not yet been called, leading to a segmentation fault.
2018-02-10 18:11:27 +01:00
Daniel Kochmanski
07843b3e86 Don't depend in tag-ref-{ccb,clb} which are broken anyway
We have dummy variable for that, so we refere to

(var-ref-ccb (tag-var blk))
(var-ref-clb (tag-var blk))

Brokeness comes from the fact that closures are computed after function
compilation pass-1 (and tagbody is inside). Analogous change to the previous
commit in cmpblock.

Also improve comments in cmptypes to make it clear that these parts are not
used. Further refactor could make tag inherit from variable - then we wouldn't
have a dummy variable and unnecessary fields whatsoever.
2018-02-10 18:01:55 +01:00
Marius Gerbershagen
6d7ec733eb threading: more race condition fixes for interruptions during stack manipulations 2018-02-10 17:54:35 +01:00
Daniel Kochmanski
78d4e5f923 Don't depend in blk-ref-{ccb,clb} which are broken anyway
We have dummy variable for that, so we refere to

(var-ref-ccb (blk-var blk))
(var-ref-clb (blk-var blk))

Brokeness comes from the fact that closures are computed after function
compilation pass-1 (and block is inside). Fixes #374.

Also improve comments in cmptypes to make it clear that these parts are not
used. Further refactor could make blk inherit from variable - then we wouldn't
have a dummy variable and unnecessary fields whatsoever.
2018-02-10 17:52:30 +01:00