Commit graph

8297 commits

Author SHA1 Message Date
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
76b78660b2 Merge branch 'cmp-fix-macrolet' into develop 2018-02-14 16:30:10 +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
21016c9fc9 Merge branch 'cmp-fix-374' into 'develop'
Moderate compiler refactor

Closes #374

See merge request embeddable-common-lisp/ecl!98
2018-02-11 17:42:06 +00: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
c9cf8df872 cosmetic: add two entries to gitignore. 2018-02-10 20:25:45 +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
Daniel Kochmanski
f9fbd3ee30 Add test for local variable corruption inside block #374. 2018-02-10 17:52:30 +01:00
Daniel Kochmanski
3f9c69d5b3 Add unwind-protect transformation when cleanup-forms are empty
This optimization doesn't buy us much but it doesn't cost us anything
either. Note that it emits c1form in case of expression what means that
expression won't be promoted to top-level form after the reduction.
2018-02-10 17:52:30 +01:00
Daniel Kochmanski
c138be5818 cmp: some cleanup changes
Add missing declarations here and there, remove setf to unused variable etc.
2018-02-10 17:51:53 +01:00
Daniel Kochmanski
48d5420b16 cmp: all baboon have now error message
This is useful for identification, where the problem occured. Also add some
indent and line wrap fixes which are estetic. Comment out unused variable.
2018-02-05 18:11:35 +01:00
Marius Gerbershagen
3ec7c3b749 threading: fix race conditions when interrupted while pushing in the stack
We have to make sure that the stack pointers always point to a
    valid object. This means that we have to increase env->stack_top
    before we change things in the stack.
2018-02-04 21:53:45 +01:00
Marius Gerbershagen
276f4c79ff threading: save/restore more environment elements in handle_all_queued to prevent race conditions
env->stack_top has to be temporarily increased too, to prevent
    it from being overwritten from the interrupting code.
2018-02-04 21:26:08 +01:00
Marius Gerbershagen
b92f30d263 threading: use safer allocation method for interrupt_struct in _ecl_alloc_env 2018-02-03 22:45:33 +01:00
Marius Gerbershagen
11f495f2b3 threading: restore env->function in handle_all_queued
If a thread is interrupted directly after a call to
    ecl_function_dispatch, env->function may be overwritten before
    it is used. Thus we need to save and restore when we
    execute queued signals.
2018-02-03 22:29:04 +01:00
Daniel Kochmanski
9be0e12ccd Revert "Fix package of *clos-booted* which is set in streams"
This reverts commit 04e8b63b18.
2018-02-03 16:27:30 +01:00
Daniel Kochmanski
04e8b63b18 Fix package of *clos-booted* which is set in streams
GRAY package was used and symbols were not EQ, so I assume this was a
typo. Problem noticed by drmeister (thanks!).
2018-02-03 11:16:51 +01:00
Marius Gerbershagen
1beabdf9a2 threading: fix ecl_import/release_current_thread
Due to the recent changes introduced in ECL_WITH_SPINLOCK_BEGIN,
    we need a functioning environment when we use this macros.
2018-02-02 20:00:24 +01:00
Marius Gerbershagen
e458caf652 threading: fix barrier implementation
The logic im mp_barrier_wait is wrong. decrement_counter returns
    the value of the counter __before__ it is decremented. Before
    the fix, the counter decremented until it reached 0 and then the
    next arriving thread would get stuck in decrement_counter. Also,
    interrupts were not reenabled in all cases.
2018-01-26 20:56:16 +01:00
Marius Gerbershagen
6449d67337 threading: prevent deadlock in ecl_get_spinlock if we already own the lock 2018-01-22 21:58:40 +01:00
Marius Gerbershagen
3946e2031f threading: lock signal_queue_spinlock in queue_signal with the right thread 2018-01-22 21:56:46 +01:00
Marius Gerbershagen
34ca2a2f38 threading: fix newly introduced race condition in mp_process_enable
If mp_process_enable is interrupted after pthread_create, but
    before its exit code is examined, the cleanup code may be run
    even when pthread_create did not fail, so we need to disable
    interrupts in this region.
2018-01-22 21:52:25 +01:00
Marius Gerbershagen
79b77fc7e5 add another forgotten ecl_enable_interrupts 2018-01-22 21:13:07 +01:00