Commit graph

2811 commits

Author SHA1 Message Date
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
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
39000946e3 bytecmp: Make sure that load time forms are applied in the correct order. Fixes #312 2017-12-19 21:13:11 +01:00
Daniel Kochmanski
2e9c58b3d4 mulithreading: fix semaphore-signal
It didn't wake up all processes to check the condition what caused n+1 lag in
condition check for signal-process (when called with n>1). Fixes #421. No
regression test, because this is already tested in sem-signal-* tests (they were
failing).
2017-12-08 13:40:34 +01:00
Daniel Kochmanski
e42d95d41a cosmetic: some indent fixes 2017-10-11 10:27:01 +02:00
Daniel Kochmanski
c771b46c5f feature: export make-stream-from-fd interface 2017-10-11 10:25:59 +02:00
Daniel Kochmanski
05871c943a fix debugging leftover 2017-10-09 22:56:32 +02:00
Daniel Kochmanski
835e85bc99 cleanup: remove dead code block
if x length is < 5, reader will signal an error, so it will never be
equal 2. Probably a leftover from some previous bytecodes
implementation state.
2017-10-09 22:51:52 +02:00
Daniel Kochmanski
9ba7440782 bytecmp: be smart wrt bytecompiled code
bytecompiled functions may not have a name (i.e lambda assigned to
smothing). Recognize that fact, so when we read back such functions
from file we can call bc-compile on them. Fixes #313.
2017-10-09 22:45:50 +02:00
Daniel Kochmanski
b851e85701 cosmetic: line unwrap 2017-10-09 22:45:38 +02:00
Daniel Kochmanski
2a98ce10fe core: si:copy-stream has three arguments
argument `wait' denots, whenever we wait for EOF or yield when there
is no input available in the first stream.
2017-10-09 09:35:54 +02:00
Daniel Kochmanski
7cad2c8e7d types: introduce ext:virtual-stream type
This type applies to all streams which doesn't have a
descriptor (gray:fundamental-stream and string-stream for now).
2017-10-08 20:21:49 +02:00
Daniel Kochmanski
d02ec85d24 ffi: void functions return no values 2017-09-30 20:34:08 +02:00
Daniel Kochmanski
fe392867c3 consistency: defcallback always returns just pointer, not a list
Fixes #223.
2017-09-30 12:23:57 +02:00
Daniel Kochmański
abdd5f3b5d Merge branch 'develop' into 'develop'
make potential_number_p thread-safe

Closes #406

See merge request embeddable-common-lisp/ecl!93
2017-09-28 16:21:10 +00:00
Marius Gerbershagen
82dbd0ea1f make potential_number_p thread-safe. Closes #406 2017-09-24 19:03:38 +02:00
Daniel Kochmański
2877ffde65 Merge branch 'fix-memory-corruption' into 'develop'
Use bdwgc macros to allow memory debug.

See merge request embeddable-common-lisp/ecl!92
2017-09-19 14:02:08 +00:00
Daniel Kochmański
cb244bfad9 Merge branch 'develop' into 'develop'
Fix segmentation faults when interrupting a thread while it is exiting

See merge request embeddable-common-lisp/ecl!91
2017-09-19 13:59:18 +00:00
Fabrizio Fabbri
bc522801a9
Use bdwgc macros to allow memory debug. 2017-09-19 00:23:47 -04:00
Fabrizio Fabbri
f0d09de88e
Fix #402 multiple-values are not returned (reverted)
Reintroduce fix for additional coverity warnings.
2017-09-19 00:16:06 -04:00
Marius Gerbershagen
7365d59407 cosmetic: use ECL_WITH_SPINLOCK_BEGIN/END instead of manual calls to ecl_giveup_spinlock 2017-09-15 18:15:09 +02:00
Marius Gerbershagen
8c2748da17 fix segmentation faults when interrupting a thread while it is exiting
When mp_process_interrupt and thread_cleanup are called at the same
time, it is possible that the thread-local environment is deallocated
while ecl_interrupt_process tries to use it. This two methods thus
need to be protected with a lock.
2017-09-13 18:51:44 +02:00
Daniel Kochmanski
7db4543051 environ: accept empty list as nil environment
To inherit current process environemnt, user has to pass `:default' as
environ (what is a default value).
2017-09-05 20:17:39 +02:00
Daniel Kochmanski
e7876023c8 cosmetic: add dot to the end of message 2017-09-05 20:16:22 +02:00
Daniel Kochmanski
5ef3d3d51d Revert "Fix additional coverity warnings."
This reverts commit 06f5697074.
2017-09-01 09:51:40 +02:00
Marius Gerbershagen
bd1c5675ce ecl_number_equalp: fix comparision with floating point infinities and NaNs 2017-08-25 18:39:27 +02:00
Marius Gerbershagen
a7fdcf5cf3 fix sign of infinity returned by expt of 0.0 and a negative number, e.g. (expt 0.0 -1.0) 2017-08-25 17:42:17 +02:00
Daniel Kochmanski
436e6a62ca pathname-match-p: fix invalid comparison
(pathname-match-p "foo" "foo?") returned T, because we had too weak
comparison. Now it returns NIL.
2017-08-18 07:59:57 +02:00
Marius Gerbershagen
5f71f728a3 disable floating point exceptions when feenableexcept is not defined 2017-08-12 13:34:11 +02:00
Marius Gerbershagen
722faa1a20 undo last two commits 2017-08-12 13:33:29 +02:00
Marius Gerbershagen
de205bb114 fix handling of floating point exceptions on certain architectures 2017-08-03 17:20:20 +02:00
Daniel Kochmanski
1dd6870cd5 cleanup: signal error if pipe couldn't be created 2017-07-21 10:41:26 +02:00
Daniel Kochmanski
00bfed0386 cleanup: remove unused variable 2017-07-21 10:14:23 +02:00
Fabrizio Fabbri
cc442ac9cd
Compiled assoc does not check arguments 2017-07-04 04:59:37 +02:00
Daniel Kochmański
9735057bc3 stacks: don't call si_set_finalizer
si_set_finalizer is CL-world function and returns 0 values. That means
in particular, that env->nvalues is changed.

