Remove libc_r threading library. It has been disconnected from the build

for four years (since r162846).

Submitted by: Alexander Best arundel@
This commit is contained in:
Ed Maste 2010-11-13 22:22:18 +00:00
parent d79326ecc8
commit 13ec45d644
167 changed files with 0 additions and 23451 deletions

View File

@ -1,31 +0,0 @@
# $FreeBSD$
#
# All library objects contain FreeBSD revision strings by default; they may be
# excluded as a space-saving measure. To produce a library that does
# not contain these strings, add -DSTRIP_FBSDID (see <sys/cdefs.h>) to CFLAGS
# below. Note, there are no IDs for syscall stubs whose sources are generated.
# To included legacy CSRG sccsid strings, add -DLIBC_SCCS and -DSYSLIBC_SCCS
# (for system call stubs) to CFLAGS below. -DSYSLIBC_SCCS affects just the
# system call stubs.
.include <bsd.own.mk>
LIB=c_r
SHLIB_MAJOR= 7
CFLAGS+=-DPTHREAD_KERNEL
CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/uthread \
-I${.CURDIR}/../../include
# Uncomment this if you want libc_r to contain debug information for
# thread locking.
CFLAGS+=-D_LOCK_DEBUG
# enable extra internal consistancy checks
CFLAGS+=-D_PTHREADS_INVARIANTS
PRECIOUSLIB=
.include "${.CURDIR}/uthread/Makefile.inc"
.include "${.CURDIR}/sys/Makefile.inc"
.include <bsd.lib.mk>

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
* copyright Douglas Santry 1996
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the above copyright is retained
* in the source form.
*
* THIS SOFTWARE IS PROVIDED BY Douglas Santry AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Douglas Santry OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_RCS) && !defined(lint)
.text
.asciz "$FreeBSD$"
#endif /* LIBC_RCS and not lint */
#include <machine/asm.h>
/*
* Atomicly lock a location with an identifier provided the location
* is not currently locked.
*
* long _atomic_lock(long *);
* eax will contain the return value (zero if lock obtained).
*/
ENTRY(_atomic_lock)
movl $1, %eax
xchgq %rax, (%rdi)
ret
END(_atomic_lock)

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
* copyright Douglas Santry 1996
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the above copyright is retained
* in the source form.
*
* THIS SOFTWARE IS PROVIDED BY Douglas Santry AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Douglas Santry OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_RCS) && !defined(lint)
.text
.asciz "$FreeBSD$"
#endif /* LIBC_RCS and not lint */
#include <machine/asm.h>
/*
* Atomicly lock a location with an identifier provided the location
* is not currently locked.
*
* long _atomic_lock(long *);
* eax will contain the return value (zero if lock obtained).
*/
ENTRY(_atomic_lock)
movl 4(%esp), %ecx
movl $1, %eax
xchg %eax, (%ecx)
ret
END(_atomic_lock)

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2002 Marcel Moolenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(LIBC_RCS) && !defined(lint)
.text
.asciz "$FreeBSD$"
#endif /* LIBC_RCS and not lint */
#include <machine/asm.h>
/*
* Atomicly lock a location with an identifier provided the location
* is not currently locked.
*
* long _atomic_lock(long *);
*/
ENTRY(_atomic_lock, 1)
mov ar.ccv = r0
add r14 = 1, r0
nop 0
;;
cmpxchg8.acq r8 = [r32], r14, ar.ccv
br.ret.sptk rp
END(_atomic_lock)

View File

@ -1,45 +0,0 @@
/*-
* Copyright (c) 2002 Dag-Erling Coïdan Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
/*
* long _atomic_lock(long *)
*
* Atomically acquire a lock by storing a non-zero value in its
* location, provided it is not already locked. Note that we only use
* the first byte of the location provided.
*/
ENTRY(_atomic_lock)
ldstub [%o0], %o1
membar #LoadLoad | #StoreStore
retl
mov %o1, %o0
END(_atomic_lock)

View File

@ -1,6 +0,0 @@
# $FreeBSD$
.PATH: ${.CURDIR}/sys ${.CURDIR}/arch/${MACHINE_CPUARCH}
SRCS+= uthread_error.c _atomic_lock.S

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* Copyright (c) 1994 by Chris Provenzano, proven@mit.edu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by John Birrell
* and Chris Provenzano.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <pthread.h>
#include "pthread_private.h"
extern int errno;
int * __error()
{
int *p_errno;
if (_thread_run == _thread_initial) {
p_errno = &errno;
} else {
p_errno = &_thread_run->error;
}
return(p_errno);
}

View File

@ -1,115 +0,0 @@
#
# $FreeBSD$
#
# Automated test suite for libc_r (pthreads).
#
# File lists.
# Tests written in C.
CTESTS := hello_d.c hello_s.c join_leak_d.c mutex_d.c sem_d.c sigsuspend_d.c \
sigwait_d.c
# C programs that are used internally by the tests. The build system merely
# compiles these.
BTESTS := guard_b.c hello_b.c
# Tests written in perl.
PTESTS := guard_s.pl propagate_s.pl
# Munge the file lists to their final executable names (strip the .c).
CTESTS := $(CTESTS:R)
BTESTS := $(BTESTS:R)
CPPFLAGS := -D_LIBC_R_ -D_REENTRANT
CFLAGS := -Wall -pipe -g3
LDFLAGS_A := -static
LDFLAGS_P := -pg
LDFLAGS_S :=
LIBS := -lc_r
# Flags passed to verify. "-v" or "-u" may be useful.
VFLAGS :=
all : default
# Only use the following suffixes, in order to avoid any strange built-in rules.
.SUFFIXES :
.SUFFIXES : .c .o .d .pl
# Clear out all paths, then set just one (default path) for the main build
# directory.
.PATH :
.PATH : .
# Build the C programs.
.for bin in $(CTESTS) $(BTESTS)
$(bin)_a : $(bin:S/$/&.c/)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
$(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_A) $(LIBS)
@$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_a.o \2/g\" > $(@:R:S/$/&.d/)"
$(bin)_p : $(bin:S/$/&.c/)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
$(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_P) $(LIBS)
@$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_p.o \2/g\" > $(@:R:S/$/&.d/)"
$(bin)_s : $(bin:S/$/&.c/)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(bin:S/$/&.c/) -o $(@:S/$/&.o/)
$(CC) -o $@ $(@:S/$/&.o/) $(LDFLAGS_S) $(LIBS)
@$(SHELL) -ec "$(CC) -M $(CPPFLAGS) $(bin:S/$/&.c/) | sed \"s/\($(bin:T)\)\.o\([ :]*\)/$(bin:H:S!/!\\/!g)\/\1_s.o \2/g\" > $(@:R:S/$/&.d/)"
.endfor
# Dependency file inclusion.
.for depfile in $(CTESTS:R:S/$/&_a.d/) $(BTESTS:R:S/$/&_a.d/) \
$(CTESTS:R:S/$/&_p.d/) $(BTESTS:R:S/$/&_p.d/) \
$(CTESTS:R:S/$/&_s.d/) $(BTESTS:R:S/$/&_s.d/)
.if exists($(depfile))
.include "$(depfile)"
.endif
.endfor
default : check
tests_a : $(CTESTS:S/$/&_a/) $(BTESTS:S/$/&_a/)
tests_p : $(CTESTS:S/$/&_p/) $(BTESTS:S/$/&_p/)
tests_s : $(CTESTS:S/$/&_s/) $(BTESTS:S/$/&_s/)
tests : tests_a tests_p tests_s
check_a : tests_a
.for bin in $(CTESTS) $(BTESTS)
@cp $(bin)_a $(bin)
.endfor
@echo "Test static library:"
@./verify $(VFLAGS) $(CTESTS) $(PTESTS)
check_p : tests_p
.for bin in $(CTESTS) $(BTESTS)
@cp $(bin)_p $(bin)
.endfor
@echo "Test profile library:"
@./verify $(VFLAGS) $(CTESTS) $(PTESTS)
check_s : tests_s
.for bin in $(CTESTS) $(BTESTS)
@cp $(bin)_s $(bin)
.endfor
@echo "Test shared library:"
@./verify $(VFLAGS) $(CTESTS) $(PTESTS)
check : check_a check_p check_s
clean :
rm -f *~
rm -f *.core
rm -f *.out
rm -f *.perf
rm -f *.diff
rm -f *.gmon
rm -f $(CTESTS) $(BTESTS)
rm -f $(CTESTS:S/$/&_a/) $(BTESTS:S/$/&_a/)
rm -f $(CTESTS:S/$/&_p/) $(BTESTS:S/$/&_p/)
rm -f $(CTESTS:S/$/&_s/) $(BTESTS:S/$/&_s/)
rm -f *.d
rm -f *.o

View File

@ -1,28 +0,0 @@
$FreeBSD$
This test suite is meant to test general functionality of pthreads, as well as
provide a simple framework for regression tests. In general, this test suite
can be used with any pthreads library, but in reality there are a number of
libc_r-specific aspects to this test suite which would require some effort to
get around if testing another pthreads library.
This test suite assumes that libc_r is installed.
There are two forms of test that the 'verify' script understands. The simpler
form is the diff format, where the output of the test program is diff'ed with
the correspondingly named .exp file. If there is diff output, the test fails.
The sequence test format is somewhat more complex, and is documented in the
command line usage output for verify. The advantage of this format is that it
allows multiple tests to pass/fail within one program.
There is no driving need for test naming consistency, but the existing tests
generally follow these conventions:
<name>_d.c <name>_d.exp : Diff mode C test and expected output file.
<name>_s.c : Sequence mode C test.
<name>_b*.c : Back end C program used by perl tests.
<name>_d.pl <name>_d.pl.exp : Diff mode perl test and expected output file.
<name>_s.pl : Sequence mode perl test.
<name> is something descriptive, such as "pr14685" in the case of a PR-related
regression test, or "mutex" in the case of a test of mutexes.

View File

@ -1,151 +0,0 @@
/*
* Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer
* unmodified other than the allowable addition of one or more
* copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*
* Test thread stack guard functionality.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#define FRAME_SIZE 1024
#define FRAME_OVERHEAD 40
struct args
{
void *top; /* Top of thread's initial stack frame. */
int cur; /* Recursion depth. */
int max; /* Maximum recursion depth. */
};
void *
recurse(void *args)
{
int top;
struct args *parms = (struct args *)args;
char filler[FRAME_SIZE - FRAME_OVERHEAD];
/* Touch the memory in this stack frame. */
top = 0xa5;
memset(filler, 0xa5, sizeof(filler));
if (parms->top == NULL) {
/* Initial stack frame. */
parms->top = (void*)&top;
}
/*
* Make sure frame size is what we expect. Getting this right involves
* hand tweaking, so just print a warning rather than aborting.
*/
if (parms->top - (void *)&top != FRAME_SIZE * parms->cur) {
fprintf(stderr, "Stack size (%d) != expected (%d), frame %d\n",
(int)(parms->top - (void *)&top), FRAME_SIZE * parms->cur,
parms->cur);
}
parms->cur++;
if (parms->cur < parms->max)
recurse(args);
return NULL;
}
int
main(int argc, char **argv)
{
size_t def_stacksize, def_guardsize;
size_t stacksize, guardsize;
pthread_t thread;
pthread_attr_t attr;
struct args args;
if (argc != 3) {
fprintf(stderr, "usage: guard_b <stacksize> <guardsize>\n");
exit(1);
}
fprintf(stderr, "Test begin\n");
stacksize = strtoul(argv[1], NULL, 10);
guardsize = strtoul(argv[2], NULL, 10);
assert(pthread_attr_init(&attr) == 0);
/*
* Exercise the attribute APIs more thoroughly than is strictly
* necessary for the meat of this test program.
*/
assert(pthread_attr_getstacksize(&attr, &def_stacksize) == 0);
assert(pthread_attr_getguardsize(&attr, &def_guardsize) == 0);
if (def_stacksize != stacksize) {
assert(pthread_attr_setstacksize(&attr, stacksize) == 0);
assert(pthread_attr_getstacksize(&attr, &def_stacksize) == 0);
assert(def_stacksize == stacksize);
}
if (def_guardsize != guardsize) {
assert(pthread_attr_setguardsize(&attr, guardsize) == 0);
assert(pthread_attr_getguardsize(&attr, &def_guardsize) == 0);
assert(def_guardsize >= guardsize);
}
/*
* Create a thread that will come just short of overflowing the thread
* stack. We need to leave a bit of breathing room in case the thread
* is context switched, and we also have to take care not to call any
* functions in the deepest stack frame.
*/
args.top = NULL;
args.cur = 0;
args.max = (stacksize / FRAME_SIZE) - 1;
fprintf(stderr, "No overflow:\n");
assert(pthread_create(&thread, &attr, recurse, &args) == 0);
assert(pthread_join(thread, NULL) == 0);
/*
* Create a thread that will barely of overflow the thread stack. This
* should cause a segfault.
*/
args.top = NULL;
args.cur = 0;
args.max = (stacksize / FRAME_SIZE) + 1;
fprintf(stderr, "Overflow:\n");
assert(pthread_create(&thread, &attr, recurse, &args) == 0);
assert(pthread_join(thread, NULL) == 0);
/* Not reached. */
fprintf(stderr, "Unexpected success\n");
abort();
return 0;
}

View File

@ -1,3 +0,0 @@
Test begin
No overflow:
Overflow:

View File

@ -1,69 +0,0 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice(s), this list of conditions and the following disclaimer
# unmodified other than the allowable addition of one or more
# copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
# notice(s), this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $FreeBSD$
#
# Test thread stack guard functionality. The C test program needs to be driven
# by this script because it segfaults when the stack guard is hit.
#
print "1..30\n";
$i = 0;
# Iterates 10 times.
for ($stacksize = 65536; $stacksize < 131072; $stacksize += 7168)
{
# Iterates 3 times (1024, 4096, 7168).
for ($guardsize = 1024; $guardsize < 8192; $guardsize += 3072)
{
$i++;
print "stacksize: $stacksize, guardsize: $guardsize\n";
`./guard_b $stacksize $guardsize >guard_b.out 2>&1`;
if (! -f "./guard_b.out")
{
print "not ok $i\n";
}
else
{
`diff guard_b.exp guard_b.out >guard_b.diff 2>&1`;
if ($?)
{
# diff returns non-zero if there is a difference.
print "not ok $i\n";
}
else
{
print "ok $i\n";
}
}
}
}

View File

@ -1,13 +0,0 @@
/****************************************************************************
*
* Back end C programs can be anything compilable.
*
* $FreeBSD$
*
****************************************************************************/
int
main()
{
return 0;
}

View File

@ -1,38 +0,0 @@
/****************************************************************************
*
* Simple diff mode test.
*
* $FreeBSD$
*
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <pthread.h>
void *
entry(void * a_arg)
{
fprintf(stderr, "Hello world\n");
return NULL;
}
int
main()
{
pthread_t thread;
int error;
error = pthread_create(&thread, NULL, entry, NULL);
if (error)
fprintf(stderr, "Error in pthread_create(): %s\n",
strerror(error));
error = pthread_join(thread, NULL);
if (error)
fprintf(stderr, "Error in pthread_join(): %s\n",
strerror(error));
return 0;
}

View File

@ -1 +0,0 @@
Hello world

View File

@ -1,47 +0,0 @@
/****************************************************************************
*
* Simple sequence mode test.
*
* $FreeBSD$
*
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <pthread.h>
void *
entry(void * a_arg)
{
fprintf(stderr, "ok 1\n");
fprintf(stderr, "ok \n");
fprintf(stderr, "ok 3\n");
return NULL;
}
int
main()
{
pthread_t thread;
int error;
fprintf(stderr, "1..3\n");
fprintf(stderr, "Some random text\n");
error = pthread_create(&thread, NULL, entry, NULL);
fprintf(stderr, "More unimportant text\n");
if (error)
fprintf(stderr,"Error in pthread_create(): %s\n",
strerror(error));
error = pthread_join(thread, NULL);
if (error)
fprintf(stderr, "Error in pthread_join(): %s\n",
strerror(error));
fprintf(stderr, "Hello world\n");
return 0;
}

View File

@ -1,112 +0,0 @@
/*
* Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer as
* the first lines of this file unmodified other than the possible
* addition of one or more copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*
* Test for leaked joined threads.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
#define NITERATIONS 16384
#define MAXGROWTH 16384
void *
thread_entry(void *a_arg)
{
return NULL;
}
int
main(void)
{
pthread_t thread;
int i, error;
char *brk, *nbrk;
unsigned growth;
fprintf(stderr, "Test begin\n");
/* Get an initial brk value. */
brk = sbrk(0);
/* Create threads and join them, one at a time. */
for (i = 0; i < NITERATIONS; i++) {
if ((error = pthread_create(&thread, NULL, thread_entry, NULL))
!= 0) {
if (error == EAGAIN) {
i--;
continue;
}
fprintf(stderr, "Error in pthread_create(): %s\n",
strerror(error));
exit(1);
}
if ((error = pthread_join(thread, NULL)) != 0) {
fprintf(stderr, "Error in pthread_join(): %s\n",
strerror(error));
exit(1);
}
}
/* Get a final brk value. */
nbrk = sbrk(0);
/*
* Check that the amount of heap space allocated is below an acceptable
* threshold. We could just compare brk and nbrk, but the test could
* conceivably break if the internals of the threads library changes.
*/
if (nbrk > brk) {
/* Heap grows up. */
growth = nbrk - brk;
} else if (nbrk <= brk) {
/* Heap grows down, or no growth. */
growth = brk - nbrk;
}
if (growth > MAXGROWTH) {
fprintf(stderr, "Heap growth exceeded maximum (%u > %u)\n",
growth, MAXGROWTH);
}
#if (0)
else {
fprintf(stderr, "Heap growth acceptable (%u <= %u)\n",
growth, MAXGROWTH);
}
#endif
fprintf(stderr, "Test end\n");
return 0;
}

View File

@ -1,2 +0,0 @@
Test begin
Test end

File diff suppressed because it is too large Load Diff

View File

@ -1,290 +0,0 @@
Testing pthread_mutex_init
--------------------------
Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified) - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified) - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified) - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE - PASS
Testing pthread_mutex_destroy
-----------------------------
Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Destruction of unused mutex - PASS
Destruction of mutex locked by self - PASS
Destruction of mutex locked by another thread - PASS
Destruction of mutex while being used in cond_wait - PASS
Testing pthread_mutex_lock
--------------------------
Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Lock on unlocked mutex - PASS
Lock on invalid mutex - PASS
Lock on mutex held by self - PASS
Testing pthread_mutex_unlock
----------------------------
Protocol PTHREAD_PRIO_NONE, Type POSIX (type not specified)
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_DEFAULT
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_NORMAL
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_NONE, Type SS2 PTHREAD_MUTEX_RECURSIVE
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Protocol PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Unlock on mutex held by self - PASS
Unlock on invalid mutex - PASS
Unlock on mutex locked by another thread - PASS
Testing queueing order
----------------------
Queueing order on a mutex - PASS
Queueing order on a condition variable - PASS
Testing priority inheritence
----------------------------
Protype PTHREAD_PRIO_INHERIT, Type POSIX (type not specified)
Simple inheritence test - PASS
Inheritence test with change of priority - PASS
Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_DEFAULT
Simple inheritence test - PASS
Inheritence test with change of priority - PASS
Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Simple inheritence test - PASS
Inheritence test with change of priority - PASS
Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_NORMAL
Simple inheritence test - PASS
Inheritence test with change of priority - PASS
Protype PTHREAD_PRIO_INHERIT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Simple inheritence test - PASS
Inheritence test with change of priority - PASS
Testing priority ceilings
-------------------------
Protype PTHREAD_PRIO_PROTECT, Type POSIX (type not specified)
Lock with ceiling priority < thread priority - PASS
Lock with ceiling priority = thread priority - PASS
Lock with ceiling priority > thread priority - PASS
Preemption with ceiling priority < thread priority - PASS
Preemption with ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_DEFAULT
Lock with ceiling priority < thread priority - PASS
Lock with ceiling priority = thread priority - PASS
Lock with ceiling priority > thread priority - PASS
Preemption with ceiling priority < thread priority - PASS
Preemption with ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_ERRORCHECK
Lock with ceiling priority < thread priority - PASS
Lock with ceiling priority = thread priority - PASS
Lock with ceiling priority > thread priority - PASS
Preemption with ceiling priority < thread priority - PASS
Preemption with ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_NORMAL
Lock with ceiling priority < thread priority - PASS
Lock with ceiling priority = thread priority - PASS
Lock with ceiling priority > thread priority - PASS
Preemption with ceiling priority < thread priority - PASS
Preemption with ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
Protype PTHREAD_PRIO_PROTECT, Type SS2 PTHREAD_MUTEX_RECURSIVE
Lock with ceiling priority < thread priority - PASS
Lock with ceiling priority = thread priority - PASS
Lock with ceiling priority > thread priority - PASS
Preemption with ceiling priority < thread priority - PASS
Preemption with ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority = thread priority - PASS
SCHED_FIFO scheduling and ceiling priority > thread priority - PASS
Total tests 212, passed 212, failed 0

