Commit Graph

499 Commits

Author SHA1 Message Date
Philippe Charnier
ab165955de The .Fn function 2003-06-08 10:13:50 +00:00
Marcel Moolenaar
fee5c3f1f8 Make this compile without warnings on 64-bit architectures:
Don't cast thread_self() to int. Cast to uintptr_t. Pull in the
predefined printf format from <inttypes.h>
2003-06-04 20:38:54 +00:00
Marcel Moolenaar
f10382ac87 Make this compile without warnings on 64-bit architectures:
In recurse(), cast the pointer difference to int to match the format.
The difference is expected to fit in an int.
2003-06-04 20:36:08 +00:00
Mike Makonnen
f833c84a8f If the library is not able to create a thread because resources
don't allow it at the moment, the correct thing to do is try again.
Otherwise, libthr would fail this test because it doesn't allow
an unlimited number of concurrent threads per application.
2003-06-04 08:16:32 +00:00
Peter Wemm
19816dec92 Update for amd64 after repocopy from i386/ 2003-06-02 22:30:59 +00:00
Peter Wemm
3aefe09423 Port libc_r to amd64, and turn it back on for amd64. It passes all of
the same src/lib/libc_r/test/* tests that the other platforms pass.
2003-06-02 22:22:52 +00:00
Robert Watson
778f8875c7 Revert accidental change: don't change the thread library for testing to
libthr.  Oops, sorry about that.

Submitted by:	"Simon L. Nielsen" <simon@nitro.dk>
2003-06-02 00:21:41 +00:00
Robert Watson
0bbe770d6f Include string.h for memset(). 2003-06-01 23:03:49 +00:00
Ruslan Ermilov
61fa6d584f Fixed another bug in the threaded close() call; clear the
stale stdio descriptors flags.

PR:		bin/51535
Submitted by:	Enache Adrian <enache@rdslink.ro>
Reviewed by:	deischen
Approved by:	re (scottl)
2003-05-31 05:23:20 +00:00
Ruslan Ermilov
d635dc4671 If an application closes one of its stdio descriptors (0..2),
an excessive close() on one of these descriptors would cause
a memory for this descriptor to be allocated in the internal
descriptor table.  When this descriptor gets used again, e.g.
through the call to open() or socket(), the descriptor would
be erroneously left in the blocking mode, and the whole
application would get stuck on a blocking operation, e.g.,
in accept(2).

Prevent this bug from happening by disallowing close() against
non-active descriptors (return -1 and set errno to EBADF in
this case).

Reviewed by:	deischen
Approved by:	re (scottl)
2003-05-31 05:20:44 +00:00
Ruslan Ermilov
734ac3b543 mdoc(7) fixes.
Approved by:	re (blanket)
2003-05-24 19:53:08 +00:00
John Polstra
8c0d4b5f92 Add stub implementations of pthread_[gs]etconcurrency to libc_r and
libthr.  No changes were made to libpthread by request of deischen,
who will soon commit a real implementation for that library.

PR:		standards/50848
Submitted by:	Sergey A. Osokin <osa@freebsd.org.ru>
MFC after:	1 week
2003-04-20 01:53:13 +00:00
Jeff Roberson
cc3521d660 - Define a _spinunlock() function so that threading implementations may do
more complicated things than just setting the lock to 0.
 - Implement stubs for this function in libc and the two threading libraries
   that are currently in the tree.
2003-03-26 04:02:24 +00:00
Philippe Charnier
9d09157a0f The .Fn function. Use .Xr where appropriate. 2003-03-24 16:05:24 +00:00
Marcel Moolenaar
cafd6dbd76 Fix threaded applications on ia64 that are linked dynamicly. We did
not save (restore) the global pointer (GP) in the jmpbuf in setjmp
(longjmp) because it's not needed in general. GP is considered a
scratch register at callsites and hence is always restored after a
call (when it's possible that the call resolves to a symbol in a
different loadmodule; otherwise GP does not have to be saved and
restored at all), including calls to setjmp/longjmp. There's just
one problem with this now that we use setjmp/longjmp for context
switching: A new context must have GP defined properly for the
thread's entry point. This means that we need to put GP in the
jmpbuf and consequently that we have to restore is in longjmp.
This automaticly requires us to save it as well.

When setjmp/longjmp isn't used for context switching, this can be
reverted again.
2003-03-05 04:39:24 +00:00
Marcel Moolenaar
d4f7f050a8 Don't cast an int to a pointer type without (possibly) widening the
integral type to the size of a pointer type when it's known that the
cast is valid. On ia64 such casts are generally bad news and has led
us (=peter :-) to make such casts fatal. By casting to intptr_t
before casting to a pointer type, this now compiles cleanly in LP64
architectures. Note that the final cast has been changed to void*
(instead of siginfo_t*) to make it explicit that we're not trying to
pass a siginfo_t pointer but rather trying to pass an int when the
prototype says it should be a pointer.
2003-03-05 04:28:08 +00:00
Ruslan Ermilov
4497800cbc Fixed a typo in MLINKS. 2003-02-24 22:59:01 +00:00
Ruslan Ermilov
ace5be682d mdoc(7) police: Scheduled sweep. 2003-02-24 22:53:26 +00:00
Alexey Zelkin
d92bdf427f Enable just committed manual pages, update MLINKS 2003-02-13 22:12:56 +00:00
Alexey Zelkin
597cf12892 Add AUTHORS section 2003-02-13 22:11:19 +00:00
Alexey Zelkin
318d8cfd73 Finally! Document all undocumented functions in libc_r.
Add manual pages for following functions:

. pthread_attr_setcreatesuspend_np(3)
. pthread_main_np(3)
. pthread_multi_np(3)
. pthread_single_np(3)
. pthread_mutexattr_getkind_np(3)
. pthread_mutexattr_setkind_np(3)
. pthread_resume_all_np(3)
. pthread_resume_np(3)
. pthread_set_name_np(3)
. pthread_suspend_all_np(3)
. pthread_suspend_np(3)
. pthread_switch_add_np(3)
. pthread_switch_delete_np(3)

MFC after:	3 days
2003-02-13 22:10:10 +00:00
Alexey Zelkin
c18f0ff70c Break important implementation detail note into IMPLEMENTATION DETAILS
section. Add cross reference to pthread_attr_getstack() function.

MFC after:	1 day
2003-02-13 18:39:06 +00:00
Alexey Zelkin
41dd2d2dfa Add cross reference for pthread_attr_get_np() 2003-02-13 18:36:48 +00:00
Alexey Zelkin
faa19450ec Rehash MLINKS: add missing ones for recently added pthread_attr_{get,set}stack()
functions and remove links for 3 non-existent functions
2003-02-13 18:35:05 +00:00
Alfred Perlstein
969e2ea158 Actually link in the attr_{set,get}stack. 2003-02-11 07:28:28 +00:00
Alfred Perlstein
4e44912c6c Add pthread_attr_getstack() and pthread_attr_setstack().
Submitted by: Craig Rodrigues <rodrigc@attbi.com>
2003-02-10 08:48:04 +00:00
Philippe Charnier
6f673fd1c0 The .Fn function 2003-02-06 11:10:32 +00:00
Alexey Zelkin
f3cf900844 Document additional behaviour of this function (see
rev 1.3 of uthread_attr_get_np.c)
2003-02-03 10:10:40 +00:00
Alexey Zelkin
618a8b4df0 Improve pthread_attr_get_np() by enabling it to return thread's real stack
address instead of specified by pthread_attr_t passed to pthread_create().

Suggested by:	deischen
2003-02-03 10:08:45 +00:00
Max Khon
1746ea2b02 remove #ifdef _THREAD_SAFE 2003-01-24 01:46:30 +00:00
Tim J. Robbins
5b8dbaa1f9 Add a missing word. 2003-01-15 09:48:15 +00:00
Tim J. Robbins
bae7e9ec5e Document the named semaphore functions. This could still use a bit
of polishing.
2003-01-15 03:07:40 +00:00
Tim J. Robbins
74e03642ee Back out previous; sharing semaphores between processes only works
in certain special cases.
2003-01-14 07:14:06 +00:00
Tim J. Robbins
ab099bd309 Sharing semaphores between processes works now, so remove the stale comments
about it always returning EPERM. Document that ENFILE occurs when the
limit on kernel semaphores is reached.
2003-01-14 04:12:33 +00:00
Tim J. Robbins
51f2ddd7af Cross reference sem(4) so users know which kernel options are required
to use these semaphore functions.
2003-01-14 03:39:09 +00:00
Daniel Eischen
c54f72859c Increase the scheduler stack to 4 pages. This should prevent a stack
overflow when dumping thread info (generated by receipt of SIGINFO).

Reported by:	jmallet
2003-01-11 00:43:20 +00:00
Max Khon
f7ed1917e2 pthread_attr_get_np() now takes 'pthread_t' (not 'pthread_t *')
to be consistent with other pthread_XXX functions
2003-01-07 21:43:30 +00:00
Marcel Moolenaar
4b1d654efb Port libc_r to ia64. We need to do things slightly different
because we have 2 stacks per thread: the regular downward
memory stack and the irregular upward register stack. This
implementation lets both stacks grow toward each other. An
alternative scheme is to have them grow away from each other.
The alternate scheme has the advantage that both stack grow
toward guard pages. Since libc_r is virtually dead and we
really want the *context stuff for thread switching, we don't
try to be perfect, just functional.
2003-01-06 00:56:23 +00:00
Thomas Moestl
54a701f52e Add MD definitions for sparc64. This is based on work by des. 2003-01-05 22:37:03 +00:00
Thomas Moestl
e15d881535 Add an implementation of _atomic_lock for sparc64. This was submitted by
des; I tweaked it slightly by extending the membar and making it match
the style of the rest of the sparc64 assembler code.
2003-01-05 22:23:11 +00:00
Daniel Eischen
3f28905813 Fix typos in comment.
Submitted by:	Craig Rodrigues <rodrigc@attbi.com>
2002-12-28 05:20:03 +00:00
Jens Schweikhardt
57bd0fc6e8 english(4) police. 2002-12-27 12:15:40 +00:00
Ruslan Ermilov
facc67676f mdoc(7) police: Deal with self-xrefs. 2002-12-24 13:41:48 +00:00
Ruslan Ermilov
8d436e783f Make accept(), connect(), recvfrom(), recvmsg(), sendmsg(),
and sendto() cancelation points, as required by POSIX.1-2001.

Reviewed by:	deischen
2002-12-19 11:39:20 +00:00
Ruslan Ermilov
e199383992 mdoc(7) police: overhaul. 2002-12-09 12:41:29 +00:00
Marcel Moolenaar
f8739dd5f9 Implement the lock with a cmpxchg instruction instead of a xchg.
Both are atomic, but the cmpxchg has memory ordering hints. We
give this acquire semantics.

NOTE: The unlock in libc_r is implemented by a "normal" assign
statement. This is not correct on ia64 due to the memory ordering
characteristics of the architecture. We need release semantics
for an unlock.
2002-11-16 17:05:06 +00:00
Archie Cobbs
e46cac58cd When about to do an execve(), don't reset the O_NONBLOCK flag on any file
descriptors that have the close-on-exec flag set, as that will have no
effect anyway and might screw something else up if the file descriptor
happens to be shared with another process.

PR:		standards/43335
MFC after:	1 week
2002-11-15 00:34:28 +00:00
Daniel Eischen
f38fac1471 At initialization, override the pthread stub routines in libc
by filling in the jump table.

Convert uses of pthread routines within libc_r to use the internal
versions (_pthread_foo instead of pthread_foo).

Remove a couple of globals from application namespace.
2002-11-13 18:13:26 +00:00
Archie Cobbs
6578194b8b Fix bogus return values from libc_r's writev() routine in situations where
a partial-write is followed by an error.

PR:		43335
MFC after:	3 days
2002-11-12 19:01:49 +00:00
Archie Cobbs
83189ac197 Fix bogus return values from libc_r's write() routine in situations where
a partial-write is followed by an error.

PR:		43335
MFC after:	1 week
2002-11-05 00:59:18 +00:00
Daniel Eischen
0ece26b0ba Use the strong symbol'd version of pthread_mutex_init so we don't
accidentally call a stub or application provided version of the
same routine.

Submitted by:	dfr
2002-10-31 18:17:58 +00:00
Alexey Zelkin
1f1e884a91 Add & hookup manpage for pthread_attr_get_np(3).
MFC after:	3 days
2002-10-26 15:04:29 +00:00
Alexey Zelkin
cab33357a5 Hook uthread_attr_get_np.c to build 2002-10-26 13:55:35 +00:00
Alexey Zelkin
6dc0be5f9f Add pthread_attr_get_np() function. This is FreeBSD non-portable POSIX threads
extenston function. It supposed to provide facility to get already created
thread's attributes. Looks like it's last thing we need to make JDK's Hotspot
building without requirement to have source tree.

Reviewed by:	deischen
MFC after:	3 days
2002-10-26 13:53:22 +00:00
Alexey Zelkin
64536616e6 Be more agresive on arguments' checking.
OK'ed by:	deischen
MFC after:	3 days
2002-10-26 13:47:06 +00:00
Max Khon
979187053d remove unused __sys_sigaltstack() declaration
Approved by:	deischen
2002-10-22 17:13:32 +00:00
Juli Mallett
47a6e68f2c When dumping thread info, only include the filename and line if we actually
know what file! (Prevents use of NULL).

MFC after:	1 day
Reviewed by:	deischen
2002-10-20 22:49:06 +00:00
Juli Mallett
4aba47f7ce FD locking is not enabled anymore, so the table which contains the owner
of a file descriptor has NULL entries, so don't dereference the table entries
to get the owners ever -- don't print the owners when processing a thread_dump
request as a result of SIGINFO.

Reviewed by:	deischen
2002-10-17 20:26:26 +00:00
Max Khon
19521b0699 fix typo in comments (in preparation for MFC)
Approved by:	deischen
2002-10-15 16:40:57 +00:00
Kris Kennaway
56373a5196 Dump in $TMPDIR if !setugid, and use mode 0644 instead of 0666.
MFC after:	2 weeks
2002-10-13 11:23:31 +00:00
Daniel Eischen
be779e1ae2 Once again, remove the i386-specific hacks to save and restore
the FPU state on receiving and returning from a signal.
The FPU save and restore macros are no longer needed, but
remain defined in case we need to use them again (something
else breaks).  They'll be removed permanently once new
syscalls are added to handle the new i386 ucontext size.
2002-10-05 02:22:26 +00:00
Mike Barcroft
ddb4fb5b44 Add restrict type-qualifier to sem_getvalue(). 2002-10-04 21:32:00 +00:00
Robert Drehmel
e31d11c36a Add the 'restrict' type qualifier to the prototypes of `sigaction',
`sigprocmask', `sigaltstack', and `sigwait' as well as to the
prototypes of the apparantly unimplemented functions `sigtimedwait'
and `sigwaitinfo'.  This complies with IEEE Std 1003.1-2001.
2002-10-02 10:53:44 +00:00
Daniel Eischen
e19573391d Install library-installed signal handlers with the SA_RESTART flag
set.
2002-09-30 08:47:42 +00:00
Daniel Eischen
cbed250de4 Add back the i386-specific hack to save and restore the FP state
to/from a ucontext when a thread is interrupted by a signal.
This will be removed when a proper fix is made in the kernel
to save/restore the FP state without breaking the ABI.
2002-09-30 08:45:38 +00:00
Peter Wemm
224af215a6 Zap now-unused SHLIB_MINOR 2002-09-28 00:25:32 +00:00
Julian Elischer
67d7ad01aa Part of a bandaid to get libc_r on air again.
Submitted by: Dan Eischen (deischen@freebsd.org)
Pointy hat for breakage just before going offline: Mini@freebsd.org
2002-09-19 07:35:39 +00:00
Daniel Eischen
d8b5986dd6 Remove much of the dereferencing of the fd table entries to look
at file flags and replace it with functions that will avoid null
pointer checks.

MFC to be done by archie ;-)

PR:		42100
Reviewed by:	archie, robert
MFC after:	3 days
2002-08-29 23:06:07 +00:00
Archie Cobbs
afa4625307 Make the libc_r version of select() set the readable or writable
file descriptor bit if poll() returns POLLERR, POLLHUP, or POLLNVAL.
Othewise, it's possible for select() to return successfully but
with no bits set.

Reviewed by:	deischen
MFC after:	3 days
PR:		bin/42175
2002-08-29 21:39:19 +00:00
Archie Cobbs
ccde72a411 When poll(2)'ing for readability or writability of a file descriptor
on behalf of a thread, we should check the POLLERR, POLLHUP, and
POLLNVAL flags as well to wake up the thread in these cases.

Suggested by:	deischen
MFC after:	3 days
2002-08-29 00:44:11 +00:00
Philippe Charnier
7fed38d0a0 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:10:45 +00:00
Peter Wemm
7657553c76 Add an ia64 atomic lock primitive for libc_r. This is mostly for
completeness and doesn't get us a working libc_r there because libc_r
uses setjmp() and setjmp() cannot be used for context switches on ia64
as-is (or sparc64).  Rather than making setjmp/longjmp behave like
the *context() calls, it would be far better to make libc_r use *context()
directly which is what they are for.

Obtained from:  marcel
2002-07-20 19:22:10 +00:00
Maxim Konovalov
25a6539985 Fix a typo.
MFC after:	3 days
2002-07-10 09:06:42 +00:00
Daniel Eischen
582dfa2dd4 Oops, forgot to set the suspended flag for threads that are created
initially suspended.  This was preventing such threads from getting
resumed.

Reported by:	Bill Huey <billh@gnuppy.monkey.org>
2002-07-09 13:24:52 +00:00
Daniel Eischen
c3d580c9a1 Fix a couple of minor nits that prevented this from compiling.
Pointed out by:	julian
2002-07-02 01:26:16 +00:00
Daniel Eischen
88127f1a62 Make sigpending and sigsuspend account for signals that are pending on
the process as well as pending on the current thread.

Reported by:	Andrew MacIntyre <andymac@bullseye.apana.org.au>
2002-06-28 13:28:41 +00:00
Daniel Eischen
b4e1c937c7 Add a wrapper for pselect() in order to make it a cancellation point.
Prompted by: wollman
2002-06-28 13:26:02 +00:00
Robert Drehmel
4b571b192a Fix a bug which prevented the duplication of the standard i/o
file descriptors in programs linked with libc_r with flags
other than the default ones.  This kept, inter alia, freopen()
from working correctly when reopening standard streams.

reviewed by:	deischen
PR:		misc/39377
2002-06-23 20:41:30 +00:00
Robert Watson
4a85ccbe6d Missed in earlier commit -- I did cvs commit src/lib/libc. Oops. 2002-06-14 04:02:25 +00:00
Daniel Eischen
5eb8d1f0b0 Revamp suspend and resume. While I'm here add pthread_suspend_all_np()
and pthread_resume_all_np().  These suspend and resume all threads except
the current thread, respectively.  The existing functions pthread_single_np()
and pthread_multi_np(), which formerly had no effect, now exhibit the same
behaviour and pthread_suspend_all_np() and pthread_resume_all_np().  These
functions have been added mostly for the native java port.

Don't allow the uthread kernel pipe to use the same descriptors as
stdio.  Mostily submitted by Oswald Buddenhagen <ossi@kde.org>.

Correct some minor style nits.
2002-05-24 04:32:28 +00:00
Alfred Perlstein
2b75bbdb31 Undo namespace pollution by prefixing the globals pthread_guard_default and
pthread_page_size.

Fix a bunch line wrapping.

Pointed out by: deischen
2002-05-15 05:37:48 +00:00
Alfred Perlstein
efe5270b1e Don't use PAGE_SIZE in userland, instead use getpagesize(), this is to
allow running on other arches when the instructions are supported but
the page size granularity is not.

Glanced at by: peter
2002-05-13 07:58:15 +00:00
Alfred Perlstein
e5ba687a2c Use GCC's __attribute__ ((constructor)) mechanism to invoke the pthread
startup code rather than a static C++ object since c++ seems to be broken.

This doesn't seem to work for staticically linked program just yet, I'll
give that some more work when I get a chance.
2002-05-11 08:13:42 +00:00
Archie Cobbs
663fc9cc7c Make these functions cancellation points like they should be:
poll(2), readv(2), select(2), wait4(2), writev(2).

PR:		bin/37658
Reviewed by:	deischen
MFC after:	1 week
2002-05-02 19:58:43 +00:00
Archie Cobbs
ca0989d865 Make sure calls to pthread_cancel() do not take effect if the target
thread is already exiting.

PR:		bin/37614
Reviewed by:	deischen
MFC after:	1 week
2002-05-02 19:57:59 +00:00
Dag-Erling Smørgrav
d397408818 Usage style sweep: spell "usage" with a small 'u'.
Also change one case of blatant __progname abuse (several more remain)
This commit does not touch anything in src/{contrib,crypto,gnu}/.
2002-04-22 13:44:47 +00:00
David E. O'Brien
07a7a2eba8 The GCC developers have made good on their threats against #pragma for 3.1.
Use __weak_reference in place of the #pragma.

Submitted by:	eischen
2002-04-15 23:11:38 +00:00
David E. O'Brien
cb81cd7952 Sync SCM ID comments with libc. 2002-04-15 20:22:28 +00:00
Jeroen Ruigrok van der Werven
92d2baa6a2 Return correct number of total bits set in all fd_set's.
Change case of POLLNVAL as an error.
Remove POLLHUP and POLLERR from one case, their place is most likely
amongst read events.

PR:		33723
Submitted by:	Alexander Litvin <archer@whichever.org>
Reviewed by:	deischen [Provided a small change to the PR patch as well]
MFC after:	4 weeks
2002-04-09 05:41:00 +00:00
Mark Murray
4cd0119367 Do not use __progname directly (except in [gs]etprogname(3)).
Also, make an internal _getprogname() that is used only inside
libc. For libc, getprogname(3) is a weak symbol in case a
function of the same name is defined in userland.
2002-03-29 22:43:43 +00:00
Daniel Eischen
3003bdb598 Add the ability to recognize old references to keys, and return NULL
when old keys are referenced (after pthread_key_delete()) via
pthread_getspecific().
2002-03-19 22:58:56 +00:00
Brian S. Dean
b18ae9245d Fix the return code from pthread_rwlock_try[rw|rd]lock() functions;
these should return EBUSY when the calling thread would block.

MFC after: 2 weeks
2002-03-15 18:27:58 +00:00
Daniel Eischen
ca4b2c1a79 Properly clear the status of a join operation if the joining thread is
canceled or the joinee is detached.
2002-03-06 19:28:41 +00:00
John Birrell
9db56888ee Fix a bug where a short write to a non-blocking socket would
leave the descriptor locked, causing other threads to hang
if they happened to access the socket.

MFC after:	5 days
2002-02-22 04:26:54 +00:00
Daniel Eischen
9e9c4443f6 Don't rely on <sys/signal.h> to include <sys/ucontext.h> 2002-02-17 17:21:27 +00:00
Maxim Konovalov
b85282ba08 Prevent dup2(2) from closing internal libc_r pipe descriptors.
PR:		misc/28947
Reviewed by:	jasone, ru
Approved by:	jasone, ru
MFC after:	1 week
2002-02-14 15:26:59 +00:00
Maxim Konovalov
0878d2e5e9 Correct a typo pthread_attr_setscope() function fails unconditionally
due to.

PR:		misc/30699
Reviewed by:	jasone, ru
Approved by:	jasone, ru
MFC after:	1 week
2002-02-14 15:20:36 +00:00
Daniel Eischen
69c287d288 This has been sitting in my local tree long enough. Remove the use
of an alternate signal stack for handling signals.  Let the kernel
send signals on the stack of the current thread and teach the threads
signal handler how to deliver signals to the current thread if it
needs to.  Also, always store a threads context as a jmp_buf.  Eventually
this will change to be a ucontext_t or mcontext_t.

Other small nits.  Use struct pthread * instead of pthread_t in internal
library routines.  The threads code wants struct pthread *, and pthread_t
doesn't necessarily have to be the same.

Reviewed by:	jasone
2002-02-09 19:58:41 +00:00
Daniel Eischen
b68bb42b5c Silence a warning by initializing the return value. This wasn't
set in the case of a short write, and I think returning 0 for this
is what was intended.
2002-02-09 19:48:55 +00:00
David Greenman
2e4bf827e5 Undo the work-around for the sendfile bug where nbytes needed the hdr/trl
size added to it in order for it to work properly when nbytes != 0.

Reviewed by:	alfred
MFC after:	3 days
2002-01-22 23:35:09 +00:00