Commit Graph

267 Commits

Author SHA1 Message Date
Daniel Eischen
1cf08f3929 Reinstall the alternate signal stack after a fork.
PR:		25110
Tested by:	knu
2001-04-18 12:40:30 +00:00
Daniel Eischen
f9c408bc01 Clean up a bit. Use the correct TAILQ link when walking the thread
lists to free thread resources after a fork (in the child).  Also
remember to free the dead thread list.
2001-04-10 04:25:49 +00:00
Daniel Eischen
437df4859a To be consistent, use the __weak_reference macro from <sys/cdefs.h>
instead of #pragma weak to create weak definitions.

Suggested by:	bde
2001-04-10 04:19:21 +00:00
Thomas Moestl
8b28ef9528 Activate build of posix1e extensions in libc and libc_r that have been
moved in from libposix1e, and deactivate build of the soon-to-be-removed
libposix1e.

Approved by:	rwatson
Obtained from:	TrustedBSD Project
2001-04-04 18:17:28 +00:00
Thomas Moestl
16cb0dd753 Add thread safety wrappers for the posix1e syscalls that deal with file
descriptors.

Approved by:	rwatson
Obtained from:	TrustedBSD Project
2001-04-04 18:10:25 +00:00
Ian Dowse
92f5474235 Add a leading underscore to the pthread_main_np function name, and
a "#pragma weak" directive linking the external symbol. This matches
the other pthread_* definitions, and ensures that users of this
function from within libc get the real version, not the stub.

Suggested by:	deischen
Reviewed by:	deischen, alfred
2001-04-03 22:25:39 +00:00
Alfred Perlstein
8360efbd6c Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.

  Bring in required TLI library routines to support this.

  Since we don't support TLI we've essentially copied what NetBSD
  has done, adding a thin layer to emulate direct the TLI calls
  into BSD socket calls.

  This is mostly from Sun's tirpc release that was made in 1994,
  however some fixes were backported from the 1999 release (supposedly
  only made available after this porting effort was underway).

  The submitter has agreed to continue on and bring us up to the
  1999 release.

  Several key features are introduced with this update:
    Client calls are thread safe. (1999 code has server side thread
    safe)
    Updated, a more modern interface.

  Many userland updates were done to bring the code up to par with
  the recent RPC API.

  There is an update to the pthreads library, a function
  pthread_main_np() was added to emulate a function of Sun's threads
  library.

  While we're at it, bring in NetBSD's lockd, it's been far too
  long of a wait.

  New rpcbind(8) replaces portmap(8) (supporting communication over
  an authenticated Unix-domain socket, and by default only allowing
  set and unset requests over that channel). It's much more secure
  than the old portmapper.

  Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
  to support TI-RPC and to support IPV6.

  Umount(8) is also fixed to unmount pathnames longer than 80 chars,
  which are currently truncated by the Kernel statfs structure.

Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
Daniel Eischen
af4878847e Correct a race condition where it was possible for a signaled
thread to become stranded and not placed in the run queue.

MFC Candidate

Reported by:	tegge
2001-03-09 16:05:43 +00:00
Daniel Eischen
c33f8c177f Really set the flags for a private mutex (used by libc/libc_r). 2001-02-26 01:06:52 +00:00
Daniel Eischen
c6f2aed102 Limit threads clock resolution to no less than 1000usec (1000Hz).
PR:		25300
Submitted by:	Tom Pavel <pavel@alum.mit.edu> (in part)
2001-02-26 01:05:33 +00:00
Daniel Eischen
f434cd45ed Remove (int) file descriptor locking. It should be up to the
application to provide locking for I/O operations.  This doesn't
break any of my tests, but the old behavior can be restored by
compiling with _FDLOCKS_ENABLED.  This will eventually be removed
when it is obvious it does not cause any problems.

Remove most of flockfile implementation, with the exception of
flockfile_debug.

