Commit graph

123 commits

Author SHA1 Message Date
Stas Boukarev f119986c69 Fix sb-posix for 64-bit time_t. 2025-01-17 05:34:24 +03:00
Stas Boukarev f979e2c60d Unexport sb-posix:posix-fork.
Some checks failed
CL-host / ecl (push) Waiting to run
CL-host / clisp (push) Waiting to run
CL-host / ccl (push) Waiting to run
CL-host / cmucl (push) Waiting to run
CL-host / sbcl (push) Waiting to run
CL-host / compare-xc-host-fasls (ccl, false) (push) Blocked by required conditions
CL-host / compare-xc-host-fasls (clisp, false) (push) Blocked by required conditions
CL-host / compare-xc-host-fasls (cmucl, false) (push) Blocked by required conditions
CL-host / compare-xc-host-fasls (self, false) (push) Blocked by required conditions
Linux / build (x86, --with-sb-thread, ) (push) Waiting to run
Linux / build (x86, --without-sb-thread, ) (push) Waiting to run
Linux / build (x86, --without-sb-unicode, ) (push) Waiting to run
Linux / build (x86-64, --with-mark-region-gc) (push) Waiting to run
Linux / build (x86-64, --with-sb-fasteval --without-sb-eval, fasteval) (push) Waiting to run
Linux / build (x86-64, --with-sb-thread, ) (push) Waiting to run
Linux / build (x86-64, --with-sb-thread, sse4) (push) Waiting to run
Linux / build (x86-64, --without-sb-thread, ) (push) Waiting to run
Linux / build (x86-64, --without-sb-unicode, ) (push) Waiting to run
Mac / build (--without-sb-thread, x86-64) (push) Waiting to run
Mac / build (arm64, --with-mark-region-gc) (push) Waiting to run
Mac / build (arm64, --with-sb-thread) (push) Waiting to run
Mac / build (x86-64, --with-mark-region-gc) (push) Waiting to run
Mac / build (x86-64, --with-sb-thread) (push) Waiting to run
Windows / build (push) Waiting to run
Linux qemu / ppc64le (push) Failing after 0s
sb-posix:fork is the interface, calling fork() directly will just
crash with multiple threads.
2024-09-30 22:27:05 +03:00
Douglas Katzman bbe8ed1e5e Use WITH-ALIEN instead of LET
Saves about 200 bytes per function. The compiler can't seem to avoid
materialization of an alien when LET-bound.
2024-09-06 08:57:00 -04:00
Douglas Katzman 968120d0ee Make a single C function for sb-posix:fork to call
I considered using pthread_atfork to run this but decided against it.
2024-07-17 12:16:06 -04:00
Richard M Kreuter e068d347f6 Don't export GET/SET/END??ENT or WITH-*-DATABASE macros
It's a little hard to envision a use for the GET/SET/END??END routines
that the DO- macros don't cover. Since the GET/SET/END routines are
not reentrant, calling them during a DO- iteration can only serve to
mess up that iteration, so making those functions available seems only
to expose error possibilities. And if those functions are not external
to SB-POSIX, then users don't need WITH-*-DATABASE macros either.
2023-08-31 12:16:47 -04:00
Richard M Kreuter 20e61f6b8a Add DO-PASSWDS and DO-GROUPS to SB-POSIX
For stepping through the respective databases.
2023-08-31 12:15:20 -04:00
Richard M Kreuter 153ff9fdbb Insinuate passwd/group database coordination into functions
Have GETPWNAM, GETPWUID implicitly use WITH-PASSWD-DATABASE; GETGRNAM,
GETGRGID use WITH-GROUP-DATABASE. Require that GETPWENT, SETPWENT,
ENDPWENT be called during the extent of a WITH-PASSWD-DATABASE, and
likewise for the group functions.

Add simple tests for these. (These tests add 2 seconds to the
sb-posix test suite runtime, unfortunately.)
2023-08-31 11:57:34 -04:00
Richard M Kreuter d9c52a282f Add WITH-PASSWD-DATABASE and WITH-GROUP-DATABASE to SB-POSIX
These protect against concurrent uses of the respective databases in
distinct threads, as well as prohibit attempts at reentrant use. It's
up to users to wrap their getpw* and getgr* calls in these macros.