View File

@ -1,74 +0,0 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice(s), this list of conditions and the following disclaimer as
# the first lines of this file unmodified other than the possible
# addition of one or more copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
# notice(s), this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###########################################################################
#
# Verify that no cancellation points are propagated inside of libc_r.
#
# $FreeBSD$
#
@CPOINTS = ("aio_suspend", "close", "creat", "fcntl", "fsync", "mq_receive",
"mq_send", "msync", "nanosleep", "open", "pause",
"pthread_cond_timedwait", "pthread_cond_wait", "pthread_join",
"pthread_testcancel", "read", "sem_wait", "sigsuspend",
"sigtimedwait", "sigwait", "sigwaitinfo", "sleep", "system",
"tcdrain", "wait", "waitpid", "write");
print "1..1\n";
$cpoints = join '\|', @CPOINTS;
$regexp = "\" U \\(" . $cpoints . "\\\)\$\"";
`nm -a /usr/lib/libc.a |grep $regexp >propagate_s.out`;
if (!open (NMOUT, "<./propagate_s.out"))
{
print "not ok 1\n";
}
else
{
$propagations = 0;
while (<NMOUT>)
{
$propagations++;
print "$_\n";
}
if ($propagations != 0)
{
print "$propagations propagation(s)\n";
print "not ok 1\n";
}
else
{
print "ok 1\n";
}
close NMOUT;
unlink "propagate_s.out";
}

View File

@ -1,133 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer as
* the first lines of this file unmodified other than the possible
* addition of one or more copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* sem test.
*
* $FreeBSD$
*
****************************************************************************/
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <semaphore.h>
#include <pthread.h>
#define NTHREADS 10
void *
entry(void * a_arg)
{
sem_t * sem = (sem_t *) a_arg;
sem_wait(sem);
fprintf(stderr, "Got semaphore\n");
return NULL;
}
int
main()
{
sem_t sem_a, sem_b;
pthread_t threads[NTHREADS];
unsigned i;
int val;
fprintf(stderr, "Test begin\n");
#ifdef _LIBC_R_
assert(-1 == sem_init(&sem_b, 1, 0));
assert(EPERM == errno);
#endif
assert(0 == sem_init(&sem_b, 0, 0));
assert(0 == sem_getvalue(&sem_b, &val));
assert(0 == val);
assert(0 == sem_post(&sem_b));
assert(0 == sem_getvalue(&sem_b, &val));
assert(1 == val);
assert(0 == sem_wait(&sem_b));
assert(-1 == sem_trywait(&sem_b));
assert(EAGAIN == errno);
assert(0 == sem_post(&sem_b));
assert(0 == sem_trywait(&sem_b));
assert(0 == sem_post(&sem_b));
assert(0 == sem_wait(&sem_b));
assert(0 == sem_post(&sem_b));
#ifdef _LIBC_R_
assert(SEM_FAILED == sem_open("/foo", O_CREAT | O_EXCL, 0644, 0));
assert(ENOSYS == errno);
assert(-1 == sem_close(&sem_b));
assert(ENOSYS == errno);
assert(-1 == sem_unlink("/foo"));
assert(ENOSYS == errno);
#endif
assert(0 == sem_destroy(&sem_b));
assert(0 == sem_init(&sem_a, 0, 0));
for (i = 0; i < NTHREADS; i++) {
pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
}
for (i = 0; i < NTHREADS; i++) {
assert(0 == sem_post(&sem_a));
}
for (i = 0; i < NTHREADS; i++) {
pthread_join(threads[i], NULL);
}
for (i = 0; i < NTHREADS; i++) {
pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
}
for (i = 0; i < NTHREADS; i++) {
assert(0 == sem_post(&sem_a));
}
for (i = 0; i < NTHREADS; i++) {
pthread_join(threads[i], NULL);
}
assert(0 == sem_destroy(&sem_a));
fprintf(stderr, "Test end\n");
return 0;
}

View File

@ -1,22 +0,0 @@
Test begin
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Got semaphore
Test end

View File

@ -1,288 +0,0 @@
/*
* Copyright (c) 1998 Daniel M. Eischen <eischen@vigrid.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel M. Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL M. EISCHEN AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#if defined(_LIBC_R_)
#include <pthread_np.h>
#endif
static int sigcounts[NSIG + 1];
static int sigfifo[NSIG + 1];
static int fifo_depth = 0;
static sigset_t suspender_mask;
static pthread_t suspender_tid;
static void *
sigsuspender (void *arg)
{
int save_count, status, i;
sigset_t run_mask;
/* Run with all signals blocked. */
sigfillset (&run_mask);
sigprocmask (SIG_SETMASK, &run_mask, NULL);
/* Allow these signals to wake us up during a sigsuspend. */
sigfillset (&suspender_mask); /* Default action */
sigdelset (&suspender_mask, SIGINT); /* terminate */
sigdelset (&suspender_mask, SIGHUP); /* terminate */
sigdelset (&suspender_mask, SIGQUIT); /* create core image */
sigdelset (&suspender_mask, SIGURG); /* ignore */
sigdelset (&suspender_mask, SIGIO); /* ignore */
sigdelset (&suspender_mask, SIGUSR2); /* terminate */
while (sigcounts[SIGINT] == 0) {
save_count = sigcounts[SIGUSR2];
status = sigsuspend (&suspender_mask);
if ((status == 0) || (errno != EINTR)) {
fprintf (stderr, "Unable to suspend for signals, "
"errno %d, return value %d\n",
errno, status);
exit (1);
}
for (i = 0; i < fifo_depth; i++)
fprintf (stderr, "Sigsuspend woke up by signal %d\n",
sigfifo[i]);
fifo_depth = 0;
}
pthread_exit (arg);
return (NULL);
}
static void
sighandler (int signo)
{
sigset_t set, suspend_set;
pthread_t self;
if ((signo >= 0) && (signo <= NSIG))
sigcounts[signo]++;
/*
* If we are running on behalf of the suspender thread,
* ensure that we have the correct mask set.
*/
self = pthread_self ();
if (self == suspender_tid) {
sigfifo[fifo_depth] = signo;
fifo_depth++;
fprintf (stderr,
" -> Suspender thread signal handler caught signal %d\n",
signo);
/* Get the current signal mask. */
sigprocmask (SIG_SETMASK, NULL, &set);
/* The handler should run with the current signal masked. */
suspend_set = suspender_mask;
sigaddset(&suspend_set, signo);
if (memcmp(&set, &suspend_set, sizeof(set)))
fprintf (stderr,
" >>> FAIL: sigsuspender signal handler running "
"with incorrect mask.\n");
}
else
fprintf (stderr,
" -> Main thread signal handler caught signal %d\n",
signo);
}
static void
send_thread_signal (pthread_t tid, int signo)
{
if (pthread_kill (tid, signo) != 0) {
fprintf (stderr, "Unable to send thread signal, errno %d.\n",
errno);
exit (1);
}
}
static void
send_process_signal (int signo)
{
if (kill (getpid (), signo) != 0) {
fprintf (stderr, "Unable to send process signal, errno %d.\n",
errno);
exit (1);
}
}
int main (int argc, char *argv[])
{
pthread_attr_t pattr;
void * exit_status;
struct sigaction act;
sigset_t oldset;
sigset_t newset;
/* Initialize our signal counts. */
memset ((void *) sigcounts, 0, NSIG * sizeof (int));
/* Ignore signal SIGIO. */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGIO);
act.sa_handler = SIG_IGN;
act.sa_flags = 0;
sigaction (SIGIO, &act, NULL);
/* Install a signal handler for SIGURG. */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGURG);
act.sa_handler = sighandler;
act.sa_flags = SA_RESTART;
sigaction (SIGURG, &act, NULL);
/* Install a signal handler for SIGXCPU */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGXCPU);
sigaction (SIGXCPU, &act, NULL);
/* Get our current signal mask. */
sigprocmask (SIG_SETMASK, NULL, &oldset);
/* Mask out SIGUSR1 and SIGUSR2. */
newset = oldset;
sigaddset (&newset, SIGUSR1);
sigaddset (&newset, SIGUSR2);
sigprocmask (SIG_SETMASK, &newset, NULL);
/* Install a signal handler for SIGUSR1 */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGUSR1);
sigaction (SIGUSR1, &act, NULL);
/* Install a signal handler for SIGUSR2 */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGUSR2);
sigaction (SIGUSR2, &act, NULL);
/*
* Initialize the thread attribute.
*/
if ((pthread_attr_init (&pattr) != 0) ||
(pthread_attr_setdetachstate (&pattr,
PTHREAD_CREATE_JOINABLE) != 0)) {
fprintf (stderr, "Unable to initialize thread attributes.\n");
exit (1);
}
/*
* Create the sigsuspender thread.
*/
if (pthread_create (&suspender_tid, &pattr, sigsuspender, NULL) != 0) {
fprintf (stderr, "Unable to create thread, errno %d.\n", errno);
exit (1);
}
#if defined(_LIBC_R)
pthread_set_name_np (suspender_tid, "sigsuspender");
#endif
/*
* Verify that an ignored signal doesn't cause a wakeup.
* We don't have a handler installed for SIGIO.
*/
send_thread_signal (suspender_tid, SIGIO);
sleep (1);
send_process_signal (SIGIO);
sleep (1);
if (sigcounts[SIGIO] != 0)
fprintf (stderr, "FAIL: sigsuspend wakes up for ignored signal "
"SIGIO.\n");
/*
* Verify that a signal with a default action of ignore, for
* which we have a signal handler installed, will release a
* sigsuspend.
*/
send_thread_signal (suspender_tid, SIGURG);
sleep (1);
send_process_signal (SIGURG);
sleep (1);
if (sigcounts[SIGURG] != 2)
fprintf (stderr,
"FAIL: sigsuspend doesn't wake up for SIGURG.\n");
/*
* Verify that a SIGUSR2 signal will release a sigsuspended
* thread.
*/
send_thread_signal (suspender_tid, SIGUSR2);
sleep (1);
send_process_signal (SIGUSR2);
sleep (1);
if (sigcounts[SIGUSR2] != 2)
fprintf (stderr,
"FAIL: sigsuspend doesn't wake up for SIGUSR2.\n");
/*
* Verify that a signal, blocked in both the main and
* sigsuspender threads, does not cause the signal handler
* to be called.
*/
send_thread_signal (suspender_tid, SIGUSR1);
sleep (1);
send_process_signal (SIGUSR1);
sleep (1);
if (sigcounts[SIGUSR1] != 0)
fprintf (stderr, "FAIL: signal hander called for SIGUSR1.\n");
/*
* Verify that we can still kill the process for a signal
* not being waited on by sigwait.
*/
send_process_signal (SIGPIPE);
fprintf (stderr, "FAIL: SIGPIPE did not terminate process.\n");
/*
* Wait for the thread to finish.
*/
pthread_join (suspender_tid, &exit_status);
return (0);
}

View File

@ -1,8 +0,0 @@
-> Suspender thread signal handler caught signal 16
Sigsuspend woke up by signal 16
-> Suspender thread signal handler caught signal 16
Sigsuspend woke up by signal 16
-> Suspender thread signal handler caught signal 31
Sigsuspend woke up by signal 31
-> Suspender thread signal handler caught signal 31
Sigsuspend woke up by signal 31

View File

@ -1,304 +0,0 @@
/*
* Copyright (c) 1998 Daniel M. Eischen <eischen@vigrid.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel M. Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL M. EISCHEN AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#if defined(_LIBC_R_)
#include <pthread_np.h>
#endif
static int sigcounts[NSIG + 1];
static sigset_t wait_mask;
static pthread_mutex_t waiter_mutex;
static void *
sigwaiter (void *arg)
{
int signo;
sigset_t mask;
/* Block SIGHUP */
sigemptyset (&mask);
sigaddset (&mask, SIGHUP);
sigprocmask (SIG_BLOCK, &mask, NULL);
while (sigcounts[SIGINT] == 0) {
if (sigwait (&wait_mask, &signo) != 0) {
fprintf (stderr,
"Unable to wait for signal, errno %d\n",
errno);
exit (1);
}
sigcounts[signo]++;
fprintf (stderr, "Sigwait caught signal %d\n", signo);
/* Allow the main thread to prevent the sigwait. */
pthread_mutex_lock (&waiter_mutex);
pthread_mutex_unlock (&waiter_mutex);
}
pthread_exit (arg);
return (NULL);
}
static void
sighandler (int signo)
{
fprintf (stderr, " -> Signal handler caught signal %d\n", signo);
if ((signo >= 0) && (signo <= NSIG))
sigcounts[signo]++;
}
static void
send_thread_signal (pthread_t tid, int signo)
{
if (pthread_kill (tid, signo) != 0) {
fprintf (stderr, "Unable to send thread signal, errno %d.\n",
errno);
exit (1);
}
}
static void
send_process_signal (int signo)
{
if (kill (getpid (), signo) != 0) {
fprintf (stderr, "Unable to send process signal, errno %d.\n",
errno);
exit (1);
}
}
int main (int argc, char *argv[])
{
pthread_mutexattr_t mattr;
pthread_attr_t pattr;
pthread_t tid;
void * exit_status;
struct sigaction act;
/* Initialize our signal counts. */
memset ((void *) sigcounts, 0, NSIG * sizeof (int));
/* Setup our wait mask. */
sigemptyset (&wait_mask); /* Default action */
sigaddset (&wait_mask, SIGHUP); /* terminate */
sigaddset (&wait_mask, SIGINT); /* terminate */
sigaddset (&wait_mask, SIGQUIT); /* create core image */
sigaddset (&wait_mask, SIGURG); /* ignore */
sigaddset (&wait_mask, SIGIO); /* ignore */
sigaddset (&wait_mask, SIGUSR1); /* terminate */
/* Ignore signals SIGHUP and SIGIO. */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGHUP);
sigaddset (&act.sa_mask, SIGIO);
act.sa_handler = SIG_IGN;
act.sa_flags = 0;
sigaction (SIGHUP, &act, NULL);
sigaction (SIGIO, &act, NULL);
/* Install a signal handler for SIGURG */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGURG);
act.sa_handler = sighandler;
act.sa_flags = SA_RESTART;
sigaction (SIGURG, &act, NULL);
/* Install a signal handler for SIGXCPU */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGXCPU);
sigaction (SIGXCPU, &act, NULL);
/*
* Initialize the thread attribute.
*/
if ((pthread_attr_init (&pattr) != 0) ||
(pthread_attr_setdetachstate (&pattr,
PTHREAD_CREATE_JOINABLE) != 0)) {
fprintf (stderr, "Unable to initialize thread attributes.\n");
exit (1);
}
/*
* Initialize and create a mutex.
*/
if ((pthread_mutexattr_init (&mattr) != 0) ||
(pthread_mutex_init (&waiter_mutex, &mattr) != 0)) {
fprintf (stderr, "Unable to create waiter mutex.\n");
exit (1);
}
/*
* Create the sigwaiter thread.
*/
if (pthread_create (&tid, &pattr, sigwaiter, NULL) != 0) {
fprintf (stderr, "Unable to create thread.\n");
exit (1);
}
#if defined(_LIBC_R_)
pthread_set_name_np (tid, "sigwaiter");
#endif
/*
* Verify that an ignored signal doesn't cause a wakeup.
* We don't have a handler installed for SIGIO.
*/
send_thread_signal (tid, SIGIO);
sleep (1);
send_process_signal (SIGIO);
sleep (1);
if (sigcounts[SIGIO] != 0)
fprintf (stderr,
"FAIL: sigwait wakes up for ignored signal SIGIO.\n");
/*
* Verify that a signal with a default action of ignore, for
* which we have a signal handler installed, will release a sigwait.
*/
send_thread_signal (tid, SIGURG);
sleep (1);
send_process_signal (SIGURG);
sleep (1);
if (sigcounts[SIGURG] != 2)
fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGURG.\n");
/*
* Verify that a signal with a default action that terminates
* the process will release a sigwait.
*/
send_thread_signal (tid, SIGUSR1);
sleep (1);
send_process_signal (SIGUSR1);
sleep (1);
if (sigcounts[SIGUSR1] != 2)
fprintf (stderr,
"FAIL: sigwait doesn't wake up for SIGUSR1.\n");
/*
* Verify that if we install a signal handler for a previously
* ignored signal, an occurrence of this signal will release
* the (already waiting) sigwait.
*/
/* Install a signal handler for SIGHUP. */
sigemptyset (&act.sa_mask);
sigaddset (&act.sa_mask, SIGHUP);
act.sa_handler = sighandler;
act.sa_flags = SA_RESTART;
sigaction (SIGHUP, &act, NULL);
/* Sending SIGHUP should release the sigwait. */
send_process_signal (SIGHUP);
sleep (1);
send_thread_signal (tid, SIGHUP);
sleep (1);
if (sigcounts[SIGHUP] != 2)
fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGHUP.\n");
/*
* Verify that a pending signal in the waiters mask will
* cause sigwait to return the pending signal. We do this
* by taking the waiters mutex and signaling the waiter to
* release him from the sigwait. The waiter will block
* on taking the mutex, and we can then send the waiter a
* signal which should be added to his pending signals.
* The next time the waiter does a sigwait, he should
* return with the pending signal.
*/
sigcounts[SIGHUP] = 0;
pthread_mutex_lock (&waiter_mutex);
/* Release the waiter from sigwait. */
send_process_signal (SIGHUP);
sleep (1);
if (sigcounts[SIGHUP] != 1)
fprintf (stderr, "FAIL: sigwait doesn't wake up for SIGHUP.\n");
/*
* Add SIGHUP to the process pending signals. Since there is
* a signal handler installed for SIGHUP and this signal is
* blocked from the waiter thread and unblocked in the main
* thread, the signal handler should be called once for SIGHUP.
*/
send_process_signal (SIGHUP);
/* Release the waiter thread and allow him to run. */
pthread_mutex_unlock (&waiter_mutex);
sleep (1);
if (sigcounts[SIGHUP] != 2)
fprintf (stderr,
"FAIL: sigwait doesn't return for pending SIGHUP.\n");
/*
* Repeat the above test using pthread_kill and SIGUSR1.
*/
sigcounts[SIGUSR1] = 0;
pthread_mutex_lock (&waiter_mutex);
/* Release the waiter from sigwait. */
send_thread_signal (tid, SIGUSR1);
sleep (1);
if (sigcounts[SIGUSR1] != 1)
fprintf (stderr,
"FAIL: sigwait doesn't wake up for SIGUSR1.\n");
/* Add SIGUSR1 to the waiters pending signals. */
send_thread_signal (tid, SIGUSR1);
/* Release the waiter thread and allow him to run. */
pthread_mutex_unlock (&waiter_mutex);
sleep (1);
if (sigcounts[SIGUSR1] != 2)
fprintf (stderr,
"FAIL: sigwait doesn't return for pending SIGUSR1.\n");
/*
* Verify that we can still kill the process for a signal
* not being waited on by sigwait.
*/
send_process_signal (SIGPIPE);
fprintf (stderr, "FAIL: SIGPIPE did not terminate process.\n");
/*
* Wait for the thread to finish.
*/
pthread_join (tid, &exit_status);
return (0);
}