Make error messages more informational (submitted by Mike Heffner
<spock@techfour.net>, who's now known as mikeh@FreeBSD.org).
2001-02-11 22:07:32 +00:00
Daniel Eischen
f8a19b12fb s/_thread_sys_write/__sys_write/
Submitted by:	Mike Heffner <mheffner@vt.edu>
2001-01-31 02:16:57 +00:00
Daniel Eischen
f47892a9f7 Unbreak world by correctly specifying the prototype for __sys_aio_suspend.
A make buildworld was done but not with the committed pthread_private.h.

Reported by:	Manfred Antar <null@pozo.com>
2001-01-29 18:59:53 +00:00
Daniel Eischen
221b1e69c5 _exit in libc is now __sys_exit not __sys__exit.
Add another check for thread library initialization (jdp, we
really need a way to get _thread_init called at program start
before any constructors are run).
2001-01-29 03:24:23 +00:00
Daniel Eischen
75f7221ee6 -pthread -> -lc_r 2001-01-24 13:41:04 +00:00
Daniel Eischen
e5106342c6 Add weak definitions for wrapped system calls. In general:
_foo - wrapped system call
	foo - weak definition to _foo

and for cancellation points:

	_foo - wrapped system call
	__foo - enter cancellation point, call _foo(), leave
	        cancellation point
	foo - weak definition to __foo

Change use of global _thread_run to call a function to get the
currently running thread.

Make all pthread_foo functions weak definitions to _pthread_foo,
where _pthread_foo is the implementation.  This allows an application
to provide its own pthread functions.

Provide slightly different versions of pthread_mutex_lock and
pthread_mutex_init so that we can tell the difference between
a libc mutex and an application mutex.  Threads holding mutexes
internal to libc should never be allowed to exit, call signal
handlers, or cancel.

Approved by:	-arch
2001-01-24 13:03:38 +00:00
David E. O'Brien
cad1dd7bb4 Force strong references to several pthread_* functions which are weakly
referenced to by libgcc.a.

This is needed when linking statically as SVR4 (ie, ELF) behavior is to only
link in a module if it satisfies an undefined strong reference from somewhere.
(this surprises a lot of people) Things are different when using shared libs,
the entire library and its modules and their symbols are available at run-time
(when the weak reference is seen to still be unsatisfied and is satisfied on
the spot), this is not the case with static libs.

Thus one can have a static binary with unresolved week references, and at
run-time dereference a NULL pointer.

Submitted by:	eischen
2001-01-06 06:07:52 +00:00
Daniel Eischen
9ffc4537c8 When retrieving the time of day in nanosleep(), store it in the
global time of day.  This costs us nothing, but is a bit of a hack
to work around a process blocking and not having the time updated
by an ITIMER_PROF signal.

PR:		23679
2000-12-20 17:04:12 +00:00
Daniel Eischen
d73eb8c8ca Enable check for pending signals after calling a signal handler.
Restoration of a threads signal mask after invocation of a signal
handler may allow pending signals to become deliverable.

PR:		23647
2000-12-20 16:55:57 +00:00
Daniel Eischen
47c1571785 Change a "while {}" loop to a "do {} while" to allow it to be
executed at least once, fixing pthread_mutex_lock() for recursive
mutex lock attempts.

Correctly set a threads signal mask while it is executing a signal
handler.  The mask should be the union of its current mask, the
signal being handled, and the mask from the signal action.

Reported by: Dan Nelson <dnelson@emsphone.com>

MFC Candidate
2000-11-20 13:12:44 +00:00
Daniel Eischen
499c499c61 Fix MD macros to work for alpha. Without this fix, threads under alpha
seem to be totally broke.

MFC Candidate

Submitted by:	gallatin
2000-11-20 01:57:19 +00:00
Daniel Eischen
f17033e38d Fix a bug where a statically initialized condition variable
was not getting properly initialized in pthread_cond_signal()
and pthread_cond_broadcast().  Reportedly, this can cause
an application to die.

MFC candidate

Submitted by:	ade
2000-11-16 22:50:33 +00:00
Daniel Eischen
810888e2f8 Delete 4 lines of misleading/incorrect comments. 2000-11-16 19:15:56 +00:00
Daniel Eischen
eb4463fde6 When entering the scheduler from the signal handler, tell
the kernel to (re)use the alternate signal stack.  In this
case, we don't return normally from the signal handler,
so the kernel still thinks we are using the signal stack.
The fixes a nasty bug where the signal handler can start
fiddling with the stack of a thread while the handler is
actually running on the same stack.

MFC candidate
2000-11-14 20:00:19 +00:00
David E. O'Brien
fe17fef5d2 Bump the shared lib version. There seems to have been an incompatible
change committed to RELENG_4 where a bump there is now necessary.
We've got to go before RELENG_4 does.
2000-11-14 02:46:23 +00:00
Daniel Eischen
00e550955e Correct the logic for checking the emptiness of the waiting queue.
This fixes a potential problem where the file descriptors would not
be polled causing waiting threads to stay waiting.  Doh!

MFC candidate.
2000-11-11 22:20:36 +00:00
Daniel Eischen
b5a8a15c2f Don't needlessly poll file descriptors when there are no
file descriptors needing to be polled (Doh!).  Reported
by Dan Nelson <dnelson@emsphone.com>.

Don't install and start the scheduling timer until the
first thread is created.  This prevents the overhead of
having a periodic scheduling signal in a single threaded
program.  Reported by Dan Nelson <dnelson@emsphone.com>.

Allow builtin longjmps out of application installed
signal handlers without the need perform any post-handler
cleanup:

  o Change signal handling to save the threads interrupted
    context on the stack.  The threads current context is
    now always stored in the same place (in the pthread).
    If and when a signal handler returns, the interrupted
    context is copied back to the storage area in the pthread.

  o Before calling invoking a signal handler for a thread,
    back the thread out of any internal waiting queues
    (mutex, CV, join, etc) to which it belongs.

Rework uthread_info.c a bit to make it easier to change
the format of a thread dump.

Use an alternal signal stack for the thread library's
signal handler.  This allows us to fiddle with the main
threads stack without fear of it being in use.

Reviewed by:	jasone
2000-11-09 05:08:26 +00:00
John Polstra
a9bda22cd6 At the beginning of pthread_mutex_lock(), call _thread_init() if
necessary.  This works around a bug in old versions of libgcc_r.a
which are statically linked into old executables.
2000-11-01 20:19:07 +00:00
Daniel Eischen
c418675341 Make pthread_kill() know about temporary signal handlers installed
by sigwait().  This prevents a signal from being sent to the process
when there are no application installed signal handlers.

Correct a typo in sigwait (foo -> foo[i]).
2000-10-25 11:46:07 +00:00
Daniel Eischen
2fbba8b1b8 We use ___setjmp (non-signal saving) to setup a signal frame. When
adding a signal frame to a thread, be sure to label the context
correctly so we don't restore an uninitialized process mask.

Reported by:	kimc@W8HD.ORG and Andrey Rouskol <anry@sovintel.ru>
2000-10-22 18:35:11 +00:00
Peter Wemm
100063a74b Try and get libc_r to compile again on the alpha after deischen's commit 2000-10-17 06:31:40 +00:00
Brian Somers
9c8ec4f794 #include <sys/types.h> 2000-10-15 20:04:09 +00:00
Daniel Eischen
b4145b0bfa Enable _PTHREADS_INVARIANTS until the recent libc_r changes are
shaken out.
2000-10-13 22:19:50 +00:00
Daniel Eischen
fbeb36e4bf Implement zero system call thread switching. Performance of
thread switches should be on par with that under scheduler
activations.

  o Timing is achieved through the use of a fixed interval
    timer (ITIMER_PROF) to count scheduling ticks instead
    of retrieving the time-of-day upon every thread switch
    and calculating elapsed real time.

  o Polling for I/O readiness is performed once for each
    scheduling tick instead of every thread switch.

  o The non-signal saving/restoring versions of setjmp/longjmp
    are used to save and restore thread contexts.  This may
    allow the removal of _THREAD_SAFE macros from setjmp()
    and longjmp() - needs more investigation.

Change signal handling so that signals are handled in the
context of the thread that is receiving the signal.  When
signals are dispatched to a thread, a special signal handling
frame is created on top of the target threads stack.  The
frame contains the threads saved state information and a new
context in which the thread can run.  The applications signal
handler is invoked through a wrapper routine that knows how
to restore the threads saved state and unwind to previous
frames.

Fix interruption of threads due to signals.  Some states
were being improperly interrupted while other states were
not being interrupted.  This should fix several PRs.

Signal handlers, which are invoked as a result of a process
signal (not by pthread_kill()), are now called with the
code (or siginfo_t if SA_SIGINFO was set in sa_flags) and
sigcontext_t as received from the process signal handler.

Modify the search for a thread to which a signal is delivered.
The search algorithm is now:

  o First thread found in sigwait() with signal in wait mask.
  o First thread found sigsuspend()'d on the signal.
  o Current thread if signal is unmasked.
  o First thread found with signal unmasked.

Collapse machine dependent support into macros defined in
pthread_private.h.  These should probably eventually be moved
into separate MD files.

Change the range of settable priorities to be compliant with
POSIX (0-31).  The threads library uses higher priorities
internally for real-time threads (not yet implemented) and
threads executing signal handlers.  Real-time threads and
threads running signal handlers add 64 and 32, respectively,
to a threads base priority.

Some other small changes and cleanups.

PR:		17757 18559 21943
Reviewed by:	jasone
2000-10-13 22:12:32 +00:00
Maxim Sobolev
24a1dab36f Add thread-safe wrapper for fpathconf(2) syscall.
Reviewed by:	jlemon
2000-09-19 18:01:03 +00:00
Jason Evans
f3ee83c3bf The second call to _thread_kern_sig_defer() in sem_post() should be a call
to _thread_kern_sig_undefer().
2000-08-23 07:59:50 +00:00
Alfred Perlstein
022daa34f2 Fix an off-by-one error in the recursive mutex handling that made it
prematurely release recursive mutexes.

Test case provided by: Bradley T. Hughes <bhughes@trolltech.com>
Reviewed by: deischen
2000-08-13 01:30:36 +00:00
Jonathan Lemon
532c92a865 Add wrapper for kevent() syscall
Noted as missing by: nicolas.leonard@animaths.com
2000-08-07 16:51:56 +00:00
Jason Evans
b167c9a5c1 Make sem_post() safe to call from within a signal handler, as required by
POSIX/SUSv2.
2000-08-01 21:19:09 +00:00
Doug Rabson
678ef1b49e Call _thread_init() from pthread_once() if it has not already been called.
This fixes a segfault in some C++ programs which use exceptions before
main() has been called (i.e. from global constructors).

Reviewed by: deischen
2000-07-21 09:31:13 +00:00
Jason Evans
8e234adf86 Change my email address in the copyright notices for the sake of consistency
(jasone@canonware.com --> jasone@freebsd.org).
2000-07-18 01:38:19 +00:00
Jason Evans
390a1cd5eb Deal correctly with statically initialized condition variables in
pthread_cond_signal(), pthread_cond_broadcast(), and pthread_cond_timedwait().

Do not dump core in pthread_cond_timedwait() (due to a NULL pointer
dereference) if attempting to wait on an uninitialized condition variable.

PR:	bin/18099
2000-07-17 22:55:05 +00:00
Jason Evans
e21fa6847e Remove DEBUG_FLAGS=-g3, which never should have been committed. 2000-07-05 16:21:42 +00:00
Jason Evans
8d107d1210 If multiple threads are blocked in sigwait() for the same signal that does
not have a user-supplied signal handler, when a signal is delivered, one
thread will receive the signal, and then the code reverts to having no
signal handler for the signal.  This can leave the other sigwait()ing
threads stranded permanently if the signal is later ignored, or can result
in process termination when the process should have delivered the signal to
one of the threads in sigwait().

To fix this problem, maintain a count of sigwait()ers for each signal that
has no default signal handler.  Use the count to correctly install/uninstall
dummy signal handlers.

Reviewed by:	deischen
2000-06-27 21:30:16 +00:00
Jason Evans
314be1347b pthread_mutex_lock(), pthread_cond_trywait(), and pthread_cond_wait() are
not allowed to return EINTR, but use of pthread_suspend_np() could cause
EINTR to be returned.  To fix this, restructure pthread_suspend_np() so that
it does not interrupt a thread that is waiting on a mutex or condition, and
keep enough state around that pthread_resume_np() can fix things up
afterwards.

Reviewed by:	deischen
2000-06-14 17:17:41 +00:00
Jake Burkholder
e39756439c Back out the previous change to the queue(3) interface.
It was not discussed and should probably not happen.

Requested by:		msmith and others
2000-05-26 02:09:24 +00:00
Jake Burkholder
740a1973a6 Change the way that the queue(3) structures are declared; don't assume that
the type argument to *_HEAD and *_ENTRY is a struct.

Suggested by:	phk
Reviewed by:	phk
Approved by:	mdodd
2000-05-23 20:41:01 +00:00
Jason Evans
ccb3a748f4 Fix a memory leak. pthread_set_name_np() allocates space for a name, but
was not deallocating space for the previous name, if any.

PR:	misc/18504
2000-05-16 22:08:14 +00:00
Bruce Evans
80a07932e7 Fixed missing consts for function parameters, so that the code matches
the man page and POSIX.1.  Fixed nearby misformatting.  Fixed a missing
prototype.
2000-05-11 15:57:17 +00:00
Jason Evans
4c089f4dff Add missing man pages. Fix various compliance bugs, mostly having to do with
error return values.  Implement pthread_mutexattr_gettype().

PR:		docs/16537, docs/17538
2000-05-02 06:51:40 +00:00
Jason Evans
98a1f447bb Add a wrapper for the sendfile() system call.
PR:		bin/17366
2000-04-27 00:59:44 +00:00
Jason Evans
e419521997 Add test to detect propagation of cancellation points within libc_r. 2000-04-26 23:25:58 +00:00
Jason Evans
be1d533999 Automated regression test harness for libc_r. Existing tests are integrated,
a new test for POSIX semaphores was added, and examples of harness usage are
included.
2000-04-24 21:07:45 +00:00
Jason Evans
7e5e179982 Explicitly include sys/cdefs.h to get the definition of __strong_reference(),
rather than getting lucky due to header dependencies.
2000-03-18 22:36:46 +00:00
Daniel Eischen
1d013a86ed Fix pthread_suspend_np/pthread_resume_np. For the record, suspending a
thread waiting on an event (I/O, condvar, etc) will, when resumed using
pthread_resume_np, return with EINTR.  For example, suspending and resuming
a thread blocked on read() will not requeue the thread for the read, but
will return -1 with errno = EINTR.  If the suspended thread is in a critical
region, the thread is suspended as soon as it leaves the critical region.

Fix a bogon in pthread_kill() where a signal was being delivered twice
to threads waiting in sigwait().

Reported by (suspend/resume bug):	jdp
Reviewed by:	jasone
2000-03-15 13:59:27 +00:00
Jason Evans
8a668b9049 For errors, return -1 and set errno to indicate the error type, rather than
returning the error directly.

For sem_post(), make sure that the correct thread is woken up.  This has
unfortunate performance implications, but is necessary for POSIX compliance.

Approved by:	jkh
2000-02-16 19:34:53 +00:00
Jason Evans
d77639f25f Use __strong_reference() instead of __weak_reference() to assure that the
weak symbols of the same name are not used.
2000-01-29 22:53:55 +00:00
Jason Evans
4ec6f67d10 Use _fcntl() (not fcntl()) inside of fcntl().
Reported by:	green
2000-01-28 22:10:27 +00:00
Jason Evans
9233c4d942 Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo().  In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate.  In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by:	deischen
2000-01-27 23:07:25 +00:00
Jason Evans
0c5d1a3361 Fix millisecond to nanosecond conversion.
PR:		misc/16245
2000-01-22 09:15:15 +00:00
Jason Evans
beab1ec9b5 Minor *jmp() cleanups. 2000-01-20 21:53:59 +00:00
Jason Evans
120bfc9ded Add sem_*() functions. Named semaphores and process-shared semaphores
are not supported by this implementation, and the error return values
from sem_init(), sem_open(), sem_close(), and sem_unlink() reflect this.

Approved by:	jkh
2000-01-20 07:54:49 +00:00
Jason Evans
adbd6ee028 Do signal deferral for pthread_kill() as it was done in the old days.
Submitted by:	deischen
2000-01-20 04:46:52 +00:00
Jason Evans
0a3fa43c7e Implement continuations to correctly handle [sig|_]longjmp() inside of a
signal handler.  Explicitly check for jumps to anywhere other than the
current stack, since such jumps are undefined according to POSIX.

While we're at it, convert thread cancellation to use continuations, since
it's cleaner than the original cancellation code.

Avoid delivering a signal to a thread twice.  This was a pre-existing bug,
but was likely unexposed until these other changes were made.

Defer signals generated by pthread_kill() so that they can be delivered on
the appropriate stack.  deischen claims that this is unnecessary, which is
likely true, but without this change, pthread_kill() can cause undefined
priority queue states and/or PANICs in [sig|_]longjmp(), so I'm leaving
this in for now.  To compile this code out and exercise the bug, define
the _NO_UNDISPATCH cpp macro.  Defining _PTHREADS_INVARIANTS as well will
cause earlier crashes.

PR:			kern/14685
Collaboration with:	deischen
2000-01-19 07:04:50 +00:00
Daniel Eischen
7e416d8e49 Properly initialize the last active time of the initial thread. This fixes
the case that a CPU hungry main thread is prevented from being preempted
due to a negative calculation of its time slice.

Reported by:	Alexander Litvin <archer@lucky.net>
2000-01-18 11:35:25 +00:00
Jason Evans
f560c4e709 Track libc's three-tier symbol naming. libc_r must currently implement
the _libc_*() entry points and add *() weak aliases.  This will all
change for the better when libc_r becomes libpthread.
2000-01-12 09:28:58 +00:00
Daniel Eischen
3eadb69d1f Make sched_param parameter a const to comply with POSIX and SUSv2 specs.
This doesn't need to be applied to stable, because somehow -stable seems
to have gotten it right.

Reviewed by:	jasone
2000-01-10 04:14:08 +00:00
Jason Evans
91e92a2d3d Don't explicitly mmap() red zones at the bottom of thread stacks (except
the initial thread).  Instead, just leave an unmapped gap between thread
stacks and make sure that the thread stacks won't grow into these gaps,
simply by limiting the size of the stacks with the 'len' argument to
mmap().  This (if I understand correctly) reduces VM overhead
considerably.

