Sync: merge r215189 through r215272 from ^/head.

This commit is contained in:
Dimitry Andric 2010-11-14 01:06:10 +00:00
commit c6d2d1b4ac
258 changed files with 1707 additions and 24461 deletions

View File

@ -281,7 +281,7 @@ tinderbox:
# existing system is.
#
.if make(universe) || make(universe_kernels) || make(tinderbox)
TARGETS?=amd64 i386 ia64 pc98 powerpc sparc64 sun4v
TARGETS?=amd64 i386 ia64 pc98 powerpc sparc64 sun4v mips
.if defined(DOING_TINDERBOX)
FAILFILE=tinderbox.failed

View File

@ -123,6 +123,21 @@ TARGET_ARCH= ${TARGET:S/pc98/i386/:S/sun4v/sparc64/:S/mips/mipsel/}
${TARGET_ARCH} != ${MACHINE_ARCH}
TARGET= ${TARGET_ARCH:C/mipse[lb]/mips/:C/armeb/arm}
.endif
# Legacy names, for a transition period mips:mips -> mipsel:mips
.if defined(TARGET) && defined(TARGET_ARCH) && \
${TARGET_ARCH} == "mips" && ${TARGET} == "mips"
.warning "TARGET_ARCH of mips is deprecated in favor of mipsel or mipseb"
.if defined(TARGET_BIG_ENDIAN)
TARGET_ARCH=mipseb
.else
TARGET_ARCH=mipsel
.endif
.endif
# arm with TARGET_BIG_ENDIAN -> armeb
.if defined(TARGET_ARCH) && ${TARGET_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
.warning "TARGET_ARCH of arm with TARGET_BIG_ENDIAN is deprecated. use armeb"
TARGET_ARCH=armeb
.endif
# Otherwise, default to current machine type and architecture.
TARGET?= ${MACHINE}
TARGET_ARCH?= ${MACHINE_ARCH}

View File

@ -32,7 +32,7 @@
.\" @(#)echo.1 8.1 (Berkeley) 7/22/93
.\" $FreeBSD$
.\"
.Dd April 12, 2003
.Dd November 12, 2010
.Dt ECHO 1
.Os
.Sh NAME
@ -56,24 +56,37 @@ The following option is available:
.Bl -tag -width flag
.It Fl n
Do not print the trailing newline character.
This may also be achieved by appending
.El
.Pp
The end-of-options marker
.Fl Fl
is not recognized and written literally.
.Pp
The newline may also be suppressed by appending
.Ql \ec
to the end of the string, as is done
by iBCS2 compatible systems.
Note that this option as well as the effect of
Note that the
.Fl n
option as well as the effect of
.Ql \ec
are implementation-defined in
.St -p1003.1-2001
as amended by Cor.\& 1-2002.
Applications aiming for maximum
portability are strongly encouraged to use
.Xr printf 1
to suppress the newline character.
.El
.Pp
Some shells may provide a builtin
For portability,
.Nm
command which is similar or identical to this utility.
should only be used if the first argument does not start with a hyphen
.Pq Ql "-"
and does not contain any backslashes
.Pq Ql "\e" .
If this is not sufficient,
.Xr printf 1
should be used.
.Pp
Most shells provide a builtin
.Nm
command which tends to differ from this utility
in the treatment of options and backslashes.
Consult the
.Xr builtin 1
manual page.

View File

@ -34,6 +34,6 @@
suspend() {
local -
set +j
set +m
kill -TSTP 0
}

View File

@ -626,6 +626,7 @@ There are two kinds of built-in commands: regular and special.
Assignments before special builtins persist after they finish
executing and assignment errors, redirection errors and certain
operand errors cause a script to be aborted.
Special builtins cannot be overridden with a function.
Both regular and special builtins can affect the shell in ways
normal programs cannot.
.Pp
@ -1268,19 +1269,22 @@ consists of all characters until the matching
.Ql } .
Any
.Ql }
escaped by a backslash or within a single-quoted string, and characters in
escaped by a backslash or within a single-quoted or double-quoted
string, and characters in
embedded arithmetic expansions, command substitutions, and variable
expansions, are not examined in determining the matching
.Ql } .
Except for the variants with
If the variants with
.Ql + ,
.Ql - ,
.Ql =
or
.Ql ?\& ,
any
.Ql ?\&
occur within a double-quoted string,
as an extension there may be unquoted parts
(via double-quotes inside the expansion);
.Ql }
within a double-quoted string is also not examined in determining the matching
within such parts are also not examined in determining the matching
.Ql } .
.Pp
The simplest form for parameter expansion is:

