Commit graph

2803 commits

Author SHA1 Message Date
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
Kris Katterjohn
c9e7326275 No longer allow M-V-B to bind constants in bytecode compiler/interpreter
M-V-B was allowed to lexically and dynamically bind constants in the
bytecode compiler and interpreter:

> (multiple-value-bind (pi rem) (truncate pi) pi)
3

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 gives errors for these sorts of things, and the bytecode
compiler and interpreter gives 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 M-V-B is
inconsistent with the C-compiler and other parts of the bytecode
compiler and interpreter.

Now give an error when attempting to bind a constant variable in M-V-B
in the bytecode compiler and interpreter.
2017-06-27 18:44:14 -05:00
Kris Katterjohn
74568641cd No longer allow LET/LET* to bind constants in bytecode compiler/interpreter
LET/LET* were allowed to lexically and dynamically bind constants in
the bytecode compiler and interpreter:

> (let ((pi 3)) pi)
3

> (progn (defconstant +c+ 'foo) (let ((+c+ 'bar)) +c+))
BAR

> (flet ((hello () (format t "hi")))
    (let ((t nil))
      (declare (special t))
      ; Oops, now this returns a string
      (hello)))
"hi"

Plus plenty of other ways to wreak havoc on unsuspecting code.

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).
(Well, CLHS 3.4.1 explicitly says that constant variables cannot be
used for variables in lambda lists.)

The C-compiler gives errors for these sorts of things, and the bytecode
compiler and interpreter gives errors when attempting to bind or assign
constant variables in lambda expressions, SETQ and various other forms.
So the behavior above in LET is inconsistent with both the C-compiler
and other parts of the bytecode compiler and interpreter.

Now give an error when attempting to bind a constant variable in
LET/LET* in the bytecode compiler and interpreter.

This also changes the behavior of PROG/PROG* and DESTRUCTURING-BIND so
that they give errors when attempting to bind constants as well.
2017-06-27 18:42:20 -05:00
Kris Katterjohn
9ff1420cf5 Check for a symbol before attempting to bind it in PROGV
PROGV was attempting to bind whatever was in its variable list
without checking its type.  Using either the C-compiler or bytecode
compiler/interpreter, the following example would lead to a segfault
on my OpenBSD and Linux boxes:

> (defun foo () (progv (list 3) (list 3)))
FOO

> (foo)
Condition of type: SEGMENTATION-VIOLATION
[...]

Now give an error when attempting to bind something that is not a
symbol in PROGV (in both the C-compiler and bytecode compiler and
interpreter).
2017-06-27 18:35:24 -05:00
Kris Katterjohn
26e7802917 Stop depending on uninitialized variables when setting TCP_NODELAY
The contents of an uninitialized variable was used when setting the
TCP_NODELAY option for sockets created with open-client-stream and
open-server-stream, so this option would not be set when the value
of the variable happened to be 0 (which happened regularly on my
OpenBSD box).

Tested on OpenBSD and Linux.
2017-06-23 17:06:57 -05:00
Kris Katterjohn
0c5be44ad9 #include netinet/tcp.h so TCP_* will actually be defined
This header needs to be included so the TCP_* defines are available.
Sockets created with open-client-stream and open-server-stream would
try to set TCP_NODELAY if available, but they couldn't because this
was not defined.

Tested on OpenBSD and Linux.
2017-06-23 17:04:43 -05:00
Fabrizio Fabbri
aa23a0339f
Merge remote-tracking branch 'origin/develop' into develop 2017-06-22 00:47:10 +02:00
Yuguo Zhang
52a232b2d1 adjust memory allocation functions in windows API ecl_get_commandline_args.
the caller and the callee maybe use difference compiler and settings.
2017-06-13 18:22:59 +08:00
Fabrizio Fabbri
06f5697074
Fix additional coverity warnings. 2017-06-06 23:43:02 +02:00