Reviewed by:	deischen
1999-12-29 15:44:59 +00:00
Daniel Eischen
1752e66d49 -Wall and minor style(9) cleanups. 1999-12-28 18:13:04 +00:00
Daniel Eischen
69186ed701 Change stack allocation algorithm to make better use of memory
(it was leaving an unused block).  Also protect the global stack
pointer from context changes while fiddling with it.
1999-12-28 18:12:07 +00:00
Daniel Eischen
8d048bba15 Don't wakeup threads when there is a process signal and no installed
handler.  Thread-to-thread signals (pthread_signal) are treated differently
than process signals; a pthread_signal can wakeup a blocked thread if
a signal handler is not installed for that signal.

Found by:	ACE tests
1999-12-28 18:08:09 +00:00
Jason Evans
386812d440 Fix some minor POSIX/SUSv2 compliance nits.
PR:		kern/11982
1999-12-18 01:00:42 +00:00
Daniel Eischen
fc8f3f5bfe Fix problems with cancellation while in critical regions.
o Cancellation flags were not getting properly set/cleared.
  o Loops waiting for internal locks were not being exited
    correctly by a cancelled thread.
  o Minor spelling (cancelation -> cancellation) and formatting
    corrections (missing tab).

Found by:	tg
Reviewed by:	jasone
1999-12-17 00:57:54 +00:00
Daniel Eischen
3dc268f4e7 Fixes for signal handling:
o Don't call signal handlers with the signal handler access lock
    held.
  o Remove pending signals before calling signal handlers.  If
    pending signals were not removed prior to handling them,
    invocation of the handler could cause the handler to be
    called more than once for the same signal.  Found by: JB
  o When SIGCHLD arrives, wake up all threads in PS_WAIT_WAIT
    (wait4).