In this situation, when new binding was introduced, we could lose our
nvalues, what lead to invalid multiple-value-bind (next commit will
contain a regression test).

We use unprotected version. If interrupts cause problems with it, we
may need to wrap it in disable_interrupts. Threading code uses
ecl_set_finalizer_unprotected without such wrapping though, so I
believe that should be safe.

Fixes #233.
2017-07-02 22:35:37 +02:00
Daniel Kochmański
0828b1f48a equalp: don't compare clos instance slots
Problem identified and fixed by Marius Gerbershagen. Closes #391.
2017-06-30 20:19:51 +02:00
Kris Katterjohn
91bf0c4998 Fix typo in error message: ist -> is 2017-06-29 17:29:18 -05:00
Kris Katterjohn
028ab410b2 Remove FEprogram_error_noreturn and replace uses with FEprogram_error
These two function are the same.

Here is my understanding: FEprogram_error_noreturn was introduced with
the noreturn function attribute in commit 7d9fb8bb because
FEprogram_error did not have this attribute.  However, FEprogram_error
got the noreturn function attribute in commit 790d466c.  Now there is
no reason to have both of these.

This removes FEprogram_error_noreturn and changes all calls to it
with calls to FEprogram_error instead.
2017-06-29 17:24:54 -05:00
Kris Katterjohn
643651e320 Move FEillegal_variable_name to error.d and use it where appropriate
This was local to compiler.d, but it should also be used in stacks.d.

This is used in place of the error message introduced in commit 9ff142.
2017-06-28 14:21:28 -05:00
Kris Katterjohn
f5b9430c6c Introduce FEbinding_a_constant and use it where appropriate
This is for signalling an error about binding a constant variable.

This makes the error messages originally in commits 745686, c9e732
and 4e3283 more precise.
2017-06-28 14:03:29 -05:00
Kris Katterjohn
4e3283706f No longer allow PROGV to bind constants
PROGV was allowed to bind constants in the C-compiler and the bytecode
compiler and interpreter, but the behavior would differ between them:

> (defun foo ()
    (flet ((memq (item list) (member item list :test #'eq)))
      (progv (list :test) (list :test-not)
        (memq 'bar '(bar baz quux)))))
FOO

> (foo)
(BAZ QUUX)

> (compile 'foo)
FOO

> (foo)
(BAR BAZ QUUX)

CLHS says the behavior is undefined when attempting to bind or assign
constant variables (CLHS 3.1.2.1.1.3 and the entry for defconstant).

The C-compiler and bytecode compiler and interpreter give errors when
attempting to bind or assign constant variables in lambda expressions,
LET, SETQ and various other binding/assignment forms.  So the behavior
above in PROGV is inconsistent.

Now give an error when attempting to bind a constant variable in PROGV
in the C-compiler and the bytecode compiler and interpreter.
2017-06-27 18:46:55 -05:00