Commit Graph

429 Commits

Author SHA1 Message Date
David Xu
39454d368f Decrease reference count if we won't use the thread, this avoids memory
leak under some cases.
2004-10-21 03:42:24 +00:00
David Xu
42c7735ce5 if system scope thread didn't set timeout, don't call clock_gettime syscall
before and after sleeping.

Reviewed by: deischen
2004-10-08 22:57:30 +00:00
David Xu
2dad2d6bfc Use PTHREAD_SCOPE_SYSTEM to decide what should be done. 2004-10-07 14:23:15 +00:00
David Xu
e897f51327 Follow kernel change, restore signal mask correctly by using a command
of kse_thr_interrupt.
2004-10-07 13:52:18 +00:00
David Xu
de97eeddd3 Allocate red zone and stack space together and then split red zone from
allocated space, orignal code left red zone unallocated, but those space
can be allocated by user code, and result was providing no protection.
2004-10-06 08:11:07 +00:00
Daniel Eischen
862e463a75 Add a wrapper for execve(). The exec'd process must be started with
the signal mask and pending signals of the calling thread.  These
are stored in userland in libpthread.

There is a small race condition in this patch which could cause
problems if a signal arrives after setting the (kernel) signal
mask and before exec'ing.  The thread's set of pending signals
also are not yet installed in the exec'd process.  Both of these
will be corrected with the addition of a special syscall.

Reported & Tested by:	Joost Bekkers <joost at jodocus dot org>
Reviewed by:	julian, davidxu
2004-09-26 06:50:15 +00:00
Suleiman Souhlal
eea4bca56b Make sure we don't call _thr_start_sig_daemon() when SYSTEM_SCOPE_ONLY is defined. This makes libpthread usable on powerpc.
Approved by:	grehan (mentor), deischen
2004-09-24 06:36:31 +00:00
David Xu
0dabb2c8a0 Pull debug symbols in for statically linked binary.
Reviewed by: desichen
2004-08-21 11:49:19 +00:00
David Xu
a002d437ea 1. Add macro DTV_OFFSET to calculate dtv offset in tcb.
2. Export symbols needed by debugger.
2004-08-16 03:27:29 +00:00
David Xu
497c17e0ae Add a file to collection all symbols will be needed by debugger. 2004-08-16 03:25:07 +00:00
Doug Rabson
99c8d0836d Add TLS support for i386 and amd64. 2004-08-15 16:28:05 +00:00
Daniel Eischen
b9de27c005 As long as we have a knob to force system scope threads, why not have
a knob to force process scope threads.  If the environment variable
LIBPTHREAD_PROCESS_SCOPE is set, force all threads to be process
scope threads regardless of how the application creates them.  If
LIBPTHREAD_SYSTEM_SCOPE is set (forcing system scope threads), it
overrides LIBPTHREAD_PROCESS_SCOPE.

        $ # To force system scope threads
        $ LIBPTHREAD_SYSTEM_SCOPE=anything threaded_app
        $ # To force process scope threads
        $ LIBPTHREAD_PROCESS_SCOPE=anything threaded_app
2004-08-12 12:12:12 +00:00
David Xu
78f687539a Check debugger suspending flag for system scope thread.
Reviewed by: deischen
2004-08-08 22:42:11 +00:00
Daniel Eischen
00be1d3d12 Add a way to force 1:1 mode for libpthread. To do this, define
LIBPTHREAD_SYSTEM_SCOPE in the environment.

You can still force libpthread to be built in strictly 1:1 by
adding -DSYSTEM_SCOPE_ONLY to CFLAGS.  This is kept for archs
that don't yet support M:N mode.

Requested by:   rwatson
Reviewed by:    davidxu
2004-08-07 15:15:38 +00:00
David Xu
4513fb36aa s/TMDF_DONOTRUNUSER/TMDF_SUSPEND/g
Dicussed with: deischen
2004-08-03 02:23:06 +00:00
Marcel Moolenaar
3271031518 Don't include lock.h and pthread_md.h when we're being included by
libthread_db. Both headers are included seperately.
2004-07-18 04:22:01 +00:00
David Xu
63db3fb215 Remove unused symbols. 2004-07-13 22:53:56 +00:00
David Xu
c7f5b2dbc5 Let debugger check signal, make SIGINFO works. 2004-07-13 22:52:11 +00:00
David Xu
099e4630c1 If _libkse_debug is not zero, activate thread mode. 2004-07-13 22:51:03 +00:00
David Xu
566382df0a Add code to support thread debugging.
1. Add global varible _libkse_debug, debugger uses the varible to identify
   libpthread. when the varible is written to non-zero by debugger, libpthread
   will take some special action at context switch time, it will check
   TMDF_DOTRUNUSER flags, if a thread has the flags set by debugger, it won't
   be scheduled, when a thread leaves KSE critical region, thread checks
   the flag, if it was set, the thread relinquish CPU.