PR:		bin/15328
Reviewed by:	jasone
1999-12-17 00:56:36 +00:00
Jason Evans
e6a5e33c6b Avoid an infinite loop if the last element of the iov array passed to
writev() has an iov_len of 0.

PR:		bin/8281
1999-12-16 22:35:40 +00:00
Daniel Eischen
4fc937ef8f Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked.  Signals also improperly woke up
threads waiting on I/O.  With this change, signals are now
handled in the following way:

  o If a thread is waiting in a sigwait for the signal,
    then the thread is woken up.

  o If no threads are sigwait'ing on the signal and a
    thread is in a sigsuspend waiting for the signal,
    then the thread is woken up.

  o In the case that no threads are waiting or suspended
    on the signal, then the signal is delivered to the
    first thread we find that has the signal unmasked.

  o If no threads are waiting or suspended on the signal,
    and no threads have the signal unmasked, then the signal
    is added to the process wide pending signal set.  The
    signal will be delivered to the first thread that unmasks
    the signal.

If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.

In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.

Reported by:	Scott Hess <scott@avantgo.com>
Reviewed by:	jb, jasone
1999-12-04 22:55:59 +00:00
Doug Rabson
3c085f72bb * Fix the stack allocation code so that it works for alpha. Change it
to use mmap(..., MAP_STACK, ...) on alpha too since that should work
  now.