View File

@ -1,10 +0,0 @@
Sigwait caught signal 16
Sigwait caught signal 16
Sigwait caught signal 30
Sigwait caught signal 30
Sigwait caught signal 1
Sigwait caught signal 1
Sigwait caught signal 1
-> Signal handler caught signal 1
Sigwait caught signal 30
Sigwait caught signal 30

View File

@ -1,474 +0,0 @@
#!/usr/bin/perl -w
#-*-mode:perl-*-
#############################################################################
#
# Copyright (C) 1999-2001 Jason Evans <jasone@freebsd.org>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice(s), this list of conditions and the following disclaimer as
# the first lines of this file unmodified other than the possible
# addition of one or more copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
# notice(s), this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#############################################################################
#
# Test harness.
#
# $FreeBSD$
#
#############################################################################
# Shut off buffering.
select(STDOUT);
$| = 1;
#
# Parse command-line arguments.
#
use Getopt::Long;
Getopt::Long::config("bundling"); # Allow -hv rather than forcing -h -v.
# Set option defaults for optional arguments.
$opt_help = 0;
$opt_verbose = 0;
$opt_quiet = 0;
$opt_srcdir = ".";
$opt_objdir = ".";
$opt_ustats = 0;
$opt_zero = 0;
$opt_retval =
&GetOptions("h|help" => \$opt_help,
"v|verbose" => \$opt_verbose,
"q|quiet" => \$opt_quiet,
"s|srcdir=s" => \$opt_srcdir,
"o|objdir=s" => \$opt_objdir,
"u|ustats" => \$opt_ustats,
"z|zero" => \$opt_zero
);
if ($opt_help)
{
&usage();
exit(0);
}
if ($opt_retval == 0)
{
&usage();
exit 1;
}
if ($opt_verbose && $opt_quiet)
{
print STDERR "-v and -q are incompatible\n";
&usage();
exit 1;
}
if ($#ARGV + 1 == 0)
{
print STDERR "No tests specified\n";
&usage();
exit 1;
}
if ($opt_verbose)
{
print STDERR "Option values: h:$opt_help, v:$opt_verbose, "
. "s:\"$opt_srcdir\", o:\"$opt_objdir\" "
. "q:$opt_quiet, u:$opt_ustats, z:$opt_zero\n";
printf STDERR "Tests (%d total): @ARGV\n", $#ARGV + 1;
}
#
# Create and print header.
#
@TSTATS =
(
"--------------------------------------------------------------------------\n",
"Test c_user c_system c_total chng\n",
" passed/FAILED h_user h_system h_total %% chng\n"
);
if (!$opt_quiet)
{
foreach $line (@TSTATS)
{
printf STDOUT "$line";
}
}
#
# Run sequence test(s).
#
$total_utime = 0.0; # Total user time.
$total_stime = 0.0; # Total system time.
$total_hutime = 0.0; # Total historical user time.
$total_hstime = 0.0; # Total historical system time.
$total_ntime = 0.0; # Total time for tests that have historical data.
foreach $test (@ARGV)
{
# Strip out any whitespace in $test.
$test =~ s/^\s*(.*)\s*$/$1/;
$okay = 1;
if (-e "$opt_srcdir/$test.exp")
{
# Diff mode.
($okay, $utime, $stime) = &run_test($test);
if (-e "$opt_objdir/$test.out")
{
`diff $opt_srcdir/$test.exp $opt_objdir/$test.out > $opt_objdir/$test.diff 2>&1`;
if ($?)
{
# diff returns non-zero if there is a difference.
$okay = 0;
}
}
else
{
$okay = 0;
if ($opt_verbose)
{
print STDERR
"Nonexistent output file \"$opt_objdir/$test.out\"\n";
}
}
($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
}
else
{
# Sequence mode.
($okay, $utime, $stime) = &run_test($test);
if (open (STEST_OUT, "<$opt_objdir/$test.out"))
{
$num_subtests = 0;
$num_failed_subtests = 0;
while (defined($line = <STEST_OUT>))
{
if ($line =~ /1\.\.(\d+)/)
{
$num_subtests = $1;
last;
}
}
if ($num_subtests == 0)
{
$okay = 0;
if ($opt_verbose)
{
print STDERR "Malformed or missing 1..n line\n";
}
}
else
{
for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
{
while (defined($line = <STEST_OUT>))
{
if ($line =~ /^not\s+ok\s+(\d+)?/)
{
$not = 1;
$test_num = $1;
last;
}
elsif ($line =~ /^ok\s+(\d+)?/)
{
$not = 0;
$test_num = $1;
last;
}
}
if (defined($line))
{
if (defined($test_num) && ($test_num != $subtest))
{
# There was no output printed for one or more tests.
for (; $subtest < $test_num; $subtest++)
{
$num_failed_subtests++;
}
}
if ($not)
{
$num_failed_subtests++;
}
}
else
{
for (; $subtest <= $num_subtests; $subtest++)
{
$num_failed_subtests++;
}
}
}
if (0 < $num_failed_subtests)
{
$okay = 0;
}
}
}
else
{
if (!$opt_quiet)
{
print STDERR "Cannot open output file \"$opt_objdir/$test.out\"\n";
}
exit 1;
}
($hutime, $hstime) = &print_stats($test, $okay,
$num_failed_subtests, $num_subtests,
$utime, $stime);
}
$total_hutime += $hutime;
$total_hstime += $hstime;
if ($okay)
{
$total_utime += $utime;
$total_stime += $stime;
}
else
{
@FAILED_TESTS = (@FAILED_TESTS, $test);
}
# If there were historical data, add the run time to the total time to
# compare against the historical run time.
if (0 < ($hutime + $hstime))
{
$total_ntime += $utime + $stime;
}
}
# Print summary stats.
$tt_str = sprintf ("%d / %d passed (%5.2f%%%%)",
($#ARGV + 1) - ($#FAILED_TESTS + 1),
$#ARGV + 1,
(($#ARGV + 1) - ($#FAILED_TESTS + 1))
/ ($#ARGV + 1) * 100);
$t_str = sprintf ("Totals %7.2f %7.2f %7.2f"
. " %7.2f\n"
. " %s %7.2f %7.2f %7.2f %7.2f%%%%\n",
$total_utime, $total_stime, $total_utime + $total_stime,
($total_ntime - ($total_hutime + $total_hstime)),
$tt_str . ' ' x (40 - length($tt_str)),
$total_hutime, $total_hstime, $total_hutime + $total_hstime,
($total_hutime + $total_hstime == 0.0) ? 0.0 :
(($total_ntime
- ($total_hutime + $total_hstime))
/ ($total_hutime + $total_hstime) * 100));
@TSTATS = ("--------------------------------------------------------------------------\n",
$t_str,
"--------------------------------------------------------------------------\n"
);
if (!$opt_quiet)
{
foreach $line (@TSTATS)
{
printf STDOUT "$line";
}
}
if ($#FAILED_TESTS >= 0)
{
# One or more tests failed, so return an error.
exit 1;
}
# End of main execution.
sub run_test
{
my ($test) = @_;
my ($okay) = 1;
my ($tutime, $tstime);
my ($utime, $stime, $cutime, $cstime);
my (@TSTATS, @TPATH);
my ($t_str);
my ($srcdir, $objdir);
# Get the path component of $test, if any.
@TPATH = split(/\//, $test);
pop(@TPATH);
$srcdir = join('/', ($opt_srcdir, @TPATH));
$objdir = join('/', ($opt_objdir, @TPATH));
@TSTATS = ("--------------------------------------------------------------------------\n");
$t_str = sprintf ("%s%s", $test, ' ' x (40 - length($test)));
@TSTATS = (@TSTATS, $t_str);
@STATS = (@STATS, @TSTATS);
if (!$opt_quiet)
{
foreach $line (@TSTATS)
{
printf STDOUT "$line";
}
}
($utime, $stime, $cutime, $cstime) = times;
`$opt_objdir/$test $srcdir $objdir > $opt_objdir/$test.out 2>&1`;
($utime, $stime, $tutime, $tstime) = times;
# Subtract the before time from the after time.
$tutime -= $cutime;
$tstime -= $cstime;
if ($opt_zero)
{
if ($?)
{
$okay = 0;
if ($opt_verbose)
{
print STDERR
"\"$opt_objdir/$test > $opt_objdir/$test.out 2>&1\" returned $?\n";
}
}
}
return ($okay, $tutime, $tstime);
}
sub print_stats
{
my ($test, $okay, $failed_subtests, $subtests, $utime, $stime) = @_;
my ($hutime, $hstime);
# my (TEST_PERF);
my (@TSTATS);
my ($t_str, $pass_str);
$pass_str = $okay ? "passed" : "*** FAILED ***";
if ((0 != $subtests) && (!$okay))
{
$pass_str = $pass_str . " ($failed_subtests/$subtests failed)";
}
$pass_str = $pass_str . ' ' x (39 - length($pass_str));
if (-r "$test.perf")
{
if (!open (TEST_PERF, "<$opt_objdir/$test.perf"))
{
print STDERR "Unable to open \"$opt_objdir/$test.perf\"\n";
exit 1;
}
$_ = <TEST_PERF>;
($hutime, $hstime) = split;
close TEST_PERF;
$t_str = sprintf (" %7.2f %7.2f %7.2f %7.2f\n"
. " %s %7.2f %7.2f %7.2f %7.2f%%%%\n",
$utime, $stime, $utime + $stime,
($utime + $stime) - ($hutime + $hstime),
$pass_str,
$hutime, $hstime, $hutime + $hstime,
(($hutime + $hstime) == 0.0) ? 0.0 :
((($utime + $stime) - ($hutime + $hstime))
/ ($hutime + $hstime) * 100));
}
else
{
$hutime = 0.0;
$hstime = 0.0;
$t_str = sprintf (" %7.2f %7.2f %7.2f \n"
. " %s\n",
$utime, $stime, $utime + $stime,
$pass_str);
}
@TSTATS = ($t_str);
if (!$opt_quiet)
{
foreach $line (@TSTATS)
{
printf STDOUT "$line";
}
}
if ($okay && $opt_ustats)
{
if (!open (TEST_PERF, ">$opt_objdir/$test.perf"))
{
if (!$opt_quiet)
{
print STDERR "Unable to update \"$opt_objdir/$test.perf\"\n";
}
}
else
{
print TEST_PERF "$utime $stime\n";
close TEST_PERF;
}
}
return ($hutime, $hstime);
}
sub usage
{
print <<EOF;
$0 usage:
$0 [<options>] <test>+
Option | Description
--------------+-------------------------------------------------------------
-h --help | Print usage and exit.
-v --verbose | Verbose (incompatible with quiet).
-q --quiet | Quiet (incompatible with verbose).
-s --srcdir | Path to source tree (default is ".").
-o --objdir | Path to object tree (default is ".").
-u --ustats | Update historical statistics (stored in "<test>.perf".
-z --zero | Consider non-zero exit code to be an error.
--------------+-------------------------------------------------------------
If <test>.exp exists, <test>'s output is diff'ed with <test>.exp. Any
difference is considered failure.
If <test>.exp does not exist, output to stdout of the following form is
expected:
1..<n>
{not }ok[ 1]
{not }ok[ 2]
...
{not }ok[ n]
1 <= <n> < 2^31
Lines which do not match the patterns shown above are ignored.
EOF
}

View File

@ -1,143 +0,0 @@
# $FreeBSD$
# uthread sources
.PATH: ${.CURDIR}/uthread
SRCS+= \
uthread_accept.c \
uthread_acl_delete_fd.c \
uthread_acl_get_fd.c \
uthread_acl_set_fd.c \
uthread_acl_aclcheck_fd.c \
uthread_aio_suspend.c \
uthread_atfork.c \
uthread_attr_destroy.c \
uthread_attr_init.c \
uthread_attr_getdetachstate.c \
uthread_attr_getguardsize.c \
uthread_attr_getinheritsched.c \
uthread_attr_getschedparam.c \
uthread_attr_getschedpolicy.c \
uthread_attr_getscope.c \
uthread_attr_getstack.c \
uthread_attr_getstackaddr.c \
uthread_attr_getstacksize.c \
uthread_attr_get_np.c \
uthread_attr_setcreatesuspend_np.c \
uthread_attr_setdetachstate.c \
uthread_attr_setguardsize.c \
uthread_attr_setinheritsched.c \
uthread_attr_setschedparam.c \
uthread_attr_setschedpolicy.c \
uthread_attr_setscope.c \
uthread_attr_setstack.c \
uthread_attr_setstackaddr.c \
uthread_attr_setstacksize.c \
uthread_autoinit.c \
uthread_bind.c \
uthread_cancel.c \
uthread_clean.c \
uthread_close.c \
uthread_concurrency.c \
uthread_cond.c \
uthread_condattr_destroy.c \
uthread_condattr_init.c \
uthread_connect.c \
uthread_creat.c \
uthread_create.c \
uthread_detach.c \
uthread_dup.c \
uthread_dup2.c \
uthread_equal.c \
uthread_execve.c \
uthread_exit.c \
uthread_fchflags.c \
uthread_fchmod.c \
uthread_fchown.c \
uthread_fcntl.c \
uthread_fd.c \
uthread_file.c \
uthread_find_thread.c \
uthread_flock.c \
uthread_fork.c \
uthread_fpathconf.c \
uthread_fstat.c \
uthread_fstatfs.c \
uthread_fsync.c \
uthread_gc.c \
uthread_getdirentries.c \
uthread_getpeername.c \
uthread_getprio.c \
uthread_getschedparam.c \
uthread_getsockname.c \
uthread_getsockopt.c \
uthread_info.c \
uthread_init.c \
uthread_ioctl.c \
uthread_jmp.c \
uthread_join.c \
uthread_kern.c \
uthread_kevent.c \
uthread_kqueue.c \
uthread_kill.c \
uthread_listen.c \
uthread_main_np.c \
uthread_mattr_init.c \
uthread_mattr_kind_np.c \
uthread_msync.c \
uthread_multi_np.c \
uthread_mutex.c \
uthread_mutex_prioceiling.c \
uthread_mutex_protocol.c \
uthread_mutexattr_destroy.c \
uthread_nanosleep.c \
uthread_once.c \
uthread_open.c \
uthread_pause.c \
uthread_pipe.c \
uthread_poll.c \
uthread_priority_queue.c \
uthread_pselect.c \
uthread_read.c \
uthread_readv.c \
uthread_recvfrom.c \
uthread_recvmsg.c \
uthread_resume_np.c \
uthread_rwlock.c \
uthread_rwlockattr.c \
uthread_select.c \
uthread_self.c \
uthread_sem.c \
uthread_sendfile.c \
uthread_sendmsg.c \
uthread_sendto.c \
uthread_seterrno.c \
uthread_setprio.c \
uthread_setschedparam.c \
uthread_setsockopt.c \
uthread_shutdown.c \
uthread_sig.c \
uthread_sigaction.c \
uthread_sigmask.c \
uthread_sigpending.c \
uthread_sigprocmask.c \
uthread_sigsuspend.c \
uthread_sigwait.c \
uthread_single_np.c \
uthread_sleep.c \
uthread_socket.c \
uthread_socketpair.c \
uthread_spec.c \
uthread_spinlock.c \
uthread_stack.c \
uthread_suspend_np.c \
uthread_switch_np.c \
uthread_system.c \
uthread_tcdrain.c \
uthread_vfork.c \
uthread_wait.c \
uthread_wait4.c \
uthread_waitpid.c \
uthread_write.c \
uthread_writev.c \
uthread_yield.c

File diff suppressed because it is too large Load Diff

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(__accept, accept);
int
_accept(int fd, struct sockaddr * name, socklen_t *namelen)
{
struct pthread *curthread = _get_curthread();
int ret;
/* Lock the file descriptor: */
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
/* Enter a loop to wait for a connection request: */
while ((ret = __sys_accept(fd, name, namelen)) < 0) {
/* Check if the socket is to block: */
if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0
&& (errno == EWOULDBLOCK || errno == EAGAIN)) {
/* Save the socket file descriptor: */
curthread->data.fd.fd = fd;
curthread->data.fd.fname = __FILE__;
curthread->data.fd.branch = __LINE__;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
curthread->interrupted = 0;
/* Schedule the next thread: */
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
break;
}
} else {
/*
* Another error has occurred, so exit the
* loop here:
*/
break;
}
}
/* Check for errors: */
if (ret < 0) {
}
/* Initialise the file descriptor table for the new socket: */
else if (_thread_fd_table_init(ret) != 0) {
/* Quietly close the socket: */
__sys_close(ret);
/* Return an error: */
ret = -1;
}
/*
* If the parent socket was blocking, make sure that
* the new socket is also set blocking here (as the
* call to _thread_fd_table_init() above will always
* set the new socket flags to non-blocking, as that
* will be the inherited state of the new socket.
*/
if((ret > 0) && (_thread_fd_getflags(fd) & O_NONBLOCK) == 0)
_thread_fd_setflags(ret,
_thread_fd_getflags(ret) & ~O_NONBLOCK);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
/* Return the socket file descriptor or -1 on error: */
return (ret);
}
int
__accept(int fd, struct sockaddr * name, socklen_t *namelen)
{
int ret;
_thread_enter_cancellation_point();
ret = _accept(fd, name, namelen);
_thread_leave_cancellation_point();
return (ret);
}

View File

@ -1,47 +0,0 @@
/*-
* Copyright (c) 2001 Thomas Moestl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/acl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(___acl_aclcheck_fd, __acl_aclcheck_fd);
int
___acl_aclcheck_fd(int fd, acl_type_t tp, acl_t acl)
{
int error;
if ((error = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
error = __sys___acl_aclcheck_fd(fd, tp, (struct acl *)acl);
_FD_UNLOCK(fd, FD_READ);
}
return (error);
}

View File

@ -1,46 +0,0 @@
/*-
* Copyright (c) 2001 Thomas Moestl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/acl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(___acl_delete_fd, __acl_delete_fd);
int
___acl_delete_fd(int fd, acl_type_t tp)
{
int error;
if ((error = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
error = __sys___acl_delete_fd(fd, tp);
_FD_UNLOCK(fd, FD_WRITE);
}
return (error);
}

View File

@ -1,47 +0,0 @@
/*-
* Copyright (c) 2001 Thomas Moestl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/acl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(___acl_get_fd, __acl_get_fd);
int
___acl_get_fd(int fd, acl_type_t tp, struct acl *acl_p)
{
int error;
if ((error = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
error = __sys___acl_get_fd(fd, tp, acl_p);
_FD_UNLOCK(fd, FD_READ);
}
return (error);
}

View File

@ -1,46 +0,0 @@
/*-
* Copyright (c) 2001 Thomas Moestl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/acl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(___acl_set_fd, __acl_set_fd);
int
___acl_set_fd(int fd, acl_type_t tp, struct acl *acl_p)
{
int error;
if ((error = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
error = __sys___acl_set_fd(fd, tp, acl_p);
_FD_UNLOCK(fd, FD_WRITE);
}
return (error);
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer as
* the first lines of this file unmodified other than the possible
* addition of one or more copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <aio.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_aio_suspend, aio_suspend);
int
_aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
timespec *timeout)
{
int ret;
_thread_enter_cancellation_point();
ret = __sys_aio_suspend(iocbs, niocb, timeout);
_thread_leave_cancellation_point();
return ret;
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/queue.h>
#include "pthread_private.h"
__weak_reference(_pthread_atfork, pthread_atfork);
int
_pthread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void))
{
struct pthread_atfork *af;
if (_thread_initial == NULL)
_thread_init();
if ((af = malloc(sizeof(struct pthread_atfork))) == NULL)
return (ENOMEM);
af->prepare = prepare;
af->parent = parent;
af->child = child;
_pthread_mutex_lock(&_atfork_mutex);
TAILQ_INSERT_TAIL(&_atfork_list, af, qe);
_pthread_mutex_unlock(&_atfork_mutex);
return (0);
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_destroy, pthread_attr_destroy);
int
_pthread_attr_destroy(pthread_attr_t *attr)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL)
/* Invalid argument: */
ret = EINVAL;
else {
/* Free the memory allocated to the attribute object: */
free(*attr);
/*
* Leave the attribute pointer NULL now that the memory
* has been freed:
*/
*attr = NULL;
ret = 0;
}
return(ret);
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <string.h>
#include <pthread.h>
#include <pthread_np.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_get_np, pthread_attr_get_np);
int
_pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst)
{
int ret;
if (pid == NULL || dst == NULL || *dst == NULL)
return (EINVAL);
if ((ret = _find_thread(pid)) != 0)
return (ret);
memcpy(*dst, &pid->attr, sizeof(struct pthread_attr));
/*
* Special case, if stack address was not provided by caller
* of pthread_create(), then return address allocated internally
*/
if ((*dst)->stackaddr_attr == NULL)
(*dst)->stackaddr_attr = pid->stack;
return (0);
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getdetachstate, pthread_attr_getdetachstate);
int
_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || detachstate == NULL)
ret = EINVAL;
else {
/* Check if the detached flag is set: */
if ((*attr)->flags & PTHREAD_DETACHED)
/* Return detached: */
*detachstate = PTHREAD_CREATE_DETACHED;
else
/* Return joinable: */
*detachstate = PTHREAD_CREATE_JOINABLE;
ret = 0;
}
return(ret);
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer
* unmodified other than the allowable addition of one or more
* copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getguardsize, pthread_attr_getguardsize);
int
_pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || guardsize == NULL)
ret = EINVAL;
else {
/* Return the guard size: */
*guardsize = (*attr)->guardsize_attr;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getinheritsched, pthread_attr_getinheritsched);
int
_pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL))
ret = EINVAL;
else
*sched_inherit = (*attr)->sched_inherit;
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getschedparam, pthread_attr_getschedparam);
int
_pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL) || (param == NULL))
ret = EINVAL;
else
param->sched_priority = (*attr)->prio;
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getschedpolicy, pthread_attr_getschedpolicy);
int
_pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL) || (policy == NULL))
ret = EINVAL;
else
*policy = (*attr)->sched_policy;
return(ret);
}

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getscope, pthread_attr_getscope);
int
_pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL) || (contentionscope == NULL))
/* Return an invalid argument: */
ret = EINVAL;
else
*contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ?
PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS;
return(ret);
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Craig Rodrigues.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getstack, pthread_attr_getstack);
int
_pthread_attr_getstack(const pthread_attr_t * __restrict attr,
void ** __restrict stackaddr,
size_t * __restrict stacksize)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stackaddr == NULL
|| stacksize == NULL )
ret = EINVAL;
else {
/* Return the stack address and size */
*stackaddr = (*attr)->stackaddr_attr;
*stacksize = (*attr)->stacksize_attr;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getstackaddr, pthread_attr_getstackaddr);
int
_pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stackaddr == NULL)
ret = EINVAL;
else {
/* Return the stack address: */
*stackaddr = (*attr)->stackaddr_attr;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_getstacksize, pthread_attr_getstacksize);
int
_pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stacksize == NULL)
ret = EINVAL;
else {
/* Return the stack size: */
*stacksize = (*attr)->stacksize_attr;
ret = 0;
}
return(ret);
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_init, pthread_attr_init);
int
_pthread_attr_init(pthread_attr_t *attr)
{
int ret;
pthread_attr_t pattr;
/* Allocate memory for the attribute object: */
if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL)
/* Insufficient memory: */
ret = ENOMEM;
else {
/* Initialise the attribute object with the defaults: */
memcpy(pattr, &_pthread_attr_default, sizeof(*pattr));
/* Return a pointer to the attribute object: */
*attr = pattr;
ret = 0;
}
return(ret);
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setcreatesuspend_np, pthread_attr_setcreatesuspend_np);
int
_pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
} else {
(*attr)->suspend = PTHREAD_CREATE_SUSPENDED;
ret = 0;
}
return(ret);
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setdetachstate, pthread_attr_setdetachstate);
int
_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL ||
(detachstate != PTHREAD_CREATE_DETACHED &&
detachstate != PTHREAD_CREATE_JOINABLE))
ret = EINVAL;
else {
/* Check if detached state: */
if (detachstate == PTHREAD_CREATE_DETACHED)
/* Set the detached flag: */
(*attr)->flags |= PTHREAD_DETACHED;
else
/* Reset the detached flag: */
(*attr)->flags &= ~PTHREAD_DETACHED;
ret = 0;
}
return(ret);
}

