Commit graph

9090 commits

Author SHA1 Message Date
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
Marius Gerbershagen
30a4e64c97 fix typo in ecl_clear_interrupts_env() 2018-01-22 21:11:24 +01:00
Marius Gerbershagen
1265ab111a threading: add error message for forgotten ecl_enable_interrupts 2018-01-22 21:11:24 +01:00
Marius Gerbershagen
5b28a8fc1f threading: make sure that spinlocks are unlocked
If a thread is killed while it holds a spinlock, the lock will
    never be released, leading to deadlocks. Hence we have to clean
    up spinlocks in ECL_WITH_SPINLOCK_END. In mp_process_enable,
    other cleanup (deallocating the environment, unlisting the
    process) has to performed too.
2018-01-22 21:08:34 +01:00
Marius Gerbershagen
ba8b85fc22 make sure interrupts are enabled again after having been disabled
This is important to prevent race conditions. If interrupts are
    left disabled, the environment may be wrongly write protected by
    an interrupting thread and completely harmless writes in the
    environment can lead to segmentation faults.
2018-01-14 20:26:15 +01:00
Marius Gerbershagen
6316012408 fix race condition when a process during cleanup is interrupted too early by a call to mp_exit_process
If a process, that has already unwound its whole frame stack
  (after ECL_CATCH_ALL_END in thread_entry_point) is interrupted by
  a call to mp_exit_process, ECL will crash with a segmentation
  fault. We thus need to aquire the start_stop_spinlock before we
  unwind the frame stack.
2018-01-07 16:31:40 +01:00
Marius Gerbershagen
f5a503c862 fix segmentation faults when a signal is queued for a thread whose environment is write protected
If a thread is interrupted while interrupts are disabled by C,
    then the signal is queued and the environment is write protected
    by mprotect. If another thread then calls queue_signal, it will
    try to write in the protected environment, leading to a
    segmentation fault. Since mprotect can only protect whole memory
    pages, we need to allocate the pending interrupts and the signal
    queue in a separate struct.
2018-01-06 17:58:59 +01:00
Marius Gerbershagen
9227f4e342 fix #409: order of evaluation of values forms
the fix for #330 is unaffected
2017-12-29 16:58:27 +01:00