* Add hooks to allow GDB to access the internals of pthreads without
  having to know the exact layout of struct pthread.

Reviewed by: deischen
1999-11-28 19:47:43 +00:00
Alfred Perlstein
7285bccf1a add pthread_cancel, obtained from OpenBSD.
eischen (Daniel Eischen) added wrappers to protect against cancled
threads orphaning internal resources.

the cancelability code is still a bit fuzzy but works for test
programs of my own, OpenBSD's and some examples from ORA's books.

add readdir_r to both libc and libc_r

add some 'const' attributes to function parameters

Reviewed by: eischen, jasone
1999-11-28 05:38:13 +00:00
Marcel Moolenaar
616842b791 Add sigsuspend.o and sigpending.o to HIDDEN_SYSCALLS as well.
Pointed out by: jdp
1999-10-14 10:08:53 +00:00
Marcel Moolenaar
a8ce772846 Add sigprocmask to HIDDEN_SYSCALLS. This renames the syscall to
_thread_sys_sisprocmask in libc_r. This solves the undefined symbol...

Reported by: Kenneth Wayne Culver
1999-09-30 15:07:43 +00:00
Marcel Moolenaar
74562f1a2a Add the proper headers so that the SIGNOTEMPTY and SIGSETAND
macros are defined.
1999-09-30 14:51:31 +00:00
Marcel Moolenaar
3cf3c5d9dd sigset_t change (part 5 of 5)
-----------------------------