View File

@ -1,61 +0,0 @@
/*
* Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer
* unmodified other than the allowable addition of one or more
* copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setguardsize, pthread_attr_setguardsize);
int
_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
{
int ret;
/* Check for invalid arguments. */
if (attr == NULL || *attr == NULL)
ret = EINVAL;
else {
/*
* Round guardsize up to the nearest multiple of
* _pthread_page_size.
*/
if (guardsize % _pthread_page_size != 0)
guardsize = ((guardsize / _pthread_page_size) + 1) *
_pthread_page_size;
/* Save the stack size. */
(*attr)->guardsize_attr = guardsize;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setinheritsched, pthread_attr_setinheritsched);
int
_pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL))
ret = EINVAL;
else
(*attr)->sched_inherit = sched_inherit;
return(ret);
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setschedparam, pthread_attr_setschedparam);
int
_pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL))
ret = EINVAL;
else if (param == NULL) {
ret = ENOTSUP;
} else if ((param->sched_priority < PTHREAD_MIN_PRIORITY) ||
(param->sched_priority > PTHREAD_MAX_PRIORITY)) {
/* Return an unsupported value error. */
ret = ENOTSUP;
} else
(*attr)->prio = param->sched_priority;
return(ret);
}

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setschedpolicy, pthread_attr_setschedpolicy);
int
_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL))
ret = EINVAL;
else if ((policy < SCHED_FIFO) || (policy > SCHED_RR)) {
ret = ENOTSUP;
} else
(*attr)->sched_policy = policy;
return(ret);
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setscope, pthread_attr_setscope);
int
_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
{
int ret = 0;
if ((attr == NULL) || (*attr == NULL)) {
/* Return an invalid argument: */
ret = EINVAL;
} else if ((contentionscope != PTHREAD_SCOPE_PROCESS) ||
(contentionscope == PTHREAD_SCOPE_SYSTEM)) {
/* We don't support PTHREAD_SCOPE_SYSTEM. */
ret = ENOTSUP;
} else
(*attr)->flags |= contentionscope;
return(ret);
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Craig Rodrigues.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setstack, pthread_attr_setstack);
int
_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
size_t stacksize)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stackaddr == NULL
|| stacksize < PTHREAD_STACK_MIN )
ret = EINVAL;
else {
/* Save the stack address and stack size */
(*attr)->stackaddr_attr = stackaddr;
(*attr)->stacksize_attr = stacksize;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setstackaddr, pthread_attr_setstackaddr);
int
_pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stackaddr == NULL)
ret = EINVAL;
else {
/* Save the stack address: */
(*attr)->stackaddr_attr = stackaddr;
ret = 0;
}
return(ret);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_attr_setstacksize, pthread_attr_setstacksize);
int
_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
{
int ret;
/* Check for invalid arguments: */
if (attr == NULL || *attr == NULL || stacksize < PTHREAD_STACK_MIN)
ret = EINVAL;
else {
/* Save the stack size: */
(*attr)->stacksize_attr = stacksize;
ret = 0;
}
return(ret);
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2002 Alfred Perlstein <alfred@freebsd.org>.
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by John Birrell.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <pthread.h>
#include <pthread_private.h>
/*
* This module uses GCC extentions to initialize the
* threads package at program start-up time.
*/
void _thread_init_hack(void) __attribute__ ((constructor));
void
_thread_init_hack(void)
{
_thread_init();
}
/*
* For the shared version of the threads library, the above is sufficient.
* But for the archive version of the library, we need a little bit more.
* Namely, we must arrange for this particular module to be pulled in from
* the archive library at link time. To accomplish that, we define and
* initialize a variable, "_thread_autoinit_dummy_decl". This variable is
* referenced (as an extern) from libc/stdlib/exit.c. This will always
* create a need for this module, ensuring that it is present in the
* executable.
*/
extern int _thread_autoinit_dummy_decl;
int _thread_autoinit_dummy_decl = 0;

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_bind, bind);
int
_bind(int fd, const struct sockaddr * name, socklen_t namelen)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = __sys_bind(fd, name, namelen);
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}

View File

@ -1,231 +0,0 @@
/*
* David Leonard <d@openbsd.org>, 1999. Public domain.
* $FreeBSD$
*/
#include <sys/errno.h>
#include <pthread.h>
#include "pthread_private.h"
static void finish_cancellation(void *arg);
__weak_reference(_pthread_cancel, pthread_cancel);
__weak_reference(_pthread_setcancelstate, pthread_setcancelstate);
__weak_reference(_pthread_setcanceltype, pthread_setcanceltype);
__weak_reference(_pthread_testcancel, pthread_testcancel);
int
_pthread_cancel(pthread_t pthread)
{
int ret;
if ((ret = _find_thread(pthread)) != 0) {
/* NOTHING */
} else if (pthread->state == PS_DEAD || pthread->state == PS_DEADLOCK
|| (pthread->flags & PTHREAD_EXITING) != 0) {
ret = 0;
} else {
/* Protect the scheduling queues: */
_thread_kern_sig_defer();
if (((pthread->cancelflags & PTHREAD_CANCEL_DISABLE) != 0) ||
(((pthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) == 0) &&
((pthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0)))
/* Just mark it for cancellation: */
pthread->cancelflags |= PTHREAD_CANCELLING;
else {
/*
* Check if we need to kick it back into the
* run queue:
*/
switch (pthread->state) {
case PS_RUNNING:
/* No need to resume: */
pthread->cancelflags |= PTHREAD_CANCELLING;
break;
case PS_SPINBLOCK:
case PS_FDR_WAIT:
case PS_FDW_WAIT:
case PS_POLL_WAIT:
case PS_SELECT_WAIT:
/* Remove these threads from the work queue: */
if ((pthread->flags & PTHREAD_FLAGS_IN_WORKQ)
!= 0)
PTHREAD_WORKQ_REMOVE(pthread);
/* Fall through: */
case PS_SIGTHREAD:
case PS_SLEEP_WAIT:
case PS_WAIT_WAIT:
case PS_SIGSUSPEND:
case PS_SIGWAIT:
/* Interrupt and resume: */
pthread->interrupted = 1;
pthread->cancelflags |= PTHREAD_CANCELLING;
PTHREAD_NEW_STATE(pthread,PS_RUNNING);
break;
case PS_JOIN:
/*
* Disconnect the thread from the joinee:
*/
if (pthread->join_status.thread != NULL) {
pthread->join_status.thread->joiner
= NULL;
pthread->join_status.thread = NULL;
}
pthread->cancelflags |= PTHREAD_CANCELLING;
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
break;
case PS_SUSPENDED:
case PS_MUTEX_WAIT:
case PS_COND_WAIT:
case PS_FDLR_WAIT:
case PS_FDLW_WAIT:
case PS_FILE_WAIT:
/*
* Threads in these states may be in queues.
* In order to preserve queue integrity, the
* cancelled thread must remove itself from the
* queue. Mark the thread as interrupted and
* needing cancellation, and set the state to
* running. When the thread resumes, it will
* remove itself from the queue and call the
* cancellation completion routine.
*/
pthread->interrupted = 1;
pthread->cancelflags |= PTHREAD_CANCEL_NEEDED;
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
pthread->continuation = finish_cancellation;
break;
case PS_DEAD:
case PS_DEADLOCK:
case PS_STATE_MAX:
/* Ignore - only here to silence -Wall: */
break;
}
}
/* Unprotect the scheduling queues: */
_thread_kern_sig_undefer();
ret = 0;
}
return (ret);
}
int
_pthread_setcancelstate(int state, int *oldstate)
{
struct pthread *curthread = _get_curthread();
int ostate;
int ret;
ostate = curthread->cancelflags & PTHREAD_CANCEL_DISABLE;
switch (state) {
case PTHREAD_CANCEL_ENABLE:
if (oldstate != NULL)
*oldstate = ostate;
curthread->cancelflags &= ~PTHREAD_CANCEL_DISABLE;
if ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)
pthread_testcancel();
ret = 0;
break;
case PTHREAD_CANCEL_DISABLE:
if (oldstate != NULL)
*oldstate = ostate;
curthread->cancelflags |= PTHREAD_CANCEL_DISABLE;
ret = 0;
break;
default:
ret = EINVAL;
}
return (ret);
}
int
_pthread_setcanceltype(int type, int *oldtype)
{
struct pthread *curthread = _get_curthread();
int otype;
int ret;
otype = curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS;
switch (type) {
case PTHREAD_CANCEL_ASYNCHRONOUS:
if (oldtype != NULL)
*oldtype = otype;
curthread->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS;
pthread_testcancel();
ret = 0;
break;
case PTHREAD_CANCEL_DEFERRED:
if (oldtype != NULL)
*oldtype = otype;
curthread->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS;
ret = 0;
break;
default:
ret = EINVAL;
}
return (ret);
}
void
_pthread_testcancel(void)
{
struct pthread *curthread = _get_curthread();
if (((curthread->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) &&
((curthread->cancelflags & PTHREAD_CANCELLING) != 0) &&
((curthread->flags & PTHREAD_EXITING) == 0)) {
/*
* It is possible for this thread to be swapped out
* while performing cancellation; do not allow it
* to be cancelled again.
*/
curthread->cancelflags &= ~PTHREAD_CANCELLING;
_thread_exit_cleanup();
pthread_exit(PTHREAD_CANCELED);
PANIC("cancel");
}
}
void
_thread_enter_cancellation_point(void)
{
struct pthread *curthread = _get_curthread();
/* Look for a cancellation before we block: */
pthread_testcancel();
curthread->cancelflags |= PTHREAD_AT_CANCEL_POINT;
}
void
_thread_leave_cancellation_point(void)
{
struct pthread *curthread = _get_curthread();
curthread->cancelflags &= ~PTHREAD_AT_CANCEL_POINT;
/* Look for a cancellation after we unblock: */
pthread_testcancel();
}
static void
finish_cancellation(void *arg)
{
struct pthread *curthread = _get_curthread();
curthread->continuation = NULL;
curthread->interrupted = 0;
if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) {
curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED;
_thread_exit_cleanup();
pthread_exit(PTHREAD_CANCELED);
}
}

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_cleanup_push, pthread_cleanup_push);
__weak_reference(_pthread_cleanup_pop, pthread_cleanup_pop);
void
_pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
{
struct pthread *curthread = _get_curthread();
struct pthread_cleanup *new;
if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) {
new->routine = routine;
new->routine_arg = routine_arg;
new->next = curthread->cleanup;
curthread->cleanup = new;
}
}
void
_pthread_cleanup_pop(int execute)
{
struct pthread *curthread = _get_curthread();
struct pthread_cleanup *old;
if ((old = curthread->cleanup) != NULL) {
curthread->cleanup = old->next;
if (execute) {
old->routine(old->routine_arg);
}
free(old);
}
}

View File

@ -1,119 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(__close, close);
int
_close(int fd)
{
int flags;
int ret;
struct stat sb;
struct fd_table_entry *entry;
if ((fd < 0) || (fd >= _thread_dtablesize) ||
(fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1]) ||
(_thread_fd_table[fd] == NULL)) {
/*
* Don't allow silly programs to close the kernel pipe
* and non-active descriptors.
*/
errno = EBADF;
ret = -1;
}
/*
* Lock the file descriptor while the file is closed and get
* the file descriptor status:
*/
else if (((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) &&
((ret = __sys_fstat(fd, &sb)) == 0)) {
/*
* Check if the file should be left as blocking.
*
* This is so that the file descriptors shared with a parent
* process aren't left set to non-blocking if the child
* closes them prior to exit. An example where this causes
* problems with /bin/sh is when a child closes stdin.
*
* Setting a file as blocking causes problems if a threaded
* parent accesses the file descriptor before the child exits.
* Once the threaded parent receives a SIGCHLD then it resets
* all of its files to non-blocking, and so it is then safe
* to access them.
*
* Pipes are not set to blocking when they are closed, as
* the parent and child will normally close the file
* descriptor of the end of the pipe that they are not
* using, which would then cause any reads to block
* indefinitely.
*/
if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode))
&& (_thread_fd_getflags(fd) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(fd, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
__sys_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
}
/* XXX: Assumes well behaved threads. */
/* XXX: Defer real close to avoid race condition */
entry = _thread_fd_table[fd];
_thread_fd_table[fd] = NULL;
free(entry);
/* Drop stale pthread stdio descriptor flags. */
if (fd < 3)
_pthread_stdio_flags[fd] = -1;
/* Close the file descriptor: */
ret = __sys_close(fd);
}
return (ret);
}
int
__close(int fd)
{
int ret;
_thread_enter_cancellation_point();
ret = _close(fd);
_thread_leave_cancellation_point();
return ret;
}

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2003 Sergey Osokin <osa@FreeBSD.org.ru>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Sergey Osokin.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
static int current_concurrency = 0;
__weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
__weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
int
_pthread_getconcurrency(void)
{
return current_concurrency;
}
int
_pthread_setconcurrency(int new_level)
{
int ret;
if (new_level < 0) {
ret = EINVAL;
} else {
current_concurrency = new_level;
ret = 0;
}
return(ret);
}

View File