2. Add pq_first_debug to select a thread allowd to run by debugger.

3. Some names prefixed with _thr are renamed to _thread prefix.

which is allowed to run by debugger.
2004-07-13 22:49:58 +00:00
David Xu
5321c2a9b0 Check pending signals, if there is signal will be unblocked by
sigsuspend, thread shouldn't wait, in old code, it may be
ignored.
When a signal handler is invoked in sigsuspend, thread gets
two different signal masks, one is in thread structure,
sigprocmask() can retrieve it, another is in ucontext
which is a third parameter of signal handler, the former is
the result of sigsuspend mask ORed with sigaction's sa_mask
and current signal, the later is the mask in thread structure
before sigsuspend is called. After signal handler is called,
the mask in ucontext should be copied into thread structure,
and becomes CURRENT signal mask, then sigsuspend returns to
user code.

Reviewed by: deischen
Tested by: Sean McNeil <sean@mcneil.com>
2004-06-12 07:40:01 +00:00
Daniel Eischen
b8bbeeda02 After forking and initializing the library to single-threaded
mode (where the forked thread is the one and only thread and
is marked as system scope), set the system scope flag before
initializing the signal mask.  This prevents trying to use
internal locks that haven't yet been initialized.

Reported by:	Dan Nelson <dnelson at allantgroup.com>
Reviewed by:	davidxu
2004-04-08 23:16:21 +00:00
David Xu
3128c7b24e Fix a POSIX conformance bug. POSIX says sigwait should return error number
in return value not in errno.
2004-03-17 02:12:19 +00:00
Bruce Evans
2dc8d58f59 Fixed a misspelling of 0 as NULL. 2004-03-14 05:27:26 +00:00
Colin Percival
d623b765cf style cleanup: Remove duplicate $FreeBSD$ tags.
These files had tags after the copyright notice,
inside the comment block (incorrect, removed),
and outside the comment block (correct).

Approved by:	rwatson (mentor)
2004-02-10 20:42:33 +00:00
Daniel Eischen
4b4d63bdfe Add cancellation point to sem_wait() and sem_timedwait() for pshared
semaphores.  Also add cancellation cleanup handlers to keep semaphores
in a consistent state.

Submitted in part by:	davidxu
Reviewed by:		davidxu
2004-02-06 15:20:56 +00:00
Daniel Eischen
6bf50f98b1 Provide a userland version of non-pshared semaphores and add cancellation
points to sem_wait() and sem_timedwait().  Also make sem_post signal-safe.
2004-02-03 05:50:07 +00:00
David Xu
e4dcaa6ee9 Return EPERM if mutex owner is not current thread but it tries to
unlock the mutex, old code confuses some programs when it returns EINVAL.

Noticed by: bland
2004-01-17 03:09:57 +00:00
Daniel Eischen
24f33bca1c Add a simple work-around for deadlocking on recursive read locks
on a rwlock while there are writers waiting.  We normally favor
writers but when a reader already has at least one other read lock,
we favor the reader.  We don't track all the rwlocks owned by a
thread, nor all the threads that own a rwlock -- we just keep
a count of all the read locks owned by a thread.