Most of the userland changes are in libc. For both the alpha
and the i386 setjmp has been changed to accomodate for the
new sigset_t. Internally, libc is mostly rewritten to use the
new syscalls. The exception is in compat-43/sigcompat.c

The POSIX thread library has also been rewritten to use the
new sigset_t. Except, that it currently only handles NSIG
signals instead of the maximum _SIG_MAXSIG. This should not
be a problem because current applications don't use any
signals higher than NSIG.

There are version bumps for the following libraries:
  libdialog
  libreadline
  libc
  libc_r
  libedit
  libftpio
  libss

These libraries either a) have one of the modified structures
visible in the interface, or b) use sigset_t internally and
may cause breakage if new binaries are used against libraries
that don't have the sigset_t change. This not an immediate
issue, but will be as soon as applications start using the
new range to its fullest.

NOTE: libncurses already had an version bump and has not been
      given one now.

NOTE: doscmd is a real casualty and has been disconnected for
      the moment. Reconnection will eventually happen after
      doscmd has been fixed. I'm aware that being the last one
      to touch it, I'm automaticly promoted to being maintainer.
      According to good taste this means that I will receive a
      badge which either will be glued or mechanically stapled,
      drilled or otherwise violently forced onto me :-)

NOTE: pcvt/vttest cannot be compiled with -traditional. The
      change cause sys/types to be included along the way which
      contains the const and volatile modifiers. I don't consider
      this a solution, but more a workaround.