@ -1,765 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
#include "pthread_private.h"
/*
* Prototypes
*/
static inline pthread_t cond_queue_deq(pthread_cond_t);
static inline void cond_queue_remove(pthread_cond_t, pthread_t);
static inline void cond_queue_enq(pthread_cond_t, pthread_t);
int __pthread_cond_timedwait(pthread_cond_t *,
pthread_mutex_t *, const struct timespec *);
int __pthread_cond_wait(pthread_cond_t *,
pthread_mutex_t *);
/*
* Double underscore versions are cancellation points. Single underscore
* versions are not and are provided for libc internal usage (which
* shouldn't introduce cancellation points).
*/
__weak_reference(__pthread_cond_wait, pthread_cond_wait);
__weak_reference(__pthread_cond_timedwait, pthread_cond_timedwait);
__weak_reference(_pthread_cond_init, pthread_cond_init);
__weak_reference(_pthread_cond_destroy, pthread_cond_destroy);
__weak_reference(_pthread_cond_signal, pthread_cond_signal);
__weak_reference(_pthread_cond_broadcast, pthread_cond_broadcast);
/*
* Reinitialize a private condition variable; this is only used for
* internal condition variables. Currently, there is no difference.
*/
int
_cond_reinit(pthread_cond_t *cond)
{
int ret = 0;
if (cond == NULL)
ret = EINVAL;
else if (*cond == NULL)
ret = _pthread_cond_init(cond, NULL);
else {
/*
* Initialize the condition variable structure:
*/
TAILQ_INIT(&(*cond)->c_queue);
(*cond)->c_flags = COND_FLAGS_INITED;
(*cond)->c_type = COND_TYPE_FAST;
(*cond)->c_mutex = NULL;
(*cond)->c_seqno = 0;
memset(&(*cond)->lock, 0, sizeof((*cond)->lock));
}
return (ret);
}
int
_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
{
enum pthread_cond_type type;
pthread_cond_t pcond;
int rval = 0;
if (cond == NULL)
rval = EINVAL;
else {
/*
* Check if a pointer to a condition variable attribute
* structure was passed by the caller:
*/
if (cond_attr != NULL && *cond_attr != NULL) {
/* Default to a fast condition variable: */
type = (*cond_attr)->c_type;
} else {
/* Default to a fast condition variable: */
type = COND_TYPE_FAST;
}
/* Process according to condition variable type: */
switch (type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
/* Nothing to do here. */
break;
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
/* Check for no errors: */
if (rval == 0) {
if ((pcond = (pthread_cond_t)
malloc(sizeof(struct pthread_cond))) == NULL) {
rval = ENOMEM;
} else {
/*
* Initialise the condition variable
* structure:
*/
TAILQ_INIT(&pcond->c_queue);
pcond->c_flags |= COND_FLAGS_INITED;
pcond->c_type = type;
pcond->c_mutex = NULL;
pcond->c_seqno = 0;
memset(&pcond->lock,0,sizeof(pcond->lock));
*cond = pcond;
}
}
}
/* Return the completion status: */
return (rval);
}
int
_pthread_cond_destroy(pthread_cond_t *cond)
{
int rval = 0;
if (cond == NULL || *cond == NULL)
rval = EINVAL;
else {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);
/*
* Free the memory allocated for the condition
* variable structure:
*/
free(*cond);
/*
* NULL the caller's pointer now that the condition
* variable has been destroyed:
*/
*cond = NULL;
}
/* Return the completion status: */
return (rval);
}
int
_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
struct pthread *curthread = _get_curthread();
int rval = 0;
int done = 0;
int interrupted = 0;
int seqno;
if (cond == NULL)
return (EINVAL);
/*
* If the condition variable is statically initialized,
* perform the dynamic initialization:
*/
if (*cond == NULL &&
(rval = _pthread_cond_init(cond, NULL)) != 0)
return (rval);
/*
* Enter a loop waiting for a condition signal or broadcast
* to wake up this thread. A loop is needed in case the waiting
* thread is interrupted by a signal to execute a signal handler.
* It is not (currently) possible to remain in the waiting queue
* while running a handler. Instead, the thread is interrupted
* and backed out of the waiting queue prior to executing the
* signal handler.
*/
do {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);
/*
* If the condvar was statically allocated, properly
* initialize the tail queue.
*/
if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) {
TAILQ_INIT(&(*cond)->c_queue);
(*cond)->c_flags |= COND_FLAGS_INITED;
}
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
if ((mutex == NULL) || (((*cond)->c_mutex != NULL) &&
((*cond)->c_mutex != *mutex))) {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Return invalid argument error: */
rval = EINVAL;
} else {
/* Reset the timeout and interrupted flags: */
curthread->timeout = 0;
curthread->interrupted = 0;
/*
* Queue the running thread for the condition
* variable:
*/
cond_queue_enq(*cond, curthread);
/* Remember the mutex and sequence number: */
(*cond)->c_mutex = *mutex;
seqno = (*cond)->c_seqno;
/* Wait forever: */
curthread->wakeup_time.tv_sec = -1;
/* Unlock the mutex: */
if ((rval = _mutex_cv_unlock(mutex)) != 0) {
/*
* Cannot unlock the mutex, so remove
* the running thread from the condition
* variable queue:
*/
cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) ==
NULL)
(*cond)->c_mutex = NULL;
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
} else {
/*
* Schedule the next thread and unlock
* the condition variable structure:
*/
_thread_kern_sched_state_unlock(PS_COND_WAIT,
&(*cond)->lock, __FILE__, __LINE__);
done = (seqno != (*cond)->c_seqno);
interrupted = curthread->interrupted;
/*
* Check if the wait was interrupted
* (canceled) or needs to be resumed
* after handling a signal.
*/
if (interrupted != 0) {
/*
* Lock the mutex and ignore any
* errors. Note that even
* though this thread may have
* been canceled, POSIX requires
* that the mutex be reaquired
* prior to cancellation.
*/
(void)_mutex_cv_lock(mutex);
} else {
/*
* Lock the condition variable
* while removing the thread.
*/
_SPINLOCK(&(*cond)->lock);
cond_queue_remove(*cond,
curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
(*cond)->c_mutex = NULL;
_SPINUNLOCK(&(*cond)->lock);
/* Lock the mutex: */
rval = _mutex_cv_lock(mutex);
}
}
}
break;
/* Trap invalid condition variable types: */
default:
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
if ((interrupted != 0) && (curthread->continuation != NULL))
curthread->continuation((void *) curthread);
} while ((done == 0) && (rval == 0));
/* Return the completion status: */
return (rval);
}
int
__pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
int ret;
_thread_enter_cancellation_point();
ret = _pthread_cond_wait(cond, mutex);
_thread_leave_cancellation_point();
return (ret);
}
int
_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime)
{
struct pthread *curthread = _get_curthread();
int rval = 0;
int done = 0;
int interrupted = 0;
int seqno;
if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
abstime->tv_nsec >= 1000000000)
return (EINVAL);
/*
* If the condition variable is statically initialized, perform dynamic
* initialization.
*/
if (*cond == NULL && (rval = _pthread_cond_init(cond, NULL)) != 0)
return (rval);
/*
* Enter a loop waiting for a condition signal or broadcast
* to wake up this thread. A loop is needed in case the waiting
* thread is interrupted by a signal to execute a signal handler.
* It is not (currently) possible to remain in the waiting queue
* while running a handler. Instead, the thread is interrupted
* and backed out of the waiting queue prior to executing the
* signal handler.
*/
do {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);
/*
* If the condvar was statically allocated, properly
* initialize the tail queue.
*/
if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) {
TAILQ_INIT(&(*cond)->c_queue);
(*cond)->c_flags |= COND_FLAGS_INITED;
}
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
if ((mutex == NULL) || (((*cond)->c_mutex != NULL) &&
((*cond)->c_mutex != *mutex))) {
/* Return invalid argument error: */
rval = EINVAL;
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
} else {
/* Set the wakeup time: */
curthread->wakeup_time.tv_sec =
abstime->tv_sec;
curthread->wakeup_time.tv_nsec =
abstime->tv_nsec;
/* Reset the timeout and interrupted flags: */
curthread->timeout = 0;
curthread->interrupted = 0;
/*
* Queue the running thread for the condition
* variable:
*/
cond_queue_enq(*cond, curthread);
/* Remember the mutex and sequence number: */
(*cond)->c_mutex = *mutex;
seqno = (*cond)->c_seqno;
/* Unlock the mutex: */
if ((rval = _mutex_cv_unlock(mutex)) != 0) {
/*
* Cannot unlock the mutex, so remove
* the running thread from the condition
* variable queue:
*/
cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
(*cond)->c_mutex = NULL;
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
} else {
/*
* Schedule the next thread and unlock
* the condition variable structure:
*/
_thread_kern_sched_state_unlock(PS_COND_WAIT,
&(*cond)->lock, __FILE__, __LINE__);
done = (seqno != (*cond)->c_seqno);
interrupted = curthread->interrupted;
/*
* Check if the wait was interrupted
* (canceled) or needs to be resumed
* after handling a signal.
*/
if (interrupted != 0) {
/*
* Lock the mutex and ignore any
* errors. Note that even
* though this thread may have
* been canceled, POSIX requires
* that the mutex be reaquired
* prior to cancellation.
*/
(void)_mutex_cv_lock(mutex);
} else {
/*
* Lock the condition variable
* while removing the thread.
*/
_SPINLOCK(&(*cond)->lock);
cond_queue_remove(*cond,
curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
(*cond)->c_mutex = NULL;
_SPINUNLOCK(&(*cond)->lock);
/* Lock the mutex: */
rval = _mutex_cv_lock(mutex);
/*
* Return ETIMEDOUT if the wait
* timed out and there wasn't an
* error locking the mutex:
*/
if ((curthread->timeout != 0)
&& rval == 0)
rval = ETIMEDOUT;
}
}
}
break;
/* Trap invalid condition variable types: */
default:
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
if ((interrupted != 0) && (curthread->continuation != NULL))
curthread->continuation((void *) curthread);
} while ((done == 0) && (rval == 0));
/* Return the completion status: */
return (rval);
}
int
__pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime)
{
int ret;
_thread_enter_cancellation_point();
ret = _pthread_cond_timedwait(cond, mutex, abstime);
_thread_enter_cancellation_point();
return (ret);
}
int
_pthread_cond_signal(pthread_cond_t *cond)
{
int rval = 0;
pthread_t pthread;
if (cond == NULL)
rval = EINVAL;
/*
* If the condition variable is statically initialized, perform dynamic
* initialization.
*/
else if (*cond != NULL ||
(rval = _pthread_cond_init(cond, NULL)) == 0) {
/*
* Defer signals to protect the scheduling queues
* from access by the signal handler:
*/
_thread_kern_sig_defer();
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
/* Increment the sequence number: */
(*cond)->c_seqno++;
if ((pthread = cond_queue_deq(*cond)) != NULL) {
/*
* Wake up the signaled thread:
*/
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
}
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
(*cond)->c_mutex = NULL;
break;
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/*
* Undefer and handle pending signals, yielding if
* necessary:
*/
_thread_kern_sig_undefer();
}
/* Return the completion status: */
return (rval);
}
int
_pthread_cond_broadcast(pthread_cond_t *cond)
{
int rval = 0;
pthread_t pthread;
if (cond == NULL)
rval = EINVAL;
/*
* If the condition variable is statically initialized, perform dynamic
* initialization.
*/
else if (*cond != NULL ||
(rval = _pthread_cond_init(cond, NULL)) == 0) {
/*
* Defer signals to protect the scheduling queues
* from access by the signal handler:
*/
_thread_kern_sig_defer();
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
/* Increment the sequence number: */
(*cond)->c_seqno++;
/*
* Enter a loop to bring all threads off the
* condition queue:
*/
while ((pthread = cond_queue_deq(*cond)) != NULL) {
/*
* Wake up the signaled thread:
*/
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
}
/* There are no more waiting threads: */
(*cond)->c_mutex = NULL;
break;
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/*
* Undefer and handle pending signals, yielding if
* necessary:
*/
_thread_kern_sig_undefer();
}
/* Return the completion status: */
return (rval);
}
void
_cond_wait_backout(pthread_t pthread)
{
pthread_cond_t cond;
cond = pthread->data.cond;
if (cond != NULL) {
/*
* Defer signals to protect the scheduling queues
* from access by the signal handler:
*/
_thread_kern_sig_defer();
/* Lock the condition variable structure: */
_SPINLOCK(&cond->lock);
/* Process according to condition variable type: */
switch (cond->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
cond_queue_remove(cond, pthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&cond->c_queue) == NULL)
cond->c_mutex = NULL;
break;
default:
break;
}
/* Unlock the condition variable structure: */
_SPINUNLOCK(&cond->lock);
/*
* Undefer and handle pending signals, yielding if
* necessary:
*/
_thread_kern_sig_undefer();
}
}
/*
* Dequeue a waiting thread from the head of a condition queue in
* descending priority order.
*/
static inline pthread_t
cond_queue_deq(pthread_cond_t cond)
{
pthread_t pthread;
while ((pthread = TAILQ_FIRST(&cond->c_queue)) != NULL) {
TAILQ_REMOVE(&cond->c_queue, pthread, sqe);
pthread->flags &= ~PTHREAD_FLAGS_IN_CONDQ;
if ((pthread->timeout == 0) && (pthread->interrupted == 0))
/*
* Only exit the loop when we find a thread
* that hasn't timed out or been canceled;
* those threads are already running and don't
* need their run state changed.
*/
break;
}
return(pthread);
}
/*
* Remove a waiting thread from a condition queue in descending priority
* order.
*/
static inline void
cond_queue_remove(pthread_cond_t cond, pthread_t pthread)
{
/*
* Because pthread_cond_timedwait() can timeout as well
* as be signaled by another thread, it is necessary to
* guard against removing the thread from the queue if
* it isn't in the queue.
*/
if (pthread->flags & PTHREAD_FLAGS_IN_CONDQ) {
TAILQ_REMOVE(&cond->c_queue, pthread, sqe);
pthread->flags &= ~PTHREAD_FLAGS_IN_CONDQ;
}
}
/*
* Enqueue a waiting thread to a condition queue in descending priority
* order.
*/
static inline void
cond_queue_enq(pthread_cond_t cond, pthread_t pthread)
{
pthread_t tid = TAILQ_LAST(&cond->c_queue, cond_head);
PTHREAD_ASSERT_NOT_IN_SYNCQ(pthread);
/*
* For the common case of all threads having equal priority,
* we perform a quick check against the priority of the thread
* at the tail of the queue.
*/
if ((tid == NULL) || (pthread->active_priority <= tid->active_priority))
TAILQ_INSERT_TAIL(&cond->c_queue, pthread, sqe);
else {
tid = TAILQ_FIRST(&cond->c_queue);
while (pthread->active_priority <= tid->active_priority)
tid = TAILQ_NEXT(tid, sqe);
TAILQ_INSERT_BEFORE(tid, pthread, sqe);
}
pthread->flags |= PTHREAD_FLAGS_IN_CONDQ;
pthread->data.cond = cond;
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_condattr_destroy, pthread_condattr_destroy);
int
_pthread_condattr_destroy(pthread_condattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;
ret = 0;
}
return(ret);
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_condattr_init, pthread_condattr_init);
static struct pthread_cond_attr default_condattr = PTHREAD_CONDATTR_DEFAULT;
int
_pthread_condattr_init(pthread_condattr_t *attr)
{
int ret;
pthread_condattr_t pattr;
if ((pattr = (pthread_condattr_t)
malloc(sizeof(struct pthread_cond_attr))) == NULL) {
ret = ENOMEM;
} else {
memcpy(pattr, &default_condattr,
sizeof(struct pthread_cond_attr));
*attr = pattr;
ret = 0;
}
return(ret);
}

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(__connect, connect);
int
_connect(int fd, const struct sockaddr * name, socklen_t namelen)
{
struct pthread *curthread = _get_curthread();
struct sockaddr tmpname;
int errnolen, ret, tmpnamelen;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
if ((ret = __sys_connect(fd, name, namelen)) < 0) {
if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0
&& ((errno == EWOULDBLOCK) || (errno == EINPROGRESS)
|| (errno == EALREADY) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
tmpnamelen = sizeof(tmpname);
/* 0 now lets see if it really worked */
if (((ret = __sys_getpeername(fd, &tmpname, &tmpnamelen)) < 0) && (errno == ENOTCONN)) {
/*
* Get the error, this function
* should not fail
*/
errnolen = sizeof(errno);
__sys_getsockopt(fd, SOL_SOCKET, SO_ERROR, &errno, &errnolen);
}
} else {
ret = -1;
}
}
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}
int
__connect(int fd, const struct sockaddr * name, socklen_t namelen)
{
int ret;
_thread_enter_cancellation_point();
ret = _connect(fd, name, namelen);
_thread_leave_cancellation_point();
return (ret);
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer as
* the first lines of this file unmodified other than the possible
* addition of one or more copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <fcntl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(___creat, creat);
int
___creat(const char *path, mode_t mode)
{
int ret;
_thread_enter_cancellation_point();
ret = __creat(path, mode);
_thread_leave_cancellation_point();
return ret;
}

View File

@ -1,281 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/time.h>
#include <machine/reg.h>
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
#include "pthread_private.h"
#include "libc_private.h"
static u_int64_t next_uniqueid = 1;
#define OFF(f) offsetof(struct pthread, f)
int _thread_next_offset = OFF(tle.tqe_next);
int _thread_uniqueid_offset = OFF(uniqueid);
int _thread_state_offset = OFF(state);
int _thread_name_offset = OFF(name);
int _thread_ctx_offset = OFF(ctx);
#undef OFF
int _thread_PS_RUNNING_value = PS_RUNNING;
int _thread_PS_DEAD_value = PS_DEAD;
__weak_reference(_pthread_create, pthread_create);
int
_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
struct pthread *curthread = _get_curthread();
struct itimerval itimer;
int f_gc = 0;
int ret = 0;
pthread_t gc_thread;
pthread_t new_thread;
pthread_attr_t pattr;
void *stack;
#if !defined(__ia64__)
u_long stackp;
#endif
if (thread == NULL)
return(EINVAL);
/*
* Locking functions in libc are required when there are
* threads other than the initial thread.
*/
__isthreaded = 1;
/* Allocate memory for the thread structure: */
if ((new_thread = (pthread_t) malloc(sizeof(struct pthread))) == NULL) {
/* Insufficient memory to create a thread: */
ret = EAGAIN;
} else {
/* Check if default thread attributes are required: */
if (attr == NULL || *attr == NULL) {
/* Use the default thread attributes: */
pattr = &_pthread_attr_default;
} else {
pattr = *attr;
}
/* Check if a stack was specified in the thread attributes: */
if ((stack = pattr->stackaddr_attr) != NULL) {
}
/* Allocate a stack: */
else {
stack = _thread_stack_alloc(pattr->stacksize_attr,
pattr->guardsize_attr);
if (stack == NULL) {
ret = EAGAIN;
free(new_thread);
}
}
/* Check for errors: */
if (ret != 0) {
} else {
/* Initialise the thread structure: */
memset(new_thread, 0, sizeof(struct pthread));
new_thread->slice_usec = -1;
new_thread->stack = stack;
new_thread->start_routine = start_routine;
new_thread->arg = arg;
new_thread->cancelflags = PTHREAD_CANCEL_ENABLE |
PTHREAD_CANCEL_DEFERRED;
/*
* Write a magic value to the thread structure
* to help identify valid ones:
*/
new_thread->magic = PTHREAD_MAGIC;
/* Initialise the thread for signals: */
new_thread->sigmask = curthread->sigmask;
new_thread->sigmask_seqno = 0;
/* Initialize the signal frame: */
new_thread->curframe = NULL;
/* Initialise the jump buffer: */
_setjmp(new_thread->ctx.jb);
/*
* Set up new stack frame so that it looks like it
* returned from a longjmp() to the beginning of
* _thread_start().
*/
SET_RETURN_ADDR_JB(new_thread->ctx.jb, _thread_start);
#if !defined(__ia64__)
stackp = (long)new_thread->stack + pattr->stacksize_attr - sizeof(double);
#if defined(__amd64__)
stackp &= ~0xFUL;
#endif
/* The stack starts high and builds down: */
SET_STACK_JB(new_thread->ctx.jb, stackp);
#else
SET_STACK_JB(new_thread->ctx.jb,
(long)new_thread->stack, pattr->stacksize_attr);
#endif
/* Copy the thread attributes: */
memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr));
/*
* Check if this thread is to inherit the scheduling
* attributes from its parent:
*/
if (new_thread->attr.flags & PTHREAD_INHERIT_SCHED) {
/* Copy the scheduling attributes: */
new_thread->base_priority =
curthread->base_priority &
~PTHREAD_SIGNAL_PRIORITY;
new_thread->attr.prio =
curthread->base_priority &
~PTHREAD_SIGNAL_PRIORITY;
new_thread->attr.sched_policy =
curthread->attr.sched_policy;
} else {
/*
* Use just the thread priority, leaving the
* other scheduling attributes as their
* default values:
*/
new_thread->base_priority =
new_thread->attr.prio;
}
new_thread->active_priority = new_thread->base_priority;
new_thread->inherited_priority = 0;
/* Initialize joiner to NULL (no joiner): */
new_thread->joiner = NULL;
/* Initialize the mutex queue: */
TAILQ_INIT(&new_thread->mutexq);
/* Initialise hooks in the thread structure: */
new_thread->specific = NULL;
new_thread->cleanup = NULL;
new_thread->flags = 0;
new_thread->poll_data.nfds = 0;
new_thread->poll_data.fds = NULL;
new_thread->continuation = NULL;
/*
* Defer signals to protect the scheduling queues
* from access by the signal handler:
*/
_thread_kern_sig_defer();
/*
* Initialise the unique id which GDB uses to
* track threads.
*/
new_thread->uniqueid = next_uniqueid++;
/*
* Check if the garbage collector thread
* needs to be started.
*/
f_gc = (TAILQ_FIRST(&_thread_list) == _thread_initial);
/* Add the thread to the linked list of all threads: */
TAILQ_INSERT_HEAD(&_thread_list, new_thread, tle);
if (pattr->suspend == PTHREAD_CREATE_SUSPENDED) {
new_thread->flags |= PTHREAD_FLAGS_SUSPENDED;
new_thread->state = PS_SUSPENDED;
} else {
new_thread->state = PS_RUNNING;
PTHREAD_PRIOQ_INSERT_TAIL(new_thread);
}
/*
* Undefer and handle pending signals, yielding
* if necessary.
*/
_thread_kern_sig_undefer();
/* Return a pointer to the thread structure: */
(*thread) = new_thread;
if (f_gc != 0) {
/* Install the scheduling timer: */
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = _clock_res_usec;
itimer.it_value = itimer.it_interval;
if (setitimer(_ITIMER_SCHED_TIMER, &itimer,
NULL) != 0)
PANIC("Cannot set interval timer");
}
/* Schedule the new user thread: */
_thread_kern_sched(NULL);
/*
* Start a garbage collector thread
* if necessary.
*/
if (f_gc && _pthread_create(&gc_thread, NULL,
_thread_gc, NULL) != 0)
PANIC("Can't create gc thread");
}
}
/* Return the status: */
return (ret);
}
void
_thread_start(void)
{
struct pthread *curthread = _get_curthread();
/* We just left the scheduler via longjmp: */
_thread_kern_in_sched = 0;
/* Run the current thread's start routine with argument: */
_pthread_exit(curthread->start_routine(curthread->arg));
/* This point should never be reached. */
PANIC("Thread has resumed after exit");
}

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_detach, pthread_detach);
int
_pthread_detach(pthread_t pthread)
{
int rval = 0;
/* Check for invalid calling parameters: */
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
/* Return an invalid argument error: */
rval = EINVAL;
/* Check if the thread has not been detached: */
else if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) {
/* Flag the thread as detached: */
pthread->attr.flags |= PTHREAD_DETACHED;
/*
* Defer signals to protect the scheduling queues from
* access by the signal handler:
*/
_thread_kern_sig_defer();
/* Check if there is a joiner: */
if (pthread->joiner != NULL) {
struct pthread *joiner = pthread->joiner;
/* Make the thread runnable: */
PTHREAD_NEW_STATE(joiner, PS_RUNNING);
/* Set the return value for the woken thread: */
joiner->join_status.error = ESRCH;
joiner->join_status.ret = NULL;
joiner->join_status.thread = NULL;
/*
* Disconnect the joiner from the thread being detached:
*/
pthread->joiner = NULL;
}
/*
* Undefer and handle pending signals, yielding if a
* scheduling signal occurred while in the critical region.
*/
_thread_kern_sig_undefer();
} else
/* Return an error: */
rval = EINVAL;
/* Return the completion status: */
return (rval);
}

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_dup, dup);
int
_dup(int fd)
{
int ret;
/* Lock the file descriptor: */
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
/* Perform the 'dup' syscall: */
if ((ret = __sys_dup(fd)) < 0) {
}
/* Initialise the file descriptor table entry: */
else if (_thread_fd_table_init(ret) != 0) {
/* Quietly close the file: */
__sys_close(ret);
/* Reset the file descriptor: */
ret = -1;
} else {
/*
* Save the file open flags so that they can be
* checked later:
*/
_thread_fd_setflags(ret, _thread_fd_getflags(fd));
}
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
/* Return the completion status: */
return (ret);
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_dup2, dup2);
int
_dup2(int fd, int newfd)
{
int ret;
int newfd_opened;
/* Check if the file descriptor is out of range: */
if (newfd < 0 || newfd >= _thread_dtablesize ||
newfd == _thread_kern_pipe[0] || newfd == _thread_kern_pipe[1]) {
/* Return a bad file descriptor error: */
errno = EBADF;
ret = -1;
}
/* Lock the file descriptor: */
else if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
/* Lock the file descriptor: */
if (!(newfd_opened = (_thread_fd_table[newfd] != NULL)) ||
(ret = _FD_LOCK(newfd, FD_RDWR, NULL)) == 0) {
/* Perform the 'dup2' syscall: */
ret = __sys_dup2(fd, newfd);
if (ret >= 0) {
/*
* If we are duplicating one of the standard
* file descriptors, update its flags in the
* table of pthread stdio descriptor flags.
*/
if (ret < 3) {
_pthread_stdio_flags[ret] =
_thread_fd_table[fd]->flags;
}
/* Initialise the file descriptor table entry */
if (_thread_fd_table_init(ret) != 0) {
/* Quietly close the file: */
__sys_close(ret);
/* Reset the file descriptor: */
ret = -1;
} else {
/*
* Save the file open flags so that
* they can be checked later:
*/
_thread_fd_setflags(ret,
_thread_fd_getflags(fd));
}
}
/* Unlock the file descriptor: */
if (newfd_opened)
_FD_UNLOCK(newfd, FD_RDWR);
}
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
/* Return the completion status: */
return (ret);
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_equal, pthread_equal);
int
_pthread_equal(pthread_t t1, pthread_t t2)
{
/* Compare the two thread pointers: */
return (t1 == t2);
}

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_execve, execve);
int
_execve(const char *name, char *const * argv, char *const * envp)
{
struct pthread *curthread = _get_curthread();
int flags;
int i;
int ret;
struct sigaction act;
struct sigaction oact;
struct itimerval itimer;
/* Disable the interval timer: */
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL);
/* Close the pthread kernel pipe: */
__sys_close(_thread_kern_pipe[0]);
__sys_close(_thread_kern_pipe[1]);
/*
* Enter a loop to set all file descriptors to blocking
* if they were not created as non-blocking:
*/
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
(_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Skip if the close-on-exec flag is set */
flags = __sys_fcntl(i, F_GETFD, NULL);
if ((flags & FD_CLOEXEC) != 0)
continue; /* don't bother, no point */
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
__sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
}
}
/* Enter a loop to adopt the signal actions for the running thread: */
for (i = 1; i < NSIG; i++) {
/* Check for signals which cannot be caught: */
if (i == SIGKILL || i == SIGSTOP) {
/* Don't do anything with these signals. */
} else {
/* Check if ignoring this signal: */
if (_thread_sigact[i - 1].sa_handler == SIG_IGN) {
/* Continue to ignore this signal: */
act.sa_handler = SIG_IGN;
} else {
/* Use the default handler for this signal: */
act.sa_handler = SIG_DFL;
}
/* Copy the mask and flags for this signal: */
act.sa_mask = _thread_sigact[i - 1].sa_mask;
act.sa_flags = _thread_sigact[i - 1].sa_flags;
/* Change the signal action for the process: */
__sys_sigaction(i, &act, &oact);
}
}
/* Set the signal mask: */
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
/* Execute the process: */
ret = __sys_execve(name, argv, envp);
/* Return the completion status: */
return (ret);
}