View File

@ -805,6 +805,7 @@ poplocalvars(void)
if (vp == NULL) { /* $- saved */
memcpy(optlist, lvp->text, sizeof optlist);
ckfree(lvp->text);
optschanged();
} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
(void)unsetvar(vp->text);
} else {

View File

@ -863,14 +863,18 @@ case "${targ}" in
targ_defvec=bfd_elf32_tradlittlemips_vec
targ_selvecs="bfd_elf32_tradbigmips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_little_vec ecoff_big_vec"
;;
mips*-*-freebsd*)
targ_defvec=bfd_elf32_tradbigmips_vec
targ_selvecs="bfd_elf32_tradlittlemips_vec bfd_elf32_ntradbigmisp_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*-*-netbsd*)
targ_defvec=bfd_elf32_tradbigmips_vec
targ_selvecs="bfd_elf32_tradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*el-*-freebsd*)
targ_defvec=bfd_elf32_tradlittlemips_vec
targ_selvecs="bfd_elf32_tradbigmips_vec bfd_elf32_ntradbigmisp_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*-*-freebsd*)
targ_defvec=bfd_elf32_tradbigmips_vec
targ_selvecs="bfd_elf32_tradlittlemips_vec bfd_elf32_ntradbigmisp_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*-dec-* | mips*el-*-ecoff*)
targ_defvec=ecoff_little_vec
targ_selvecs=ecoff_big_vec

View File

@ -160,6 +160,9 @@ daily_status_security_diff_flags="-b -u" # flags for diff output
# 100.chksetuid
daily_status_security_chksetuid_enable="YES"
# 110.neggrpperm
daily_status_security_neggrpperm_enable="NO"
# 200.chkmounts
daily_status_security_chkmounts_enable="YES"
#daily_status_security_chkmounts_ignore="^amd:" # Don't check matching

View File

@ -97,6 +97,13 @@ detach 100 {
action "/etc/rc.d/bluetooth quietstop $device-name";
};
# Firmware downloader for Atheros AR3011 based USB Bluetooth devices
#attach 100 {
# match "vendor" "0x0cf3";
# match "product" "0x3000";
# action "sleep 2 && /usr/sbin/ath3kfw -d $device-name -f /usr/local/etc/ath3k-1.fw";
#};
# When a USB keyboard arrives, attach it as the console keyboard.
attach 100 {
device-name "ukbd0";

View File

@ -0,0 +1,54 @@
#!/bin/sh -
#
# Copyright (c) 2001 The FreeBSD Project
# 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$
#
# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
. /etc/defaults/periodic.conf
source_periodic_confs
fi
rc=0
case "$daily_status_security_neggrpperm_enable" in
[Yy][Ee][Ss])
echo ""
echo 'Checking negative group permissions:'
MP=`mount -t ufs,zfs | awk '$0 !~ /no(suid|exec)/ { print $3 }'`
n=$(find -sx $MP /dev/null -type f \
\( \( ! -perm +010 -and -perm +001 \) -or \
\( ! -perm +020 -and -perm +002 \) -or \
\( ! -perm +040 -and -perm +004 \) \) \
-exec ls -liTd \{\} \+ | tee /dev/stderr | wc -l)
[ $n -gt 0 ] && rc=1 || rc=0
;;
esac
exit $rc