1999-09-29 15:18:46 +00:00
Dmitrij Tejblum
ffd73a0043 Fix a memory leak: free the thread-specific poll_data, used in the select()
implementation.

PR:		13368
Submitted by:	Steve Bernacki, Jr. <steve@copacetic.net>
1999-08-30 15:45:42 +00:00
Daniel Eischen
3e12058d25 When checking for valid timevals in the wrapped select() and poll()
routines, don't return EINVAL but set errno to EINVAL and return -1.
Added a check in pthread_cond_timedwait for a null timespec pointer.
1999-08-30 00:02:08 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Alfred Perlstein
89f6acf96a move sanity check of timeval struct so as not to segfault when passed
a null pointer.

Pointed out by: Thomas Gellekum <tg@ihf.rwth-aachen.de>
Reviewed by:    eivind
1999-08-20 21:06:20 +00:00
John Birrell
e4065e8294 When checking if there is a stack to free, observe the fact that it
might have been mmapped, and if so, passing the pointer to free() is
really not a good idea.

[ In the next millenium, when I've taken over the world, I'm going
  to ban 8 character tabs. You've been warned. ]
1999-08-20 12:17:09 +00:00
Alfred Perlstein
4c263f605c time_to_sleep->tv_nsec > 1000000000
-to-
time_to_sleep->tv_nsec >= 1000000000
1999-08-19 23:18:07 +00:00
Alfred Perlstein
91518882e0 Sanity check time structures passed in, return EINVAL like the system
calls do to avoid corrupting the thread library's concept of wakeup
time.

PR:		kern/12141
Reviewed by:	deischen, eivind
1999-08-19 23:06:11 +00:00
Alfred Perlstein
c81c6baf1d handle under/overflow of time values in a more robust manner,
there may be an overflow that need to be adjusted more than once.

Pointed out by: Fabian Thylmann <fthylmann@stats.net>

Reviewed by:	eivind, jb
1999-08-19 16:49:53 +00:00
Daniel Eischen
936aa6b443 Add check for runnable threads before polling file descriptors.
Submitted by:	tegge
1999-08-12 19:34:39 +00:00
Daniel Eischen
fa7c4d5575 Add RCS IDs to those files without them.
Fix copyrights (s/REGENTS/AUTHOR).

Suggested by:	tg
Approved by:	jb
1999-08-05 12:15:30 +00:00
Daniel Eischen
8b5d18ec76 Fix thread initialization to allow for the case where stdio file
descriptors are not opened.

PR:		bin/12853
Reviewed by:	jb
1999-08-05 12:08:10 +00:00
Dmitrij Tejblum
6ff19e189d Use USRSTACK (defined in <machine/vmparam.h>) to get top of the initial stack.
PTHREAD_STACK_TOP was wrong for all supported architectures.
1999-07-12 16:09:30 +00:00
Jason Evans
66da783384 Fix a couple more coding style nits. 1999-07-11 06:06:52 +00:00
Jason Evans
34582929f1 Modify previous changes to conform better to libc_r's coding style.
Always use mmap() for default-size stack allocation.  Use MAP_ANON instead
of MAP_STACK on the alpha architecture.

Reduce the amount of code executed while owning _gc_mutex during stack
allocation.
1999-07-11 05:56:37 +00:00
Jason Evans
876cc3dae0 Always use growable thread stacks on the i386. The VM_STACK kernel option
must be made default for the alpha before growable thread stacks are
enabled for the alpha.
1999-07-06 00:25:38 +00:00
Jason Evans
439cce0e4b Disable growable stacks by default, as advertised. 1999-07-05 00:38:12 +00:00
Jason Evans
ecaa6e8c9e Use growable stacks for thread stacks that are the default stack size.
Cache discarded default thread stacks for use in subsequent thread creations.

Create a red zone at the end of each stack (including the initial thread
stack), with the hope of causing a segfault if a stack overflows.

To activate these modifications, add -D_PTHREAD_GSTACK to CFLAGS in
src/lib/libc_r/Makefile.  Since the modifications depend on the VM_STACK
kernel option, I'm not sure how to safely use growable stacks by default.

Testing, as well as algorithmic and stylistic comments are welcome.
1999-07-05 00:35:19 +00:00
Dmitrij Tejblum
db06cf96d5 Defer signals, so we will not wait for SIGCHLD after it was delivered. 1999-06-29 19:57:07 +00:00