View File

@ -1,224 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
#include "pthread_private.h"
__weak_reference(_pthread_exit, pthread_exit);
void
_exit(int status)
{
int flags;
int i;
struct itimerval itimer;
/* Disable the interval timer: */
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL);
/* Close the pthread kernel pipe: */
__sys_close(_thread_kern_pipe[0]);
__sys_close(_thread_kern_pipe[1]);
/*
* Enter a loop to set all file descriptors to blocking
* if they were not created as non-blocking:
*/
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
(_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
__sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
}
}
/* Call the _exit syscall: */
__sys_exit(status);
}
void
_thread_exit(char *fname, int lineno, char *string)
{
char s[256];
/* Prepare an error message string: */
snprintf(s, sizeof(s),
"Fatal error '%s' at line %d in file %s (errno = %d)\n",
string, lineno, fname, errno);
/* Write the string to the standard error file descriptor: */
__sys_write(2, s, strlen(s));
/* Force this process to exit: */
/* XXX - Do we want abort to be conditional on _PTHREADS_INVARIANTS? */
#if defined(_PTHREADS_INVARIANTS)
abort();
#else
__sys_exit(1);
#endif
}
/*
* Only called when a thread is cancelled. It may be more useful
* to call it from pthread_exit() if other ways of asynchronous or
* abnormal thread termination can be found.
*/
void
_thread_exit_cleanup(void)
{
struct pthread *curthread = _get_curthread();
/*
* POSIX states that cancellation/termination of a thread should
* not release any visible resources (such as mutexes) and that
* it is the applications responsibility. Resources that are
* internal to the threads library, including file and fd locks,
* are not visible to the application and need to be released.
*/
/* Unlock all owned fd locks: */
_thread_fd_unlock_owned(curthread);
/* Unlock all private mutexes: */
_mutex_unlock_private(curthread);
/*
* This still isn't quite correct because we don't account
* for held spinlocks (see libc/stdlib/malloc.c).
*/
}
void
_pthread_exit(void *status)
{
struct pthread *curthread = _get_curthread();
pthread_t pthread;
/* Check if this thread is already in the process of exiting: */
if ((curthread->flags & PTHREAD_EXITING) != 0) {
char msg[128];
snprintf(msg, sizeof(msg), "Thread %p has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!",curthread);
PANIC(msg);
}
/* Flag this thread as exiting: */
curthread->flags |= PTHREAD_EXITING;
/* Save the return value: */
curthread->ret = status;
while (curthread->cleanup != NULL) {
pthread_cleanup_pop(1);
}
if (curthread->attr.cleanup_attr != NULL) {
curthread->attr.cleanup_attr(curthread->attr.arg_attr);
}
/* Check if there is thread specific data: */
if (curthread->specific != NULL) {
/* Run the thread-specific data destructors: */
_thread_cleanupspecific();
}
/* Free thread-specific poll_data structure, if allocated: */
if (curthread->poll_data.fds != NULL) {
free(curthread->poll_data.fds);
curthread->poll_data.fds = NULL;
}
/*
* Lock the garbage collector mutex to ensure that the garbage
* collector is not using the dead thread list.
*/
if (_pthread_mutex_lock(&_gc_mutex) != 0)
PANIC("Cannot lock gc mutex");
/* Add this thread to the list of dead threads. */
TAILQ_INSERT_HEAD(&_dead_list, curthread, dle);
/*
* Signal the garbage collector thread that there is something
* to clean up.
*/
if (_pthread_cond_signal(&_gc_cond) != 0)
PANIC("Cannot signal gc cond");
/*
* Avoid a race condition where a scheduling signal can occur
* causing the garbage collector thread to run. If this happens,
* the current thread can be cleaned out from under us.
*/
_thread_kern_sig_defer();
/* Unlock the garbage collector mutex: */
if (_pthread_mutex_unlock(&_gc_mutex) != 0)
PANIC("Cannot unlock gc mutex");
/* Check if there is a thread joining this one: */
if (curthread->joiner != NULL) {
pthread = curthread->joiner;
curthread->joiner = NULL;
/* Make the joining thread runnable: */
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
/* Set the return value for the joining thread: */
pthread->join_status.ret = curthread->ret;
pthread->join_status.error = 0;
pthread->join_status.thread = NULL;
/* Make this thread collectable by the garbage collector. */
PTHREAD_ASSERT(((curthread->attr.flags & PTHREAD_DETACHED) ==
0), "Cannot join a detached thread");
curthread->attr.flags |= PTHREAD_DETACHED;
}
/* Remove this thread from the thread list: */
TAILQ_REMOVE(&_thread_list, curthread, tle);
/* This thread will never be re-scheduled. */
_thread_kern_sched_state(PS_DEAD, __FILE__, __LINE__);
/* This point should not be reached. */
PANIC("Dead thread has resumed");
}

View File

@ -1,24 +0,0 @@
/*
* David Leonard <d@openbsd.org>, 1999. Public Domain.
*
* $OpenBSD: uthread_fchflags.c,v 1.1 1999/01/08 05:42:18 d Exp $
* $FreeBSD$
*/
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fchflags, fchflags);
int
_fchflags(int fd, u_long flags)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
ret = __sys_fchflags(fd, flags);
_FD_UNLOCK(fd, FD_WRITE);
}
return (ret);
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fchmod, fchmod);
int
_fchmod(int fd, mode_t mode)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
ret = __sys_fchmod(fd, mode);
_FD_UNLOCK(fd, FD_WRITE);
}
return (ret);
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fchown, fchown);
int
_fchown(int fd, uid_t owner, gid_t group)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
ret = __sys_fchown(fd, owner, group);
_FD_UNLOCK(fd, FD_WRITE);
}
return (ret);
}

View File

@ -1,170 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(__fcntl, fcntl);
extern int __fcntl_compat(int fd, int cmd, ...);
int
_fcntl(int fd, int cmd,...)
{
int flags = 0;
int nonblock;
int oldfd;
int ret;
va_list ap;
/* Lock the file descriptor: */
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
/* Initialise the variable argument list: */
va_start(ap, cmd);
/* Process according to file control command type: */
switch (cmd) {
/* Duplicate a file descriptor: */
case F_DUPFD:
/*
* Get the file descriptor that the caller wants to
* use:
*/
oldfd = va_arg(ap, int);
/* Initialise the file descriptor table entry: */
if ((ret = __sys_fcntl(fd, cmd, oldfd)) < 0) {
}
/* Initialise the file descriptor table entry: */
else if (_thread_fd_table_init(ret) != 0) {
/* Quietly close the file: */
__sys_close(ret);
/* Reset the file descriptor: */
ret = -1;
} else {
/*
* Save the file open flags so that they can
* be checked later:
*/
_thread_fd_setflags(ret,
_thread_fd_getflags(fd));
}
break;
case F_SETFD:
flags = va_arg(ap, int);
ret = __sys_fcntl(fd, cmd, flags);
break;
case F_GETFD:
ret = __sys_fcntl(fd, cmd, 0);
break;
case F_GETFL:
ret = _thread_fd_getflags(fd);
break;
case F_SETFL:
/*
* Get the file descriptor flags passed by the
* caller:
*/
flags = va_arg(ap, int);
/*
* Check if the user wants a non-blocking file
* descriptor:
*/
nonblock = flags & O_NONBLOCK;
/* Set the file descriptor flags: */
if ((ret = __sys_fcntl(fd, cmd, flags | O_NONBLOCK)) != 0) {
/* Get the flags so that we behave like the kernel: */
} else if ((flags = __sys_fcntl(fd,
F_GETFL, 0)) == -1) {
/* Error getting flags: */
ret = -1;
/*
* Check if the file descriptor is non-blocking
* with respect to the user:
*/
} else if (nonblock)
/* A non-blocking descriptor: */
_thread_fd_setflags(fd, flags | O_NONBLOCK);
else
/* Save the flags: */
_thread_fd_setflags(fd, flags & ~O_NONBLOCK);
break;
default:
/* Might want to make va_arg use a union */
ret = __fcntl_compat(fd, cmd, va_arg(ap, void *));
break;
}
/* Free variable arguments: */
va_end(ap);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
/* Return the completion status: */
return (ret);
}
int
__fcntl(int fd, int cmd,...)
{
int ret;
va_list ap;
_thread_enter_cancellation_point();
va_start(ap, cmd);
switch (cmd) {
case F_DUPFD:
case F_SETFD:
case F_SETFL:
ret = _fcntl(fd, cmd, va_arg(ap, int));
break;
case F_GETFD:
case F_GETFL:
ret = _fcntl(fd, cmd);
break;
default:
ret = _fcntl(fd, cmd, va_arg(ap, void *));
}
va_end(ap);
_thread_leave_cancellation_point();
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by John Birrell.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*
* POSIX stdio FILE locking functions. These assume that the locking
* is only required at FILE structure level, not at file descriptor
* level too.
*
*/
#include <stdio.h>
#include <pthread.h>
#include "pthread_private.h"
extern void _flockfile(FILE *);
void
_flockfile_debug(FILE *fp, char *fname, int lineno)
{
pthread_t curthread = _pthread_self();
curthread->lineno = lineno;
curthread->fname = fname;
_flockfile(fp);
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
/* Find a thread in the linked list of active threads: */
int
_find_thread(pthread_t pthread)
{
pthread_t pthread1;
/* Check if the caller has specified an invalid thread: */
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
/* Invalid thread: */
return(EINVAL);
/*
* Defer signals to protect the thread list from access
* by the signal handler:
*/
_thread_kern_sig_defer();
/* Search for the specified thread: */
TAILQ_FOREACH(pthread1, &_thread_list, tle) {
if (pthread == pthread1)
break;
}
/* Undefer and handle pending signals, yielding if necessary: */
_thread_kern_sig_undefer();
/* Return zero if the thread exists: */
return ((pthread1 != NULL) ? 0:ESRCH);
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/file.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_flock, flock);
int
_flock(int fd, int operation)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = __sys_flock(fd, operation);
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}

View File

@ -1,262 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include "pthread_private.h"
static void free_thread_resources(struct pthread *thread);
__weak_reference(_fork, fork);
pid_t
_fork(void)
{
struct pthread *curthread = _get_curthread();
struct pthread_atfork *af;
int i, flags, use_deadlist = 0;
pid_t ret;
pthread_t pthread;
pthread_t pthread_save;
/*
* Defer signals to protect the scheduling queues from access
* by the signal handler:
*/
_thread_kern_sig_defer();
_pthread_mutex_lock(&_atfork_mutex);
/* Run down atfork prepare handlers. */
TAILQ_FOREACH_REVERSE(af, &_atfork_list, atfork_head, qe) {
if (af->prepare != NULL)
af->prepare();
}
/* Fork a new process: */
if ((ret = __sys_fork()) != 0) {
/* Run down atfork parent handlers. */
TAILQ_FOREACH(af, &_atfork_list, qe) {
if (af->parent != NULL)
af->parent();
}
_pthread_mutex_unlock(&_atfork_mutex);
} else {
/* Close the pthread kernel pipe: */
__sys_close(_thread_kern_pipe[0]);
__sys_close(_thread_kern_pipe[1]);
/* Reset signals pending for the running thread: */
sigemptyset(&curthread->sigpend);
/*
* Create a pipe that is written to by the signal handler to
* prevent signals being missed in calls to
* __sys_select:
*/
if (__sys_pipe(_thread_kern_pipe) != 0) {
/* Cannot create pipe, so abort: */
PANIC("Cannot create pthread kernel pipe for forked process");
}
/* Get the flags for the read pipe: */
else if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
/* Abort this application: */
abort();
}
/* Make the read pipe non-blocking: */
else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
/* Abort this application: */
abort();
}
/* Get the flags for the write pipe: */
else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
/* Abort this application: */
abort();
}
/* Make the write pipe non-blocking: */
else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
/* Abort this application: */
abort();
}
/* Reinitialize the GC mutex: */
else if (_mutex_reinit(&_gc_mutex) != 0) {
/* Abort this application: */
PANIC("Cannot initialize GC mutex for forked process");
}
/* Reinitialize the GC condition variable: */
else if (_cond_reinit(&_gc_cond) != 0) {
/* Abort this application: */
PANIC("Cannot initialize GC condvar for forked process");
}
/* Initialize the ready queue: */
else if (_pq_init(&_readyq) != 0) {
/* Abort this application: */
PANIC("Cannot initialize priority ready queue.");
} else {
/*
* Enter a loop to remove all threads other than
* the running thread from the thread list:
*/
if ((pthread = TAILQ_FIRST(&_thread_list)) == NULL) {
pthread = TAILQ_FIRST(&_dead_list);
use_deadlist = 1;
}
while (pthread != NULL) {
/* Save the thread to be freed: */
pthread_save = pthread;
/*
* Advance to the next thread before
* destroying the current thread:
*/
if (use_deadlist != 0)
pthread = TAILQ_NEXT(pthread, dle);
else
pthread = TAILQ_NEXT(pthread, tle);
/* Make sure this isn't the running thread: */
if (pthread_save != curthread) {
/*
* Remove this thread from the
* appropriate list:
*/
if (use_deadlist != 0)
TAILQ_REMOVE(&_thread_list,
pthread_save, dle);
else
TAILQ_REMOVE(&_thread_list,
pthread_save, tle);
free_thread_resources(pthread_save);
}
/*
* Switch to the deadlist when the active
* thread list has been consumed. This can't
* be at the top of the loop because it is
* used to determine to which list the thread
* belongs (when it is removed from the list).
*/
if (pthread == NULL) {
pthread = TAILQ_FIRST(&_dead_list);
use_deadlist = 1;
}
}
/* Treat the current thread as the initial thread: */
_thread_initial = curthread;
/* Re-init the dead thread list: */
TAILQ_INIT(&_dead_list);
/* Re-init the waiting and work queues. */
TAILQ_INIT(&_waitingq);
TAILQ_INIT(&_workq);
/* Re-init the threads mutex queue: */
TAILQ_INIT(&curthread->mutexq);
/* No spinlocks yet: */
_spinblock_count = 0;
/* Don't queue signals yet: */
_queue_signals = 0;
/* Initialize the scheduling switch hook routine: */
_sched_switch_hook = NULL;
/* Clear out any locks in the file descriptor table: */
for (i = 0; i < _thread_dtablesize; i++) {
if (_thread_fd_table[i] != NULL) {
/* Initialise the file locks: */
memset(&_thread_fd_table[i]->lock, 0,
sizeof(_thread_fd_table[i]->lock));
_thread_fd_table[i]->r_owner = NULL;
_thread_fd_table[i]->w_owner = NULL;
_thread_fd_table[i]->r_fname = NULL;
_thread_fd_table[i]->w_fname = NULL;
_thread_fd_table[i]->r_lineno = 0;;
_thread_fd_table[i]->w_lineno = 0;;
_thread_fd_table[i]->r_lockcount = 0;;
_thread_fd_table[i]->w_lockcount = 0;;
/* Initialise the read/write queues: */
TAILQ_INIT(&_thread_fd_table[i]->r_queue);
TAILQ_INIT(&_thread_fd_table[i]->w_queue);
}
}
}
/* Run down atfork child handlers. */
TAILQ_FOREACH(af, &_atfork_list, qe) {
if (af->child != NULL)
af->child();
}
_mutex_reinit(&_atfork_mutex);
}
/*
* Undefer and handle pending signals, yielding if necessary:
*/
_thread_kern_sig_undefer();
/* Return the process ID: */
return (ret);
}
static void
free_thread_resources(struct pthread *thread)
{
/* Check to see if the threads library allocated the stack. */
if ((thread->attr.stackaddr_attr == NULL) && (thread->stack != NULL)) {
/*
* Since this is being called from fork, we are currently single
* threaded so there is no need to protect the call to
* _thread_stack_free() with _gc_mutex.
*/
_thread_stack_free(thread->stack, thread->attr.stacksize_attr,
thread->attr.guardsize_attr);
}
if (thread->specific != NULL)
free(thread->specific);
if (thread->poll_data.fds != NULL)
free(thread->poll_data.fds);
free(thread);
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2000 Maxim Sobolev <sobomax@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fpathconf, fpathconf);
long
_fpathconf(int fd, int name)
{
long ret;
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
ret = __sys_fpathconf(fd, name);
_FD_UNLOCK(fd, FD_READ);
}
return ret;
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fstat, fstat);
int
_fstat(int fd, struct stat * buf)
{
int ret;
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the file status: */
ret = __sys_fstat(fd, buf);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_READ);
}
return (ret);
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_fstatfs, fstatfs);
int
_fstatfs(int fd, struct statfs * buf)
{
int ret;
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the file system status: */
ret = __sys_fstatfs(fd, buf);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_READ);
}
return (ret);
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <unistd.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(__fsync, fsync);
int
_fsync(int fd)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = __sys_fsync(fd);
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}
int
__fsync(int fd)
{
int ret;
_thread_enter_cancellation_point();
ret = _fsync(fd);
_thread_leave_cancellation_point();
return ret;
}