PR:	24641
2004-01-08 15:37:09 +00:00
David Xu
7a29c72c07 Kernel now supports per-thread sigaltstack, follow the change to
enable sigaltstack for scope system thread.
2004-01-03 02:40:27 +00:00
David Xu
ac4476923c Return error code in errno, not in return value. 2004-01-02 00:38:42 +00:00
David Xu
f909113819 Fix a typo. 2004-01-02 00:27:30 +00:00
David Xu
4560f4f0b1 Forgot to commit this file for last commit. :( 2003-12-29 23:33:51 +00:00
David Xu
02eead1d0a Implement sigaltstack() as per-threaded. Current only scope process thread
is supported, for scope system process, kernel signal bits need to be
changed.

Reviewed by: deischen
Tested on  : i386 amd64 ia64
2003-12-29 23:21:09 +00:00
David Xu
fff5bd9ed9 Correctly retrieve sigaction flags. 2003-12-28 12:20:04 +00:00
David Xu
c7148de1a6 Replace a comment with more accurated one, memory heap is now protected by
new fork() wrapper.
2003-12-19 13:24:54 +00:00
David Xu
22df7d650a Code clean up, remove unused MACROS and function prototypes. 2003-12-19 12:57:08 +00:00
Daniel Eischen
6ed6ccb310 accept() returns a file descriptor when it succeeds which is very
likely to be non-zero.  When leaving the cancellation point, check
the return value against -1 to see if cancellation should be
checked.  While I'm here, make the same change to connect() just
to be consisitent.

Pointed out by: davidxu
2003-12-09 23:40:27 +00:00
Daniel Eischen
fcebdd871d Remove an unused struct definition. 2003-12-09 15:18:40 +00:00
Daniel Eischen
cf25ae6974 Add cancellation points for accept() and connect(). 2003-12-09 15:16:27 +00:00
David Xu
cdbc3e83fa Use mutex instead of low level thread lock to implement spinlock, this
avoids signal to be blocked when otherwise it can be handled.
2003-12-09 02:37:40 +00:00
David Xu
71679e629d Rename _thr_enter_cancellation_point to _thr_cancel_enter, rename
_thr_leave_cancellation_point to _thr_cancel_leave, add a parameter
to _thr_cancel_leave to indicate whether cancellation point should be
checked, this gives us an option to not check cancallation point if
a syscall successfully returns to avoid any leaks, current I have
creat(), open() and fcntl(F_DUPFD) to not check cancellation point
after they sucessfully returned.

Replace some members in structure kse with bit flags to same some
memory.

Conditionally compile THR_ASSERT to nothing if _PTHREAD_INVARIANTS is
not defined.

Inline some small functions in thr_cancel.c.

Use __predict_false in thr_kern.c for some executed only once code.

Reviewd by: deischen
2003-12-09 02:20:56 +00:00
David Xu
d5c854e890 More reliably check timeout for pthread_mutex_timedlock. 2003-12-09 00:52:28 +00:00
Daniel Eischen
80fecc4d18 Go back to using rev 1.18 where thread locks are used instead of KSE
locks for [libc] spinlock implementation.  This was previously backed
out because it exposed a bug in ia64 implementation.

OK'd by:	marcel
2003-12-08 13:33:20 +00:00
David Xu
170422c2ef 1.Macro optimizing KSE_LOCK_ACQUIRE and THR_LOCK_ACQUIRE to use static fall
through branch predict as suggested in INTEL IA32 optimization guide.

2.Allocate siginfo arrary separately to avoid pthread to be allocated at
2K boundary, which hits L1 address alias problem and causes context
switch to be slow down.

3.Simplify context switch code by removing redundant code, code size is
reduced, so it is expected to run faster.

Reviewed by: deischen
Approved by: re (scottl)
2003-11-29 14:22:29 +00:00
David Xu
5a8fe60d7e Remove surplus mmap() call for stack guard page in init_private, it is done
in init_main_thread. Also don't initialize lock and lockuser again for initial
thread, it is already done by _thr_alloc().

Reviewed by: deischen
Approved by: re (scottl)
2003-11-29 14:10:02 +00:00
Daniel Eischen
5303e94607 Back out last change and go back to using KSE locks instead of thread
locks until we know why this breaks ia64.

Reported by:	marcel
2003-11-16 15:01:26 +00:00
David Xu
0e17930dd7 If a thread in critical region got a synchronous signal, according current
signal handling mode, there is no chance to handle the signal, something
must be wrong in the library, just call kse_thr_interrupt to dump its core.
I have the code for a long time, but forgot to commit it.
2003-11-09 00:37:14 +00:00
David Xu
38a53c6206 Use THR lock instead of KSE lock to avoid scheduler be blocked in spinlock.
Reviewed by: deischen
2003-11-08 06:07:04 +00:00
Daniel Eischen
7a1192c1d3 style(9)
Reviewed by:	bde
2003-11-05 18:19:24 +00:00