View File

@ -3,6 +3,7 @@
.include <bsd.own.mk>
FILES= 100.chksetuid \
110.neggrpperm \
200.chkmounts \
300.chkuid0 \
400.passwdless \

View File

@ -33,24 +33,31 @@ echo 4/ddp #AppleTalk Echo Protocol
rje 5/tcp #Remote Job Entry
rje 5/udp #Remote Job Entry
zip 6/ddp #Zone Information Protocol
echo 7/sctp
echo 7/tcp
echo 7/udp
discard 9/sctp sink null
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users #Active Users
systat 11/udp users #Active Users
daytime 13/sctp
daytime 13/tcp
daytime 13/udp
qotd 17/tcp quote #Quote of the Day
qotd 17/udp quote #Quote of the Day
msp 18/tcp #Message Send Protocol
msp 18/udp #Message Send Protocol
chargen 19/sctp ttytst source #Character Generator
chargen 19/tcp ttytst source #Character Generator
chargen 19/udp ttytst source #Character Generator
ftp-data 20/sctp #File Transfer [Default Data]
ftp-data 20/tcp #File Transfer [Default Data]
ftp-data 20/udp #File Transfer [Default Data]
ftp 21/sctp #File Transfer [Control]
ftp 21/tcp #File Transfer [Control]
ftp 21/udp #File Transfer [Control]
ssh 22/sctp #Secure Shell Login
ssh 22/tcp #Secure Shell Login
ssh 22/udp #Secure Shell Login
telnet 23/tcp
@ -151,6 +158,7 @@ vettcp 78/tcp
vettcp 78/udp
finger 79/tcp
finger 79/udp
http 80/sctp www www-http #World Wide Web HTTP
http 80/tcp www www-http #World Wide Web HTTP
http 80/udp www www-http #World Wide Web HTTP
hosts2-ns 81/tcp #HOSTS2 Name Server
@ -350,6 +358,7 @@ xdmcp 177/tcp #X Display Manager Control Protocol
xdmcp 177/udp #X Display Manager Control Protocol
NextStep 178/tcp nextstep NeXTStep #NextStep Window Server
NextStep 178/udp nextstep NeXTStep #NextStep Window Server
bgp 179/sctp #Border Gateway Protocol
bgp 179/tcp #Border Gateway Protocol
bgp 179/udp #Border Gateway Protocol
ris 180/tcp #Intergraph
@ -738,6 +747,7 @@ decvms-sysmgt 441/tcp
decvms-sysmgt 441/udp
cvc_hostd 442/tcp
cvc_hostd 442/udp
https 443/sctp
https 443/tcp
https 443/udp
snpp 444/tcp #Simple Network Paging Protocol
@ -1519,7 +1529,9 @@ nfsd-keepalive 1110/udp #Client status info
supfiledbg 1127/tcp # for SUP
nfa 1155/tcp #Network File Access
nfa 1155/udp #Network File Access
phone 1167/udp #conference calling
cisco-ipsla 1167/sctp #Cisco IP SLAs Control Protocol
cisco-ipsla 1167/tcp #Cisco IP SLAs Control Protocol
cisco-ipsla 1167/udp #Cisco IP SLAs Control Protocol
skkserv 1178/tcp #SKK (kanji input)
openvpn 1194/tcp #OpenVPN
openvpn 1194/udp #OpenVPN
@ -2119,6 +2131,7 @@ sdfunc 2046/udp
#dls 2047/udp
dls-monitor 2048/tcp
dls-monitor 2048/udp
nfsd 2049/sctp nfs # NFS server daemon
nfsd 2049/tcp nfs # NFS server daemon
nfsd 2049/udp nfs # NFS server daemon
#PROBLEMS!=============================================================
@ -2146,6 +2159,8 @@ hpssd 2207/tcp #HP Status and Services
hpssd 2207/udp #HP Status and Services
hpiod 2208/tcp #HP I/O Backend
hpiod 2208/udp #HP I/O Backend
rcip-itu 2225/sctp #Resource Connection Initiation Protocol
rcip-itu 2225/tcp #Resource Connection Initiation Protocol
ivs-video 2232/tcp #IVS Video default
ivs-video 2232/udp #IVS Video default
ivsd 2241/tcp #IVS Daemon
@ -2179,6 +2194,17 @@ dict 2628/udp #RFC 2229
listen 2766/tcp #System V listener port
www-dev 2784/tcp #world wide web - development
www-dev 2784/udp #world wide web - development
m2ua 2904/sctp #M2UA
m2ua 2904/tcp #M2UA
m2ua 2904/udp #M2UA
m3ua 2905/sctp #M3UA
m3ua 2905/tcp #M3UA
megaco-h248 2944/sctp #Megaco-H.248 text
megaco-h248 2944/tcp #Megaco H-248
megaco-h248 2944/udp #Megaco H-248
h248-binary 2945/sctp #Megaco/H.248 binary
h248-binary 2945/tcp #H248 Binary
h248-binary 2945/udp #H248 Binary
eppc 3031/tcp #Remote AppleEvents/PPC Toolbox
eppc 3031/udp #Remote AppleEvents/PPC Toolbox
NSWS 3049/tcp
@ -2186,6 +2212,7 @@ NSWS 3049/udp
gds_db 3050/tcp #InterBase Database Remote Protocol
gds_db 3050/udp #InterBase Database Remote Protocol
sj3 3086/tcp #SJ3 (kanji input)
itu-bicc-stc 3097/sctp #ITU-T Q.1902.1/Q.2150.3
vmodem 3141/tcp
vmodem 3141/udp
iscsi-target 3260/tcp # iSCSI port
@ -2205,10 +2232,19 @@ vat-control 3457/tcp #VAT default control
vat-control 3457/udp #VAT default control
nut 3493/tcp #Network UPS Tools
nut 3493/udp #Network UPS Tools
m2pa 3565/sctp #M2PA
m2pa 3565/tcp #M2PA
tsp 3653/tcp #Tunnel Setup Protocol
tsp 3653/udp #Tunnel Setup Protocol
svn 3690/tcp #Subversion
svn 3690/udp #Subversion
asap 3863/sctp #asap sctp
asap 3863/tcp #asap tcp port
asap 3863/udp #asap udp port
asap-tls 3864/sctp #asap-sctp/tls
asap-tls 3864/tcp #asap/tls tcp port
diameter 3868/tcp #DIAMETER
diameter 3868/sctp #DIAMETER
udt_os 3900/tcp #Unidata UDT OS
udt_os 3900/udp #Unidata UDT OS
mapper-nodemgr 3984/tcp #MAPPER network node manager
@ -2245,6 +2281,12 @@ fax 4557/tcp #FAX transmission service
hylafax 4559/tcp #HylaFAX client-server protocol
rfa 4672/tcp #remote file access server
rfa 4672/udp #remote file access server
ipfix 4739/sctp #IP Flow Info Export
ipfix 4739/tcp #IP Flow Info Export
ipfix 4739/udp #IP Flow Info Export
ipfixs 4740/sctp #ipfix protocol over DTLS
ipfixs 4740/tcp #ipfix protocol over TLS
ipfixs 4740/udp #ipfix protocol over DTLS
commplex-main 5000/tcp
commplex-main 5000/udp
commplex-link 5001/tcp
@ -2263,6 +2305,8 @@ sip 5060/tcp #Session Initialization Protocol (VoIP)
sip 5060/udp #Session Initialization Protocol (VoIP)
sip-tls 5061/tcp #SIP over TLS
sip-tls 5061/udp #SIP over TLS
car 5090/sctp #Candidate AR
cxtp 5091/sctp #Context Transfer Protocol
rmonitor_secure 5145/tcp
rmonitor_secure 5145/udp
aol 5190/tcp #America-Online
@ -2298,6 +2342,12 @@ mdns 5353/udp #Multicast DNS
postgresql 5432/tcp #PostgreSQL Database
postgresql 5432/udp #PostgreSQL Database
rplay 5555/udp
amqp 5672/sctp #AMQP
amqp 5672/tcp #AMQP
amqp 5672/udp #AMQP
v5ua 5675/sctp #V5UA application port
v5ua 5675/tcp #V5UA application port
v5ua 5675/udp #V5UA application port
canna 5680/tcp #Canna (Japanese Input)
proshareaudio 5713/tcp #proshare conf audio
proshareaudio 5713/udp #proshare conf audio
@ -2343,6 +2393,9 @@ xdsxdm 6558/udp
sane-port 6566/tcp #Scanner Access Now Easy (SANE) Control Port
sane-port 6566/udp #Scanner Access Now Easy (SANE) Control Port
ircd 6667/tcp #Internet Relay Chat (unoffical)
frc-hp 6704/sctp #ForCES HP (High Priority) channel
frc-mp 6705/sctp #ForCES MP (Medium Priority) channel
frc-lp 6706/sctp #ForCES LP (Low priority) channel
acmsoda 6969/tcp
acmsoda 6969/udp
afs3-fileserver 7000/tcp #file server itself
@ -2377,8 +2430,16 @@ fodms 7200/tcp #FODMS FLIP
fodms 7200/udp #FODMS FLIP
dlip 7201/tcp
dlip 7201/udp
simco 7626/sctp #SImple Middlebox COnfiguration (SIMCO)
simco 7626/tcp #SImple Middlebox COnfiguration (SIMCO) Server
ftp-proxy 8021/tcp # FTP proxy
pim 8471/sctp #PIM over Reliable Transport
pim 8471/tcp #PIM over Reliable Transport
natd 8668/divert # Network Address Translation
lcs-ap 9082/sctp #LCS Application Protocol
aurora 9084/sctp #IBM AURORA Performance Visualizer
aurora 9084/tcp #IBM AURORA Performance Visualizer
aurora 9084/udp #IBM AURORA Performance Visualizer
jetdirect 9100/tcp #HP JetDirect card
git 9418/tcp #git pack transfer service
git 9418/udp #git pack transfer service
@ -2386,18 +2447,37 @@ man 9535/tcp
man 9535/udp
sd 9876/tcp #Session Director
sd 9876/udp #Session Director
iua 9900/sctp #IUA
iua 9900/tcp #IUA
iua 9900/udp #IUA
enrp 9901/sctp #enrp server channel
enrp 9901/udp #enrp server channel
enrp-tls 9902/sctp #enrp/tls server channel
amanda 10080/tcp #Dump server control
amanda 10080/udp #Dump server control
amandaidx 10082/tcp #Amanda indexing
amidxtape 10083/tcp #Amanda tape indexing
wmereceiving 11997/sctp #WorldMailExpress
wmedistribution 11998/sctp #WorldMailExpress
wmereporting 11999/sctp #WorldMailExpress
sua 14001/sctp #SUA
sua 14001/tcp #SUA
isode-dua 17007/tcp
isode-dua 17007/udp
biimenu 18000/tcp #Beckman Instruments, Inc.
biimenu 18000/udp #Beckman Instruments, Inc.
nfsrdma 20049/sctp #Network File System (NFS) over RDMA
nfsrdma 20049/tcp #Network File System (NFS) over RDMA
nfsrdma 20049/udp #Network File System (NFS) over RDMA
wnn4 22273/tcp wnn6 #Wnn4 (Japanese input)
wnn4_Cn 22289/tcp wnn6_Cn #Wnn4 (Chinese input)
wnn4_Kr 22305/tcp wnn6_Kr #Wnn4 (Korean input)
wnn4_Tw 22321/tcp wnn6_Tw #Wnn4 (Taiwanse input)
wnn6_DS 26208/tcp #Wnn6 (Dserver)
sgsap 29118/sctp #SGsAP in 3GPP
sbcap 29168/sctp #SBcAP in 3GPP
iuhsctpassoc 29169/sctp #HNBAP and RUA Common Association
s1-control 36412/sctp #S1-Control Plane (3GPP)
x2-control 36422/sctp #X2-Control Plane (3GPP)
dbbrowse 47557/tcp #Databeam Corporation
dbbrowse 47557/udp #Databeam Corporation