View File

@ -1,218 +0,0 @@
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*
* Garbage collector thread. Frees memory allocated for dead threads.
*
*/
#include <sys/param.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
#include "pthread_private.h"
pthread_addr_t
_thread_gc(pthread_addr_t arg)
{
struct pthread *curthread = _get_curthread();
int f_debug;
int f_done = 0;
int ret;
sigset_t mask;
pthread_t pthread;
pthread_t pthread_cln;
struct timespec abstime;
void *p_stack;
/* Block all signals */
sigfillset(&mask);
_pthread_sigmask(SIG_BLOCK, &mask, NULL);
/* Mark this thread as a library thread (not a user thread). */
curthread->flags |= PTHREAD_FLAGS_PRIVATE;
/* Set a debug flag based on an environment variable. */
f_debug = (getenv("LIBC_R_DEBUG") != NULL);
/* Set the name of this thread. */
pthread_set_name_np(curthread,"GC");
while (!f_done) {
/* Check if debugging this application. */
if (f_debug)
/* Dump thread info to file. */
_thread_dump_info();
/*
* Defer signals to protect the scheduling queues from
* access by the signal handler:
*/
_thread_kern_sig_defer();
/* Check if this is the last running thread: */
if (TAILQ_FIRST(&_thread_list) == curthread &&
TAILQ_NEXT(curthread, tle) == NULL)
/*
* This is the last thread, so it can exit
* now.
*/
f_done = 1;
/*
* Undefer and handle pending signals, yielding if
* necessary:
*/
_thread_kern_sig_undefer();
/* No stack of thread structure to free yet: */
p_stack = NULL;
pthread_cln = NULL;
/*
* Lock the garbage collector mutex which ensures that
* this thread sees another thread exit:
*/
if (_pthread_mutex_lock(&_gc_mutex) != 0)
PANIC("Cannot lock gc mutex");
/*
* Enter a loop to search for the first dead thread that
* has memory to free.
*/
for (pthread = TAILQ_FIRST(&_dead_list);
p_stack == NULL && pthread_cln == NULL && pthread != NULL;
pthread = TAILQ_NEXT(pthread, dle)) {
/* Check if the initial thread: */
if (pthread == _thread_initial) {
/* Don't destroy the initial thread. */
}
/*
* Check if this thread has detached:
*/
else if ((pthread->attr.flags &
PTHREAD_DETACHED) != 0) {
/* Remove this thread from the dead list: */
TAILQ_REMOVE(&_dead_list, pthread, dle);
/*
* Check if the stack was not specified by
* the caller to pthread_create() and has not
* been destroyed yet:
*/
if (pthread->attr.stackaddr_attr == NULL &&
pthread->stack != NULL) {
_thread_stack_free(pthread->stack,
pthread->attr.stacksize_attr,
pthread->attr.guardsize_attr);
}
/*
* Point to the thread structure that must
* be freed outside the locks:
*/
pthread_cln = pthread;
} else {
/*
* This thread has not detached, so do
* not destroy it.
*
* Check if the stack was not specified by
* the caller to pthread_create() and has not
* been destroyed yet:
*/
if (pthread->attr.stackaddr_attr == NULL &&
pthread->stack != NULL) {
_thread_stack_free(pthread->stack,
pthread->attr.stacksize_attr,
pthread->attr.guardsize_attr);
/*
* NULL the stack pointer now that the
* memory has been freed:
*/
pthread->stack = NULL;
}
}
}
/*
* Check if this is not the last thread and there is no
* memory to free this time around.
*/
if (!f_done && p_stack == NULL && pthread_cln == NULL) {
/* Get the current time. */
if (clock_gettime(CLOCK_REALTIME,&abstime) != 0)
PANIC("gc cannot get time");
/*
* Do a backup poll in 10 seconds if no threads
* die before then.
*/
abstime.tv_sec += 10;
/*
* Wait for a signal from a dying thread or a
* timeout (for a backup poll).
*/
if ((ret = _pthread_cond_timedwait(&_gc_cond,
&_gc_mutex, &abstime)) != 0 && ret != ETIMEDOUT)
PANIC("gc cannot wait for a signal");
}
/* Unlock the garbage collector mutex: */
if (_pthread_mutex_unlock(&_gc_mutex) != 0)
PANIC("Cannot unlock gc mutex");
/*
* If there is memory to free, do it now. The call to
* free() might block, so this must be done outside the
* locks.
*/
if (p_stack != NULL)
free(p_stack);
if (pthread_cln != NULL) {
if (pthread_cln->name != NULL) {
/* Free the thread name string. */
free(pthread_cln->name);
}
/*
* Free the memory allocated for the thread
* structure.
*/
free(pthread_cln);
}
}
return (NULL);
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <dirent.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_getdirentries, getdirentries);
int
_getdirentries(int fd, char *buf, int nbytes, long *basep)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = __sys_getdirentries(fd, buf, nbytes, basep);
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_getpeername, getpeername);
int
_getpeername(int fd, struct sockaddr * peer, socklen_t *paddrlen)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
ret = __sys_getpeername(fd, peer, paddrlen);
_FD_UNLOCK(fd, FD_READ);
}
return ret;
}

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_getprio, pthread_getprio);
int
_pthread_getprio(pthread_t pthread)
{
int policy, ret;
struct sched_param param;
if ((ret = pthread_getschedparam(pthread, &policy, &param)) == 0)
ret = param.sched_priority;
else {
/* Invalid thread: */
errno = ret;
ret = -1;
}
/* Return the thread priority or an error status: */
return (ret);
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Daniel Eischen.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_pthread_getschedparam, pthread_getschedparam);
int
_pthread_getschedparam(pthread_t pthread, int *policy,
struct sched_param *param)
{
int ret;
if ((param == NULL) || (policy == NULL))
/* Return an invalid argument error: */
ret = EINVAL;
/* Find the thread in the list of active threads: */
else if ((ret = _find_thread(pthread)) == 0) {
/* Return the threads base priority and scheduling policy: */
param->sched_priority =
PTHREAD_BASE_PRIORITY(pthread->base_priority);
*policy = pthread->attr.sched_policy;
}
return(ret);
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_getsockname, getsockname);
int
_getsockname(int s, struct sockaddr * name, socklen_t *namelen)
{
int ret;
if ((ret = _FD_LOCK(s, FD_READ, NULL)) == 0) {
ret = __sys_getsockname(s, name, namelen);
_FD_UNLOCK(s, FD_READ);
}
return ret;
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_getsockopt, getsockopt);
int
_getsockopt(int fd, int level, int optname, void *optval, socklen_t
*optlen)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = __sys_getsockopt(fd, level, optname, optval, optlen);
_FD_UNLOCK(fd, FD_RDWR);
}
return ret;
}