(No tests are added for these because it seemed as if doing so would
merely exercise WITH-MUTEX, which is tested for elsewhere.)
2023-08-30 21:01:49 -04:00
Richard M Kreuter 0e9880fc10 Add SB-POSIX bindings for get-/set-/end- of -pwent/-grent. 2023-08-30 20:58:16 -04:00
Richard M Kreuter d4e181c3a7 Add a MEM slot & accessor to SB-POSIX:GROUP
Also add docstrings for the class & slots, and get the manual to
include them.
2023-08-30 20:53:30 -04:00
Richard M Kreuter 3b86708787 SB-POSIX:SYSCALL-ERROR for routines that can return NULL.
Specifically: getpwnam, getpwuid, getgrnam, getgruid, readdir, and
getenv. For all but getenv, POSIX describes the convention that a NULL
return value and "unchanged" errno is a non-error (including
end-of-directory for readdir, no-such-user for getpw*, etc), but NULL
and a changed errno is an error. SB-POSIX hasn't ever signaled errors
for a changed errno before, but probably should. (As for getenv, POSIX
does not define any errors for it, but FreeBSD and OSX document
setting errno to EINVAL sometimes; and FreeBSD actually behaves as
documented; so it seems reasonable to bind to whatever the OS does.)

Unfortunately, it's unclear how to force these errors for testing. For
the ones having to do with the passwd and group databases, SBCL
probably can't and certainly shouldn't try to interfere with them. For
readdir, I was unable to induce an error in a few experiments
concurrently modifying a directory while SBCL was enumerating it; and
the getenv case isn't required to set errno anywhere.
2023-08-30 20:14:54 -04:00
Douglas Katzman 40276b2537 Complete merge of mark-region-gc
Put "--without-gencgc --with-mark-region-gc" in the make.sh invocation
to enable it (which automatically disables immobile space for now).
There are some known test failures.

Big thanks to Hayley Patton for this.
2023-08-09 22:20:11 -04:00
Stas Boukarev dd3771b402 Fix ioctl on darwin-arm64
Reported by fiddlerwoaroof
2023-04-27 00:56:13 +03:00
Douglas Katzman b32c31b686 Fix style-warnings for #-unix 2022-09-23 11:35:33 -04:00
Kartik Singh 96f0f2612e Remove non-pauseless-threadstart code
This is a modified version of Douglas Katzman's commit 869f2acd62
(Remove non-pauseless-threadstart code), which gets the
pauseless-threadstart feature to work on Windows.  Since Windows is the
last outstanding platform that builds with pauseless-threadstart
disabled by default, this commit also removes the pauseless-threadstart
feature flag entirely.

The original commit was modified so that it applies to 2.2.7 as well as
to remove the setup semaphore and to set th->no_tls_value_marker to
NO_TLS_VALUE_MARKER in alloc_thread_struct.