View File

@ -1,31 +1,24 @@
/* $OpenBSD: /usr/local/www/cvsroot/OpenBSD/src/include/readpassphrase.h,v 1.2 2002/02/16 21:27:17 millert Exp $ */
/* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */
/* $FreeBSD$ */
/*
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``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.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Sponsored in part by the Defense Advanced Research Projects
* Agency (DARPA) and Air Force Research Laboratory, Air Force
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
#ifndef _READPASSPHRASE_H_
@ -37,6 +30,7 @@
#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
#include <sys/cdefs.h>
#include <sys/_types.h>

View File

@ -1,33 +1,26 @@
.\" $OpenBSD: readpassphrase.3,v 1.7 2001/12/15 15:37:51 millert Exp $
.\" $OpenBSD: readpassphrase.3,v 1.17 2007/05/31 19:19:28 jmc Exp $
.\"
.\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
.\" All rights reserved.
.\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
.\"
.\" 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. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THIS SOFTWARE IS PROVIDED ``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.
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" Sponsored in part by the Defense Advanced Research Projects
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
.\" $FreeBSD$
.\"
.Dd December 7, 2001
.Dd May 31, 2007
.Dt READPASSPHRASE 3
.Os
.Sh NAME
@ -79,6 +72,8 @@ force input to lower case
force input to upper case
.It Dv RPP_SEVENBIT
strip the high bit from input
.It Dv RPP_STDIN
force read of passphrase from stdin
.El
.Pp
The calling process should zero the passphrase as soon as possible to
@ -87,7 +82,7 @@ space.
.Sh RETURN VALUES
Upon successful completion,
.Fn readpassphrase
returns a pointer to the null-terminated passphrase.
returns a pointer to the NUL-terminated passphrase.
If an error is encountered, the terminal state is restored and
a
.Dv NULL
@ -117,40 +112,6 @@ if (compare(transform(passbuf), epass) != 0)
memset(passbuf, 0, sizeof(passbuf));
.Ed
.Sh SIGNALS
The
.Fn readpassphrase
function
will catch the following signals:
.Pp
.Bl -tag -compact
.It Dv SIGINT
.It Dv SIGHUP
.It Dv SIGQUIT
.It Dv SIGTERM
.It Dv SIGTSTP
.It Dv SIGTTIN
.It Dv SIGTTOU
.El
.Pp
When one of the above signals is intercepted, terminal echo will
be restored if it had previously been turned off.
If a signal handler was installed for the signal when
.Fn readpassphrase
was called that handler is then executed.
If no handler was previously installed for the signal then the
default action is taken as per
.Xr sigaction 2 .
.Pp
The
.Dv SIGTSTP , SIGTTIN ,
and
.Dv SIGTTOU
signals (stop signal generated from keyboard or due to terminal I/O
from a background process) are treated specially.
When the process is resumed after it has been stopped,
.Fn readpassphrase
will reprint the prompt and the user may then enter a passphrase.
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EINTR
@ -159,14 +120,14 @@ The
function was interrupted by a signal.
.It Bq Er EINVAL
The
.Fa bufsiz
.Ar bufsiz
argument was zero.
.It Bq Er EIO
The process is a member of a background process attempting to read
from its controlling terminal, the process is ignoring or blocking
the
.Dv SIGTTIN
signal or the process group is orphaned.
signal, or the process group is orphaned.
.It Bq Er EMFILE
The process has already reached its limit for open file descriptors.
.It Bq Er ENFILE
@ -176,6 +137,35 @@ There is no controlling terminal and the
.Dv RPP_REQUIRE_TTY
flag was specified.
.El
.Sh SIGNALS
The
.Fn readpassphrase
function
will catch the following signals:
.Bd -literal -offset indent
SIGALRM SIGHUP SIGINT
SIGPIPE SIGQUIT SIGTERM
SIGTSTP SIGTTIN SIGTTOU
.Ed
.Pp
When one of the above signals is intercepted, terminal echo will
be restored if it had previously been turned off.
If a signal handler was installed for the signal when
.Fn readpassphrase
was called, that handler is then executed.
If no handler was previously installed for the signal then the
default action is taken as per
.Xr sigaction 2 .
.Pp
The
.Dv SIGTSTP , SIGTTIN
and
.Dv SIGTTOU
signals (stop signals generated from keyboard or due to terminal I/O
from a background process) are treated specially.
When the process is resumed after it has been stopped,
.Fn readpassphrase
will reprint the prompt and the user may then enter a passphrase.
.Sh SEE ALSO
.Xr sigaction 2 ,
.Xr getpass 3

View File

@ -1,35 +1,26 @@
/* $OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $ */
/* $OpenBSD: readpassphrase.c,v 1.23 2010/05/14 13:30:34 millert Exp $ */
/*
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* Copyright (c) 2000-2002, 2007, 2010
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``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.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Sponsored in part by the Defense Advanced Research Projects
* Agency (DARPA) and Air Force Research Laboratory, Air Force
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -46,7 +37,7 @@ __FBSDID("$FreeBSD$");
#include <readpassphrase.h>
#include "un-namespace.h"
static volatile sig_atomic_t signo;
static volatile sig_atomic_t signo[NSIG];
static void handler(int);
@ -54,11 +45,11 @@ char *
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
{
ssize_t nr;
int input, output, save_errno;
int input, output, save_errno, i, need_restart;
char ch, *p, *end;
struct termios term, oterm;
struct sigaction sa, saveint, savehup, savequit, saveterm;
struct sigaction savetstp, savettin, savettou;
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
struct sigaction savetstp, savettin, savettou, savepipe;
/* I suppose we could alloc on demand in this case (XXX). */
if (bufsiz == 0) {
@ -67,11 +58,17 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
}
restart:
for (i = 0; i < NSIG; i++)
signo[i] = 0;
nr = -1;
save_errno = 0;
need_restart = 0;
/*
* Read and write to /dev/tty if available. If not, read from
* stdin and write to stderr unless a tty is required.
*/
if ((input = output = _open(_PATH_TTY, O_RDWR)) == -1) {
if ((flags & RPP_STDIN) ||
(input = output = _open(_PATH_TTY, O_RDWR)) == -1) {
if (flags & RPP_REQUIRE_TTY) {
errno = ENOTTY;
return(NULL);
@ -81,23 +78,11 @@ restart:
}
/*
* Catch signals that would otherwise cause the user to end
* up with echo turned off in the shell. Don't worry about
* things like SIGALRM and SIGPIPE for now.
* Turn off echo if possible.
* If we are using a tty but are not the foreground pgrp this will
* generate SIGTTOU, so do it *before* installing the signal handlers.
*/
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; /* don't restart system calls */
sa.sa_handler = handler;
(void)_sigaction(SIGINT, &sa, &saveint);
(void)_sigaction(SIGHUP, &sa, &savehup);
(void)_sigaction(SIGQUIT, &sa, &savequit);
(void)_sigaction(SIGTERM, &sa, &saveterm);
(void)_sigaction(SIGTSTP, &sa, &savetstp);
(void)_sigaction(SIGTTIN, &sa, &savettin);
(void)_sigaction(SIGTTOU, &sa, &savettou);
/* Turn off echo if possible. */
if (tcgetattr(input, &oterm) == 0) {
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
memcpy(&term, &oterm, sizeof(term));
if (!(flags & RPP_ECHO_ON))
term.c_lflag &= ~(ECHO | ECHONL);
@ -106,20 +91,42 @@ restart:
(void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
} else {
memset(&term, 0, sizeof(term));
term.c_lflag |= ECHO;
memset(&oterm, 0, sizeof(oterm));
oterm.c_lflag |= ECHO;
}
(void)_write(output, prompt, strlen(prompt));
/*
* Catch signals that would otherwise cause the user to end
* up with echo turned off in the shell. Don't worry about
* things like SIGXCPU and SIGVTALRM for now.
*/
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; /* don't restart system calls */
sa.sa_handler = handler;
(void)_sigaction(SIGALRM, &sa, &savealrm);
(void)_sigaction(SIGHUP, &sa, &savehup);
(void)_sigaction(SIGINT, &sa, &saveint);
(void)_sigaction(SIGPIPE, &sa, &savepipe);
(void)_sigaction(SIGQUIT, &sa, &savequit);
(void)_sigaction(SIGTERM, &sa, &saveterm);
(void)_sigaction(SIGTSTP, &sa, &savetstp);
(void)_sigaction(SIGTTIN, &sa, &savettin);
(void)_sigaction(SIGTTOU, &sa, &savettou);
if (!(flags & RPP_STDIN))
(void)_write(output, prompt, strlen(prompt));
end = buf + bufsiz - 1;
for (p = buf; (nr = _read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
p = buf;
while ((nr = _read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
if (p < end) {
if ((flags & RPP_SEVENBIT))
ch &= 0x7f;
if (isalpha(ch)) {
if ((flags & RPP_FORCELOWER))
ch = tolower(ch);
ch = (char)tolower(ch);
if ((flags & RPP_FORCEUPPER))
ch = toupper(ch);
ch = (char)toupper(ch);
}
*p++ = ch;
}
@ -130,11 +137,16 @@ restart:
(void)_write(output, "\n", 1);
/* Restore old terminal settings and signals. */
if (memcmp(&term, &oterm, sizeof(term)) != 0)
(void)tcsetattr(input, TCSANOW|TCSASOFT, &oterm);
(void)_sigaction(SIGINT, &saveint, NULL);
if (memcmp(&term, &oterm, sizeof(term)) != 0) {
while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
errno == EINTR && !signo[SIGTTOU])
continue;
}
(void)_sigaction(SIGALRM, &savealrm, NULL);
(void)_sigaction(SIGHUP, &savehup, NULL);
(void)_sigaction(SIGINT, &saveint, NULL);
(void)_sigaction(SIGQUIT, &savequit, NULL);
(void)_sigaction(SIGPIPE, &savepipe, NULL);
(void)_sigaction(SIGTERM, &saveterm, NULL);
(void)_sigaction(SIGTSTP, &savetstp, NULL);
(void)_sigaction(SIGTTIN, &savettin, NULL);
@ -146,18 +158,22 @@ restart:
* If we were interrupted by a signal, resend it to ourselves
* now that we have restored the signal handlers.
*/
if (signo) {
kill(getpid(), signo);
switch (signo) {
case SIGTSTP:
case SIGTTIN:
case SIGTTOU:
signo = 0;
goto restart;
for (i = 0; i < NSIG; i++) {
if (signo[i]) {
kill(getpid(), i);
switch (i) {
case SIGTSTP:
case SIGTTIN:
case SIGTTOU:
need_restart = 1;
}
}
}
if (need_restart)
goto restart;
errno = save_errno;
if (save_errno)
errno = save_errno;
return(nr == -1 ? NULL : buf);
}
@ -174,5 +190,5 @@ getpass(const char *prompt)
static void handler(int s)
{
signo = s;
signo[s] = 1;
}

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);
}

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