View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <paths.h>
#include <pthread.h>
#include <unistd.h>
#include "pthread_private.h"
#ifndef NELEMENTS
#define NELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
static void dump_thread(int fd, pthread_t pthread, int long_version);
__weak_reference(_pthread_set_name_np, pthread_set_name_np);
struct s_thread_info {
enum pthread_state state;
char *name;
};
/* Static variables: */
static const struct s_thread_info thread_info[] = {
{PS_RUNNING , "Running"},
{PS_SIGTHREAD , "Waiting on signal thread"},
{PS_MUTEX_WAIT , "Waiting on a mutex"},
{PS_COND_WAIT , "Waiting on a condition variable"},
{PS_FDLR_WAIT , "Waiting for a file read lock"},
{PS_FDLW_WAIT , "Waiting for a file write lock"},
{PS_FDR_WAIT , "Waiting for read"},
{PS_FDW_WAIT , "Waiting for write"},
{PS_FILE_WAIT , "Waiting for FILE lock"},
{PS_POLL_WAIT , "Waiting on poll"},
{PS_SELECT_WAIT , "Waiting on select"},
{PS_SLEEP_WAIT , "Sleeping"},
{PS_WAIT_WAIT , "Waiting process"},
{PS_SIGSUSPEND , "Suspended, waiting for a signal"},
{PS_SIGWAIT , "Waiting for a signal"},
{PS_SPINBLOCK , "Waiting for a spinlock"},
{PS_JOIN , "Waiting to join"},
{PS_SUSPENDED , "Suspended"},
{PS_DEAD , "Dead"},
{PS_DEADLOCK , "Deadlocked"},
{PS_STATE_MAX , "Not a real state!"}
};
void
_thread_dump_info(void)
{
char s[512];
int fd;
int i;
pthread_t pthread;
char *tmpdir;
char tmpfile[PATH_MAX];
pq_list_t *pq_list;
if (issetugid() != 0 || (tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = _PATH_TMP;
for (i = 0; i < 100000; i++) {
snprintf(tmpfile, sizeof(tmpfile), "%s/uthread.dump.%u.%i",
tmpdir, getpid(), i);
/* Open the dump file for append and create it if necessary: */
if ((fd = __sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL,
0644)) < 0) {
/* Can't open the dump file. */
if (errno == EEXIST)
continue;
/*
* We only need to continue in case of
* EEXIST error. Most other error
* codes means that we will fail all
* the time.
*/
return;
} else {
break;
}
}
if (i==100000) {
/* all 100000 possibilities are in use :( */
return;
} else {
/* Output a header for active threads: */
strcpy(s, "\n\n=============\nACTIVE THREADS\n\n");
__sys_write(fd, s, strlen(s));
/* Enter a loop to report each thread in the global list: */
TAILQ_FOREACH(pthread, &_thread_list, tle) {
dump_thread(fd, pthread, /*long_verson*/ 1);
}
/* Output a header for ready threads: */
strcpy(s, "\n\n=============\nREADY THREADS\n\n");
__sys_write(fd, s, strlen(s));
/* Enter a loop to report each thread in the ready queue: */
TAILQ_FOREACH (pq_list, &_readyq.pq_queue, pl_link) {
TAILQ_FOREACH(pthread, &pq_list->pl_head, pqe) {
dump_thread(fd, pthread, /*long_version*/ 0);
}
}
/* Output a header for waiting threads: */
strcpy(s, "\n\n=============\nWAITING THREADS\n\n");
__sys_write(fd, s, strlen(s));
/* Enter a loop to report each thread in the waiting queue: */
TAILQ_FOREACH (pthread, &_waitingq, pqe) {
dump_thread(fd, pthread, /*long_version*/ 0);
}
/* Output a header for threads in the work queue: */
strcpy(s, "\n\n=============\nTHREADS IN WORKQ\n\n");
__sys_write(fd, s, strlen(s));
/* Enter a loop to report each thread in the waiting queue: */
TAILQ_FOREACH (pthread, &_workq, qe) {
dump_thread(fd, pthread, /*long_version*/ 0);
}
/* Check if there are no dead threads: */
if (TAILQ_FIRST(&_dead_list) == NULL) {
/* Output a record: */
strcpy(s, "\n\nTHERE ARE NO DEAD THREADS\n");
__sys_write(fd, s, strlen(s));
} else {
/* Output a header for dead threads: */
strcpy(s, "\n\nDEAD THREADS\n\n");
__sys_write(fd, s, strlen(s));
/*
* Enter a loop to report each thread in the global
* dead thread list:
*/
TAILQ_FOREACH(pthread, &_dead_list, dle) {
dump_thread(fd, pthread, /*long_version*/ 0);
}
}
/* Output a header for file descriptors: */
snprintf(s, sizeof(s), "\n\n=============\nFILE DESCRIPTOR "
"TABLE (table size %d)\n\n", _thread_dtablesize);
__sys_write(fd, s, strlen(s));
/* Enter a loop to report file descriptor lock usage: */
for (i = 0; i < _thread_dtablesize; i++) {
/*
* Check if memory is allocated for this file
* descriptor:
*/
if (_thread_fd_table[i] != NULL) {
/* Report the file descriptor lock status: */
snprintf(s, sizeof(s),
"fd[%3d] read owner %p count %d [%s:%d]\n"
" write owner %p count %d [%s:%d]\n",
i, _thread_fd_table[i]->r_owner,
_thread_fd_table[i]->r_lockcount,
_thread_fd_table[i]->r_fname,
_thread_fd_table[i]->r_lineno,
_thread_fd_table[i]->w_owner,
_thread_fd_table[i]->w_lockcount,
_thread_fd_table[i]->w_fname,
_thread_fd_table[i]->w_lineno);
__sys_write(fd, s, strlen(s));
}
}
/* Close the dump file: */
__sys_close(fd);
}
}
static void
dump_thread(int fd, pthread_t pthread, int long_version)
{
struct pthread *curthread = _get_curthread();
char s[512];
int i;
/* Find the state: */
for (i = 0; i < NELEMENTS(thread_info) - 1; i++)
if (thread_info[i].state == pthread->state)
break;
/* Output a record for the thread: */
snprintf(s, sizeof(s),
"--------------------\nThread %p (%s) prio %3d state %s",
pthread, (pthread->name == NULL) ? "" : pthread->name,
pthread->active_priority, thread_info[i].name);
__sys_write(fd, s, strlen(s));
/* And now where it is. */
if (pthread->fname != NULL) {
snprintf(s, sizeof(s), " [%s:%d]", pthread->fname,
pthread->lineno);
__sys_write(fd, s, strlen(s));
}
__sys_write(fd, "\n", 1);
if (long_version != 0) {
/* Check if this is the running thread: */
if (pthread == curthread) {
/* Output a record for the running thread: */
strcpy(s, "This is the running thread\n");
__sys_write(fd, s, strlen(s));
}
/* Check if this is the initial thread: */
if (pthread == _thread_initial) {
/* Output a record for the initial thread: */
strcpy(s, "This is the initial thread\n");
__sys_write(fd, s, strlen(s));
}
/* Process according to thread state: */
switch (pthread->state) {
/* File descriptor read lock wait: */
case PS_FDLR_WAIT:
case PS_FDLW_WAIT:
case PS_FDR_WAIT:
case PS_FDW_WAIT:
/* Write the lock details: */
snprintf(s, sizeof(s), "fd %d[%s:%d]",
pthread->data.fd.fd,
pthread->data.fd.fname,
pthread->data.fd.branch);
__sys_write(fd, s, strlen(s));
break;
case PS_SIGWAIT:
snprintf(s, sizeof(s), "sigmask (hi)");
__sys_write(fd, s, strlen(s));
for (i = _SIG_WORDS - 1; i >= 0; i--) {
snprintf(s, sizeof(s), "%08x\n",
pthread->sigmask.__bits[i]);
__sys_write(fd, s, strlen(s));
}
snprintf(s, sizeof(s), "(lo)\n");
__sys_write(fd, s, strlen(s));
break;
/*
* Trap other states that are not explicitly
* coded to dump information:
*/
default:
/* Nothing to do here. */
break;
}
}
}
/* Set the thread name for debug: */
void
_pthread_set_name_np(pthread_t thread, const char *name)
{
/* Check if the caller has specified a valid thread: */
if (thread != NULL && thread->magic == PTHREAD_MAGIC) {
if (thread->name != NULL) {
/* Free space for previous name. */
free(thread->name);
}
thread->name = strdup(name);
}
}

View File

@ -1,608 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/* Allocate space for global thread variables here: */
#define GLOBAL_PTHREAD_PRIVATE
#include "namespace.h"
#include <sys/param.h>
#include <sys/types.h>
#include <machine/reg.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/event.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/ttycom.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <poll.h>
#include <pthread.h>
#include <pthread_np.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "pthread_private.h"
int __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
int __pthread_mutex_lock(pthread_mutex_t *);
int __pthread_mutex_trylock(pthread_mutex_t *);
/*
* All weak references used within libc should be in this table.
* This allows static libraries to work.
*/
static void *references[] = {
&_accept,
&_bind,
&_close,
&_connect,
&_dup,
&_dup2,
&_execve,
&_fcntl,
&_flock,
&_flockfile,
&_fstat,
&_fstatfs,
&_fsync,
&_funlockfile,
&_getdirentries,
&_getlogin,
&_getpeername,
&_getsockname,
&_getsockopt,
&_ioctl,
&_kevent,
&_kqueue,
&_listen,
&_nanosleep,
&_open,
&_pthread_cond_destroy,
&_pthread_cond_init,
&_pthread_cond_signal,
&_pthread_cond_wait,
&_pthread_getspecific,
&_pthread_key_create,
&_pthread_key_delete,
&_pthread_mutex_destroy,
&_pthread_mutex_init,
&_pthread_mutex_lock,
&_pthread_mutex_trylock,
&_pthread_mutex_unlock,
&_pthread_mutexattr_init,
&_pthread_mutexattr_destroy,
&_pthread_mutexattr_settype,
&_pthread_once,
&_pthread_setspecific,
&_read,
&_readv,
&_recvfrom,
&_recvmsg,
&_select,
&_sendmsg,
&_sendto,
&_setsockopt,
&_sigaction,
&_sigprocmask,
&_sigsuspend,
&_socket,
&_socketpair,
&_wait4,
&_write,
&_writev
};
/*
* These are needed when linking statically. All references within
* libgcc (and libc) to these routines are weak, but if they are not
* (strongly) referenced by the application or other libraries, then
* the actual functions will not be loaded.
*/
static void *libgcc_references[] = {
&_pthread_once,
&_pthread_key_create,
&_pthread_key_delete,
&_pthread_getspecific,
&_pthread_setspecific,
&_pthread_mutex_init,
&_pthread_mutex_destroy,
&_pthread_mutex_lock,
&_pthread_mutex_trylock,
&_pthread_mutex_unlock
};
#define DUAL_ENTRY(entry) \
(pthread_func_t)entry, (pthread_func_t)entry
static pthread_func_t jmp_table[][2] = {
{DUAL_ENTRY(_pthread_atfork)}, /* PJT_ATFORK */
{DUAL_ENTRY(_pthread_attr_destroy)}, /* PJT_ATTR_DESTROY */
{DUAL_ENTRY(_pthread_attr_getdetachstate)}, /* PJT_ATTR_GETDETACHSTATE */
{DUAL_ENTRY(_pthread_attr_getguardsize)}, /* PJT_ATTR_GETGUARDSIZE */
{DUAL_ENTRY(_pthread_attr_getinheritsched)}, /* PJT_ATTR_GETINHERITSCHED */
{DUAL_ENTRY(_pthread_attr_getschedparam)}, /* PJT_ATTR_GETSCHEDPARAM */
{DUAL_ENTRY(_pthread_attr_getschedpolicy)}, /* PJT_ATTR_GETSCHEDPOLICY */
{DUAL_ENTRY(_pthread_attr_getscope)}, /* PJT_ATTR_GETSCOPE */
{DUAL_ENTRY(_pthread_attr_getstackaddr)}, /* PJT_ATTR_GETSTACKADDR */
{DUAL_ENTRY(_pthread_attr_getstacksize)}, /* PJT_ATTR_GETSTACKSIZE */
{DUAL_ENTRY(_pthread_attr_init)}, /* PJT_ATTR_INIT */
{DUAL_ENTRY(_pthread_attr_setdetachstate)}, /* PJT_ATTR_SETDETACHSTATE */
{DUAL_ENTRY(_pthread_attr_setguardsize)}, /* PJT_ATTR_SETGUARDSIZE */
{DUAL_ENTRY(_pthread_attr_setinheritsched)}, /* PJT_ATTR_SETINHERITSCHED */
{DUAL_ENTRY(_pthread_attr_setschedparam)}, /* PJT_ATTR_SETSCHEDPARAM */
{DUAL_ENTRY(_pthread_attr_setschedpolicy)}, /* PJT_ATTR_SETSCHEDPOLICY */
{DUAL_ENTRY(_pthread_attr_setscope)}, /* PJT_ATTR_SETSCOPE */
{DUAL_ENTRY(_pthread_attr_setstackaddr)}, /* PJT_ATTR_SETSTACKADDR */
{DUAL_ENTRY(_pthread_attr_setstacksize)}, /* PJT_ATTR_SETSTACKSIZE */
{DUAL_ENTRY(_pthread_cancel)}, /* PJT_CANCEL */
{DUAL_ENTRY(_pthread_cleanup_pop)}, /* PJT_CLEANUP_POP */
{DUAL_ENTRY(_pthread_cleanup_push)}, /* PJT_CLEANUP_PUSH */
{DUAL_ENTRY(_pthread_cond_broadcast)}, /* PJT_COND_BROADCAST */
{DUAL_ENTRY(_pthread_cond_destroy)}, /* PJT_COND_DESTROY */
{DUAL_ENTRY(_pthread_cond_init)}, /* PJT_COND_INIT */
{DUAL_ENTRY(_pthread_cond_signal)}, /* PJT_COND_SIGNAL */
{DUAL_ENTRY(_pthread_cond_timedwait)}, /* PJT_COND_TIMEDWAIT */
{(pthread_func_t)__pthread_cond_wait,
(pthread_func_t)_pthread_cond_wait}, /* PJT_COND_WAIT */
{DUAL_ENTRY(_pthread_detach)}, /* PJT_DETACH */
{DUAL_ENTRY(_pthread_equal)}, /* PJT_EQUAL */
{DUAL_ENTRY(_pthread_exit)}, /* PJT_EXIT */
{DUAL_ENTRY(_pthread_getspecific)}, /* PJT_GETSPECIFIC */
{DUAL_ENTRY(_pthread_join)}, /* PJT_JOIN */
{DUAL_ENTRY(_pthread_key_create)}, /* PJT_KEY_CREATE */
{DUAL_ENTRY(_pthread_key_delete)}, /* PJT_KEY_DELETE*/
{DUAL_ENTRY(_pthread_kill)}, /* PJT_KILL */
{DUAL_ENTRY(_pthread_main_np)}, /* PJT_MAIN_NP */
{DUAL_ENTRY(_pthread_mutexattr_destroy)}, /* PJT_MUTEXATTR_DESTROY */
{DUAL_ENTRY(_pthread_mutexattr_init)}, /* PJT_MUTEXATTR_INIT */
{DUAL_ENTRY(_pthread_mutexattr_settype)}, /* PJT_MUTEXATTR_SETTYPE */
{DUAL_ENTRY(_pthread_mutex_destroy)}, /* PJT_MUTEX_DESTROY */
{DUAL_ENTRY(_pthread_mutex_init)}, /* PJT_MUTEX_INIT */
{(pthread_func_t)__pthread_mutex_lock,
(pthread_func_t)_pthread_mutex_lock}, /* PJT_MUTEX_LOCK */
{(pthread_func_t)__pthread_mutex_trylock,
(pthread_func_t)_pthread_mutex_trylock},/* PJT_MUTEX_TRYLOCK */
{DUAL_ENTRY(_pthread_mutex_unlock)}, /* PJT_MUTEX_UNLOCK */
{DUAL_ENTRY(_pthread_once)}, /* PJT_ONCE */
{DUAL_ENTRY(_pthread_rwlock_destroy)}, /* PJT_RWLOCK_DESTROY */
{DUAL_ENTRY(_pthread_rwlock_init)}, /* PJT_RWLOCK_INIT */
{DUAL_ENTRY(_pthread_rwlock_rdlock)}, /* PJT_RWLOCK_RDLOCK */
{DUAL_ENTRY(_pthread_rwlock_tryrdlock)},/* PJT_RWLOCK_TRYRDLOCK */
{DUAL_ENTRY(_pthread_rwlock_trywrlock)},/* PJT_RWLOCK_TRYWRLOCK */
{DUAL_ENTRY(_pthread_rwlock_unlock)}, /* PJT_RWLOCK_UNLOCK */
{DUAL_ENTRY(_pthread_rwlock_wrlock)}, /* PJT_RWLOCK_WRLOCK */
{DUAL_ENTRY(_pthread_self)}, /* PJT_SELF */
{DUAL_ENTRY(_pthread_setcancelstate)}, /* PJT_SETCANCELSTATE */
{DUAL_ENTRY(_pthread_setcanceltype)}, /* PJT_SETCANCELTYPE */
{DUAL_ENTRY(_pthread_setspecific)}, /* PJT_SETSPECIFIC */
{DUAL_ENTRY(_pthread_sigmask)}, /* PJT_SIGMASK */
{DUAL_ENTRY(_pthread_testcancel)} /* PJT_TESTCANCEL */
};
int _pthread_guard_default;
int _pthread_page_size;
int _pthread_stack_default;
int _pthread_stack_initial;
/*
* Threaded process initialization
*/
void
_thread_init(void)
{
int fd;
int flags;
int i;
size_t len;
int mib[2];
int sched_stack_size; /* Size of scheduler stack. */
#if !defined(__ia64__)
u_long stackp;
#endif
struct clockinfo clockinfo;
struct sigaction act;
/* Check if this function has already been called: */
if (_thread_initial)
/* Only initialise the threaded application once. */
return;
_pthread_page_size = getpagesize();;
_pthread_guard_default = _pthread_page_size;
sched_stack_size = 4 * _pthread_page_size;
if (sizeof(void *) == 8) {
_pthread_stack_default = PTHREAD_STACK64_DEFAULT;
_pthread_stack_initial = PTHREAD_STACK64_INITIAL;
}
else {
_pthread_stack_default = PTHREAD_STACK32_DEFAULT;
_pthread_stack_initial = PTHREAD_STACK32_INITIAL;
}
_pthread_attr_default.guardsize_attr = _pthread_guard_default;
_pthread_attr_default.stacksize_attr = _pthread_stack_default;
/*
* Make gcc quiescent about {,libgcc_}references not being
* referenced:
*/
if ((references[0] == NULL) || (libgcc_references[0] == NULL))
PANIC("Failed loading mandatory references in _thread_init");
/*
* Check the size of the jump table to make sure it is preset
* with the correct number of entries.
*/
if (sizeof(jmp_table) != (sizeof(pthread_func_t) * PJT_MAX * 2))
PANIC("Thread jump table not properly initialized");
memcpy(__thr_jtable, jmp_table, sizeof(jmp_table));
/*
* Check for the special case of this process running as
* or in place of init as pid = 1:
*/
if (getpid() == 1) {
/*
* Setup a new session for this process which is
* assumed to be running as root.
*/
if (setsid() == -1)
PANIC("Can't set session ID");
if (revoke(_PATH_CONSOLE) != 0)
PANIC("Can't revoke console");
if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
PANIC("Can't open console");
if (setlogin("root") == -1)
PANIC("Can't set login to root");
if (__sys_ioctl(fd, TIOCSCTTY, (char *) NULL) == -1)
PANIC("Can't set controlling terminal");
if (__sys_dup2(fd, 0) == -1 ||
__sys_dup2(fd, 1) == -1 ||
__sys_dup2(fd, 2) == -1)
PANIC("Can't dup2");
}
/* Get the standard I/O flags before messing with them : */
for (i = 0; i < 3; i++) {
if (((_pthread_stdio_flags[i] =
__sys_fcntl(i, F_GETFL, NULL)) == -1) &&
(errno != EBADF))
PANIC("Cannot get stdio flags");
}
/*
* Create a pipe that is written to by the signal handler to prevent
* signals being missed in calls to _select:
*/
if (__sys_pipe(_thread_kern_pipe) != 0) {
/* Cannot create pipe, so abort: */
PANIC("Cannot create kernel pipe");
}
/*
* Make sure the pipe does not get in the way of stdio:
*/
for (i = 0; i < 2; i++) {
if (_thread_kern_pipe[i] < 3) {
fd = __sys_fcntl(_thread_kern_pipe[i], F_DUPFD, 3);
if (fd == -1)
PANIC("Cannot create kernel pipe");
__sys_close(_thread_kern_pipe[i]);
_thread_kern_pipe[i] = fd;
}
}
/* Get the flags for the read pipe: */
if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
/* Abort this application: */
PANIC("Cannot get kernel read pipe flags");
}
/* Make the read pipe non-blocking: */
else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
/* Abort this application: */
PANIC("Cannot make kernel read pipe non-blocking");
}
/* Get the flags for the write pipe: */
else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
/* Abort this application: */
PANIC("Cannot get kernel write pipe flags");
}
/* Make the write pipe non-blocking: */
else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
/* Abort this application: */
PANIC("Cannot get kernel write pipe flags");
}
/* Allocate and initialize the ready queue: */
else if (_pq_alloc(&_readyq, PTHREAD_MIN_PRIORITY, PTHREAD_LAST_PRIORITY) != 0) {
/* Abort this application: */
PANIC("Cannot allocate priority ready queue.");
}
/* Allocate memory for the thread structure of the initial thread: */
else if ((_thread_initial = (pthread_t) malloc(sizeof(struct pthread))) == NULL) {
/*
* Insufficient memory to initialise this application, so
* abort:
*/
PANIC("Cannot allocate memory for initial thread");
}
/* Allocate memory for the scheduler stack: */
else if ((_thread_kern_sched_stack = malloc(sched_stack_size)) == NULL)
PANIC("Failed to allocate stack for scheduler");
else {
/* Zero the global kernel thread structure: */
memset(&_thread_kern_thread, 0, sizeof(struct pthread));
_thread_kern_thread.flags = PTHREAD_FLAGS_PRIVATE;
memset(_thread_initial, 0, sizeof(struct pthread));
/* Initialize the waiting and work queues: */
TAILQ_INIT(&_waitingq);
TAILQ_INIT(&_workq);
/* Initialize the scheduling switch hook routine: */
_sched_switch_hook = NULL;
/* Give this thread default attributes: */
memcpy((void *) &_thread_initial->attr, &_pthread_attr_default,
sizeof(struct pthread_attr));
/* Find the stack top */
mib[0] = CTL_KERN;
mib[1] = KERN_USRSTACK;
len = sizeof (_usrstack);
if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
_usrstack = (void *)USRSTACK;
/*
* Create a red zone below the main stack. All other stacks are
* constrained to a maximum size by the paramters passed to
* mmap(), but this stack is only limited by resource limits, so
* this stack needs an explicitly mapped red zone to protect the
* thread stack that is just beyond.
*/
if (mmap(_usrstack - _pthread_stack_initial -
_pthread_guard_default, _pthread_guard_default, 0,
MAP_ANON, -1, 0) == MAP_FAILED)
PANIC("Cannot allocate red zone for initial thread");
/* Set the main thread stack pointer. */
_thread_initial->stack = _usrstack - _pthread_stack_initial;
/* Set the stack attributes: */
_thread_initial->attr.stackaddr_attr = _thread_initial->stack;
_thread_initial->attr.stacksize_attr = _pthread_stack_initial;
/* Setup the context for the scheduler: */
_setjmp(_thread_kern_sched_jb);
#if !defined(__ia64__)
stackp = (long)_thread_kern_sched_stack + sched_stack_size - sizeof(double);
#if defined(__amd64__)
stackp &= ~0xFUL;
#endif
SET_STACK_JB(_thread_kern_sched_jb, stackp);
#else
SET_STACK_JB(_thread_kern_sched_jb, _thread_kern_sched_stack,
sched_stack_size);
#endif
SET_RETURN_ADDR_JB(_thread_kern_sched_jb, _thread_kern_scheduler);
/*
* Write a magic value to the thread structure
* to help identify valid ones:
*/
_thread_initial->magic = PTHREAD_MAGIC;
/* Set the initial cancel state */
_thread_initial->cancelflags = PTHREAD_CANCEL_ENABLE |
PTHREAD_CANCEL_DEFERRED;
/* Default the priority of the initial thread: */
_thread_initial->base_priority = PTHREAD_DEFAULT_PRIORITY;
_thread_initial->active_priority = PTHREAD_DEFAULT_PRIORITY;
_thread_initial->inherited_priority = 0;
/* Initialise the state of the initial thread: */
_thread_initial->state = PS_RUNNING;
/* Set the name of the thread: */
_thread_initial->name = strdup("_thread_initial");
/* Initialize joiner to NULL (no joiner): */
_thread_initial->joiner = NULL;
/* Initialize the owned mutex queue and count: */
TAILQ_INIT(&(_thread_initial->mutexq));
_thread_initial->priority_mutex_count = 0;
/* Initialize the global scheduling time: */
_sched_ticks = 0;
gettimeofday((struct timeval *) &_sched_tod, NULL);
/* Initialize last active: */
_thread_initial->last_active = (long) _sched_ticks;
/* Initialize the initial context: */
_thread_initial->curframe = NULL;
/* Initialise the rest of the fields: */
_thread_initial->poll_data.nfds = 0;
_thread_initial->poll_data.fds = NULL;
_thread_initial->sig_defer_count = 0;
_thread_initial->yield_on_sig_undefer = 0;
_thread_initial->specific = NULL;
_thread_initial->cleanup = NULL;
_thread_initial->flags = 0;
_thread_initial->error = 0;
TAILQ_INIT(&_thread_list);
TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle);
_set_curthread(_thread_initial);
TAILQ_INIT(&_atfork_list);
_pthread_mutex_init(&_atfork_mutex, NULL);
/* Initialise the global signal action structure: */
sigfillset(&act.sa_mask);
act.sa_handler = (void (*) ()) _thread_sig_handler;
act.sa_flags = SA_SIGINFO | SA_RESTART;
/* Clear pending signals for the process: */
sigemptyset(&_process_sigpending);
/* Clear the signal queue: */
memset(_thread_sigq, 0, sizeof(_thread_sigq));
/* Enter a loop to get the existing signal status: */
for (i = 1; i < NSIG; i++) {
/* Check for signals which cannot be trapped: */
if (i == SIGKILL || i == SIGSTOP) {
}
/* Get the signal handler details: */
else if (__sys_sigaction(i, NULL,
&_thread_sigact[i - 1]) != 0) {
/*
* Abort this process if signal
* initialisation fails:
*/
PANIC("Cannot read signal handler info");
}
/* Initialize the SIG_DFL dummy handler count. */
_thread_dfl_count[i] = 0;
}
/*
* Install the signal handler for the most important
* signals that the user-thread kernel needs. Actually
* SIGINFO isn't really needed, but it is nice to have.
*/
if (__sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 ||
__sys_sigaction(SIGINFO, &act, NULL) != 0 ||
__sys_sigaction(SIGCHLD, &act, NULL) != 0) {
/*
* Abort this process if signal initialisation fails:
*/
PANIC("Cannot initialise signal handler");
}
_thread_sigact[_SCHED_SIGNAL - 1].sa_flags = SA_SIGINFO;
_thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO;
_thread_sigact[SIGCHLD - 1].sa_flags = SA_SIGINFO;
/* Get the process signal mask: */
__sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask);
/* Get the kernel clockrate: */
mib[0] = CTL_KERN;
mib[1] = KERN_CLOCKRATE;
len = sizeof (struct clockinfo);
if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0)
_clock_res_usec = clockinfo.tick > CLOCK_RES_USEC_MIN ?
clockinfo.tick : CLOCK_RES_USEC_MIN;
/* Get the table size: */
if ((_thread_dtablesize = getdtablesize()) < 0) {
/*
* Cannot get the system defined table size, so abort
* this process.
*/
PANIC("Cannot get dtablesize");
}
/* Allocate memory for the file descriptor table: */
if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) {
/* Avoid accesses to file descriptor table on exit: */
_thread_dtablesize = 0;
/*
* Cannot allocate memory for the file descriptor
* table, so abort this process.
*/
PANIC("Cannot allocate memory for file descriptor table");
}
/* Allocate memory for the pollfd table: */
if ((_thread_pfd_table = (struct pollfd *) malloc(sizeof(struct pollfd) * _thread_dtablesize)) == NULL) {
/*
* Cannot allocate memory for the file descriptor
* table, so abort this process.
*/
PANIC("Cannot allocate memory for pollfd table");
} else {
/*
* Enter a loop to initialise the file descriptor
* table:
*/
for (i = 0; i < _thread_dtablesize; i++) {
/* Initialise the file descriptor table: */
_thread_fd_table[i] = NULL;
}
/* Initialize stdio file descriptor table entries: */
for (i = 0; i < 3; i++) {
if ((_thread_fd_table_init(i) != 0) &&
(errno != EBADF))
PANIC("Cannot initialize stdio file "
"descriptor table entry");
}
}
}
/* Initialise the garbage collector mutex and condition variable. */
if (_pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
_pthread_cond_init(&_gc_cond,NULL) != 0)
PANIC("Failed to initialise garbage collector mutex or condvar");
}
/*
* Special start up code for NetBSD/Alpha
*/
#if defined(__NetBSD__) && defined(__alpha__)
int
main(int argc, char *argv[], char *env);
int
_thread_main(int argc, char *argv[], char *env)
{
_thread_init();
return (main(argc, argv, env));
}
#endif

View File

@ -1,81 +0,0 @@
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h> /* O_NONBLOCK*/
#include <pthread.h>
#include "pthread_private.h"
__weak_reference(_ioctl, ioctl);
int
_ioctl(int fd, unsigned long request,...)
{
int ret;
int flags;
int *op;
va_list ap;
/* Lock the file descriptor: */
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
/* Initialise the variable argument list: */
va_start(ap, request);
switch( request) {
case FIONBIO:
/*
* descriptors must be non-blocking; we are only
* twiddling the flag based on the request
*/
op = va_arg(ap, int *);
flags = _thread_fd_getflags(fd);
if (*op == 0)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
_thread_fd_setflags(fd, flags);
ret = 0;
break;
default:
ret = __sys_ioctl(fd, request, va_arg(ap, char *));
break;
}
/* Free variable arguments: */
va_end(ap);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
/* Return the completion status: */
return (ret);
}

Some files were not shown because too many files have changed in this diff Show More