Note: The original commit was reverted by 15f2ccc551 (Revert "Remove
non-pauseless-threadstart code") due to failing tests.
2022-08-02 18:52:28 -04:00
Douglas Katzman 6bbdfe5ffc Revise SB-POSIX implementation for wait, waitpid, pipe
Use WITH-ALIEN, preserving backwards-compatibility at the API though
2021-06-10 20:04:56 -04:00
Jan Moringen fb46f952f0 Remove redundant read-time conditionals 2021-02-09 01:35:44 +01:00
Stas Boukarev c4b191eec3 Fix sb-posix on darwin-arm64.
open() and fcntl() are variadic functions.
2021-02-04 01:27:00 +03:00
Douglas Katzman 5ac62accfa Start the finalizer thread early and often
This change should resolve both lp#1906571 and lp#1907872.

Delaying finalizer thread creation until just-in-time was too complicated.
Doing it at startup is less confusing because the state of the world is known,
and synchronously stopping/restarting around any call to FORK, as well as
immediately prior to SAVE-LISP-AND-DIE, is easier too.

Use a native condition variable to inform the thread when to run or exit.
Deadlock can't happen because triggering finalizers never involves make-thread
or a mutex (though native condition vars may use one internally), and there's
no hidden "possibly starting a thread" state.
2020-12-29 15:07:45 -05:00
Douglas Katzman 39c952d211 sb-posix: Test both utime and utimes
Because sb_utimes was removed except on netbsd and nothing caught that.
Why isn't sb-posix responsible for building its own C wrappers?
2020-10-13 11:24:22 -04:00
Douglas Katzman 0987b39cfa Use external symbol 2020-09-20 18:16:33 -04:00
Douglas Katzman 8ce0e3fb37 Reduce size of per-thread safepoint page
GC page granularity is larger than needed. Use the OS-reported size.
2020-09-18 12:32:16 -04:00
Douglas Katzman 15f2ccc551 Revert "Remove non-pauseless-threadstart code"
This reverts commit 869f2acd62.
2020-09-11 10:59:41 -04:00
Douglas Katzman eaa1a54bcf Fix #-sb-thread some more 2020-09-10 17:05:43 -04:00
Douglas Katzman 869f2acd62 Remove non-pauseless-threadstart code
Add a setup semaphore for win32 so the new code resembles the old.
I don't know why it's needed, but tests fail without. The differences
in safepoint logic for unix versus win32 might explain things.
2020-09-10 15:10:55 -04:00
Douglas Katzman 88b98e2d20 Speed up MAKE-THREAD for x86[-64] on linux
* Remove the create_thread_lock and thread setup semaphore. The start function
  is handed off in a GC-safe way and the creating thread is allowed to continue
  as soon as pthread_create() returns.

* Retain the memory from up to 2 exited threads for reuse by new threads.
  This is not shared with the FOREIGN-THREAD memory pool, but perhaps could be.

While this adds more conditionalization to both C and Lisp, it should be
adaptable to OS_THREAD_STACK so that ultimately we can have only one way
of performing post-mortem freeing instead of three.

Benchmarks show about 6x to 7x faster lisp thread creation.

Incidentally this fixes lp#1595699.
2020-07-20 22:48:37 -04:00
Douglas Katzman 1dbad9cb90 Remove *ALL-THREADS-LOCK*
It's not needed to protect the AVL tree.

It was overloaded to not only do that but also prevent creation of new threads
which is better done with the make-thread lock; as well as prevent thread exit,
for which its use was completely horrible.

Since each thread already has a mutex for interruptions, use that for
SYMBOL-VALUE-IN-THREAD (and INTERRUPT-THREAD) to ensure that the memory
exists (in the former case) or the pthread ID exists (in the latter).
There is absolutely no reason to look in the C variable all_threads,
unless you're using one of the platforms/configs that I don't understand.
2020-06-30 11:20:55 -04:00
Douglas Katzman cc425f4be3 Fix sb-posix for riscv
As to the fcntl.1 test, it seems at this point that we should only look
for the expected o-nonblock bit rather than have two variations of the test.
2020-03-02 10:25:09 -05:00
Douglas Katzman 6863dcbae6 Require :sb-dynamic-core for arm64
I assumed that this would help find the cause of crashing with #-sb-thread,
and miraculously the change actually seems to have entirely fixed the problem.
Given that observation, I surmised that the bug lay with misuse of LR as a
temp register which this change removes. Further confirmation was obtained by
reverting the patch and merely adding (LOAD-IMMEDIATE-WORD ,LIP 0) after each
inline allocation. Simply clearing LIP made the random crashing disappear.

I don't know if there was a point in the past when the non-thread build was
perfectly reliable despite the allocation macro being relatively unchanged.
It didn't seem sufficiently interesting a question for me to answer, but in
the interest of code health, I think the LIP argument should be removed.
2020-02-15 21:22:32 -05:00
Douglas Katzman b01a734539 Require :sb-dynamic-core for ppc 32-bit
With #+sb-thread this already worked. Without threads, it benefited from a
simple change to the 'allocation' macro which removed 1 instruction.
2020-02-09 12:10:05 -05:00
Douglas Katzman 795438df9d ppc64: Wrap stat(), lstat(), fstat() for sb-posix 2019-08-30 14:19:09 -04:00
Jan Moringen acfde66e5a Fix more redundant and unsatisfiable read-time conditionals 2019-04-14 18:31:25 +02:00
Douglas Katzman 99a4eb8348 Use fewer sharp-dots
* #.(1- (ash 1 sb-vm:n-word-bits)) can be spelled MOST-POSITIVE-WORD.

* instead of '(mumble #.(expr)) use `(mumble ,(expr)) when expr is constant.
  backquote is constant-foldable in that case.

* but in particular `(signed-byte ,sb-vm:n-word-bits) is just SIGNED-WORD,
  respectively `(unsigned-byte ,sb-vm:n-word-bits) is WORD.

* unrelatedly, sb-vm:n-machine-word-bits is external in its package.
2019-03-21 10:16:28 -04:00
Douglas Katzman ed5f1538f4 Change *ALL-THREADS* to an AVL tree
Use a single source of truth for stack addresses and set of running threads.
The AVL tree is of the pure functional variety, and the root node is swapped
out for any insert or delete. The STACK-ALLOCATED-P function becomes safer -
at worst it sees a stale tree but never one that violates any invariants.

I do not know whether this fixes the duplicate insertion problem observed
in https://sourceforge.net/p/sbcl/mailman/message/36517264/
but it should allow us to figure out whether the problem pre-dated use of a
tree structure in the sense that tree insertion failure would happen only if
*ALL-THREADS* itself would have contained zombie threads.
I believe that to be the case, as the code for tree insert and delete were
guarded by the same critical section that guarded *ALL-THREADS*.
Therefore if deletion failed to happen in the tree for a previous thread
death, then it ought to have failed to happen in the list representations too.

Of course it's also possible that the treap code was buggy, and/or the
AVL code, but they were/are regression tested by a random tester. Another
scenario would be the code inserting a new thread somehow running before
the code deleting the old, but I don't understand in that case how you would
get a stack address that is the same, because the deletion runs on the stack
of the very thread that is dying. i.e. a physical stack is freeable only
after having removed yourself from *all-threads*. Therefore no new thread can
lay claim to that address space. I really think that if a thread died a
hard (horrible) death, it could fail to remove itself from any lists.

A final note - it seem that the "portable-threads" library directly uses
SB-THREAD::*ALL-THREADS* which is obviously wrong. If we can't find someone
to shoot, then we could rename the global var to something different,
and then (DEFINE-SYMBOL-MACRO *ALL-THREADS* (LIST-ALL-THREADS))
which restores the look-and-feel of the sb-thread internals.
2019-01-27 23:08:20 -05:00
Stas Boukarev 19bff5cac3 sb-posix:fork: do finalizer-thread-stop. 2018-03-03 14:59:06 +03:00
Stas Boukarev 6a17b926af Use unsigned-long for ioctl().
That's what it is on Linux and BSDs.

Fixes lp#1746619
2018-02-01 19:19:30 +03:00
Douglas Katzman b62ec12736 Export by defpackage, not random unconditional toplevel form 2018-01-23 23:19:34 -05:00
Jan Moringen 5ff75f656f PROCESS-STATUS tracks stopped and continued processes properly
Based on patch by Elias Pipping.

fixes lp#1624941
2017-09-10 15:38:03 +02:00
Stas Boukarev 1df5faffd4 sb-posix:read/write should accept size-t length, not int. 2017-03-06 05:01:17 +03:00
Stas Boukarev 46734cced8 Fix sleeping after sb-posix:fork on macOS.
Call init_mach_clock() after forking.

Reported by Johann 'Myrkraverk' Oskarsson.
2017-01-31 15:22:22 +03:00
Stas Boukarev 47d4552ccd sb-posix: no getresgid getresuid on Darwin. 2016-10-03 22:31:04 +03:00
Stas Boukarev a833d4df83 sb-posix: Fix getresuid() and getresgid().
The functions actually accept three arguments, not zero.
Pass pointers to uid-t/gid-t to them, return three values.

Fixes lp#1603806
2016-07-18 18:56:30 +03:00
Stas Boukarev b260c63071 SHIFTF should use LET* for binding temporary variables.
Or any other user of setf-expander, says CLHS. SHIFTF was using LET.

Reported by Frank Huttner.
2015-11-13 02:33:29 +03:00
Stas Boukarev 6c264b59b7 Fix handling of errors in SB-UNIX:UNIX-READDIR.
An error from readdir is indicated as a non zero errno and a zero
return value, otherwise errno is unchanged. Set errno to 0 in the
sb_readdir wrapper.
2015-11-11 18:06:26 +03:00
Alastair Bridgewater d539677a65 sb-posix: Partial fix for lp#1500951
* cfsetispeed(3) and cfsetospeed(3) are defined to mutate an
existing termios structure, but while SB-POSIX:CFSETISPEED and
SB-POSIX:CFSETOSPEED were accepting a TERMIOS structure as input,
they were not setting up the "alien" termios structure based on
the input, thus clobbering most of the termios state.

  * Fix, by adding a couple of calls to TERMIOS-TO-ALIEN.

  * Note that this does not help the other major part of
lp#1500951, which is confirmed to affect FreeBSD and NetBSD, and
possibly other systems: the termios structure may have fields
beyond the minimum specified set, and these fields may be used to
hold the ispeed and ospeed values.
2015-10-18 14:26:57 -04:00
Joshua Elsasser 161af96a63 Simplify quoting to unbreak netbsd build of sb-posix.
From Aleksej Saushev <asau@netbsd.org>
2015-03-10 17:08:35 -07:00
Douglas Katzman ffe7f8fcbe Implement sb_mkstemp using the real mkstemp except on win32. 2014-08-04 21:14:32 -04:00
Robert Swindells 64d0778fd1 sb-posix NetBSD fixups
- argument to mmap(2) is size_t, not unsigned;
- disable tests for fcntl(2)
- wrap utimes(2)
2014-06-13 16:09:32 +01:00
Stas Boukarev e55432f31f Revert "Implement sb-posix:stat using wrappers."
It doesn't fix all the Android problems, just pushes them away.
2014-06-01 10:25:29 +04:00
Stas Boukarev 27776258ca Implement sb-posix:stat using wrappers.
It's not easy to determine the layout of struct stat, and it fails to
do so on Android, sb-unix:stat is implemented with a wrapper which
parses everything on the C side. Just reuse that wrapper for
sb-posix:stat.
2014-06-01 08:04:50 +04:00