diff options
author | dim <dim@FreeBSD.org> | 2010-11-14 01:06:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-11-14 01:06:10 +0000 |
commit | 466abdddb672857d5af81ed2471904a9b734a52b (patch) | |
tree | ffb2723c09a80be6dc84091175675ba7bb4e4980 | |
parent | 7b4d6157428e658dfa749ddf481c0df946de63c6 (diff) | |
parent | 6011bea49b131d3d52a0854f271d6a0ce475512e (diff) | |
download | FreeBSD-src-466abdddb672857d5af81ed2471904a9b734a52b.zip FreeBSD-src-466abdddb672857d5af81ed2471904a9b734a52b.tar.gz |
Sync: merge r215189 through r215272 from ^/head.
258 files changed, 1704 insertions, 24458 deletions
@@ -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 diff --git a/Makefile.inc1 b/Makefile.inc1 index cd29204..fb71ce1 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -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} diff --git a/bin/echo/echo.1 b/bin/echo/echo.1 index 5f7123e..f1f3907 100644 --- a/bin/echo/echo.1 +++ b/bin/echo/echo.1 @@ -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 +For portability, +.Nm +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 -to suppress the newline character. -.El +should be used. .Pp -Some shells may provide a builtin +Most shells provide a builtin .Nm -command which is similar or identical to this utility. +command which tends to differ from this utility +in the treatment of options and backslashes. Consult the .Xr builtin 1 manual page. diff --git a/bin/sh/funcs/suspend b/bin/sh/funcs/suspend index 81bb53d..1749298 100644 --- a/bin/sh/funcs/suspend +++ b/bin/sh/funcs/suspend @@ -34,6 +34,6 @@ suspend() { local - - set +j + set +m kill -TSTP 0 } diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 062a9da..7b1eb61 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -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: diff --git a/bin/sh/var.c b/bin/sh/var.c index f5ea775..3bba368 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -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 { diff --git a/contrib/binutils/bfd/config.bfd b/contrib/binutils/bfd/config.bfd index 9253996..2f9d4d2 100755 --- a/contrib/binutils/bfd/config.bfd +++ b/contrib/binutils/bfd/config.bfd @@ -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 diff --git a/etc/defaults/periodic.conf b/etc/defaults/periodic.conf index 8267ac7..29e3b00 100644 --- a/etc/defaults/periodic.conf +++ b/etc/defaults/periodic.conf @@ -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 diff --git a/etc/devd.conf b/etc/devd.conf index e249ffd..77dda05 100644 --- a/etc/devd.conf +++ b/etc/devd.conf @@ -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"; diff --git a/etc/periodic/security/110.neggrpperm b/etc/periodic/security/110.neggrpperm new file mode 100755 index 0000000..68d1e7b --- /dev/null +++ b/etc/periodic/security/110.neggrpperm @@ -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 diff --git a/etc/periodic/security/Makefile b/etc/periodic/security/Makefile index fc67723..74e7b61 100644 --- a/etc/periodic/security/Makefile +++ b/etc/periodic/security/Makefile @@ -3,6 +3,7 @@ .include <bsd.own.mk> FILES= 100.chksetuid \ + 110.neggrpperm \ 200.chkmounts \ 300.chkuid0 \ 400.passwdless \ diff --git a/etc/services b/etc/services index 6bb207a..146fefc 100644 --- a/etc/services +++ b/etc/services @@ -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 diff --git a/include/readpassphrase.h b/include/readpassphrase.h index 75cb8cb..d9641fa 100644 --- a/include/readpassphrase.h +++ b/include/readpassphrase.h @@ -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> diff --git a/lib/libc/gen/readpassphrase.3 b/lib/libc/gen/readpassphrase.3 index 0d6a7ff..3bcee6f 100644 --- a/lib/libc/gen/readpassphrase.3 +++ b/lib/libc/gen/readpassphrase.3 @@ -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 diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c index 983e01d..d57e703 100644 --- a/lib/libc/gen/readpassphrase.c +++ b/lib/libc/gen/readpassphrase.c @@ -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,45 +78,55 @@ restart: } /* + * 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. + */ + if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { + memcpy(&term, &oterm, sizeof(term)); + if (!(flags & RPP_ECHO_ON)) + term.c_lflag &= ~(ECHO | ECHONL); + if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) + term.c_cc[VSTATUS] = _POSIX_VDISABLE; + (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; + } + + /* * 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. + * 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(SIGINT, &sa, &saveint); + (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); - /* Turn off echo if possible. */ - if (tcgetattr(input, &oterm) == 0) { - memcpy(&term, &oterm, sizeof(term)); - if (!(flags & RPP_ECHO_ON)) - term.c_lflag &= ~(ECHO | ECHONL); - if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) - term.c_cc[VSTATUS] = _POSIX_VDISABLE; - (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); - } else { - memset(&term, 0, sizeof(term)); - memset(&oterm, 0, sizeof(oterm)); - } - - (void)_write(output, prompt, strlen(prompt)); + 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; } diff --git a/lib/libc_r/Makefile b/lib/libc_r/Makefile deleted file mode 100644 index a424876..0000000 --- a/lib/libc_r/Makefile +++ /dev/null @@ -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> diff --git a/lib/libc_r/arch/amd64/_atomic_lock.S b/lib/libc_r/arch/amd64/_atomic_lock.S deleted file mode 100644 index 0a90709..0000000 --- a/lib/libc_r/arch/amd64/_atomic_lock.S +++ /dev/null @@ -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) - diff --git a/lib/libc_r/arch/i386/_atomic_lock.S b/lib/libc_r/arch/i386/_atomic_lock.S deleted file mode 100644 index 7dba53c..0000000 --- a/lib/libc_r/arch/i386/_atomic_lock.S +++ /dev/null @@ -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) - diff --git a/lib/libc_r/arch/ia64/_atomic_lock.S b/lib/libc_r/arch/ia64/_atomic_lock.S deleted file mode 100644 index b4b84da..0000000 --- a/lib/libc_r/arch/ia64/_atomic_lock.S +++ /dev/null @@ -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) diff --git a/lib/libc_r/arch/sparc64/_atomic_lock.S b/lib/libc_r/arch/sparc64/_atomic_lock.S deleted file mode 100644 index ce931df..0000000 --- a/lib/libc_r/arch/sparc64/_atomic_lock.S +++ /dev/null @@ -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) diff --git a/lib/libc_r/sys/Makefile.inc b/lib/libc_r/sys/Makefile.inc deleted file mode 100644 index ab6db1f..0000000 --- a/lib/libc_r/sys/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/sys ${.CURDIR}/arch/${MACHINE_CPUARCH} - -SRCS+= uthread_error.c _atomic_lock.S - diff --git a/lib/libc_r/sys/uthread_error.c b/lib/libc_r/sys/uthread_error.c deleted file mode 100644 index 8c52967..0000000 --- a/lib/libc_r/sys/uthread_error.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/test/Makefile b/lib/libc_r/test/Makefile deleted file mode 100644 index 0eb530c..0000000 --- a/lib/libc_r/test/Makefile +++ /dev/null @@ -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 diff --git a/lib/libc_r/test/README b/lib/libc_r/test/README deleted file mode 100644 index 507ea4e..0000000 --- a/lib/libc_r/test/README +++ /dev/null @@ -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. diff --git a/lib/libc_r/test/guard_b.c b/lib/libc_r/test/guard_b.c deleted file mode 100644 index 35aa406..0000000 --- a/lib/libc_r/test/guard_b.c +++ /dev/null @@ -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*)⊤ - } - - /* - * 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; -} diff --git a/lib/libc_r/test/guard_b.exp b/lib/libc_r/test/guard_b.exp deleted file mode 100644 index 8e5b9e4..0000000 --- a/lib/libc_r/test/guard_b.exp +++ /dev/null @@ -1,3 +0,0 @@ -Test begin -No overflow: -Overflow: diff --git a/lib/libc_r/test/guard_s.pl b/lib/libc_r/test/guard_s.pl deleted file mode 100755 index 7802ff3..0000000 --- a/lib/libc_r/test/guard_s.pl +++ /dev/null @@ -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"; - } - } - } -} diff --git a/lib/libc_r/test/hello_b.c b/lib/libc_r/test/hello_b.c deleted file mode 100644 index 2eefa7f..0000000 --- a/lib/libc_r/test/hello_b.c +++ /dev/null @@ -1,13 +0,0 @@ -/**************************************************************************** - * - * Back end C programs can be anything compilable. - * - * $FreeBSD$ - * - ****************************************************************************/ - -int -main() -{ - return 0; -} diff --git a/lib/libc_r/test/hello_d.c b/lib/libc_r/test/hello_d.c deleted file mode 100644 index 6d77526..0000000 --- a/lib/libc_r/test/hello_d.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/test/hello_d.exp b/lib/libc_r/test/hello_d.exp deleted file mode 100644 index 802992c..0000000 --- a/lib/libc_r/test/hello_d.exp +++ /dev/null @@ -1 +0,0 @@ -Hello world diff --git a/lib/libc_r/test/hello_s.c b/lib/libc_r/test/hello_s.c deleted file mode 100644 index 942bf2d..0000000 --- a/lib/libc_r/test/hello_s.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/test/join_leak_d.c b/lib/libc_r/test/join_leak_d.c deleted file mode 100644 index 9a35140..0000000 --- a/lib/libc_r/test/join_leak_d.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/test/join_leak_d.exp b/lib/libc_r/test/join_leak_d.exp deleted file mode 100644 index 369a88d..0000000 --- a/lib/libc_r/test/join_leak_d.exp +++ /dev/null @@ -1,2 +0,0 @@ -Test begin -Test end diff --git a/lib/libc_r/test/mutex_d.c b/lib/libc_r/test/mutex_d.c deleted file mode 100644 index 2f0c868..0000000 --- a/lib/libc_r/test/mutex_d.c +++ /dev/null @@ -1,1555 +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 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 <unistd.h> - -#include <sys/ioctl.h> -#include <assert.h> -#include <errno.h> -#include <inttypes.h> -#include "pthread.h" -#include <sched.h> -#include <signal.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <sysexits.h> - -#if defined(_LIBC_R_) -#include <pthread_np.h> -#endif - -#ifndef NELEMENTS -#define NELEMENTS(arr) (sizeof (arr) / sizeof (arr[0])) -#endif - -#ifndef NUM_THREADS -#define NUM_THREADS 10 -#endif - -#define MAX_THREAD_CMDS 10 - -static void log_error(const char *, ...) __printflike(1, 2); -static void log_trace (const char *, ...) __printflike(1, 2); -static void log (const char *, ...) __printflike(1, 2); - -/*------------------------------------------------------------ - * Types - *----------------------------------------------------------*/ - -typedef enum { - STAT_INITIAL, /* initial state */ - STAT_WAITCONDVAR, /* waiting for condition variable signal */ - STAT_WAITMUTEX /* waiting for mutex lock */ -} thread_status_t; - -typedef enum { - FLAGS_REPORT_WAITCONDMUTEX = 0x01, - FLAGS_REPORT_WAITCONDVAR = 0x02, - FLAGS_REPORT_WAITMUTEX = 0x04, - FLAGS_REPORT_BUSY_LOOP = 0x08, - FLAGS_IS_BUSY = 0x10, - FLAGS_WAS_BUSY = 0x20 -} thread_flags_t; - -typedef enum { - CMD_NONE, - CMD_TAKE_MUTEX, - CMD_RELEASE_MUTEX, - CMD_WAIT_FOR_SIGNAL, - CMD_BUSY_LOOP, - CMD_PROTECTED_OP, - CMD_RELEASE_ALL -} thread_cmd_id_t; - -typedef struct { - thread_cmd_id_t cmd_id; - pthread_mutex_t *mutex; - pthread_cond_t *cond; -} thread_cmd_t; - -typedef struct { - pthread_cond_t cond_var; - thread_status_t status; - thread_cmd_t cmd; - int flags; - int priority; - int ret; - pthread_t tid; - u_int8_t id; -} thread_state_t; - -typedef enum { - M_POSIX, - M_SS2_DEFAULT, - M_SS2_ERRORCHECK, - M_SS2_NORMAL, - M_SS2_RECURSIVE -} mutex_kind_t; - - -/*------------------------------------------------------------ - * Constants - *----------------------------------------------------------*/ - -const char *protocol_strs[] = { - "PTHREAD_PRIO_NONE", - "PTHREAD_PRIO_INHERIT", - "PTHREAD_PRIO_PROTECT" -}; - -const int protocols[] = { - PTHREAD_PRIO_NONE, - PTHREAD_PRIO_INHERIT, - PTHREAD_PRIO_PROTECT -}; - -const char *mutextype_strs[] = { - "POSIX (type not specified)", - "SS2 PTHREAD_MUTEX_DEFAULT", - "SS2 PTHREAD_MUTEX_ERRORCHECK", - "SS2 PTHREAD_MUTEX_NORMAL", - "SS2 PTHREAD_MUTEX_RECURSIVE" -}; - -const int mutex_types[] = { - 0, /* M_POSIX */ - PTHREAD_MUTEX_DEFAULT, /* M_SS2_DEFAULT */ - PTHREAD_MUTEX_ERRORCHECK, /* M_SS2_ERRORCHECK */ - PTHREAD_MUTEX_NORMAL, /* M_SS2_NORMAL */ - PTHREAD_MUTEX_RECURSIVE /* M_SS2_RECURSIVE */ -}; - - -/*------------------------------------------------------------ - * Objects - *----------------------------------------------------------*/ - -static int done = 0; -static int trace_enabled = 0; -static int use_global_condvar = 0; -static thread_state_t states[NUM_THREADS]; -static int pipefd[2]; - -static pthread_mutex_t waiter_mutex; -static pthread_mutex_t cond_mutex; -static pthread_cond_t cond_var; - -static FILE *logfile; -static int error_count = 0, pass_count = 0, total = 0; - - -/*------------------------------------------------------------ - * Prototypes - *----------------------------------------------------------*/ -extern char *strtok_r(char *str, const char *sep, char **last); - - -/*------------------------------------------------------------ - * Functions - *----------------------------------------------------------*/ - -#ifdef DEBUG -static void -kern_switch (pthread_t pthread_out, pthread_t pthread_in) -{ - if (pthread_out != NULL) - printf ("Swapping out thread 0x%x, ", (int) pthread_out); - else - printf ("Swapping out kernel thread, "); - - if (pthread_in != NULL) - printf ("swapping in thread 0x%x\n", (int) pthread_in); - else - printf ("swapping in kernel thread.\n"); -} -#endif - - -static void -log_error (const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - fprintf (logfile, "FAIL: "); - vfprintf (logfile, fmt, ap); - error_count = error_count + 1; - total = total + 1; -} - - -static void -log_pass (void) -{ - fprintf (logfile, "PASS\n"); - pass_count = pass_count + 1; - total = total + 1; -} - - -static void -log_trace (const char *fmt, ...) -{ - va_list ap; - - if (trace_enabled) { - va_start (ap, fmt); - vfprintf (logfile, fmt, ap); - } -} - - -static void -log (const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - vfprintf (logfile, fmt, ap); -} - - -static void -check_result (int expected, int actual) -{ - if (expected != actual) - log_error ("expected %d, returned %d\n", expected, actual); - else - log_pass (); -} - - -/* - * Check to see that the threads ran in the specified order. - */ -static void -check_run_order (char *order) -{ - const char *sep = ":,"; - char *tok, *last, *idstr, *endptr; - int expected_id, bytes, count = 0, errors = 0; - u_int8_t id; - - assert ((tok = (char *) malloc (strlen(order) + 1)) != NULL); - strcpy (tok, order); /* tok has to be larger than order */ - assert (ioctl (pipefd[0], FIONREAD, &bytes) == 0); - log_trace ("%d bytes read from FIFO.\n", bytes); - - for (idstr = strtok_r (tok, sep, &last); - (idstr != NULL) && (count < bytes); - idstr = strtok_r (NULL, sep, &last)) { - - /* Get the expected id: */ - expected_id = (int) strtol (idstr, &endptr, 10); - assert ((endptr != NULL) && (*endptr == '\0')); - - /* Read the actual id from the pipe: */ - assert (read (pipefd[0], &id, sizeof (id)) == sizeof (id)); - count = count + sizeof (id); - - if (id != expected_id) { - log_trace ("Thread %d ran out of order.\n", id); - errors = errors + 1; - } - else { - log_trace ("Thread %d at priority %d reporting.\n", - (int) id, states[id].priority); - } - } - - if (count < bytes) { - /* Clear the pipe: */ - while (count < bytes) { - read (pipefd[0], &id, sizeof (id)); - count = count + 1; - errors = errors + 1; - } - } - else if (bytes < count) - errors = errors + count - bytes; - - if (errors == 0) - log_pass (); - else - log_error ("%d threads ran out of order", errors); -} - - -static void * -waiter (void *arg) -{ - thread_state_t *statep = (thread_state_t *) arg; - pthread_mutex_t *held_mutex[MAX_THREAD_CMDS]; - int held_mutex_owned[MAX_THREAD_CMDS]; - sigset_t mask; - struct timeval tv1, tv2; - thread_cmd_t cmd; - int i, mutex_count = 0; - - statep->status = STAT_INITIAL; - - /* Block all signals except for interrupt.*/ - sigfillset (&mask); - sigdelset (&mask, SIGINT); - sigprocmask (SIG_BLOCK, &mask, NULL); - - while (done == 0) { - /* Wait for signal from the main thread to continue. */ - statep->status = STAT_WAITMUTEX; - log_trace ("Thread %d: locking cond_mutex.\n", - (int) statep->id); - pthread_mutex_lock (&cond_mutex); - - /* Do we report our status. */ - if (statep->flags & FLAGS_REPORT_WAITCONDMUTEX) - write (pipefd[1], &statep->id, sizeof (statep->id)); - log_trace ("Thread %d: waiting for cond_var.\n", - (int) statep->id); - - /* Wait for a command. */ - statep->status = STAT_WAITCONDVAR; - - /* - * The threads are allowed commanded to wait either on - * their own unique condition variable (so they may be - * separately signaled) or on one global condition variable - * (so they may be signaled together). - */ - if (use_global_condvar != 0) - pthread_cond_wait (&cond_var, &cond_mutex); - else - pthread_cond_wait (&statep->cond_var, &cond_mutex); - - /* Do we report our status? */ - if (statep->flags & FLAGS_REPORT_WAITCONDVAR) { - write (pipefd[1], &statep->id, sizeof (statep->id)); - log_trace ("Thread %d: wrote to pipe.\n", - (int) statep->id); - } - log_trace ("Thread %d: received cond_var signal.\n", - (int) statep->id); - - /* Get a copy of the command before releasing the mutex. */ - cmd = statep->cmd; - - /* Clear the command after copying it. */ - statep->cmd.cmd_id = CMD_NONE; - - /* Unlock the condition variable mutex. */ - assert (pthread_mutex_unlock (&cond_mutex) == 0); - - /* Peform the command.*/ - switch (cmd.cmd_id) { - case CMD_TAKE_MUTEX: - statep->ret = pthread_mutex_lock (cmd.mutex); - if (statep->ret == 0) { - assert (mutex_count < sizeof (held_mutex)); - held_mutex[mutex_count] = cmd.mutex; - held_mutex_owned[mutex_count] = 1; - mutex_count++; - } - else { - held_mutex_owned[mutex_count] = 0; - log_trace ("Thread id %d unable to lock mutex, " - "error = %d\n", (int) statep->id, - statep->ret); - } - break; - - case CMD_RELEASE_MUTEX: - assert ((mutex_count <= sizeof (held_mutex)) && - (mutex_count > 0)); - mutex_count--; - if (held_mutex_owned[mutex_count] != 0) - assert (pthread_mutex_unlock - (held_mutex[mutex_count]) == 0); - break; - - case CMD_WAIT_FOR_SIGNAL: - assert (pthread_mutex_lock (cmd.mutex) == 0); - assert (pthread_cond_wait (cmd.cond, cmd.mutex) == 0); - assert (pthread_mutex_unlock (cmd.mutex) == 0); - break; - - case CMD_BUSY_LOOP: - log_trace ("Thread %d: Entering busy loop.\n", - (int) statep->id); - /* Spin for 15 seconds. */ - assert (gettimeofday (&tv2, NULL) == 0); - tv1.tv_sec = tv2.tv_sec + 5; - tv1.tv_usec = tv2.tv_usec; - statep->flags |= FLAGS_IS_BUSY; - while (timercmp (&tv2, &tv1,<)) { - assert (gettimeofday (&tv2, NULL) == 0); - } - statep->flags &= ~FLAGS_IS_BUSY; - statep->flags |= FLAGS_WAS_BUSY; - - /* Do we report our status? */ - if (statep->flags & FLAGS_REPORT_BUSY_LOOP) - write (pipefd[1], &statep->id, - sizeof (statep->id)); - - log_trace ("Thread %d: Leaving busy loop.\n", - (int) statep->id); - break; - - case CMD_PROTECTED_OP: - assert (pthread_mutex_lock (cmd.mutex) == 0); - statep->flags |= FLAGS_WAS_BUSY; - /* Do we report our status? */ - if (statep->flags & FLAGS_REPORT_BUSY_LOOP) - write (pipefd[1], &statep->id, - sizeof (statep->id)); - - assert (pthread_mutex_unlock (cmd.mutex) == 0); - break; - - case CMD_RELEASE_ALL: - assert ((mutex_count <= sizeof (held_mutex)) && - (mutex_count > 0)); - for (i = mutex_count - 1; i >= 0; i--) { - if (held_mutex_owned[i] != 0) - assert (pthread_mutex_unlock - (held_mutex[i]) == 0); - } - mutex_count = 0; - break; - - case CMD_NONE: - default: - break; - } - - /* Wait for the big giant waiter lock. */ - statep->status = STAT_WAITMUTEX; - log_trace ("Thread %d: waiting for big giant lock.\n", - (int) statep->id); - pthread_mutex_lock (&waiter_mutex); - if (statep->flags & FLAGS_REPORT_WAITMUTEX) - write (pipefd[1], &statep->id, sizeof (statep->id)); - log_trace ("Thread %d: got big giant lock.\n", - (int) statep->id); - statep->status = STAT_INITIAL; - pthread_mutex_unlock (&waiter_mutex); - } - - log_trace ("Thread %d: Exiting thread 0x%" PRIxPTR "\n", - (int) statep->id, (uintptr_t) pthread_self()); - pthread_exit (arg); - return (NULL); -} - - -static void * -lock_twice (void *arg) -{ - thread_state_t *statep = (thread_state_t *) arg; - sigset_t mask; - - statep->status = STAT_INITIAL; - - /* Block all signals except for interrupt.*/ - sigfillset (&mask); - sigdelset (&mask, SIGINT); - sigprocmask (SIG_BLOCK, &mask, NULL); - - /* Wait for a signal to continue. */ - log_trace ("Thread %d: locking cond_mutex.\n", (int) statep->id); - pthread_mutex_lock (&cond_mutex); - - log_trace ("Thread %d: waiting for cond_var.\n", (int) statep->id); - statep->status = STAT_WAITCONDVAR; - pthread_cond_wait (&cond_var, &cond_mutex); - - log_trace ("Thread %d: received cond_var signal.\n", (int) statep->id); - - /* Unlock the condition variable mutex. */ - assert (pthread_mutex_unlock (&cond_mutex) == 0); - - statep->status = STAT_WAITMUTEX; - /* Lock the mutex once. */ - assert (pthread_mutex_lock (statep->cmd.mutex) == 0); - - /* Lock it again and capture the error. */ - statep->ret = pthread_mutex_lock (statep->cmd.mutex); - statep->status = 0; - - assert (pthread_mutex_unlock (statep->cmd.mutex) == 0); - - /* Unlock it again if it is locked recursively. */ - if (statep->ret == 0) - pthread_mutex_unlock (statep->cmd.mutex); - - log_trace ("Thread %d: Exiting thread 0x%" PRIxPTR "\n", - (int) statep->id, (uintptr_t) pthread_self()); - pthread_exit (arg); - return (NULL); -} - - -static void -sighandler (int signo) -{ - log ("Signal handler caught signal %d, thread id 0x%" PRIxPTR "\n", - signo, (uintptr_t) pthread_self()); - - if (signo == SIGINT) - done = 1; -} - - -static void -send_cmd (int id, thread_cmd_id_t cmd) -{ - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (states[id].status == STAT_WAITCONDVAR); - states[id].cmd.cmd_id = cmd; - states[id].cmd.mutex = NULL; - states[id].cmd.cond = NULL; - /* Clear the busy flags. */ - states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY); - assert (pthread_cond_signal (&states[id].cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); -} - - -static void -send_mutex_cmd (int id, thread_cmd_id_t cmd, pthread_mutex_t *m) -{ - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (states[id].status == STAT_WAITCONDVAR); - states[id].cmd.cmd_id = cmd; - states[id].cmd.mutex = m; - states[id].cmd.cond = NULL; - /* Clear the busy flags. */ - states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY); - assert (pthread_cond_signal (&states[id].cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); -} - - -static void -send_mutex_cv_cmd (int id, thread_cmd_id_t cmd, pthread_mutex_t *m, - pthread_cond_t *cv) -{ - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (states[id].status == STAT_WAITCONDVAR); - states[id].cmd.cmd_id = cmd; - states[id].cmd.mutex = m; - states[id].cmd.cond = cv; - /* Clear the busy flags. */ - states[id].flags &= ~(FLAGS_WAS_BUSY | FLAGS_IS_BUSY); - assert (pthread_cond_signal (&states[id].cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); -} - - -static void -mutex_init_test (void) -{ - pthread_mutexattr_t mattr; - pthread_mutex_t mutex; - mutex_kind_t mkind; - int mproto, ret; - - /* - * Initialize a mutex attribute. - * - * pthread_mutexattr_init not tested for: ENOMEM - */ - assert (pthread_mutexattr_init (&mattr) == 0); - - /* - * Initialize a mutex. - * - * pthread_mutex_init not tested for: EAGAIN ENOMEM EPERM EBUSY - */ - log ("Testing pthread_mutex_init\n"); - log ("--------------------------\n"); - - for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) { - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - /* Initialize the mutex attribute. */ - assert (pthread_mutexattr_init (&mattr) == 0); - assert (pthread_mutexattr_setprotocol (&mattr, - protocols[mproto]) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - log (" Protocol %s, Type %s - ", - protocol_strs[mproto], mutextype_strs[mkind]); - ret = pthread_mutex_init (&mutex, &mattr); - check_result (/* expected */ 0, ret); - assert (pthread_mutex_destroy (&mutex) == 0); - - /* - * Destroy a mutex attribute. - * - * XXX - There should probably be a magic number - * associated with a mutex attribute so that - * destroy can be reasonably sure the attribute - * is valid. - * - * pthread_mutexattr_destroy not tested for: EINVAL - */ - assert (pthread_mutexattr_destroy (&mattr) == 0); - } - } -} - - -static void -mutex_destroy_test (void) -{ - pthread_mutexattr_t mattr; - pthread_mutex_t mutex; - pthread_condattr_t cattr; - pthread_cond_t cv; - pthread_attr_t pattr; - int mproto, ret; - mutex_kind_t mkind; - thread_state_t state; - - /* - * Destroy a mutex. - * - * XXX - There should probably be a magic number associated - * with a mutex so that destroy can be reasonably sure - * the mutex is valid. - * - * pthread_mutex_destroy not tested for: - */ - log ("Testing pthread_mutex_destroy\n"); - log ("-----------------------------\n"); - - assert (pthread_attr_init (&pattr) == 0); - assert (pthread_attr_setdetachstate (&pattr, - PTHREAD_CREATE_DETACHED) == 0); - state.flags = 0; /* No flags yet. */ - - for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) { - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - /* Initialize the mutex attribute. */ - assert (pthread_mutexattr_init (&mattr) == 0); - assert (pthread_mutexattr_setprotocol (&mattr, - protocols[mproto]) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - /* Create the mutex. */ - assert (pthread_mutex_init (&mutex, &mattr) == 0); - - log (" Protocol %s, Type %s\n", - protocol_strs[mproto], mutextype_strs[mkind]); - - log (" Destruction of unused mutex - "); - assert (pthread_mutex_init (&mutex, &mattr) == 0); - ret = pthread_mutex_destroy (&mutex); - check_result (/* expected */ 0, ret); - - log (" Destruction of mutex locked by self - "); - assert (pthread_mutex_init (&mutex, &mattr) == 0); - assert (pthread_mutex_lock (&mutex) == 0); - ret = pthread_mutex_destroy (&mutex); - check_result (/* expected */ EBUSY, ret); - assert (pthread_mutex_unlock (&mutex) == 0); - assert (pthread_mutex_destroy (&mutex) == 0); - - log (" Destruction of mutex locked by another " - "thread - "); - assert (pthread_mutex_init (&mutex, &mattr) == 0); - send_mutex_cmd (0, CMD_TAKE_MUTEX, &mutex); - sleep (1); - ret = pthread_mutex_destroy (&mutex); - check_result (/* expected */ EBUSY, ret); - send_cmd (0, CMD_RELEASE_ALL); - sleep (1); - assert (pthread_mutex_destroy (&mutex) == 0); - - log (" Destruction of mutex while being used in " - "cond_wait - "); - assert (pthread_mutex_init (&mutex, &mattr) == 0); - assert (pthread_condattr_init (&cattr) == 0); - assert (pthread_cond_init (&cv, &cattr) == 0); - send_mutex_cv_cmd (0, CMD_WAIT_FOR_SIGNAL, &mutex, &cv); - sleep (1); - ret = pthread_mutex_destroy (&mutex); - check_result (/* expected */ EBUSY, ret); - pthread_cond_signal (&cv); - sleep (1); - assert (pthread_mutex_destroy (&mutex) == 0); - } - } -} - - -static void -mutex_lock_test (void) -{ - pthread_mutexattr_t mattr; - pthread_mutex_t mutex; - pthread_attr_t pattr; - int mproto, ret; - mutex_kind_t mkind; - thread_state_t state; - - /* - * Lock a mutex. - * - * pthread_lock not tested for: - */ - log ("Testing pthread_mutex_lock\n"); - log ("--------------------------\n"); - - assert (pthread_attr_init (&pattr) == 0); - assert (pthread_attr_setdetachstate (&pattr, - PTHREAD_CREATE_DETACHED) == 0); - state.flags = 0; /* No flags yet. */ - - for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) { - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - /* Initialize the mutex attribute. */ - assert (pthread_mutexattr_init (&mattr) == 0); - assert (pthread_mutexattr_setprotocol (&mattr, - protocols[mproto]) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - /* Create the mutex. */ - assert (pthread_mutex_init (&mutex, &mattr) == 0); - - log (" Protocol %s, Type %s\n", - protocol_strs[mproto], mutextype_strs[mkind]); - - log (" Lock on unlocked mutex - "); - ret = pthread_mutex_lock (&mutex); - check_result (/* expected */ 0, ret); - pthread_mutex_unlock (&mutex); - - log (" Lock on invalid mutex - "); - ret = pthread_mutex_lock (NULL); - check_result (/* expected */ EINVAL, ret); - - log (" Lock on mutex held by self - "); - assert (pthread_create (&state.tid, &pattr, lock_twice, - (void *) &state) == 0); - /* Let the thread start. */ - sleep (1); - state.cmd.mutex = &mutex; - state.ret = 0xdeadbeef; - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (pthread_cond_signal (&cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); - /* Let the thread receive and process the command. */ - sleep (1); - - switch (mkind) { - case M_POSIX: - check_result (/* expected */ EDEADLK, - state.ret); - break; - case M_SS2_DEFAULT: - check_result (/* expected */ EDEADLK, - state.ret); - break; - case M_SS2_ERRORCHECK: - check_result (/* expected */ EDEADLK, - state.ret); - break; - case M_SS2_NORMAL: - check_result (/* expected */ 0xdeadbeef, - state.ret); - break; - case M_SS2_RECURSIVE: - check_result (/* expected */ 0, state.ret); - break; - } - pthread_mutex_destroy (&mutex); - pthread_mutexattr_destroy (&mattr); - } - } -} - - -static void -mutex_unlock_test (void) -{ - const int test_thread_id = 0; /* ID of test thread */ - pthread_mutexattr_t mattr; - pthread_mutex_t mutex; - int mproto, ret; - mutex_kind_t mkind; - - /* - * Unlock a mutex. - * - * pthread_unlock not tested for: - */ - log ("Testing pthread_mutex_unlock\n"); - log ("----------------------------\n"); - - for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) { - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - /* Initialize the mutex attribute. */ - assert (pthread_mutexattr_init (&mattr) == 0); - assert (pthread_mutexattr_setprotocol (&mattr, - protocols[mproto]) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - /* Create the mutex. */ - assert (pthread_mutex_init (&mutex, &mattr) == 0); - - log (" Protocol %s, Type %s\n", - protocol_strs[mproto], mutextype_strs[mkind]); - - log (" Unlock on mutex held by self - "); - assert (pthread_mutex_lock (&mutex) == 0); - ret = pthread_mutex_unlock (&mutex); - check_result (/* expected */ 0, ret); - - log (" Unlock on invalid mutex - "); - ret = pthread_mutex_unlock (NULL); - check_result (/* expected */ EINVAL, ret); - - log (" Unlock on mutex locked by another thread - "); - send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &mutex); - sleep (1); - ret = pthread_mutex_unlock (&mutex); - switch (mkind) { - case M_POSIX: - check_result (/* expected */ EPERM, ret); - break; - case M_SS2_DEFAULT: - check_result (/* expected */ EPERM, ret); - break; - case M_SS2_ERRORCHECK: - check_result (/* expected */ EPERM, ret); - break; - case M_SS2_NORMAL: - check_result (/* expected */ EPERM, ret); - break; - case M_SS2_RECURSIVE: - check_result (/* expected */ EPERM, ret); - break; - } - if (ret == 0) { - /* - * If for some reason we were able to unlock - * the mutex, relock it so that the test - * thread has no problems releasing the mutex. - */ - pthread_mutex_lock (&mutex); - } - send_cmd (test_thread_id, CMD_RELEASE_ALL); - sleep (1); - - pthread_mutex_destroy (&mutex); - pthread_mutexattr_destroy (&mattr); - } - } -} - - -static void -queueing_order_test (void) -{ - int i; - - log ("Testing queueing order\n"); - log ("----------------------\n"); - assert (pthread_mutex_lock (&waiter_mutex) == 0); - /* - * Tell the threads to report when they take the waiters mutex. - */ - assert (pthread_mutex_lock (&cond_mutex) == 0); - for (i = 0; i < NUM_THREADS; i++) { - states[i].flags = FLAGS_REPORT_WAITMUTEX; - assert (pthread_cond_signal (&states[i].cond_var) == 0); - } - assert (pthread_mutex_unlock (&cond_mutex) == 0); - - /* Signal the threads to continue. */ - sleep (1); - - /* Use the global condition variable next time. */ - use_global_condvar = 1; - - /* Release the waiting threads and allow them to run again. */ - assert (pthread_mutex_unlock (&waiter_mutex) == 0); - sleep (1); - - log (" Queueing order on a mutex - "); - check_run_order ("9,8,7,6,5,4,3,2,1,0"); - for (i = 0; i < NUM_THREADS; i = i + 1) { - /* Tell the threads to report when they've been signaled. */ - states[i].flags = FLAGS_REPORT_WAITCONDVAR; - } - - /* - * Prevent the threads from continuing their loop after we - * signal them. - */ - assert (pthread_mutex_lock (&waiter_mutex) == 0); - - - log (" Queueing order on a condition variable - "); - /* - * Signal one thread to run and see that the highest priority - * thread executes. - */ - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (pthread_cond_signal (&cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); - sleep (1); - if (states[NUM_THREADS - 1].status != STAT_WAITMUTEX) - log_error ("highest priority thread does not run.\n"); - - /* Signal the remaining threads. */ - assert (pthread_mutex_lock (&cond_mutex) == 0); - assert (pthread_cond_broadcast (&cond_var) == 0); - assert (pthread_mutex_unlock (&cond_mutex) == 0); - sleep (1); - - check_run_order ("9,8,7,6,5,4,3,2,1,0"); - for (i = 0; i < NUM_THREADS; i = i + 1) { - /* Tell the threads not to report anything. */ - states[i].flags = 0; - } - - /* Use the thread unique condition variable next time. */ - use_global_condvar = 0; - - /* Allow the threads to continue their loop. */ - assert (pthread_mutex_unlock (&waiter_mutex) == 0); - sleep (1); -} - - -static void -mutex_prioceiling_test (void) -{ - const int test_thread_id = 0; /* ID of test thread */ - pthread_mutexattr_t mattr; - struct sched_param param; - pthread_mutex_t m[3]; - mutex_kind_t mkind; - int i, ret, policy, my_prio, old_ceiling; - - log ("Testing priority ceilings\n"); - log ("-------------------------\n"); - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - - log (" Protype PTHREAD_PRIO_PROTECT, Type %s\n", - mutextype_strs[mkind]); - - /* - * Initialize and create a mutex. - */ - assert (pthread_mutexattr_init (&mattr) == 0); - - /* Get this threads current priority. */ - assert (pthread_getschedparam (pthread_self(), &policy, - ¶m) == 0); - my_prio = param.sched_priority; /* save for later use */ - log_trace ("Current scheduling policy %d, priority %d\n", - policy, my_prio); - - /* - * Initialize and create 3 priority protection mutexes with - * default (max priority) ceilings. - */ - assert (pthread_mutexattr_setprotocol(&mattr, - PTHREAD_PRIO_PROTECT) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - for (i = 0; i < 3; i++) - assert (pthread_mutex_init (&m[i], &mattr) == 0); - - /* - * Set the ceiling priorities for the 3 priority protection - * mutexes to, 5 less than, equal to, and 5 greater than, - * this threads current priority. - */ - for (i = 0; i < 3; i++) - assert (pthread_mutex_setprioceiling (&m[i], - my_prio - 5 + 5*i, &old_ceiling) == 0); - - /* - * Check that if we attempt to take a mutex whose priority - * ceiling is lower than our priority, we get an error. - */ - log (" Lock with ceiling priority < thread priority - "); - ret = pthread_mutex_lock (&m[0]); - check_result (/* expected */ EINVAL, ret); - if (ret == 0) - pthread_mutex_unlock (&m[0]); - - /* - * Check that we can take a mutex whose priority ceiling - * is equal to our priority. - */ - log (" Lock with ceiling priority = thread priority - "); - ret = pthread_mutex_lock (&m[1]); - check_result (/* expected */ 0, ret); - if (ret == 0) - pthread_mutex_unlock (&m[1]); - - /* - * Check that we can take a mutex whose priority ceiling - * is higher than our priority. - */ - log (" Lock with ceiling priority > thread priority - "); - ret = pthread_mutex_lock (&m[2]); - check_result (/* expected */ 0, ret); - if (ret == 0) - pthread_mutex_unlock (&m[2]); - - /* - * Have the test thread go into a busy loop for 5 seconds - * and see that it doesn't block this thread (since the - * priority ceiling of mutex 0 and the priority of the test - * thread are both less than the priority of this thread). - */ - log (" Preemption with ceiling priority < thread " - "priority - "); - /* Have the test thread take mutex 0. */ - send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[0]); - sleep (1); - - log_trace ("Sending busy command.\n"); - send_cmd (test_thread_id, CMD_BUSY_LOOP); - log_trace ("Busy sent, yielding\n"); - pthread_yield (); - log_trace ("Returned from yield.\n"); - if (states[test_thread_id].flags & - (FLAGS_IS_BUSY | FLAGS_WAS_BUSY)) - log_error ("test thread inproperly preempted us.\n"); - else { - /* Let the thread finish its busy loop. */ - sleep (6); - if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0) - log_error ("test thread never finished.\n"); - else - log_pass (); - } - states[test_thread_id].flags &= ~FLAGS_WAS_BUSY; - - /* Have the test thread release mutex 0. */ - send_cmd (test_thread_id, CMD_RELEASE_ALL); - sleep (1); - - /* - * Have the test thread go into a busy loop for 5 seconds - * and see that it preempts this thread (since the priority - * ceiling of mutex 1 is the same as the priority of this - * thread). The test thread should not run to completion - * as its time quantum should expire before the 5 seconds - * are up. - */ - log (" Preemption with ceiling priority = thread " - "priority - "); - - /* Have the test thread take mutex 1. */ - send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[1]); - sleep (1); - - log_trace ("Sending busy\n"); - send_cmd (test_thread_id, CMD_BUSY_LOOP); - log_trace ("Busy sent, yielding\n"); - pthread_yield (); - log_trace ("Returned from yield.\n"); - if ((states[test_thread_id].flags & FLAGS_IS_BUSY) == 0) - log_error ("test thread did not switch in on yield.\n"); - else if (states[test_thread_id].flags & FLAGS_WAS_BUSY) - log_error ("test thread ran to completion.\n"); - else { - /* Let the thread finish its busy loop. */ - sleep (6); - if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0) - log_error ("test thread never finished.\n"); - else - log_pass (); - } - states[test_thread_id].flags &= ~FLAGS_WAS_BUSY; - - /* Have the test thread release mutex 1. */ - send_cmd (test_thread_id, CMD_RELEASE_ALL); - sleep (1); - - /* - * Set the scheduling policy of the test thread to SCHED_FIFO - * and have it go into a busy loop for 5 seconds. This - * thread is SCHED_RR, and since the priority ceiling of - * mutex 1 is the same as the priority of this thread, the - * test thread should run to completion once it is switched - * in. - */ - log (" SCHED_FIFO scheduling and ceiling priority = " - "thread priority - "); - param.sched_priority = states[test_thread_id].priority; - assert (pthread_setschedparam (states[test_thread_id].tid, - SCHED_FIFO, ¶m) == 0); - - /* Have the test thread take mutex 1. */ - send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[1]); - sleep (1); - - log_trace ("Sending busy\n"); - send_cmd (test_thread_id, CMD_BUSY_LOOP); - log_trace ("Busy sent, yielding\n"); - pthread_yield (); - log_trace ("Returned from yield.\n"); - if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0) { - log_error ("test thread did not run to completion.\n"); - /* Let the thread finish it's busy loop. */ - sleep (6); - } - else - log_pass (); - states[test_thread_id].flags &= ~FLAGS_WAS_BUSY; - - /* Restore the test thread scheduling parameters. */ - param.sched_priority = states[test_thread_id].priority; - assert (pthread_setschedparam (states[test_thread_id].tid, - SCHED_RR, ¶m) == 0); - - /* Have the test thread release mutex 1. */ - send_cmd (test_thread_id, CMD_RELEASE_ALL); - sleep (1); - - /* - * Have the test thread go into a busy loop for 5 seconds - * and see that it preempts this thread (since the priority - * ceiling of mutex 2 is the greater than the priority of - * this thread). The test thread should run to completion - * and block this thread because its active priority is - * higher. - */ - log (" SCHED_FIFO scheduling and ceiling priority > " - "thread priority - "); - /* Have the test thread take mutex 2. */ - send_mutex_cmd (test_thread_id, CMD_TAKE_MUTEX, &m[2]); - sleep (1); - - log_trace ("Sending busy\n"); - send_cmd (test_thread_id, CMD_BUSY_LOOP); - log_trace ("Busy sent, yielding\n"); - pthread_yield (); - log_trace ("Returned from yield.\n"); - if ((states[test_thread_id].flags & FLAGS_IS_BUSY) != 0) { - log_error ("test thread did not run to completion.\n"); - /* Let the thread finish it's busy loop. */ - sleep (6); - } - else if ((states[test_thread_id].flags & FLAGS_WAS_BUSY) == 0) - log_error ("test thread never finished.\n"); - else - log_pass (); - states[test_thread_id].flags &= ~FLAGS_WAS_BUSY; - - /* Have the test thread release mutex 2. */ - send_cmd (test_thread_id, CMD_RELEASE_ALL); - sleep (1); - - /* Destroy the mutexes. */ - for (i = 0; i < 3; i++) - assert (pthread_mutex_destroy (&m[i]) == 0); - } -} - - -static void -mutex_prioinherit_test (void) -{ - pthread_mutexattr_t mattr; - struct sched_param param; - pthread_mutex_t m[3]; - mutex_kind_t mkind; - int i, policy, my_prio; - - /* Get this threads current priority. */ - assert (pthread_getschedparam (pthread_self(), &policy, - ¶m) == 0); - my_prio = param.sched_priority; /* save for later use */ - log_trace ("Current scheduling policy %d, priority %d\n", - policy, my_prio); - - log ("Testing priority inheritence\n"); - log ("----------------------------\n"); - for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) { - - log (" Protype PTHREAD_PRIO_INHERIT, Type %s\n", - mutextype_strs[mkind]); - - /* - * Initialize and create a mutex. - */ - assert (pthread_mutexattr_init (&mattr) == 0); - - /* - * Initialize and create 3 priority inheritence mutexes with - * default (max priority) ceilings. - */ - assert (pthread_mutexattr_setprotocol(&mattr, - PTHREAD_PRIO_INHERIT) == 0); - - /* - * Ensure that the first mutex type is a POSIX - * compliant mutex. - */ - if (mkind != M_POSIX) { - assert (pthread_mutexattr_settype (&mattr, - mutex_types[mkind]) == 0); - } - - for (i = 0; i < 3; i++) - assert (pthread_mutex_init (&m[i], &mattr) == 0); - - /* - * Test setup: - * Thread 4 - take mutex 0, 1 - * Thread 2 - enter protected busy loop with mutex 0 - * Thread 3 - enter protected busy loop with mutex 1 - * Thread 4 - enter protected busy loop with mutex 2 - * Thread 5 - enter busy loop - * Thread 6 - enter protected busy loop with mutex 0 - * Thread 4 - releases mutexes 1 and 0. - * - * Expected results: - * Threads complete in order 4, 6, 5, 3, 2 - */ - log (" Simple inheritence test - "); - - /* - * Command thread 4 to take mutexes 0 and 1. - */ - send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[0]); - sleep (1); /* Allow command to be received. */ - send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[1]); - sleep (1); - - /* - * Tell the threads to report themselves when they are - * at the bottom of their loop (waiting on wait_mutex). - */ - for (i = 0; i < NUM_THREADS; i++) - states[i].flags |= FLAGS_REPORT_WAITMUTEX; - - /* - * Command thread 2 to take mutex 0 and thread 3 to take - * mutex 1, both via a protected operation command. Since - * thread 4 owns mutexes 0 and 1, both threads 2 and 3 - * will block until the mutexes are released by thread 4. - */ - log_trace ("Commanding protected operation to thread 2.\n"); - send_mutex_cmd (2, CMD_PROTECTED_OP, &m[0]); - log_trace ("Commanding protected operation to thread 3.\n"); - send_mutex_cmd (3, CMD_PROTECTED_OP, &m[1]); - sleep (1); - - /* - * Command thread 4 to take mutex 2 via a protected operation - * and thread 5 to enter a busy loop for 5 seconds. Since - * thread 5 has higher priority than thread 4, thread 5 will - * enter the busy loop before thread 4 is activated. - */ - log_trace ("Commanding protected operation to thread 4.\n"); - send_mutex_cmd (4, CMD_PROTECTED_OP, &m[2]); - log_trace ("Commanding busy loop to thread 5.\n"); - send_cmd (5, CMD_BUSY_LOOP); - sleep (1); - if ((states[5].flags & FLAGS_IS_BUSY) == 0) - log_error ("thread 5 is not running.\n"); - log_trace ("Commanding protected operation thread 6.\n"); - send_mutex_cmd (6, CMD_PROTECTED_OP, &m[0]); - sleep (1); - if ((states[4].flags & FLAGS_WAS_BUSY) == 0) - log_error ("thread 4 failed to inherit priority.\n"); - states[4].flags = 0; - send_cmd (4, CMD_RELEASE_ALL); - sleep (5); - check_run_order ("4,6,5,3,2"); - - /* - * Clear the flags. - */ - for (i = 0; i < NUM_THREADS; i++) - states[i].flags = 0; - - /* - * Test setup: - * Thread 2 - enter busy loop (SCHED_FIFO) - * Thread 4 - take mutex 0 - * Thread 4 - priority change to same priority as thread 2 - * Thread 4 - release mutex 0 - * - * Expected results: - * Since thread 4 owns a priority mutex, it should be - * placed at the front of the run queue (for its new - * priority slot) when its priority is lowered to the - * same priority as thread 2. If thread 4 did not own - * a priority mutex, then it would have been added to - * the end of the run queue and thread 2 would have - * executed until it blocked (because it's scheduling - * policy is SCHED_FIFO). - * - */ - log (" Inheritence test with change of priority - "); - - /* - * Change threads 2 and 4 scheduling policies to be - * SCHED_FIFO. - */ - param.sched_priority = states[2].priority; - assert (pthread_setschedparam (states[2].tid, SCHED_FIFO, - ¶m) == 0); - param.sched_priority = states[4].priority; - assert (pthread_setschedparam (states[4].tid, SCHED_FIFO, - ¶m) == 0); - - /* - * Command thread 4 to take mutex 0. - */ - send_mutex_cmd (4, CMD_TAKE_MUTEX, &m[0]); - sleep (1); - - /* - * Command thread 2 to enter busy loop. - */ - send_cmd (2, CMD_BUSY_LOOP); - sleep (1); /* Allow command to be received. */ - - /* - * Command thread 4 to enter busy loop. - */ - send_cmd (4, CMD_BUSY_LOOP); - sleep (1); /* Allow command to be received. */ - - /* Have threads 2 and 4 report themselves. */ - states[2].flags = FLAGS_REPORT_WAITMUTEX; - states[4].flags = FLAGS_REPORT_WAITMUTEX; - - /* Change the priority of thread 4. */ - param.sched_priority = states[2].priority; - assert (pthread_setschedparam (states[4].tid, SCHED_FIFO, - ¶m) == 0); - sleep (5); - check_run_order ("4,2"); - - /* Clear the flags */ - states[2].flags = 0; - states[4].flags = 0; - - /* Reset the policies. */ - param.sched_priority = states[2].priority; - assert (pthread_setschedparam (states[2].tid, SCHED_RR, - ¶m) == 0); - param.sched_priority = states[4].priority; - assert (pthread_setschedparam (states[4].tid, SCHED_RR, - ¶m) == 0); - - send_cmd (4, CMD_RELEASE_MUTEX); - sleep (1); - - /* Destroy the mutexes. */ - for (i = 0; i < 3; i++) - assert (pthread_mutex_destroy (&m[i]) == 0); - } -} - - -int main (int argc, char *argv[]) -{ - pthread_mutexattr_t mattr; - pthread_condattr_t cattr; - pthread_attr_t pattr; - int i, policy, main_prio; - void * exit_status; - sigset_t mask; - struct sigaction act; - struct sched_param param; - - logfile = stdout; - - assert (pthread_getschedparam (pthread_self (), &policy, ¶m) == 0); - main_prio = param.sched_priority; - - /* Setupt our signal mask. */ - sigfillset (&mask); - sigdelset (&mask, SIGINT); - sigprocmask (SIG_SETMASK, &mask, NULL); - - /* Install a signal handler for SIGINT */ - sigemptyset (&act.sa_mask); - sigaddset (&act.sa_mask, SIGINT); - act.sa_handler = sighandler; - act.sa_flags = SA_RESTART; - sigaction (SIGINT, &act, NULL); - - /* - * Initialize the thread attribute. - */ - assert (pthread_attr_init (&pattr) == 0); - assert (pthread_attr_setdetachstate (&pattr, - PTHREAD_CREATE_JOINABLE) == 0); - - /* - * Initialize and create the waiter and condvar mutexes. - */ - assert (pthread_mutexattr_init (&mattr) == 0); - assert (pthread_mutex_init (&waiter_mutex, &mattr) == 0); - assert (pthread_mutex_init (&cond_mutex, &mattr) == 0); - - /* - * Initialize and create a condition variable. - */ - assert (pthread_condattr_init (&cattr) == 0); - assert (pthread_cond_init (&cond_var, &cattr) == 0); - - /* Create a pipe to catch the results of thread wakeups. */ - assert (pipe (pipefd) == 0); - -#ifdef DEBUG - assert (pthread_switch_add_np (kern_switch) == 0); -#endif - - /* - * Create the waiting threads. - */ - for (i = 0; i < NUM_THREADS; i++) { - assert (pthread_cond_init (&states[i].cond_var, &cattr) == 0); - states[i].id = (u_int8_t) i; /* NUM_THREADS must be <= 256 */ - states[i].status = 0; - states[i].cmd.cmd_id = CMD_NONE; - states[i].flags = 0; /* No flags yet. */ - assert (pthread_create (&states[i].tid, &pattr, waiter, - (void *) &states[i]) == 0); - param.sched_priority = main_prio - 10 + i; - states[i].priority = param.sched_priority; - assert (pthread_setschedparam (states[i].tid, SCHED_OTHER, - ¶m) == 0); -#if defined(_LIBC_R_) - { - char buf[30]; - - snprintf (buf, sizeof(buf), "waiter_%d", i); - pthread_set_name_np (states[i].tid, buf); - } -#endif - } - - /* Allow the threads to start. */ - sleep (1); - log_trace ("Done creating threads.\n"); - - log ("\n"); - mutex_init_test (); - log ("\n"); - mutex_destroy_test (); - log ("\n"); - mutex_lock_test (); - log ("\n"); - mutex_unlock_test (); - log ("\n"); - queueing_order_test (); - log ("\n"); - mutex_prioinherit_test (); - log ("\n"); - mutex_prioceiling_test (); - log ("\n"); - - log ("Total tests %d, passed %d, failed %d\n", - total, pass_count, error_count); - - /* Set the done flag and signal the threads to exit. */ - log_trace ("Setting done flag.\n"); - done = 1; - - /* - * Wait for the threads to finish. - */ - log_trace ("Trying to join threads.\n"); - for (i = 0; i < NUM_THREADS; i++) { - send_cmd (i, CMD_NONE); - assert (pthread_join (states[i].tid, &exit_status) == 0); - } - - /* Clean up after ourselves. */ - close (pipefd[0]); - close (pipefd[1]); - - if (error_count != 0) - exit (EX_OSERR); /* any better ideas??? */ - else - exit (EX_OK); -} diff --git a/lib/libc_r/test/mutex_d.exp b/lib/libc_r/test/mutex_d.exp deleted file mode 100644 index de8a4e4..0000000 --- a/lib/libc_r/test/mutex_d.exp +++ /dev/null @@ -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 diff --git a/lib/libc_r/test/propagate_s.pl b/lib/libc_r/test/propagate_s.pl deleted file mode 100755 index 9cd5fb0..0000000 --- a/lib/libc_r/test/propagate_s.pl +++ /dev/null @@ -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"; -} diff --git a/lib/libc_r/test/sem_d.c b/lib/libc_r/test/sem_d.c deleted file mode 100644 index b834591..0000000 --- a/lib/libc_r/test/sem_d.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/test/sem_d.exp b/lib/libc_r/test/sem_d.exp deleted file mode 100644 index b0de3da..0000000 --- a/lib/libc_r/test/sem_d.exp +++ /dev/null @@ -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 diff --git a/lib/libc_r/test/sigsuspend_d.c b/lib/libc_r/test/sigsuspend_d.c deleted file mode 100644 index d2420ed..0000000 --- a/lib/libc_r/test/sigsuspend_d.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/test/sigsuspend_d.exp b/lib/libc_r/test/sigsuspend_d.exp deleted file mode 100644 index 901fa50..0000000 --- a/lib/libc_r/test/sigsuspend_d.exp +++ /dev/null @@ -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 diff --git a/lib/libc_r/test/sigwait_d.c b/lib/libc_r/test/sigwait_d.c deleted file mode 100644 index f3ccd6b..0000000 --- a/lib/libc_r/test/sigwait_d.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/test/sigwait_d.exp b/lib/libc_r/test/sigwait_d.exp deleted file mode 100644 index 2e9b2c4..0000000 --- a/lib/libc_r/test/sigwait_d.exp +++ /dev/null @@ -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 diff --git a/lib/libc_r/test/verify b/lib/libc_r/test/verify deleted file mode 100755 index 2863e5c..0000000 --- a/lib/libc_r/test/verify +++ /dev/null @@ -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 -} diff --git a/lib/libc_r/uthread/Makefile.inc b/lib/libc_r/uthread/Makefile.inc deleted file mode 100644 index 6d457c1..0000000 --- a/lib/libc_r/uthread/Makefile.inc +++ /dev/null @@ -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 diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h deleted file mode 100644 index 56f7415..0000000 --- a/lib/libc_r/uthread/pthread_private.h +++ /dev/null @@ -1,1411 +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. - * - * Private thread definitions for the uthread kernel. - * - * $FreeBSD$ - */ - -#ifndef _PTHREAD_PRIVATE_H -#define _PTHREAD_PRIVATE_H - -/* - * Evaluate the storage class specifier. - */ -#ifdef GLOBAL_PTHREAD_PRIVATE -#define SCLASS -#else -#define SCLASS extern -#endif - -/* - * Include files. - */ -#include <setjmp.h> -#include <signal.h> -#include <stdio.h> -#include <sys/param.h> -#include <sys/queue.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/cdefs.h> -#include <sched.h> -#include <spinlock.h> -#include <ucontext.h> -#include <pthread_np.h> -#include <vm/vm.h> -#include <vm/vm_param.h> -#include <vm/pmap.h> -#include <vm/vm_map.h> - -/* - * Define machine dependent macros to get and set the stack pointer - * from the supported contexts. Also define a macro to set the return - * address in a jmp_buf context. - * - * XXX - These need to be moved into architecture dependent support files. - * XXX - These need to be documented so porters know what's required. - */ -#if defined(__i386__) -#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2])) -#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2])) -#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_esp)) -#define SET_STACK_JB(jb, stk) (jb)[0]._jb[2] = (int)(stk) -#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[2] = (int)(stk) -#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_esp = (int)(stk) -#define FP_SAVE_UC(ucp) do { \ - char *fdata; \ - fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \ - __asm__("fnsave %0": :"m"(*fdata)); \ -} while (0) -#define FP_RESTORE_UC(ucp) do { \ - char *fdata; \ - fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \ - __asm__("frstor %0": :"m"(*fdata)); \ -} while (0) -#define SET_RETURN_ADDR_JB(jb, ra) do { \ - (jb)[0]._jb[0] = (int)(ra); \ - (jb)[0]._jb[3] = 0; \ -} while (0) -#elif defined(__amd64__) -#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2])) -#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2])) -#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_rsp)) -#define SET_STACK_JB(jb, stk) (jb)[0]._jb[2] = (long)(stk) -#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[2] = (long)(stk) -#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_rsp = (long)(stk) -#define FP_SAVE_UC(ucp) do { \ - char *fdata; \ - fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \ - __asm__("fxsave %0": :"m"(*fdata)); \ -} while (0) -#define FP_RESTORE_UC(ucp) do { \ - char *fdata; \ - fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \ - __asm__("fxrstor %0": :"m"(*fdata)); \ -} while (0) -#define SET_RETURN_ADDR_JB(jb, ra) (jb)[0]._jb[0] = (long)(ra) -#elif defined(__alpha__) -#include <machine/reg.h> -#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[R_SP + 4])) -#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[R_SP + 4])) -#define GET_STACK_UC(ucp) ((ucp)->uc_mcontext.mc_regs[R_SP]) -#define SET_STACK_JB(jb, stk) (jb)[0]._jb[R_SP + 4] = (long)(stk) -#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[R_SP + 4] = (long)(stk) -#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_regs[R_SP] = (unsigned long)(stk) -#define FP_SAVE_UC(ucp) -#define FP_RESTORE_UC(ucp) -#define SET_RETURN_ADDR_JB(jb, ra) do { \ - (jb)[0]._jb[2] = (long)(ra); \ - (jb)[0]._jb[R_RA + 4] = (long)(ra); \ - (jb)[0]._jb[R_T12 + 4] = (long)(ra); \ -} while (0) -#elif defined(__ia64__) -#define GET_BSP_JB(jb) (*((unsigned long*)JMPBUF_ADDR_OF(jb,J_BSP))) -#define GET_STACK_JB(jb) (*((unsigned long*)JMPBUF_ADDR_OF(jb,J_SP))) -#define GET_STACK_SJB(sjb) GET_STACK_JB(sjb) -#define SET_RETURN_ADDR_JB(jb, ra) \ -do { \ - *((unsigned long*)JMPBUF_ADDR_OF(jb,J_B0)) = ((long*)(ra))[0]; \ - *((unsigned long*)JMPBUF_ADDR_OF(jb,J_GP)) = ((long*)(ra))[1]; \ - *((unsigned long*)JMPBUF_ADDR_OF(jb,J_PFS)) &= ~0x1FFFFFFFFFUL; \ -} while (0) -#define SET_STACK_JB(jb, stk, sz) \ -do { \ - UPD_STACK_JB(jb, stk + sz - 16); \ - GET_BSP_JB(jb) = (long)(stk); \ -} while (0) -#define UPD_STACK_JB(jb, stk) GET_STACK_JB(jb) = (long)(stk) -#elif defined(__sparc64__) -#include <machine/frame.h> - -#define CCFSZ sizeof (struct frame) - -#define GET_STACK_JB(jb) \ - ((unsigned long)((jb)[0]._jb[_JB_SP]) + SPOFF) -#define GET_STACK_SJB(sjb) \ - ((unsigned long)((sjb)[0]._sjb[_JB_SP]) + SPOFF) -#define GET_STACK_UC(ucp) \ - ((ucp)->uc_mcontext.mc_sp + SPOFF) -/* - * XXX: sparc64 _longjmp() expects a register window on the stack - * at the given position, so we must make sure that the space where - * it is expected is readable. Subtracting the frame size here works - * because the SET_STACK macros are only used to set up new stacks - * or signal stacks, but it is a bit dirty. - */ -#define SET_STACK_JB(jb, stk) \ - (jb)[0]._jb[_JB_SP] = (long)(stk) - SPOFF - CCFSZ -#define SET_STACK_SJB(sjb, stk) \ - (sjb)[0]._sjb[_JB_SP] = (long)(stk) - SPOFF - CCFSZ -#define SET_STACK_UC(ucp, stk) \ - (ucp)->uc_mcontext.mc_sp = (unsigned long)(stk) - SPOFF - CCFSZ -#define FP_SAVE_UC(ucp) /* XXX */ -#define FP_RESTORE_UC(ucp) /* XXX */ -#define SET_RETURN_ADDR_JB(jb, ra) \ - (jb)[0]._jb[_JB_PC] = (long)(ra) - 8 -#else -#error "Don't recognize this architecture!" -#endif - -/* - * Kernel fatal error handler macro. - */ -#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) - - -/* Output debug messages like this: */ -#define stdout_debug(args...) do { \ - char buf[128]; \ - snprintf(buf, sizeof(buf), ##args); \ - __sys_write(1, buf, strlen(buf)); \ -} while (0) -#define stderr_debug(args...) do { \ - char buf[128]; \ - snprintf(buf, sizeof(buf), ##args); \ - __sys_write(2, buf, strlen(buf)); \ -} while (0) - - - -/* - * Priority queue manipulation macros (using pqe link): - */ -#define PTHREAD_PRIOQ_INSERT_HEAD(thrd) _pq_insert_head(&_readyq,thrd) -#define PTHREAD_PRIOQ_INSERT_TAIL(thrd) _pq_insert_tail(&_readyq,thrd) -#define PTHREAD_PRIOQ_REMOVE(thrd) _pq_remove(&_readyq,thrd) -#define PTHREAD_PRIOQ_FIRST() _pq_first(&_readyq) - -/* - * Waiting queue manipulation macros (using pqe link): - */ -#define PTHREAD_WAITQ_REMOVE(thrd) _waitq_remove(thrd) -#define PTHREAD_WAITQ_INSERT(thrd) _waitq_insert(thrd) - -#if defined(_PTHREADS_INVARIANTS) -#define PTHREAD_WAITQ_CLEARACTIVE() _waitq_clearactive() -#define PTHREAD_WAITQ_SETACTIVE() _waitq_setactive() -#else -#define PTHREAD_WAITQ_CLEARACTIVE() -#define PTHREAD_WAITQ_SETACTIVE() -#endif - -/* - * Work queue manipulation macros (using qe link): - */ -#define PTHREAD_WORKQ_INSERT(thrd) do { \ - TAILQ_INSERT_TAIL(&_workq,thrd,qe); \ - (thrd)->flags |= PTHREAD_FLAGS_IN_WORKQ; \ -} while (0) -#define PTHREAD_WORKQ_REMOVE(thrd) do { \ - TAILQ_REMOVE(&_workq,thrd,qe); \ - (thrd)->flags &= ~PTHREAD_FLAGS_IN_WORKQ; \ -} while (0) - - -/* - * State change macro without scheduling queue change: - */ -#define PTHREAD_SET_STATE(thrd, newstate) do { \ - (thrd)->state = newstate; \ - (thrd)->fname = __FILE__; \ - (thrd)->lineno = __LINE__; \ -} while (0) - -/* - * State change macro with scheduling queue change - This must be - * called with preemption deferred (see thread_kern_sched_[un]defer). - */ -#if defined(_PTHREADS_INVARIANTS) -#include <assert.h> -#define PTHREAD_ASSERT(cond, msg) do { \ - if (!(cond)) \ - PANIC(msg); \ -} while (0) -#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd) \ - PTHREAD_ASSERT((((thrd)->flags & PTHREAD_FLAGS_IN_SYNCQ) == 0), \ - "Illegal call from signal handler"); -#define PTHREAD_NEW_STATE(thrd, newstate) do { \ - if (_thread_kern_new_state != 0) \ - PANIC("Recursive PTHREAD_NEW_STATE"); \ - _thread_kern_new_state = 1; \ - if ((thrd)->state != newstate) { \ - if ((thrd)->state == PS_RUNNING) { \ - PTHREAD_PRIOQ_REMOVE(thrd); \ - PTHREAD_SET_STATE(thrd, newstate); \ - PTHREAD_WAITQ_INSERT(thrd); \ - } else if (newstate == PS_RUNNING) { \ - PTHREAD_WAITQ_REMOVE(thrd); \ - PTHREAD_SET_STATE(thrd, newstate); \ - PTHREAD_PRIOQ_INSERT_TAIL(thrd); \ - } \ - } \ - _thread_kern_new_state = 0; \ -} while (0) -#else -#define PTHREAD_ASSERT(cond, msg) -#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd) -#define PTHREAD_NEW_STATE(thrd, newstate) do { \ - if ((thrd)->state != newstate) { \ - if ((thrd)->state == PS_RUNNING) { \ - PTHREAD_PRIOQ_REMOVE(thrd); \ - PTHREAD_WAITQ_INSERT(thrd); \ - } else if (newstate == PS_RUNNING) { \ - PTHREAD_WAITQ_REMOVE(thrd); \ - PTHREAD_PRIOQ_INSERT_TAIL(thrd); \ - } \ - } \ - PTHREAD_SET_STATE(thrd, newstate); \ -} while (0) -#endif - -/* - * Define the signals to be used for scheduling. - */ -#if defined(_PTHREADS_COMPAT_SCHED) -#define _ITIMER_SCHED_TIMER ITIMER_VIRTUAL -#define _SCHED_SIGNAL SIGVTALRM -#else -#define _ITIMER_SCHED_TIMER ITIMER_PROF -#define _SCHED_SIGNAL SIGPROF -#endif - -/* - * Priority queues. - * - * XXX It'd be nice if these were contained in uthread_priority_queue.[ch]. - */ -typedef struct pq_list { - TAILQ_HEAD(, pthread) pl_head; /* list of threads at this priority */ - TAILQ_ENTRY(pq_list) pl_link; /* link for queue of priority lists */ - int pl_prio; /* the priority of this list */ - int pl_queued; /* is this in the priority queue */ -} pq_list_t; - -typedef struct pq_queue { - TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */ - pq_list_t *pq_lists; /* array of all priority lists */ - int pq_size; /* number of priority lists */ -} pq_queue_t; - - -/* - * TailQ initialization values. - */ -#define TAILQ_INITIALIZER { NULL, NULL } - -/* - * Mutex definitions. - */ -union pthread_mutex_data { - void *m_ptr; - int m_count; -}; - -struct pthread_mutex { - enum pthread_mutextype m_type; - int m_protocol; - TAILQ_HEAD(mutex_head, pthread) m_queue; - struct pthread *m_owner; - union pthread_mutex_data m_data; - long m_flags; - int m_refcount; - - /* - * Used for priority inheritence and protection. - * - * m_prio - For priority inheritence, the highest active - * priority (threads locking the mutex inherit - * this priority). For priority protection, the - * ceiling priority of this mutex. - * m_saved_prio - mutex owners inherited priority before - * taking the mutex, restored when the owner - * unlocks the mutex. - */ - int m_prio; - int m_saved_prio; - - /* - * Link for list of all mutexes a thread currently owns. - */ - TAILQ_ENTRY(pthread_mutex) m_qe; - - /* - * Lock for accesses to this structure. - */ - spinlock_t lock; -}; - -/* - * Flags for mutexes. - */ -#define MUTEX_FLAGS_PRIVATE 0x01 -#define MUTEX_FLAGS_INITED 0x02 -#define MUTEX_FLAGS_BUSY 0x04 - -/* - * Static mutex initialization values. - */ -#define PTHREAD_MUTEX_STATIC_INITIALIZER \ - { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \ - NULL, { NULL }, MUTEX_FLAGS_PRIVATE, 0, 0, 0, TAILQ_INITIALIZER, \ - _SPINLOCK_INITIALIZER } - -struct pthread_mutex_attr { - enum pthread_mutextype m_type; - int m_protocol; - int m_ceiling; - long m_flags; -}; - -#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ - { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } - -/* - * Condition variable definitions. - */ -enum pthread_cond_type { - COND_TYPE_FAST, - COND_TYPE_MAX -}; - -struct pthread_cond { - enum pthread_cond_type c_type; - TAILQ_HEAD(cond_head, pthread) c_queue; - pthread_mutex_t c_mutex; - void *c_data; - long c_flags; - int c_seqno; - - /* - * Lock for accesses to this structure. - */ - spinlock_t lock; -}; - -struct pthread_cond_attr { - enum pthread_cond_type c_type; - long c_flags; -}; - -/* - * Flags for condition variables. - */ -#define COND_FLAGS_PRIVATE 0x01 -#define COND_FLAGS_INITED 0x02 -#define COND_FLAGS_BUSY 0x04 - -/* - * Static cond initialization values. - */ -#define PTHREAD_COND_STATIC_INITIALIZER \ - { COND_TYPE_FAST, TAILQ_INITIALIZER, NULL, NULL, \ - 0, 0, _SPINLOCK_INITIALIZER } - -/* - * Semaphore definitions. - */ -struct sem { -#define SEM_MAGIC ((u_int32_t) 0x09fa4012) - u_int32_t magic; - pthread_mutex_t lock; - pthread_cond_t gtzero; - u_int32_t count; - u_int32_t nwaiters; -}; - -/* - * Cleanup definitions. - */ -struct pthread_cleanup { - struct pthread_cleanup *next; - void (*routine) (); - void *routine_arg; -}; - -struct pthread_atfork { - TAILQ_ENTRY(pthread_atfork) qe; - void (*prepare)(void); - void (*parent)(void); - void (*child)(void); -}; - -struct pthread_attr { - int sched_policy; - int sched_inherit; - int sched_interval; - int prio; - int suspend; - int flags; - void *arg_attr; - void (*cleanup_attr) (); - void *stackaddr_attr; - size_t stacksize_attr; - size_t guardsize_attr; -}; - -/* - * Thread creation state attributes. - */ -#define PTHREAD_CREATE_RUNNING 0 -#define PTHREAD_CREATE_SUSPENDED 1 - -/* - * Miscellaneous definitions. - */ -#define PTHREAD_STACK32_DEFAULT (1 * 1024 * 1024) -#define PTHREAD_STACK64_DEFAULT (2 * 1024 * 1024) - -/* - * Size of default red zone at the end of each stack. In actuality, this "red - * zone" is merely an unmapped region, except in the case of the initial stack. - * Since mmap() makes it possible to specify the maximum growth of a MAP_STACK - * region, an unmapped gap between thread stacks achieves the same effect as - * explicitly mapped red zones. - * This is declared and initialized in uthread_init.c. - */ -extern int _pthread_guard_default; - -extern int _pthread_page_size; - -extern int _pthread_stack_default; - -extern int _pthread_stack_initial; - -/* - * Maximum size of initial thread's stack. This perhaps deserves to be larger - * than the stacks of other threads, since many applications are likely to run - * almost entirely on this stack. - */ -#define PTHREAD_STACK32_INITIAL (2 * 1024 * 1024) -#define PTHREAD_STACK64_INITIAL (4 * 1024 * 1024) - -/* - * Define the different priority ranges. All applications have thread - * priorities constrained within 0-31. The threads library raises the - * priority when delivering signals in order to ensure that signal - * delivery happens (from the POSIX spec) "as soon as possible". - * In the future, the threads library will also be able to map specific - * threads into real-time (cooperating) processes or kernel threads. - * The RT and SIGNAL priorities will be used internally and added to - * thread base priorities so that the scheduling queue can handle both - * normal and RT priority threads with and without signal handling. - * - * The approach taken is that, within each class, signal delivery - * always has priority over thread execution. - */ -#define PTHREAD_DEFAULT_PRIORITY 15 -#define PTHREAD_MIN_PRIORITY 0 -#define PTHREAD_MAX_PRIORITY 31 /* 0x1F */ -#define PTHREAD_SIGNAL_PRIORITY 32 /* 0x20 */ -#define PTHREAD_RT_PRIORITY 64 /* 0x40 */ -#define PTHREAD_FIRST_PRIORITY PTHREAD_MIN_PRIORITY -#define PTHREAD_LAST_PRIORITY \ - (PTHREAD_MAX_PRIORITY + PTHREAD_SIGNAL_PRIORITY + PTHREAD_RT_PRIORITY) -#define PTHREAD_BASE_PRIORITY(prio) ((prio) & PTHREAD_MAX_PRIORITY) - -/* - * Clock resolution in microseconds. - */ -#define CLOCK_RES_USEC 10000 -#define CLOCK_RES_USEC_MIN 1000 - -/* - * Time slice period in microseconds. - */ -#define TIMESLICE_USEC 20000 - -/* - * Define a thread-safe macro to get the current time of day - * which is updated at regular intervals by the scheduling signal - * handler. - */ -#define GET_CURRENT_TOD(tv) \ - do { \ - tv.tv_sec = _sched_tod.tv_sec; \ - tv.tv_usec = _sched_tod.tv_usec; \ - } while (tv.tv_sec != _sched_tod.tv_sec) - - -struct pthread_rwlockattr { - int pshared; -}; - -struct pthread_rwlock { - pthread_mutex_t lock; /* monitor lock */ - int state; /* 0 = idle >0 = # of readers -1 = writer */ - pthread_cond_t read_signal; - pthread_cond_t write_signal; - int blocked_writers; -}; - -/* - * Thread states. - */ -enum pthread_state { - PS_RUNNING, - PS_SIGTHREAD, - PS_MUTEX_WAIT, - PS_COND_WAIT, - PS_FDLR_WAIT, - PS_FDLW_WAIT, - PS_FDR_WAIT, - PS_FDW_WAIT, - PS_FILE_WAIT, - PS_POLL_WAIT, - PS_SELECT_WAIT, - PS_SLEEP_WAIT, - PS_WAIT_WAIT, - PS_SIGSUSPEND, - PS_SIGWAIT, - PS_SPINBLOCK, - PS_JOIN, - PS_SUSPENDED, - PS_DEAD, - PS_DEADLOCK, - PS_STATE_MAX -}; - - -/* - * File descriptor locking definitions. - */ -#define FD_READ 0x1 -#define FD_WRITE 0x2 -#define FD_RDWR (FD_READ | FD_WRITE) - -/* - * File descriptor table structure. - */ -struct fd_table_entry { - /* - * Lock for accesses to this file descriptor table - * entry. This is passed to _spinlock() to provide atomic - * access to this structure. It does *not* represent the - * state of the lock on the file descriptor. - */ - spinlock_t lock; - TAILQ_HEAD(, pthread) r_queue; /* Read queue. */ - TAILQ_HEAD(, pthread) w_queue; /* Write queue. */ - struct pthread *r_owner; /* Ptr to thread owning read lock. */ - struct pthread *w_owner; /* Ptr to thread owning write lock. */ - char *r_fname; /* Ptr to read lock source file name */ - int r_lineno; /* Read lock source line number. */ - char *w_fname; /* Ptr to write lock source file name */ - int w_lineno; /* Write lock source line number. */ - int r_lockcount; /* Count for FILE read locks. */ - int w_lockcount; /* Count for FILE write locks. */ - int flags; /* Flags used in open. */ -}; - -struct pthread_poll_data { - int nfds; - struct pollfd *fds; -}; - -union pthread_wait_data { - pthread_mutex_t mutex; - pthread_cond_t cond; - const sigset_t *sigwait; /* Waiting on a signal in sigwait */ - struct { - short fd; /* Used when thread waiting on fd */ - short branch; /* Line number, for debugging. */ - char *fname; /* Source file name for debugging.*/ - } fd; - FILE *fp; - struct pthread_poll_data *poll_data; - spinlock_t *spinlock; - struct pthread *thread; -}; - -/* - * Define a continuation routine that can be used to perform a - * transfer of control: - */ -typedef void (*thread_continuation_t) (void *); - -struct pthread_signal_frame; - -struct pthread_state_data { - struct pthread_signal_frame *psd_curframe; - sigset_t psd_sigmask; - struct timespec psd_wakeup_time; - union pthread_wait_data psd_wait_data; - enum pthread_state psd_state; - int psd_flags; - int psd_interrupted; - int psd_longjmp_val; - int psd_sigmask_seqno; - int psd_signo; - int psd_sig_defer_count; - /* XXX - What about thread->timeout and/or thread->error? */ -}; - -struct join_status { - struct pthread *thread; - void *ret; - int error; -}; - -/* - * The frame that is added to the top of a threads stack when setting up - * up the thread to run a signal handler. - */ -struct pthread_signal_frame { - /* - * This stores the threads state before the signal. - */ - struct pthread_state_data saved_state; - - /* - * Threads return context; we use only jmp_buf's for now. - */ - union { - jmp_buf jb; - ucontext_t uc; - } ctx; - int signo; /* signal, arg 1 to sighandler */ - int sig_has_args; /* use signal args if true */ - ucontext_t uc; - siginfo_t siginfo; -}; - -struct pthread_specific_elem { - const void *data; - int seqno; -}; - -/* - * Thread structure. - */ -struct pthread { - /* - * Magic value to help recognize a valid thread structure - * from an invalid one: - */ -#define PTHREAD_MAGIC ((u_int32_t) 0xd09ba115) - u_int32_t magic; - char *name; - u_int64_t uniqueid; /* for gdb */ - - /* - * Lock for accesses to this thread structure. - */ - spinlock_t lock; - - /* Queue entry for list of all threads: */ - TAILQ_ENTRY(pthread) tle; - - /* Queue entry for list of dead threads: */ - TAILQ_ENTRY(pthread) dle; - - /* - * Thread start routine, argument, stack pointer and thread - * attributes. - */ - void *(*start_routine)(void *); - void *arg; - void *stack; - struct pthread_attr attr; - - /* - * Threads return context; we use only jmp_buf's for now. - */ - union { - jmp_buf jb; - ucontext_t uc; - } ctx; - - /* - * Used for tracking delivery of signal handlers. - */ - struct pthread_signal_frame *curframe; - - /* - * Cancelability flags - the lower 2 bits are used by cancel - * definitions in pthread.h - */ -#define PTHREAD_AT_CANCEL_POINT 0x0004 -#define PTHREAD_CANCELLING 0x0008 -#define PTHREAD_CANCEL_NEEDED 0x0010 - int cancelflags; - - thread_continuation_t continuation; - - /* - * Current signal mask and pending signals. - */ - sigset_t sigmask; - sigset_t sigpend; - int sigmask_seqno; - int check_pending; - - /* Thread state: */ - enum pthread_state state; - - /* Scheduling clock when this thread was last made active. */ - long last_active; - - /* Scheduling clock when this thread was last made inactive. */ - long last_inactive; - - /* - * Number of microseconds accumulated by this thread when - * time slicing is active. - */ - long slice_usec; - - /* - * Time to wake up thread. This is used for sleeping threads and - * for any operation which may time out (such as select). - */ - struct timespec wakeup_time; - - /* TRUE if operation has timed out. */ - int timeout; - - /* - * Error variable used instead of errno. The function __error() - * returns a pointer to this. - */ - int error; - - /* - * The joiner is the thread that is joining to this thread. The - * join status keeps track of a join operation to another thread. - */ - struct pthread *joiner; - struct join_status join_status; - - /* - * The current thread can belong to only one scheduling queue at - * a time (ready or waiting queue). It can also belong to: - * - * o A queue of threads waiting for a mutex - * o A queue of threads waiting for a condition variable - * o A queue of threads waiting for a file descriptor lock - * o A queue of threads needing work done by the kernel thread - * (waiting for a spinlock or file I/O) - * - * A thread can also be joining a thread (the joiner field above). - * - * It must not be possible for a thread to belong to any of the - * above queues while it is handling a signal. Signal handlers - * may longjmp back to previous stack frames circumventing normal - * control flow. This could corrupt queue integrity if the thread - * retains membership in the queue. Therefore, if a thread is a - * member of one of these queues when a signal handler is invoked, - * it must remove itself from the queue before calling the signal - * handler and reinsert itself after normal return of the handler. - * - * Use pqe for the scheduling queue link (both ready and waiting), - * sqe for synchronization (mutex and condition variable) queue - * links, and qe for all other links. - */ - TAILQ_ENTRY(pthread) pqe; /* priority queue link */ - TAILQ_ENTRY(pthread) sqe; /* synchronization queue link */ - TAILQ_ENTRY(pthread) qe; /* all other queues link */ - - /* Wait data. */ - union pthread_wait_data data; - - /* - * Allocated for converting select into poll. - */ - struct pthread_poll_data poll_data; - - /* - * Set to TRUE if a blocking operation was - * interrupted by a signal: - */ - int interrupted; - - /* Signal number when in state PS_SIGWAIT: */ - int signo; - - /* - * Set to non-zero when this thread has deferred signals. - * We allow for recursive deferral. - */ - int sig_defer_count; - - /* - * Set to TRUE if this thread should yield after undeferring - * signals. - */ - int yield_on_sig_undefer; - - /* Miscellaneous flags; only set with signals deferred. */ - int flags; -#define PTHREAD_FLAGS_PRIVATE 0x0001 -#define PTHREAD_EXITING 0x0002 -#define PTHREAD_FLAGS_IN_WAITQ 0x0004 /* in waiting queue using pqe link */ -#define PTHREAD_FLAGS_IN_PRIOQ 0x0008 /* in priority queue using pqe link */ -#define PTHREAD_FLAGS_IN_WORKQ 0x0010 /* in work queue using qe link */ -#define PTHREAD_FLAGS_IN_FILEQ 0x0020 /* in file lock queue using qe link */ -#define PTHREAD_FLAGS_IN_FDQ 0x0040 /* in fd lock queue using qe link */ -#define PTHREAD_FLAGS_IN_CONDQ 0x0080 /* in condition queue using sqe link*/ -#define PTHREAD_FLAGS_IN_MUTEXQ 0x0100 /* in mutex queue using sqe link */ -#define PTHREAD_FLAGS_SUSPENDED 0x0200 /* thread is suspended */ -#define PTHREAD_FLAGS_TRACE 0x0400 /* for debugging purposes */ -#define PTHREAD_FLAGS_IN_SYNCQ \ - (PTHREAD_FLAGS_IN_CONDQ | PTHREAD_FLAGS_IN_MUTEXQ) - - /* - * Base priority is the user setable and retrievable priority - * of the thread. It is only affected by explicit calls to - * set thread priority and upon thread creation via a thread - * attribute or default priority. - */ - char base_priority; - - /* - * Inherited priority is the priority a thread inherits by - * taking a priority inheritence or protection mutex. It - * is not affected by base priority changes. Inherited - * priority defaults to and remains 0 until a mutex is taken - * that is being waited on by any other thread whose priority - * is non-zero. - */ - char inherited_priority; - - /* - * Active priority is always the maximum of the threads base - * priority and inherited priority. When there is a change - * in either the base or inherited priority, the active - * priority must be recalculated. - */ - char active_priority; - - /* Number of priority ceiling or protection mutexes owned. */ - int priority_mutex_count; - - /* Number rwlocks rdlocks held. */ - int rdlock_count; - - /* - * Queue of currently owned mutexes. - */ - TAILQ_HEAD(, pthread_mutex) mutexq; - - void *ret; - struct pthread_specific_elem *specific; - int specific_data_count; - - /* Cleanup handlers Link List */ - struct pthread_cleanup *cleanup; - char *fname; /* Ptr to source file name */ - int lineno; /* Source line number. */ -}; - -/* - * Global variables for the uthread kernel. - */ - -SCLASS void *_usrstack -#ifdef GLOBAL_PTHREAD_PRIVATE -= (void *) USRSTACK; -#else -; -#endif - -/* Kernel thread structure used when there are no running threads: */ -SCLASS struct pthread _thread_kern_thread; - -/* Ptr to the thread structure for the running thread: */ -SCLASS struct pthread * volatile _thread_run -#ifdef GLOBAL_PTHREAD_PRIVATE -= &_thread_kern_thread; -#else -; -#endif - -/* Ptr to the thread structure for the last user thread to run: */ -SCLASS struct pthread * volatile _last_user_thread -#ifdef GLOBAL_PTHREAD_PRIVATE -= &_thread_kern_thread; -#else -; -#endif - -/* List of all threads: */ -SCLASS TAILQ_HEAD(, pthread) _thread_list -#ifdef GLOBAL_PTHREAD_PRIVATE -= TAILQ_HEAD_INITIALIZER(_thread_list); -#else -; -#endif - -/* - * Array of kernel pipe file descriptors that are used to ensure that - * no signals are missed in calls to _select. - */ -SCLASS int _thread_kern_pipe[2] -#ifdef GLOBAL_PTHREAD_PRIVATE -= { - -1, - -1 -}; -#else -; -#endif -SCLASS int volatile _queue_signals -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif -SCLASS int _thread_kern_in_sched -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS int _sig_in_handler -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -/* Time of day at last scheduling timer signal: */ -SCLASS struct timeval volatile _sched_tod -#ifdef GLOBAL_PTHREAD_PRIVATE -= { 0, 0 }; -#else -; -#endif - -/* - * Current scheduling timer ticks; used as resource usage. - */ -SCLASS unsigned int volatile _sched_ticks -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -/* Dead threads: */ -SCLASS TAILQ_HEAD(, pthread) _dead_list -#ifdef GLOBAL_PTHREAD_PRIVATE -= TAILQ_HEAD_INITIALIZER(_dead_list); -#else -; -#endif - -/* Initial thread: */ -SCLASS struct pthread *_thread_initial -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -SCLASS TAILQ_HEAD(atfork_head, pthread_atfork) _atfork_list; -SCLASS pthread_mutex_t _atfork_mutex; - -/* Default thread attributes: */ -SCLASS struct pthread_attr _pthread_attr_default -#ifdef GLOBAL_PTHREAD_PRIVATE -= { SCHED_RR, 0, TIMESLICE_USEC, PTHREAD_DEFAULT_PRIORITY, - PTHREAD_CREATE_RUNNING, PTHREAD_CREATE_JOINABLE, NULL, NULL, NULL, - -1, -1 }; -#else -; -#endif - -/* Default mutex attributes: */ -#define PTHREAD_MUTEXATTR_DEFAULT \ - { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, 0 } - -/* Default condition variable attributes: */ -#define PTHREAD_CONDATTR_DEFAULT { COND_TYPE_FAST, 0 } - -/* - * Standard I/O file descriptors need special flag treatment since - * setting one to non-blocking does all on *BSD. Sigh. This array - * is used to store the initial flag settings. - */ -SCLASS int _pthread_stdio_flags[3]; - -/* File table information: */ -SCLASS struct fd_table_entry **_thread_fd_table -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -/* Table for polling file descriptors: */ -SCLASS struct pollfd *_thread_pfd_table -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -SCLASS const int dtablecount -#ifdef GLOBAL_PTHREAD_PRIVATE -= 4096/sizeof(struct fd_table_entry); -#else -; -#endif -SCLASS int _thread_dtablesize /* Descriptor table size. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS int _clock_res_usec /* Clock resolution in usec. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= CLOCK_RES_USEC; -#else -; -#endif - -/* Garbage collector mutex and condition variable. */ -SCLASS pthread_mutex_t _gc_mutex -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; -SCLASS pthread_cond_t _gc_cond -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; - -/* - * Array of signal actions for this process. - */ -SCLASS struct sigaction _thread_sigact[NSIG]; - -/* - * Array of counts of dummy handlers for SIG_DFL signals. This is used to - * assure that there is always a dummy signal handler installed while there is a - * thread sigwait()ing on the corresponding signal. - */ -SCLASS int _thread_dfl_count[NSIG]; - -/* - * Pending signals and mask for this process: - */ -SCLASS sigset_t _process_sigpending; -SCLASS sigset_t _process_sigmask -#ifdef GLOBAL_PTHREAD_PRIVATE -= { {0, 0, 0, 0} } -#endif -; - -/* - * Scheduling queues: - */ -SCLASS pq_queue_t _readyq; -SCLASS TAILQ_HEAD(, pthread) _waitingq; - -/* - * Work queue: - */ -SCLASS TAILQ_HEAD(, pthread) _workq; - -/* Tracks the number of threads blocked while waiting for a spinlock. */ -SCLASS volatile int _spinblock_count -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* Used to maintain pending and active signals: */ -struct sigstatus { - int pending; /* Is this a pending signal? */ - int blocked; /* - * A handler is currently active for - * this signal; ignore subsequent - * signals until the handler is done. - */ - int signo; /* arg 1 to signal handler */ - siginfo_t siginfo; /* arg 2 to signal handler */ - ucontext_t uc; /* arg 3 to signal handler */ -}; - -SCLASS struct sigstatus _thread_sigq[NSIG]; - -/* Indicates that the signal queue needs to be checked. */ -SCLASS volatile int _sigq_check_reqd -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* Thread switch hook. */ -SCLASS pthread_switch_routine_t _sched_switch_hook -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; - -/* - * Declare the kernel scheduler jump buffer and stack: - */ -SCLASS jmp_buf _thread_kern_sched_jb; - -SCLASS void * _thread_kern_sched_stack -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; - - -/* Used for _PTHREADS_INVARIANTS checking. */ -SCLASS int _thread_kern_new_state -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* Undefine the storage class specifier: */ -#undef SCLASS - -#ifdef _LOCK_DEBUG -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock_debug(_fd, _type, \ - _ts, __FILE__, __LINE__) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock_debug(_fd, _type, \ - __FILE__, __LINE__) -#else -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) -#endif - -/* - * Function prototype definitions. - */ -__BEGIN_DECLS -char *__ttyname_basic(int); -void _cond_wait_backout(pthread_t); -void _fd_lock_backout(pthread_t); -int _find_thread(pthread_t); -struct pthread *_get_curthread(void); -void _set_curthread(struct pthread *); -void *_thread_stack_alloc(size_t, size_t); -void _thread_stack_free(void *, size_t, size_t); -int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t); -int _mutex_cv_lock(pthread_mutex_t *); -int _mutex_cv_unlock(pthread_mutex_t *); -void _mutex_lock_backout(pthread_t); -void _mutex_notify_priochange(pthread_t); -int _mutex_reinit(pthread_mutex_t *); -void _mutex_unlock_private(pthread_t); -int _cond_reinit(pthread_cond_t *); -int _pq_alloc(struct pq_queue *, int, int); -int _pq_init(struct pq_queue *); -void _pq_remove(struct pq_queue *pq, struct pthread *); -void _pq_insert_head(struct pq_queue *pq, struct pthread *); -void _pq_insert_tail(struct pq_queue *pq, struct pthread *); -struct pthread *_pq_first(struct pq_queue *pq); -void *_pthread_getspecific(pthread_key_t); -int _pthread_key_create(pthread_key_t *, void (*) (void *)); -int _pthread_key_delete(pthread_key_t); -int _pthread_mutex_destroy(pthread_mutex_t *); -int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); -int _pthread_mutex_lock(pthread_mutex_t *); -int _pthread_mutex_trylock(pthread_mutex_t *); -int _pthread_mutex_unlock(pthread_mutex_t *); -int _pthread_mutexattr_init(pthread_mutexattr_t *); -int _pthread_mutexattr_destroy(pthread_mutexattr_t *); -int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); -int _pthread_once(pthread_once_t *, void (*) (void)); -pthread_t _pthread_self(void); -int _pthread_setspecific(pthread_key_t, const void *); -void _waitq_insert(pthread_t pthread); -void _waitq_remove(pthread_t pthread); -#if defined(_PTHREADS_INVARIANTS) -void _waitq_setactive(void); -void _waitq_clearactive(void); -#endif -void _thread_exit(char *, int, char *) __dead2; -void _thread_exit_cleanup(void); -int _thread_fd_getflags(int); -int _thread_fd_lock(int, int, struct timespec *); -int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno); -void _thread_fd_setflags(int, int); -int _thread_fd_table_init(int fd); -void _thread_fd_unlock(int, int); -void _thread_fd_unlock_debug(int, int, char *, int); -void _thread_fd_unlock_owned(pthread_t); -void *_thread_cleanup(pthread_t); -void _thread_cleanupspecific(void); -void _thread_dump_info(void); -void _thread_init(void); -void _thread_kern_sched(ucontext_t *); -void _thread_kern_scheduler(void); -void _thread_kern_sched_frame(struct pthread_signal_frame *psf); -void _thread_kern_sched_sig(void); -void _thread_kern_sched_state(enum pthread_state, char *fname, int lineno); -void _thread_kern_sched_state_unlock(enum pthread_state state, - spinlock_t *lock, char *fname, int lineno); -void _thread_kern_set_timeout(const struct timespec *); -void _thread_kern_sig_defer(void); -void _thread_kern_sig_undefer(void); -void _thread_sig_handler(int, siginfo_t *, ucontext_t *); -void _thread_sig_check_pending(struct pthread *pthread); -void _thread_sig_handle_pending(void); -void _thread_sig_send(struct pthread *pthread, int sig); -void _thread_sig_wrapper(void); -void _thread_sigframe_restore(struct pthread *thread, - struct pthread_signal_frame *psf); -void _thread_start(void); -void _thread_seterrno(pthread_t, int); -pthread_addr_t _thread_gc(pthread_addr_t); -void _thread_enter_cancellation_point(void); -void _thread_leave_cancellation_point(void); -void _thread_cancellation_point(void); - -/* #include <sys/acl.h> */ -#ifdef _SYS_ACL_H -int __sys___acl_aclcheck_fd(int, acl_type_t, struct acl *); -int __sys___acl_delete_fd(int, acl_type_t); -int __sys___acl_get_fd(int, acl_type_t, struct acl *); -int __sys___acl_set_fd(int, acl_type_t, struct acl *); -#endif - -/* #include <sys/aio.h> */ -#ifdef _SYS_AIO_H_ -int __sys_aio_suspend(const struct aiocb * const[], int, const struct timespec *); -#endif - -/* #include <sys/event.h> */ -#ifdef _SYS_EVENT_H_ -int __sys_kevent(int, const struct kevent *, int, struct kevent *, - int, const struct timespec *); -#endif - -/* #include <sys/ioctl.h> */ -#ifdef _SYS_IOCTL_H_ -int __sys_ioctl(int, unsigned long, ...); -#endif - -/* #include <sys/mman.h> */ -#ifdef _SYS_MMAN_H_ -int __sys_msync(void *, size_t, int); -#endif - -/* #include <sys/mount.h> */ -#ifdef _SYS_MOUNT_H_ -int __sys_fstatfs(int, struct statfs *); -#endif - -/* #include <sys/socket.h> */ -#ifdef _SYS_SOCKET_H_ -int __sys_accept(int, struct sockaddr *, socklen_t *); -int __sys_bind(int, const struct sockaddr *, socklen_t); -int __sys_connect(int, const struct sockaddr *, socklen_t); -int __sys_getpeername(int, struct sockaddr *, socklen_t *); -int __sys_getsockname(int, struct sockaddr *, socklen_t *); -int __sys_getsockopt(int, int, int, void *, socklen_t *); -int __sys_listen(int, int); -ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); -ssize_t __sys_recvmsg(int, struct msghdr *, int); -int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int); -ssize_t __sys_sendmsg(int, const struct msghdr *, int); -ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t); -int __sys_setsockopt(int, int, int, const void *, socklen_t); -int __sys_shutdown(int, int); -int __sys_socket(int, int, int); -int __sys_socketpair(int, int, int, int *); -#endif - -/* #include <sys/stat.h> */ -#ifdef _SYS_STAT_H_ -int __sys_fchflags(int, u_long); -int __sys_fchmod(int, mode_t); -int __sys_fstat(int, struct stat *); -#endif - -/* #include <sys/uio.h> */ -#ifdef _SYS_UIO_H_ -ssize_t __sys_readv(int, const struct iovec *, int); -ssize_t __sys_writev(int, const struct iovec *, int); -#endif - -/* #include <sys/wait.h> */ -#ifdef WNOHANG -pid_t __sys_wait4(pid_t, int *, int, struct rusage *); -#endif - -/* #include <dirent.h> */ -#ifdef _DIRENT_H_ -int __sys_getdirentries(int, char *, int, long *); -#endif - -/* #include <fcntl.h> */ -#ifdef _SYS_FCNTL_H_ -int __sys_fcntl(int, int, ...); -int __sys_flock(int, int); -int __sys_open(const char *, int, ...); -#endif - -/* #include <poll.h> */ -#ifdef _SYS_POLL_H_ -int __sys_poll(struct pollfd *, unsigned, int); -#endif - -/* #include <signal.h> */ -#ifdef _SIGNAL_H_ -int __sys_sigaction(int, const struct sigaction *, struct sigaction *); -int __sys_sigprocmask(int, const sigset_t *, sigset_t *); -int __sys_sigreturn(ucontext_t *); -#endif - -/* #include <unistd.h> */ -#ifdef _UNISTD_H_ -int __sys_close(int); -int __sys_dup(int); -int __sys_dup2(int, int); -int __sys_execve(const char *, char * const *, char * const *); -void __sys_exit(int) __dead2; -int __sys_fchown(int, uid_t, gid_t); -pid_t __sys_fork(void); -long __sys_fpathconf(int, int); -int __sys_fsync(int); -int __sys_pipe(int *); -ssize_t __sys_read(int, void *, size_t); -ssize_t __sys_write(int, const void *, size_t); -#endif - -/* #include <setjmp.h> */ -#ifdef _SETJMP_H_ -extern void __siglongjmp(sigjmp_buf, int) __dead2; -extern void __longjmp(jmp_buf, int) __dead2; -extern void ___longjmp(jmp_buf, int) __dead2; -#endif -__END_DECLS - -#endif /* !_PTHREAD_PRIVATE_H */ diff --git a/lib/libc_r/uthread/uthread_accept.c b/lib/libc_r/uthread/uthread_accept.c deleted file mode 100644 index 2e284a9..0000000 --- a/lib/libc_r/uthread/uthread_accept.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_acl_aclcheck_fd.c b/lib/libc_r/uthread/uthread_acl_aclcheck_fd.c deleted file mode 100644 index 19e9aaa..0000000 --- a/lib/libc_r/uthread/uthread_acl_aclcheck_fd.c +++ /dev/null @@ -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); -} - diff --git a/lib/libc_r/uthread/uthread_acl_delete_fd.c b/lib/libc_r/uthread/uthread_acl_delete_fd.c deleted file mode 100644 index 2368c5f..0000000 --- a/lib/libc_r/uthread/uthread_acl_delete_fd.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_acl_get_fd.c b/lib/libc_r/uthread/uthread_acl_get_fd.c deleted file mode 100644 index f0fa8b1..0000000 --- a/lib/libc_r/uthread/uthread_acl_get_fd.c +++ /dev/null @@ -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); - -} diff --git a/lib/libc_r/uthread/uthread_acl_set_fd.c b/lib/libc_r/uthread/uthread_acl_set_fd.c deleted file mode 100644 index c68751a..0000000 --- a/lib/libc_r/uthread/uthread_acl_set_fd.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_aio_suspend.c b/lib/libc_r/uthread/uthread_aio_suspend.c deleted file mode 100644 index 23d34f9..0000000 --- a/lib/libc_r/uthread/uthread_aio_suspend.c +++ /dev/null @@ -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; -} - diff --git a/lib/libc_r/uthread/uthread_atfork.c b/lib/libc_r/uthread/uthread_atfork.c deleted file mode 100644 index 8a09468..0000000 --- a/lib/libc_r/uthread/uthread_atfork.c +++ /dev/null @@ -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); -} - diff --git a/lib/libc_r/uthread/uthread_attr_destroy.c b/lib/libc_r/uthread/uthread_attr_destroy.c deleted file mode 100644 index fd0ff44..0000000 --- a/lib/libc_r/uthread/uthread_attr_destroy.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_get_np.c b/lib/libc_r/uthread/uthread_attr_get_np.c deleted file mode 100644 index ba6fd19..0000000 --- a/lib/libc_r/uthread/uthread_attr_get_np.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getdetachstate.c b/lib/libc_r/uthread/uthread_attr_getdetachstate.c deleted file mode 100644 index 94e2bd1..0000000 --- a/lib/libc_r/uthread/uthread_attr_getdetachstate.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getguardsize.c b/lib/libc_r/uthread/uthread_attr_getguardsize.c deleted file mode 100644 index 849bf27..0000000 --- a/lib/libc_r/uthread/uthread_attr_getguardsize.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getinheritsched.c b/lib/libc_r/uthread/uthread_attr_getinheritsched.c deleted file mode 100644 index 6d6d324..0000000 --- a/lib/libc_r/uthread/uthread_attr_getinheritsched.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getschedparam.c b/lib/libc_r/uthread/uthread_attr_getschedparam.c deleted file mode 100644 index cac86fa..0000000 --- a/lib/libc_r/uthread/uthread_attr_getschedparam.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getschedpolicy.c b/lib/libc_r/uthread/uthread_attr_getschedpolicy.c deleted file mode 100644 index f2b74fc..0000000 --- a/lib/libc_r/uthread/uthread_attr_getschedpolicy.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getscope.c b/lib/libc_r/uthread/uthread_attr_getscope.c deleted file mode 100644 index 8abf418..0000000 --- a/lib/libc_r/uthread/uthread_attr_getscope.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getstack.c b/lib/libc_r/uthread/uthread_attr_getstack.c deleted file mode 100644 index e63cd8f..0000000 --- a/lib/libc_r/uthread/uthread_attr_getstack.c +++ /dev/null @@ -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); -} - diff --git a/lib/libc_r/uthread/uthread_attr_getstackaddr.c b/lib/libc_r/uthread/uthread_attr_getstackaddr.c deleted file mode 100644 index a9a05de..0000000 --- a/lib/libc_r/uthread/uthread_attr_getstackaddr.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_getstacksize.c b/lib/libc_r/uthread/uthread_attr_getstacksize.c deleted file mode 100644 index 436d25a..0000000 --- a/lib/libc_r/uthread/uthread_attr_getstacksize.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_init.c b/lib/libc_r/uthread/uthread_attr_init.c deleted file mode 100644 index d973bfa..0000000 --- a/lib/libc_r/uthread/uthread_attr_init.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setcreatesuspend_np.c b/lib/libc_r/uthread/uthread_attr_setcreatesuspend_np.c deleted file mode 100644 index bb29e85..0000000 --- a/lib/libc_r/uthread/uthread_attr_setcreatesuspend_np.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setdetachstate.c b/lib/libc_r/uthread/uthread_attr_setdetachstate.c deleted file mode 100644 index 932bf13..0000000 --- a/lib/libc_r/uthread/uthread_attr_setdetachstate.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setguardsize.c b/lib/libc_r/uthread/uthread_attr_setguardsize.c deleted file mode 100644 index ad3e8bb..0000000 --- a/lib/libc_r/uthread/uthread_attr_setguardsize.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setinheritsched.c b/lib/libc_r/uthread/uthread_attr_setinheritsched.c deleted file mode 100644 index 3538131..0000000 --- a/lib/libc_r/uthread/uthread_attr_setinheritsched.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setschedparam.c b/lib/libc_r/uthread/uthread_attr_setschedparam.c deleted file mode 100644 index c42973e..0000000 --- a/lib/libc_r/uthread/uthread_attr_setschedparam.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setschedpolicy.c b/lib/libc_r/uthread/uthread_attr_setschedpolicy.c deleted file mode 100644 index d9c83e6..0000000 --- a/lib/libc_r/uthread/uthread_attr_setschedpolicy.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setscope.c b/lib/libc_r/uthread/uthread_attr_setscope.c deleted file mode 100644 index 3614615..0000000 --- a/lib/libc_r/uthread/uthread_attr_setscope.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setstack.c b/lib/libc_r/uthread/uthread_attr_setstack.c deleted file mode 100644 index e03f6de..0000000 --- a/lib/libc_r/uthread/uthread_attr_setstack.c +++ /dev/null @@ -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); -} - diff --git a/lib/libc_r/uthread/uthread_attr_setstackaddr.c b/lib/libc_r/uthread/uthread_attr_setstackaddr.c deleted file mode 100644 index b595451..0000000 --- a/lib/libc_r/uthread/uthread_attr_setstackaddr.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_attr_setstacksize.c b/lib/libc_r/uthread/uthread_attr_setstacksize.c deleted file mode 100644 index 2e73626..0000000 --- a/lib/libc_r/uthread/uthread_attr_setstacksize.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_autoinit.c b/lib/libc_r/uthread/uthread_autoinit.c deleted file mode 100644 index 03ee58d..0000000 --- a/lib/libc_r/uthread/uthread_autoinit.c +++ /dev/null @@ -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; diff --git a/lib/libc_r/uthread/uthread_bind.c b/lib/libc_r/uthread/uthread_bind.c deleted file mode 100644 index d15be6e..0000000 --- a/lib/libc_r/uthread/uthread_bind.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_cancel.c b/lib/libc_r/uthread/uthread_cancel.c deleted file mode 100644 index d9324ab..0000000 --- a/lib/libc_r/uthread/uthread_cancel.c +++ /dev/null @@ -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); - } -} diff --git a/lib/libc_r/uthread/uthread_clean.c b/lib/libc_r/uthread/uthread_clean.c deleted file mode 100644 index 826f6b8..0000000 --- a/lib/libc_r/uthread/uthread_clean.c +++ /dev/null @@ -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); - } -} - diff --git a/lib/libc_r/uthread/uthread_close.c b/lib/libc_r/uthread/uthread_close.c deleted file mode 100644 index 2808076..0000000 --- a/lib/libc_r/uthread/uthread_close.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/uthread/uthread_concurrency.c b/lib/libc_r/uthread/uthread_concurrency.c deleted file mode 100644 index ddb82c1..0000000 --- a/lib/libc_r/uthread/uthread_concurrency.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c deleted file mode 100644 index 6a4c038..0000000 --- a/lib/libc_r/uthread/uthread_cond.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/uthread/uthread_condattr_destroy.c b/lib/libc_r/uthread/uthread_condattr_destroy.c deleted file mode 100644 index aef920d..0000000 --- a/lib/libc_r/uthread/uthread_condattr_destroy.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_condattr_init.c b/lib/libc_r/uthread/uthread_condattr_init.c deleted file mode 100644 index e35b217..0000000 --- a/lib/libc_r/uthread/uthread_condattr_init.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_connect.c b/lib/libc_r/uthread/uthread_connect.c deleted file mode 100644 index efe6efd..0000000 --- a/lib/libc_r/uthread/uthread_connect.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_creat.c b/lib/libc_r/uthread/uthread_creat.c deleted file mode 100644 index 92da971..0000000 --- a/lib/libc_r/uthread/uthread_creat.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/uthread/uthread_create.c b/lib/libc_r/uthread/uthread_create.c deleted file mode 100644 index 3474bfa..0000000 --- a/lib/libc_r/uthread/uthread_create.c +++ /dev/null @@ -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"); -} diff --git a/lib/libc_r/uthread/uthread_detach.c b/lib/libc_r/uthread/uthread_detach.c deleted file mode 100644 index e8ac8b0..0000000 --- a/lib/libc_r/uthread/uthread_detach.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_dup.c b/lib/libc_r/uthread/uthread_dup.c deleted file mode 100644 index 4b66e97..0000000 --- a/lib/libc_r/uthread/uthread_dup.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_dup2.c b/lib/libc_r/uthread/uthread_dup2.c deleted file mode 100644 index 0508361..0000000 --- a/lib/libc_r/uthread/uthread_dup2.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_equal.c b/lib/libc_r/uthread/uthread_equal.c deleted file mode 100644 index 9c21c3a..0000000 --- a/lib/libc_r/uthread/uthread_equal.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_execve.c b/lib/libc_r/uthread/uthread_execve.c deleted file mode 100644 index 50db4fe..0000000 --- a/lib/libc_r/uthread/uthread_execve.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_exit.c b/lib/libc_r/uthread/uthread_exit.c deleted file mode 100644 index 87a9dcd..0000000 --- a/lib/libc_r/uthread/uthread_exit.c +++ /dev/null @@ -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"); -} diff --git a/lib/libc_r/uthread/uthread_fchflags.c b/lib/libc_r/uthread/uthread_fchflags.c deleted file mode 100644 index cd076e2..0000000 --- a/lib/libc_r/uthread/uthread_fchflags.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_fchmod.c b/lib/libc_r/uthread/uthread_fchmod.c deleted file mode 100644 index ba0a35f..0000000 --- a/lib/libc_r/uthread/uthread_fchmod.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_fchown.c b/lib/libc_r/uthread/uthread_fchown.c deleted file mode 100644 index 6990b75..0000000 --- a/lib/libc_r/uthread/uthread_fchown.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_fcntl.c b/lib/libc_r/uthread/uthread_fcntl.c deleted file mode 100644 index 81c5d7f..0000000 --- a/lib/libc_r/uthread/uthread_fcntl.c +++ /dev/null @@ -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; -} diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c deleted file mode 100644 index 4258323..0000000 --- a/lib/libc_r/uthread/uthread_fd.c +++ /dev/null @@ -1,1054 +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 <stdlib.h> -#include <string.h> -#include <pthread.h> -#include "pthread_private.h" - -#define FDQ_INSERT(q,p) \ -do { \ - TAILQ_INSERT_TAIL(q,p,qe); \ - p->flags |= PTHREAD_FLAGS_IN_FDQ; \ -} while (0) - -#define FDQ_REMOVE(q,p) \ -do { \ - if ((p->flags & PTHREAD_FLAGS_IN_FDQ) != 0) { \ - TAILQ_REMOVE(q,p,qe); \ - p->flags &= ~PTHREAD_FLAGS_IN_FDQ; \ - } \ -} while (0) - - -/* Static variables: */ -static spinlock_t fd_table_lock = _SPINLOCK_INITIALIZER; - -/* Prototypes: */ -#ifdef _FDLOCKS_ENABLED -static inline pthread_t fd_next_reader(int fd); -static inline pthread_t fd_next_writer(int fd); -#endif - - -/* - * This function *must* return -1 and set the thread specific errno - * as a system call. This is because the error return from this - * function is propagated directly back from thread-wrapped system - * calls. - */ - -int -_thread_fd_table_init(int fd) -{ - int ret = 0; - struct fd_table_entry *entry; - int saved_errno; - - if (_thread_initial == NULL) - _thread_init(); - - /* Check if the file descriptor is out of range: */ - if (fd < 0 || fd >= _thread_dtablesize) { - /* Return a bad file descriptor error: */ - errno = EBADF; - ret = -1; - } - - /* - * Check if memory has already been allocated for this file - * descriptor: - */ - else if (_thread_fd_table[fd] != NULL) { - /* Memory has already been allocated. */ - - /* Allocate memory for the file descriptor table entry: */ - } else if ((entry = (struct fd_table_entry *) - malloc(sizeof(struct fd_table_entry))) == NULL) { - /* Return an insufficient memory error: */ - errno = ENOMEM; - ret = -1; - } else { - /* Initialise the file locks: */ - memset(&entry->lock, 0, sizeof(entry->lock)); - entry->r_owner = NULL; - entry->w_owner = NULL; - entry->r_fname = NULL; - entry->w_fname = NULL; - entry->r_lineno = 0; - entry->w_lineno = 0; - entry->r_lockcount = 0; - entry->w_lockcount = 0; - - /* Initialise the read/write queues: */ - TAILQ_INIT(&entry->r_queue); - TAILQ_INIT(&entry->w_queue); - - /* Get the flags for the file: */ - if (((fd >= 3) || (_pthread_stdio_flags[fd] == -1)) && - (entry->flags = __sys_fcntl(fd, F_GETFL, 0)) == -1) { - ret = -1; - } - else { - /* Check if a stdio descriptor: */ - if ((fd < 3) && (_pthread_stdio_flags[fd] != -1)) - /* - * Use the stdio flags read by - * _pthread_init() to avoid - * mistaking the non-blocking - * flag that, when set on one - * stdio fd, is set on all stdio - * fds. - */ - entry->flags = _pthread_stdio_flags[fd]; - - /* - * Make the file descriptor non-blocking. - * This might fail if the device driver does - * not support non-blocking calls, or if the - * driver is naturally non-blocking. - */ - saved_errno = errno; - __sys_fcntl(fd, F_SETFL, - entry->flags | O_NONBLOCK); - errno = saved_errno; - - /* Lock the file descriptor table: */ - _SPINLOCK(&fd_table_lock); - - /* - * Check if another thread allocated the - * file descriptor entry while this thread - * was doing the same thing. The table wasn't - * kept locked during this operation because - * it has the potential to recurse. - */ - if (_thread_fd_table[fd] == NULL) { - /* This thread wins: */ - _thread_fd_table[fd] = entry; - entry = NULL; - } - - /* Unlock the file descriptor table: */ - _SPINUNLOCK(&fd_table_lock); - } - - /* - * Check if another thread initialised the table entry - * before this one could: - */ - if (entry != NULL) - /* - * Throw away the table entry that this thread - * prepared. The other thread wins. - */ - free(entry); - } - - /* Return the completion status: */ - return (ret); -} - -int -_thread_fd_getflags(int fd) -{ - if (_thread_fd_table[fd] != NULL) - return (_thread_fd_table[fd]->flags); - else - return (0); -} - -void -_thread_fd_setflags(int fd, int flags) -{ - if (_thread_fd_table[fd] != NULL) - _thread_fd_table[fd]->flags = flags; -} - -#ifdef _FDLOCKS_ENABLED -void -_thread_fd_unlock(int fd, int lock_type) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - /* - * Check that the file descriptor table is initialised for this - * entry: - */ - if ((ret = _thread_fd_table_init(fd)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - /* Check if the running thread owns the read lock: */ - if (_thread_fd_table[fd]->r_owner == curthread) { - /* Check the file descriptor and lock types: */ - if (lock_type == FD_READ || lock_type == FD_RDWR) { - /* - * Decrement the read lock count for the - * running thread: - */ - _thread_fd_table[fd]->r_lockcount--; - - /* - * Check if the running thread still has read - * locks on this file descriptor: - */ - if (_thread_fd_table[fd]->r_lockcount != 0) { - } - /* - * Get the next thread in the queue for a - * read lock on this file descriptor: - */ - else if ((_thread_fd_table[fd]->r_owner = fd_next_reader(fd)) == NULL) { - } else { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, - _thread_fd_table[fd]->r_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->r_owner,PS_RUNNING); - - /* - * Reset the number of read locks. - * This will be incremented by the - * new owner of the lock when it sees - * that it has the lock. - */ - _thread_fd_table[fd]->r_lockcount = 0; - } - } - } - /* Check if the running thread owns the write lock: */ - if (_thread_fd_table[fd]->w_owner == curthread) { - /* Check the file descriptor and lock types: */ - if (lock_type == FD_WRITE || lock_type == FD_RDWR) { - /* - * Decrement the write lock count for the - * running thread: - */ - _thread_fd_table[fd]->w_lockcount--; - - /* - * Check if the running thread still has - * write locks on this file descriptor: - */ - if (_thread_fd_table[fd]->w_lockcount != 0) { - } - /* - * Get the next thread in the queue for a - * write lock on this file descriptor: - */ - else if ((_thread_fd_table[fd]->w_owner = fd_next_writer(fd)) == NULL) { - } else { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, - _thread_fd_table[fd]->w_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->w_owner,PS_RUNNING); - - /* - * Reset the number of write locks. - * This will be incremented by the - * new owner of the lock when it - * sees that it has the lock. - */ - _thread_fd_table[fd]->w_lockcount = 0; - } - } - } - - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } -} - -int -_thread_fd_lock(int fd, int lock_type, struct timespec * timeout) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - /* - * Check that the file descriptor table is initialised for this - * entry: - */ - if ((ret = _thread_fd_table_init(fd)) == 0) { - /* Clear the interrupted flag: */ - curthread->interrupted = 0; - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - /* Check the file descriptor and lock types: */ - if (lock_type == FD_READ || lock_type == FD_RDWR) { - /* - * Wait for the file descriptor to be locked - * for read for the current thread: - */ - while ((_thread_fd_table[fd]->r_owner != curthread) && - (curthread->interrupted == 0)) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (_thread_fd_table[fd]->r_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for read, so join the - * queue of threads waiting for a - * read lock on this file descriptor: - */ - FDQ_INSERT(&_thread_fd_table[fd]->r_queue, curthread); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unlock the file descriptor - * table entry: - */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Schedule this thread to wait on - * the read lock. It will only be - * woken when it becomes the next in - * the queue and is granted access - * to the lock by the thread - * that is unlocking the file - * descriptor. - */ - _thread_kern_sched_state(PS_FDLR_WAIT, __FILE__, __LINE__); - - /* - * Lock the file descriptor - * table entry again: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, - curthread); - } - } else { - /* - * The running thread now owns the - * read lock on this file descriptor: - */ - _thread_fd_table[fd]->r_owner = curthread; - - /* - * Reset the number of read locks for - * this file descriptor: - */ - _thread_fd_table[fd]->r_lockcount = 0; - } - } - - if (_thread_fd_table[fd]->r_owner == curthread) - /* Increment the read lock count: */ - _thread_fd_table[fd]->r_lockcount++; - } - - /* Check the file descriptor and lock types: */ - if (curthread->interrupted == 0 && - (lock_type == FD_WRITE || lock_type == FD_RDWR)) { - /* - * Wait for the file descriptor to be locked - * for write for the current thread: - */ - while ((_thread_fd_table[fd]->w_owner != curthread) && - (curthread->interrupted == 0)) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (_thread_fd_table[fd]->w_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for write, so join the - * queue of threads waiting for a - * write lock on this file - * descriptor: - */ - FDQ_INSERT(&_thread_fd_table[fd]->w_queue, curthread); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unlock the file descriptor - * table entry: - */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Schedule this thread to wait on - * the write lock. It will only be - * woken when it becomes the next in - * the queue and is granted access to - * the lock by the thread that is - * unlocking the file descriptor. - */ - _thread_kern_sched_state(PS_FDLW_WAIT, __FILE__, __LINE__); - - /* - * Lock the file descriptor - * table entry again: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, - curthread); - } - } else { - /* - * The running thread now owns the - * write lock on this file - * descriptor: - */ - _thread_fd_table[fd]->w_owner = curthread; - - /* - * Reset the number of write locks - * for this file descriptor: - */ - _thread_fd_table[fd]->w_lockcount = 0; - } - } - - if (_thread_fd_table[fd]->w_owner == curthread) - /* Increment the write lock count: */ - _thread_fd_table[fd]->w_lockcount++; - } - - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - ret = -1; - errno = EINTR; - if (curthread->continuation != NULL) - curthread->continuation((void *)curthread); - } - } - - /* Return the completion status: */ - return (ret); -} - -void -_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - /* - * Check that the file descriptor table is initialised for this - * entry: - */ - if ((ret = _thread_fd_table_init(fd)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _spinlock_debug(&_thread_fd_table[fd]->lock, fname, lineno); - - /* Check if the running thread owns the read lock: */ - if (_thread_fd_table[fd]->r_owner == curthread) { - /* Check the file descriptor and lock types: */ - if (lock_type == FD_READ || lock_type == FD_RDWR) { - /* - * Decrement the read lock count for the - * running thread: - */ - _thread_fd_table[fd]->r_lockcount--; - - /* - * Check if the running thread still has read - * locks on this file descriptor: - */ - if (_thread_fd_table[fd]->r_lockcount != 0) { - } - /* - * Get the next thread in the queue for a - * read lock on this file descriptor: - */ - else if ((_thread_fd_table[fd]->r_owner = fd_next_reader(fd)) == NULL) { - } else { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, - _thread_fd_table[fd]->r_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->r_owner,PS_RUNNING); - - /* - * Reset the number of read locks. - * This will be incremented by the - * new owner of the lock when it sees - * that it has the lock. - */ - _thread_fd_table[fd]->r_lockcount = 0; - } - } - } - /* Check if the running thread owns the write lock: */ - if (_thread_fd_table[fd]->w_owner == curthread) { - /* Check the file descriptor and lock types: */ - if (lock_type == FD_WRITE || lock_type == FD_RDWR) { - /* - * Decrement the write lock count for the - * running thread: - */ - _thread_fd_table[fd]->w_lockcount--; - - /* - * Check if the running thread still has - * write locks on this file descriptor: - */ - if (_thread_fd_table[fd]->w_lockcount != 0) { - } - /* - * Get the next thread in the queue for a - * write lock on this file descriptor: - */ - else if ((_thread_fd_table[fd]->w_owner = fd_next_writer(fd)) == NULL) { - } else { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, - _thread_fd_table[fd]->w_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->w_owner,PS_RUNNING); - - /* - * Reset the number of write locks. - * This will be incremented by the - * new owner of the lock when it - * sees that it has the lock. - */ - _thread_fd_table[fd]->w_lockcount = 0; - } - } - } - - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary. - */ - _thread_kern_sig_undefer(); - } -} - -int -_thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, - char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - /* - * Check that the file descriptor table is initialised for this - * entry: - */ - if ((ret = _thread_fd_table_init(fd)) == 0) { - /* Clear the interrupted flag: */ - curthread->interrupted = 0; - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _spinlock_debug(&_thread_fd_table[fd]->lock, fname, lineno); - - /* Check the file descriptor and lock types: */ - if (lock_type == FD_READ || lock_type == FD_RDWR) { - /* - * Wait for the file descriptor to be locked - * for read for the current thread: - */ - while ((_thread_fd_table[fd]->r_owner != curthread) && - (curthread->interrupted == 0)) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (_thread_fd_table[fd]->r_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for read, so join the - * queue of threads waiting for a - * read lock on this file descriptor: - */ - FDQ_INSERT(&_thread_fd_table[fd]->r_queue, curthread); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unlock the file descriptor - * table entry: - */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Schedule this thread to wait on - * the read lock. It will only be - * woken when it becomes the next in - * the queue and is granted access - * to the lock by the thread - * that is unlocking the file - * descriptor. - */ - _thread_kern_sched_state(PS_FDLR_WAIT, __FILE__, __LINE__); - - /* - * Lock the file descriptor - * table entry again: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, - curthread); - } - } else { - /* - * The running thread now owns the - * read lock on this file descriptor: - */ - _thread_fd_table[fd]->r_owner = curthread; - - /* - * Reset the number of read locks for - * this file descriptor: - */ - _thread_fd_table[fd]->r_lockcount = 0; - - /* - * Save the source file details for - * debugging: - */ - _thread_fd_table[fd]->r_fname = fname; - _thread_fd_table[fd]->r_lineno = lineno; - } - } - - if (_thread_fd_table[fd]->r_owner == curthread) - /* Increment the read lock count: */ - _thread_fd_table[fd]->r_lockcount++; - } - - /* Check the file descriptor and lock types: */ - if (curthread->interrupted == 0 && - (lock_type == FD_WRITE || lock_type == FD_RDWR)) { - /* - * Wait for the file descriptor to be locked - * for write for the current thread: - */ - while ((_thread_fd_table[fd]->w_owner != curthread) && - (curthread->interrupted == 0)) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (_thread_fd_table[fd]->w_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for write, so join the - * queue of threads waiting for a - * write lock on this file - * descriptor: - */ - FDQ_INSERT(&_thread_fd_table[fd]->w_queue, curthread); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unlock the file descriptor - * table entry: - */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Schedule this thread to wait on - * the write lock. It will only be - * woken when it becomes the next in - * the queue and is granted access to - * the lock by the thread that is - * unlocking the file descriptor. - */ - _thread_kern_sched_state(PS_FDLW_WAIT, __FILE__, __LINE__); - - /* - * Lock the file descriptor - * table entry again: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, - curthread); - } - } else { - /* - * The running thread now owns the - * write lock on this file - * descriptor: - */ - _thread_fd_table[fd]->w_owner = curthread; - - /* - * Reset the number of write locks - * for this file descriptor: - */ - _thread_fd_table[fd]->w_lockcount = 0; - - /* - * Save the source file details for - * debugging: - */ - _thread_fd_table[fd]->w_fname = fname; - _thread_fd_table[fd]->w_lineno = lineno; - } - } - - if (_thread_fd_table[fd]->w_owner == curthread) - /* Increment the write lock count: */ - _thread_fd_table[fd]->w_lockcount++; - } - - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - if (curthread->interrupted != 0) { - ret = -1; - errno = EINTR; - if (curthread->continuation != NULL) - curthread->continuation((void *)curthread); - } - } - - /* Return the completion status: */ - return (ret); -} - -void -_thread_fd_unlock_owned(pthread_t pthread) -{ - int fd; - - for (fd = 0; fd < _thread_dtablesize; fd++) { - if ((_thread_fd_table[fd] != NULL) && - ((_thread_fd_table[fd]->r_owner == pthread) || - (_thread_fd_table[fd]->w_owner == pthread))) { - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - /* Check if the thread owns the read lock: */ - if (_thread_fd_table[fd]->r_owner == pthread) { - /* Clear the read lock count: */ - _thread_fd_table[fd]->r_lockcount = 0; - - /* - * Get the next thread in the queue for a - * read lock on this file descriptor: - */ - if ((_thread_fd_table[fd]->r_owner = fd_next_reader(fd)) != NULL) { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, - _thread_fd_table[fd]->r_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->r_owner,PS_RUNNING); - } - } - - /* Check if the thread owns the write lock: */ - if (_thread_fd_table[fd]->w_owner == pthread) { - /* Clear the write lock count: */ - _thread_fd_table[fd]->w_lockcount = 0; - - /* - * Get the next thread in the queue for a - * write lock on this file descriptor: - */ - if ((_thread_fd_table[fd]->w_owner = fd_next_writer(fd)) != NULL) { - /* Remove this thread from the queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, - _thread_fd_table[fd]->w_owner); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(_thread_fd_table[fd]->w_owner,PS_RUNNING); - - } - } - - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&_thread_fd_table[fd]->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary. - */ - _thread_kern_sig_undefer(); - } - } -} - -void -_fd_lock_backout(pthread_t pthread) -{ - int fd; - - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - switch (pthread->state) { - - case PS_FDLR_WAIT: - fd = pthread->data.fd.fd; - - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - /* Remove the thread from the waiting queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, pthread); - break; - - case PS_FDLW_WAIT: - fd = pthread->data.fd.fd; - - /* - * Lock the file descriptor table entry to prevent - * other threads from clashing with the current - * thread's accesses: - */ - _SPINLOCK(&_thread_fd_table[fd]->lock); - - /* Remove the thread from the waiting queue: */ - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, pthread); - break; - - default: - break; - } - - /* - * Undefer and handle pending signals, yielding if - * necessary. - */ - _thread_kern_sig_undefer(); -} - -static inline pthread_t -fd_next_reader(int fd) -{ - pthread_t pthread; - - while (((pthread = TAILQ_FIRST(&_thread_fd_table[fd]->r_queue)) != NULL) && - (pthread->interrupted != 0)) { - /* - * This thread has either been interrupted by a signal or - * it has been canceled. Remove it from the queue. - */ - FDQ_REMOVE(&_thread_fd_table[fd]->r_queue, pthread); - } - - return (pthread); -} - -static inline pthread_t -fd_next_writer(int fd) -{ - pthread_t pthread; - - while (((pthread = TAILQ_FIRST(&_thread_fd_table[fd]->w_queue)) != NULL) && - (pthread->interrupted != 0)) { - /* - * This thread has either been interrupted by a signal or - * it has been canceled. Remove it from the queue. - */ - FDQ_REMOVE(&_thread_fd_table[fd]->w_queue, pthread); - } - - return (pthread); -} - -#else - -void -_thread_fd_unlock(int fd, int lock_type) -{ -} - -int -_thread_fd_lock(int fd, int lock_type, struct timespec * timeout) -{ - /* - * Insure that the file descriptor table is initialized for this - * entry: - */ - return (_thread_fd_table_init(fd)); -} - -void -_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) -{ -} - -int -_thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, - char *fname, int lineno) -{ - /* - * Insure that the file descriptor table is initialized for this - * entry: - */ - return (_thread_fd_table_init(fd)); -} - -void -_thread_fd_unlock_owned(pthread_t pthread) -{ -} - -void -_fd_lock_backout(pthread_t pthread) -{ -} - -#endif diff --git a/lib/libc_r/uthread/uthread_file.c b/lib/libc_r/uthread/uthread_file.c deleted file mode 100644 index cbedbc7..0000000 --- a/lib/libc_r/uthread/uthread_file.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_find_thread.c b/lib/libc_r/uthread/uthread_find_thread.c deleted file mode 100644 index 299d53c..0000000 --- a/lib/libc_r/uthread/uthread_find_thread.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_flock.c b/lib/libc_r/uthread/uthread_flock.c deleted file mode 100644 index 388c025..0000000 --- a/lib/libc_r/uthread/uthread_flock.c +++ /dev/null @@ -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); -} diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c deleted file mode 100644 index a24ad98..0000000 --- a/lib/libc_r/uthread/uthread_fork.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/param.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -static void free_thread_resources(struct pthread *thread); - -__weak_reference(_fork, fork); - -pid_t -_fork(void) -{ - struct pthread *curthread = _get_curthread(); - struct pthread_atfork *af; - int i, flags, use_deadlist = 0; - pid_t ret; - pthread_t pthread; - pthread_t pthread_save; - - /* - * Defer signals to protect the scheduling queues from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - _pthread_mutex_lock(&_atfork_mutex); - - /* Run down atfork prepare handlers. */ - TAILQ_FOREACH_REVERSE(af, &_atfork_list, atfork_head, qe) { - if (af->prepare != NULL) - af->prepare(); - } - - /* Fork a new process: */ - if ((ret = __sys_fork()) != 0) { - /* Run down atfork parent handlers. */ - TAILQ_FOREACH(af, &_atfork_list, qe) { - if (af->parent != NULL) - af->parent(); - } - _pthread_mutex_unlock(&_atfork_mutex); - - } else { - /* Close the pthread kernel pipe: */ - __sys_close(_thread_kern_pipe[0]); - __sys_close(_thread_kern_pipe[1]); - - /* Reset signals pending for the running thread: */ - sigemptyset(&curthread->sigpend); - - /* - * Create a pipe that is written to by the signal handler to - * prevent signals being missed in calls to - * __sys_select: - */ - if (__sys_pipe(_thread_kern_pipe) != 0) { - /* Cannot create pipe, so abort: */ - PANIC("Cannot create pthread kernel pipe for forked process"); - } - /* Get the flags for the read pipe: */ - else if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - abort(); - } - /* Make the read pipe non-blocking: */ - else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - abort(); - } - /* Get the flags for the write pipe: */ - else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - abort(); - } - /* Make the write pipe non-blocking: */ - else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - abort(); - } - /* Reinitialize the GC mutex: */ - else if (_mutex_reinit(&_gc_mutex) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize GC mutex for forked process"); - } - /* Reinitialize the GC condition variable: */ - else if (_cond_reinit(&_gc_cond) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize GC condvar for forked process"); - } - /* Initialize the ready queue: */ - else if (_pq_init(&_readyq) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize priority ready queue."); - } else { - /* - * Enter a loop to remove all threads other than - * the running thread from the thread list: - */ - if ((pthread = TAILQ_FIRST(&_thread_list)) == NULL) { - pthread = TAILQ_FIRST(&_dead_list); - use_deadlist = 1; - } - while (pthread != NULL) { - /* Save the thread to be freed: */ - pthread_save = pthread; - - /* - * Advance to the next thread before - * destroying the current thread: - */ - if (use_deadlist != 0) - pthread = TAILQ_NEXT(pthread, dle); - else - pthread = TAILQ_NEXT(pthread, tle); - - /* Make sure this isn't the running thread: */ - if (pthread_save != curthread) { - /* - * Remove this thread from the - * appropriate list: - */ - if (use_deadlist != 0) - TAILQ_REMOVE(&_thread_list, - pthread_save, dle); - else - TAILQ_REMOVE(&_thread_list, - pthread_save, tle); - - free_thread_resources(pthread_save); - } - - /* - * Switch to the deadlist when the active - * thread list has been consumed. This can't - * be at the top of the loop because it is - * used to determine to which list the thread - * belongs (when it is removed from the list). - */ - if (pthread == NULL) { - pthread = TAILQ_FIRST(&_dead_list); - use_deadlist = 1; - } - } - - /* Treat the current thread as the initial thread: */ - _thread_initial = curthread; - - /* Re-init the dead thread list: */ - TAILQ_INIT(&_dead_list); - - /* Re-init the waiting and work queues. */ - TAILQ_INIT(&_waitingq); - TAILQ_INIT(&_workq); - - /* Re-init the threads mutex queue: */ - TAILQ_INIT(&curthread->mutexq); - - /* No spinlocks yet: */ - _spinblock_count = 0; - - /* Don't queue signals yet: */ - _queue_signals = 0; - - /* Initialize the scheduling switch hook routine: */ - _sched_switch_hook = NULL; - - /* Clear out any locks in the file descriptor table: */ - for (i = 0; i < _thread_dtablesize; i++) { - if (_thread_fd_table[i] != NULL) { - /* Initialise the file locks: */ - memset(&_thread_fd_table[i]->lock, 0, - sizeof(_thread_fd_table[i]->lock)); - _thread_fd_table[i]->r_owner = NULL; - _thread_fd_table[i]->w_owner = NULL; - _thread_fd_table[i]->r_fname = NULL; - _thread_fd_table[i]->w_fname = NULL; - _thread_fd_table[i]->r_lineno = 0;; - _thread_fd_table[i]->w_lineno = 0;; - _thread_fd_table[i]->r_lockcount = 0;; - _thread_fd_table[i]->w_lockcount = 0;; - - /* Initialise the read/write queues: */ - TAILQ_INIT(&_thread_fd_table[i]->r_queue); - TAILQ_INIT(&_thread_fd_table[i]->w_queue); - } - } - } - /* Run down atfork child handlers. */ - TAILQ_FOREACH(af, &_atfork_list, qe) { - if (af->child != NULL) - af->child(); - } - _mutex_reinit(&_atfork_mutex); - } - - - /* - * Undefer and handle pending signals, yielding if necessary: - */ - _thread_kern_sig_undefer(); - - /* Return the process ID: */ - return (ret); -} - -static void -free_thread_resources(struct pthread *thread) -{ - - /* Check to see if the threads library allocated the stack. */ - if ((thread->attr.stackaddr_attr == NULL) && (thread->stack != NULL)) { - /* - * Since this is being called from fork, we are currently single - * threaded so there is no need to protect the call to - * _thread_stack_free() with _gc_mutex. - */ - _thread_stack_free(thread->stack, thread->attr.stacksize_attr, - thread->attr.guardsize_attr); - } - - if (thread->specific != NULL) - free(thread->specific); - - if (thread->poll_data.fds != NULL) - free(thread->poll_data.fds); - - free(thread); -} diff --git a/lib/libc_r/uthread/uthread_fpathconf.c b/lib/libc_r/uthread/uthread_fpathconf.c deleted file mode 100644 index 97e1d65..0000000 --- a/lib/libc_r/uthread/uthread_fpathconf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2000 Maxim Sobolev <sobomax@FreeBSD.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_fpathconf, fpathconf); - -long -_fpathconf(int fd, int name) -{ - long ret; - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - ret = __sys_fpathconf(fd, name); - _FD_UNLOCK(fd, FD_READ); - } - return ret; -} - diff --git a/lib/libc_r/uthread/uthread_fstat.c b/lib/libc_r/uthread/uthread_fstat.c deleted file mode 100644 index d52e4aa..0000000 --- a/lib/libc_r/uthread/uthread_fstat.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_fstat, fstat); - -int -_fstat(int fd, struct stat * buf) -{ - int ret; - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the file status: */ - ret = __sys_fstat(fd, buf); - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} - diff --git a/lib/libc_r/uthread/uthread_fstatfs.c b/lib/libc_r/uthread/uthread_fstatfs.c deleted file mode 100644 index c53c4a5..0000000 --- a/lib/libc_r/uthread/uthread_fstatfs.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_fstatfs, fstatfs); - -int -_fstatfs(int fd, struct statfs * buf) -{ - int ret; - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the file system status: */ - ret = __sys_fstatfs(fd, buf); - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_fsync.c b/lib/libc_r/uthread/uthread_fsync.c deleted file mode 100644 index 46ccbfe..0000000 --- a/lib/libc_r/uthread/uthread_fsync.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__fsync, fsync); - -int -_fsync(int fd) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_fsync(fd); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} - -int -__fsync(int fd) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _fsync(fd); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_gc.c b/lib/libc_r/uthread/uthread_gc.c deleted file mode 100644 index c5bf59f..0000000 --- a/lib/libc_r/uthread/uthread_gc.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - * - * Garbage collector thread. Frees memory allocated for dead threads. - * - */ -#include <sys/param.h> -#include <errno.h> -#include <time.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include "namespace.h" -#include <pthread.h> -#include "un-namespace.h" -#include "pthread_private.h" - -pthread_addr_t -_thread_gc(pthread_addr_t arg) -{ - struct pthread *curthread = _get_curthread(); - int f_debug; - int f_done = 0; - int ret; - sigset_t mask; - pthread_t pthread; - pthread_t pthread_cln; - struct timespec abstime; - void *p_stack; - - /* Block all signals */ - sigfillset(&mask); - _pthread_sigmask(SIG_BLOCK, &mask, NULL); - - /* Mark this thread as a library thread (not a user thread). */ - curthread->flags |= PTHREAD_FLAGS_PRIVATE; - - /* Set a debug flag based on an environment variable. */ - f_debug = (getenv("LIBC_R_DEBUG") != NULL); - - /* Set the name of this thread. */ - pthread_set_name_np(curthread,"GC"); - - while (!f_done) { - /* Check if debugging this application. */ - if (f_debug) - /* Dump thread info to file. */ - _thread_dump_info(); - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Check if this is the last running thread: */ - if (TAILQ_FIRST(&_thread_list) == curthread && - TAILQ_NEXT(curthread, tle) == NULL) - /* - * This is the last thread, so it can exit - * now. - */ - f_done = 1; - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - - /* No stack of thread structure to free yet: */ - p_stack = NULL; - pthread_cln = NULL; - - /* - * Lock the garbage collector mutex which ensures that - * this thread sees another thread exit: - */ - if (_pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - /* - * Enter a loop to search for the first dead thread that - * has memory to free. - */ - for (pthread = TAILQ_FIRST(&_dead_list); - p_stack == NULL && pthread_cln == NULL && pthread != NULL; - pthread = TAILQ_NEXT(pthread, dle)) { - /* Check if the initial thread: */ - if (pthread == _thread_initial) { - /* Don't destroy the initial thread. */ - } - /* - * Check if this thread has detached: - */ - else if ((pthread->attr.flags & - PTHREAD_DETACHED) != 0) { - /* Remove this thread from the dead list: */ - TAILQ_REMOVE(&_dead_list, pthread, dle); - - /* - * Check if the stack was not specified by - * the caller to pthread_create() and has not - * been destroyed yet: - */ - if (pthread->attr.stackaddr_attr == NULL && - pthread->stack != NULL) { - _thread_stack_free(pthread->stack, - pthread->attr.stacksize_attr, - pthread->attr.guardsize_attr); - } - - /* - * Point to the thread structure that must - * be freed outside the locks: - */ - pthread_cln = pthread; - - } else { - /* - * This thread has not detached, so do - * not destroy it. - * - * Check if the stack was not specified by - * the caller to pthread_create() and has not - * been destroyed yet: - */ - if (pthread->attr.stackaddr_attr == NULL && - pthread->stack != NULL) { - _thread_stack_free(pthread->stack, - pthread->attr.stacksize_attr, - pthread->attr.guardsize_attr); - - /* - * NULL the stack pointer now that the - * memory has been freed: - */ - pthread->stack = NULL; - } - } - } - - /* - * Check if this is not the last thread and there is no - * memory to free this time around. - */ - if (!f_done && p_stack == NULL && pthread_cln == NULL) { - /* Get the current time. */ - if (clock_gettime(CLOCK_REALTIME,&abstime) != 0) - PANIC("gc cannot get time"); - - /* - * Do a backup poll in 10 seconds if no threads - * die before then. - */ - abstime.tv_sec += 10; - - /* - * Wait for a signal from a dying thread or a - * timeout (for a backup poll). - */ - if ((ret = _pthread_cond_timedwait(&_gc_cond, - &_gc_mutex, &abstime)) != 0 && ret != ETIMEDOUT) - PANIC("gc cannot wait for a signal"); - } - - /* Unlock the garbage collector mutex: */ - if (_pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - - /* - * If there is memory to free, do it now. The call to - * free() might block, so this must be done outside the - * locks. - */ - if (p_stack != NULL) - free(p_stack); - if (pthread_cln != NULL) { - if (pthread_cln->name != NULL) { - /* Free the thread name string. */ - free(pthread_cln->name); - } - /* - * Free the memory allocated for the thread - * structure. - */ - free(pthread_cln); - } - } - return (NULL); -} diff --git a/lib/libc_r/uthread/uthread_getdirentries.c b/lib/libc_r/uthread/uthread_getdirentries.c deleted file mode 100644 index f2c8f79..0000000 --- a/lib/libc_r/uthread/uthread_getdirentries.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <dirent.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_getdirentries, getdirentries); - -int -_getdirentries(int fd, char *buf, int nbytes, long *basep) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_getdirentries(fd, buf, nbytes, basep); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_getpeername.c b/lib/libc_r/uthread/uthread_getpeername.c deleted file mode 100644 index 0a61054..0000000 --- a/lib/libc_r/uthread/uthread_getpeername.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_getpeername, getpeername); - -int -_getpeername(int fd, struct sockaddr * peer, socklen_t *paddrlen) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - ret = __sys_getpeername(fd, peer, paddrlen); - _FD_UNLOCK(fd, FD_READ); - } - return ret; -} - diff --git a/lib/libc_r/uthread/uthread_getprio.c b/lib/libc_r/uthread/uthread_getprio.c deleted file mode 100644 index 363e3cf..0000000 --- a/lib/libc_r/uthread/uthread_getprio.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_getprio, pthread_getprio); - -int -_pthread_getprio(pthread_t pthread) -{ - int policy, ret; - struct sched_param param; - - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) - ret = param.sched_priority; - else { - /* Invalid thread: */ - errno = ret; - ret = -1; - } - - /* Return the thread priority or an error status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_getschedparam.c b/lib/libc_r/uthread/uthread_getschedparam.c deleted file mode 100644 index 0d1ffe9..0000000 --- a/lib/libc_r/uthread/uthread_getschedparam.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_getschedparam, pthread_getschedparam); - -int -_pthread_getschedparam(pthread_t pthread, int *policy, - struct sched_param *param) -{ - int ret; - - if ((param == NULL) || (policy == NULL)) - /* Return an invalid argument error: */ - ret = EINVAL; - - /* Find the thread in the list of active threads: */ - else if ((ret = _find_thread(pthread)) == 0) { - /* Return the threads base priority and scheduling policy: */ - param->sched_priority = - PTHREAD_BASE_PRIORITY(pthread->base_priority); - *policy = pthread->attr.sched_policy; - } - - return(ret); -} diff --git a/lib/libc_r/uthread/uthread_getsockname.c b/lib/libc_r/uthread/uthread_getsockname.c deleted file mode 100644 index 1870555..0000000 --- a/lib/libc_r/uthread/uthread_getsockname.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_getsockname, getsockname); - -int -_getsockname(int s, struct sockaddr * name, socklen_t *namelen) -{ - int ret; - - if ((ret = _FD_LOCK(s, FD_READ, NULL)) == 0) { - ret = __sys_getsockname(s, name, namelen); - _FD_UNLOCK(s, FD_READ); - } - return ret; -} diff --git a/lib/libc_r/uthread/uthread_getsockopt.c b/lib/libc_r/uthread/uthread_getsockopt.c deleted file mode 100644 index 23f9860..0000000 --- a/lib/libc_r/uthread/uthread_getsockopt.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_getsockopt, getsockopt); - -int -_getsockopt(int fd, int level, int optname, void *optval, socklen_t - *optlen) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_getsockopt(fd, level, optname, optval, optlen); - _FD_UNLOCK(fd, FD_RDWR); - } - return ret; -} diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c deleted file mode 100644 index 2128820..0000000 --- a/lib/libc_r/uthread/uthread_info.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <paths.h> -#include <pthread.h> -#include <unistd.h> -#include "pthread_private.h" - -#ifndef NELEMENTS -#define NELEMENTS(arr) (sizeof(arr) / sizeof(arr[0])) -#endif - -static void dump_thread(int fd, pthread_t pthread, int long_version); - -__weak_reference(_pthread_set_name_np, pthread_set_name_np); - -struct s_thread_info { - enum pthread_state state; - char *name; -}; - -/* Static variables: */ -static const struct s_thread_info thread_info[] = { - {PS_RUNNING , "Running"}, - {PS_SIGTHREAD , "Waiting on signal thread"}, - {PS_MUTEX_WAIT , "Waiting on a mutex"}, - {PS_COND_WAIT , "Waiting on a condition variable"}, - {PS_FDLR_WAIT , "Waiting for a file read lock"}, - {PS_FDLW_WAIT , "Waiting for a file write lock"}, - {PS_FDR_WAIT , "Waiting for read"}, - {PS_FDW_WAIT , "Waiting for write"}, - {PS_FILE_WAIT , "Waiting for FILE lock"}, - {PS_POLL_WAIT , "Waiting on poll"}, - {PS_SELECT_WAIT , "Waiting on select"}, - {PS_SLEEP_WAIT , "Sleeping"}, - {PS_WAIT_WAIT , "Waiting process"}, - {PS_SIGSUSPEND , "Suspended, waiting for a signal"}, - {PS_SIGWAIT , "Waiting for a signal"}, - {PS_SPINBLOCK , "Waiting for a spinlock"}, - {PS_JOIN , "Waiting to join"}, - {PS_SUSPENDED , "Suspended"}, - {PS_DEAD , "Dead"}, - {PS_DEADLOCK , "Deadlocked"}, - {PS_STATE_MAX , "Not a real state!"} -}; - -void -_thread_dump_info(void) -{ - char s[512]; - int fd; - int i; - pthread_t pthread; - char *tmpdir; - char tmpfile[PATH_MAX]; - pq_list_t *pq_list; - - if (issetugid() != 0 || (tmpdir = getenv("TMPDIR")) == NULL) - tmpdir = _PATH_TMP; - for (i = 0; i < 100000; i++) { - snprintf(tmpfile, sizeof(tmpfile), "%s/uthread.dump.%u.%i", - tmpdir, getpid(), i); - /* Open the dump file for append and create it if necessary: */ - if ((fd = __sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL, - 0644)) < 0) { - /* Can't open the dump file. */ - if (errno == EEXIST) - continue; - /* - * We only need to continue in case of - * EEXIST error. Most other error - * codes means that we will fail all - * the time. - */ - return; - } else { - break; - } - } - if (i==100000) { - /* all 100000 possibilities are in use :( */ - return; - } else { - /* Output a header for active threads: */ - strcpy(s, "\n\n=============\nACTIVE THREADS\n\n"); - __sys_write(fd, s, strlen(s)); - - /* Enter a loop to report each thread in the global list: */ - TAILQ_FOREACH(pthread, &_thread_list, tle) { - dump_thread(fd, pthread, /*long_verson*/ 1); - } - - /* Output a header for ready threads: */ - strcpy(s, "\n\n=============\nREADY THREADS\n\n"); - __sys_write(fd, s, strlen(s)); - - /* Enter a loop to report each thread in the ready queue: */ - TAILQ_FOREACH (pq_list, &_readyq.pq_queue, pl_link) { - TAILQ_FOREACH(pthread, &pq_list->pl_head, pqe) { - dump_thread(fd, pthread, /*long_version*/ 0); - } - } - - /* Output a header for waiting threads: */ - strcpy(s, "\n\n=============\nWAITING THREADS\n\n"); - __sys_write(fd, s, strlen(s)); - - /* Enter a loop to report each thread in the waiting queue: */ - TAILQ_FOREACH (pthread, &_waitingq, pqe) { - dump_thread(fd, pthread, /*long_version*/ 0); - } - - /* Output a header for threads in the work queue: */ - strcpy(s, "\n\n=============\nTHREADS IN WORKQ\n\n"); - __sys_write(fd, s, strlen(s)); - - /* Enter a loop to report each thread in the waiting queue: */ - TAILQ_FOREACH (pthread, &_workq, qe) { - dump_thread(fd, pthread, /*long_version*/ 0); - } - - /* Check if there are no dead threads: */ - if (TAILQ_FIRST(&_dead_list) == NULL) { - /* Output a record: */ - strcpy(s, "\n\nTHERE ARE NO DEAD THREADS\n"); - __sys_write(fd, s, strlen(s)); - } else { - /* Output a header for dead threads: */ - strcpy(s, "\n\nDEAD THREADS\n\n"); - __sys_write(fd, s, strlen(s)); - - /* - * Enter a loop to report each thread in the global - * dead thread list: - */ - TAILQ_FOREACH(pthread, &_dead_list, dle) { - dump_thread(fd, pthread, /*long_version*/ 0); - } - } - - /* Output a header for file descriptors: */ - snprintf(s, sizeof(s), "\n\n=============\nFILE DESCRIPTOR " - "TABLE (table size %d)\n\n", _thread_dtablesize); - __sys_write(fd, s, strlen(s)); - - /* Enter a loop to report file descriptor lock usage: */ - for (i = 0; i < _thread_dtablesize; i++) { - /* - * Check if memory is allocated for this file - * descriptor: - */ - if (_thread_fd_table[i] != NULL) { - /* Report the file descriptor lock status: */ - snprintf(s, sizeof(s), - "fd[%3d] read owner %p count %d [%s:%d]\n" - " write owner %p count %d [%s:%d]\n", - i, _thread_fd_table[i]->r_owner, - _thread_fd_table[i]->r_lockcount, - _thread_fd_table[i]->r_fname, - _thread_fd_table[i]->r_lineno, - _thread_fd_table[i]->w_owner, - _thread_fd_table[i]->w_lockcount, - _thread_fd_table[i]->w_fname, - _thread_fd_table[i]->w_lineno); - __sys_write(fd, s, strlen(s)); - } - } - - /* Close the dump file: */ - __sys_close(fd); - } -} - -static void -dump_thread(int fd, pthread_t pthread, int long_version) -{ - struct pthread *curthread = _get_curthread(); - char s[512]; - int i; - - /* Find the state: */ - for (i = 0; i < NELEMENTS(thread_info) - 1; i++) - if (thread_info[i].state == pthread->state) - break; - - /* Output a record for the thread: */ - snprintf(s, sizeof(s), - "--------------------\nThread %p (%s) prio %3d state %s", - pthread, (pthread->name == NULL) ? "" : pthread->name, - pthread->active_priority, thread_info[i].name); - __sys_write(fd, s, strlen(s)); - /* And now where it is. */ - if (pthread->fname != NULL) { - snprintf(s, sizeof(s), " [%s:%d]", pthread->fname, - pthread->lineno); - __sys_write(fd, s, strlen(s)); - } - __sys_write(fd, "\n", 1); - - if (long_version != 0) { - /* Check if this is the running thread: */ - if (pthread == curthread) { - /* Output a record for the running thread: */ - strcpy(s, "This is the running thread\n"); - __sys_write(fd, s, strlen(s)); - } - /* Check if this is the initial thread: */ - if (pthread == _thread_initial) { - /* Output a record for the initial thread: */ - strcpy(s, "This is the initial thread\n"); - __sys_write(fd, s, strlen(s)); - } - /* Process according to thread state: */ - switch (pthread->state) { - /* File descriptor read lock wait: */ - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FDR_WAIT: - case PS_FDW_WAIT: - /* Write the lock details: */ - snprintf(s, sizeof(s), "fd %d[%s:%d]", - pthread->data.fd.fd, - pthread->data.fd.fname, - pthread->data.fd.branch); - __sys_write(fd, s, strlen(s)); - break; - case PS_SIGWAIT: - snprintf(s, sizeof(s), "sigmask (hi)"); - __sys_write(fd, s, strlen(s)); - for (i = _SIG_WORDS - 1; i >= 0; i--) { - snprintf(s, sizeof(s), "%08x\n", - pthread->sigmask.__bits[i]); - __sys_write(fd, s, strlen(s)); - } - snprintf(s, sizeof(s), "(lo)\n"); - __sys_write(fd, s, strlen(s)); - break; - /* - * Trap other states that are not explicitly - * coded to dump information: - */ - default: - /* Nothing to do here. */ - break; - } - } -} - -/* Set the thread name for debug: */ -void -_pthread_set_name_np(pthread_t thread, const char *name) -{ - /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == PTHREAD_MAGIC) { - if (thread->name != NULL) { - /* Free space for previous name. */ - free(thread->name); - } - thread->name = strdup(name); - } -} diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c deleted file mode 100644 index 7c8c444..0000000 --- a/lib/libc_r/uthread/uthread_init.c +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* Allocate space for global thread variables here: */ -#define GLOBAL_PTHREAD_PRIVATE - -#include "namespace.h" -#include <sys/param.h> -#include <sys/types.h> -#include <machine/reg.h> - -#include <sys/ioctl.h> -#include <sys/mount.h> -#include <sys/uio.h> -#include <sys/socket.h> -#include <sys/event.h> -#include <sys/stat.h> -#include <sys/sysctl.h> -#include <sys/time.h> -#include <sys/ttycom.h> -#include <sys/wait.h> -#include <sys/mman.h> -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <paths.h> -#include <poll.h> -#include <pthread.h> -#include <pthread_np.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include "un-namespace.h" - -#include "libc_private.h" -#include "pthread_private.h" - -int __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); -int __pthread_mutex_lock(pthread_mutex_t *); -int __pthread_mutex_trylock(pthread_mutex_t *); - -/* - * All weak references used within libc should be in this table. - * This allows static libraries to work. - */ -static void *references[] = { - &_accept, - &_bind, - &_close, - &_connect, - &_dup, - &_dup2, - &_execve, - &_fcntl, - &_flock, - &_flockfile, - &_fstat, - &_fstatfs, - &_fsync, - &_funlockfile, - &_getdirentries, - &_getlogin, - &_getpeername, - &_getsockname, - &_getsockopt, - &_ioctl, - &_kevent, - &_kqueue, - &_listen, - &_nanosleep, - &_open, - &_pthread_cond_destroy, - &_pthread_cond_init, - &_pthread_cond_signal, - &_pthread_cond_wait, - &_pthread_getspecific, - &_pthread_key_create, - &_pthread_key_delete, - &_pthread_mutex_destroy, - &_pthread_mutex_init, - &_pthread_mutex_lock, - &_pthread_mutex_trylock, - &_pthread_mutex_unlock, - &_pthread_mutexattr_init, - &_pthread_mutexattr_destroy, - &_pthread_mutexattr_settype, - &_pthread_once, - &_pthread_setspecific, - &_read, - &_readv, - &_recvfrom, - &_recvmsg, - &_select, - &_sendmsg, - &_sendto, - &_setsockopt, - &_sigaction, - &_sigprocmask, - &_sigsuspend, - &_socket, - &_socketpair, - &_wait4, - &_write, - &_writev -}; - -/* - * These are needed when linking statically. All references within - * libgcc (and libc) to these routines are weak, but if they are not - * (strongly) referenced by the application or other libraries, then - * the actual functions will not be loaded. - */ -static void *libgcc_references[] = { - &_pthread_once, - &_pthread_key_create, - &_pthread_key_delete, - &_pthread_getspecific, - &_pthread_setspecific, - &_pthread_mutex_init, - &_pthread_mutex_destroy, - &_pthread_mutex_lock, - &_pthread_mutex_trylock, - &_pthread_mutex_unlock -}; - -#define DUAL_ENTRY(entry) \ - (pthread_func_t)entry, (pthread_func_t)entry - -static pthread_func_t jmp_table[][2] = { - {DUAL_ENTRY(_pthread_atfork)}, /* PJT_ATFORK */ - {DUAL_ENTRY(_pthread_attr_destroy)}, /* PJT_ATTR_DESTROY */ - {DUAL_ENTRY(_pthread_attr_getdetachstate)}, /* PJT_ATTR_GETDETACHSTATE */ - {DUAL_ENTRY(_pthread_attr_getguardsize)}, /* PJT_ATTR_GETGUARDSIZE */ - {DUAL_ENTRY(_pthread_attr_getinheritsched)}, /* PJT_ATTR_GETINHERITSCHED */ - {DUAL_ENTRY(_pthread_attr_getschedparam)}, /* PJT_ATTR_GETSCHEDPARAM */ - {DUAL_ENTRY(_pthread_attr_getschedpolicy)}, /* PJT_ATTR_GETSCHEDPOLICY */ - {DUAL_ENTRY(_pthread_attr_getscope)}, /* PJT_ATTR_GETSCOPE */ - {DUAL_ENTRY(_pthread_attr_getstackaddr)}, /* PJT_ATTR_GETSTACKADDR */ - {DUAL_ENTRY(_pthread_attr_getstacksize)}, /* PJT_ATTR_GETSTACKSIZE */ - {DUAL_ENTRY(_pthread_attr_init)}, /* PJT_ATTR_INIT */ - {DUAL_ENTRY(_pthread_attr_setdetachstate)}, /* PJT_ATTR_SETDETACHSTATE */ - {DUAL_ENTRY(_pthread_attr_setguardsize)}, /* PJT_ATTR_SETGUARDSIZE */ - {DUAL_ENTRY(_pthread_attr_setinheritsched)}, /* PJT_ATTR_SETINHERITSCHED */ - {DUAL_ENTRY(_pthread_attr_setschedparam)}, /* PJT_ATTR_SETSCHEDPARAM */ - {DUAL_ENTRY(_pthread_attr_setschedpolicy)}, /* PJT_ATTR_SETSCHEDPOLICY */ - {DUAL_ENTRY(_pthread_attr_setscope)}, /* PJT_ATTR_SETSCOPE */ - {DUAL_ENTRY(_pthread_attr_setstackaddr)}, /* PJT_ATTR_SETSTACKADDR */ - {DUAL_ENTRY(_pthread_attr_setstacksize)}, /* PJT_ATTR_SETSTACKSIZE */ - {DUAL_ENTRY(_pthread_cancel)}, /* PJT_CANCEL */ - {DUAL_ENTRY(_pthread_cleanup_pop)}, /* PJT_CLEANUP_POP */ - {DUAL_ENTRY(_pthread_cleanup_push)}, /* PJT_CLEANUP_PUSH */ - {DUAL_ENTRY(_pthread_cond_broadcast)}, /* PJT_COND_BROADCAST */ - {DUAL_ENTRY(_pthread_cond_destroy)}, /* PJT_COND_DESTROY */ - {DUAL_ENTRY(_pthread_cond_init)}, /* PJT_COND_INIT */ - {DUAL_ENTRY(_pthread_cond_signal)}, /* PJT_COND_SIGNAL */ - {DUAL_ENTRY(_pthread_cond_timedwait)}, /* PJT_COND_TIMEDWAIT */ - {(pthread_func_t)__pthread_cond_wait, - (pthread_func_t)_pthread_cond_wait}, /* PJT_COND_WAIT */ - {DUAL_ENTRY(_pthread_detach)}, /* PJT_DETACH */ - {DUAL_ENTRY(_pthread_equal)}, /* PJT_EQUAL */ - {DUAL_ENTRY(_pthread_exit)}, /* PJT_EXIT */ - {DUAL_ENTRY(_pthread_getspecific)}, /* PJT_GETSPECIFIC */ - {DUAL_ENTRY(_pthread_join)}, /* PJT_JOIN */ - {DUAL_ENTRY(_pthread_key_create)}, /* PJT_KEY_CREATE */ - {DUAL_ENTRY(_pthread_key_delete)}, /* PJT_KEY_DELETE*/ - {DUAL_ENTRY(_pthread_kill)}, /* PJT_KILL */ - {DUAL_ENTRY(_pthread_main_np)}, /* PJT_MAIN_NP */ - {DUAL_ENTRY(_pthread_mutexattr_destroy)}, /* PJT_MUTEXATTR_DESTROY */ - {DUAL_ENTRY(_pthread_mutexattr_init)}, /* PJT_MUTEXATTR_INIT */ - {DUAL_ENTRY(_pthread_mutexattr_settype)}, /* PJT_MUTEXATTR_SETTYPE */ - {DUAL_ENTRY(_pthread_mutex_destroy)}, /* PJT_MUTEX_DESTROY */ - {DUAL_ENTRY(_pthread_mutex_init)}, /* PJT_MUTEX_INIT */ - {(pthread_func_t)__pthread_mutex_lock, - (pthread_func_t)_pthread_mutex_lock}, /* PJT_MUTEX_LOCK */ - {(pthread_func_t)__pthread_mutex_trylock, - (pthread_func_t)_pthread_mutex_trylock},/* PJT_MUTEX_TRYLOCK */ - {DUAL_ENTRY(_pthread_mutex_unlock)}, /* PJT_MUTEX_UNLOCK */ - {DUAL_ENTRY(_pthread_once)}, /* PJT_ONCE */ - {DUAL_ENTRY(_pthread_rwlock_destroy)}, /* PJT_RWLOCK_DESTROY */ - {DUAL_ENTRY(_pthread_rwlock_init)}, /* PJT_RWLOCK_INIT */ - {DUAL_ENTRY(_pthread_rwlock_rdlock)}, /* PJT_RWLOCK_RDLOCK */ - {DUAL_ENTRY(_pthread_rwlock_tryrdlock)},/* PJT_RWLOCK_TRYRDLOCK */ - {DUAL_ENTRY(_pthread_rwlock_trywrlock)},/* PJT_RWLOCK_TRYWRLOCK */ - {DUAL_ENTRY(_pthread_rwlock_unlock)}, /* PJT_RWLOCK_UNLOCK */ - {DUAL_ENTRY(_pthread_rwlock_wrlock)}, /* PJT_RWLOCK_WRLOCK */ - {DUAL_ENTRY(_pthread_self)}, /* PJT_SELF */ - {DUAL_ENTRY(_pthread_setcancelstate)}, /* PJT_SETCANCELSTATE */ - {DUAL_ENTRY(_pthread_setcanceltype)}, /* PJT_SETCANCELTYPE */ - {DUAL_ENTRY(_pthread_setspecific)}, /* PJT_SETSPECIFIC */ - {DUAL_ENTRY(_pthread_sigmask)}, /* PJT_SIGMASK */ - {DUAL_ENTRY(_pthread_testcancel)} /* PJT_TESTCANCEL */ -}; - -int _pthread_guard_default; -int _pthread_page_size; -int _pthread_stack_default; -int _pthread_stack_initial; - -/* - * Threaded process initialization - */ -void -_thread_init(void) -{ - int fd; - int flags; - int i; - size_t len; - int mib[2]; - int sched_stack_size; /* Size of scheduler stack. */ -#if !defined(__ia64__) - u_long stackp; -#endif - - struct clockinfo clockinfo; - struct sigaction act; - - - /* Check if this function has already been called: */ - if (_thread_initial) - /* Only initialise the threaded application once. */ - return; - - _pthread_page_size = getpagesize();; - _pthread_guard_default = _pthread_page_size; - sched_stack_size = 4 * _pthread_page_size; - if (sizeof(void *) == 8) { - _pthread_stack_default = PTHREAD_STACK64_DEFAULT; - _pthread_stack_initial = PTHREAD_STACK64_INITIAL; - } - else { - _pthread_stack_default = PTHREAD_STACK32_DEFAULT; - _pthread_stack_initial = PTHREAD_STACK32_INITIAL; - } - - _pthread_attr_default.guardsize_attr = _pthread_guard_default; - _pthread_attr_default.stacksize_attr = _pthread_stack_default; - - /* - * Make gcc quiescent about {,libgcc_}references not being - * referenced: - */ - if ((references[0] == NULL) || (libgcc_references[0] == NULL)) - PANIC("Failed loading mandatory references in _thread_init"); - - /* - * Check the size of the jump table to make sure it is preset - * with the correct number of entries. - */ - if (sizeof(jmp_table) != (sizeof(pthread_func_t) * PJT_MAX * 2)) - PANIC("Thread jump table not properly initialized"); - memcpy(__thr_jtable, jmp_table, sizeof(jmp_table)); - - /* - * Check for the special case of this process running as - * or in place of init as pid = 1: - */ - if (getpid() == 1) { - /* - * Setup a new session for this process which is - * assumed to be running as root. - */ - if (setsid() == -1) - PANIC("Can't set session ID"); - if (revoke(_PATH_CONSOLE) != 0) - PANIC("Can't revoke console"); - if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0) - PANIC("Can't open console"); - if (setlogin("root") == -1) - PANIC("Can't set login to root"); - if (__sys_ioctl(fd, TIOCSCTTY, (char *) NULL) == -1) - PANIC("Can't set controlling terminal"); - if (__sys_dup2(fd, 0) == -1 || - __sys_dup2(fd, 1) == -1 || - __sys_dup2(fd, 2) == -1) - PANIC("Can't dup2"); - } - - /* Get the standard I/O flags before messing with them : */ - for (i = 0; i < 3; i++) { - if (((_pthread_stdio_flags[i] = - __sys_fcntl(i, F_GETFL, NULL)) == -1) && - (errno != EBADF)) - PANIC("Cannot get stdio flags"); - } - - /* - * Create a pipe that is written to by the signal handler to prevent - * signals being missed in calls to _select: - */ - if (__sys_pipe(_thread_kern_pipe) != 0) { - /* Cannot create pipe, so abort: */ - PANIC("Cannot create kernel pipe"); - } - - /* - * Make sure the pipe does not get in the way of stdio: - */ - for (i = 0; i < 2; i++) { - if (_thread_kern_pipe[i] < 3) { - fd = __sys_fcntl(_thread_kern_pipe[i], F_DUPFD, 3); - if (fd == -1) - PANIC("Cannot create kernel pipe"); - __sys_close(_thread_kern_pipe[i]); - _thread_kern_pipe[i] = fd; - } - } - /* Get the flags for the read pipe: */ - if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - PANIC("Cannot get kernel read pipe flags"); - } - /* Make the read pipe non-blocking: */ - else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - PANIC("Cannot make kernel read pipe non-blocking"); - } - /* Get the flags for the write pipe: */ - else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - PANIC("Cannot get kernel write pipe flags"); - } - /* Make the write pipe non-blocking: */ - else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - PANIC("Cannot get kernel write pipe flags"); - } - /* Allocate and initialize the ready queue: */ - else if (_pq_alloc(&_readyq, PTHREAD_MIN_PRIORITY, PTHREAD_LAST_PRIORITY) != 0) { - /* Abort this application: */ - PANIC("Cannot allocate priority ready queue."); - } - /* Allocate memory for the thread structure of the initial thread: */ - else if ((_thread_initial = (pthread_t) malloc(sizeof(struct pthread))) == NULL) { - /* - * Insufficient memory to initialise this application, so - * abort: - */ - PANIC("Cannot allocate memory for initial thread"); - } - /* Allocate memory for the scheduler stack: */ - else if ((_thread_kern_sched_stack = malloc(sched_stack_size)) == NULL) - PANIC("Failed to allocate stack for scheduler"); - else { - /* Zero the global kernel thread structure: */ - memset(&_thread_kern_thread, 0, sizeof(struct pthread)); - _thread_kern_thread.flags = PTHREAD_FLAGS_PRIVATE; - memset(_thread_initial, 0, sizeof(struct pthread)); - - /* Initialize the waiting and work queues: */ - TAILQ_INIT(&_waitingq); - TAILQ_INIT(&_workq); - - /* Initialize the scheduling switch hook routine: */ - _sched_switch_hook = NULL; - - /* Give this thread default attributes: */ - memcpy((void *) &_thread_initial->attr, &_pthread_attr_default, - sizeof(struct pthread_attr)); - - /* Find the stack top */ - mib[0] = CTL_KERN; - mib[1] = KERN_USRSTACK; - len = sizeof (_usrstack); - if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1) - _usrstack = (void *)USRSTACK; - /* - * Create a red zone below the main stack. All other stacks are - * constrained to a maximum size by the paramters passed to - * mmap(), but this stack is only limited by resource limits, so - * this stack needs an explicitly mapped red zone to protect the - * thread stack that is just beyond. - */ - if (mmap(_usrstack - _pthread_stack_initial - - _pthread_guard_default, _pthread_guard_default, 0, - MAP_ANON, -1, 0) == MAP_FAILED) - PANIC("Cannot allocate red zone for initial thread"); - - /* Set the main thread stack pointer. */ - _thread_initial->stack = _usrstack - _pthread_stack_initial; - - /* Set the stack attributes: */ - _thread_initial->attr.stackaddr_attr = _thread_initial->stack; - _thread_initial->attr.stacksize_attr = _pthread_stack_initial; - - /* Setup the context for the scheduler: */ - _setjmp(_thread_kern_sched_jb); -#if !defined(__ia64__) - stackp = (long)_thread_kern_sched_stack + sched_stack_size - sizeof(double); -#if defined(__amd64__) - stackp &= ~0xFUL; -#endif - SET_STACK_JB(_thread_kern_sched_jb, stackp); -#else - SET_STACK_JB(_thread_kern_sched_jb, _thread_kern_sched_stack, - sched_stack_size); -#endif - SET_RETURN_ADDR_JB(_thread_kern_sched_jb, _thread_kern_scheduler); - - /* - * Write a magic value to the thread structure - * to help identify valid ones: - */ - _thread_initial->magic = PTHREAD_MAGIC; - - /* Set the initial cancel state */ - _thread_initial->cancelflags = PTHREAD_CANCEL_ENABLE | - PTHREAD_CANCEL_DEFERRED; - - /* Default the priority of the initial thread: */ - _thread_initial->base_priority = PTHREAD_DEFAULT_PRIORITY; - _thread_initial->active_priority = PTHREAD_DEFAULT_PRIORITY; - _thread_initial->inherited_priority = 0; - - /* Initialise the state of the initial thread: */ - _thread_initial->state = PS_RUNNING; - - /* Set the name of the thread: */ - _thread_initial->name = strdup("_thread_initial"); - - /* Initialize joiner to NULL (no joiner): */ - _thread_initial->joiner = NULL; - - /* Initialize the owned mutex queue and count: */ - TAILQ_INIT(&(_thread_initial->mutexq)); - _thread_initial->priority_mutex_count = 0; - - /* Initialize the global scheduling time: */ - _sched_ticks = 0; - gettimeofday((struct timeval *) &_sched_tod, NULL); - - /* Initialize last active: */ - _thread_initial->last_active = (long) _sched_ticks; - - /* Initialize the initial context: */ - _thread_initial->curframe = NULL; - - /* Initialise the rest of the fields: */ - _thread_initial->poll_data.nfds = 0; - _thread_initial->poll_data.fds = NULL; - _thread_initial->sig_defer_count = 0; - _thread_initial->yield_on_sig_undefer = 0; - _thread_initial->specific = NULL; - _thread_initial->cleanup = NULL; - _thread_initial->flags = 0; - _thread_initial->error = 0; - TAILQ_INIT(&_thread_list); - TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle); - _set_curthread(_thread_initial); - TAILQ_INIT(&_atfork_list); - _pthread_mutex_init(&_atfork_mutex, NULL); - - /* Initialise the global signal action structure: */ - sigfillset(&act.sa_mask); - act.sa_handler = (void (*) ()) _thread_sig_handler; - act.sa_flags = SA_SIGINFO | SA_RESTART; - - /* Clear pending signals for the process: */ - sigemptyset(&_process_sigpending); - - /* Clear the signal queue: */ - memset(_thread_sigq, 0, sizeof(_thread_sigq)); - - /* Enter a loop to get the existing signal status: */ - for (i = 1; i < NSIG; i++) { - /* Check for signals which cannot be trapped: */ - if (i == SIGKILL || i == SIGSTOP) { - } - - /* Get the signal handler details: */ - else if (__sys_sigaction(i, NULL, - &_thread_sigact[i - 1]) != 0) { - /* - * Abort this process if signal - * initialisation fails: - */ - PANIC("Cannot read signal handler info"); - } - - /* Initialize the SIG_DFL dummy handler count. */ - _thread_dfl_count[i] = 0; - } - - /* - * Install the signal handler for the most important - * signals that the user-thread kernel needs. Actually - * SIGINFO isn't really needed, but it is nice to have. - */ - if (__sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 || - __sys_sigaction(SIGINFO, &act, NULL) != 0 || - __sys_sigaction(SIGCHLD, &act, NULL) != 0) { - /* - * Abort this process if signal initialisation fails: - */ - PANIC("Cannot initialise signal handler"); - } - _thread_sigact[_SCHED_SIGNAL - 1].sa_flags = SA_SIGINFO; - _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO; - _thread_sigact[SIGCHLD - 1].sa_flags = SA_SIGINFO; - - /* Get the process signal mask: */ - __sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask); - - /* Get the kernel clockrate: */ - mib[0] = CTL_KERN; - mib[1] = KERN_CLOCKRATE; - len = sizeof (struct clockinfo); - if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0) - _clock_res_usec = clockinfo.tick > CLOCK_RES_USEC_MIN ? - clockinfo.tick : CLOCK_RES_USEC_MIN; - - /* Get the table size: */ - if ((_thread_dtablesize = getdtablesize()) < 0) { - /* - * Cannot get the system defined table size, so abort - * this process. - */ - PANIC("Cannot get dtablesize"); - } - /* Allocate memory for the file descriptor table: */ - if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) { - /* Avoid accesses to file descriptor table on exit: */ - _thread_dtablesize = 0; - - /* - * Cannot allocate memory for the file descriptor - * table, so abort this process. - */ - PANIC("Cannot allocate memory for file descriptor table"); - } - /* Allocate memory for the pollfd table: */ - if ((_thread_pfd_table = (struct pollfd *) malloc(sizeof(struct pollfd) * _thread_dtablesize)) == NULL) { - /* - * Cannot allocate memory for the file descriptor - * table, so abort this process. - */ - PANIC("Cannot allocate memory for pollfd table"); - } else { - /* - * Enter a loop to initialise the file descriptor - * table: - */ - for (i = 0; i < _thread_dtablesize; i++) { - /* Initialise the file descriptor table: */ - _thread_fd_table[i] = NULL; - } - - /* Initialize stdio file descriptor table entries: */ - for (i = 0; i < 3; i++) { - if ((_thread_fd_table_init(i) != 0) && - (errno != EBADF)) - PANIC("Cannot initialize stdio file " - "descriptor table entry"); - } - } - } - - /* Initialise the garbage collector mutex and condition variable. */ - if (_pthread_mutex_init(&_gc_mutex,NULL) != 0 || - _pthread_cond_init(&_gc_cond,NULL) != 0) - PANIC("Failed to initialise garbage collector mutex or condvar"); -} - - -/* - * Special start up code for NetBSD/Alpha - */ -#if defined(__NetBSD__) && defined(__alpha__) -int -main(int argc, char *argv[], char *env); - -int -_thread_main(int argc, char *argv[], char *env) -{ - _thread_init(); - return (main(argc, argv, env)); -} -#endif diff --git a/lib/libc_r/uthread/uthread_ioctl.c b/lib/libc_r/uthread/uthread_ioctl.c deleted file mode 100644 index f56146a..0000000 --- a/lib/libc_r/uthread/uthread_ioctl.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <stdarg.h> -#include <sys/ioctl.h> -#include <sys/fcntl.h> /* O_NONBLOCK*/ -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_ioctl, ioctl); - -int -_ioctl(int fd, unsigned long request,...) -{ - int ret; - int flags; - int *op; - va_list ap; - - /* Lock the file descriptor: */ - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - /* Initialise the variable argument list: */ - va_start(ap, request); - - switch( request) { - case FIONBIO: - /* - * descriptors must be non-blocking; we are only - * twiddling the flag based on the request - */ - op = va_arg(ap, int *); - flags = _thread_fd_getflags(fd); - if (*op == 0) - flags &= ~O_NONBLOCK; - else - flags |= O_NONBLOCK; - _thread_fd_setflags(fd, flags); - ret = 0; - break; - default: - ret = __sys_ioctl(fd, request, va_arg(ap, char *)); - break; - } - - /* Free variable arguments: */ - va_end(ap); - - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_RDWR); - } - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_jmp.c b/lib/libc_r/uthread/uthread_jmp.c deleted file mode 100644 index 5aa0001..0000000 --- a/lib/libc_r/uthread/uthread_jmp.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>. - * All rights reserved. - * Copyright (C) 2000 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(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 <unistd.h> -#include <setjmp.h> -#include <sys/param.h> -#include <machine/reg.h> -#include <pthread.h> -#include "pthread_private.h" - -/* Prototypes: */ -static inline int check_stack(pthread_t thread, void *stackp); - -__weak_reference(_thread_siglongjmp, siglongjmp); -__weak_reference(_thread_longjmp, longjmp); -__weak_reference(__thread_longjmp, _longjmp); - -void -_thread_siglongjmp(sigjmp_buf env, int savemask) -{ - struct pthread *curthread = _get_curthread(); - - if (check_stack(curthread, (void *) GET_STACK_SJB(env))) - PANIC("siglongjmp()ing between thread contexts is undefined by " - "POSIX 1003.1"); - - /* - * The stack pointer is somewhere within the threads stack. - * Jump to the users context. - */ - __siglongjmp(env, savemask); -} - -void -_thread_longjmp(jmp_buf env, int val) -{ - struct pthread *curthread = _get_curthread(); - - if (check_stack(curthread, (void *) GET_STACK_JB(env))) - PANIC("longjmp()ing between thread contexts is undefined by " - "POSIX 1003.1"); - - /* - * The stack pointer is somewhere within the threads stack. - * Jump to the users context. - */ - __longjmp(env, val); -} - -void -__thread_longjmp(jmp_buf env, int val) -{ - struct pthread *curthread = _get_curthread(); - - if (check_stack(curthread, (void *) GET_STACK_JB(env))) - PANIC("_longjmp()ing between thread contexts is undefined by " - "POSIX 1003.1"); - - /* - * The stack pointer is somewhere within the threads stack. - * Jump to the users context. - */ - ___longjmp(env, val); -} - -/* Returns 0 if stack check is OK, non-zero otherwise. */ -static inline int -check_stack(pthread_t thread, void *stackp) -{ - void *stack_begin, *stack_end; - - /* Get the bounds of the current threads stack. */ - PTHREAD_ASSERT(thread->stack != NULL, - "Thread stack pointer is null"); - stack_begin = thread->stack; - stack_end = stack_begin + thread->attr.stacksize_attr; - - /* - * Make sure we aren't jumping to a different stack. Make sure - * jmp_stackp is between stack_begin and stack end, to correctly detect - * this condition regardless of whether the stack grows up or down. - */ - if (((stackp < stack_begin) && (stackp < stack_end)) || - ((stackp > stack_begin) && (stackp > stack_end))) - return (1); - else - return (0); -} diff --git a/lib/libc_r/uthread/uthread_join.c b/lib/libc_r/uthread/uthread_join.c deleted file mode 100644 index c8f8441..0000000 --- a/lib/libc_r/uthread/uthread_join.c +++ /dev/null @@ -1,164 +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 "namespace.h" -#include <pthread.h> -#include "un-namespace.h" -#include "pthread_private.h" - -__weak_reference(_pthread_join, pthread_join); - -int -_pthread_join(pthread_t pthread, void **thread_return) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - pthread_t thread; - - _thread_enter_cancellation_point(); - - /* Check if the caller has specified an invalid thread: */ - if (pthread == NULL || pthread->magic != PTHREAD_MAGIC) { - /* Invalid thread: */ - _thread_leave_cancellation_point(); - return(EINVAL); - } - - /* Check if the caller has specified itself: */ - if (pthread == curthread) { - /* Avoid a deadlock condition: */ - _thread_leave_cancellation_point(); - return(EDEADLK); - } - - /* - * 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"); - - /* - * Defer signals to protect the thread list from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Unlock the garbage collector mutex, now that the garbage collector - * can't be run: - */ - if (_pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - /* - * Search for the specified thread in the list of active threads. This - * is done manually here rather than calling _find_thread() because - * the searches in _thread_list and _dead_list (as well as setting up - * join/detach state) have to be done atomically. - */ - TAILQ_FOREACH(thread, &_thread_list, tle) { - if (thread == pthread) - break; - } - if (thread == NULL) { - /* - * Search for the specified thread in the list of dead threads: - */ - TAILQ_FOREACH(thread, &_dead_list, dle) { - if (thread == pthread) - break; - } - } - - /* Check if the thread was not found or has been detached: */ - if (thread == NULL || - ((pthread->attr.flags & PTHREAD_DETACHED) != 0)) { - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - - /* Return an error: */ - ret = ESRCH; - - } else if (pthread->joiner != NULL) { - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - - /* Multiple joiners are not supported. */ - ret = ENOTSUP; - - /* Check if the thread is not dead: */ - } else if (pthread->state != PS_DEAD) { - /* Set the running thread to be the joiner: */ - pthread->joiner = curthread; - - /* Keep track of which thread we're joining to: */ - curthread->join_status.thread = pthread; - - while (curthread->join_status.thread == pthread) { - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); - } - - /* - * The thread return value and error are set by the thread we're - * joining to when it exits or detaches: - */ - ret = curthread->join_status.error; - if ((ret == 0) && (thread_return != NULL)) - *thread_return = curthread->join_status.ret; - - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - } else { - /* - * The thread exited (is dead) without being detached, and no - * thread has joined it. - */ - - /* Check if the return value is required: */ - if (thread_return != NULL) { - /* Return the thread's return value: */ - *thread_return = pthread->ret; - } - - /* Make the thread collectable by the garbage collector. */ - pthread->attr.flags |= PTHREAD_DETACHED; - - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - } - - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c deleted file mode 100644 index 8bd25b4..0000000 --- a/lib/libc_r/uthread/uthread_kern.c +++ /dev/null @@ -1,1135 +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 <poll.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <unistd.h> -#include <setjmp.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/signalvar.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <sys/syscall.h> -#include <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -/* #define DEBUG_THREAD_KERN */ -#ifdef DEBUG_THREAD_KERN -#define DBG_MSG stdout_debug -#else -#define DBG_MSG(x...) -#endif - -/* Static function prototype definitions: */ -static void -thread_kern_poll(int wait_reqd); - -static void -dequeue_signals(void); - -static inline void -thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in); - -/* Static variables: */ -static int last_tick = 0; -static int called_from_handler = 0; - -/* - * This is called when a signal handler finishes and wants to - * return to a previous frame. - */ -void -_thread_kern_sched_frame(struct pthread_signal_frame *psf) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a signal from interrupting this execution and - * corrupting the (soon-to-be) current frame. - */ - _thread_kern_in_sched = 1; - - /* Restore the signal frame: */ - _thread_sigframe_restore(curthread, psf); - - /* The signal mask was restored; check for any pending signals: */ - curthread->check_pending = 1; - - /* Switch to the thread scheduler: */ - ___longjmp(_thread_kern_sched_jb, 1); -} - - -void -_thread_kern_sched(ucontext_t *ucp) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* Check if this function was called from the signal handler: */ - if (ucp != NULL) { - called_from_handler = 1; - DBG_MSG("Entering scheduler due to signal\n"); - } - - /* Save the state of the current thread: */ - if (_setjmp(curthread->ctx.jb) != 0) { - DBG_MSG("Returned from ___longjmp, thread %p\n", - curthread); - /* - * This point is reached when a longjmp() is called - * to restore the state of a thread. - * - * This is the normal way out of the scheduler. - */ - _thread_kern_in_sched = 0; - - if (curthread->sig_defer_count == 0) { - if (((curthread->cancelflags & - PTHREAD_AT_CANCEL_POINT) == 0) && - ((curthread->cancelflags & - PTHREAD_CANCEL_ASYNCHRONOUS) != 0)) - /* - * Cancellations override signals. - * - * Stick a cancellation point at the - * start of each async-cancellable - * thread's resumption. - * - * We allow threads woken at cancel - * points to do their own checks. - */ - pthread_testcancel(); - } - - if (_sched_switch_hook != NULL) { - /* Run the installed switch hook: */ - thread_run_switch_hook(_last_user_thread, curthread); - } - if (ucp == NULL) - return; - else { - /* - * Set the process signal mask in the context; it - * could have changed by the handler. - */ - ucp->uc_sigmask = _process_sigmask; - - /* Resume the interrupted thread: */ - __sys_sigreturn(ucp); - } - } - /* Switch to the thread scheduler: */ - ___longjmp(_thread_kern_sched_jb, 1); -} - -void -_thread_kern_sched_sig(void) -{ - struct pthread *curthread = _get_curthread(); - - curthread->check_pending = 1; - _thread_kern_sched(NULL); -} - - -void -_thread_kern_scheduler(void) -{ - struct timespec ts; - struct timeval tv; - struct pthread *curthread = _get_curthread(); - pthread_t pthread, pthread_h; - unsigned int current_tick; - int add_to_prioq; - - /* If the currently running thread is a user thread, save it: */ - if ((curthread->flags & PTHREAD_FLAGS_PRIVATE) == 0) - _last_user_thread = curthread; - - if (called_from_handler != 0) { - called_from_handler = 0; - - /* - * We were called from a signal handler; restore the process - * signal mask. - */ - if (__sys_sigprocmask(SIG_SETMASK, - &_process_sigmask, NULL) != 0) - PANIC("Unable to restore process mask after signal"); - } - - /* - * Enter a scheduling loop that finds the next thread that is - * ready to run. This loop completes when there are no more threads - * in the global list or when a thread has its state restored by - * either a sigreturn (if the state was saved as a sigcontext) or a - * longjmp (if the state was saved by a setjmp). - */ - while (!(TAILQ_EMPTY(&_thread_list))) { - /* Get the current time of day: */ - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, &ts); - current_tick = _sched_ticks; - - /* - * Protect the scheduling queues from access by the signal - * handler. - */ - _queue_signals = 1; - add_to_prioq = 0; - - if (curthread != &_thread_kern_thread) { - /* - * This thread no longer needs to yield the CPU. - */ - curthread->yield_on_sig_undefer = 0; - - if (curthread->state != PS_RUNNING) { - /* - * Save the current time as the time that the - * thread became inactive: - */ - curthread->last_inactive = (long)current_tick; - if (curthread->last_inactive < - curthread->last_active) { - /* Account for a rollover: */ - curthread->last_inactive =+ - UINT_MAX + 1; - } - } - - /* - * Place the currently running thread into the - * appropriate queue(s). - */ - switch (curthread->state) { - case PS_DEAD: - case PS_STATE_MAX: /* to silence -Wall */ - case PS_SUSPENDED: - /* - * Dead and suspended threads are not placed - * in any queue: - */ - break; - - case PS_RUNNING: - /* - * Runnable threads can't be placed in the - * priority queue until after waiting threads - * are polled (to preserve round-robin - * scheduling). - */ - add_to_prioq = 1; - break; - - /* - * States which do not depend on file descriptor I/O - * operations or timeouts: - */ - case PS_DEADLOCK: - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - case PS_JOIN: - case PS_MUTEX_WAIT: - case PS_SIGSUSPEND: - case PS_SIGTHREAD: - case PS_SIGWAIT: - case PS_WAIT_WAIT: - /* No timeouts for these states: */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - break; - - /* States which can timeout: */ - case PS_COND_WAIT: - case PS_SLEEP_WAIT: - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - break; - - /* States that require periodic work: */ - case PS_SPINBLOCK: - /* No timeouts for this state: */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - - /* Increment spinblock count: */ - _spinblock_count++; - - /* FALLTHROUGH */ - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - - /* Insert into the work queue: */ - PTHREAD_WORKQ_INSERT(curthread); - break; - } - - /* - * Are there pending signals for this thread? - * - * This check has to be performed after the thread - * has been placed in the queue(s) appropriate for - * its state. The process of adding pending signals - * can change a threads state, which in turn will - * attempt to add or remove the thread from any - * scheduling queue to which it belongs. - */ - if (curthread->check_pending != 0) { - curthread->check_pending = 0; - _thread_sig_check_pending(curthread); - } - } - - /* - * Avoid polling file descriptors if there are none - * waiting: - */ - if (TAILQ_EMPTY(&_workq) != 0) { - } - /* - * Poll file descriptors only if a new scheduling signal - * has occurred or if we have no more runnable threads. - */ - else if (((current_tick = _sched_ticks) != last_tick) || - ((curthread->state != PS_RUNNING) && - (PTHREAD_PRIOQ_FIRST() == NULL))) { - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * Poll file descriptors to update the state of threads - * waiting on file I/O where data may be available: - */ - thread_kern_poll(0); - - /* Protect the scheduling queues: */ - _queue_signals = 1; - } - last_tick = current_tick; - - /* - * Wake up threads that have timedout. This has to be - * done after polling in case a thread does a poll or - * select with zero time. - */ - PTHREAD_WAITQ_SETACTIVE(); - while (((pthread = TAILQ_FIRST(&_waitingq)) != NULL) && - (pthread->wakeup_time.tv_sec != -1) && - (((pthread->wakeup_time.tv_sec == 0) && - (pthread->wakeup_time.tv_nsec == 0)) || - (pthread->wakeup_time.tv_sec < ts.tv_sec) || - ((pthread->wakeup_time.tv_sec == ts.tv_sec) && - (pthread->wakeup_time.tv_nsec <= ts.tv_nsec)))) { - switch (pthread->state) { - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Return zero file descriptors ready: */ - pthread->data.poll_data->nfds = 0; - /* FALLTHROUGH */ - default: - /* - * Remove this thread from the waiting queue - * (and work queue if necessary) and place it - * in the ready queue. - */ - PTHREAD_WAITQ_CLEARACTIVE(); - if (pthread->flags & PTHREAD_FLAGS_IN_WORKQ) - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - break; - } - /* - * Flag the timeout in the thread structure: - */ - pthread->timeout = 1; - } - PTHREAD_WAITQ_CLEARACTIVE(); - - /* - * Check to see if the current thread needs to be added - * to the priority queue: - */ - if (add_to_prioq != 0) { - /* - * Save the current time as the time that the - * thread became inactive: - */ - current_tick = _sched_ticks; - curthread->last_inactive = (long)current_tick; - if (curthread->last_inactive < - curthread->last_active) { - /* Account for a rollover: */ - curthread->last_inactive =+ UINT_MAX + 1; - } - - if ((curthread->slice_usec != -1) && - (curthread->attr.sched_policy != SCHED_FIFO)) { - /* - * Accumulate the number of microseconds for - * which the current thread has run: - */ - curthread->slice_usec += - (curthread->last_inactive - - curthread->last_active) * - (long)_clock_res_usec; - /* Check for time quantum exceeded: */ - if (curthread->slice_usec > TIMESLICE_USEC) - curthread->slice_usec = -1; - } - - if (curthread->slice_usec == -1) { - /* - * The thread exceeded its time - * quantum or it yielded the CPU; - * place it at the tail of the - * queue for its priority. - */ - PTHREAD_PRIOQ_INSERT_TAIL(curthread); - } else { - /* - * The thread hasn't exceeded its - * interval. Place it at the head - * of the queue for its priority. - */ - PTHREAD_PRIOQ_INSERT_HEAD(curthread); - } - } - - /* - * Get the highest priority thread in the ready queue. - */ - pthread_h = PTHREAD_PRIOQ_FIRST(); - - /* Check if there are no threads ready to run: */ - if (pthread_h == NULL) { - /* - * Lock the pthread kernel by changing the pointer to - * the running thread to point to the global kernel - * thread structure: - */ - _set_curthread(&_thread_kern_thread); - curthread = &_thread_kern_thread; - - DBG_MSG("No runnable threads, using kernel thread %p\n", - curthread); - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * There are no threads ready to run, so wait until - * something happens that changes this condition: - */ - thread_kern_poll(1); - - /* - * This process' usage will likely be very small - * while waiting in a poll. Since the scheduling - * clock is based on the profiling timer, it is - * unlikely that the profiling timer will fire - * and update the time of day. To account for this, - * get the time of day after polling with a timeout. - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - - /* Check once more for a runnable thread: */ - _queue_signals = 1; - pthread_h = PTHREAD_PRIOQ_FIRST(); - _queue_signals = 0; - } - - if (pthread_h != NULL) { - /* Remove the thread from the ready queue: */ - PTHREAD_PRIOQ_REMOVE(pthread_h); - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * Check for signals queued while the scheduling - * queues were protected: - */ - while (_sigq_check_reqd != 0) { - /* Clear before handling queued signals: */ - _sigq_check_reqd = 0; - - /* Protect the scheduling queues again: */ - _queue_signals = 1; - - dequeue_signals(); - - /* - * Check for a higher priority thread that - * became runnable due to signal handling. - */ - if (((pthread = PTHREAD_PRIOQ_FIRST()) != NULL) && - (pthread->active_priority > pthread_h->active_priority)) { - /* Remove the thread from the ready queue: */ - PTHREAD_PRIOQ_REMOVE(pthread); - - /* - * Insert the lower priority thread - * at the head of its priority list: - */ - PTHREAD_PRIOQ_INSERT_HEAD(pthread_h); - - /* There's a new thread in town: */ - pthread_h = pthread; - } - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - } - - /* Make the selected thread the current thread: */ - _set_curthread(pthread_h); - curthread = pthread_h; - - /* - * Save the current time as the time that the thread - * became active: - */ - current_tick = _sched_ticks; - curthread->last_active = (long) current_tick; - - /* - * Check if this thread is running for the first time - * or running again after using its full time slice - * allocation: - */ - if (curthread->slice_usec == -1) { - /* Reset the accumulated time slice period: */ - curthread->slice_usec = 0; - } - - /* - * If we had a context switch, run any - * installed switch hooks. - */ - if ((_sched_switch_hook != NULL) && - (_last_user_thread != curthread)) { - thread_run_switch_hook(_last_user_thread, - curthread); - } - /* - * Continue the thread at its current frame: - */ -#if NOT_YET - _setcontext(&curthread->ctx.uc); -#else - ___longjmp(curthread->ctx.jb, 1); -#endif - /* This point should not be reached. */ - PANIC("Thread has returned from sigreturn or longjmp"); - } - } - - /* There are no more threads, so exit this process: */ - exit(0); -} - -void -_thread_kern_sched_state(enum pthread_state state, char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* - * Prevent the signal handler from fiddling with this thread - * before its state is set and is placed into the proper queue. - */ - _queue_signals = 1; - - /* Change the state of the current thread: */ - curthread->state = state; - curthread->fname = fname; - curthread->lineno = lineno; - - /* Schedule the next thread that is ready: */ - _thread_kern_sched(NULL); -} - -void -_thread_kern_sched_state_unlock(enum pthread_state state, - spinlock_t *lock, char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* - * Prevent the signal handler from fiddling with this thread - * before its state is set and it is placed into the proper - * queue(s). - */ - _queue_signals = 1; - - /* Change the state of the current thread: */ - curthread->state = state; - curthread->fname = fname; - curthread->lineno = lineno; - - _SPINUNLOCK(lock); - - /* Schedule the next thread that is ready: */ - _thread_kern_sched(NULL); -} - -static void -thread_kern_poll(int wait_reqd) -{ - int count = 0; - int i, found; - int kern_pipe_added = 0; - int nfds = 0; - int timeout_ms = 0; - struct pthread *pthread; - struct timespec ts; - struct timeval tv; - - /* Check if the caller wants to wait: */ - if (wait_reqd == 0) { - timeout_ms = 0; - } - else { - /* Get the current time of day: */ - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, &ts); - - _queue_signals = 1; - pthread = TAILQ_FIRST(&_waitingq); - _queue_signals = 0; - - if ((pthread == NULL) || (pthread->wakeup_time.tv_sec == -1)) { - /* - * Either there are no threads in the waiting queue, - * or there are no threads that can timeout. - */ - timeout_ms = INFTIM; - } - else if (pthread->wakeup_time.tv_sec - ts.tv_sec > 60000) - /* Limit maximum timeout to prevent rollover. */ - timeout_ms = 60000; - else { - /* - * Calculate the time left for the next thread to - * timeout: - */ - timeout_ms = ((pthread->wakeup_time.tv_sec - ts.tv_sec) * - 1000) + ((pthread->wakeup_time.tv_nsec - ts.tv_nsec) / - 1000000); - /* - * Don't allow negative timeouts: - */ - if (timeout_ms < 0) - timeout_ms = 0; - } - } - - /* Protect the scheduling queues: */ - _queue_signals = 1; - - /* - * Check to see if the signal queue needs to be walked to look - * for threads awoken by a signal while in the scheduler. - */ - if (_sigq_check_reqd != 0) { - /* Reset flag before handling queued signals: */ - _sigq_check_reqd = 0; - - dequeue_signals(); - } - - /* - * Check for a thread that became runnable due to a signal: - */ - if (PTHREAD_PRIOQ_FIRST() != NULL) { - /* - * Since there is at least one runnable thread, - * disable the wait. - */ - timeout_ms = 0; - } - - /* - * Form the poll table: - */ - nfds = 0; - if (timeout_ms != 0) { - /* Add the kernel pipe to the poll table: */ - _thread_pfd_table[nfds].fd = _thread_kern_pipe[0]; - _thread_pfd_table[nfds].events = POLLRDNORM; - _thread_pfd_table[nfds].revents = 0; - nfds++; - kern_pipe_added = 1; - } - - PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { - switch (pthread->state) { - case PS_SPINBLOCK: - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - /* One less thread in a spinblock state: */ - _spinblock_count--; - /* - * Since there is at least one runnable - * thread, disable the wait. - */ - timeout_ms = 0; - } - break; - - /* File descriptor read wait: */ - case PS_FDR_WAIT: - /* Limit number of polled files to table size: */ - if (nfds < _thread_dtablesize) { - _thread_pfd_table[nfds].events = POLLRDNORM; - _thread_pfd_table[nfds].fd = pthread->data.fd.fd; - nfds++; - } - break; - - /* File descriptor write wait: */ - case PS_FDW_WAIT: - /* Limit number of polled files to table size: */ - if (nfds < _thread_dtablesize) { - _thread_pfd_table[nfds].events = POLLWRNORM; - _thread_pfd_table[nfds].fd = pthread->data.fd.fd; - nfds++; - } - break; - - /* File descriptor poll or select wait: */ - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Limit number of polled files to table size: */ - if (pthread->data.poll_data->nfds + nfds < - _thread_dtablesize) { - for (i = 0; i < pthread->data.poll_data->nfds; i++) { - _thread_pfd_table[nfds + i].fd = - pthread->data.poll_data->fds[i].fd; - _thread_pfd_table[nfds + i].events = - pthread->data.poll_data->fds[i].events; - } - nfds += pthread->data.poll_data->nfds; - } - break; - - /* Other states do not depend on file I/O. */ - default: - break; - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - - /* - * Wait for a file descriptor to be ready for read, write, or - * an exception, or a timeout to occur: - */ - count = __sys_poll(_thread_pfd_table, nfds, timeout_ms); - - if (kern_pipe_added != 0) - /* - * Remove the pthread kernel pipe file descriptor - * from the pollfd table: - */ - nfds = 1; - else - nfds = 0; - - /* - * Check if it is possible that there are bytes in the kernel - * read pipe waiting to be read: - */ - if (count < 0 || ((kern_pipe_added != 0) && - (_thread_pfd_table[0].revents & POLLRDNORM))) { - /* - * If the kernel read pipe was included in the - * count: - */ - if (count > 0) { - /* Decrement the count of file descriptors: */ - count--; - } - - if (_sigq_check_reqd != 0) { - /* Reset flag before handling signals: */ - _sigq_check_reqd = 0; - - dequeue_signals(); - } - } - - /* - * Check if any file descriptors are ready: - */ - if (count > 0) { - /* - * Enter a loop to look for threads waiting on file - * descriptors that are flagged as available by the - * _poll syscall: - */ - PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { - switch (pthread->state) { - case PS_SPINBLOCK: - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - - /* - * One less thread in a spinblock state: - */ - _spinblock_count--; - } - break; - - /* File descriptor read wait: */ - case PS_FDR_WAIT: - if ((nfds < _thread_dtablesize) && - (_thread_pfd_table[nfds].revents - & (POLLRDNORM|POLLERR|POLLHUP|POLLNVAL)) - != 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - nfds++; - break; - - /* File descriptor write wait: */ - case PS_FDW_WAIT: - if ((nfds < _thread_dtablesize) && - (_thread_pfd_table[nfds].revents - & (POLLWRNORM|POLLERR|POLLHUP|POLLNVAL)) - != 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - nfds++; - break; - - /* File descriptor poll or select wait: */ - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - if (pthread->data.poll_data->nfds + nfds < - _thread_dtablesize) { - /* - * Enter a loop looking for I/O - * readiness: - */ - found = 0; - for (i = 0; i < pthread->data.poll_data->nfds; i++) { - if (_thread_pfd_table[nfds + i].revents != 0) { - pthread->data.poll_data->fds[i].revents = - _thread_pfd_table[nfds + i].revents; - found++; - } - } - - /* Increment before destroying: */ - nfds += pthread->data.poll_data->nfds; - - if (found != 0) { - pthread->data.poll_data->nfds = found; - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - } - else - nfds += pthread->data.poll_data->nfds; - break; - - /* Other states do not depend on file I/O. */ - default: - break; - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - } - else if (_spinblock_count != 0) { - /* - * Enter a loop to look for threads waiting on a spinlock - * that is now available. - */ - PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { - if (pthread->state == PS_SPINBLOCK) { - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - - /* - * One less thread in a spinblock state: - */ - _spinblock_count--; - } - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - } - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - while (_sigq_check_reqd != 0) { - /* Handle queued signals: */ - _sigq_check_reqd = 0; - - /* Protect the scheduling queues: */ - _queue_signals = 1; - - dequeue_signals(); - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - } -} - -void -_thread_kern_set_timeout(const struct timespec * timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec current_time; - struct timeval tv; - - /* Reset the timeout flag for the running thread: */ - curthread->timeout = 0; - - /* Check if the thread is to wait forever: */ - if (timeout == NULL) { - /* - * Set the wakeup time to something that can be recognised as - * different to an actual time of day: - */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - } - /* Check if no waiting is required: */ - else if (timeout->tv_sec == 0 && timeout->tv_nsec == 0) { - /* Set the wake up time to 'immediately': */ - curthread->wakeup_time.tv_sec = 0; - curthread->wakeup_time.tv_nsec = 0; - } else { - /* Get the current time: */ - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time); - - /* Calculate the time for the current thread to wake up: */ - curthread->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec; - curthread->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec; - - /* Check if the nanosecond field needs to wrap: */ - if (curthread->wakeup_time.tv_nsec >= 1000000000) { - /* Wrap the nanosecond field: */ - curthread->wakeup_time.tv_sec += 1; - curthread->wakeup_time.tv_nsec -= 1000000000; - } - } -} - -void -_thread_kern_sig_defer(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Allow signal deferral to be recursive. */ - curthread->sig_defer_count++; -} - -void -_thread_kern_sig_undefer(void) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Perform checks to yield only if we are about to undefer - * signals. - */ - if (curthread->sig_defer_count > 1) { - /* Decrement the signal deferral count. */ - curthread->sig_defer_count--; - } - else if (curthread->sig_defer_count == 1) { - /* Reenable signals: */ - curthread->sig_defer_count = 0; - - /* - * Check if there are queued signals: - */ - if (_sigq_check_reqd != 0) - _thread_kern_sched(NULL); - - /* - * Check for asynchronous cancellation before delivering any - * pending signals: - */ - if (((curthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0) && - ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)) - pthread_testcancel(); - - /* - * If there are pending signals or this thread has - * to yield the CPU, call the kernel scheduler: - * - * XXX - Come back and revisit the pending signal problem - */ - if ((curthread->yield_on_sig_undefer != 0) || - SIGNOTEMPTY(curthread->sigpend)) { - curthread->yield_on_sig_undefer = 0; - _thread_kern_sched(NULL); - } - } -} - -static void -dequeue_signals(void) -{ - char bufr[128]; - int num; - - /* - * Enter a loop to clear the pthread kernel pipe: - */ - while (((num = __sys_read(_thread_kern_pipe[0], bufr, - sizeof(bufr))) > 0) || (num == -1 && errno == EINTR)) { - } - if ((num < 0) && (errno != EAGAIN)) { - /* - * The only error we should expect is if there is - * no data to read. - */ - PANIC("Unable to read from thread kernel pipe"); - } - /* Handle any pending signals: */ - _thread_sig_handle_pending(); -} - -static inline void -thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in) -{ - pthread_t tid_out = thread_out; - pthread_t tid_in = thread_in; - - if ((tid_out != NULL) && - (tid_out->flags & PTHREAD_FLAGS_PRIVATE) != 0) - tid_out = NULL; - if ((tid_in != NULL) && - (tid_in->flags & PTHREAD_FLAGS_PRIVATE) != 0) - tid_in = NULL; - - if ((_sched_switch_hook != NULL) && (tid_out != tid_in)) { - /* Run the scheduler switch hook: */ - _sched_switch_hook(tid_out, tid_in); - } -} - -struct pthread * -_get_curthread(void) -{ - if (_thread_initial == NULL) - _thread_init(); - - return (_thread_run); -} - -void -_set_curthread(struct pthread *newthread) -{ - _thread_run = newthread; -} diff --git a/lib/libc_r/uthread/uthread_kevent.c b/lib/libc_r/uthread/uthread_kevent.c deleted file mode 100644 index 17aeaea..0000000 --- a/lib/libc_r/uthread/uthread_kevent.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * Copyright (c) 2000 Jonathan Lemon <jlemon@flugsvamp.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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <unistd.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/event.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_kevent, kevent); - -int -_kevent(int kq, const struct kevent *changelist, int nchanges, - struct kevent *eventlist, int nevents, const struct timespec *timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec nullts = { 0, 0 }; - int rc; - - /* Set the wake up time */ - _thread_kern_set_timeout(timeout); - - rc = __sys_kevent(kq, changelist, nchanges, - eventlist, nevents, &nullts); - if (rc == 0 && eventlist != NULL && nevents > 0 && (timeout == NULL || - timeout->tv_sec != 0 || timeout->tv_nsec != 0)) { - /* Save the socket file descriptor: */ - curthread->data.fd.fd = kq; - curthread->data.fd.fname = __FILE__; - curthread->data.fd.branch = __LINE__; - - do { - /* Reset the interrupted and timeout flags: */ - curthread->interrupted = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_FDR_WAIT, - __FILE__, __LINE__); - - if (curthread->interrupted) { - errno = EINTR; - rc = -1; - break; - } - rc = __sys_kevent(kq, NULL, 0, - eventlist, nevents, &nullts); - } while (rc == 0 && curthread->timeout == 0); - } - return (rc); -} diff --git a/lib/libc_r/uthread/uthread_kill.c b/lib/libc_r/uthread/uthread_kill.c deleted file mode 100644 index 985ba0c..0000000 --- a/lib/libc_r/uthread/uthread_kill.c +++ /dev/null @@ -1,71 +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 <signal.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_kill, pthread_kill); - -int -_pthread_kill(pthread_t pthread, int sig) -{ - int ret; - - /* Check for invalid signal numbers: */ - if (sig < 0 || sig >= NSIG) - /* Invalid signal: */ - ret = EINVAL; - /* - * Ensure the thread is in the list of active threads, and the - * signal is valid (signal 0 specifies error checking only) and - * not being ignored: - */ - else if (((ret = _find_thread(pthread)) == 0) && (sig > 0) && - (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - _thread_sig_send(pthread, sig); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_kqueue.c b/lib/libc_r/uthread/uthread_kqueue.c deleted file mode 100644 index 15aceb0..0000000 --- a/lib/libc_r/uthread/uthread_kqueue.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003 Mark Peek <mp@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 <sys/types.h> -#include <sys/event.h> -#include <fcntl.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_kqueue, kqueue); - -int -_kqueue(void) -{ - int fd; - - /* Create a kqueue: */ - if ((fd = __sys_kqueue()) < 0) { - /* Error creating socket. */ - - /* Initialise the entry in the file descriptor table: */ - } else if (_thread_fd_table_init(fd) != 0) { - __sys_close(fd); - fd = -1; - } - return (fd); -} diff --git a/lib/libc_r/uthread/uthread_listen.c b/lib/libc_r/uthread/uthread_listen.c deleted file mode 100644 index 600a4cb..0000000 --- a/lib/libc_r/uthread/uthread_listen.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_listen, listen); - -int -_listen(int fd, int backlog) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_listen(fd, backlog); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} - diff --git a/lib/libc_r/uthread/uthread_main_np.c b/lib/libc_r/uthread/uthread_main_np.c deleted file mode 100644 index 1c9c30b..0000000 --- a/lib/libc_r/uthread/uthread_main_np.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2001 Alfred Perlstein - * Author: Alfred Perlstein <alfred@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 <pthread.h> -#include <pthread_np.h> -#include "pthread_private.h" - -__weak_reference(_pthread_main_np, pthread_main_np); - -/* - * Provide the equivalent to Solaris thr_main() function - */ -int -_pthread_main_np() -{ - - if (!_thread_initial) - return (-1); - else - return (pthread_equal(pthread_self(), _thread_initial) ? 1 : 0); -} diff --git a/lib/libc_r/uthread/uthread_mattr_init.c b/lib/libc_r/uthread/uthread_mattr_init.c deleted file mode 100644 index 5c1fb6f..0000000 --- a/lib/libc_r/uthread/uthread_mattr_init.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1996 Jeffrey Hsu <hsu@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 Jeffrey Hsu. - * 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 JEFFREY HSU 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_mutexattr_init, pthread_mutexattr_init); - -static struct pthread_mutex_attr default_mutexattr = PTHREAD_MUTEXATTR_DEFAULT; - -int -_pthread_mutexattr_init(pthread_mutexattr_t *attr) -{ - int ret; - pthread_mutexattr_t pattr; - - if ((pattr = (pthread_mutexattr_t) - malloc(sizeof(struct pthread_mutex_attr))) == NULL) { - ret = ENOMEM; - } else { - memcpy(pattr, &default_mutexattr, - sizeof(struct pthread_mutex_attr)); - *attr = pattr; - ret = 0; - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_mattr_kind_np.c b/lib/libc_r/uthread/uthread_mattr_kind_np.c deleted file mode 100644 index 08fb0db..0000000 --- a/lib/libc_r/uthread/uthread_mattr_kind_np.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1996 Jeffrey Hsu <hsu@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 Jeffrey Hsu. - * 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 JEFFREY HSU 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_mutexattr_setkind_np, pthread_mutexattr_setkind_np); -__weak_reference(_pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np); -__weak_reference(_pthread_mutexattr_gettype, pthread_mutexattr_gettype); -__weak_reference(_pthread_mutexattr_settype, pthread_mutexattr_settype); - -int -_pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind) -{ - int ret; - if (attr == NULL || *attr == NULL) { - errno = EINVAL; - ret = -1; - } else { - (*attr)->m_type = kind; - ret = 0; - } - return(ret); -} - -int -_pthread_mutexattr_getkind_np(pthread_mutexattr_t attr) -{ - int ret; - if (attr == NULL) { - errno = EINVAL; - ret = -1; - } else { - ret = attr->m_type; - } - return(ret); -} - -int -_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) -{ - int ret; - if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) { - errno = EINVAL; - ret = -1; - } else { - (*attr)->m_type = type; - ret = 0; - } - return(ret); -} - -int -_pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type) -{ - int ret; - - if (attr == NULL || *attr == NULL || (*attr)->m_type >= - PTHREAD_MUTEX_TYPE_MAX) { - ret = EINVAL; - } else { - *type = (*attr)->m_type; - ret = 0; - } - return ret; -} diff --git a/lib/libc_r/uthread/uthread_msync.c b/lib/libc_r/uthread/uthread_msync.c deleted file mode 100644 index 24cbaa6..0000000 --- a/lib/libc_r/uthread/uthread_msync.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * David Leonard <d@openbsd.org>, 1999. Public Domain. - * - * $OpenBSD: uthread_msync.c,v 1.2 1999/06/09 07:16:17 d Exp $ - * - * $FreeBSD$ - */ - -#include <sys/types.h> -#include <sys/mman.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__msync, msync); - -int -_msync(void *addr, size_t len, int flags) -{ - int ret; - - ret = __sys_msync(addr, len, flags); - - return (ret); -} - -int -__msync(void *addr, size_t len, int flags) -{ - int ret; - - /* - * XXX This is quite pointless unless we know how to get the - * file descriptor associated with the memory, and lock it for - * write. The only real use of this wrapper is to guarantee - * a cancellation point, as per the standard. sigh. - */ - _thread_enter_cancellation_point(); - ret = _msync(addr, len, flags); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_multi_np.c b/lib/libc_r/uthread/uthread_multi_np.c deleted file mode 100644 index 99b6df3..0000000 --- a/lib/libc_r/uthread/uthread_multi_np.c +++ /dev/null @@ -1,47 +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 <pthread.h> -#include <pthread_np.h> - -__weak_reference(_pthread_multi_np, pthread_multi_np); - -int -_pthread_multi_np() -{ - - /* Return to multi-threaded scheduling mode: */ - /* - * XXX - Do we want to do this? - * __is_threaded = 1; - */ - pthread_resume_all_np(); - return (0); -} diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c deleted file mode 100644 index 47fd7f6..0000000 --- a/lib/libc_r/uthread/uthread_mutex.c +++ /dev/null @@ -1,1542 +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 <sys/param.h> -#include <sys/queue.h> -#include <pthread.h> -#include "pthread_private.h" - -#if defined(_PTHREADS_INVARIANTS) -#define _MUTEX_INIT_LINK(m) do { \ - (m)->m_qe.tqe_prev = NULL; \ - (m)->m_qe.tqe_next = NULL; \ -} while (0) -#define _MUTEX_ASSERT_IS_OWNED(m) do { \ - if ((m)->m_qe.tqe_prev == NULL) \ - PANIC("mutex is not on list"); \ -} while (0) -#define _MUTEX_ASSERT_NOT_OWNED(m) do { \ - if (((m)->m_qe.tqe_prev != NULL) || \ - ((m)->m_qe.tqe_next != NULL)) \ - PANIC("mutex is on list"); \ -} while (0) -#else -#define _MUTEX_INIT_LINK(m) -#define _MUTEX_ASSERT_IS_OWNED(m) -#define _MUTEX_ASSERT_NOT_OWNED(m) -#endif - -/* - * Prototypes - */ -static inline int mutex_self_trylock(pthread_mutex_t); -static inline int mutex_self_lock(pthread_mutex_t); -static inline int mutex_unlock_common(pthread_mutex_t *, int); -static void mutex_priority_adjust(pthread_mutex_t); -static void mutex_rescan_owned (pthread_t, pthread_mutex_t); -static inline pthread_t mutex_queue_deq(pthread_mutex_t); -static inline void mutex_queue_remove(pthread_mutex_t, pthread_t); -static inline void mutex_queue_enq(pthread_mutex_t, pthread_t); - - -static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER; - -static struct pthread_mutex_attr static_mutex_attr = - PTHREAD_MUTEXATTR_STATIC_INITIALIZER; -static pthread_mutexattr_t static_mattr = &static_mutex_attr; - -/* Single underscore versions provided for libc internal usage: */ -__weak_reference(__pthread_mutex_trylock, pthread_mutex_trylock); -__weak_reference(__pthread_mutex_lock, pthread_mutex_lock); - -/* No difference between libc and application usage of these: */ -__weak_reference(_pthread_mutex_init, pthread_mutex_init); -__weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy); -__weak_reference(_pthread_mutex_unlock, pthread_mutex_unlock); - - -/* - * Reinitialize a private mutex; this is only used for internal mutexes. - */ -int -_mutex_reinit(pthread_mutex_t * mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - else if (*mutex == NULL) - ret = _pthread_mutex_init(mutex, NULL); - else { - /* - * Initialize the mutex structure: - */ - (*mutex)->m_type = PTHREAD_MUTEX_DEFAULT; - (*mutex)->m_protocol = PTHREAD_PRIO_NONE; - TAILQ_INIT(&(*mutex)->m_queue); - (*mutex)->m_owner = NULL; - (*mutex)->m_data.m_count = 0; - (*mutex)->m_flags |= MUTEX_FLAGS_INITED | MUTEX_FLAGS_PRIVATE; - (*mutex)->m_refcount = 0; - (*mutex)->m_prio = 0; - (*mutex)->m_saved_prio = 0; - _MUTEX_INIT_LINK(*mutex); - memset(&(*mutex)->lock, 0, sizeof((*mutex)->lock)); - } - return (ret); -} - -int -_pthread_mutex_init(pthread_mutex_t * mutex, - const pthread_mutexattr_t * mutex_attr) -{ - enum pthread_mutextype type; - int protocol; - int ceiling; - int flags; - pthread_mutex_t pmutex; - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* Check if default mutex attributes: */ - if (mutex_attr == NULL || *mutex_attr == NULL) { - /* Default to a (error checking) POSIX mutex: */ - type = PTHREAD_MUTEX_ERRORCHECK; - protocol = PTHREAD_PRIO_NONE; - ceiling = PTHREAD_MAX_PRIORITY; - flags = 0; - } - - /* Check mutex type: */ - else if (((*mutex_attr)->m_type < PTHREAD_MUTEX_ERRORCHECK) || - ((*mutex_attr)->m_type >= PTHREAD_MUTEX_TYPE_MAX)) - /* Return an invalid argument error: */ - ret = EINVAL; - - /* Check mutex protocol: */ - else if (((*mutex_attr)->m_protocol < PTHREAD_PRIO_NONE) || - ((*mutex_attr)->m_protocol > PTHREAD_MUTEX_RECURSIVE)) - /* Return an invalid argument error: */ - ret = EINVAL; - - else { - /* Use the requested mutex type and protocol: */ - type = (*mutex_attr)->m_type; - protocol = (*mutex_attr)->m_protocol; - ceiling = (*mutex_attr)->m_ceiling; - flags = (*mutex_attr)->m_flags; - } - - /* Check no errors so far: */ - if (ret == 0) { - if ((pmutex = (pthread_mutex_t) - malloc(sizeof(struct pthread_mutex))) == NULL) - ret = ENOMEM; - else { - /* Set the mutex flags: */ - pmutex->m_flags = flags; - - /* Process according to mutex type: */ - switch (type) { - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - case PTHREAD_MUTEX_NORMAL: - /* Nothing to do here. */ - break; - - /* Single UNIX Spec 2 recursive mutex: */ - case PTHREAD_MUTEX_RECURSIVE: - /* Reset the mutex count: */ - pmutex->m_data.m_count = 0; - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - if (ret == 0) { - /* Initialise the rest of the mutex: */ - TAILQ_INIT(&pmutex->m_queue); - pmutex->m_flags |= MUTEX_FLAGS_INITED; - pmutex->m_owner = NULL; - pmutex->m_type = type; - pmutex->m_protocol = protocol; - pmutex->m_refcount = 0; - if (protocol == PTHREAD_PRIO_PROTECT) - pmutex->m_prio = ceiling; - else - pmutex->m_prio = 0; - pmutex->m_saved_prio = 0; - _MUTEX_INIT_LINK(pmutex); - memset(&pmutex->lock, 0, sizeof(pmutex->lock)); - *mutex = pmutex; - } else { - free(pmutex); - *mutex = NULL; - } - } - } - /* Return the completion status: */ - return (ret); -} - -int -_pthread_mutex_destroy(pthread_mutex_t * mutex) -{ - int ret = 0; - - if (mutex == NULL || *mutex == NULL) - ret = EINVAL; - else { - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * Check to see if this mutex is in use: - */ - if (((*mutex)->m_owner != NULL) || - (TAILQ_FIRST(&(*mutex)->m_queue) != NULL) || - ((*mutex)->m_refcount != 0)) { - ret = EBUSY; - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - } - else { - /* - * Free the memory allocated for the mutex - * structure: - */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - free(*mutex); - - /* - * Leave the caller's pointer NULL now that - * the mutex has been destroyed: - */ - *mutex = NULL; - } - } - - /* Return the completion status: */ - return (ret); -} - -static int -init_static(pthread_mutex_t *mutex) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = _pthread_mutex_init(mutex, NULL); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return (ret); -} - -static int -init_static_private(pthread_mutex_t *mutex) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = _pthread_mutex_init(mutex, &static_mattr); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return (ret); -} - -static int -mutex_trylock_common(pthread_mutex_t *mutex) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL), - "Uninitialized mutex in pthread_mutex_trylock_basic"); - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * If the mutex was statically allocated, properly - * initialize the tail queue. - */ - if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*mutex)->m_queue); - _MUTEX_INIT_LINK(*mutex); - (*mutex)->m_flags |= MUTEX_FLAGS_INITED; - } - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The mutex takes on the attributes of the - * running thread when there are no waiters. - */ - (*mutex)->m_prio = curthread->active_priority; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* POSIX priority protection mutex: */ - case PTHREAD_PRIO_PROTECT: - /* Check for a priority ceiling violation: */ - if (curthread->active_priority > (*mutex)->m_prio) - ret = EINVAL; - - /* Check if this mutex is not locked: */ - else if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The running thread inherits the ceiling - * priority of the mutex and executes at that - * priority. - */ - curthread->active_priority = (*mutex)->m_prio; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - - /* Return the completion status: */ - return (ret); -} - -int -__pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - else if ((*mutex != NULL) || (ret = init_static(mutex)) == 0) - ret = mutex_trylock_common(mutex); - - return (ret); -} - -int -_pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization marking the mutex private (delete safe): - */ - else if ((*mutex != NULL) || (ret = init_static_private(mutex)) == 0) - ret = mutex_trylock_common(mutex); - - return (ret); -} - -static int -mutex_lock_common(pthread_mutex_t * mutex) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL), - "Uninitialized mutex in pthread_mutex_trylock_basic"); - - /* Reset the interrupted flag: */ - curthread->interrupted = 0; - - /* - * Enter a loop waiting to become the mutex owner. We need a - * loop 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 { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * If the mutex was statically allocated, properly - * initialize the tail queue. - */ - if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*mutex)->m_queue); - (*mutex)->m_flags |= MUTEX_FLAGS_INITED; - _MUTEX_INIT_LINK(*mutex); - } - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for this thread: */ - (*mutex)->m_owner = curthread; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - } - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for this thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The mutex takes on attributes of the - * running thread when there are no waiters. - */ - (*mutex)->m_prio = curthread->active_priority; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - if (curthread->active_priority > - (*mutex)->m_prio) - /* Adjust priorities: */ - mutex_priority_adjust(*mutex); - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - } - break; - - /* POSIX priority protection mutex: */ - case PTHREAD_PRIO_PROTECT: - /* Check for a priority ceiling violation: */ - if (curthread->active_priority > (*mutex)->m_prio) - ret = EINVAL; - - /* Check if this mutex is not locked: */ - else if ((*mutex)->m_owner == NULL) { - /* - * Lock the mutex for the running - * thread: - */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The running thread inherits the ceiling - * priority of the mutex and executes at that - * priority: - */ - curthread->active_priority = (*mutex)->m_prio; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - /* Clear any previous error: */ - curthread->error = 0; - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * The threads priority may have changed while - * waiting for the mutex causing a ceiling - * violation. - */ - ret = curthread->error; - curthread->error = 0; - } - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - /* - * Check to see if this thread was interrupted and - * is still in the mutex queue of waiting threads: - */ - if (curthread->interrupted != 0) - mutex_queue_remove(*mutex, curthread); - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } while (((*mutex)->m_owner != curthread) && (ret == 0) && - (curthread->interrupted == 0)); - - if (curthread->interrupted != 0 && - curthread->continuation != NULL) - curthread->continuation((void *) curthread); - - /* Return the completion status: */ - return (ret); -} - -int -__pthread_mutex_lock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (_thread_initial == NULL) - _thread_init(); - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0)) - ret = mutex_lock_common(mutex); - - return (ret); -} - -int -_pthread_mutex_lock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (_thread_initial == NULL) - _thread_init(); - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization marking it private (delete safe): - */ - else if ((*mutex != NULL) || ((ret = init_static_private(mutex)) == 0)) - ret = mutex_lock_common(mutex); - - return (ret); -} - -int -_pthread_mutex_unlock(pthread_mutex_t * mutex) -{ - return (mutex_unlock_common(mutex, /* add reference */ 0)); -} - -int -_mutex_cv_unlock(pthread_mutex_t * mutex) -{ - return (mutex_unlock_common(mutex, /* add reference */ 1)); -} - -int -_mutex_cv_lock(pthread_mutex_t * mutex) -{ - int ret; - if ((ret = _pthread_mutex_lock(mutex)) == 0) - (*mutex)->m_refcount--; - return (ret); -} - -static inline int -mutex_self_trylock(pthread_mutex_t mutex) -{ - int ret = 0; - - switch (mutex->m_type) { - - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - case PTHREAD_MUTEX_NORMAL: - /* - * POSIX specifies that mutexes should return EDEADLK if a - * recursive lock is detected. - */ - ret = EBUSY; - break; - - case PTHREAD_MUTEX_RECURSIVE: - /* Increment the lock count: */ - mutex->m_data.m_count++; - break; - - default: - /* Trap invalid mutex types; */ - ret = EINVAL; - } - - return (ret); -} - -static inline int -mutex_self_lock(pthread_mutex_t mutex) -{ - int ret = 0; - - switch (mutex->m_type) { - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - /* - * POSIX specifies that mutexes should return EDEADLK if a - * recursive lock is detected. - */ - ret = EDEADLK; - break; - - case PTHREAD_MUTEX_NORMAL: - /* - * What SS2 define as a 'normal' mutex. Intentionally - * deadlock on attempts to get a lock you already own. - */ - _thread_kern_sched_state_unlock(PS_DEADLOCK, - &mutex->lock, __FILE__, __LINE__); - break; - - case PTHREAD_MUTEX_RECURSIVE: - /* Increment the lock count: */ - mutex->m_data.m_count++; - break; - - default: - /* Trap invalid mutex types; */ - ret = EINVAL; - } - - return (ret); -} - -static inline int -mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - if (mutex == NULL || *mutex == NULL) { - ret = EINVAL; - } else { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Get the next thread from the queue of - * threads waiting on the mutex: - */ - if (((*mutex)->m_owner = - mutex_queue_deq(*mutex)) != NULL) { - /* Make the new owner runnable: */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - - /* - * Add the mutex to the threads list of - * owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - } - } - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* - * Restore the threads inherited priority and - * recompute the active priority (being careful - * not to override changes in the threads base - * priority subsequent to locking the mutex). - */ - curthread->inherited_priority = - (*mutex)->m_saved_prio; - curthread->active_priority = - MAX(curthread->inherited_priority, - curthread->base_priority); - - /* - * This thread now owns one less priority mutex. - */ - curthread->priority_mutex_count--; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Get the next thread from the queue of threads - * waiting on the mutex: - */ - if (((*mutex)->m_owner = - mutex_queue_deq(*mutex)) == NULL) - /* This mutex has no priority. */ - (*mutex)->m_prio = 0; - else { - /* - * Track number of priority mutexes owned: - */ - (*mutex)->m_owner->priority_mutex_count++; - - /* - * Add the mutex to the threads list - * of owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - - /* - * Set the priority of the mutex. Since - * our waiting threads are in descending - * priority order, the priority of the - * mutex becomes the active priority of - * the thread we just dequeued. - */ - (*mutex)->m_prio = - (*mutex)->m_owner->active_priority; - - /* - * Save the owning threads inherited - * priority: - */ - (*mutex)->m_saved_prio = - (*mutex)->m_owner->inherited_priority; - - /* - * The owning threads inherited priority - * now becomes his active priority (the - * priority of the mutex). - */ - (*mutex)->m_owner->inherited_priority = - (*mutex)->m_prio; - - /* - * Make the new owner runnable: - */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - } - } - break; - - /* POSIX priority ceiling mutex: */ - case PTHREAD_PRIO_PROTECT: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* - * Restore the threads inherited priority and - * recompute the active priority (being careful - * not to override changes in the threads base - * priority subsequent to locking the mutex). - */ - curthread->inherited_priority = - (*mutex)->m_saved_prio; - curthread->active_priority = - MAX(curthread->inherited_priority, - curthread->base_priority); - - /* - * This thread now owns one less priority mutex. - */ - curthread->priority_mutex_count--; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Enter a loop to find a waiting thread whose - * active priority will not cause a ceiling - * violation: - */ - while ((((*mutex)->m_owner = - mutex_queue_deq(*mutex)) != NULL) && - ((*mutex)->m_owner->active_priority > - (*mutex)->m_prio)) { - /* - * Either the mutex ceiling priority - * been lowered and/or this threads - * priority has been raised subsequent - * to this thread being queued on the - * waiting list. - */ - (*mutex)->m_owner->error = EINVAL; - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - /* - * The thread is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - } - - /* Check for a new owner: */ - if ((*mutex)->m_owner != NULL) { - /* - * Track number of priority mutexes owned: - */ - (*mutex)->m_owner->priority_mutex_count++; - - /* - * Add the mutex to the threads list - * of owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - - /* - * Save the owning threads inherited - * priority: - */ - (*mutex)->m_saved_prio = - (*mutex)->m_owner->inherited_priority; - - /* - * The owning thread inherits the - * ceiling priority of the mutex and - * executes at that priority: - */ - (*mutex)->m_owner->inherited_priority = - (*mutex)->m_prio; - (*mutex)->m_owner->active_priority = - (*mutex)->m_prio; - - /* - * Make the new owner runnable: - */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - } - } - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - if ((ret == 0) && (add_reference != 0)) { - /* Increment the reference count: */ - (*mutex)->m_refcount++; - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (ret); -} - - -/* - * This function is called when a change in base priority occurs for - * a thread that is holding or waiting for a priority protection or - * inheritence mutex. A change in a threads base priority can effect - * changes to active priorities of other threads and to the ordering - * of mutex locking by waiting threads. - * - * This must be called while thread scheduling is deferred. - */ -void -_mutex_notify_priochange(pthread_t pthread) -{ - /* Adjust the priorites of any owned priority mutexes: */ - if (pthread->priority_mutex_count > 0) { - /* - * Rescan the mutexes owned by this thread and correct - * their priorities to account for this threads change - * in priority. This has the side effect of changing - * the threads active priority. - */ - mutex_rescan_owned(pthread, /* rescan all owned */ NULL); - } - - /* - * If this thread is waiting on a priority inheritence mutex, - * check for priority adjustments. A change in priority can - * also effect a ceiling violation(*) for a thread waiting on - * a priority protection mutex; we don't perform the check here - * as it is done in pthread_mutex_unlock. - * - * (*) It should be noted that a priority change to a thread - * _after_ taking and owning a priority ceiling mutex - * does not affect ownership of that mutex; the ceiling - * priority is only checked before mutex ownership occurs. - */ - if (pthread->state == PS_MUTEX_WAIT) { - /* Lock the mutex structure: */ - _SPINLOCK(&pthread->data.mutex->lock); - - /* - * Check to make sure this thread is still in the same state - * (the spinlock above can yield the CPU to another thread): - */ - if (pthread->state == PS_MUTEX_WAIT) { - /* - * Remove and reinsert this thread into the list of - * waiting threads to preserve decreasing priority - * order. - */ - mutex_queue_remove(pthread->data.mutex, pthread); - mutex_queue_enq(pthread->data.mutex, pthread); - - if (pthread->data.mutex->m_protocol == - PTHREAD_PRIO_INHERIT) { - /* Adjust priorities: */ - mutex_priority_adjust(pthread->data.mutex); - } - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&pthread->data.mutex->lock); - } -} - -/* - * Called when a new thread is added to the mutex waiting queue or - * when a threads priority changes that is already in the mutex - * waiting queue. - */ -static void -mutex_priority_adjust(pthread_mutex_t mutex) -{ - pthread_t pthread_next, pthread = mutex->m_owner; - int temp_prio; - pthread_mutex_t m = mutex; - - /* - * Calculate the mutex priority as the maximum of the highest - * active priority of any waiting threads and the owning threads - * active priority(*). - * - * (*) Because the owning threads current active priority may - * reflect priority inherited from this mutex (and the mutex - * priority may have changed) we must recalculate the active - * priority based on the threads saved inherited priority - * and its base priority. - */ - pthread_next = TAILQ_FIRST(&m->m_queue); /* should never be NULL */ - temp_prio = MAX(pthread_next->active_priority, - MAX(m->m_saved_prio, pthread->base_priority)); - - /* See if this mutex really needs adjusting: */ - if (temp_prio == m->m_prio) - /* No need to propagate the priority: */ - return; - - /* Set new priority of the mutex: */ - m->m_prio = temp_prio; - - while (m != NULL) { - /* - * Save the threads priority before rescanning the - * owned mutexes: - */ - temp_prio = pthread->active_priority; - - /* - * Fix the priorities for all the mutexes this thread has - * locked since taking this mutex. This also has a - * potential side-effect of changing the threads priority. - */ - mutex_rescan_owned(pthread, m); - - /* - * If the thread is currently waiting on a mutex, check - * to see if the threads new priority has affected the - * priority of the mutex. - */ - if ((temp_prio != pthread->active_priority) && - (pthread->state == PS_MUTEX_WAIT) && - (pthread->data.mutex->m_protocol == PTHREAD_PRIO_INHERIT)) { - /* Grab the mutex this thread is waiting on: */ - m = pthread->data.mutex; - - /* - * The priority for this thread has changed. Remove - * and reinsert this thread into the list of waiting - * threads to preserve decreasing priority order. - */ - mutex_queue_remove(m, pthread); - mutex_queue_enq(m, pthread); - - /* Grab the waiting thread with highest priority: */ - pthread_next = TAILQ_FIRST(&m->m_queue); - - /* - * Calculate the mutex priority as the maximum of the - * highest active priority of any waiting threads and - * the owning threads active priority. - */ - temp_prio = MAX(pthread_next->active_priority, - MAX(m->m_saved_prio, m->m_owner->base_priority)); - - if (temp_prio != m->m_prio) { - /* - * The priority needs to be propagated to the - * mutex this thread is waiting on and up to - * the owner of that mutex. - */ - m->m_prio = temp_prio; - pthread = m->m_owner; - } - else - /* We're done: */ - m = NULL; - - } - else - /* We're done: */ - m = NULL; - } -} - -static void -mutex_rescan_owned(pthread_t pthread, pthread_mutex_t mutex) -{ - int active_prio, inherited_prio; - pthread_mutex_t m; - pthread_t pthread_next; - - /* - * Start walking the mutexes the thread has taken since - * taking this mutex. - */ - if (mutex == NULL) { - /* - * A null mutex means start at the beginning of the owned - * mutex list. - */ - m = TAILQ_FIRST(&pthread->mutexq); - - /* There is no inherited priority yet. */ - inherited_prio = 0; - } - else { - /* - * The caller wants to start after a specific mutex. It - * is assumed that this mutex is a priority inheritence - * mutex and that its priority has been correctly - * calculated. - */ - m = TAILQ_NEXT(mutex, m_qe); - - /* Start inheriting priority from the specified mutex. */ - inherited_prio = mutex->m_prio; - } - active_prio = MAX(inherited_prio, pthread->base_priority); - - while (m != NULL) { - /* - * We only want to deal with priority inheritence - * mutexes. This might be optimized by only placing - * priority inheritence mutexes into the owned mutex - * list, but it may prove to be useful having all - * owned mutexes in this list. Consider a thread - * exiting while holding mutexes... - */ - if (m->m_protocol == PTHREAD_PRIO_INHERIT) { - /* - * Fix the owners saved (inherited) priority to - * reflect the priority of the previous mutex. - */ - m->m_saved_prio = inherited_prio; - - if ((pthread_next = TAILQ_FIRST(&m->m_queue)) != NULL) - /* Recalculate the priority of the mutex: */ - m->m_prio = MAX(active_prio, - pthread_next->active_priority); - else - m->m_prio = active_prio; - - /* Recalculate new inherited and active priorities: */ - inherited_prio = m->m_prio; - active_prio = MAX(m->m_prio, pthread->base_priority); - } - - /* Advance to the next mutex owned by this thread: */ - m = TAILQ_NEXT(m, m_qe); - } - - /* - * Fix the threads inherited priority and recalculate its - * active priority. - */ - pthread->inherited_priority = inherited_prio; - active_prio = MAX(inherited_prio, pthread->base_priority); - - if (active_prio != pthread->active_priority) { - /* - * If this thread is in the priority queue, it must be - * removed and reinserted for its new priority. - */ - if (pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) { - /* - * Remove the thread from the priority queue - * before changing its priority: - */ - PTHREAD_PRIOQ_REMOVE(pthread); - - /* - * POSIX states that if the priority is being - * lowered, the thread must be inserted at the - * head of the queue for its priority if it owns - * any priority protection or inheritence mutexes. - */ - if ((active_prio < pthread->active_priority) && - (pthread->priority_mutex_count > 0)) { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - - PTHREAD_PRIOQ_INSERT_HEAD(pthread); - } - else { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - - PTHREAD_PRIOQ_INSERT_TAIL(pthread); - } - } - else { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - } - } -} - -void -_mutex_unlock_private(pthread_t pthread) -{ - struct pthread_mutex *m, *m_next; - - for (m = TAILQ_FIRST(&pthread->mutexq); m != NULL; m = m_next) { - m_next = TAILQ_NEXT(m, m_qe); - if ((m->m_flags & MUTEX_FLAGS_PRIVATE) != 0) - _pthread_mutex_unlock(&m); - } -} - -void -_mutex_lock_backout(pthread_t pthread) -{ - struct pthread_mutex *mutex; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - if ((pthread->flags & PTHREAD_FLAGS_IN_MUTEXQ) != 0) { - mutex = pthread->data.mutex; - - /* Lock the mutex structure: */ - _SPINLOCK(&mutex->lock); - - mutex_queue_remove(mutex, pthread); - - /* This thread is no longer waiting for the mutex: */ - pthread->data.mutex = NULL; - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&mutex->lock); - - } - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); -} - -/* - * Dequeue a waiting thread from the head of a mutex queue in descending - * priority order. - */ -static inline pthread_t -mutex_queue_deq(pthread_mutex_t mutex) -{ - pthread_t pthread; - - while ((pthread = TAILQ_FIRST(&mutex->m_queue)) != NULL) { - TAILQ_REMOVE(&mutex->m_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_MUTEXQ; - - /* - * Only exit the loop if the thread hasn't been - * cancelled. - */ - if (pthread->interrupted == 0) - break; - } - - return (pthread); -} - -/* - * Remove a waiting thread from a mutex queue in descending priority order. - */ -static inline void -mutex_queue_remove(pthread_mutex_t mutex, pthread_t pthread) -{ - if ((pthread->flags & PTHREAD_FLAGS_IN_MUTEXQ) != 0) { - TAILQ_REMOVE(&mutex->m_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_MUTEXQ; - } -} - -/* - * Enqueue a waiting thread to a queue in descending priority order. - */ -static inline void -mutex_queue_enq(pthread_mutex_t mutex, pthread_t pthread) -{ - pthread_t tid = TAILQ_LAST(&mutex->m_queue, mutex_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(&mutex->m_queue, pthread, sqe); - else { - tid = TAILQ_FIRST(&mutex->m_queue); - while (pthread->active_priority <= tid->active_priority) - tid = TAILQ_NEXT(tid, sqe); - TAILQ_INSERT_BEFORE(tid, pthread, sqe); - } - pthread->flags |= PTHREAD_FLAGS_IN_MUTEXQ; -} - diff --git a/lib/libc_r/uthread/uthread_mutex_prioceiling.c b/lib/libc_r/uthread/uthread_mutex_prioceiling.c deleted file mode 100644 index eccc9e4..0000000 --- a/lib/libc_r/uthread/uthread_mutex_prioceiling.c +++ /dev/null @@ -1,115 +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 <string.h> -#include <stdlib.h> -#include <errno.h> -#include "namespace.h" -#include <pthread.h> -#include "un-namespace.h" -#include "pthread_private.h" - -__weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling); -__weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling); -__weak_reference(_pthread_mutex_getprioceiling, pthread_mutex_getprioceiling); -__weak_reference(_pthread_mutex_setprioceiling, pthread_mutex_setprioceiling); - -int -_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - *prioceiling = (*mattr)->m_ceiling; - - return(ret); -} - -int -_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - (*mattr)->m_ceiling = prioceiling; - - return(ret); -} - -int -_pthread_mutex_getprioceiling(pthread_mutex_t *mutex, - int *prioceiling) -{ - int ret; - - if ((mutex == NULL) || (*mutex == NULL)) - ret = EINVAL; - else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - ret = (*mutex)->m_prio; - - return(ret); -} - -int -_pthread_mutex_setprioceiling(pthread_mutex_t *mutex, - int prioceiling, int *old_ceiling) -{ - int ret = 0; - - if ((mutex == NULL) || (*mutex == NULL)) - ret = EINVAL; - else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else { - /* Lock the mutex: */ - if ((ret = _pthread_mutex_lock(mutex)) == 0) { - /* Return the old ceiling and set the new ceiling: */ - *old_ceiling = (*mutex)->m_prio; - (*mutex)->m_prio = prioceiling; - - /* Unlock the mutex: */ - ret = _pthread_mutex_unlock(mutex); - } - } - return(ret); -} diff --git a/lib/libc_r/uthread/uthread_mutex_protocol.c b/lib/libc_r/uthread/uthread_mutex_protocol.c deleted file mode 100644 index 4d020d6..0000000 --- a/lib/libc_r/uthread/uthread_mutex_protocol.c +++ /dev/null @@ -1,70 +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 <string.h> -#include <stdlib.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol); -__weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol); - -int -_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else - *protocol = (*mattr)->m_protocol; - - return(ret); -} - -int -_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL) || - (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT)) - ret = EINVAL; - else { - (*mattr)->m_protocol = protocol; - (*mattr)->m_ceiling = PTHREAD_MAX_PRIORITY; - } - return(ret); -} - diff --git a/lib/libc_r/uthread/uthread_mutexattr_destroy.c b/lib/libc_r/uthread/uthread_mutexattr_destroy.c deleted file mode 100644 index 25d2293..0000000 --- a/lib/libc_r/uthread/uthread_mutexattr_destroy.c +++ /dev/null @@ -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_mutexattr_destroy, pthread_mutexattr_destroy); - -int -_pthread_mutexattr_destroy(pthread_mutexattr_t *attr) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - free(*attr); - *attr = NULL; - ret = 0; - } - return(ret); -} diff --git a/lib/libc_r/uthread/uthread_nanosleep.c b/lib/libc_r/uthread/uthread_nanosleep.c deleted file mode 100644 index a8bea22..0000000 --- a/lib/libc_r/uthread/uthread_nanosleep.c +++ /dev/null @@ -1,140 +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 <stdio.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__nanosleep, nanosleep); - -int -_nanosleep(const struct timespec * time_to_sleep, - struct timespec * time_remaining) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - struct timespec current_time; - struct timespec current_time1; - struct timespec remaining_time; - struct timeval tv; - - /* Check if the time to sleep is legal: */ - if (time_to_sleep == NULL || time_to_sleep->tv_sec < 0 || - time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec >= 1000000000) { - /* Return an EINVAL error : */ - errno = EINVAL; - ret = -1; - } else { - /* - * As long as we're going to get the time of day, we - * might as well store it in the global time of day: - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time); - - /* Calculate the time for the current thread to wake up: */ - curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec; - curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec; - - /* Check if the nanosecond field has overflowed: */ - if (curthread->wakeup_time.tv_nsec >= 1000000000) { - /* Wrap the nanosecond field: */ - curthread->wakeup_time.tv_sec += 1; - curthread->wakeup_time.tv_nsec -= 1000000000; - } - curthread->interrupted = 0; - - /* Reschedule the current thread to sleep: */ - _thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__); - - /* - * As long as we're going to get the time of day, we - * might as well store it in the global time of day: - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time1); - - /* Calculate the remaining time to sleep: */ - remaining_time.tv_sec = time_to_sleep->tv_sec + current_time.tv_sec - current_time1.tv_sec; - remaining_time.tv_nsec = time_to_sleep->tv_nsec + current_time.tv_nsec - current_time1.tv_nsec; - - /* Check if the nanosecond field has underflowed: */ - if (remaining_time.tv_nsec < 0) { - /* Handle the underflow: */ - remaining_time.tv_sec -= 1; - remaining_time.tv_nsec += 1000000000; - } - - /* Check if the nanosecond field has overflowed: */ - if (remaining_time.tv_nsec >= 1000000000) { - /* Handle the overflow: */ - remaining_time.tv_sec += 1; - remaining_time.tv_nsec -= 1000000000; - } - - /* Check if the sleep was longer than the required time: */ - if (remaining_time.tv_sec < 0) { - /* Reset the time left: */ - remaining_time.tv_sec = 0; - remaining_time.tv_nsec = 0; - } - - /* Check if the time remaining is to be returned: */ - if (time_remaining != NULL) { - /* Return the actual time slept: */ - time_remaining->tv_sec = remaining_time.tv_sec; - time_remaining->tv_nsec = remaining_time.tv_nsec; - } - - /* Check if the sleep was interrupted: */ - if (curthread->interrupted) { - /* Return an EINTR error : */ - errno = EINTR; - ret = -1; - } - } - return (ret); -} - -int -__nanosleep(const struct timespec * time_to_sleep, struct timespec * - time_remaining) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _nanosleep(time_to_sleep, time_remaining); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_once.c b/lib/libc_r/uthread/uthread_once.c deleted file mode 100644 index 6aa0c49..0000000 --- a/lib/libc_r/uthread/uthread_once.c +++ /dev/null @@ -1,52 +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 "namespace.h" -#include <pthread.h> -#include "un-namespace.h" -#include "pthread_private.h" - -__weak_reference(_pthread_once, pthread_once); - -int -_pthread_once(pthread_once_t * once_control, void (*init_routine) (void)) -{ - if (once_control->state == PTHREAD_NEEDS_INIT) { - if (_thread_initial == NULL) - _thread_init(); - _pthread_mutex_lock(&(once_control->mutex)); - if (once_control->state == PTHREAD_NEEDS_INIT) { - init_routine(); - once_control->state = PTHREAD_DONE_INIT; - } - _pthread_mutex_unlock(&(once_control->mutex)); - } - return (0); -} diff --git a/lib/libc_r/uthread/uthread_open.c b/lib/libc_r/uthread/uthread_open.c deleted file mode 100644 index 9d7b8b2..0000000 --- a/lib/libc_r/uthread/uthread_open.c +++ /dev/null @@ -1,93 +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 <dirent.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__open, open); - -int -_open(const char *path, int flags,...) -{ - int fd; - int mode = 0; - va_list ap; - - /* Check if the file is being created: */ - if (flags & O_CREAT) { - /* Get the creation mode: */ - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - /* Open the file: */ - if ((fd = __sys_open(path, flags, mode)) < 0) { - } - /* Initialise the file descriptor table entry: */ - else if (_thread_fd_table_init(fd) != 0) { - /* Quietly close the file: */ - __sys_close(fd); - - /* Reset the file descriptor: */ - fd = -1; - } - - /* Return the file descriptor or -1 on error: */ - return (fd); -} - -int -__open(const char *path, int flags,...) -{ - int ret; - int mode = 0; - va_list ap; - - _thread_enter_cancellation_point(); - - /* Check if the file is being created: */ - if (flags & O_CREAT) { - /* Get the creation mode: */ - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - - ret = _open(path, flags, mode); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_pause.c b/lib/libc_r/uthread/uthread_pause.c deleted file mode 100644 index 57b508f..0000000 --- a/lib/libc_r/uthread/uthread_pause.c +++ /dev/null @@ -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 <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pause, pause); - -int -_pause(void) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = __pause(); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_pipe.c b/lib/libc_r/uthread/uthread_pipe.c deleted file mode 100644 index 3d0090b..0000000 --- a/lib/libc_r/uthread/uthread_pipe.c +++ /dev/null @@ -1,51 +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 <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pipe, pipe); - -int -_pipe(int fds[2]) -{ - int ret; - if ((ret = __sys_pipe(fds)) >= 0) { - if (_thread_fd_table_init(fds[0]) != 0 || - _thread_fd_table_init(fds[1]) != 0) { - __sys_close(fds[0]); - __sys_close(fds[1]); - ret = -1; - } - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_poll.c b/lib/libc_r/uthread/uthread_poll.c deleted file mode 100644 index 62b2613..0000000 --- a/lib/libc_r/uthread/uthread_poll.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1999 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 <unistd.h> -#include <errno.h> -#include <string.h> -#include <poll.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__poll, poll); - -int -_poll(struct pollfd *fds, unsigned int nfds, int timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec ts; - int numfds = nfds; - int i, ret = 0; - struct pthread_poll_data data; - - if (numfds > _thread_dtablesize) { - numfds = _thread_dtablesize; - } - /* Check if a timeout was specified: */ - if (timeout == INFTIM) { - /* Wait for ever: */ - _thread_kern_set_timeout(NULL); - } else if (timeout > 0) { - /* Convert the timeout in msec to a timespec: */ - ts.tv_sec = timeout / 1000; - ts.tv_nsec = (timeout % 1000) * 1000000; - - /* Set the wake up time: */ - _thread_kern_set_timeout(&ts); - } else if (timeout < 0) { - /* a timeout less than zero but not == INFTIM is invalid */ - errno = EINVAL; - return (-1); - } - - if (((ret = __sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) { - data.nfds = numfds; - data.fds = fds; - - /* - * Clear revents in case of a timeout which leaves fds - * unchanged: - */ - for (i = 0; i < numfds; i++) { - fds[i].revents = 0; - } - - curthread->data.poll_data = &data; - curthread->interrupted = 0; - _thread_kern_sched_state(PS_POLL_WAIT, __FILE__, __LINE__); - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - } else { - ret = data.nfds; - } - } - - return (ret); -} - -int -__poll(struct pollfd *fds, unsigned int nfds, int timeout) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _poll(fds, nfds, timeout); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_priority_queue.c b/lib/libc_r/uthread/uthread_priority_queue.c deleted file mode 100644 index b700d97..0000000 --- a/lib/libc_r/uthread/uthread_priority_queue.c +++ /dev/null @@ -1,370 +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 <stdlib.h> -#include <sys/queue.h> -#include <string.h> -#include <pthread.h> -#include "pthread_private.h" - -/* Prototypes: */ -static void pq_insert_prio_list(pq_queue_t *pq, int prio); - -#if defined(_PTHREADS_INVARIANTS) - -static int _pq_active = 0; - -#define _PQ_IN_SCHEDQ (PTHREAD_FLAGS_IN_PRIOQ | PTHREAD_FLAGS_IN_WAITQ | PTHREAD_FLAGS_IN_WORKQ) - -#define _PQ_SET_ACTIVE() _pq_active = 1 -#define _PQ_CLEAR_ACTIVE() _pq_active = 0 -#define _PQ_ASSERT_ACTIVE(msg) do { \ - if (_pq_active == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_INACTIVE(msg) do { \ - if (_pq_active != 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_IN_WAITQ(thrd, msg) do { \ - if (((thrd)->flags & PTHREAD_FLAGS_IN_WAITQ) == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_IN_PRIOQ(thrd, msg) do { \ - if (((thrd)->flags & PTHREAD_FLAGS_IN_PRIOQ) == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_NOT_QUEUED(thrd, msg) do { \ - if (((thrd)->flags & _PQ_IN_SCHEDQ) != 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_PROTECTED(msg) \ - PTHREAD_ASSERT((_thread_kern_in_sched != 0) || \ - ((_get_curthread())->sig_defer_count > 0) ||\ - (_sig_in_handler != 0), msg); - -#else - -#define _PQ_SET_ACTIVE() -#define _PQ_CLEAR_ACTIVE() -#define _PQ_ASSERT_ACTIVE(msg) -#define _PQ_ASSERT_INACTIVE(msg) -#define _PQ_ASSERT_IN_WAITQ(thrd, msg) -#define _PQ_ASSERT_IN_PRIOQ(thrd, msg) -#define _PQ_ASSERT_NOT_QUEUED(thrd, msg) -#define _PQ_ASSERT_PROTECTED(msg) - -#endif - -int -_pq_alloc(pq_queue_t *pq, int minprio, int maxprio) -{ - int ret = 0; - int prioslots = maxprio - minprio + 1; - - if (pq == NULL) - ret = -1; - - /* Create the priority queue with (maxprio - minprio + 1) slots: */ - else if ((pq->pq_lists = - (pq_list_t *) malloc(sizeof(pq_list_t) * prioslots)) == NULL) - ret = -1; - - else { - /* Remember the queue size: */ - pq->pq_size = prioslots; - ret = _pq_init(pq); - } - return (ret); -} - -int -_pq_init(pq_queue_t *pq) -{ - int i, ret = 0; - - if ((pq == NULL) || (pq->pq_lists == NULL)) - ret = -1; - - else { - /* Initialize the queue for each priority slot: */ - for (i = 0; i < pq->pq_size; i++) { - TAILQ_INIT(&pq->pq_lists[i].pl_head); - pq->pq_lists[i].pl_prio = i; - pq->pq_lists[i].pl_queued = 0; - } - - /* Initialize the priority queue: */ - TAILQ_INIT(&pq->pq_queue); - _PQ_CLEAR_ACTIVE(); - } - return (ret); -} - -void -_pq_remove(pq_queue_t *pq, pthread_t pthread) -{ - int prio = pthread->active_priority; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_remove: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_IN_PRIOQ(pthread, "_pq_remove: Not in priority queue"); - _PQ_ASSERT_PROTECTED("_pq_remove: prioq not protected!"); - - /* - * Remove this thread from priority list. Note that if - * the priority list becomes empty, it is not removed - * from the priority queue because another thread may be - * added to the priority list (resulting in a needless - * removal/insertion). Priority lists are only removed - * from the priority queue when _pq_first is called. - */ - TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe); - - /* This thread is now longer in the priority queue. */ - pthread->flags &= ~PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); -} - - -void -_pq_insert_head(pq_queue_t *pq, pthread_t pthread) -{ - int prio; - - /* - * Don't insert suspended threads into the priority queue. - * The caller is responsible for setting the threads state. - */ - if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) { - /* Make sure the threads state is suspended. */ - if (pthread->state != PS_SUSPENDED) - PTHREAD_SET_STATE(pthread, PS_SUSPENDED); - } else { - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_insert_head: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, - "_pq_insert_head: Already in priority queue"); - _PQ_ASSERT_PROTECTED("_pq_insert_head: prioq not protected!"); - - prio = pthread->active_priority; - TAILQ_INSERT_HEAD(&pq->pq_lists[prio].pl_head, pthread, pqe); - if (pq->pq_lists[prio].pl_queued == 0) - /* Insert the list into the priority queue: */ - pq_insert_prio_list(pq, prio); - - /* Mark this thread as being in the priority queue. */ - pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); - } -} - - -void -_pq_insert_tail(pq_queue_t *pq, pthread_t pthread) -{ - int prio; - - /* - * Don't insert suspended threads into the priority queue. - * The caller is responsible for setting the threads state. - */ - if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) { - /* Make sure the threads state is suspended. */ - if (pthread->state != PS_SUSPENDED) - PTHREAD_SET_STATE(pthread, PS_SUSPENDED); - } else { - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_insert_tail: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, - "_pq_insert_tail: Already in priority queue"); - _PQ_ASSERT_PROTECTED("_pq_insert_tail: prioq not protected!"); - - prio = pthread->active_priority; - TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe); - if (pq->pq_lists[prio].pl_queued == 0) - /* Insert the list into the priority queue: */ - pq_insert_prio_list(pq, prio); - - /* Mark this thread as being in the priority queue. */ - pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); - } -} - - -pthread_t -_pq_first(pq_queue_t *pq) -{ - pq_list_t *pql; - pthread_t pthread = NULL; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_first: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_PROTECTED("_pq_first: prioq not protected!"); - - while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) && - (pthread == NULL)) { - if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) { - /* - * The priority list is empty; remove the list - * from the queue. - */ - TAILQ_REMOVE(&pq->pq_queue, pql, pl_link); - - /* Mark the list as not being in the queue: */ - pql->pl_queued = 0; - } else if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) { - /* - * This thread is suspended; remove it from the - * list and ensure its state is suspended. - */ - TAILQ_REMOVE(&pql->pl_head, pthread, pqe); - PTHREAD_SET_STATE(pthread, PS_SUSPENDED); - - /* This thread is now longer in the priority queue. */ - pthread->flags &= ~PTHREAD_FLAGS_IN_PRIOQ; - pthread = NULL; - } - } - - _PQ_CLEAR_ACTIVE(); - return (pthread); -} - - -static void -pq_insert_prio_list(pq_queue_t *pq, int prio) -{ - pq_list_t *pql; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_ACTIVE("pq_insert_prio_list: pq_active"); - _PQ_ASSERT_PROTECTED("_pq_insert_prio_list: prioq not protected!"); - - /* - * The priority queue is in descending priority order. Start at - * the beginning of the queue and find the list before which the - * new list should be inserted. - */ - pql = TAILQ_FIRST(&pq->pq_queue); - while ((pql != NULL) && (pql->pl_prio > prio)) - pql = TAILQ_NEXT(pql, pl_link); - - /* Insert the list: */ - if (pql == NULL) - TAILQ_INSERT_TAIL(&pq->pq_queue, &pq->pq_lists[prio], pl_link); - else - TAILQ_INSERT_BEFORE(pql, &pq->pq_lists[prio], pl_link); - - /* Mark this list as being in the queue: */ - pq->pq_lists[prio].pl_queued = 1; -} - -void -_waitq_insert(pthread_t pthread) -{ - pthread_t tid; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_waitq_insert: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, "_waitq_insert: Already in queue"); - - if (pthread->wakeup_time.tv_sec == -1) - TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe); - else { - tid = TAILQ_FIRST(&_waitingq); - while ((tid != NULL) && (tid->wakeup_time.tv_sec != -1) && - ((tid->wakeup_time.tv_sec < pthread->wakeup_time.tv_sec) || - ((tid->wakeup_time.tv_sec == pthread->wakeup_time.tv_sec) && - (tid->wakeup_time.tv_nsec <= pthread->wakeup_time.tv_nsec)))) - tid = TAILQ_NEXT(tid, pqe); - if (tid == NULL) - TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe); - else - TAILQ_INSERT_BEFORE(tid, pthread, pqe); - } - pthread->flags |= PTHREAD_FLAGS_IN_WAITQ; - - _PQ_CLEAR_ACTIVE(); -} - -void -_waitq_remove(pthread_t pthread) -{ - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_waitq_remove: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_IN_WAITQ(pthread, "_waitq_remove: Not in queue"); - - TAILQ_REMOVE(&_waitingq, pthread, pqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_WAITQ; - - _PQ_CLEAR_ACTIVE(); -} - -void -_waitq_setactive(void) -{ - _PQ_ASSERT_INACTIVE("_waitq_setactive: pq_active"); - _PQ_SET_ACTIVE(); -} - -void -_waitq_clearactive(void) -{ - _PQ_ASSERT_ACTIVE("_waitq_clearactive: ! pq_active"); - _PQ_CLEAR_ACTIVE(); -} diff --git a/lib/libc_r/uthread/uthread_pselect.c b/lib/libc_r/uthread/uthread_pselect.c deleted file mode 100644 index 9848863..0000000 --- a/lib/libc_r/uthread/uthread_pselect.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2002 Daniel M. 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. - * - * 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. - * - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/select.h> -#include <sys/time.h> - -#include <errno.h> -#include <signal.h> -#include <pthread.h> - -#include "pthread_private.h" - -extern int __pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds, - const struct timespec *timo, const sigset_t *mask); - -__weak_reference(_pselect, pselect); - -int -_pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds, - const struct timespec *timo, const sigset_t *mask) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = __pselect(count, rfds, wfds, efds, timo, mask); - _thread_leave_cancellation_point(); - - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_read.c b/lib/libc_r/uthread/uthread_read.c deleted file mode 100644 index 655abdf..0000000 --- a/lib/libc_r/uthread/uthread_read.c +++ /dev/null @@ -1,108 +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/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__read, read); - -ssize_t -_read(int fd, void *buf, size_t nbytes) -{ - struct pthread *curthread = _get_curthread(); - int ret; - int type; - - /* POSIX says to do just this: */ - if (nbytes == 0) { - return (0); - } - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_getflags(fd) & O_ACCMODE; - - /* Check if the file is not open for read: */ - if (type != O_RDONLY && type != O_RDWR) { - /* File is not open for read: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_READ); - return (-1); - } - - /* Perform a non-blocking read syscall: */ - while ((ret = __sys_read(fd, buf, nbytes)) < 0) { - if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 && - (errno == EWOULDBLOCK || errno == EAGAIN)) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(NULL); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - _thread_kern_sched_state(PS_FDR_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } else { - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} - -ssize_t -__read(int fd, void *buf, size_t nbytes) -{ - ssize_t ret; - - _thread_enter_cancellation_point(); - ret = _read(fd, buf, nbytes); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_readv.c b/lib/libc_r/uthread/uthread_readv.c deleted file mode 100644 index 11e3433..0000000 --- a/lib/libc_r/uthread/uthread_readv.c +++ /dev/null @@ -1,103 +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/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__readv, readv); - -ssize_t -_readv(int fd, const struct iovec * iov, int iovcnt) -{ - struct pthread *curthread = _get_curthread(); - int ret; - int type; - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_getflags(fd) & O_ACCMODE; - - /* Check if the file is not open for read: */ - if (type != O_RDONLY && type != O_RDWR) { - /* File is not open for read: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_READ); - return (-1); - } - - /* Perform a non-blocking readv syscall: */ - while ((ret = __sys_readv(fd, iov, iovcnt)) < 0) { - if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 && - (errno == EWOULDBLOCK || errno == EAGAIN)) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(NULL); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - _thread_kern_sched_state(PS_FDR_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } else { - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} - -ssize_t -__readv(int fd, const struct iovec *iov, int iovcnt) -{ - ssize_t ret; - - _thread_enter_cancellation_point(); - ret = _readv(fd, iov, iovcnt); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_recvfrom.c b/lib/libc_r/uthread/uthread_recvfrom.c deleted file mode 100644 index 50a0a42..0000000 --- a/lib/libc_r/uthread/uthread_recvfrom.c +++ /dev/null @@ -1,86 +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(__recvfrom, recvfrom); - -ssize_t -_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, - socklen_t *from_len) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - while ((ret = __sys_recvfrom(fd, buf, len, flags, from, from_len)) < 0) { - if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0) - && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - curthread->interrupted = 0; - _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 { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} - -ssize_t -__recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, - socklen_t *from_len) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _recvfrom(fd, buf, len, flags, from, from_len); - _thread_leave_cancellation_point(); - - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_recvmsg.c b/lib/libc_r/uthread/uthread_recvmsg.c deleted file mode 100644 index ed83f1a..0000000 --- a/lib/libc_r/uthread/uthread_recvmsg.c +++ /dev/null @@ -1,84 +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 <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__recvmsg, recvmsg); - -ssize_t -_recvmsg(int fd, struct msghdr *msg, int flags) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - while ((ret = __sys_recvmsg(fd, msg, flags)) < 0) { - if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0) - && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - curthread->interrupted = 0; - _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 { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} - -ssize_t -__recvmsg(int fd, struct msghdr *msg, int flags) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _recvmsg(fd, msg, flags); - _thread_leave_cancellation_point(); - - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_resume_np.c b/lib/libc_r/uthread/uthread_resume_np.c deleted file mode 100644 index 2ca1bc4..0000000 --- a/lib/libc_r/uthread/uthread_resume_np.c +++ /dev/null @@ -1,108 +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" - -static void resume_common(struct pthread *); - -__weak_reference(_pthread_resume_np, pthread_resume_np); -__weak_reference(_pthread_resume_all_np, pthread_resume_all_np); - -/* Resume a thread: */ -int -_pthread_resume_np(pthread_t thread) -{ - int ret; - - /* Find the thread in the list of active threads: */ - if ((ret = _find_thread(thread)) == 0) { - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - if ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) - resume_common(thread); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - return (ret); -} - -void -_pthread_resume_all_np(void) -{ - struct pthread *curthread = _get_curthread(); - struct pthread *thread; - - /* - * Defer signals to protect the scheduling queues from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - TAILQ_FOREACH(thread, &_thread_list, tle) { - if ((thread != curthread) && - ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0)) - resume_common(thread); - } - - /* - * Undefer and handle pending signals, yielding if necessary: - */ - _thread_kern_sig_undefer(); -} - -static void -resume_common(struct pthread *thread) -{ - /* Clear the suspend flag: */ - thread->flags &= ~PTHREAD_FLAGS_SUSPENDED; - - /* - * If the thread's state is suspended, that means it is - * now runnable but not in any scheduling queue. Set the - * state to running and insert it into the run queue. - */ - if (thread->state == PS_SUSPENDED) { - PTHREAD_SET_STATE(thread, PS_RUNNING); - if (thread->priority_mutex_count > 0) - PTHREAD_PRIOQ_INSERT_HEAD(thread); - else - PTHREAD_PRIOQ_INSERT_TAIL(thread); - } -} diff --git a/lib/libc_r/uthread/uthread_rwlock.c b/lib/libc_r/uthread/uthread_rwlock.c deleted file mode 100644 index fdda04c..0000000 --- a/lib/libc_r/uthread/uthread_rwlock.c +++ /dev/null @@ -1,379 +0,0 @@ -/*- - * Copyright (c) 1998 Alex Nash - * 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 <limits.h> -#include <stdlib.h> - -#include "namespace.h" -#include <pthread.h> -#include "un-namespace.h" - -#include "pthread_private.h" - -/* maximum number of times a read lock may be obtained */ -#define MAX_READ_LOCKS (INT_MAX - 1) - -__weak_reference(_pthread_rwlock_destroy, pthread_rwlock_destroy); -__weak_reference(_pthread_rwlock_init, pthread_rwlock_init); -__weak_reference(_pthread_rwlock_rdlock, pthread_rwlock_rdlock); -__weak_reference(_pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); -__weak_reference(_pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); -__weak_reference(_pthread_rwlock_unlock, pthread_rwlock_unlock); -__weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); - -static int init_static (pthread_rwlock_t *rwlock); - -static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER; - -static int -init_static (pthread_rwlock_t *rwlock) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*rwlock == NULL) - ret = _pthread_rwlock_init(rwlock, NULL); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return (ret); -} - -int -_pthread_rwlock_destroy (pthread_rwlock_t *rwlock) -{ - int ret; - - if (rwlock == NULL) - ret = EINVAL; - else { - pthread_rwlock_t prwlock; - - prwlock = *rwlock; - - _pthread_mutex_destroy(&prwlock->lock); - _pthread_cond_destroy(&prwlock->read_signal); - _pthread_cond_destroy(&prwlock->write_signal); - free(prwlock); - - *rwlock = NULL; - - ret = 0; - } - return (ret); -} - -int -_pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) -{ - pthread_rwlock_t prwlock; - int ret; - - /* allocate rwlock object */ - prwlock = (pthread_rwlock_t)malloc(sizeof(struct pthread_rwlock)); - - if (prwlock == NULL) - return(ENOMEM); - - /* initialize the lock */ - if ((ret = _pthread_mutex_init(&prwlock->lock, NULL)) != 0) - free(prwlock); - else { - /* initialize the read condition signal */ - ret = _pthread_cond_init(&prwlock->read_signal, NULL); - - if (ret != 0) { - _pthread_mutex_destroy(&prwlock->lock); - free(prwlock); - } else { - /* initialize the write condition signal */ - ret = _pthread_cond_init(&prwlock->write_signal, NULL); - - if (ret != 0) { - _pthread_cond_destroy(&prwlock->read_signal); - _pthread_mutex_destroy(&prwlock->lock); - free(prwlock); - } else { - /* success */ - prwlock->state = 0; - prwlock->blocked_writers = 0; - - *rwlock = prwlock; - } - } - } - - return (ret); -} - -int -_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - /* check lock count */ - if (prwlock->state == MAX_READ_LOCKS) { - _pthread_mutex_unlock(&prwlock->lock); - return (EAGAIN); - } - - curthread = _get_curthread(); - if ((curthread->rdlock_count > 0) && (prwlock->state > 0)) { - /* - * To avoid having to track all the rdlocks held by - * a thread or all of the threads that hold a rdlock, - * we keep a simple count of all the rdlocks held by - * a thread. If a thread holds any rdlocks it is - * possible that it is attempting to take a recursive - * rdlock. If there are blocked writers and precedence - * is given to them, then that would result in the thread - * deadlocking. So allowing a thread to take the rdlock - * when it already has one or more rdlocks avoids the - * deadlock. I hope the reader can follow that logic ;-) - */ - ; /* nothing needed */ - } else { - /* give writers priority over readers */ - while (prwlock->blocked_writers || prwlock->state < 0) { - ret = _pthread_cond_wait(&prwlock->read_signal, - &prwlock->lock); - - if (ret != 0) { - /* can't do a whole lot if this fails */ - _pthread_mutex_unlock(&prwlock->lock); - return(ret); - } - } - } - - curthread->rdlock_count++; - prwlock->state++; /* indicate we are locked for reading */ - - /* - * Something is really wrong if this call fails. Returning - * error won't do because we've already obtained the read - * lock. Decrementing 'state' is no good because we probably - * don't have the monitor lock. - */ - _pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -_pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - curthread = _get_curthread(); - if (prwlock->state == MAX_READ_LOCKS) - ret = EAGAIN; /* too many read locks acquired */ - else if ((curthread->rdlock_count > 0) && (prwlock->state > 0)) { - /* see comment for pthread_rwlock_rdlock() */ - curthread->rdlock_count++; - prwlock->state++; - } - /* give writers priority over readers */ - else if (prwlock->blocked_writers || prwlock->state < 0) - ret = EBUSY; - else { - prwlock->state++; /* indicate we are locked for reading */ - curthread->rdlock_count++; - } - - /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -_pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - if (prwlock->state != 0) - ret = EBUSY; - else - /* indicate we are locked for writing */ - prwlock->state = -1; - - /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -_pthread_rwlock_unlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - if (prwlock == NULL) - return(EINVAL); - - /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - curthread = _get_curthread(); - if (prwlock->state > 0) { - curthread->rdlock_count--; - prwlock->state--; - if (prwlock->state == 0 && prwlock->blocked_writers) - ret = _pthread_cond_signal(&prwlock->write_signal); - } else if (prwlock->state < 0) { - prwlock->state = 0; - - if (prwlock->blocked_writers) - ret = _pthread_cond_signal(&prwlock->write_signal); - else - ret = _pthread_cond_broadcast(&prwlock->read_signal); - } else - ret = EINVAL; - - /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - while (prwlock->state != 0) { - prwlock->blocked_writers++; - - ret = _pthread_cond_wait(&prwlock->write_signal, - &prwlock->lock); - - if (ret != 0) { - prwlock->blocked_writers--; - _pthread_mutex_unlock(&prwlock->lock); - return(ret); - } - - prwlock->blocked_writers--; - } - - /* indicate we are locked for writing */ - prwlock->state = -1; - - /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - diff --git a/lib/libc_r/uthread/uthread_rwlockattr.c b/lib/libc_r/uthread/uthread_rwlockattr.c deleted file mode 100644 index bc1b9ee..0000000 --- a/lib/libc_r/uthread/uthread_rwlockattr.c +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * Copyright (c) 1998 Alex Nash - * 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 <stdlib.h> - -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_rwlockattr_destroy, pthread_rwlockattr_destroy); -__weak_reference(_pthread_rwlockattr_getpshared, pthread_rwlockattr_getpshared); -__weak_reference(_pthread_rwlockattr_init, pthread_rwlockattr_init); -__weak_reference(_pthread_rwlockattr_setpshared, pthread_rwlockattr_setpshared); - -int -_pthread_rwlockattr_destroy(pthread_rwlockattr_t *rwlockattr) -{ - pthread_rwlockattr_t prwlockattr; - - if (rwlockattr == NULL) - return(EINVAL); - - prwlockattr = *rwlockattr; - - if (prwlockattr == NULL) - return(EINVAL); - - free(prwlockattr); - - return(0); -} - -int -_pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *rwlockattr, - int *pshared) -{ - *pshared = (*rwlockattr)->pshared; - - return(0); -} - -int -_pthread_rwlockattr_init(pthread_rwlockattr_t *rwlockattr) -{ - pthread_rwlockattr_t prwlockattr; - - if (rwlockattr == NULL) - return(EINVAL); - - prwlockattr = (pthread_rwlockattr_t) - malloc(sizeof(struct pthread_rwlockattr)); - - if (prwlockattr == NULL) - return(ENOMEM); - - prwlockattr->pshared = PTHREAD_PROCESS_PRIVATE; - *rwlockattr = prwlockattr; - - return(0); -} - -int -_pthread_rwlockattr_setpshared(pthread_rwlockattr_t *rwlockattr, int pshared) -{ - /* Only PTHREAD_PROCESS_PRIVATE is supported. */ - if (pshared != PTHREAD_PROCESS_PRIVATE) - return(EINVAL); - - (*rwlockattr)->pshared = pshared; - - return(0); -} - diff --git a/lib/libc_r/uthread/uthread_select.c b/lib/libc_r/uthread/uthread_select.c deleted file mode 100644 index 69293e3..0000000 --- a/lib/libc_r/uthread/uthread_select.c +++ /dev/null @@ -1,228 +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 <errno.h> -#include <poll.h> -#include <stdlib.h> -#include <string.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__select, select); - -int -_select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, - struct timeval * timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec ts; - int i, ret = 0, f_wait = 1; - int pfd_index, got_events = 0, fd_count = 0; - struct pthread_poll_data data; - - if (numfds > _thread_dtablesize) { - numfds = _thread_dtablesize; - } - /* Count the number of file descriptors to be polled: */ - if (readfds || writefds || exceptfds) { - for (i = 0; i < numfds; i++) { - if ((readfds && FD_ISSET(i, readfds)) || - (exceptfds && FD_ISSET(i, exceptfds)) || - (writefds && FD_ISSET(i, writefds))) { - fd_count++; - } - } - } - - /* - * Allocate memory for poll data if it hasn't already been - * allocated or if previously allocated memory is insufficient. - */ - if ((curthread->poll_data.fds == NULL) || - (curthread->poll_data.nfds < fd_count)) { - data.fds = (struct pollfd *) realloc(curthread->poll_data.fds, - sizeof(struct pollfd) * MAX(128, fd_count)); - if (data.fds == NULL) { - errno = ENOMEM; - ret = -1; - } - else { - /* - * Note that the threads poll data always - * indicates what is allocated, not what is - * currently being polled. - */ - curthread->poll_data.fds = data.fds; - curthread->poll_data.nfds = MAX(128, fd_count); - } - } - /* Check if a timeout was specified: */ - if (timeout) { - if (timeout->tv_sec < 0 || - timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) { - errno = EINVAL; - return (-1); - } - - /* Convert the timeval to a timespec: */ - TIMEVAL_TO_TIMESPEC(timeout, &ts); - - /* Set the wake up time: */ - _thread_kern_set_timeout(&ts); - if (ts.tv_sec == 0 && ts.tv_nsec == 0) - f_wait = 0; - } else { - /* Wait for ever: */ - _thread_kern_set_timeout(NULL); - } - - if (ret == 0) { - /* Setup the wait data. */ - data.fds = curthread->poll_data.fds; - data.nfds = fd_count; - - /* - * Setup the array of pollfds. Optimize this by - * running the loop in reverse and stopping when - * the number of selected file descriptors is reached. - */ - for (i = numfds - 1, pfd_index = fd_count - 1; - (i >= 0) && (pfd_index >= 0); i--) { - data.fds[pfd_index].events = 0; - if (readfds && FD_ISSET(i, readfds)) { - data.fds[pfd_index].events = POLLRDNORM; - } - if (exceptfds && FD_ISSET(i, exceptfds)) { - data.fds[pfd_index].events |= POLLRDBAND; - } - if (writefds && FD_ISSET(i, writefds)) { - data.fds[pfd_index].events |= POLLWRNORM; - } - if (data.fds[pfd_index].events != 0) { - /* - * Set the file descriptor to be polled and - * clear revents in case of a timeout which - * leaves fds unchanged: - */ - data.fds[pfd_index].fd = i; - data.fds[pfd_index].revents = 0; - pfd_index--; - } - } - if (((ret = __sys_poll(data.fds, data.nfds, 0)) == 0) && - (f_wait != 0)) { - curthread->data.poll_data = &data; - curthread->interrupted = 0; - _thread_kern_sched_state(PS_SELECT_WAIT, __FILE__, __LINE__); - if (curthread->interrupted) { - errno = EINTR; - data.nfds = 0; - ret = -1; - } else - ret = data.nfds; - } - } - - if (ret >= 0) { - numfds = 0; - for (i = 0; i < fd_count; i++) { - /* - * Check the results of the poll and clear - * this file descriptor from the fdset if - * the requested event wasn't ready. - */ - - /* - * First check for invalid descriptor. - * If found, set errno and return -1. - */ - if (data.fds[i].revents & POLLNVAL) { - errno = EBADF; - return -1; - } - - got_events = 0; - if (readfds != NULL) { - if (FD_ISSET(data.fds[i].fd, readfds)) { - if ((data.fds[i].revents & (POLLIN - | POLLRDNORM | POLLERR - | POLLHUP | POLLNVAL)) != 0) - got_events++; - else - FD_CLR(data.fds[i].fd, readfds); - } - } - if (writefds != NULL) { - if (FD_ISSET(data.fds[i].fd, writefds)) { - if ((data.fds[i].revents & (POLLOUT - | POLLWRNORM | POLLWRBAND | POLLERR - | POLLHUP | POLLNVAL)) != 0) - got_events++; - else - FD_CLR(data.fds[i].fd, - writefds); - } - } - if (exceptfds != NULL) { - if (FD_ISSET(data.fds[i].fd, exceptfds)) { - if (data.fds[i].revents & (POLLRDBAND | - POLLPRI)) - got_events++; - else - FD_CLR(data.fds[i].fd, - exceptfds); - } - } - if (got_events != 0) - numfds+=got_events; - } - ret = numfds; - } - - return (ret); -} - -int -__select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _select(numfds, readfds, writefds, exceptfds, timeout); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_self.c b/lib/libc_r/uthread/uthread_self.c deleted file mode 100644 index 8a30b7a..0000000 --- a/lib/libc_r/uthread/uthread_self.c +++ /dev/null @@ -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_self, pthread_self); - -pthread_t -_pthread_self(void) -{ - /* Return the running thread pointer: */ - return (_get_curthread()); -} diff --git a/lib/libc_r/uthread/uthread_sem.c b/lib/libc_r/uthread/uthread_sem.c deleted file mode 100644 index f85bb91..0000000 --- a/lib/libc_r/uthread/uthread_sem.c +++ /dev/null @@ -1,256 +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 <stdlib.h> -#include <errno.h> -#include <semaphore.h> -#include "namespace.h" -#include <pthread.h> -#include "un-namespace.h" -#include "pthread_private.h" - -#define _SEM_CHECK_VALIDITY(sem) \ - if ((*(sem))->magic != SEM_MAGIC) { \ - errno = EINVAL; \ - retval = -1; \ - goto RETURN; \ - } - -__weak_reference(_sem_init, sem_init); -__weak_reference(_sem_destroy, sem_destroy); -__weak_reference(_sem_open, sem_open); -__weak_reference(_sem_close, sem_close); -__weak_reference(_sem_unlink, sem_unlink); -__weak_reference(_sem_wait, sem_wait); -__weak_reference(_sem_trywait, sem_trywait); -__weak_reference(_sem_post, sem_post); -__weak_reference(_sem_getvalue, sem_getvalue); - - -int -_sem_init(sem_t *sem, int pshared, unsigned int value) -{ - int retval; - - /* - * Range check the arguments. - */ - if (pshared != 0) { - /* - * The user wants a semaphore that can be shared among - * processes, which this implementation can't do. Sounds like a - * permissions problem to me (yeah right). - */ - errno = EPERM; - retval = -1; - goto RETURN; - } - - if (value > SEM_VALUE_MAX) { - errno = EINVAL; - retval = -1; - goto RETURN; - } - - *sem = (sem_t)malloc(sizeof(struct sem)); - if (*sem == NULL) { - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - /* - * Initialize the semaphore. - */ - if (_pthread_mutex_init(&(*sem)->lock, NULL) != 0) { - free(*sem); - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - if (_pthread_cond_init(&(*sem)->gtzero, NULL) != 0) { - _pthread_mutex_destroy(&(*sem)->lock); - free(*sem); - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - (*sem)->count = (u_int32_t)value; - (*sem)->nwaiters = 0; - (*sem)->magic = SEM_MAGIC; - - retval = 0; - RETURN: - return retval; -} - -int -_sem_destroy(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - /* Make sure there are no waiters. */ - _pthread_mutex_lock(&(*sem)->lock); - if ((*sem)->nwaiters > 0) { - _pthread_mutex_unlock(&(*sem)->lock); - errno = EBUSY; - retval = -1; - goto RETURN; - } - _pthread_mutex_unlock(&(*sem)->lock); - - _pthread_mutex_destroy(&(*sem)->lock); - _pthread_cond_destroy(&(*sem)->gtzero); - (*sem)->magic = 0; - - free(*sem); - - retval = 0; - RETURN: - return retval; -} - -sem_t * -_sem_open(const char *name, int oflag, ...) -{ - errno = ENOSYS; - return SEM_FAILED; -} - -int -_sem_close(sem_t *sem) -{ - errno = ENOSYS; - return -1; -} - -int -_sem_unlink(const char *name) -{ - errno = ENOSYS; - return -1; -} - -int -_sem_wait(sem_t *sem) -{ - int retval; - - _thread_enter_cancellation_point(); - - _SEM_CHECK_VALIDITY(sem); - - _pthread_mutex_lock(&(*sem)->lock); - - while ((*sem)->count == 0) { - (*sem)->nwaiters++; - _pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock); - (*sem)->nwaiters--; - } - (*sem)->count--; - - _pthread_mutex_unlock(&(*sem)->lock); - - retval = 0; - RETURN: - _thread_leave_cancellation_point(); - return retval; -} - -int -_sem_trywait(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - _pthread_mutex_lock(&(*sem)->lock); - - if ((*sem)->count > 0) { - (*sem)->count--; - retval = 0; - } else { - errno = EAGAIN; - retval = -1; - } - - _pthread_mutex_unlock(&(*sem)->lock); - - RETURN: - return retval; -} - -int -_sem_post(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - /* - * sem_post() is required to be safe to call from within signal - * handlers. Thus, we must defer signals. - */ - _thread_kern_sig_defer(); - - _pthread_mutex_lock(&(*sem)->lock); - - (*sem)->count++; - if ((*sem)->nwaiters > 0) - _pthread_cond_signal(&(*sem)->gtzero); - - _pthread_mutex_unlock(&(*sem)->lock); - - _thread_kern_sig_undefer(); - retval = 0; - RETURN: - return retval; -} - -int -_sem_getvalue(sem_t *sem, int *sval) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - _pthread_mutex_lock(&(*sem)->lock); - *sval = (int)(*sem)->count; - _pthread_mutex_unlock(&(*sem)->lock); - - retval = 0; - RETURN: - return retval; -} diff --git a/lib/libc_r/uthread/uthread_sendfile.c b/lib/libc_r/uthread/uthread_sendfile.c deleted file mode 100644 index ddaddeb..0000000 --- a/lib/libc_r/uthread/uthread_sendfile.c +++ /dev/null @@ -1,194 +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 <sys/fcntl.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sendfile, sendfile); - -int -_sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr, - off_t *sbytes, int flags) -{ - struct pthread *curthread = _get_curthread(); - int type, blocking; - int ret = 0; - ssize_t wvret, num = 0; - off_t n, nwritten = 0; - - /* - * Write the headers if any. - * If some data is written but not all we must return here. - */ - if ((hdtr != NULL) && (hdtr->headers != NULL)) { - if ((wvret = writev(s, hdtr->headers, hdtr->hdr_cnt)) == -1) { - ret = -1; - goto ERROR; - } else { - int i; - ssize_t hdrtot; - - nwritten += wvret; - - for (i = 0, hdrtot = 0; i < hdtr->hdr_cnt; i++) - hdrtot += hdtr->headers[i].iov_len; - if (wvret < hdrtot) - goto SHORT_WRITE; - } - } - - /* Lock the descriptors. */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) != 0) { - ret = -1; - errno = EBADF; - goto ERROR; - } - if ((ret = _FD_LOCK(s, FD_WRITE, NULL)) != 0) { - ret = -1; - errno = EBADF; - goto ERROR_1; - } - - /* Check the descriptor access modes. */ - type = _thread_fd_getflags(fd) & O_ACCMODE; - if (type != O_RDONLY && type != O_RDWR) { - /* File is not open for read. */ - ret = -1; - errno = EBADF; - goto ERROR_2; - } - type = _thread_fd_getflags(s) & O_ACCMODE; - if (type != O_WRONLY && type != O_RDWR) { - /* File is not open for write. */ - ret = -1; - errno = EBADF; - goto ERROR_2; - } - - /* Check if file operations are to block */ - blocking = ((_thread_fd_getflags(s) & O_NONBLOCK) == 0); - - /* - * Loop while no error occurs and until the expected number of bytes are - * written. - */ - for (;;) { - /* Perform a non-blocking sendfile syscall. */ - ret = __sys_sendfile(fd, s, offset + num, nbytes - num, - NULL, &n, flags); - - /* - * We have to handle the sideways return path of sendfile. - * - * If the result is 0, we're done. - * If the result is anything else check the errno. - * If the errno is not EGAIN return the error. - * Otherwise, take into account how much - * sendfile may have written for us because sendfile can - * return EAGAIN even though it has written data. - * - * We don't clear 'ret' because the sendfile(2) syscall - * would not have either. - */ - if (ret == 0) { - /* Writing completed. */ - num += n; - break; - } else if ((ret == -1) && (errno == EAGAIN)) { - /* - * Some bytes were written but there are still more to - * write. - */ - - /* Update the count of bytes written. */ - num += n; - - /* - * If we're not blocking then return. - */ - if (!blocking) { - _FD_UNLOCK(s, FD_WRITE); - _FD_UNLOCK(fd, FD_READ); - goto SHORT_WRITE; - } - - /* - * Otherwise wait on the fd. - */ - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(NULL); - - /* Reset the interrupted operation flag. */ - curthread->interrupted = 0; - - _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, - __LINE__); - - if (curthread->interrupted) { - /* Interrupted by a signal. Return an error. */ - break; - } - } else { - /* Incomplete non-blocking syscall, or error. */ - break; - } - } - - ERROR_2: - _FD_UNLOCK(s, FD_WRITE); - ERROR_1: - _FD_UNLOCK(fd, FD_READ); - ERROR: - if (ret == 0) { - /* Write the trailers, if any. */ - if ((hdtr != NULL) && (hdtr->trailers != NULL)) { - if ((wvret = writev(s, hdtr->trailers, hdtr->trl_cnt)) - == -1) - ret = -1; - else - nwritten += wvret; - } - } - SHORT_WRITE: - if (sbytes != NULL) { - /* - * Number of bytes written in headers/trailers, plus in the main - * sendfile() loop. - */ - *sbytes = nwritten + num; - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sendmsg.c b/lib/libc_r/uthread/uthread_sendmsg.c deleted file mode 100644 index 30262f4..0000000 --- a/lib/libc_r/uthread/uthread_sendmsg.c +++ /dev/null @@ -1,83 +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 <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__sendmsg, sendmsg); - -ssize_t -_sendmsg(int fd, const struct msghdr *msg, int flags) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - while ((ret = __sys_sendmsg(fd, msg, flags)) < 0) { - if (!(_thread_fd_getflags(fd) & O_NONBLOCK) - && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - curthread->interrupted = 0; - _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__); - - /* Check if the operation was interrupted: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} - -ssize_t -__sendmsg(int fd, const struct msghdr *msg, int flags) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _sendmsg(fd, msg, flags); - _thread_leave_cancellation_point(); - - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sendto.c b/lib/libc_r/uthread/uthread_sendto.c deleted file mode 100644 index 2e4367a..0000000 --- a/lib/libc_r/uthread/uthread_sendto.c +++ /dev/null @@ -1,85 +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(__sendto, sendto); - -ssize_t -_sendto(int fd, const void *msg, size_t len, int flags, const struct - sockaddr * to, socklen_t to_len) -{ - struct pthread *curthread = _get_curthread(); - int ret; - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - while ((ret = __sys_sendto(fd, msg, len, flags, to, to_len)) < 0) { - if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0) - && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - curthread->interrupted = 0; - _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__); - - /* Check if the operation was interrupted: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} - -ssize_t -__sendto(int fd, const void *msg, size_t len, int flags, const struct - sockaddr * to, socklen_t to_len) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _sendto(fd, msg, len, flags, to, to_len); - _thread_leave_cancellation_point(); - - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_seterrno.c b/lib/libc_r/uthread/uthread_seterrno.c deleted file mode 100644 index dfcc576..0000000 --- a/lib/libc_r/uthread/uthread_seterrno.c +++ /dev/null @@ -1,56 +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" - -/* - * This function needs to reference the global error variable which is - * normally hidden from the user. - */ -#ifdef errno -#undef errno; -#endif -extern int errno; - -void -_thread_seterrno(pthread_t thread, int error) -{ - /* Check for the initial thread: */ - if (thread == _thread_initial) - /* The initial thread always uses the global error variable: */ - errno = error; - else - /* - * Threads other than the initial thread always use the error - * field in the thread structureL - */ - thread->error = error; -} diff --git a/lib/libc_r/uthread/uthread_setprio.c b/lib/libc_r/uthread/uthread_setprio.c deleted file mode 100644 index efc96c1..0000000 --- a/lib/libc_r/uthread/uthread_setprio.c +++ /dev/null @@ -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 <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_setprio, pthread_setprio); - -int -_pthread_setprio(pthread_t pthread, int prio) -{ - int ret, policy; - struct sched_param param; - - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) { - param.sched_priority = prio; - ret = pthread_setschedparam(pthread, policy, ¶m); - } - - /* Return the error status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_setschedparam.c b/lib/libc_r/uthread/uthread_setschedparam.c deleted file mode 100644 index 7696762..0000000 --- a/lib/libc_r/uthread/uthread_setschedparam.c +++ /dev/null @@ -1,119 +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 <sys/param.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_setschedparam, pthread_setschedparam); - -int -_pthread_setschedparam(pthread_t pthread, int policy, - const struct sched_param *param) -{ - int old_prio, in_readyq = 0, ret = 0; - - if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) { - /* Return an invalid argument error: */ - ret = EINVAL; - } else if ((param->sched_priority < PTHREAD_MIN_PRIORITY) || - (param->sched_priority > PTHREAD_MAX_PRIORITY)) { - /* Return an unsupported value error. */ - ret = ENOTSUP; - - /* Find the thread in the list of active threads: */ - } else if ((ret = _find_thread(pthread)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - if (param->sched_priority != - PTHREAD_BASE_PRIORITY(pthread->base_priority)) { - /* - * Remove the thread from its current priority - * queue before any adjustments are made to its - * active priority: - */ - old_prio = pthread->active_priority; - if ((pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) != 0) { - in_readyq = 1; - PTHREAD_PRIOQ_REMOVE(pthread); - } - - /* Set the thread base priority: */ - pthread->base_priority &= - (PTHREAD_SIGNAL_PRIORITY | PTHREAD_RT_PRIORITY); - pthread->base_priority = param->sched_priority; - - /* Recalculate the active priority: */ - pthread->active_priority = MAX(pthread->base_priority, - pthread->inherited_priority); - - if (in_readyq) { - if ((pthread->priority_mutex_count > 0) && - (old_prio > pthread->active_priority)) { - /* - * POSIX states that if the priority is - * being lowered, the thread must be - * inserted at the head of the queue for - * its priority if it owns any priority - * protection or inheritence mutexes. - */ - PTHREAD_PRIOQ_INSERT_HEAD(pthread); - } - else - PTHREAD_PRIOQ_INSERT_TAIL(pthread); - } - - /* - * Check for any mutex priority adjustments. This - * includes checking for a priority mutex on which - * this thread is waiting. - */ - _mutex_notify_priochange(pthread); - } - - /* Set the scheduling policy: */ - pthread->attr.sched_policy = policy; - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - return(ret); -} diff --git a/lib/libc_r/uthread/uthread_setsockopt.c b/lib/libc_r/uthread/uthread_setsockopt.c deleted file mode 100644 index 1c9baf1..0000000 --- a/lib/libc_r/uthread/uthread_setsockopt.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_setsockopt, setsockopt); - -int -_setsockopt(int fd, int level, int optname, const void *optval, socklen_t - optlen) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_setsockopt(fd, level, optname, optval, optlen); - _FD_UNLOCK(fd, FD_RDWR); - } - return ret; -} diff --git a/lib/libc_r/uthread/uthread_shutdown.c b/lib/libc_r/uthread/uthread_shutdown.c deleted file mode 100644 index e97b9b7..0000000 --- a/lib/libc_r/uthread/uthread_shutdown.c +++ /dev/null @@ -1,69 +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 <pthread.h> -#include "pthread_private.h" - -__weak_reference(_shutdown, shutdown); - -int -_shutdown(int fd, int how) -{ - int ret; - - switch (how) { - case 0: - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - ret = __sys_shutdown(fd, how); - _FD_UNLOCK(fd, FD_READ); - } - break; - case 1: - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - ret = __sys_shutdown(fd, how); - _FD_UNLOCK(fd, FD_WRITE); - } - break; - case 2: - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = __sys_shutdown(fd, how); - _FD_UNLOCK(fd, FD_RDWR); - } - break; - default: - errno = EBADF; - ret = -1; - break; - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sig.c b/lib/libc_r/uthread/uthread_sig.c deleted file mode 100644 index 7f700b2..0000000 --- a/lib/libc_r/uthread/uthread_sig.c +++ /dev/null @@ -1,1165 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/param.h> -#include <sys/types.h> -#include <sys/signalvar.h> -#include <signal.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <setjmp.h> -#include <string.h> -#include <pthread.h> -#include "pthread_private.h" - -/* Prototypes: */ -static void thread_sig_add(struct pthread *pthread, int sig, int has_args); -static void thread_sig_check_state(struct pthread *pthread, int sig); -static struct pthread *thread_sig_find(int sig); -static void thread_sig_handle_special(int sig); -static void thread_sigframe_add(struct pthread *thread, int sig, - int has_args); -static void thread_sigframe_save(struct pthread *thread, - struct pthread_signal_frame *psf); -static void thread_sig_invoke_handler(int sig, siginfo_t *info, - ucontext_t *ucp, int unblock); - -/*#define DEBUG_SIGNAL*/ -#ifdef DEBUG_SIGNAL -#define DBG_MSG stdout_debug -#else -#define DBG_MSG(x...) -#endif - -#if defined(_PTHREADS_INVARIANTS) -#define SIG_SET_ACTIVE() _sig_in_handler = 1 -#define SIG_SET_INACTIVE() _sig_in_handler = 0 -#else -#define SIG_SET_ACTIVE() -#define SIG_SET_INACTIVE() -#endif - -void -_thread_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp) -{ - struct pthread *curthread = _get_curthread(); - struct pthread *pthread, *pthread_h; - int in_sched = _thread_kern_in_sched; - char c; - sigset_t sigset; - - if (ucp == NULL) - PANIC("Thread signal handler received null context"); - DBG_MSG("Got signal %d, current thread %p\n", sig, curthread); - - /* Check if an interval timer signal: */ - if (sig == _SCHED_SIGNAL) { - /* Update the scheduling clock: */ - gettimeofday((struct timeval *)&_sched_tod, NULL); - _sched_ticks++; - - if (in_sched != 0) { - /* - * The scheduler is already running; ignore this - * signal. - */ - } - /* - * Check if the scheduler interrupt has come when - * the currently running thread has deferred thread - * signals. - */ - else if (curthread->sig_defer_count > 0) - curthread->yield_on_sig_undefer = 1; - else { - /* Schedule the next thread: */ - _thread_kern_sched(ucp); - - /* - * This point should not be reached, so abort the - * process: - */ - PANIC("Returned to signal function from scheduler"); - } - } - /* - * Check if the kernel has been interrupted while the scheduler - * is accessing the scheduling queues or if there is a currently - * running thread that has deferred signals. - */ - else if ((in_sched != 0) || (curthread->sig_defer_count > 0)) { - /* Cast the signal number to a character variable: */ - c = sig; - - /* - * Write the signal number to the kernel pipe so that it will - * be ready to read when this signal handler returns. - */ - if (_queue_signals != 0) { - ssize_t wgot; - do { - wgot = __sys_write(_thread_kern_pipe[1], &c, - 1); - } while (wgot < 0 && errno == EINTR); - if (wgot < 0 && errno != EAGAIN) { - PANIC("Failed to queue signal"); - } - DBG_MSG("Got signal %d, queueing to kernel pipe\n", sig); - } - if (_thread_sigq[sig - 1].blocked == 0) { - DBG_MSG("Got signal %d, adding to _thread_sigq\n", sig); - /* - * Do not block this signal; it will be blocked - * when the pending signals are run down. - */ - /* _thread_sigq[sig - 1].blocked = 1; */ - - /* - * Queue the signal, saving siginfo and sigcontext - * (ucontext). - * - * XXX - Do we need to copy siginfo and ucp? - */ - _thread_sigq[sig - 1].signo = sig; - if (info != NULL) - memcpy(&_thread_sigq[sig - 1].siginfo, info, - sizeof(*info)); - memcpy(&_thread_sigq[sig - 1].uc, ucp, sizeof(*ucp)); - - /* Indicate that there are queued signals: */ - _thread_sigq[sig - 1].pending = 1; - _sigq_check_reqd = 1; - } - /* These signals need special handling: */ - else if (sig == SIGCHLD || sig == SIGTSTP || - sig == SIGTTIN || sig == SIGTTOU) { - _thread_sigq[sig - 1].pending = 1; - _thread_sigq[sig - 1].signo = sig; - _sigq_check_reqd = 1; - } - else - DBG_MSG("Got signal %d, ignored.\n", sig); - } - /* - * The signal handlers should have been installed so that they - * cannot be interrupted by other signals. - */ - else if (_thread_sigq[sig - 1].blocked == 0) { - /* - * The signal is not blocked; handle the signal. - * - * Ignore subsequent occurrences of this signal - * until the current signal is handled: - */ - _thread_sigq[sig - 1].blocked = 1; - - /* This signal will be handled; clear the pending flag: */ - _thread_sigq[sig - 1].pending = 0; - - /* - * Save siginfo and sigcontext (ucontext). - * - * XXX - Do we need to copy siginfo and ucp? - */ - _thread_sigq[sig - 1].signo = sig; - - if (info != NULL) - memcpy(&_thread_sigq[sig - 1].siginfo, info, - sizeof(*info)); - memcpy(&_thread_sigq[sig - 1].uc, ucp, sizeof(*ucp)); - SIG_SET_ACTIVE(); - - /* Handle special signals: */ - thread_sig_handle_special(sig); - - pthread_h = NULL; - if ((pthread = thread_sig_find(sig)) == NULL) - DBG_MSG("No thread to handle signal %d\n", sig); - else if (pthread == curthread) { - /* Call the signal handler for the current thread: */ - thread_sig_invoke_handler(sig, info, ucp, 2); - - /* - * Set the process signal mask in the context; it - * could have changed by the handler. - */ - ucp->uc_sigmask = _process_sigmask; - - /* - * The signal mask was restored; check for any - * pending signals: - */ - sigset = curthread->sigpend; - SIGSETOR(sigset, _process_sigpending); - SIGSETNAND(sigset, curthread->sigmask); - if (SIGNOTEMPTY(sigset)) - curthread->check_pending = 1; - - /* Resume the interrupted thread: */ - __sys_sigreturn(ucp); - } else { - DBG_MSG("Got signal %d, adding frame to thread %p\n", - sig, pthread); - - /* Setup the target thread to receive the signal: */ - thread_sig_add(pthread, sig, /*has_args*/ 1); - - /* Take a peek at the next ready to run thread: */ - pthread_h = PTHREAD_PRIOQ_FIRST(); - DBG_MSG("Finished adding frame, head of prio list %p\n", - pthread_h); - } - SIG_SET_INACTIVE(); - - /* - * Switch to a different context if the currently running - * thread takes a signal, or if another thread takes a - * signal and the currently running thread is not in a - * signal handler. - */ - if ((pthread_h != NULL) && - (pthread_h->active_priority > curthread->active_priority)) { - /* Enter the kernel scheduler: */ - _thread_kern_sched(ucp); - } - } - else { - SIG_SET_ACTIVE(); - thread_sig_handle_special(sig); - SIG_SET_INACTIVE(); - } -} - -static void -thread_sig_invoke_handler(int sig, siginfo_t *info, ucontext_t *ucp, - int unblock) - { - struct pthread *curthread = _get_curthread(); - void (*sigfunc)(int, siginfo_t *, void *); - int saved_seqno; - sigset_t saved_sigmask; - - /* Invoke the signal handler without going through the scheduler: - */ - DBG_MSG("Got signal %d, calling handler for current thread %p\n", - sig, curthread); - - /* Save the threads signal mask: */ - saved_sigmask = curthread->sigmask; - saved_seqno = curthread->sigmask_seqno; - - /* Setup the threads signal mask: */ - SIGSETOR(curthread->sigmask, _thread_sigact[sig - 1].sa_mask); - sigaddset(&curthread->sigmask, sig); - - if (unblock > 0) { - /* - * Unblock the signal and restore the process signal - * mask in case we don't return from the handler: - */ - _thread_sigq[sig - 1].blocked = 0; - if (unblock > 1) - __sys_sigprocmask(SIG_SETMASK, &_process_sigmask, - NULL); - } - - /* - * Check that a custom handler is installed and if - * the signal is not blocked: - */ - sigfunc = _thread_sigact[sig - 1].sa_sigaction; - if (((__sighandler_t *)sigfunc != SIG_DFL) && - ((__sighandler_t *)sigfunc != SIG_IGN)) { - if (((_thread_sigact[sig - 1].sa_flags & SA_SIGINFO) != 0) || - (info == NULL)) - (*(sigfunc))(sig, info, ucp); - else - (*(sigfunc))(sig, (void*)(intptr_t)info->si_code, ucp); - } - /* - * Only restore the signal mask if it hasn't been changed by the - * application during invocation of the signal handler: - */ - if (curthread->sigmask_seqno == saved_seqno) - curthread->sigmask = saved_sigmask; -} - -/* - * Find a thread that can handle the signal. - */ -struct pthread * -thread_sig_find(int sig) -{ - struct pthread *curthread = _get_curthread(); - int handler_installed; - struct pthread *pthread, *pthread_next; - struct pthread *suspended_thread, *signaled_thread; - - DBG_MSG("Looking for thread to handle signal %d\n", sig); - /* Check if the signal requires a dump of thread information: */ - if (sig == SIGINFO) { - /* Dump thread information to file: */ - _thread_dump_info(); - - /* Unblock this signal to allow further dumps: */ - _thread_sigq[sig - 1].blocked = 0; - } - /* Check if an interval timer signal: */ - else if (sig == _SCHED_SIGNAL) { - /* - * This shouldn't ever occur (should this panic?). - */ - } else { - /* - * Enter a loop to look for threads that have the signal - * unmasked. POSIX specifies that a thread in a sigwait - * will get the signal over any other threads. Second - * preference will be threads in a sigsuspend. Third - * preference will be the current thread. If none of the - * above, then the signal is delivered to the first thread - * that is found. Note that if a custom handler is not - * installed, the signal only affects threads in sigwait. - */ - suspended_thread = NULL; - if ((curthread != &_thread_kern_thread) && - !sigismember(&curthread->sigmask, sig)) - signaled_thread = curthread; - else - signaled_thread = NULL; - if ((_thread_sigact[sig - 1].sa_handler == SIG_IGN) || - (_thread_sigact[sig - 1].sa_handler == SIG_DFL)) - handler_installed = 0; - else - handler_installed = 1; - - for (pthread = TAILQ_FIRST(&_waitingq); - pthread != NULL; pthread = pthread_next) { - /* - * Grab the next thread before possibly destroying - * the link entry. - */ - pthread_next = TAILQ_NEXT(pthread, pqe); - - if ((pthread->state == PS_SIGWAIT) && - sigismember(pthread->data.sigwait, sig)) { - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - /* - * A signal handler is not invoked for threads - * in sigwait. Clear the blocked and pending - * flags. - */ - _thread_sigq[sig - 1].blocked = 0; - _thread_sigq[sig - 1].pending = 0; - - /* Return the signal number: */ - pthread->signo = sig; - - /* - * POSIX doesn't doesn't specify which thread - * will get the signal if there are multiple - * waiters, so we give it to the first thread - * we find. - * - * Do not attempt to deliver this signal - * to other threads and do not add the signal - * to the process pending set. - */ - return (NULL); - } - else if ((handler_installed != 0) && - !sigismember(&pthread->sigmask, sig) && - ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) == 0)) { - if (pthread->state == PS_SIGSUSPEND) { - if (suspended_thread == NULL) - suspended_thread = pthread; - } else if (signaled_thread == NULL) - signaled_thread = pthread; - } - } - - /* - * Only perform wakeups and signal delivery if there is a - * custom handler installed: - */ - if (handler_installed == 0) { - /* - * There is no handler installed. Unblock the - * signal so that if a handler _is_ installed, any - * subsequent signals can be handled. - */ - _thread_sigq[sig - 1].blocked = 0; - } else { - /* - * If we didn't find a thread in the waiting queue, - * check the all threads queue: - */ - if (suspended_thread == NULL && - signaled_thread == NULL) { - /* - * Enter a loop to look for other threads - * capable of receiving the signal: - */ - TAILQ_FOREACH(pthread, &_thread_list, tle) { - if (!sigismember(&pthread->sigmask, - sig)) { - signaled_thread = pthread; - break; - } - } - } - - if (suspended_thread == NULL && - signaled_thread == NULL) - /* - * Add it to the set of signals pending - * on the process: - */ - sigaddset(&_process_sigpending, sig); - else { - /* - * We only deliver the signal to one thread; - * give preference to the suspended thread: - */ - if (suspended_thread != NULL) - pthread = suspended_thread; - else - pthread = signaled_thread; - return (pthread); - } - } - } - - /* Returns nothing. */ - return (NULL); -} - -void -_thread_sig_check_pending(struct pthread *pthread) -{ - sigset_t sigset; - int i; - - /* - * Check if there are pending signals for the running - * thread or process that aren't blocked: - */ - sigset = pthread->sigpend; - SIGSETOR(sigset, _process_sigpending); - SIGSETNAND(sigset, pthread->sigmask); - if (SIGNOTEMPTY(sigset)) { - for (i = 1; i < NSIG; i++) { - if (sigismember(&sigset, i) != 0) { - if (sigismember(&pthread->sigpend, i) != 0) - thread_sig_add(pthread, i, - /*has_args*/ 0); - else { - thread_sig_add(pthread, i, - /*has_args*/ 1); - sigdelset(&_process_sigpending, i); - } - } - } - } -} - -/* - * This can only be called from the kernel scheduler. It assumes that - * all thread contexts are saved and that a signal frame can safely be - * added to any user thread. - */ -void -_thread_sig_handle_pending(void) -{ - struct pthread *pthread; - int i, sig; - - PTHREAD_ASSERT(_thread_kern_in_sched != 0, - "_thread_sig_handle_pending called from outside kernel schedule"); - /* - * Check the array of pending signals: - */ - for (i = 0; i < NSIG; i++) { - if (_thread_sigq[i].pending != 0) { - /* This signal is no longer pending. */ - _thread_sigq[i].pending = 0; - - sig = _thread_sigq[i].signo; - - /* Some signals need special handling: */ - thread_sig_handle_special(sig); - - if (_thread_sigq[i].blocked == 0) { - /* - * Block future signals until this one - * is handled: - */ - _thread_sigq[i].blocked = 1; - - if ((pthread = thread_sig_find(sig)) != NULL) { - /* - * Setup the target thread to receive - * the signal: - */ - thread_sig_add(pthread, sig, - /*has_args*/ 1); - } - } - } - } -} - -static void -thread_sig_handle_special(int sig) -{ - struct pthread *pthread, *pthread_next; - int i; - - switch (sig) { - case SIGCHLD: - /* - * Go through the file list and set all files - * to non-blocking again in case the child - * set some of them to block. Sigh. - */ - for (i = 0; i < _thread_dtablesize; i++) { - /* Check if this file is used: */ - if (_thread_fd_table[i] != NULL) { - /* - * Set the file descriptor to non-blocking: - */ - __sys_fcntl(i, F_SETFL, - _thread_fd_getflags(i) | O_NONBLOCK); - } - } - /* - * Enter a loop to wake up all threads waiting - * for a process to complete: - */ - for (pthread = TAILQ_FIRST(&_waitingq); - pthread != NULL; pthread = pthread_next) { - /* - * Grab the next thread before possibly - * destroying the link entry: - */ - pthread_next = TAILQ_NEXT(pthread, pqe); - - /* - * If this thread is waiting for a child - * process to complete, wake it up: - */ - if (pthread->state == PS_WAIT_WAIT) { - /* Make the thread runnable: */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } - } - break; - - /* - * POSIX says that pending SIGCONT signals are - * discarded when one of these signals occurs. - */ - case SIGTSTP: - case SIGTTIN: - case SIGTTOU: - /* - * Enter a loop to discard pending SIGCONT - * signals: - */ - TAILQ_FOREACH(pthread, &_thread_list, tle) { - sigdelset(&pthread->sigpend, SIGCONT); - } - break; - - default: - break; - } -} - -/* - * Perform thread specific actions in response to a signal. - * This function is only called if there is a handler installed - * for the signal, and if the target thread has the signal - * unmasked. - */ -static void -thread_sig_add(struct pthread *pthread, int sig, int has_args) -{ - int restart; - int suppress_handler = 0; - int thread_is_active = 0; - - restart = _thread_sigact[sig - 1].sa_flags & SA_RESTART; - - /* Make sure this signal isn't still in the pending set: */ - sigdelset(&pthread->sigpend, sig); - - /* - * Process according to thread state: - */ - switch (pthread->state) { - /* - * States which do not change when a signal is trapped: - */ - case PS_DEAD: - case PS_DEADLOCK: - case PS_STATE_MAX: - case PS_SIGTHREAD: - /* - * You can't call a signal handler for threads in these - * states. - */ - suppress_handler = 1; - break; - - /* - * States which do not need any cleanup handling when signals - * occur: - */ - case PS_RUNNING: - /* - * Remove the thread from the queue before changing its - * priority: - */ - if ((pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) != 0) - PTHREAD_PRIOQ_REMOVE(pthread); - else - /* - * This thread is running; avoid placing it in - * the run queue: - */ - thread_is_active = 1; - break; - - case PS_SUSPENDED: - break; - - case PS_SPINBLOCK: - /* Remove the thread from the workq and waitq: */ - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_WAITQ_REMOVE(pthread); - /* Make the thread runnable: */ - PTHREAD_SET_STATE(pthread, PS_RUNNING); - break; - - case PS_SIGWAIT: - /* The signal handler is not called for threads in SIGWAIT. */ - suppress_handler = 1; - /* Wake up the thread if the signal is blocked. */ - if (sigismember(pthread->data.sigwait, sig)) { - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } else - /* Increment the pending signal count. */ - sigaddset(&pthread->sigpend, sig); - break; - - /* - * The wait state is a special case due to the handling of - * SIGCHLD signals. - */ - case PS_WAIT_WAIT: - if (sig == SIGCHLD) { - /* Change the state of the thread to run: */ - PTHREAD_WAITQ_REMOVE(pthread); - PTHREAD_SET_STATE(pthread, PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } - else { - /* - * Mark the thread as interrupted only if the - * restart flag is not set on the signal action: - */ - if (restart == 0) - pthread->interrupted = 1; - PTHREAD_WAITQ_REMOVE(pthread); - PTHREAD_SET_STATE(pthread, PS_RUNNING); - } - break; - - /* - * States which cannot be interrupted but still require the - * signal handler to run: - */ - case PS_COND_WAIT: - case PS_MUTEX_WAIT: - /* - * Remove the thread from the wait queue. It will - * be added back to the wait queue once all signal - * handlers have been invoked. - */ - PTHREAD_WAITQ_REMOVE(pthread); - break; - - case PS_JOIN: - /* - * Remove the thread from the wait queue. It will - * be added back to the wait queue once all signal - * handlers have been invoked. - */ - PTHREAD_WAITQ_REMOVE(pthread); - /* Make the thread runnable: */ - PTHREAD_SET_STATE(pthread, PS_RUNNING); - break; - - /* - * States which are interruptible but may need to be removed - * from queues before any signal handler is called. - * - * XXX - We may not need to handle this condition, but will - * mark it as a potential problem. - */ - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - if (restart == 0) - pthread->interrupted = 1; - /* - * Remove the thread from the wait queue. Our - * signal handler hook will remove this thread - * from the fd or file queue before invoking - * the actual handler. - */ - PTHREAD_WAITQ_REMOVE(pthread); - break; - - /* - * States which are interruptible: - */ - case PS_FDR_WAIT: - case PS_FDW_WAIT: - if (restart == 0) { - /* - * Flag the operation as interrupted and - * set the state to running: - */ - pthread->interrupted = 1; - PTHREAD_SET_STATE(pthread, PS_RUNNING); - } - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_WAITQ_REMOVE(pthread); - break; - - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - case PS_SLEEP_WAIT: - /* - * Unmasked signals always cause poll, select, and sleep - * to terminate early, regardless of SA_RESTART: - */ - pthread->interrupted = 1; - /* Remove threads in poll and select from the workq: */ - if ((pthread->flags & PTHREAD_FLAGS_IN_WORKQ) != 0) - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_WAITQ_REMOVE(pthread); - PTHREAD_SET_STATE(pthread, PS_RUNNING); - break; - - case PS_SIGSUSPEND: - PTHREAD_WAITQ_REMOVE(pthread); - PTHREAD_SET_STATE(pthread, PS_RUNNING); - break; - } - - if (suppress_handler == 0) { - /* Setup a signal frame and save the current threads state: */ - thread_sigframe_add(pthread, sig, has_args); - - /* - * Signals are deferred until just before the threads - * signal handler is invoked: - */ - pthread->sig_defer_count = 1; - - /* Make sure the thread is runnable: */ - if (pthread->state != PS_RUNNING) - PTHREAD_SET_STATE(pthread, PS_RUNNING); - /* - * The thread should be removed from all scheduling - * queues at this point. Raise the priority and place - * the thread in the run queue. It is also possible - * for a signal to be sent to a suspended thread, - * mostly via pthread_kill(). If a thread is suspended, - * don't insert it into the priority queue; just set - * its state to suspended and it will run the signal - * handler when it is resumed. - */ - pthread->active_priority |= PTHREAD_SIGNAL_PRIORITY; - if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) - PTHREAD_SET_STATE(pthread, PS_SUSPENDED); - else if (thread_is_active == 0) - PTHREAD_PRIOQ_INSERT_TAIL(pthread); - } -} - -static void -thread_sig_check_state(struct pthread *pthread, int sig) -{ - /* - * Process according to thread state: - */ - switch (pthread->state) { - /* - * States which do not change when a signal is trapped: - */ - case PS_DEAD: - case PS_DEADLOCK: - case PS_STATE_MAX: - case PS_SIGTHREAD: - case PS_RUNNING: - case PS_SUSPENDED: - case PS_SPINBLOCK: - case PS_COND_WAIT: - case PS_JOIN: - case PS_MUTEX_WAIT: - break; - - case PS_SIGWAIT: - /* Wake up the thread if the signal is blocked. */ - if (sigismember(pthread->data.sigwait, sig)) { - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } else - /* Increment the pending signal count. */ - sigaddset(&pthread->sigpend, sig); - break; - - /* - * The wait state is a special case due to the handling of - * SIGCHLD signals. - */ - case PS_WAIT_WAIT: - if (sig == SIGCHLD) { - /* - * Remove the thread from the wait queue and - * make it runnable: - */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } - break; - - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_SIGSUSPEND: - case PS_SLEEP_WAIT: - /* - * Remove the thread from the wait queue and make it - * runnable: - */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Flag the operation as interrupted: */ - pthread->interrupted = 1; - break; - - /* - * These states are additionally in the work queue: - */ - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_FILE_WAIT: - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* - * Remove the thread from the wait and work queues, and - * make it runnable: - */ - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Flag the operation as interrupted: */ - pthread->interrupted = 1; - break; - } -} - -/* - * Send a signal to a specific thread (ala pthread_kill): - */ -void -_thread_sig_send(struct pthread *pthread, int sig) -{ - struct pthread *curthread = _get_curthread(); - - /* Check for signals whose actions are SIG_DFL: */ - if (_thread_sigact[sig - 1].sa_handler == SIG_DFL) { - /* - * Check to see if a temporary signal handler is - * installed for sigwaiters: - */ - if (_thread_dfl_count[sig] == 0) - /* - * Deliver the signal to the process if a handler - * is not installed: - */ - kill(getpid(), sig); - /* - * Assuming we're still running after the above kill(), - * make any necessary state changes to the thread: - */ - thread_sig_check_state(pthread, sig); - } - /* - * Check that the signal is not being ignored: - */ - else if (_thread_sigact[sig - 1].sa_handler != SIG_IGN) { - if (pthread->state == PS_SIGWAIT && - sigismember(pthread->data.sigwait, sig)) { - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } else if (sigismember(&pthread->sigmask, sig)) - /* Add the signal to the pending set: */ - sigaddset(&pthread->sigpend, sig); - else if (pthread == curthread) - /* Call the signal handler for the current thread: */ - thread_sig_invoke_handler(sig, NULL, NULL, 0); - else { - /* Protect the scheduling queues: */ - _thread_kern_sig_defer(); - /* - * Perform any state changes due to signal - * arrival: - */ - thread_sig_add(pthread, sig, /* has args */ 0); - /* Unprotect the scheduling queues: */ - _thread_kern_sig_undefer(); - } - } -} - -/* - * User thread signal handler wrapper. - * - * thread - current running thread - */ -void -_thread_sig_wrapper(void) -{ - struct pthread_signal_frame *psf; - struct pthread *thread = _get_curthread(); - - /* Get the current frame and state: */ - psf = thread->curframe; - thread->curframe = NULL; - PTHREAD_ASSERT(psf != NULL, "Invalid signal frame in signal handler"); - - /* - * We're coming from the kernel scheduler; clear the in - * scheduler flag: - */ - _thread_kern_in_sched = 0; - - /* Check the threads previous state: */ - if (psf->saved_state.psd_state != PS_RUNNING) { - /* - * Do a little cleanup handling for those threads in - * queues before calling the signal handler. Signals - * for these threads are temporarily blocked until - * after cleanup handling. - */ - switch (psf->saved_state.psd_state) { - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - _fd_lock_backout(thread); - psf->saved_state.psd_state = PS_RUNNING; - break; - - case PS_COND_WAIT: - _cond_wait_backout(thread); - psf->saved_state.psd_state = PS_RUNNING; - break; - - case PS_MUTEX_WAIT: - _mutex_lock_backout(thread); - psf->saved_state.psd_state = PS_RUNNING; - break; - - default: - break; - } - } - - /* - * Lower the priority before calling the handler in case - * it never returns (longjmps back): - */ - thread->active_priority &= ~PTHREAD_SIGNAL_PRIORITY; - - /* - * Reenable interruptions without checking for the need to - * context switch: - */ - thread->sig_defer_count = 0; - - /* - * Dispatch the signal via the custom signal handler: - */ - if (psf->sig_has_args == 0) - thread_sig_invoke_handler(psf->signo, NULL, NULL, 1); - else - thread_sig_invoke_handler(psf->signo, &psf->siginfo, &psf->uc, - 1); - - /* - * Call the kernel scheduler to safely restore the frame and - * schedule the next thread: - */ - _thread_kern_sched_frame(psf); -} - -static void -thread_sigframe_add(struct pthread *thread, int sig, int has_args) -{ - struct pthread_signal_frame *psf = NULL; - unsigned long stackp; - - /* Get the top of the threads stack: */ - stackp = GET_STACK_JB(thread->ctx.jb); - -#if !defined(__ia64__) - /* - * Leave a little space on the stack and round down to the - * nearest aligned word: - */ -#if defined(__amd64__) - stackp -= 128; /* Skip over 128 byte red-zone */ -#endif - stackp -= sizeof(double); -#if defined(__amd64__) - stackp &= ~0xFUL; -#else - stackp &= ~0x3UL; -#endif -#endif - - /* Allocate room on top of the stack for a new signal frame: */ - stackp -= sizeof(struct pthread_signal_frame); -#if defined(__ia64__) || defined(__amd64__) - stackp &= ~0xFUL; -#endif - - psf = (struct pthread_signal_frame *) stackp; - - /* Save the current context in the signal frame: */ - thread_sigframe_save(thread, psf); - - /* Set handler specific information: */ - psf->sig_has_args = has_args; - psf->signo = sig; - if (has_args) { - /* Copy the signal handler arguments to the signal frame: */ - memcpy(&psf->uc, &_thread_sigq[psf->signo - 1].uc, - sizeof(psf->uc)); - memcpy(&psf->siginfo, &_thread_sigq[psf->signo - 1].siginfo, - sizeof(psf->siginfo)); - } - - /* Setup the signal mask: */ - SIGSETOR(thread->sigmask, _thread_sigact[sig - 1].sa_mask); - sigaddset(&thread->sigmask, sig); - - /* Set up the new frame: */ - thread->curframe = psf; - thread->flags &= PTHREAD_FLAGS_PRIVATE | PTHREAD_FLAGS_TRACE | - PTHREAD_FLAGS_IN_SYNCQ; - /* - * Set up the context: - */ -#if !defined(__ia64__) - stackp -= sizeof(double); -#if defined(__amd64__) - stackp &= ~0xFUL; -#endif -#endif - _setjmp(thread->ctx.jb); -#if !defined(__ia64__) - SET_STACK_JB(thread->ctx.jb, stackp); -#else - UPD_STACK_JB(thread->ctx.jb, stackp - 16); -#endif - SET_RETURN_ADDR_JB(thread->ctx.jb, _thread_sig_wrapper); -} - -void -_thread_sigframe_restore(struct pthread *thread, - struct pthread_signal_frame *psf) -{ - memcpy(&thread->ctx, &psf->ctx, sizeof(thread->ctx)); - /* - * Only restore the signal mask if it hasn't been changed - * by the application during invocation of the signal handler: - */ - if (thread->sigmask_seqno == psf->saved_state.psd_sigmask_seqno) - thread->sigmask = psf->saved_state.psd_sigmask; - thread->curframe = psf->saved_state.psd_curframe; - thread->wakeup_time = psf->saved_state.psd_wakeup_time; - thread->data = psf->saved_state.psd_wait_data; - thread->state = psf->saved_state.psd_state; - thread->flags = psf->saved_state.psd_flags; - thread->interrupted = psf->saved_state.psd_interrupted; - thread->signo = psf->saved_state.psd_signo; - thread->sig_defer_count = psf->saved_state.psd_sig_defer_count; -} - -static void -thread_sigframe_save(struct pthread *thread, struct pthread_signal_frame *psf) -{ - memcpy(&psf->ctx, &thread->ctx, sizeof(thread->ctx)); - psf->saved_state.psd_sigmask = thread->sigmask; - psf->saved_state.psd_curframe = thread->curframe; - psf->saved_state.psd_wakeup_time = thread->wakeup_time; - psf->saved_state.psd_wait_data = thread->data; - psf->saved_state.psd_state = thread->state; - psf->saved_state.psd_flags = thread->flags & - (PTHREAD_FLAGS_PRIVATE | PTHREAD_FLAGS_TRACE); - psf->saved_state.psd_interrupted = thread->interrupted; - psf->saved_state.psd_sigmask_seqno = thread->sigmask_seqno; - psf->saved_state.psd_signo = thread->signo; - psf->saved_state.psd_sig_defer_count = thread->sig_defer_count; -} - diff --git a/lib/libc_r/uthread/uthread_sigaction.c b/lib/libc_r/uthread/uthread_sigaction.c deleted file mode 100644 index 25df5fc..0000000 --- a/lib/libc_r/uthread/uthread_sigaction.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <signal.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sigaction, sigaction); - -int -_sigaction(int sig, const struct sigaction * act, struct sigaction * oact) -{ - int ret = 0; - struct sigaction gact; - - /* Check if the signal number is out of range: */ - if (sig < 1 || sig > NSIG) { - /* Return an invalid argument: */ - errno = EINVAL; - ret = -1; - } else { - if (_thread_initial == NULL) - _thread_init(); - - /* - * Check if the existing signal action structure contents are - * to be returned: - */ - if (oact != NULL) { - /* Return the existing signal action contents: */ - oact->sa_handler = _thread_sigact[sig - 1].sa_handler; - oact->sa_mask = _thread_sigact[sig - 1].sa_mask; - oact->sa_flags = _thread_sigact[sig - 1].sa_flags; - } - - /* Check if a signal action was supplied: */ - if (act != NULL) { - /* Set the new signal handler: */ - _thread_sigact[sig - 1].sa_mask = act->sa_mask; - _thread_sigact[sig - 1].sa_flags = act->sa_flags; - _thread_sigact[sig - 1].sa_handler = act->sa_handler; - } - - /* - * Check if the kernel needs to be advised of a change - * in signal action: - */ - if (act != NULL && sig != _SCHED_SIGNAL && sig != SIGCHLD && - sig != SIGINFO) { - /* - * Ensure the signal handler cannot be interrupted - * by other signals. Always request the POSIX signal - * handler arguments. - */ - sigfillset(&gact.sa_mask); - gact.sa_flags = SA_SIGINFO | SA_RESTART; - - /* - * Check if the signal handler is being set to - * the default or ignore handlers: - */ - if (act->sa_handler == SIG_DFL || - act->sa_handler == SIG_IGN) - /* Specify the built in handler: */ - gact.sa_handler = act->sa_handler; - else - /* - * Specify the thread kernel signal - * handler: - */ - gact.sa_handler = (void (*) ()) _thread_sig_handler; - - /* Change the signal action in the kernel: */ - if (__sys_sigaction(sig,&gact,NULL) != 0) - ret = -1; - } - } - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sigmask.c b/lib/libc_r/uthread/uthread_sigmask.c deleted file mode 100644 index 9cd5b92..0000000 --- a/lib/libc_r/uthread/uthread_sigmask.c +++ /dev/null @@ -1,103 +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 <sys/param.h> -#include <sys/types.h> -#include <sys/signalvar.h> -#include <errno.h> -#include <signal.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_pthread_sigmask, pthread_sigmask); - -int -_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) -{ - struct pthread *curthread = _get_curthread(); - sigset_t sigset; - int ret = 0; - - /* Check if the existing signal process mask is to be returned: */ - if (oset != NULL) { - /* Return the current mask: */ - *oset = curthread->sigmask; - } - /* Check if a new signal set was provided by the caller: */ - if (set != NULL) { - /* Process according to what to do: */ - switch (how) { - /* Block signals: */ - case SIG_BLOCK: - /* Add signals to the existing mask: */ - SIGSETOR(curthread->sigmask, *set); - break; - - /* Unblock signals: */ - case SIG_UNBLOCK: - /* Clear signals from the existing mask: */ - SIGSETNAND(curthread->sigmask, *set); - break; - - /* Set the signal process mask: */ - case SIG_SETMASK: - /* Set the new mask: */ - curthread->sigmask = *set; - break; - - /* Trap invalid actions: */ - default: - /* Return an invalid argument: */ - errno = EINVAL; - ret = -1; - break; - } - - /* Increment the sequence number: */ - curthread->sigmask_seqno++; - - /* - * Check if there are pending signals for the running - * thread or process that aren't blocked: - */ - sigset = curthread->sigpend; - SIGSETOR(sigset, _process_sigpending); - SIGSETNAND(sigset, curthread->sigmask); - if (SIGNOTEMPTY(sigset)) - /* - * Call the kernel scheduler which will safely - * install a signal frame for the running thread: - */ - _thread_kern_sched_sig(); - } - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sigpending.c b/lib/libc_r/uthread/uthread_sigpending.c deleted file mode 100644 index eb9affd..0000000 --- a/lib/libc_r/uthread/uthread_sigpending.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1999 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. 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 <sys/param.h> -#include <sys/types.h> -#include <sys/signalvar.h> -#include <signal.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sigpending, sigpending); - -int -_sigpending(sigset_t *set) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - /* Check for a null signal set pointer: */ - if (set == NULL) { - /* Return an invalid argument: */ - ret = EINVAL; - } - else { - *set = curthread->sigpend; - SIGSETOR(*set, _process_sigpending); - } - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_sigprocmask.c b/lib/libc_r/uthread/uthread_sigprocmask.c deleted file mode 100644 index 064f2ba..0000000 --- a/lib/libc_r/uthread/uthread_sigprocmask.c +++ /dev/null @@ -1,45 +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 <sys/param.h> -#include <sys/types.h> -#include <sys/signalvar.h> -#include <signal.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sigprocmask, sigprocmask); - -int -_sigprocmask(int how, const sigset_t *set, sigset_t *oset) -{ - return (pthread_sigmask(how, set, oset)); -} diff --git a/lib/libc_r/uthread/uthread_sigsuspend.c b/lib/libc_r/uthread/uthread_sigsuspend.c deleted file mode 100644 index cd63dfc..0000000 --- a/lib/libc_r/uthread/uthread_sigsuspend.c +++ /dev/null @@ -1,98 +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 <sys/param.h> -#include <sys/signalvar.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__sigsuspend, sigsuspend); - -int -_sigsuspend(const sigset_t * set) -{ - struct pthread *curthread = _get_curthread(); - int ret = -1; - sigset_t oset, sigset; - - /* Check if a new signal set was provided by the caller: */ - if (set != NULL) { - /* Save the current signal mask: */ - oset = curthread->sigmask; - - /* Change the caller's mask: */ - curthread->sigmask = *set; - - /* - * Check if there are pending signals for the running - * thread or process that aren't blocked: - */ - sigset = curthread->sigpend; - SIGSETOR(sigset, _process_sigpending); - SIGSETNAND(sigset, curthread->sigmask); - if (SIGNOTEMPTY(sigset)) { - /* - * Call the kernel scheduler which will safely - * install a signal frame for the running thread: - */ - _thread_kern_sched_sig(); - } else { - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGSUSPEND, - __FILE__, __LINE__); - } - - /* Always return an interrupted error: */ - errno = EINTR; - - /* Restore the signal mask: */ - curthread->sigmask = oset; - } else { - /* Return an invalid argument error: */ - errno = EINVAL; - } - - /* Return the completion status: */ - return (ret); -} - -int -__sigsuspend(const sigset_t * set) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = _sigsuspend(set); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_sigwait.c b/lib/libc_r/uthread/uthread_sigwait.c deleted file mode 100644 index afb9def..0000000 --- a/lib/libc_r/uthread/uthread_sigwait.c +++ /dev/null @@ -1,171 +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 <signal.h> -#include <sys/param.h> -#include <sys/signalvar.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sigwait, sigwait); - -int -_sigwait(const sigset_t * __restrict set, int * __restrict sig) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - int i; - sigset_t tempset, waitset; - struct sigaction act; - - _thread_enter_cancellation_point(); - /* - * Specify the thread kernel signal handler. - */ - act.sa_handler = (void (*) ()) _thread_sig_handler; - act.sa_flags = SA_SIGINFO | SA_RESTART; - /* Ensure the signal handler cannot be interrupted by other signals: */ - sigfillset(&act.sa_mask); - - /* - * Initialize the set of signals that will be waited on: - */ - waitset = *set; - - /* These signals can't be waited on. */ - sigdelset(&waitset, SIGKILL); - sigdelset(&waitset, SIGSTOP); - sigdelset(&waitset, _SCHED_SIGNAL); - sigdelset(&waitset, SIGCHLD); - sigdelset(&waitset, SIGINFO); - - /* Check to see if a pending signal is in the wait mask. */ - tempset = curthread->sigpend; - SIGSETOR(tempset, _process_sigpending); - SIGSETAND(tempset, waitset); - if (SIGNOTEMPTY(tempset)) { - /* Enter a loop to find a pending signal: */ - for (i = 1; i < NSIG; i++) { - if (sigismember (&tempset, i)) - break; - } - - /* Clear the pending signal: */ - if (sigismember(&curthread->sigpend,i)) - sigdelset(&curthread->sigpend,i); - else - sigdelset(&_process_sigpending,i); - - /* Return the signal number to the caller: */ - *sig = i; - - _thread_leave_cancellation_point(); - return (0); - } - - /* - * Access the _thread_dfl_count array under the protection of signal - * deferral. - */ - _thread_kern_sig_defer(); - - /* - * Enter a loop to find the signals that are SIG_DFL. For - * these signals we must install a dummy signal handler in - * order for the kernel to pass them in to us. POSIX says - * that the _application_ must explicitly install a dummy - * handler for signals that are SIG_IGN in order to sigwait - * on them. Note that SIG_IGN signals are left in the - * mask because a subsequent sigaction could enable an - * ignored signal. - */ - sigemptyset(&tempset); - for (i = 1; i < NSIG; i++) { - if (sigismember(&waitset, i) && - (_thread_sigact[i - 1].sa_handler == SIG_DFL)) { - _thread_dfl_count[i]++; - sigaddset(&tempset, i); - if (_thread_dfl_count[i] == 1) { - if (__sys_sigaction(i,&act,NULL) != 0) - ret = -1; - } - } - } - /* Done accessing _thread_dfl_count for now. */ - _thread_kern_sig_undefer(); - - if (ret == 0) { - /* - * Save the wait signal mask. The wait signal - * mask is independent of the threads signal mask - * and requires separate storage. - */ - curthread->data.sigwait = &waitset; - - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__); - - /* Return the signal number to the caller: */ - *sig = curthread->signo; - - /* - * Probably unnecessary, but since it's in a union struct - * we don't know how it could be used in the future. - */ - curthread->data.sigwait = NULL; - } - - /* - * Access the _thread_dfl_count array under the protection of signal - * deferral. - */ - _thread_kern_sig_defer(); - - /* Restore the sigactions: */ - act.sa_handler = SIG_DFL; - for (i = 1; i < NSIG; i++) { - if (sigismember(&tempset, i)) { - _thread_dfl_count[i]--; - if ((_thread_sigact[i - 1].sa_handler == SIG_DFL) && - (_thread_dfl_count[i] == 0)) { - if (__sys_sigaction(i,&act,NULL) != 0) - ret = -1; - } - } - } - /* Done accessing _thread_dfl_count. */ - _thread_kern_sig_undefer(); - - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_single_np.c b/lib/libc_r/uthread/uthread_single_np.c deleted file mode 100644 index a7b6dc1..0000000 --- a/lib/libc_r/uthread/uthread_single_np.c +++ /dev/null @@ -1,46 +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 <pthread.h> -#include <pthread_np.h> - -__weak_reference(_pthread_single_np, pthread_single_np); - -int _pthread_single_np() -{ - - /* Enter single-threaded (non-POSIX) scheduling mode: */ - pthread_suspend_all_np(); - /* - * XXX - Do we want to do this? - * __is_threaded = 0; - */ - return (0); -} diff --git a/lib/libc_r/uthread/uthread_sleep.c b/lib/libc_r/uthread/uthread_sleep.c deleted file mode 100644 index 9e09db7..0000000 --- a/lib/libc_r/uthread/uthread_sleep.c +++ /dev/null @@ -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 <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_sleep, sleep); - -unsigned int -_sleep(unsigned int seconds) -{ - unsigned int ret; - - _thread_enter_cancellation_point(); - ret = __sleep(seconds); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_socket.c b/lib/libc_r/uthread/uthread_socket.c deleted file mode 100644 index c14d813..0000000 --- a/lib/libc_r/uthread/uthread_socket.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_socket, socket); - -int -_socket(int af, int type, int protocol) -{ - int fd; - - /* Create a socket: */ - if ((fd = __sys_socket(af, type, protocol)) < 0) { - /* Error creating socket. */ - - /* Initialise the entry in the file descriptor table: */ - } else if (_thread_fd_table_init(fd) != 0) { - __sys_close(fd); - fd = -1; - } - return (fd); -} diff --git a/lib/libc_r/uthread/uthread_socketpair.c b/lib/libc_r/uthread/uthread_socketpair.c deleted file mode 100644 index b76dd80..0000000 --- a/lib/libc_r/uthread/uthread_socketpair.c +++ /dev/null @@ -1,53 +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 <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_socketpair, socketpair); - -int -_socketpair(int af, int type, int protocol, int pair[2]) -{ - int ret; - if (!((ret = __sys_socketpair(af, type, protocol, pair)) < 0)) - if (_thread_fd_table_init(pair[0]) != 0 || - _thread_fd_table_init(pair[1]) != 0) { - __sys_close(pair[0]); - __sys_close(pair[1]); - ret = -1; - } - return (ret); -} diff --git a/lib/libc_r/uthread/uthread_spec.c b/lib/libc_r/uthread/uthread_spec.c deleted file mode 100644 index 0904428..0000000 --- a/lib/libc_r/uthread/uthread_spec.c +++ /dev/null @@ -1,222 +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 <stdlib.h> -#include <string.h> -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -struct pthread_key { - spinlock_t lock; - volatile int allocated; - volatile int count; - int seqno; - void (*destructor) (); -}; - -/* Static variables: */ -static struct pthread_key key_table[PTHREAD_KEYS_MAX]; - -__weak_reference(_pthread_key_create, pthread_key_create); -__weak_reference(_pthread_key_delete, pthread_key_delete); -__weak_reference(_pthread_getspecific, pthread_getspecific); -__weak_reference(_pthread_setspecific, pthread_setspecific); - - -int -_pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) -{ - for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[*key].lock); - - if (key_table[(*key)].allocated == 0) { - key_table[(*key)].allocated = 1; - key_table[(*key)].destructor = destructor; - key_table[(*key)].seqno++; - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[*key].lock); - return (0); - } - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[*key].lock); - } - return (EAGAIN); -} - -int -_pthread_key_delete(pthread_key_t key) -{ - int ret = 0; - - if (key < PTHREAD_KEYS_MAX) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[key].lock); - - if (key_table[key].allocated) - key_table[key].allocated = 0; - else - ret = EINVAL; - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[key].lock); - } else - ret = EINVAL; - return (ret); -} - -void -_thread_cleanupspecific(void) -{ - struct pthread *curthread = _get_curthread(); - void *data = NULL; - int key; - int itr; - void (*destructor)( void *); - - for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) { - for (key = 0; key < PTHREAD_KEYS_MAX; key++) { - if (curthread->specific_data_count > 0) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[key].lock); - destructor = NULL; - - if (key_table[key].allocated && - (curthread->specific[key].data != NULL)) { - if (curthread->specific[key].seqno == - key_table[key].seqno) { - data = (void *) curthread->specific[key].data; - destructor = key_table[key].destructor; - } - curthread->specific[key].data = NULL; - curthread->specific_data_count--; - } - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[key].lock); - - /* - * If there is a destructore, call it - * with the key table entry unlocked: - */ - if (destructor) - destructor(data); - } else { - free(curthread->specific); - curthread->specific = NULL; - return; - } - } - } - if (curthread->specific != NULL) { - free(curthread->specific); - curthread->specific = NULL; - } -} - -static inline struct pthread_specific_elem * -pthread_key_allocate_data(void) -{ - struct pthread_specific_elem *new_data; - - new_data = (struct pthread_specific_elem *) - malloc(sizeof(struct pthread_specific_elem) * PTHREAD_KEYS_MAX); - if (new_data != NULL) { - memset((void *) new_data, 0, - sizeof(struct pthread_specific_elem) * PTHREAD_KEYS_MAX); - } - return (new_data); -} - -int -_pthread_setspecific(pthread_key_t key, const void *value) -{ - struct pthread *pthread; - int ret = 0; - - /* Point to the running thread: */ - pthread = _get_curthread(); - - if ((pthread->specific) || - (pthread->specific = pthread_key_allocate_data())) { - if (key < PTHREAD_KEYS_MAX) { - if (key_table[key].allocated) { - if (pthread->specific[key].data == NULL) { - if (value != NULL) - pthread->specific_data_count++; - } else { - if (value == NULL) - pthread->specific_data_count--; - } - pthread->specific[key].data = value; - pthread->specific[key].seqno = - key_table[key].seqno; - ret = 0; - } else - ret = EINVAL; - } else - ret = EINVAL; - } else - ret = ENOMEM; - return (ret); -} - -void * -_pthread_getspecific(pthread_key_t key) -{ - struct pthread *pthread; - void *data; - - /* Point to the running thread: */ - pthread = _get_curthread(); - - /* Check if there is specific data: */ - if (pthread->specific != NULL && key < PTHREAD_KEYS_MAX) { - /* Check if this key has been used before: */ - if (key_table[key].allocated && - (pthread->specific[key].seqno == key_table[key].seqno)) { - /* Return the value: */ - data = (void *) pthread->specific[key].data; - } else { - /* - * This key has not been used before, so return NULL - * instead: - */ - data = NULL; - } - } else - /* No specific data has been created, so just return NULL: */ - data = NULL; - return (data); -} diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c deleted file mode 100644 index 6721470..0000000 --- a/lib/libc_r/uthread/uthread_spinlock.c +++ /dev/null @@ -1,114 +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 <stdio.h> -#include <string.h> -#include <sched.h> -#include <pthread.h> -#include <unistd.h> - -#include <libc_private.h> - -#include "pthread_private.h" - -void -_spinunlock(spinlock_t *lck) -{ - lck->access_lock = 0; -} - -/* - * Lock a location for the running thread. Yield to allow other - * threads to run if this thread is blocked because the lock is - * not available. Note that this function does not sleep. It - * assumes that the lock will be available very soon. - */ -void -_spinlock(spinlock_t *lck) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Try to grab the lock and loop if another thread grabs - * it before we do. - */ - while(_atomic_lock(&lck->access_lock)) { - /* Block the thread until the lock. */ - curthread->data.spinlock = lck; - _thread_kern_sched_state(PS_SPINBLOCK, __FILE__, __LINE__); - } - - /* The running thread now owns the lock: */ - lck->lock_owner = (long) curthread; -} - -/* - * Lock a location for the running thread. Yield to allow other - * threads to run if this thread is blocked because the lock is - * not available. Note that this function does not sleep. It - * assumes that the lock will be available very soon. - * - * This function checks if the running thread has already locked the - * location, warns if this occurs and creates a thread dump before - * returning. - */ -void -_spinlock_debug(spinlock_t *lck, char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - int cnt = 0; - - /* - * Try to grab the lock and loop if another thread grabs - * it before we do. - */ - while(_atomic_lock(&lck->access_lock)) { - cnt++; - if (cnt > 100) { - char str[256]; - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); - __sys_write(2,str,strlen(str)); - __sleep(1); - cnt = 0; - } - - /* Block the thread until the lock. */ - curthread->data.spinlock = lck; - _thread_kern_sched_state(PS_SPINBLOCK, fname, lineno); - } - - /* The running thread now owns the lock: */ - lck->lock_owner = (long) curthread; - lck->fname = fname; - lck->lineno = lineno; -} diff --git a/lib/libc_r/uthread/uthread_stack.c b/lib/libc_r/uthread/uthread_stack.c deleted file mode 100644 index 0b176ce..0000000 --- a/lib/libc_r/uthread/uthread_stack.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2001 Daniel Eischen <deischen@freebsd.org> - * Copyright (c) 2000-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, 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 AUTHORS 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 AUTHORS 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 "namespace.h" -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/param.h> -#include <sys/queue.h> -#include <stdlib.h> -#include <pthread.h> -#include "un-namespace.h" - -#include "pthread_private.h" - -/* Spare thread stack. */ -struct stack { - LIST_ENTRY(stack) qe; /* Stack queue linkage. */ - size_t stacksize; /* Stack size (rounded up). */ - size_t guardsize; /* Guard size. */ - void *stackaddr; /* Stack address. */ -}; - -/* - * Default sized (stack and guard) spare stack queue. Stacks are cached to - * avoid additional complexity managing mmap()ed stack regions. Spare stacks - * are used in LIFO order to increase cache locality. - */ -static LIST_HEAD(, stack) _dstackq = LIST_HEAD_INITIALIZER(_dstackq); - -/* - * Miscellaneous sized (non-default stack and/or guard) spare stack queue. - * Stacks are cached to avoid additional complexity managing mmap()ed stack - * regions. This list is unordered, since ordering on both stack size and guard - * size would be more trouble than it's worth. Stacks are allocated from this - * cache on a first size match basis. - */ -static LIST_HEAD(, stack) _mstackq = LIST_HEAD_INITIALIZER(_mstackq); - -/** - * Base address of the last stack allocated (including its red zone, if there is - * one). Stacks are allocated contiguously, starting beyond the top of the main - * stack. When a new stack is created, a red zone is typically created - * (actually, the red zone is simply left unmapped) above the top of the stack, - * such that the stack will not be able to grow all the way to the bottom of the - * next stack. This isn't fool-proof. It is possible for a stack to grow by a - * large amount, such that it grows into the next stack, and as long as the - * memory within the red zone is never accessed, nothing will prevent one thread - * stack from trouncing all over the next. - * - * low memory - * . . . . . . . . . . . . . . . . . . - * | | - * | stack 3 | start of 3rd thread stack - * +-----------------------------------+ - * | | - * | Red Zone (guard page) | red zone for 2nd thread - * | | - * +-----------------------------------+ - * | stack 2 - _pthread_stack_default | top of 2nd thread stack - * | | - * | | - * | | - * | | - * | stack 2 | - * +-----------------------------------+ <-- start of 2nd thread stack - * | | - * | Red Zone | red zone for 1st thread - * | | - * +-----------------------------------+ - * | stack 1 - _pthread_stack_default | top of 1st thread stack - * | | - * | | - * | | - * | | - * | stack 1 | - * +-----------------------------------+ <-- start of 1st thread stack - * | | (initial value of last_stack) - * | Red Zone | - * | | red zone for main thread - * +-----------------------------------+ - * | USRSTACK - _pthread_stack_initial | top of main thread stack - * | | ^ - * | | | - * | | | - * | | | stack growth - * | | - * +-----------------------------------+ <-- start of main thread stack - * (USRSTACK) - * high memory - * - */ -static void * last_stack; - -void * -_thread_stack_alloc(size_t stacksize, size_t guardsize) -{ - void *stack = NULL; - struct stack *spare_stack; - size_t stack_size; - - /* - * Round up stack size to nearest multiple of _pthread_page_size, - * so that mmap() * will work. If the stack size is not an even - * multiple, we end up initializing things such that there is unused - * space above the beginning of the stack, so the stack sits snugly - * against its guard. - */ - if (stacksize % _pthread_page_size != 0) - stack_size = ((stacksize / _pthread_page_size) + 1) * - _pthread_page_size; - else - stack_size = stacksize; - - /* - * If the stack and guard sizes are default, try to allocate a stack - * from the default-size stack cache: - */ - if (stack_size == _pthread_stack_default && - guardsize == _pthread_guard_default) { - /* - * Use the garbage collector mutex for synchronization of the - * spare stack list. - */ - if (_pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - if ((spare_stack = LIST_FIRST(&_dstackq)) != NULL) { - /* Use the spare stack. */ - LIST_REMOVE(spare_stack, qe); - stack = spare_stack->stackaddr; - } - - /* Unlock the garbage collector mutex. */ - if (_pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - } - /* - * The user specified a non-default stack and/or guard size, so try to - * allocate a stack from the non-default size stack cache, using the - * rounded up stack size (stack_size) in the search: - */ - else { - /* - * Use the garbage collector mutex for synchronization of the - * spare stack list. - */ - if (_pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - LIST_FOREACH(spare_stack, &_mstackq, qe) { - if (spare_stack->stacksize == stack_size && - spare_stack->guardsize == guardsize) { - LIST_REMOVE(spare_stack, qe); - stack = spare_stack->stackaddr; - break; - } - } - - /* Unlock the garbage collector mutex. */ - if (_pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - } - - /* Check if a stack was not allocated from a stack cache: */ - if (stack == NULL) { - - if (last_stack == NULL) - last_stack = _usrstack - _pthread_stack_initial - - _pthread_guard_default; - - /* Allocate a new stack. */ - stack = last_stack - stack_size; - - /* - * Even if stack allocation fails, we don't want to try to use - * this location again, so unconditionally decrement - * last_stack. Under normal operating conditions, the most - * likely reason for an mmap() error is a stack overflow of the - * adjacent thread stack. - */ - last_stack -= (stack_size + guardsize); - - /* Stack: */ - if (mmap(stack, stack_size, PROT_READ | PROT_WRITE, MAP_STACK, - -1, 0) == MAP_FAILED) - stack = NULL; - } - - return (stack); -} - -/* This function must be called with _gc_mutex held. */ -void -_thread_stack_free(void *stack, size_t stacksize, size_t guardsize) -{ - struct stack *spare_stack; - - spare_stack = (stack + stacksize - sizeof(struct stack)); - /* Round stacksize up to nearest multiple of _pthread_page_size. */ - if (stacksize % _pthread_page_size != 0) { - spare_stack->stacksize = - ((stacksize / _pthread_page_size) + 1) * - _pthread_page_size; - } else - spare_stack->stacksize = stacksize; - spare_stack->guardsize = guardsize; - spare_stack->stackaddr = stack; - - if (spare_stack->stacksize == _pthread_stack_default && - spare_stack->guardsize == _pthread_guard_default) { - /* Default stack/guard size. */ - LIST_INSERT_HEAD(&_dstackq, spare_stack, qe); - } else { - /* Non-default stack/guard size. */ - LIST_INSERT_HEAD(&_mstackq, spare_stack, qe); - } -} diff --git a/lib/libc_r/uthread/uthread_suspend_np.c b/lib/libc_r/uthread/uthread_suspend_np.c deleted file mode 100644 index 5892031..0000000 --- a/lib/libc_r/uthread/uthread_suspend_np.c +++ /dev/null @@ -1,101 +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 <pthread.h> -#include "pthread_private.h" - -static void suspend_common(struct pthread *thread); - -__weak_reference(_pthread_suspend_np, pthread_suspend_np); -__weak_reference(_pthread_suspend_all_np, pthread_suspend_all_np); - -/* Suspend a thread: */ -int -_pthread_suspend_np(pthread_t thread) -{ - int ret; - - /* Suspending the current thread doesn't make sense. */ - if (thread == _get_curthread()) - ret = EDEADLK; - - /* Find the thread in the list of active threads: */ - else if ((ret = _find_thread(thread)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - suspend_common(thread); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - return (ret); -} - -void -_pthread_suspend_all_np(void) -{ - struct pthread *curthread = _get_curthread(); - struct pthread *thread; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - TAILQ_FOREACH(thread, &_thread_list, tle) { - if (thread != curthread) - suspend_common(thread); - } - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); -} - -void -suspend_common(struct pthread *thread) -{ - thread->flags |= PTHREAD_FLAGS_SUSPENDED; - if (thread->flags & PTHREAD_FLAGS_IN_PRIOQ) { - PTHREAD_PRIOQ_REMOVE(thread); - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - } -} diff --git a/lib/libc_r/uthread/uthread_switch_np.c b/lib/libc_r/uthread/uthread_switch_np.c deleted file mode 100644 index f24d99f..0000000 --- a/lib/libc_r/uthread/uthread_switch_np.c +++ /dev/null @@ -1,71 +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_np.h> -#include "pthread_private.h" - - -__weak_reference(_pthread_switch_add_np, pthread_switch_add_np); -__weak_reference(_pthread_switch_delete_np, pthread_switch_delete_np); - -int -_pthread_switch_add_np(pthread_switch_routine_t routine) -{ - int ret = 0; - - if (routine == NULL) - /* Return an invalid argument error: */ - ret = EINVAL; - else - /* Shouldn't need a lock to protect this assigment. */ - _sched_switch_hook = routine; - - return(ret); -} - -int -_pthread_switch_delete_np(pthread_switch_routine_t routine) -{ - int ret = 0; - - if (routine != _sched_switch_hook) - /* Return an invalid argument error: */ - ret = EINVAL; - else - /* Shouldn't need a lock to protect this assigment. */ - _sched_switch_hook = NULL; - - return(ret); -} diff --git a/lib/libc_r/uthread/uthread_system.c b/lib/libc_r/uthread/uthread_system.c deleted file mode 100644 index d63969b..0000000 --- a/lib/libc_r/uthread/uthread_system.c +++ /dev/null @@ -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 <stdlib.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_system, system); - -int -_system(const char *string) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = __system(string); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_tcdrain.c b/lib/libc_r/uthread/uthread_tcdrain.c deleted file mode 100644 index 272bdf6..0000000 --- a/lib/libc_r/uthread/uthread_tcdrain.c +++ /dev/null @@ -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 <termios.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_tcdrain, tcdrain); - -int -_tcdrain(int fd) -{ - int ret; - - _thread_enter_cancellation_point(); - ret = __tcdrain(fd); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_vfork.c b/lib/libc_r/uthread/uthread_vfork.c deleted file mode 100644 index dbefc65..0000000 --- a/lib/libc_r/uthread/uthread_vfork.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * $FreeBSD$ - */ -#include <unistd.h> - -__weak_reference(_vfork, vfork); - -int -_vfork(void) -{ - return (fork()); -} diff --git a/lib/libc_r/uthread/uthread_wait.c b/lib/libc_r/uthread/uthread_wait.c deleted file mode 100644 index e61138b..0000000 --- a/lib/libc_r/uthread/uthread_wait.c +++ /dev/null @@ -1,47 +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 <pthread.h> -#include "pthread_private.h" - -__weak_reference(_wait, wait); - -pid_t -_wait(int *istat) -{ - pid_t ret; - - _thread_enter_cancellation_point(); - ret = __wait(istat); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_wait4.c b/lib/libc_r/uthread/uthread_wait4.c deleted file mode 100644 index 2c8fc56..0000000 --- a/lib/libc_r/uthread/uthread_wait4.c +++ /dev/null @@ -1,79 +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 <errno.h> -#include <sys/wait.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__wait4, wait4); - -pid_t -_wait4(pid_t pid, int *istat, int options, struct rusage * rusage) -{ - struct pthread *curthread = _get_curthread(); - pid_t ret; - - _thread_kern_sig_defer(); - - /* Perform a non-blocking wait4 syscall: */ - while ((ret = __sys_wait4(pid, istat, options | WNOHANG, rusage)) == 0 && (options & WNOHANG) == 0) { - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - /* Schedule the next thread while this one waits: */ - _thread_kern_sched_state(PS_WAIT_WAIT, __FILE__, __LINE__); - - /* Check if this call was interrupted by a signal: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } - - _thread_kern_sig_undefer(); - - return (ret); -} - -pid_t -__wait4(pid_t pid, int *istat, int options, struct rusage *rusage) -{ - pid_t ret; - - _thread_enter_cancellation_point(); - ret = _wait4(pid, istat, options, rusage); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_waitpid.c b/lib/libc_r/uthread/uthread_waitpid.c deleted file mode 100644 index fcbbc9f..0000000 --- a/lib/libc_r/uthread/uthread_waitpid.c +++ /dev/null @@ -1,49 +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 <sys/types.h> -#include <sys/wait.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(_waitpid, waitpid); - -pid_t -_waitpid(pid_t wpid, int *status, int options) -{ - pid_t ret; - - _thread_enter_cancellation_point(); - ret = __waitpid(wpid, status, options); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_write.c b/lib/libc_r/uthread/uthread_write.c deleted file mode 100644 index d9e6c84..0000000 --- a/lib/libc_r/uthread/uthread_write.c +++ /dev/null @@ -1,162 +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/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__write, write); - -ssize_t -_write(int fd, const void *buf, size_t nbytes) -{ - struct pthread *curthread = _get_curthread(); - int blocking; - int type; - ssize_t n; - ssize_t num = 0; - ssize_t ret; - - /* POSIX says to do just this: */ - if (nbytes == 0) - return (0); - - /* Lock the file descriptor for write: */ - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_getflags(fd) & O_ACCMODE; - - /* Check if the file is not open for write: */ - if (type != O_WRONLY && type != O_RDWR) { - /* File is not open for write: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_WRITE); - return (-1); - } - - /* Check if file operations are to block */ - blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0); - - /* - * Loop while no error occurs and until the expected number - * of bytes are written if performing a blocking write: - */ - while (ret == 0) { - /* Perform a non-blocking write syscall: */ - n = __sys_write(fd, (const char *)buf + num, - nbytes - num); - - /* Check if one or more bytes were written: */ - if (n > 0) - /* - * Keep a count of the number of bytes - * written: - */ - num += n; - - /* - * If performing a blocking write, check if the - * write would have blocked or if some bytes - * were written but there are still more to - * write: - */ - if (blocking && ((n < 0 && (errno == EWOULDBLOCK || - errno == EAGAIN)) || (n > 0 && num < nbytes))) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(NULL); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - _thread_kern_sched_state(PS_FDW_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted) { - if (num > 0) { - /* Return partial success: */ - ret = num; - } else { - /* Return an error: */ - errno = EINTR; - ret = -1; - } - } - - /* - * If performing a non-blocking write, - * just return whatever the write syscall did: - */ - } else if (!blocking) { - /* A non-blocking call might return zero: */ - ret = n; - break; - - /* - * If there was an error, return partial success - * (if any bytes were written) or else the error: - */ - } else if (n <= 0) { - if (num > 0) - ret = num; - else - ret = n; - if (n == 0) - break; - - /* Check if the write has completed: */ - } else if (num >= nbytes) - /* Return the number of bytes written: */ - ret = num; - } - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} - -ssize_t -__write(int fd, const void *buf, size_t nbytes) -{ - ssize_t ret; - - _thread_enter_cancellation_point(); - ret = _write(fd, buf, nbytes); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c deleted file mode 100644 index ca57607..0000000 --- a/lib/libc_r/uthread/uthread_writev.c +++ /dev/null @@ -1,230 +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/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <pthread.h> -#include "pthread_private.h" - -__weak_reference(__writev, writev); - -ssize_t -_writev(int fd, const struct iovec * iov, int iovcnt) -{ - struct pthread *curthread = _get_curthread(); - int blocking; - int idx = 0; - int type; - ssize_t cnt; - ssize_t n; - ssize_t num = 0; - ssize_t ret; - struct iovec liov[20]; - struct iovec *p_iov = liov; - - /* Check if the array size exceeds to compiled in size: */ - if (iovcnt > (sizeof(liov) / sizeof(struct iovec))) { - /* Allocate memory for the local array: */ - if ((p_iov = (struct iovec *) - malloc(iovcnt * sizeof(struct iovec))) == NULL) { - /* Insufficient memory: */ - errno = ENOMEM; - return (-1); - } - } - - /* Copy the caller's array so that it can be modified locally: */ - memcpy(p_iov,iov,iovcnt * sizeof(struct iovec)); - - /* Lock the file descriptor for write: */ - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_getflags(fd) & O_ACCMODE; - - /* Check if the file is not open for write: */ - if (type != O_WRONLY && type != O_RDWR) { - /* File is not open for write: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_WRITE); - return (-1); - } - - /* Check if file operations are to block */ - blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0); - - /* - * Loop while no error occurs and until the expected number - * of bytes are written if performing a blocking write: - */ - while (ret == 0) { - /* Perform a non-blocking write syscall: */ - n = __sys_writev(fd, &p_iov[idx], iovcnt - idx); - - /* Check if one or more bytes were written: */ - if (n > 0) { - /* - * Keep a count of the number of bytes - * written: - */ - num += n; - - /* - * Enter a loop to check if a short write - * occurred and move the index to the - * array entry where the short write - * ended: - */ - cnt = n; - while (cnt > 0 && idx < iovcnt) { - /* - * If the residual count exceeds - * the size of this vector, then - * it was completely written: - */ - if (cnt >= p_iov[idx].iov_len) - /* - * Decrement the residual - * count and increment the - * index to the next array - * entry: - */ - cnt -= p_iov[idx++].iov_len; - else { - /* - * This entry was only - * partially written, so - * adjust it's length - * and base pointer ready - * for the next write: - */ - p_iov[idx].iov_len -= cnt; - p_iov[idx].iov_base = - (char *)p_iov[idx].iov_base - + cnt; - cnt = 0; - } - } - } else if (n == 0) { - /* - * Avoid an infinite loop if the last iov_len is - * 0. - */ - while (idx < iovcnt && p_iov[idx].iov_len == 0) - idx++; - - if (idx == iovcnt) { - ret = num; - break; - } - } - - /* - * If performing a blocking write, check if the - * write would have blocked or if some bytes - * were written but there are still more to - * write: - */ - if (blocking && ((n < 0 && (errno == EWOULDBLOCK || - errno == EAGAIN)) || (n >= 0 && idx < iovcnt))) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(NULL); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - _thread_kern_sched_state(PS_FDW_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted) { - if (num > 0) { - /* Return partial success: */ - ret = num; - } else { - /* Return an error: */ - errno = EINTR; - ret = -1; - } - } - - /* - * If performing a non-blocking write, - * just return whatever the write syscall did: - */ - } else if (!blocking) { - /* A non-blocking call might return zero: */ - ret = n; - break; - - /* - * If there was an error, return partial success - * (if any bytes were written) or else the error: - */ - } else if (n < 0) { - if (num > 0) - ret = num; - else - ret = n; - - /* Check if the write has completed: */ - } else if (idx == iovcnt) - /* Return the number of bytes written: */ - ret = num; - } - _FD_UNLOCK(fd, FD_RDWR); - } - - /* If memory was allocated for the array, free it: */ - if (p_iov != liov) - free(p_iov); - - return (ret); -} - -ssize_t -__writev(int fd, const struct iovec *iov, int iovcnt) -{ - ssize_t ret; - - _thread_enter_cancellation_point(); - ret = _writev(fd, iov, iovcnt); - _thread_leave_cancellation_point(); - - return ret; -} diff --git a/lib/libc_r/uthread/uthread_yield.c b/lib/libc_r/uthread/uthread_yield.c deleted file mode 100644 index 414ff05..0000000 --- a/lib/libc_r/uthread/uthread_yield.c +++ /dev/null @@ -1,63 +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(_sched_yield, sched_yield); -__weak_reference(_pthread_yield, pthread_yield); - -int -_sched_yield(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Reset the accumulated time slice value for the current thread: */ - curthread->slice_usec = -1; - - /* Schedule the next thread: */ - _thread_kern_sched(NULL); - - /* Always return no error. */ - return(0); -} - -/* Draft 4 yield */ -void -_pthread_yield(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Reset the accumulated time slice value for the current thread: */ - curthread->slice_usec = -1; - - /* Schedule the next thread: */ - _thread_kern_sched(NULL); -} diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 5767cb2..3b8d567 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -800,6 +800,10 @@ libusb_free_transfer(struct libusb_transfer *uxfer) if (uxfer == NULL) return; /* be NULL safe */ + /* check if we should free the transfer buffer */ + if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER) + free(uxfer->buffer); + sxfer = (struct libusb_super_transfer *)( (uint8_t *)uxfer - sizeof(*sxfer)); diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 48405c9..380e312 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -187,6 +187,8 @@ do_done: /* Do all done callbacks */ while ((sxfer = TAILQ_FIRST(&ctx->tr_done))) { + uint8_t flags; + TAILQ_REMOVE(&ctx->tr_done, sxfer, entry); sxfer->entry.tqe_prev = NULL; @@ -197,13 +199,14 @@ do_done: uxfer = (struct libusb_transfer *)( ((uint8_t *)sxfer) + sizeof(*sxfer)); + /* Allow the callback to free the transfer itself. */ + flags = uxfer->flags; + if (uxfer->callback != NULL) (uxfer->callback) (uxfer); - if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER) - free(uxfer->buffer); - - if (uxfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER) + /* Check if the USB transfer should be automatically freed. */ + if (flags & LIBUSB_TRANSFER_FREE_TRANSFER) libusb_free_transfer(uxfer); CTX_LOCK(ctx); diff --git a/lib/msun/src/e_jn.c b/lib/msun/src/e_jn.c index e277e30..8b0bc62 100644 --- a/lib/msun/src/e_jn.c +++ b/lib/msun/src/e_jn.c @@ -200,7 +200,12 @@ __ieee754_jn(int n, double x) } } } - b = (t*__ieee754_j0(x)/b); + z = __ieee754_j0(x); + w = __ieee754_j1(x); + if (fabs(z) >= fabs(w)) + b = (t*z/b); + else + b = (t*w/a); } } if(sgn==1) return -b; else return b; diff --git a/lib/msun/src/e_jnf.c b/lib/msun/src/e_jnf.c index 3bbf7b7..f564aec 100644 --- a/lib/msun/src/e_jnf.c +++ b/lib/msun/src/e_jnf.c @@ -152,7 +152,12 @@ __ieee754_jnf(int n, float x) } } } - b = (t*__ieee754_j0f(x)/b); + z = __ieee754_j0f(x); + w = __ieee754_j1f(x); + if (fabsf(z) >= fabsf(w)) + b = (t*z/b); + else + b = (t*w/a); } } if(sgn==1) return -b; else return b; diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile index 54caad6..bc7ef13 100644 --- a/rescue/rescue/Makefile +++ b/rescue/rescue/Makefile @@ -22,27 +22,7 @@ dhclient_FIXED: ../../sbin/dhclient/dhclient-script sed '1s/\/bin\//\/rescue\//' ${.ALLSRC} > ${.TARGET} CLEANFILES+= dhclient_FIXED -################################################################# -# -# General notes: -# -# A number of Make variables are used to generate the crunchgen config file. -# -# CRUNCH_SRCDIRS: lists directories to search for included programs -# CRUNCH_PROGS: lists programs to be included -# CRUNCH_LIBS: libraries to link with -# CRUNCH_BUILDOPTS: generic build options to be added to every program -# -# Special options can be specified for individual programs -# CRUNCH_SRCDIR_$(P): base source directory for program $(P) -# CRUNCH_BUILDOPTS_$(P): additional build options for $(P) -# CRUNCH_ALIAS_$(P): additional names to be used for $(P) -# -# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} -# will be used to generate a hard link to the resulting binary. -# Specific links can be suppressed by setting -# CRUNCH_SUPPRESS_LINK_$(NAME) to 1. -# +# The help which used to be here is now in mk/bsd.crunchgen.mk # Define Makefile variable RESCUE CRUNCH_BUILDOPTS+= -DRESCUE @@ -73,6 +53,7 @@ CRUNCH_PROGS_bin= cat chflags chio chmod cp date dd df echo \ ed expr getfacl hostname kenv kill ln ls mkdir mv \ pkill ps pwd realpath rm rmdir setfacl sh stty sync test CRUNCH_LIBS+= -lcrypt -ledit -lkvm -ll -ltermcap -lutil +CRUNCH_BUILDTOOLS+= bin/sh # Additional options for specific programs CRUNCH_ALIAS_test= [ @@ -91,6 +72,7 @@ CRUNCH_PROGS_bin+= rcp .if ${MK_TCSH} != "no" CRUNCH_PROGS_bin+= csh CRUNCH_ALIAS_csh= -csh tcsh -tcsh +CRUNCH_BUILDTOOLS+= bin/csh CRUNCH_SUPPRESS_LINK_-csh= 1 CRUNCH_SUPPRESS_LINK_-tcsh= 1 .endif @@ -236,132 +218,5 @@ CRUNCH_ALIAS_chown= chgrp ################################################################## CRUNCH_LIBS+= -lm -################################################################## -# The following is pretty nearly a generic crunchgen-handling makefile -# - -CONF= $(PROG).conf -OUTMK= $(PROG).mk -OUTC= $(PROG).c -OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache -CRUNCHOBJS= ${.OBJDIR} -.if defined(MAKEOBJDIRPREFIX) -CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} -.else -CANONICALOBJDIR:= /usr/obj${.CURDIR} -.endif - -CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h - -# Program names and their aliases contribute hardlinks to 'rescue' executable, -# except for those that get suppressed. -.for D in $(CRUNCH_SRCDIRS) -.for P in $(CRUNCH_PROGS_$(D)) -.ifdef CRUNCH_SRCDIR_${P} -$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile -.else -$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile -.endif -.ifndef CRUNCH_SUPPRESS_LINK_${P} -LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P) -.endif -.for A in $(CRUNCH_ALIAS_$(P)) -.ifndef CRUNCH_SUPPRESS_LINK_${A} -LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A) -.endif -.endfor -.endfor -.endfor - -all: $(PROG) -exe: $(PROG) - -$(CONF): Makefile - echo \# Auto-generated, do not edit >$(.TARGET) -.ifdef CRUNCH_BUILDOPTS - echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET) -.endif -.ifdef CRUNCH_LIBS - echo libs $(CRUNCH_LIBS) >>$(.TARGET) -.endif -.for D in $(CRUNCH_SRCDIRS) -.for P in $(CRUNCH_PROGS_$(D)) - echo progs $(P) >>$(.TARGET) -.ifdef CRUNCH_SRCDIR_${P} - echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET) -.else - echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET) -.endif -.ifdef CRUNCH_BUILDOPTS_${P} - echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \ - $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET) -.else - echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET) -.endif -.for A in $(CRUNCH_ALIAS_$(P)) - echo ln $(P) $(A) >>$(.TARGET) -.endfor -.endfor -.endfor - -# XXX Make sure we don't pass -P to crunchgen(1). -.MAKEFLAGS:= ${.MAKEFLAGS:N-P} -.ORDER: $(OUTPUTS) objs -$(OUTPUTS): $(CONF) - MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \ - -c $(OUTC) $(CONF) - -$(PROG): $(OUTPUTS) objs - MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe - -objs: $(OUTMK) - MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs - -# <sigh> Someone should replace the bin/csh and bin/sh build-tools with -# shell scripts so we can remove this nonsense. -build-tools: -.for _tool in bin/csh bin/sh - cd $(.CURDIR)/../../${_tool}; \ - MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ - MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools -.endfor - -# Use a separate build tree to hold files compiled for this crunchgen binary -# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't -# get that to cooperate with bsd.prog.mk. Besides, many of the standard -# targets should NOT be propagated into the components. -cleandepend cleandir obj objlink: -.for D in $(CRUNCH_SRCDIRS) -.for P in $(CRUNCH_PROGS_$(D)) -.ifdef CRUNCH_SRCDIR_${P} - cd ${CRUNCH_SRCDIR_$(P)} && \ - MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ - DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} -.else - cd $(.CURDIR)/../../${D}/${P} && \ - MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ - DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} -.endif -.endfor -.endfor - -clean: - rm -f ${CLEANFILES} - if [ -e ${.OBJDIR}/$(OUTMK) ]; then \ - MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \ - fi -.for D in $(CRUNCH_SRCDIRS) -.for P in $(CRUNCH_PROGS_$(D)) -.ifdef CRUNCH_SRCDIR_${P} - cd ${CRUNCH_SRCDIR_$(P)} && \ - MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ - DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} -.else - cd $(.CURDIR)/../../${D}/${P} && \ - MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ - DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} -.endif -.endfor -.endfor - +.include <bsd.crunchgen.mk> .include <bsd.prog.mk> diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c index bb95043..889c54a 100644 --- a/sbin/ifconfig/ifmedia.c +++ b/sbin/ifconfig/ifmedia.c @@ -276,7 +276,7 @@ setmedia(const char *val, int d, int s, const struct afswtch *afp) IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; if ((ifr.ifr_media & IFM_TMASK) == 0) { - ifr.ifr_media &= ~IFM_GMASK; + ifr.ifr_media &= ~(IFM_GMASK | IFM_OMASK); } ifmr->ifm_current = ifr.ifr_media; @@ -757,7 +757,7 @@ print_media_word_ifconfig(int ifmw) { struct ifmedia_description *desc; struct ifmedia_type_to_subtype *ttos; - int i; + int seen_option = 0, i; /* Find the top-level interface type. */ desc = get_toptype_desc(ifmw); @@ -792,7 +792,10 @@ print_media_word_ifconfig(int ifmw) for (desc = ttos->options[i].desc; desc->ifmt_string != NULL; desc++) { if (ifmw & desc->ifmt_word) { - printf(" mediaopt %s", desc->ifmt_string); + if (seen_option == 0) + printf(" mediaopt "); + printf("%s%s", seen_option++ ? "," : "", + desc->ifmt_string); } } } diff --git a/sbin/kldstat/kldstat.c b/sbin/kldstat/kldstat.c index 78182b9..575fca8 100644 --- a/sbin/kldstat/kldstat.c +++ b/sbin/kldstat/kldstat.c @@ -50,14 +50,15 @@ printmod(int modid) printf("\t\t%2d %s\n", stat.id, stat.name); } -static void printfile(int fileid, int verbose) +static void +printfile(int fileid, int verbose) { struct kld_file_stat stat; int modid; stat.version = sizeof(struct kld_file_stat); if (kldstat(fileid, &stat) < 0) - warn("can't stat file id %d", fileid); + err(1, "can't stat file id %d", fileid); else printf("%2d %4d %p %-8zx %s", stat.id, stat.refs, stat.address, stat.size, diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 0288474..5998de5 100644 --- a/sbin/mdconfig/mdconfig.8 +++ b/sbin/mdconfig/mdconfig.8 @@ -58,7 +58,7 @@ .Op Fl S Ar sectorsize .Op Fl u Ar unit .Op Fl x Ar sectors/track -.Op Fl y Ar heads/cyl +.Op Fl y Ar heads/cylinder .Nm .Fl d .Fl u Ar unit diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index a564484..2217c6c 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -57,7 +57,7 @@ usage(void) fprintf(stderr, "usage: mdconfig -a -t type [-n] [-o [no]option] ... [-f file]\n" " [-s size] [-S sectorsize] [-u unit]\n" -" [-x sectors/track] [-y heads/cyl]\n" +" [-x sectors/track] [-y heads/cylinder]\n" " mdconfig -d -u unit [-o [no]force]\n" " mdconfig -l [-v] [-n] [-u unit]\n"); fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n"); diff --git a/share/man/man5/periodic.conf.5 b/share/man/man5/periodic.conf.5 index a3775d8..3213615 100644 --- a/share/man/man5/periodic.conf.5 +++ b/share/man/man5/periodic.conf.5 @@ -482,6 +482,14 @@ Set to .Dq Li YES to compare the modes and modification times of setuid executables with the previous day's values. +.It Va daily_status_security_neggrpperm_enable +.Pq Vt bool +Set to +.Dq Li YES +to check for files where the group of a file has less permissions than +the world at large. +When users are in more than 14 supplemental groups these negative +permissions may not be enforced via NFS shares. .It Va daily_status_security_chkmounts_enable .Pq Vt bool Set to diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index a884bff..2a4ff49 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 13, 2010 +.Dd November 13, 2010 .Dt RC.CONF 5 .Os .Sh NAME @@ -4082,65 +4082,6 @@ one could set the following: .Bd -literal mdconfig_md0_cmd="tar xfzC /var/file.tgz \e${_mp}" .Ed -.It Va ramdisk_units -.Pq Vt str -A list of one or more ramdisk units to configure with -.Xr mdconfig 8 -and -.Xr newfs 8 -in time to be mounted from -.Xr fstab 5 . -Each listed unit -.Ar X -must specify at least a -.Ar type -in a -.Va ramdisk_ Ns Ao Ar X Ac Ns Va _config -variable. -Note that this way to configure ramdisks has been deprecated -in favor of new -.Va mdconfig_md* -variables (see above). -.It Va ramdisk_ Ns Ao Ar X Ac Ns Va _config -.Pq Vt str -Arguments to -.Xr mdconfig 8 -for ramdisk -.Ar X . -At minimum a -.Fl t Ar type -must be specified, where -.Ar type -must be one of -.Cm malloc -or -.Cm swap . -.It Va ramdisk_ Ns Ao Ar X Ac Ns Va _newfs -.Pq Vt str -Optional arguments passed to -.Xr newfs 8 -to initialize ramdisk -.Ar X . -.It Va ramdisk_ Ns Ao Ar X Ac Ns Va _owner -.Pq Vt str -An ownership specification passed to -.Xr chown 8 -after the specified ramdisk unit -.Ar X -has been mounted. -Both the -.Xr md 4 -device and the mount point will be changed. -.It Va ramdisk_ Ns Ao Ar X Ac Ns Va _perms -.Pq Vt str -A mode string passed to -.Xr chmod 1 -after the specified ramdisk unit -.Ar X -has been mounted. -Both the -.Xr md 4 -device and the mount point will be changed. .It Va autobridge_interfaces .Pq Vt str Set to the list of bridge interfaces that will have newly arriving interfaces diff --git a/share/mk/bsd.crunchgen.mk b/share/mk/bsd.crunchgen.mk new file mode 100644 index 0000000..565b112 --- /dev/null +++ b/share/mk/bsd.crunchgen.mk @@ -0,0 +1,160 @@ +################################################################# +# +# General notes: +# +# A number of Make variables are used to generate the crunchgen config file. +# +# CRUNCH_SRCDIRS: lists directories to search for included programs +# CRUNCH_PROGS: lists programs to be included +# CRUNCH_LIBS: libraries to statically link with +# CRUNCH_SHLIBS: libraries to dynamically link with +# CRUNCH_BUILDOPTS: generic build options to be added to every program +# CRUNCH_BUILDTOOLS: lists programs that need build tools built in the +# local architecture. +# +# Special options can be specified for individual programs +# CRUNCH_SRCDIR_$(P): base source directory for program $(P) +# CRUNCH_BUILDOPTS_$(P): additional build options for $(P) +# CRUNCH_ALIAS_$(P): additional names to be used for $(P) +# +# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} +# will be used to generate a hard link to the resulting binary. +# Specific links can be suppressed by setting +# CRUNCH_SUPPRESS_LINK_$(NAME) to 1. +# + +# $FreeBSD$ + +################################################################## +# The following is pretty nearly a generic crunchgen-handling makefile +# + +CONF= $(PROG).conf +OUTMK= $(PROG).mk +OUTC= $(PROG).c +OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache +CRUNCHOBJS= ${.OBJDIR} +.if defined(MAKEOBJDIRPREFIX) +CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} +.else +CANONICALOBJDIR:= /usr/obj${.CURDIR} +.endif + +CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h + +# Program names and their aliases contribute hardlinks to 'rescue' executable, +# except for those that get suppressed. +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} +$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile +.else +$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile +.endif +# Disable building links for bsdbox - whatever is installing the binaries into +# the embedded system should (for now) do the linking there. This may change +# in the future. -adrian +#.ifndef CRUNCH_SUPPRESS_LINK_${P} +#LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P) +#.endif +#.for A in $(CRUNCH_ALIAS_$(P)) +#.ifndef CRUNCH_SUPPRESS_LINK_${A} +#LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A) +#.endif +#.endfor +.endfor +.endfor + +all: $(PROG) +exe: $(PROG) + +$(CONF): Makefile + echo \# Auto-generated, do not edit >$(.TARGET) +.ifdef CRUNCH_BUILDOPTS + echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET) +.endif +.ifdef CRUNCH_LIBS + echo libs $(CRUNCH_LIBS) >>$(.TARGET) +.endif +.ifdef CRUNCH_SHLIBS + echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET) +.endif +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) + echo progs $(P) >>$(.TARGET) +.ifdef CRUNCH_SRCDIR_${P} + echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET) +.else + echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET) +.endif +.ifdef CRUNCH_BUILDOPTS_${P} + echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \ + $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET) +.else + echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET) +.endif +.for A in $(CRUNCH_ALIAS_$(P)) + echo ln $(P) $(A) >>$(.TARGET) +.endfor +.endfor +.endfor + +# XXX Make sure we don't pass -P to crunchgen(1). +.MAKEFLAGS:= ${.MAKEFLAGS:N-P} +.ORDER: $(OUTPUTS) objs +$(OUTPUTS): $(CONF) + MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \ + -c $(OUTC) $(CONF) + +$(PROG): $(OUTPUTS) objs + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe + +objs: $(OUTMK) + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs + +# <sigh> Someone should replace the bin/csh and bin/sh build-tools with +# shell scripts so we can remove this nonsense. +build-tools: +.for _tool in $(CRUNCH_BUILDTOOLS) + cd $(.CURDIR)/../../${_tool}; \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools +.endfor + +# Use a separate build tree to hold files compiled for this crunchgen binary +# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't +# get that to cooperate with bsd.prog.mk. Besides, many of the standard +# targets should NOT be propagated into the components. +cleandepend cleandir obj objlink: +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} + cd ${CRUNCH_SRCDIR_$(P)} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.else + cd $(.CURDIR)/../../${D}/${P} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.endif +.endfor +.endfor + +clean: + rm -f ${CLEANFILES} + if [ -e ${.OBJDIR}/$(OUTMK) ]; then \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \ + fi +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} + cd ${CRUNCH_SRCDIR_$(P)} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.else + cd $(.CURDIR)/../../${D}/${P} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.endif +.endfor +.endfor diff --git a/sys/boot/i386/libi386/i386_module.c b/sys/boot/i386/libi386/i386_module.c index 4ddf5b2..78ab61b 100644 --- a/sys/boot/i386/libi386/i386_module.c +++ b/sys/boot/i386/libi386/i386_module.c @@ -32,12 +32,6 @@ __FBSDID("$FreeBSD$"); * */ -#include <stand.h> -#include <string.h> - -#include "bootstrap.h" -#include "libi386.h" - /* * Use voodoo to load modules required by current hardware. */ diff --git a/sys/boot/pc98/libpc98/i386_module.c b/sys/boot/pc98/libpc98/i386_module.c deleted file mode 100644 index d988b27..0000000 --- a/sys/boot/pc98/libpc98/i386_module.c +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * Copyright (c) 2003 TAKAHASHI Yoshihiro <nyan@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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -int -i386_autoload(void) -{ - - return 0; -} diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c index 30a1b315..09fcab3 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c @@ -1218,12 +1218,14 @@ zfs_mount(vfs_t *vfsp) error = zfs_domount(vfsp, osname); PICKUP_GIANT(); +#ifdef sun /* * Add an extra VFS_HOLD on our parent vfs so that it can't * disappear due to a forced unmount. */ if (error == 0 && ((zfsvfs_t *)vfsp->vfs_data)->z_issnap) VFS_HOLD(mvp->v_vfsp); +#endif /* sun */ out: return (error); @@ -1766,12 +1768,14 @@ zfs_freevfs(vfs_t *vfsp) { zfsvfs_t *zfsvfs = vfsp->vfs_data; +#ifdef sun /* * If this is a snapshot, we have an extra VFS_HOLD on our parent * from zfs_mount(). Release it here. */ if (zfsvfs->z_issnap) VFS_RELE(zfsvfs->z_parent->z_vfs); +#endif /* sun */ zfsvfs_free(zfsvfs); diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index c955507..c6a3260 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -239,13 +239,28 @@ dev/acpica/acpi_if.m standard dev/acpi_support/acpi_wmi_if.m standard dev/wpi/if_wpi.c optional wpi i386/acpica/acpi_machdep.c optional acpi -i386/acpica/acpi_wakeup.c optional acpi -acpi_wakecode.h optional acpi \ - dependency "$S/i386/acpica/acpi_wakecode.S assym.s" \ - compile-with "${MAKE} -f $S/i386/acpica/Makefile MAKESRCPATH=$S/i386/acpica" \ +acpi_wakecode.o optional acpi \ + dependency "$S/i386/acpica/acpi_wakecode.S assym.s" \ + compile-with "${NORMAL_S}" \ no-obj no-implicit-rule before-depend \ - clean "acpi_wakecode.h acpi_wakecode.o acpi_wakecode.bin" + clean "acpi_wakecode.o" +acpi_wakecode.bin optional acpi \ + dependency "acpi_wakecode.o" \ + compile-with "objcopy -S -O binary acpi_wakecode.o ${.TARGET}" \ + no-obj no-implicit-rule before-depend \ + clean "acpi_wakecode.bin" +acpi_wakecode.h optional acpi \ + dependency "acpi_wakecode.bin" \ + compile-with "file2c -sx 'static char wakecode[] = {' '};' < acpi_wakecode.bin > ${.TARGET}" \ + no-obj no-implicit-rule before-depend \ + clean "acpi_wakecode.h" +acpi_wakedata.h optional acpi \ + dependency "acpi_wakecode.o" \ + compile-with '${NM} -n --defined-only acpi_wakecode.o | while read offset dummy what; do echo "#define $${what} 0x$${offset}"; done > ${.TARGET}' \ + no-obj no-implicit-rule before-depend \ + clean "acpi_wakedata.h" # +i386/acpica/acpi_wakeup.c optional acpi i386/bios/apm.c optional apm i386/bios/mca_machdep.c optional mca i386/bios/smapi.c optional smapi diff --git a/sys/conf/ldscript.mips b/sys/conf/ldscript.mips index 0736fd1..232b79f 100644 --- a/sys/conf/ldscript.mips +++ b/sys/conf/ldscript.mips @@ -30,16 +30,9 @@ * $FreeBSD$ */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", - "elf32-tradlittlemips") - OUTPUT_ARCH(mips) ENTRY(_start) SEARCH_DIR(/usr/lib); -/* Do we need any of these for elf? - __DYNAMIC = 0; -PROVIDE (_DYNAMIC = 0); -*/ SECTIONS { /* Read-only sections, merged into text segment: */ diff --git a/sys/dev/arcmsr/arcmsr.c b/sys/dev/arcmsr/arcmsr.c index 418fd11..c175522 100644 --- a/sys/dev/arcmsr/arcmsr.c +++ b/sys/dev/arcmsr/arcmsr.c @@ -38,29 +38,32 @@ ** History ** ** REV# DATE NAME DESCRIPTION -** 1.00.00.00 3/31/2004 Erich Chen First release -** 1.20.00.02 11/29/2004 Erich Chen bug fix with arcmsr_bus_reset when PHY error -** 1.20.00.03 4/19/2005 Erich Chen add SATA 24 Ports adapter type support +** 1.00.00.00 3/31/2004 Erich Chen First release +** 1.20.00.02 11/29/2004 Erich Chen bug fix with arcmsr_bus_reset when PHY error +** 1.20.00.03 4/19/2005 Erich Chen add SATA 24 Ports adapter type support ** clean unused function -** 1.20.00.12 9/12/2005 Erich Chen bug fix with abort command handling, +** 1.20.00.12 9/12/2005 Erich Chen bug fix with abort command handling, ** firmware version check ** and firmware update notify for hardware bug fix ** handling if none zero high part physical address ** of srb resource -** 1.20.00.13 8/18/2006 Erich Chen remove pending srb and report busy +** 1.20.00.13 8/18/2006 Erich Chen remove pending srb and report busy ** add iop message xfer ** with scsi pass-through command ** add new device id of sas raid adapters ** code fit for SPARC64 & PPC -** 1.20.00.14 02/05/2007 Erich Chen bug fix for incorrect ccb_h.status report +** 1.20.00.14 02/05/2007 Erich Chen bug fix for incorrect ccb_h.status report ** and cause g_vfs_done() read write error -** 1.20.00.15 10/10/2007 Erich Chen support new RAID adapter type ARC120x -** 1.20.00.16 10/10/2009 Erich Chen Bug fix for RAID adapter type ARC120x +** 1.20.00.15 10/10/2007 Erich Chen support new RAID adapter type ARC120x +** 1.20.00.16 10/10/2009 Erich Chen Bug fix for RAID adapter type ARC120x ** bus_dmamem_alloc() with BUS_DMA_ZERO -** 1.20.00.17 07/15/2010 Ching Huang Added support ARC1880 -** report CAM_DEV_NOT_THERE instead of CAM_SEL_TIMEOUT when device failed, -** prevent cam_periph_error removing all LUN devices of one Target id -** for any one LUN device failed +** 1.20.00.17 07/15/2010 Ching Huang Added support ARC1880 +** report CAM_DEV_NOT_THERE instead of CAM_SEL_TIMEOUT when device failed, +** prevent cam_periph_error removing all LUN devices of one Target id +** for any one LUN device failed +** 1.20.00.18 10/14/2010 Ching Huang Fixed "inquiry data fails comparion at DV1 step" +** 10/25/2010 Ching Huang Fixed bad range input in bus_alloc_resource for ADAPTER_TYPE_B +** 1.20.00.19 11/11/2010 Ching Huang Fixed arcmsr driver prevent arcsas support for Areca SAS HBA ARC13x0 ****************************************************************************************** * $FreeBSD$ */ @@ -116,7 +119,7 @@ #define ARCMSR_LOCK_RELEASE(l) mtx_unlock(l) #define ARCMSR_LOCK_TRY(l) mtx_trylock(l) #define arcmsr_htole32(x) htole32(x) - typedef struct mtx arcmsr_lock_t; + typedef struct mtx arcmsr_lock_t; #else #include <sys/select.h> #include <pci/pcivar.h> @@ -134,13 +137,14 @@ #define CAM_NEW_TRAN_CODE 1 #endif +#define ARCMSR_DRIVER_VERSION "Driver Version 1.20.00.19 2010-11-11" #include <dev/arcmsr/arcmsr.h> #define ARCMSR_SRBS_POOL_SIZE ((sizeof(struct CommandControlBlock) * ARCMSR_MAX_FREESRB_NUM)) /* ************************************************************************** ************************************************************************** */ -#define CHIP_REG_READ32(s, b, r) bus_space_read_4(acb->btag[b], acb->bhandle[b], offsetof(struct s, r)) +#define CHIP_REG_READ32(s, b, r) bus_space_read_4(acb->btag[b], acb->bhandle[b], offsetof(struct s, r)) #define CHIP_REG_WRITE32(s, b, r, d) bus_space_write_4(acb->btag[b], acb->bhandle[b], offsetof(struct s, r), d) /* ************************************************************************** @@ -182,8 +186,8 @@ static void UDELAY(u_int32_t us) { DELAY(us); } ************************************************************************** ************************************************************************** */ -static bus_dmamap_callback_t arcmsr_map_freesrb; -static bus_dmamap_callback_t arcmsr_executesrb; +static bus_dmamap_callback_t arcmsr_map_free_srb; +static bus_dmamap_callback_t arcmsr_execute_srb; /* ************************************************************************** ************************************************************************** @@ -200,7 +204,7 @@ static device_method_t arcmsr_methods[]={ DEVMETHOD(device_suspend, arcmsr_suspend), DEVMETHOD(device_resume, arcmsr_resume), DEVMETHOD(bus_print_child, bus_generic_print_child), - DEVMETHOD(bus_driver_added, bus_generic_driver_added), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), { 0, 0 } }; @@ -226,29 +230,29 @@ static struct cdevsw arcmsr_cdevsw={ #if __FreeBSD_version > 502010 .d_version = D_VERSION, #endif - .d_flags = D_NEEDGIANT, - .d_open = arcmsr_open, /* open */ - .d_close = arcmsr_close, /* close */ - .d_ioctl = arcmsr_ioctl, /* ioctl */ - .d_name = "arcmsr", /* name */ + .d_flags = D_NEEDGIANT, + .d_open = arcmsr_open, /* open */ + .d_close = arcmsr_close, /* close */ + .d_ioctl = arcmsr_ioctl, /* ioctl */ + .d_name = "arcmsr", /* name */ }; #else #define ARCMSR_CDEV_MAJOR 180 static struct cdevsw arcmsr_cdevsw = { - arcmsr_open, /* open */ - arcmsr_close, /* close */ - noread, /* read */ - nowrite, /* write */ - arcmsr_ioctl, /* ioctl */ - nopoll, /* poll */ - nommap, /* mmap */ - nostrategy, /* strategy */ - "arcmsr", /* name */ - ARCMSR_CDEV_MAJOR, /* major */ - nodump, /* dump */ - nopsize, /* psize */ - 0 /* flags */ + arcmsr_open, /* open */ + arcmsr_close, /* close */ + noread, /* read */ + nowrite, /* write */ + arcmsr_ioctl, /* ioctl */ + nopoll, /* poll */ + nommap, /* mmap */ + nostrategy, /* strategy */ + "arcmsr", /* name */ + ARCMSR_CDEV_MAJOR, /* major */ + nodump, /* dump */ + nopsize, /* psize */ + 0 /* flags */ }; #endif /* @@ -259,9 +263,9 @@ static struct cdevsw arcmsr_cdevsw = { static int arcmsr_open(dev_t dev, int flags, int fmt, struct proc *proc) #else #if __FreeBSD_version < 503000 - static int arcmsr_open(dev_t dev, int flags, int fmt, struct thread *proc) + static int arcmsr_open(dev_t dev, int flags, int fmt, struct thread *proc) #else - static int arcmsr_open(struct cdev *dev, int flags, int fmt, struct thread *proc) + static int arcmsr_open(struct cdev *dev, int flags, int fmt, struct thread *proc) #endif #endif { @@ -284,9 +288,9 @@ static struct cdevsw arcmsr_cdevsw = { static int arcmsr_close(dev_t dev, int flags, int fmt, struct proc *proc) #else #if __FreeBSD_version < 503000 - static int arcmsr_close(dev_t dev, int flags, int fmt, struct thread *proc) + static int arcmsr_close(dev_t dev, int flags, int fmt, struct thread *proc) #else - static int arcmsr_close(struct cdev *dev, int flags, int fmt, struct thread *proc) + static int arcmsr_close(struct cdev *dev, int flags, int fmt, struct thread *proc) #endif #endif { @@ -309,9 +313,9 @@ static struct cdevsw arcmsr_cdevsw = { static int arcmsr_ioctl(dev_t dev, u_long ioctl_cmd, caddr_t arg, int flags, struct proc *proc) #else #if __FreeBSD_version < 503000 - static int arcmsr_ioctl(dev_t dev, u_long ioctl_cmd, caddr_t arg, int flags, struct thread *proc) + static int arcmsr_ioctl(dev_t dev, u_long ioctl_cmd, caddr_t arg, int flags, struct thread *proc) #else - static int arcmsr_ioctl(struct cdev *dev, u_long ioctl_cmd, caddr_t arg, int flags, struct thread *proc) + static int arcmsr_ioctl(struct cdev *dev, u_long ioctl_cmd, caddr_t arg, int flags, struct thread *proc) #endif #endif { @@ -345,7 +349,7 @@ static u_int32_t arcmsr_disable_allintr( struct AdapterControlBlock *acb) case ACB_ADAPTER_TYPE_B: { /* disable all outbound interrupt */ intmask_org=CHIP_REG_READ32(HBB_DOORBELL, - 0, iop2drv_doorbell_mask) & (~ARCMSR_IOP2DRV_MESSAGE_CMD_DONE); /* disable outbound message0 int */ + 0, iop2drv_doorbell_mask) & (~ARCMSR_IOP2DRV_MESSAGE_CMD_DONE); /* disable outbound message0 int */ CHIP_REG_WRITE32(HBB_DOORBELL, 0, iop2drv_doorbell_mask, 0); /* disable all interrupt */ } break; @@ -584,42 +588,6 @@ static void arcmsr_async(void *cb_arg, u_int32_t code, struct cam_path *path, vo ********************************************************************** ********************************************************************** */ -static void arcmsr_srb_complete(struct CommandControlBlock *srb, int stand_flag) -{ - struct AdapterControlBlock *acb=srb->acb; - union ccb * pccb=srb->pccb; - - if((pccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { - bus_dmasync_op_t op; - - if((pccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { - op = BUS_DMASYNC_POSTREAD; - } else { - op = BUS_DMASYNC_POSTWRITE; - } - bus_dmamap_sync(acb->dm_segs_dmat, srb->dm_segs_dmamap, op); - bus_dmamap_unload(acb->dm_segs_dmat, srb->dm_segs_dmamap); - } - if(stand_flag==1) { - atomic_subtract_int(&acb->srboutstandingcount, 1); - if((acb->acb_flags & ACB_F_CAM_DEV_QFRZN) && ( - acb->srboutstandingcount < ARCMSR_RELEASE_SIMQ_LEVEL)) { - acb->acb_flags &= ~ACB_F_CAM_DEV_QFRZN; - pccb->ccb_h.status |= CAM_RELEASE_SIMQ; - } - } - srb->startdone=ARCMSR_SRB_DONE; - srb->srb_flags=0; - acb->srbworkingQ[acb->workingsrb_doneindex]=srb; - acb->workingsrb_doneindex++; - acb->workingsrb_doneindex %= ARCMSR_MAX_FREESRB_NUM; - xpt_done(pccb); - return; -} -/* -********************************************************************** -********************************************************************** -*/ static void arcmsr_report_sense_info(struct CommandControlBlock *srb) { union ccb * pccb=srb->pccb; @@ -695,6 +663,42 @@ static void arcmsr_abort_allcmd(struct AdapterControlBlock *acb) return; } /* +********************************************************************** +********************************************************************** +*/ +static void arcmsr_srb_complete(struct CommandControlBlock *srb, int stand_flag) +{ + struct AdapterControlBlock *acb=srb->acb; + union ccb * pccb=srb->pccb; + + if((pccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { + bus_dmasync_op_t op; + + if((pccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { + op = BUS_DMASYNC_POSTREAD; + } else { + op = BUS_DMASYNC_POSTWRITE; + } + bus_dmamap_sync(acb->dm_segs_dmat, srb->dm_segs_dmamap, op); + bus_dmamap_unload(acb->dm_segs_dmat, srb->dm_segs_dmamap); + } + if(stand_flag==1) { + atomic_subtract_int(&acb->srboutstandingcount, 1); + if((acb->acb_flags & ACB_F_CAM_DEV_QFRZN) && ( + acb->srboutstandingcount < ARCMSR_RELEASE_SIMQ_LEVEL)) { + acb->acb_flags &= ~ACB_F_CAM_DEV_QFRZN; + pccb->ccb_h.status |= CAM_RELEASE_SIMQ; + } + } + srb->startdone=ARCMSR_SRB_DONE; + srb->srb_flags=0; + acb->srbworkingQ[acb->workingsrb_doneindex]=srb; + acb->workingsrb_doneindex++; + acb->workingsrb_doneindex %= ARCMSR_MAX_FREESRB_NUM; + xpt_done(pccb); + return; +} +/* ************************************************************************** ************************************************************************** */ @@ -1009,8 +1013,8 @@ static void arcmsr_post_srb(struct AdapterControlBlock *acb, struct CommandContr { CHIP_REG_WRITE32(HBC_MessageUnit,0,inbound_queueport_low, ccb_post_stamp); } - } - break; + } + break; } return; } @@ -1595,7 +1599,7 @@ static void arcmsr_hbb_postqueue_isr(struct AdapterControlBlock *acb) u_int32_t flag_srb; int index; u_int16_t error; - + /* ***************************************************************************** ** areca cdb command done @@ -2236,7 +2240,7 @@ message_out: ********************************************************************* ********************************************************************* */ -static void arcmsr_executesrb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) +static void arcmsr_execute_srb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) { struct CommandControlBlock *srb=(struct CommandControlBlock *)arg; struct AdapterControlBlock *acb=(struct AdapterControlBlock *)srb->acb; @@ -2386,18 +2390,16 @@ static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb, xpt_done(pccb); return; } - inqdata[0] = T_PROCESSOR; - /* Periph Qualifier & Periph Dev Type */ - inqdata[1] = 0; - /* rem media bit & Dev Type Modifier */ - inqdata[2] = 0; - /* ISO, ECMA, & ANSI versions */ - inqdata[4] = 31; - /* length of additional data */ - strncpy(&inqdata[8], "Areca ", 8); - /* Vendor Identification */ - strncpy(&inqdata[16], "RAID controller ", 16); - /* Product Identification */ + inqdata[0] = T_PROCESSOR; /* Periph Qualifier & Periph Dev Type */ + inqdata[1] = 0; /* rem media bit & Dev Type Modifier */ + inqdata[2] = 0; /* ISO, ECMA, & ANSI versions */ + inqdata[3] = 0; + inqdata[4] = 31; /* length of additional data */ + inqdata[5] = 0; + inqdata[6] = 0; + inqdata[7] = 0; + strncpy(&inqdata[8], "Areca ", 8); /* Vendor Identification */ + strncpy(&inqdata[16], "RAID controller ", 16); /* Product Identification */ strncpy(&inqdata[32], "R001", 4); /* Product Revision */ memcpy(buffer, inqdata, sizeof(inqdata)); xpt_done(pccb); @@ -2460,15 +2462,19 @@ static void arcmsr_action(struct cam_sim * psim, union ccb * pccb) , srb->dm_segs_dmamap , pccb->csio.data_ptr , pccb->csio.dxfer_len - , arcmsr_executesrb, srb, /*flags*/0); + , arcmsr_execute_srb, srb, /*flags*/0); if(error == EINPROGRESS) { xpt_freeze_simq(acb->psim, 1); pccb->ccb_h.status |= CAM_RELEASE_SIMQ; } splx(s); - } else { - /* Buffer is physical */ - panic("arcmsr: CAM_DATA_PHYS not supported"); + } + else { /* Buffer is physical */ + struct bus_dma_segment seg; + + seg.ds_addr = (bus_addr_t)pccb->csio.data_ptr; + seg.ds_len = pccb->csio.dxfer_len; + arcmsr_execute_srb(srb, &seg, 1, 0); } } else { /* Scatter/gather list */ @@ -2482,10 +2488,10 @@ static void arcmsr_action(struct cam_sim * psim, union ccb * pccb) return; } segs=(struct bus_dma_segment *)pccb->csio.data_ptr; - arcmsr_executesrb(srb, segs, pccb->csio.sglist_cnt, 0); + arcmsr_execute_srb(srb, segs, pccb->csio.sglist_cnt, 0); } } else { - arcmsr_executesrb(srb, NULL, 0, 0); + arcmsr_execute_srb(srb, NULL, 0, 0); } break; } @@ -3204,7 +3210,7 @@ static u_int32_t arcmsr_iop_confirm(struct AdapterControlBlock *acb) return FALSE; } post_queue_phyaddr = srb_phyaddr + ARCMSR_MAX_FREESRB_NUM*sizeof(struct CommandControlBlock) - + offsetof(struct HBB_MessageUnit, post_qbuffer); + + offsetof(struct HBB_MessageUnit, post_qbuffer); CHIP_REG_WRITE32(HBB_RWBUFFER, 1, msgcode_rwbuffer[0], ARCMSR_SIGNATURE_SET_CONFIG); /* driver "set config" signature */ CHIP_REG_WRITE32(HBB_RWBUFFER, 1, msgcode_rwbuffer[1], srb_phyaddr_hi32); /* normal should be zero */ CHIP_REG_WRITE32(HBB_RWBUFFER, 1, msgcode_rwbuffer[2], post_queue_phyaddr); /* postQ size (256+8)*4 */ @@ -3288,7 +3294,7 @@ static void arcmsr_iop_init(struct AdapterControlBlock *acb) ********************************************************************** ********************************************************************** */ -static void arcmsr_map_freesrb(void *arg, bus_dma_segment_t *segs, int nseg, int error) +static void arcmsr_map_free_srb(void *arg, bus_dma_segment_t *segs, int nseg, int error) { struct AdapterControlBlock *acb=arg; struct CommandControlBlock *srb_tmp; @@ -3351,6 +3357,7 @@ static u_int32_t arcmsr_initialize(device_t dev) max_coherent_size=ARCMSR_SRBS_POOL_SIZE; } break; + case PCIDevVenIDARC1200: case PCIDevVenIDARC1201: { acb->adapter_type=ACB_ADAPTER_TYPE_B; max_coherent_size=ARCMSR_SRBS_POOL_SIZE+(sizeof(struct HBB_MessageUnit)); @@ -3364,7 +3371,9 @@ static u_int32_t arcmsr_initialize(device_t dev) case PCIDevVenIDARC1210: case PCIDevVenIDARC1220: case PCIDevVenIDARC1230: + case PCIDevVenIDARC1231: case PCIDevVenIDARC1260: + case PCIDevVenIDARC1261: case PCIDevVenIDARC1270: case PCIDevVenIDARC1280: case PCIDevVenIDARC1212: @@ -3383,108 +3392,71 @@ static u_int32_t arcmsr_initialize(device_t dev) return ENOMEM; } } + if(bus_dma_tag_create( /*parent*/ NULL, + /*alignemnt*/ 1, + /*boundary*/ 0, + /*lowaddr*/ BUS_SPACE_MAXADDR, + /*highaddr*/ BUS_SPACE_MAXADDR, + /*filter*/ NULL, + /*filterarg*/ NULL, + /*maxsize*/ BUS_SPACE_MAXSIZE_32BIT, + /*nsegments*/ BUS_SPACE_UNRESTRICTED, + /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, + /*flags*/ 0, #if __FreeBSD_version >= 502010 - if(bus_dma_tag_create( /*parent*/ NULL, - /*alignemnt*/ 1, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ BUS_SPACE_MAXSIZE_32BIT, - /*nsegments*/ BUS_SPACE_UNRESTRICTED, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - /*lockfunc*/ NULL, - /*lockarg*/ NULL, - &acb->parent_dmat) != 0) -#else - if(bus_dma_tag_create( /*parent*/ NULL, - /*alignemnt*/ 1, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ BUS_SPACE_MAXSIZE_32BIT, - /*nsegments*/ BUS_SPACE_UNRESTRICTED, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - &acb->parent_dmat) != 0) + /*lockfunc*/ NULL, + /*lockarg*/ NULL, #endif + &acb->parent_dmat) != 0) { printf("arcmsr%d: parent_dmat bus_dma_tag_create failure!\n", device_get_unit(dev)); return ENOMEM; } + /* Create a single tag describing a region large enough to hold all of the s/g lists we will need. */ -#if __FreeBSD_version >= 502010 if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, - /*alignment*/ 1, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ MAXBSIZE, - /*nsegments*/ ARCMSR_MAX_SG_ENTRIES, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - /*lockfunc*/ busdma_lock_mutex, + /*alignment*/ 1, + /*boundary*/ 0, + /*lowaddr*/ BUS_SPACE_MAXADDR, + /*highaddr*/ BUS_SPACE_MAXADDR, + /*filter*/ NULL, + /*filterarg*/ NULL, + /*maxsize*/ ARCMSR_MAX_SG_ENTRIES * PAGE_SIZE * ARCMSR_MAX_FREESRB_NUM, + /*nsegments*/ ARCMSR_MAX_SG_ENTRIES, + /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, + /*flags*/ 0, +#if __FreeBSD_version >= 502010 + /*lockfunc*/ busdma_lock_mutex, #if __FreeBSD_version >= 700025 - /*lockarg*/ &acb->qbuffer_lock, + /*lockarg*/ &acb->qbuffer_lock, #else - /*lockarg*/ &Giant, + /*lockarg*/ &Giant, #endif - &acb->dm_segs_dmat) != 0) -#else - if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, - /*alignment*/ 1, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ MAXBSIZE, - /*nsegments*/ ARCMSR_MAX_SG_ENTRIES, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - &acb->dm_segs_dmat) != 0) #endif + &acb->dm_segs_dmat) != 0) { bus_dma_tag_destroy(acb->parent_dmat); printf("arcmsr%d: dm_segs_dmat bus_dma_tag_create failure!\n", device_get_unit(dev)); return ENOMEM; } + /* DMA tag for our srb structures.... Allocate the freesrb memory */ -#if __FreeBSD_version >= 502010 - if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, - /*alignment*/ 0x20, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR_32BIT, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ max_coherent_size, - /*nsegments*/ 1, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - /*lockfunc*/ NULL, - /*lockarg*/ NULL, - &acb->srb_dmat) != 0) -#else if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, - /*alignment*/ 0x20, - /*boundary*/ 0, - /*lowaddr*/ BUS_SPACE_MAXADDR_32BIT, - /*highaddr*/ BUS_SPACE_MAXADDR, - /*filter*/ NULL, - /*filterarg*/ NULL, - /*maxsize*/ max_coherent_size, - /*nsegments*/ 1, - /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, - /*flags*/ 0, - &acb->srb_dmat) != 0) + /*alignment*/ 0x20, + /*boundary*/ 0, + /*lowaddr*/ BUS_SPACE_MAXADDR_32BIT, + /*highaddr*/ BUS_SPACE_MAXADDR, + /*filter*/ NULL, + /*filterarg*/ NULL, + /*maxsize*/ max_coherent_size, + /*nsegments*/ 1, + /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, + /*flags*/ 0, +#if __FreeBSD_version >= 502010 + /*lockfunc*/ NULL, + /*lockarg*/ NULL, #endif + &acb->srb_dmat) != 0) { bus_dma_tag_destroy(acb->dm_segs_dmat); bus_dma_tag_destroy(acb->parent_dmat); @@ -3500,7 +3472,7 @@ static u_int32_t arcmsr_initialize(device_t dev) return ENXIO; } /* And permanently map them */ - if(bus_dmamap_load(acb->srb_dmat, acb->srb_dmamap, acb->uncacheptr, max_coherent_size, arcmsr_map_freesrb, acb, /*flags*/0)) { + if(bus_dmamap_load(acb->srb_dmat, acb->srb_dmamap, acb->uncacheptr, max_coherent_size, arcmsr_map_free_srb, acb, /*flags*/0)) { bus_dma_tag_destroy(acb->srb_dmat); bus_dma_tag_destroy(acb->dm_segs_dmat); bus_dma_tag_destroy(acb->parent_dmat); @@ -3518,7 +3490,7 @@ static u_int32_t arcmsr_initialize(device_t dev) case ACB_ADAPTER_TYPE_A: { u_int32_t rid0=PCIR_BAR(0); vm_offset_t mem_base0; - + acb->sys_res_arcmsr[0]=bus_alloc_resource(dev,SYS_RES_MEMORY, &rid0, 0ul, ~0ul, 0x1000, RF_ACTIVE); if(acb->sys_res_arcmsr[0] == NULL) { arcmsr_free_resource(acb); @@ -3549,10 +3521,10 @@ static u_int32_t arcmsr_initialize(device_t dev) for(i=0; i<2; i++) { if(i==0) { acb->sys_res_arcmsr[i]=bus_alloc_resource(dev,SYS_RES_MEMORY, &rid[i], - 0x20400, 0x20400+sizeof(struct HBB_DOORBELL), sizeof(struct HBB_DOORBELL), RF_ACTIVE); + 0ul, ~0ul, sizeof(struct HBB_DOORBELL), RF_ACTIVE); } else { acb->sys_res_arcmsr[i]=bus_alloc_resource(dev, SYS_RES_MEMORY, &rid[i], - 0x0fa00, 0x0fa00+sizeof(struct HBB_RWBUFFER), sizeof(struct HBB_RWBUFFER), RF_ACTIVE); + 0ul, ~0ul, sizeof(struct HBB_RWBUFFER), RF_ACTIVE); } if(acb->sys_res_arcmsr[i] == NULL) { arcmsr_free_resource(acb); @@ -3751,6 +3723,7 @@ static int arcmsr_probe(device_t dev) { u_int32_t id; static char buf[256]; + char x_type[]={"X-TYPE"}; char *type; int raid6 = 1; @@ -3759,8 +3732,9 @@ static int arcmsr_probe(device_t dev) } switch(id=pci_get_devid(dev)) { case PCIDevVenIDARC1110: - case PCIDevVenIDARC1210: + case PCIDevVenIDARC1200: case PCIDevVenIDARC1201: + case PCIDevVenIDARC1210: raid6 = 0; /*FALLTHRU*/ case PCIDevVenIDARC1120: @@ -3769,7 +3743,9 @@ static int arcmsr_probe(device_t dev) case PCIDevVenIDARC1170: case PCIDevVenIDARC1220: case PCIDevVenIDARC1230: + case PCIDevVenIDARC1231: case PCIDevVenIDARC1260: + case PCIDevVenIDARC1261: case PCIDevVenIDARC1270: case PCIDevVenIDARC1280: type = "SATA"; @@ -3786,9 +3762,11 @@ static int arcmsr_probe(device_t dev) type = "SAS 6G"; break; default: - type = "X-TYPE"; + type = x_type; break; } + if(type == x_type) + return(ENXIO); sprintf(buf, "Areca %s Host Adapter RAID Controller %s\n", type, raid6 ? "(RAID6 capable)" : ""); device_set_desc_copy(dev, buf); return 0; diff --git a/sys/dev/arcmsr/arcmsr.h b/sys/dev/arcmsr/arcmsr.h index 2e78f39..38787168 100644 --- a/sys/dev/arcmsr/arcmsr.h +++ b/sys/dev/arcmsr/arcmsr.h @@ -37,22 +37,21 @@ ************************************************************************** * $FreeBSD$ */ -#define ARCMSR_DRIVER_VERSION "Driver Version 1.20.00.17 2010-07-15" -#define ARCMSR_SCSI_INITIATOR_ID 255 -#define ARCMSR_DEV_SECTOR_SIZE 512 -#define ARCMSR_MAX_XFER_SECTORS 4096 -#define ARCMSR_MAX_TARGETID 17 /*16 max target id + 1*/ -#define ARCMSR_MAX_TARGETLUN 8 /*8*/ -#define ARCMSR_MAX_CHIPTYPE_NUM 4 -#define ARCMSR_MAX_OUTSTANDING_CMD 256 -#define ARCMSR_MAX_START_JOB 257 -#define ARCMSR_MAX_CMD_PERLUN ARCMSR_MAX_OUTSTANDING_CMD -#define ARCMSR_MAX_FREESRB_NUM 320 -#define ARCMSR_MAX_QBUFFER 4096 /* ioctl QBUFFER */ -#define ARCMSR_MAX_SG_ENTRIES 38 /* max 38*/ -#define ARCMSR_MAX_ADAPTER 4 -#define ARCMSR_RELEASE_SIMQ_LEVEL 230 -#define ARCMSR_MAX_HBB_POSTQUEUE 264 /* (ARCMSR_MAX_OUTSTANDING_CMD+8) */ +#define ARCMSR_SCSI_INITIATOR_ID 255 +#define ARCMSR_DEV_SECTOR_SIZE 512 +#define ARCMSR_MAX_XFER_SECTORS 4096 +#define ARCMSR_MAX_TARGETID 17 /*16 max target id + 1*/ +#define ARCMSR_MAX_TARGETLUN 8 /*8*/ +#define ARCMSR_MAX_CHIPTYPE_NUM 4 +#define ARCMSR_MAX_OUTSTANDING_CMD 256 +#define ARCMSR_MAX_START_JOB 257 +#define ARCMSR_MAX_CMD_PERLUN ARCMSR_MAX_OUTSTANDING_CMD +#define ARCMSR_MAX_FREESRB_NUM 320 +#define ARCMSR_MAX_QBUFFER 4096 /* ioctl QBUFFER */ +#define ARCMSR_MAX_SG_ENTRIES 38 /* max 38*/ +#define ARCMSR_MAX_ADAPTER 4 +#define ARCMSR_RELEASE_SIMQ_LEVEL 230 +#define ARCMSR_MAX_HBB_POSTQUEUE 264 /* (ARCMSR_MAX_OUTSTANDING_CMD+8) */ /* ********************************************************************* */ @@ -74,45 +73,51 @@ ** ********************************************************************************** */ -#define PCI_VENDOR_ID_ARECA 0x17D3 /* Vendor ID */ -#define PCI_DEVICE_ID_ARECA_1110 0x1110 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1120 0x1120 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1130 0x1130 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1160 0x1160 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1170 0x1170 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1210 0x1210 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1220 0x1220 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1230 0x1230 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1260 0x1260 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1270 0x1270 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1280 0x1280 /* Device ID */ +#define PCI_VENDOR_ID_ARECA 0x17D3 /* Vendor ID */ +#define PCI_DEVICE_ID_ARECA_1110 0x1110 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1120 0x1120 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1130 0x1130 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1160 0x1160 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1170 0x1170 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1200 0x1200 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1201 0x1201 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1210 0x1210 /* Device ID */ #define PCI_DEVICE_ID_ARECA_1212 0x1212 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1220 0x1220 /* Device ID */ #define PCI_DEVICE_ID_ARECA_1222 0x1222 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1380 0x1380 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1381 0x1381 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1680 0x1680 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1681 0x1681 /* Device ID */ -#define PCI_DEVICE_ID_ARECA_1201 0x1201 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1230 0x1230 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1231 0x1231 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1260 0x1260 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1261 0x1261 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1270 0x1270 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1280 0x1280 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1380 0x1380 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1381 0x1381 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1680 0x1680 /* Device ID */ +#define PCI_DEVICE_ID_ARECA_1681 0x1681 /* Device ID */ #define PCI_DEVICE_ID_ARECA_1880 0x1880 /* Device ID */ -#define PCIDevVenIDARC1110 0x111017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1120 0x112017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1130 0x113017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1160 0x116017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1170 0x117017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1210 0x121017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1220 0x122017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1230 0x123017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1260 0x126017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1270 0x127017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1280 0x128017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1110 0x111017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1120 0x112017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1130 0x113017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1160 0x116017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1170 0x117017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1200 0x120017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1201 0x120117D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1210 0x121017D3 /* Vendor Device ID */ #define PCIDevVenIDARC1212 0x121217D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1220 0x122017D3 /* Vendor Device ID */ #define PCIDevVenIDARC1222 0x122217D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1380 0x138017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1381 0x138117D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1680 0x168017D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1681 0x168117D3 /* Vendor Device ID */ -#define PCIDevVenIDARC1201 0x120117D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1230 0x123017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1231 0x123117D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1260 0x126017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1261 0x126117D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1270 0x127017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1280 0x128017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1380 0x138017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1381 0x138117D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1680 0x168017D3 /* Vendor Device ID */ +#define PCIDevVenIDARC1681 0x168117D3 /* Vendor Device ID */ #define PCIDevVenIDARC1880 0x188017D3 /* Vendor Device ID */ #ifndef PCIR_BARS @@ -120,30 +125,30 @@ #define PCIR_BAR(x) (PCIR_BARS + (x) * 4) #endif -#define PCI_BASE_ADDR0 0x10 -#define PCI_BASE_ADDR1 0x14 -#define PCI_BASE_ADDR2 0x18 -#define PCI_BASE_ADDR3 0x1C -#define PCI_BASE_ADDR4 0x20 -#define PCI_BASE_ADDR5 0x24 +#define PCI_BASE_ADDR0 0x10 +#define PCI_BASE_ADDR1 0x14 +#define PCI_BASE_ADDR2 0x18 +#define PCI_BASE_ADDR3 0x1C +#define PCI_BASE_ADDR4 0x20 +#define PCI_BASE_ADDR5 0x24 /* ********************************************************************************** ** ********************************************************************************** */ -#define ARCMSR_SCSICMD_IOCTL 0x77 -#define ARCMSR_CDEVSW_IOCTL 0x88 -#define ARCMSR_MESSAGE_FAIL 0x0001 -#define ARCMSR_MESSAGE_SUCCESS 0x0000 +#define ARCMSR_SCSICMD_IOCTL 0x77 +#define ARCMSR_CDEVSW_IOCTL 0x88 +#define ARCMSR_MESSAGE_FAIL 0x0001 +#define ARCMSR_MESSAGE_SUCCESS 0x0000 /* ********************************************************************************** ** ********************************************************************************** */ -#define arcmsr_ccbsrb_ptr spriv_ptr0 -#define arcmsr_ccbacb_ptr spriv_ptr1 -#define dma_addr_hi32(addr) (u_int32_t) ((addr>>16)>>16) -#define dma_addr_lo32(addr) (u_int32_t) (addr & 0xffffffff) +#define arcmsr_ccbsrb_ptr spriv_ptr0 +#define arcmsr_ccbacb_ptr spriv_ptr1 +#define dma_addr_hi32(addr) (u_int32_t) ((addr>>16)>>16) +#define dma_addr_lo32(addr) (u_int32_t) (addr & 0xffffffff) #define get_min(x,y) ((x) < (y) ? (x) : (y)) #define get_max(x,y) ((x) < (y) ? (y) : (x)) /* @@ -210,9 +215,9 @@ struct CMD_MESSAGE_FIELD { #define ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE _IOWR('F', FUNCTION_FLUSH_ADAPTER_CACHE, struct CMD_MESSAGE_FIELD) /* ARECA IOCTL ReturnCode */ -#define ARCMSR_MESSAGE_RETURNCODE_OK 0x00000001 -#define ARCMSR_MESSAGE_RETURNCODE_ERROR 0x00000006 -#define ARCMSR_MESSAGE_RETURNCODE_3F 0x0000003F +#define ARCMSR_MESSAGE_RETURNCODE_OK 0x00000001 +#define ARCMSR_MESSAGE_RETURNCODE_ERROR 0x00000006 +#define ARCMSR_MESSAGE_RETURNCODE_3F 0x0000003F #define ARCMSR_IOCTL_RETURNCODE_BUS_HANG_ON 0x00000088 /* ************************************************************************ @@ -533,32 +538,32 @@ struct CMD_MESSAGE_FIELD { ************************************************************************************************ */ /* signature of set and get firmware config */ -#define ARCMSR_SIGNATURE_GET_CONFIG 0x87974060 -#define ARCMSR_SIGNATURE_SET_CONFIG 0x87974063 +#define ARCMSR_SIGNATURE_GET_CONFIG 0x87974060 +#define ARCMSR_SIGNATURE_SET_CONFIG 0x87974063 /* message code of inbound message register */ -#define ARCMSR_INBOUND_MESG0_NOP 0x00000000 -#define ARCMSR_INBOUND_MESG0_GET_CONFIG 0x00000001 -#define ARCMSR_INBOUND_MESG0_SET_CONFIG 0x00000002 -#define ARCMSR_INBOUND_MESG0_ABORT_CMD 0x00000003 -#define ARCMSR_INBOUND_MESG0_STOP_BGRB 0x00000004 -#define ARCMSR_INBOUND_MESG0_FLUSH_CACHE 0x00000005 -#define ARCMSR_INBOUND_MESG0_START_BGRB 0x00000006 -#define ARCMSR_INBOUND_MESG0_CHK331PENDING 0x00000007 -#define ARCMSR_INBOUND_MESG0_SYNC_TIMER 0x00000008 +#define ARCMSR_INBOUND_MESG0_NOP 0x00000000 +#define ARCMSR_INBOUND_MESG0_GET_CONFIG 0x00000001 +#define ARCMSR_INBOUND_MESG0_SET_CONFIG 0x00000002 +#define ARCMSR_INBOUND_MESG0_ABORT_CMD 0x00000003 +#define ARCMSR_INBOUND_MESG0_STOP_BGRB 0x00000004 +#define ARCMSR_INBOUND_MESG0_FLUSH_CACHE 0x00000005 +#define ARCMSR_INBOUND_MESG0_START_BGRB 0x00000006 +#define ARCMSR_INBOUND_MESG0_CHK331PENDING 0x00000007 +#define ARCMSR_INBOUND_MESG0_SYNC_TIMER 0x00000008 /* doorbell interrupt generator */ -#define ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK 0x00000001 -#define ARCMSR_INBOUND_DRIVER_DATA_READ_OK 0x00000002 -#define ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK 0x00000001 -#define ARCMSR_OUTBOUND_IOP331_DATA_READ_OK 0x00000002 +#define ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK 0x00000001 +#define ARCMSR_INBOUND_DRIVER_DATA_READ_OK 0x00000002 +#define ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK 0x00000001 +#define ARCMSR_OUTBOUND_IOP331_DATA_READ_OK 0x00000002 /* srb areca cdb flag */ -#define ARCMSR_SRBPOST_FLAG_SGL_BSIZE 0x80000000 -#define ARCMSR_SRBPOST_FLAG_IAM_BIOS 0x40000000 -#define ARCMSR_SRBREPLY_FLAG_IAM_BIOS 0x40000000 -#define ARCMSR_SRBREPLY_FLAG_ERROR 0x10000000 +#define ARCMSR_SRBPOST_FLAG_SGL_BSIZE 0x80000000 +#define ARCMSR_SRBPOST_FLAG_IAM_BIOS 0x40000000 +#define ARCMSR_SRBREPLY_FLAG_IAM_BIOS 0x40000000 +#define ARCMSR_SRBREPLY_FLAG_ERROR 0x10000000 #define ARCMSR_SRBREPLY_FLAG_ERROR_MODE0 0x10000000 #define ARCMSR_SRBREPLY_FLAG_ERROR_MODE1 0x00000001 /* outbound firmware ok */ -#define ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK 0x80000000 +#define ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK 0x80000000 /* ********************************** ** @@ -603,15 +608,15 @@ struct QBUFFER { #define ARCMSR_FW_CFGVER_OFFSET 25 struct FIRMWARE_INFO { - u_int32_t signature; /*0,00-03*/ - u_int32_t request_len; /*1,04-07*/ - u_int32_t numbers_queue; /*2,08-11*/ - u_int32_t sdram_size; /*3,12-15*/ - u_int32_t ide_channels; /*4,16-19*/ - char vendor[40]; /*5,20-59*/ - char model[8]; /*15,60-67*/ - char firmware_ver[16]; /*17,68-83*/ - char device_map[16]; /*21,84-99*/ + u_int32_t signature; /*0,00-03*/ + u_int32_t request_len; /*1,04-07*/ + u_int32_t numbers_queue; /*2,08-11*/ + u_int32_t sdram_size; /*3,12-15*/ + u_int32_t ide_channels; /*4,16-19*/ + char vendor[40]; /*5,20-59*/ + char model[8]; /*15,60-67*/ + char firmware_ver[16]; /*17,68-83*/ + char device_map[16]; /*21,84-99*/ u_int32_t cfgVersion; /*25,100-103 Added for checking of new firmware capability*/ char cfgSerial[16]; /*26,104-119*/ u_int32_t cfgPicStatus; /*30,120-123*/ @@ -649,33 +654,33 @@ struct FIRMWARE_INFO { ************************************************************************************************ */ struct ARCMSR_CDB { - u_int8_t Bus; /* 00h should be 0 */ - u_int8_t TargetID; /* 01h should be 0--15 */ - u_int8_t LUN; /* 02h should be 0--7 */ - u_int8_t Function; /* 03h should be 1 */ + u_int8_t Bus; /* 00h should be 0 */ + u_int8_t TargetID; /* 01h should be 0--15 */ + u_int8_t LUN; /* 02h should be 0--7 */ + u_int8_t Function; /* 03h should be 1 */ - u_int8_t CdbLength; /* 04h not used now */ - u_int8_t sgcount; /* 05h */ - u_int8_t Flags; /* 06h */ -#define ARCMSR_CDB_FLAG_SGL_BSIZE 0x01 /* bit 0: 0(256) / 1(512) bytes */ -#define ARCMSR_CDB_FLAG_BIOS 0x02 /* bit 1: 0(from driver) / 1(from BIOS) */ -#define ARCMSR_CDB_FLAG_WRITE 0x04 /* bit 2: 0(Data in) / 1(Data out) */ -#define ARCMSR_CDB_FLAG_SIMPLEQ 0x00 /* bit 4/3 ,00 : simple Q,01 : head of Q,10 : ordered Q */ -#define ARCMSR_CDB_FLAG_HEADQ 0x08 -#define ARCMSR_CDB_FLAG_ORDEREDQ 0x10 + u_int8_t CdbLength; /* 04h not used now */ + u_int8_t sgcount; /* 05h */ + u_int8_t Flags; /* 06h */ +#define ARCMSR_CDB_FLAG_SGL_BSIZE 0x01 /* bit 0: 0(256) / 1(512) bytes */ +#define ARCMSR_CDB_FLAG_BIOS 0x02 /* bit 1: 0(from driver) / 1(from BIOS) */ +#define ARCMSR_CDB_FLAG_WRITE 0x04 /* bit 2: 0(Data in) / 1(Data out) */ +#define ARCMSR_CDB_FLAG_SIMPLEQ 0x00 /* bit 4/3 ,00 : simple Q,01 : head of Q,10 : ordered Q */ +#define ARCMSR_CDB_FLAG_HEADQ 0x08 +#define ARCMSR_CDB_FLAG_ORDEREDQ 0x10 u_int8_t msgPages; /* 07h */ - u_int32_t Context; /* 08h Address of this request */ - u_int32_t DataLength; /* 0ch not used now */ + u_int32_t Context; /* 08h Address of this request */ + u_int32_t DataLength; /* 0ch not used now */ - u_int8_t Cdb[16]; /* 10h SCSI CDB */ + u_int8_t Cdb[16]; /* 10h SCSI CDB */ /* ******************************************************** **Device Status : the same from SCSI bus if error occur ** SCSI bus status codes. ******************************************************** */ - u_int8_t DeviceStatus; /* 20h if error */ + u_int8_t DeviceStatus; /* 20h if error */ #define SCSISTAT_GOOD 0x00 #define SCSISTAT_CHECK_CONDITION 0x02 #define SCSISTAT_CONDITION_MET 0x04 @@ -685,15 +690,15 @@ struct ARCMSR_CDB { #define SCSISTAT_RESERVATION_CONFLICT 0x18 #define SCSISTAT_COMMAND_TERMINATED 0x22 #define SCSISTAT_QUEUE_FULL 0x28 -#define ARCMSR_DEV_SELECT_TIMEOUT 0xF0 -#define ARCMSR_DEV_ABORTED 0xF1 -#define ARCMSR_DEV_INIT_FAIL 0xF2 +#define ARCMSR_DEV_SELECT_TIMEOUT 0xF0 +#define ARCMSR_DEV_ABORTED 0xF1 +#define ARCMSR_DEV_INIT_FAIL 0xF2 - u_int8_t SenseData[15]; /* 21h output */ + u_int8_t SenseData[15]; /* 21h output */ union { - struct SG32ENTRY sg32entry[ARCMSR_MAX_SG_ENTRIES]; /* 30h Scatter gather address */ - struct SG64ENTRY sg64entry[ARCMSR_MAX_SG_ENTRIES]; /* 30h */ + struct SG32ENTRY sg32entry[ARCMSR_MAX_SG_ENTRIES]; /* 30h Scatter gather address */ + struct SG64ENTRY sg64entry[ARCMSR_MAX_SG_ENTRIES]; /* 30h */ } u; }; /* @@ -706,23 +711,23 @@ struct ARCMSR_CDB { */ struct CommandControlBlock { struct ARCMSR_CDB arcmsr_cdb; /* 0 -503 (size of CDB=504): arcmsr messenger scsi command descriptor size 504 bytes */ - u_int32_t cdb_shifted_phyaddr; /* 504-507 */ + u_int32_t cdb_shifted_phyaddr; /* 504-507 */ u_int32_t arc_cdb_size; /* 508-511 */ /* ======================512+32 bytes============================ */ #if defined(__x86_64__) || defined(__amd64__) || defined(__ia64__) || defined(__sparc64__) || defined(__powerpc__) union ccb *pccb; /* 512-515 516-519 pointer of freebsd scsi command */ struct AdapterControlBlock *acb; /* 520-523 524-527 */ - bus_dmamap_t dm_segs_dmamap; /* 528-531 532-535 */ - u_int16_t srb_flags; /* 536-537 */ - u_int16_t startdone; /* 538-539 */ - u_int32_t reserved2; /* 540-543 */ + bus_dmamap_t dm_segs_dmamap; /* 528-531 532-535 */ + u_int16_t srb_flags; /* 536-537 */ + u_int16_t startdone; /* 538-539 */ + u_int32_t reserved2; /* 540-543 */ #else union ccb *pccb; /* 512-515 pointer of freebsd scsi command */ struct AdapterControlBlock *acb; /* 516-519 */ - bus_dmamap_t dm_segs_dmamap; /* 520-523 */ - u_int16_t srb_flags; /* 524-525 */ - u_int16_t startdone; /* 526-527 */ - u_int32_t reserved2[4]; /* 528-531 532-535 536-539 540-543 */ + bus_dmamap_t dm_segs_dmamap; /* 520-523 */ + u_int16_t srb_flags; /* 524-525 */ + u_int16_t startdone; /* 526-527 */ + u_int32_t reserved2[4]; /* 528-531 532-535 536-539 540-543 */ #endif /* ========================================================== */ /* struct callout ccb_callout; */ @@ -752,37 +757,37 @@ struct CommandControlBlock { ** Adapter Control Block ********************************************************************* */ -#define ACB_ADAPTER_TYPE_A 0x00000001 /* hba I IOP */ -#define ACB_ADAPTER_TYPE_B 0x00000002 /* hbb M IOP */ +#define ACB_ADAPTER_TYPE_A 0x00000001 /* hba I IOP */ +#define ACB_ADAPTER_TYPE_B 0x00000002 /* hbb M IOP */ #define ACB_ADAPTER_TYPE_C 0x00000004 /* hbc L IOP */ -#define ACB_ADAPTER_TYPE_D 0x00000008 /* hbd A IOP */ - +#define ACB_ADAPTER_TYPE_D 0x00000008 /* hbd A IOP */ + struct AdapterControlBlock { u_int32_t adapter_type; /* adapter A,B..... */ - bus_space_tag_t btag[2]; - bus_space_handle_t bhandle[2]; - bus_dma_tag_t parent_dmat; - bus_dma_tag_t dm_segs_dmat; /* dmat for buffer I/O */ - bus_dma_tag_t srb_dmat; /* dmat for freesrb */ - bus_dmamap_t srb_dmamap; + bus_space_tag_t btag[2]; + bus_space_handle_t bhandle[2]; + bus_dma_tag_t parent_dmat; + bus_dma_tag_t dm_segs_dmat; /* dmat for buffer I/O */ + bus_dma_tag_t srb_dmat; /* dmat for freesrb */ + bus_dmamap_t srb_dmamap; device_t pci_dev; #if __FreeBSD_version < 503000 dev_t ioctl_dev; #else - struct cdev * ioctl_dev; + struct cdev * ioctl_dev; #endif - int pci_unit; + int pci_unit; - struct resource * sys_res_arcmsr[2]; - struct resource * irqres; - void * ih; /* interrupt handle */ + struct resource * sys_res_arcmsr[2]; + struct resource * irqres; + void * ih; /* interrupt handle */ /* Hooks into the CAM XPT */ struct cam_sim *psim; struct cam_path *ppath; u_int8_t * uncacheptr; - unsigned long vir2phy_offset; + unsigned long vir2phy_offset; union { unsigned long phyaddr; struct { @@ -794,14 +799,14 @@ struct AdapterControlBlock { /* Offset is used in making arc cdb physical to virtual calculations */ u_int32_t outbound_int_enable; - struct MessageUnit_UNION * pmu; /* message unit ATU inbound base address0 */ + struct MessageUnit_UNION * pmu; /* message unit ATU inbound base address0 */ - u_int8_t adapter_index; /* */ + u_int8_t adapter_index; /* */ u_int8_t irq; - u_int16_t acb_flags; /* */ + u_int16_t acb_flags; /* */ - struct CommandControlBlock * psrb_pool[ARCMSR_MAX_FREESRB_NUM]; /* serial srb pointer array */ - struct CommandControlBlock * srbworkingQ[ARCMSR_MAX_FREESRB_NUM]; /* working srb pointer array */ + struct CommandControlBlock * psrb_pool[ARCMSR_MAX_FREESRB_NUM]; /* serial srb pointer array */ + struct CommandControlBlock * srbworkingQ[ARCMSR_MAX_FREESRB_NUM]; /* working srb pointer array */ int32_t workingsrb_doneindex; /* done srb array index */ int32_t workingsrb_startindex; /* start srb array index */ int32_t srboutstandingcount; @@ -814,20 +819,20 @@ struct AdapterControlBlock { u_int32_t wqbuf_firstindex; /* first of write buffer */ u_int32_t wqbuf_lastindex; /* last of write buffer */ - arcmsr_lock_t workingQ_done_lock; - arcmsr_lock_t workingQ_start_lock; - arcmsr_lock_t qbuffer_lock; + arcmsr_lock_t workingQ_done_lock; + arcmsr_lock_t workingQ_start_lock; + arcmsr_lock_t qbuffer_lock; u_int8_t devstate[ARCMSR_MAX_TARGETID][ARCMSR_MAX_TARGETLUN]; /* id0 ..... id15,lun0...lun7 */ u_int32_t num_resets; u_int32_t num_aborts; - u_int32_t firm_request_len; /*1,04-07*/ - u_int32_t firm_numbers_queue; /*2,08-11*/ - u_int32_t firm_sdram_size; /*3,12-15*/ - u_int32_t firm_ide_channels; /*4,16-19*/ + u_int32_t firm_request_len; /*1,04-07*/ + u_int32_t firm_numbers_queue; /*2,08-11*/ + u_int32_t firm_sdram_size; /*3,12-15*/ + u_int32_t firm_ide_channels; /*4,16-19*/ u_int32_t firm_cfg_version; - char firm_model[12]; /*15,60-67*/ - char firm_version[20]; /*17,68-83*/ + char firm_model[12]; /*15,60-67*/ + char firm_version[20]; /*17,68-83*/ char device_map[20]; /*21,84-99 */ struct callout devmap_callout; };/* HW_DEVICE_EXTENSION */ @@ -885,7 +890,7 @@ struct HBA_MessageUnit */ struct HBB_DOORBELL { - u_int8_t doorbell_reserved[132096]; /*reserved */ + u_int8_t doorbell_reserved[ARCMSR_DRV2IOP_DOORBELL]; /*reserved */ u_int32_t drv2iop_doorbell; /*offset 0x00020400:00,01,02,03: window of "instruction flags" from driver to iop */ u_int32_t drv2iop_doorbell_mask; /* 04,05,06,07: doorbell mask */ u_int32_t iop2drv_doorbell; /* 08,09,10,11: window of "instruction flags" from iop to driver */ @@ -898,7 +903,7 @@ struct HBB_DOORBELL */ struct HBB_RWBUFFER { - u_int8_t message_reserved0[64000]; /*reserved */ + u_int8_t message_reserved0[ARCMSR_MSGCODE_RWBUFFER]; /*reserved */ u_int32_t msgcode_rwbuffer[256]; /*offset 0x0000fa00: 0, 1, 2, 3,...,1023: message code read write 1024bytes */ u_int32_t message_wbuffer[32]; /*offset 0x0000fe00:1024,1025,1026,1027,...,1151: user space data to iop 128bytes */ u_int32_t message_reserved1[32]; /* 1152,1153,1154,1155,...,1279: message reserved*/ @@ -1014,38 +1019,38 @@ struct MessageUnit_UNION ************************************************************* */ struct SENSE_DATA { - u_int8_t ErrorCode:7; - u_int8_t Valid:1; - u_int8_t SegmentNumber; - u_int8_t SenseKey:4; - u_int8_t Reserved:1; - u_int8_t IncorrectLength:1; - u_int8_t EndOfMedia:1; - u_int8_t FileMark:1; - u_int8_t Information[4]; - u_int8_t AdditionalSenseLength; - u_int8_t CommandSpecificInformation[4]; - u_int8_t AdditionalSenseCode; - u_int8_t AdditionalSenseCodeQualifier; - u_int8_t FieldReplaceableUnitCode; - u_int8_t SenseKeySpecific[3]; + u_int8_t ErrorCode:7; + u_int8_t Valid:1; + u_int8_t SegmentNumber; + u_int8_t SenseKey:4; + u_int8_t Reserved:1; + u_int8_t IncorrectLength:1; + u_int8_t EndOfMedia:1; + u_int8_t FileMark:1; + u_int8_t Information[4]; + u_int8_t AdditionalSenseLength; + u_int8_t CommandSpecificInformation[4]; + u_int8_t AdditionalSenseCode; + u_int8_t AdditionalSenseCodeQualifier; + u_int8_t FieldReplaceableUnitCode; + u_int8_t SenseKeySpecific[3]; }; /* ********************************** ** Peripheral Device Type definitions ********************************** */ -#define SCSI_DASD 0x00 /* Direct-access Device */ -#define SCSI_SEQACESS 0x01 /* Sequential-access device */ -#define SCSI_PRINTER 0x02 /* Printer device */ -#define SCSI_PROCESSOR 0x03 /* Processor device */ -#define SCSI_WRITEONCE 0x04 /* Write-once device */ -#define SCSI_CDROM 0x05 /* CD-ROM device */ -#define SCSI_SCANNER 0x06 /* Scanner device */ -#define SCSI_OPTICAL 0x07 /* Optical memory device */ -#define SCSI_MEDCHGR 0x08 /* Medium changer device */ -#define SCSI_COMM 0x09 /* Communications device */ -#define SCSI_NODEV 0x1F /* Unknown or no device type */ +#define SCSI_DASD 0x00 /* Direct-access Device */ +#define SCSI_SEQACESS 0x01 /* Sequential-access device */ +#define SCSI_PRINTER 0x02 /* Printer device */ +#define SCSI_PROCESSOR 0x03 /* Processor device */ +#define SCSI_WRITEONCE 0x04 /* Write-once device */ +#define SCSI_CDROM 0x05 /* CD-ROM device */ +#define SCSI_SCANNER 0x06 /* Scanner device */ +#define SCSI_OPTICAL 0x07 /* Optical memory device */ +#define SCSI_MEDCHGR 0x08 /* Medium changer device */ +#define SCSI_COMM 0x09 /* Communications device */ +#define SCSI_NODEV 0x1F /* Unknown or no device type */ /* ************************************************************************************************************ ** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -1168,8 +1173,8 @@ struct SENSE_DATA { ** 1=The bridge target response to I/O transactions on the primary interface is enabled. **============================================================================== */ -#define ARCMSR_PCI2PCI_PRIMARY_COMMAND_REG 0x04 /*word*/ -#define PCI_DISABLE_INTERRUPT 0x0400 +#define ARCMSR_PCI2PCI_PRIMARY_COMMAND_REG 0x04 /*word*/ +#define PCI_DISABLE_INTERRUPT 0x0400 /* **============================================================================== ** 0x07-0x06 : status register diff --git a/sys/dev/nfe/if_nfe.c b/sys/dev/nfe/if_nfe.c index 7b9b553..347cf2b 100644 --- a/sys/dev/nfe/if_nfe.c +++ b/sys/dev/nfe/if_nfe.c @@ -817,8 +817,6 @@ nfe_miibus_statchg(device_t dev) sc = device_get_softc(dev); - NFE_LOCK(sc); - mii = device_get_softc(sc->nfe_miibus); ifp = sc->nfe_ifp; @@ -848,8 +846,6 @@ nfe_miibus_statchg(device_t dev) } NFE_WRITE(sc, NFE_TX_CTL, txctl); NFE_WRITE(sc, NFE_RX_CTL, rxctl); - - NFE_UNLOCK(sc); } diff --git a/sys/dev/usb/input/uhid.c b/sys/dev/usb/input/uhid.c index 5575bdf..f0c660a 100644 --- a/sys/dev/usb/input/uhid.c +++ b/sys/dev/usb/input/uhid.c @@ -672,7 +672,7 @@ uhid_attach(device_t dev) if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) { sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr); - sc->sc_repdesc_ptr = &uhid_graphire_report_descr; + sc->sc_repdesc_ptr = (void *)&uhid_graphire_report_descr; sc->sc_flags |= UHID_FLAG_STATIC_DESC; } else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) { @@ -693,7 +693,7 @@ uhid_attach(device_t dev) usbd_errstr(error)); } sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr); - sc->sc_repdesc_ptr = &uhid_graphire3_4x5_report_descr; + sc->sc_repdesc_ptr = (void *)&uhid_graphire3_4x5_report_descr; sc->sc_flags |= UHID_FLAG_STATIC_DESC; } } else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) && @@ -702,7 +702,7 @@ uhid_attach(device_t dev) /* the Xbox 360 gamepad has no report descriptor */ sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr); - sc->sc_repdesc_ptr = &uhid_xb360gp_report_descr; + sc->sc_repdesc_ptr = (void *)&uhid_xb360gp_report_descr; sc->sc_flags |= UHID_FLAG_STATIC_DESC; } if (sc->sc_repdesc_ptr == NULL) { diff --git a/sys/dev/usb/serial/u3g.c b/sys/dev/usb/serial/u3g.c index 12bd3f4..0777cdd 100644 --- a/sys/dev/usb/serial/u3g.c +++ b/sys/dev/usb/serial/u3g.c @@ -291,6 +291,8 @@ static const struct usb_device_id u3g_devs[] = { U3G_DEV(KYOCERA2, CDMA_MSM_K, 0), U3G_DEV(KYOCERA2, KPC680, 0), U3G_DEV(LONGCHEER, WM66, U3GINIT_HUAWEI), + U3G_DEV(LONGCHEER, DISK, U3GINIT_TCT), + U3G_DEV(LONGCHEER, W14, 0), U3G_DEV(MERLIN, V620, 0), U3G_DEV(NEOTEL, PRIME, 0), U3G_DEV(NOVATEL, E725, 0), diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs index 404ec18..87350a7 100644 --- a/sys/dev/usb/usbdevs +++ b/sys/dev/usb/usbdevs @@ -2086,7 +2086,10 @@ product LOGITEC RT2870_2 0x0163 RT2870 product LOGITEC RT2870_3 0x0164 RT2870 /* Longcheer Holdings, Ltd. products */ -product LONGCHEER WM66 0x6061 Longcheer WM66 HSDPA USB modem +product LONGCHEER WM66 0x6061 Longcheer WM66 HSDPA +product LONGCHEER W14 0x9603 Mobilcom W14 +product LONGCHEER DISK 0xf000 Driver disk + /* Lucent products */ product LUCENT EVALKIT 0x1001 USS-720 evaluation kit diff --git a/sys/i386/acpica/Makefile b/sys/i386/acpica/Makefile deleted file mode 100644 index 87061d6..0000000 --- a/sys/i386/acpica/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# $FreeBSD$ - -# Correct path for kernel builds -# Don't rely on the kernel's .depend file -.ifdef MAKESRCPATH -.PATH: ${MAKESRCPATH} -DEPENDFILE= -.else -MAKESRCPATH= ${.CURDIR} -CLEANFILES= acpi_wakecode.h acpi_wakecode.bin acpi_wakecode.o -.endif -.if ${CC:T:Micc} == "icc" -CFLAGS+= -restrict -NOSTDINC= -X -.else -NOSTDINC= -nostdinc -.endif -CFLAGS+= ${NOSTDINC} -I. -I${MAKESRCPATH}/../.. - -all: acpi_wakecode.h - -acpi_wakecode.o: acpi_wakecode.S assym.s - -acpi_wakecode.bin: acpi_wakecode.o - objcopy -S -O binary acpi_wakecode.o acpi_wakecode.bin - -acpi_wakecode.h: acpi_wakecode.bin acpi_wakecode.o - sh ${MAKESRCPATH}/genwakecode.sh > acpi_wakecode.h - -.include <bsd.prog.mk> diff --git a/sys/i386/acpica/acpi_wakecode.S b/sys/i386/acpica/acpi_wakecode.S index 889a58a..e23b138 100644 --- a/sys/i386/acpica/acpi_wakecode.S +++ b/sys/i386/acpica/acpi_wakecode.S @@ -27,8 +27,6 @@ * $FreeBSD$ */ -#define LOCORE - #include <machine/asmacros.h> #include <machine/specialreg.h> diff --git a/sys/i386/acpica/acpi_wakeup.c b/sys/i386/acpica/acpi_wakeup.c index 2397d80..6a46447 100644 --- a/sys/i386/acpica/acpi_wakeup.c +++ b/sys/i386/acpica/acpi_wakeup.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include <dev/acpica/acpivar.h> #include "acpi_wakecode.h" +#include "acpi_wakedata.h" /* Make sure the code is less than one page and leave room for the stack. */ CTASSERT(sizeof(wakecode) < PAGE_SIZE - 1024); diff --git a/sys/i386/acpica/genwakecode.sh b/sys/i386/acpica/genwakecode.sh deleted file mode 100644 index caffbf8..0000000 --- a/sys/i386/acpica/genwakecode.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# $FreeBSD$ -# -file2c 'static char wakecode[] = {' '};' <acpi_wakecode.bin - -nm -n --defined-only acpi_wakecode.o | while read offset dummy what -do - echo "#define ${what} 0x${offset}" -done - -exit 0 diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index d96c5a0..030c98d 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -1675,23 +1675,19 @@ sched_prio(struct thread *td, u_char prio) void sched_user_prio(struct thread *td, u_char prio) { - u_char oldprio; td->td_base_user_pri = prio; if (td->td_flags & TDF_UBORROWING && td->td_user_pri <= prio) return; - oldprio = td->td_user_pri; td->td_user_pri = prio; } void sched_lend_user_prio(struct thread *td, u_char prio) { - u_char oldprio; THREAD_LOCK_ASSERT(td, MA_OWNED); td->td_flags |= TDF_UBORROWING; - oldprio = td->td_user_pri; td->td_user_pri = prio; } diff --git a/sys/mips/adm5120/std.adm5120 b/sys/mips/adm5120/std.adm5120 index 59bf118..c76a393 100644 --- a/sys/mips/adm5120/std.adm5120 +++ b/sys/mips/adm5120/std.adm5120 @@ -1,11 +1,13 @@ # $FreeBSD$ +# # Standard include file for ADM5120 -files "../adm5120/files.adm5120" +files "../adm5120/files.adm5120" +machine mips mipsel cpu CPU_MIPS4KC options ISA_MIPS32 -# device admpci +# device admpci device admsw device pci diff --git a/sys/mips/alchemy/std.alchemy b/sys/mips/alchemy/std.alchemy index a955b67..82f0886 100644 --- a/sys/mips/alchemy/std.alchemy +++ b/sys/mips/alchemy/std.alchemy @@ -4,5 +4,6 @@ files "../alchemy/files.alchemy" +machine mips mipsel cpu CPU_MIPS4KC options ISA_MIPS32 diff --git a/sys/mips/atheros/std.ar71xx b/sys/mips/atheros/std.ar71xx new file mode 100644 index 0000000..14859e0 --- /dev/null +++ b/sys/mips/atheros/std.ar71xx @@ -0,0 +1,9 @@ +# $FreeBSD$ +# +# standard config for all ar71xx based kernels. + +files "../atheros/files.ar71xx" + +machine mips mipseb +cpu CPU_MIPS4KC +options ISA_MIPS32 diff --git a/sys/mips/cavium/std.octeon1 b/sys/mips/cavium/std.octeon1 index 7b3152f..a99c6df 100644 --- a/sys/mips/cavium/std.octeon1 +++ b/sys/mips/cavium/std.octeon1 @@ -5,3 +5,5 @@ # $FreeBSD$ # files "../cavium/files.octeon1" +machine mips mips64eb +cpu CPU_CNMIPS diff --git a/sys/mips/conf/ADM5120 b/sys/mips/conf/ADM5120 index a834c16..23ff643 100644 --- a/sys/mips/conf/ADM5120 +++ b/sys/mips/conf/ADM5120 @@ -19,9 +19,6 @@ ident ADM5120 -#makeoptions ARCH_FLAGS=-march=mips32 -makeoptions MIPS_LITTLE_ENDIAN=defined - # Don't build any modules yet. makeoptions MODULES_OVERRIDE="" diff --git a/sys/mips/conf/ALCHEMY b/sys/mips/conf/ALCHEMY index 8fa6070..db34318 100644 --- a/sys/mips/conf/ALCHEMY +++ b/sys/mips/conf/ALCHEMY @@ -19,9 +19,6 @@ ident ALCHEMY -makeoptions ARCH_FLAGS=-march=mips32 -makeoptions MIPS_LITTLE_ENDIAN=defined - # Don't build any modules yet. makeoptions MODULES_OVERRIDE="" diff --git a/sys/mips/conf/AR71XX b/sys/mips/conf/AR71XX index bec8120..ffdf539 100644 --- a/sys/mips/conf/AR71XX +++ b/sys/mips/conf/AR71XX @@ -5,14 +5,11 @@ # ident AR71XX -cpu CPU_MIPS4KC -options ISA_MIPS32 -makeoptions TARGET_BIG_ENDIAN makeoptions KERNLOADADDR=0x80050000 options HZ=1000 -files "../atheros/files.ar71xx" hints "AR71XX.hints" +include "../atheros/std.ar71xx" makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols #makeoptions MODULES_OVERRIDE="" diff --git a/sys/mips/conf/DEFAULTS b/sys/mips/conf/DEFAULTS index dc480ce..f09ef54 100644 --- a/sys/mips/conf/DEFAULTS +++ b/sys/mips/conf/DEFAULTS @@ -3,8 +3,6 @@ # # $FreeBSD$ -machine mips - device mem device uart_ns8250 diff --git a/sys/mips/conf/MALTA b/sys/mips/conf/MALTA index 77e072c..89ebac5 100644 --- a/sys/mips/conf/MALTA +++ b/sys/mips/conf/MALTA @@ -19,8 +19,8 @@ ident MALTA -#makeoptions ARCH_FLAGS=-march=mips32 -makeoptions MIPS_LITTLE_ENDIAN=defined +machine mips mipsel # Malta supports both, so it isn't in std.malta + makeoptions KERNLOADADDR=0x80100000 options YAMON diff --git a/sys/mips/conf/MALTA64 b/sys/mips/conf/MALTA64 index 65b1e98..26376b0 100644 --- a/sys/mips/conf/MALTA64 +++ b/sys/mips/conf/MALTA64 @@ -19,8 +19,9 @@ ident MALTA +machine mips mips64el # Malta supports both, so it isn't in std.malta + makeoptions ARCH_FLAGS="-march=mips64 -mabi=64" -makeoptions MIPS_LITTLE_ENDIAN=defined makeoptions LDSCRIPT_NAME= ldscript.mips.mips64 options YAMON diff --git a/sys/mips/conf/OCTEON1 b/sys/mips/conf/OCTEON1 index a00e95d..9028ba0 100644 --- a/sys/mips/conf/OCTEON1 +++ b/sys/mips/conf/OCTEON1 @@ -18,7 +18,6 @@ # # $FreeBSD$ -machine mips cpu CPU_CNMIPS ident OCTEON1 @@ -27,7 +26,6 @@ makeoptions LDSCRIPT_NAME=ldscript.mips.octeon1.64 # Don't build any modules yet. makeoptions MODULES_OVERRIDE="" -makeoptions TARGET_BIG_ENDIAN=defined makeoptions KERNLOADADDR=0xffffffff80100000 include "../cavium/std.octeon1" diff --git a/sys/mips/conf/OCTEON1-32 b/sys/mips/conf/OCTEON1-32 index 3fe7d61..dce780d 100644 --- a/sys/mips/conf/OCTEON1-32 +++ b/sys/mips/conf/OCTEON1-32 @@ -17,18 +17,16 @@ # # $FreeBSD$ -machine mips -cpu CPU_CNMIPS -ident OCTEON1 +ident OCTEON1-32 # Don't build any modules yet. makeoptions MODULES_OVERRIDE="" -makeoptions TARGET_BIG_ENDIAN=defined makeoptions ARCH_FLAGS="-march=octeon" makeoptions LDSCRIPT_NAME=ldscript.mips.octeon1.32 makeoptions KERNLOADADDR=0x81000000 include "../cavium/std.octeon1" +machine mips mipseb hints "OCTEON1.hints" #Default places to look for devices. diff --git a/sys/mips/conf/QEMU b/sys/mips/conf/QEMU index ebb09f8..fde9085 100644 --- a/sys/mips/conf/QEMU +++ b/sys/mips/conf/QEMU @@ -20,10 +20,6 @@ cpu CPU_MIPS32 ident QEMU -# XXX: These two options must be defined in MIPS kernel configs. -makeoptions MIPS_LITTLE_ENDIAN=defined -makeoptions ARCH_FLAGS=-march=mips32 - # Don't build any modules yet. makeoptions MODULES_OVERRIDE="" diff --git a/sys/mips/conf/SENTRY5 b/sys/mips/conf/SENTRY5 index c38e45f..0f6aa16 100644 --- a/sys/mips/conf/SENTRY5 +++ b/sys/mips/conf/SENTRY5 @@ -25,14 +25,9 @@ # ident SENTRY5 -cpu CPU_MIPS4KC -options ISA_MIPS32 -options CPU_SENTRY5 # XXX should this be a - # sub-cpu option? # XXX only siba should be hardwired for now; we will use # bus enumeration there -files "../sentry5/files.sentry5" hints "SENTRY5.hints" # sentry5 normally ships with cfe firmware; use the console for now @@ -40,8 +35,6 @@ options CFE options CFE_CONSOLE options ALT_BREAK_TO_DEBUGGER -#makeoptions ARCH_FLAGS=-march=mips32 -makeoptions MIPS_LITTLE_ENDIAN=defined makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols makeoptions MODULES_OVERRIDE="" @@ -56,18 +49,18 @@ options PSEUDOFS #Pseudo-filesystem framework options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions # Debugging for use in -current -#options DEADLKRES +#options DEADLKRES options INVARIANTS options INVARIANT_SUPPORT -#options BUS_DEBUG +#options BUS_DEBUG #makeoptions BUS_DEBUG device siba # Sonics SiliconBackplane device pci # siba_pcib -# device bfe # XXX will build both pci and siba -# device miibus # attachments +# device bfe # XXX will build both pci and siba +# device miibus # attachments # pci devices # notyet: diff --git a/sys/mips/conf/SWARM b/sys/mips/conf/SWARM index 6db2181..8c304fc 100644 --- a/sys/mips/conf/SWARM +++ b/sys/mips/conf/SWARM @@ -6,6 +6,7 @@ include std.SWARM ident SWARM +machine mips mipseb options ISA_MIPS32 makeoptions ARCH_FLAGS="-mabi=32 -march=mips32" diff --git a/sys/mips/conf/SWARM64 b/sys/mips/conf/SWARM64 index af04269..21cce4a 100644 --- a/sys/mips/conf/SWARM64 +++ b/sys/mips/conf/SWARM64 @@ -6,6 +6,7 @@ include std.SWARM ident SWARM64 +machine mips mips64eb makeoptions ARCH_FLAGS="-mabi=64 -march=mips64" makeoptions LDSCRIPT_NAME=ldscript.mips.64.cfe makeoptions KERNLOADADDR=0xffffffff80001000 diff --git a/sys/mips/conf/SWARM64_SMP b/sys/mips/conf/SWARM64_SMP index 7985210..35b1a5e 100644 --- a/sys/mips/conf/SWARM64_SMP +++ b/sys/mips/conf/SWARM64_SMP @@ -9,6 +9,7 @@ ident SWARM64_SMP options SMP options PRINTF_BUFR_SIZE=128 +machine mips mips64eb makeoptions ARCH_FLAGS="-mabi=64 -march=mips64" makeoptions LDSCRIPT_NAME=ldscript.mips.64.cfe makeoptions KERNLOADADDR=0xffffffff80001000 diff --git a/sys/mips/conf/SWARM_SMP b/sys/mips/conf/SWARM_SMP index 925f1bb..0906501 100644 --- a/sys/mips/conf/SWARM_SMP +++ b/sys/mips/conf/SWARM_SMP @@ -9,6 +9,7 @@ ident SWARM_SMP options SMP options PRINTF_BUFR_SIZE=128 +machine mips mipseb options ISA_MIPS32 makeoptions ARCH_FLAGS="-mabi=32 -march=mips32" diff --git a/sys/mips/conf/XLR b/sys/mips/conf/XLR index 34551d8..3df81c4 100644 --- a/sys/mips/conf/XLR +++ b/sys/mips/conf/XLR @@ -45,7 +45,7 @@ # # $FreeBSD$ -machine mips +machine mips mipseb cpu CPU_RMI ident XLR diff --git a/sys/mips/conf/XLR64 b/sys/mips/conf/XLR64 index 4bc8794..3d18f0c 100644 --- a/sys/mips/conf/XLR64 +++ b/sys/mips/conf/XLR64 @@ -17,7 +17,7 @@ # # $FreeBSD$ -machine mips +machine mips mips64eb cpu CPU_RMI ident XLR64 diff --git a/sys/mips/conf/XLRN32 b/sys/mips/conf/XLRN32 index d26a1a4..313db52 100644 --- a/sys/mips/conf/XLRN32 +++ b/sys/mips/conf/XLRN32 @@ -17,7 +17,7 @@ # # $FreeBSD$ -machine mips +machine mips mipseb cpu CPU_RMI ident XLRN32 diff --git a/sys/mips/conf/std.SWARM b/sys/mips/conf/std.SWARM index 879d175..ca7d92c 100644 --- a/sys/mips/conf/std.SWARM +++ b/sys/mips/conf/std.SWARM @@ -2,8 +2,8 @@ # $FreeBSD: projects/binutils-2.17/sys/mips/conf/std.SWARM 215068 2010-11-10 00:28:20Z imp $ # -files "../sibyte/files.sibyte" hints "SWARM.hints" +include "../sibyte/std.sibyte" options CFE options CFE_CONSOLE diff --git a/sys/mips/idt/std.idt b/sys/mips/idt/std.idt index e40f4a4..83eba1f 100644 --- a/sys/mips/idt/std.idt +++ b/sys/mips/idt/std.idt @@ -3,4 +3,5 @@ files "../idt/files.idt" +machine mips mipsel options ISA_MIPS32 diff --git a/sys/mips/sentry5/std.sentry5 b/sys/mips/sentry5/std.sentry5 new file mode 100644 index 0000000..0cf3655 --- /dev/null +++ b/sys/mips/sentry5/std.sentry5 @@ -0,0 +1,11 @@ +# $FreeBSD$ +# + +machine mips mipsel + +cpu CPU_MIPS4KC +options ISA_MIPS32 +options CPU_SENTRY5 # XXX should this be a + # sub-cpu option? +files "../sentry5/files.sentry5" + diff --git a/sys/mips/sibyte/std.sibyte b/sys/mips/sibyte/std.sibyte new file mode 100644 index 0000000..3f31153 --- /dev/null +++ b/sys/mips/sibyte/std.sibyte @@ -0,0 +1,3 @@ +# $FreeBSD$ + +files "../sibyte/files.sibyte" diff --git a/sys/modules/Makefile b/sys/modules/Makefile index a5ce22c..8037070 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -330,7 +330,7 @@ _syscons= syscons _vpo= vpo .endif -.if ${MACHINE_ARCH} != "arm" && ${MACHINE_ARCH} != "mips" +.if ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" # no BUS_SPACE_UNSPECIFIED # No barrier instruction support (specific to this driver) _sym= sym diff --git a/sys/modules/acpi/acpi/Makefile b/sys/modules/acpi/acpi/Makefile index ce1e572..8cb3ee5 100644 --- a/sys/modules/acpi/acpi/Makefile +++ b/sys/modules/acpi/acpi/Makefile @@ -1,5 +1,9 @@ # $FreeBSD$ +.if !defined(FORCE_BUILD) +.error "The ACPI module is deprecated, set FORCE_BUILD to force it" +.endif + .if ${MACHINE_CPUARCH} == "ia64" .error "ACPI can only be compiled into the kernel on the ia64 platform" .endif @@ -96,23 +100,24 @@ opt_ddb.h: Makefile .endif # Machine-specific code such as sleep/wakeup -SRCS+= acpi_apm.c acpi_machdep.c acpi_wakecode.h acpi_wakeup.c +SRCS+= acpi_apm.c acpi_machdep.c acpi_wakecode.h acpi_wakedata.h acpi_wakeup.c SRCS+= assym.s madt.c -CLEANFILES+= acpi_wakecode.bin acpi_wakecode.h acpi_wakecode.o +CLEANFILES+=acpi_wakecode.bin acpi_wakecode.h acpi_wakecode.o acpi_wakedata.h SRCS+= opt_global.h +ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} +NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC} +NM?= nm + .if ${MACHINE_CPUARCH} == "amd64" .if !defined(KERNBUILDDIR) CFLAGS+=-DSMP .endif -SRCS+= acpi_switch.S acpi_wakedata.h -CLEANFILES+= acpi_wakedata.h -ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} -NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC} -NM?= nm +SRCS+= acpi_switch.S acpi_switch.o: acpi_switch.S ${NORMAL_S} +.endif acpi_wakecode.o: acpi_wakecode.S assym.s ${NORMAL_S} acpi_wakecode.bin: acpi_wakecode.o @@ -125,10 +130,5 @@ acpi_wakedata.h: acpi_wakecode.o while read offset dummy what; do \ echo "#define $${what} 0x$${offset}"; \ done > ${.TARGET} -.else -acpi_wakecode.h: acpi_wakecode.S assym.s - ${MAKE} -f ${.CURDIR}/../../../${MACHINE_CPUARCH}/acpica/Makefile \ - MAKESRCPATH=${.CURDIR}/../../../${MACHINE_CPUARCH}/acpica -.endif .include <bsd.kmod.mk> diff --git a/sys/net/if_llatbl.c b/sys/net/if_llatbl.c index a0fb071..910d366 100644 --- a/sys/net/if_llatbl.c +++ b/sys/net/if_llatbl.c @@ -100,18 +100,34 @@ done: * This function is called by the timer functions * such as arptimer() and nd6_llinfo_timer(), and * the caller does the locking. + * + * Returns the number of held packets, if any, that were dropped. */ -void +size_t llentry_free(struct llentry *lle) { - + size_t pkts_dropped; + struct mbuf *next; + + pkts_dropped = 0; LLE_WLOCK_ASSERT(lle); LIST_REMOVE(lle, lle_next); - if (lle->la_hold != NULL) + while ((lle->la_numheld > 0) && (lle->la_hold != NULL)) { + next = lle->la_hold->m_nextpkt; m_freem(lle->la_hold); + lle->la_hold = next; + lle->la_numheld--; + pkts_dropped++; + } + + KASSERT(lle->la_numheld == 0, + ("%s: la_numheld %d > 0, pkts_droped %zd", __func__, + lle->la_numheld, pkts_dropped)); LLE_FREE_LOCKED(lle); + + return (pkts_dropped); } /* @@ -412,6 +428,7 @@ llatbl_lle_show(struct llentry_sa *la) db_printf(" lle_tbl=%p\n", lle->lle_tbl); db_printf(" lle_head=%p\n", lle->lle_head); db_printf(" la_hold=%p\n", lle->la_hold); + db_printf(" la_numheld=%d\n", lle->la_numheld); db_printf(" la_expire=%ju\n", (uintmax_t)lle->la_expire); db_printf(" la_flags=0x%04x\n", lle->la_flags); db_printf(" la_asked=%u\n", lle->la_asked); diff --git a/sys/net/if_llatbl.h b/sys/net/if_llatbl.h index a4d02ab..6c5ad18 100644 --- a/sys/net/if_llatbl.h +++ b/sys/net/if_llatbl.h @@ -58,6 +58,7 @@ struct llentry { struct lltable *lle_tbl; struct llentries *lle_head; struct mbuf *la_hold; + int la_numheld; /* # of packets currently held */ time_t la_expire; uint16_t la_flags; uint16_t la_asked; @@ -191,7 +192,7 @@ void lltable_drain(int); #endif int lltable_sysctl_dumparp(int, struct sysctl_req *); -void llentry_free(struct llentry *); +size_t llentry_free(struct llentry *); int llentry_update(struct llentry **, struct lltable *, struct sockaddr_storage *, struct ifnet *); diff --git a/sys/net/vnet.h b/sys/net/vnet.h index 1c8d1fe..76123c7 100644 --- a/sys/net/vnet.h +++ b/sys/net/vnet.h @@ -193,15 +193,6 @@ extern struct sx vnet_sxlock; * Virtual network stack memory allocator, which allows global variables to * be automatically instantiated for each network stack instance. */ -__asm__( -#if defined(__arm__) - ".section " VNET_SETNAME ", \"aw\", %progbits\n" -#else - ".section " VNET_SETNAME ", \"aw\", @progbits\n" -#endif - "\t.p2align " __XSTRING(CACHE_LINE_SHIFT) "\n" - "\t.previous"); - #define VNET_NAME(n) vnet_entry_##n #define VNET_DECLARE(t, n) extern t VNET_NAME(n) #define VNET_DEFINE(t, n) t VNET_NAME(n) __section(VNET_SETNAME) __used diff --git a/sys/net80211/ieee80211_ratectl_none.c b/sys/net80211/ieee80211_ratectl_none.c index 0979e9d..0edec44 100644 --- a/sys/net80211/ieee80211_ratectl_none.c +++ b/sys/net80211/ieee80211_ratectl_none.c @@ -59,6 +59,7 @@ none_deinit(struct ieee80211vap *vap) static void none_node_init(struct ieee80211_node *ni) { + ni->ni_txrate = ni->ni_rates.rs_rates[0] & IEEE80211_RATE_VAL; } static void diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 6d38388..ef59cdb 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -89,13 +89,16 @@ VNET_DEFINE(int, useloopback) = 1; /* use loopback interface for static VNET_DEFINE(int, arp_proxyall) = 0; static VNET_DEFINE(int, arpt_down) = 20; /* keep incomplete entries for * 20 seconds */ -static VNET_DEFINE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ +VNET_DEFINE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ + +static VNET_DEFINE(int, arp_maxhold) = 1; #define V_arpt_keep VNET(arpt_keep) #define V_arpt_down VNET(arpt_down) #define V_arp_maxtries VNET(arp_maxtries) #define V_arp_proxyall VNET(arp_proxyall) #define V_arpstat VNET(arpstat) +#define V_arp_maxhold VNET(arp_maxhold) SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, &VNET_NAME(arpt_keep), 0, @@ -109,9 +112,15 @@ SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW, SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW, &VNET_NAME(arp_proxyall), 0, "Enable proxy ARP for all suitable requests"); +SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, wait, CTLFLAG_RW, + &VNET_NAME(arpt_down), 0, + "Incomplete ARP entry lifetime in seconds"); SYSCTL_VNET_STRUCT(_net_link_ether_arp, OID_AUTO, stats, CTLFLAG_RW, &VNET_NAME(arpstat), arpstat, "ARP statistics (struct arpstat, net/if_arp.h)"); +SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, maxhold, CTLFLAG_RW, + &VNET_NAME(arp_maxhold), 0, + "Number of packets to hold per ARP entry"); static void arp_init(void); void arprequest(struct ifnet *, @@ -162,6 +171,7 @@ arptimer(void *arg) { struct ifnet *ifp; struct llentry *lle; + int pkts_dropped; KASSERT(arg != NULL, ("%s: arg NULL", __func__)); lle = (struct llentry *)arg; @@ -176,7 +186,8 @@ arptimer(void *arg) callout_active(&lle->la_timer)) { callout_stop(&lle->la_timer); LLE_REMREF(lle); - (void) llentry_free(lle); + pkts_dropped = llentry_free(lle); + ARPSTAT_ADD(dropped, pkts_dropped); ARPSTAT_INC(timeouts); } else { #ifdef DIAGNOSTIC @@ -275,6 +286,8 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, { struct llentry *la = 0; u_int flags = 0; + struct mbuf *curr = NULL; + struct mbuf *next = NULL; int error, renew; *lle = NULL; @@ -348,15 +361,28 @@ retry: } /* * There is an arptab entry, but no ethernet address - * response yet. Replace the held mbuf with this - * latest one. + * response yet. Add the mbuf to the list, dropping + * the oldest packet if we have exceeded the system + * setting. */ if (m != NULL) { + if (la->la_numheld >= V_arp_maxhold) { + if (la->la_hold != NULL) { + next = la->la_hold->m_nextpkt; + m_freem(la->la_hold); + la->la_hold = next; + la->la_numheld--; + ARPSTAT_INC(dropped); + } + } if (la->la_hold != NULL) { - m_freem(la->la_hold); - ARPSTAT_INC(dropped); - } - la->la_hold = m; + curr = la->la_hold; + while (curr->m_nextpkt != NULL) + curr = curr->m_nextpkt; + curr->m_nextpkt = m; + } else + la->la_hold = m; + la->la_numheld++; if (renew == 0 && (flags & LLE_EXCLUSIVE)) { flags &= ~LLE_EXCLUSIVE; LLE_DOWNGRADE(la); @@ -483,7 +509,6 @@ in_arpinput(struct mbuf *m) struct rtentry *rt; struct ifaddr *ifa; struct in_ifaddr *ia; - struct mbuf *hold; struct sockaddr sa; struct in_addr isaddr, itaddr, myaddr; u_int8_t *enaddr = NULL; @@ -698,15 +723,29 @@ match: } la->la_asked = 0; la->la_preempt = V_arp_maxtries; - hold = la->la_hold; - if (hold != NULL) { - la->la_hold = NULL; + /* + * The packets are all freed within the call to the output + * routine. + * + * NB: The lock MUST be released before the call to the + * output routine. + */ + if (la->la_hold != NULL) { + struct mbuf *m_hold, *m_hold_next; + memcpy(&sa, L3_ADDR(la), sizeof(sa)); - } - LLE_WUNLOCK(la); - if (hold != NULL) - (*ifp->if_output)(ifp, hold, &sa, NULL); - } + LLE_WUNLOCK(la); + for (m_hold = la->la_hold, la->la_hold = NULL; + m_hold != NULL; m_hold = m_hold_next) { + m_hold_next = m_hold->m_nextpkt; + m_hold->m_nextpkt = NULL; + (*ifp->if_output)(ifp, m_hold, &sa, NULL); + } + } else + LLE_WUNLOCK(la); + la->la_hold = NULL; + la->la_numheld = 0; + } /* end of FIB loop */ reply: if (op != ARPOP_REQUEST) goto drop; diff --git a/sys/netinet/in.c b/sys/netinet/in.c index b2ae8d9..2ec54e2 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <net/if.h> #include <net/if_var.h> +#include <net/if_arp.h> #include <net/if_dl.h> #include <net/if_llatbl.h> #include <net/if_types.h> @@ -89,6 +90,9 @@ SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, same_prefix_carp_only, CTLFLAG_RW, VNET_DECLARE(struct inpcbinfo, ripcbinfo); #define V_ripcbinfo VNET(ripcbinfo) +VNET_DECLARE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ +#define V_arpstat VNET(arpstat) + /* * Return 1 if an internet address is for a ``local'' host * (one to which we have a connection). If subnetsarelocal @@ -1363,6 +1367,7 @@ in_lltable_prefix_free(struct lltable *llt, const struct sockaddr_in *msk = (const struct sockaddr_in *)mask; struct llentry *lle, *next; register int i; + size_t pkts_dropped; for (i=0; i < LLTBL_HASHTBL_SIZE; i++) { LIST_FOREACH_SAFE(lle, &llt->lle_head[i], lle_next, next) { @@ -1375,7 +1380,8 @@ in_lltable_prefix_free(struct lltable *llt, LLE_WLOCK(lle); if (canceled) LLE_REMREF(lle); - llentry_free(lle); + pkts_dropped = llentry_free(lle); + ARPSTAT_ADD(dropped, pkts_dropped); } } } diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index 50820b7..06d4e61 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -9927,13 +9927,14 @@ sctp_send_sack(struct sctp_tcb *stcb) caddr_t limit; uint32_t *dup; int limit_reached = 0; - unsigned int i, sel_start, siz, j; + unsigned int i, siz, j; unsigned int num_gap_blocks = 0, num_nr_gap_blocks = 0, space; int num_dups = 0; int space_req; uint32_t highest_tsn; uint8_t flags; uint8_t type; + uint8_t tsn_map; if ((stcb->asoc.sctp_nr_sack_on_off == 1) && (stcb->asoc.peer_supports_nr_sack == 1)) { @@ -10123,24 +10124,24 @@ sctp_send_sack(struct sctp_tcb *stcb) } else { offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn; } - if ((offset == 1) || - ((type == SCTP_NR_SELECTIVE_ACK) && - ((asoc->mapping_array[0] & (1 << (1 - offset))) == 0))) { - sel_start = 0; - } else { - sel_start = 1; - } if (((type == SCTP_SELECTIVE_ACK) && compare_with_wrap(highest_tsn, asoc->cumulative_tsn, MAX_TSN)) || ((type == SCTP_NR_SELECTIVE_ACK) && compare_with_wrap(asoc->highest_tsn_inside_map, asoc->cumulative_tsn, MAX_TSN))) { /* we have a gap .. maybe */ for (i = 0; i < siz; i++) { + tsn_map = asoc->mapping_array[i]; if (type == SCTP_SELECTIVE_ACK) { - selector = &sack_array[asoc->mapping_array[i] | asoc->nr_mapping_array[i]]; - } else { - selector = &sack_array[asoc->mapping_array[i]]; + tsn_map |= asoc->nr_mapping_array[i]; + } + if (i == 0) { + /* + * Clear all bits corresponding to TSNs + * smaller or equal to the cumulative TSN. + */ + tsn_map &= (~0 << (1 - offset)); } + selector = &sack_array[tsn_map]; if (mergeable && selector->right_edge) { /* * Backup, left and right edges were ok to @@ -10152,7 +10153,7 @@ sctp_send_sack(struct sctp_tcb *stcb) if (selector->num_entries == 0) mergeable = 0; else { - for (j = sel_start; j < selector->num_entries; j++) { + for (j = 0; j < selector->num_entries; j++) { if (mergeable && selector->right_edge) { /* * do a merge by NOT setting @@ -10184,7 +10185,6 @@ sctp_send_sack(struct sctp_tcb *stcb) /* Reached the limit stop */ break; } - sel_start = 0; offset += 8; } } @@ -10199,11 +10199,6 @@ sctp_send_sack(struct sctp_tcb *stcb) siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_nr_map + 7) / 8; } - if ((asoc->nr_mapping_array[0] & (1 << (1 - offset))) == 0) { - sel_start = 0; - } else { - sel_start = 1; - } if (compare_with_wrap(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, MAX_TSN)) { offset = 1; } else { @@ -10212,7 +10207,16 @@ sctp_send_sack(struct sctp_tcb *stcb) if (compare_with_wrap(asoc->highest_tsn_inside_nr_map, asoc->cumulative_tsn, MAX_TSN)) { /* we have a gap .. maybe */ for (i = 0; i < siz; i++) { - selector = &sack_array[asoc->nr_mapping_array[i]]; + tsn_map = asoc->nr_mapping_array[i]; + if (i == 0) { + /* + * Clear all bits corresponding to + * TSNs smaller or equal to the + * cumulative TSN. + */ + tsn_map &= (~0 << (1 - offset)); + } + selector = &sack_array[tsn_map]; if (mergeable && selector->right_edge) { /* * Backup, left and right edges were @@ -10224,7 +10228,7 @@ sctp_send_sack(struct sctp_tcb *stcb) if (selector->num_entries == 0) mergeable = 0; else { - for (j = sel_start; j < selector->num_entries; j++) { + for (j = 0; j < selector->num_entries; j++) { if (mergeable && selector->right_edge) { /* * do a merge by NOT @@ -10257,7 +10261,6 @@ sctp_send_sack(struct sctp_tcb *stcb) /* Reached the limit stop */ break; } - sel_start = 0; offset += 8; } } diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index 7e305c4..aaa0500 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -3464,6 +3464,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) cnt = 0; for ((asoc = LIST_FIRST(&inp->sctp_asoc_list)); asoc != NULL; asoc = nasoc) { + SCTP_TCB_LOCK(asoc); nasoc = LIST_NEXT(asoc, sctp_tcblist); if (asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { if (asoc->asoc.state & SCTP_STATE_IN_ACCEPT_QUEUE) { @@ -3471,10 +3472,10 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, asoc, NULL); } cnt++; + SCTP_TCB_UNLOCK(asoc); continue; } /* Free associations that are NOT killing us */ - SCTP_TCB_LOCK(asoc); if ((SCTP_GET_STATE(&asoc->asoc) != SCTP_STATE_COOKIE_WAIT) && ((asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0)) { struct mbuf *op_err; diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index 76c58a5..707d05c 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -1212,8 +1212,6 @@ sctp_print_mapping_array(struct sctp_association *asoc) printf("Renegable mapping array (last %d entries are zero):\n", asoc->mapping_array_size - limit); for (i = 0; i < limit; i++) { printf("%2.2x%c", asoc->mapping_array[i], ((i + 1) % 16) ? ' ' : '\n'); - if (((i + 1) % 16) == 0) - printf("\n"); } if (limit % 16) printf("\n"); diff --git a/sys/powerpc/aim/mp_cpudep.c b/sys/powerpc/aim/mp_cpudep.c index 312164e..3ee22f3 100644 --- a/sys/powerpc/aim/mp_cpudep.c +++ b/sys/powerpc/aim/mp_cpudep.c @@ -228,8 +228,8 @@ cpudep_save_config(void *dummy) powerpc_sync(); break; -#ifdef __powerpc64__ case IBMCELLBE: + #ifdef NOTYET /* Causes problems if in instruction stream on 970 */ if (mfmsr() & PSL_HV) { bsp_state[0] = mfspr(SPR_HID0); bsp_state[1] = mfspr(SPR_HID1); @@ -238,11 +238,11 @@ cpudep_save_config(void *dummy) bsp_state[4] = mfspr(SPR_CELL_TSCR); } + #endif bsp_state[5] = mfspr(SPR_CELL_TSRL); break; -#endif case MPC7450: case MPC7455: case MPC7457: @@ -303,8 +303,8 @@ cpudep_ap_setup() powerpc_sync(); break; -#ifdef __powerpc64__ case IBMCELLBE: + #ifdef NOTYET /* Causes problems if in instruction stream on 970 */ if (mfmsr() & PSL_HV) { mtspr(SPR_HID0, bsp_state[0]); mtspr(SPR_HID1, bsp_state[1]); @@ -313,11 +313,11 @@ cpudep_ap_setup() mtspr(SPR_CELL_TSCR, bsp_state[4]); } + #endif mtspr(SPR_CELL_TSRL, bsp_state[5]); break; -#endif case MPC7450: case MPC7455: case MPC7457: diff --git a/tools/regression/netinet/arphold/Makefile b/tools/regression/netinet/arphold/Makefile new file mode 100644 index 0000000..37abefb --- /dev/null +++ b/tools/regression/netinet/arphold/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= arphold +NO_MAN= +CFLAGS+= -Wall + +.include <bsd.prog.mk> diff --git a/tools/regression/netinet/arphold/arphold.c b/tools/regression/netinet/arphold/arphold.c new file mode 100644 index 0000000..092461d --- /dev/null +++ b/tools/regression/netinet/arphold/arphold.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2010 Advanced Computing Technologies LLC + * Written by George Neville-Neil gnn@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. + * + * Description: The following is a test of the arp entry packet queues + * which replaced the single packet hold entry that existed in the BSDs + * since time immemorial. The test process is: + * + * 1) Find out the current system limit (maxhold) + * 2) Using an IP address for which we do not yet have an entry + * load up an ARP entry packet queue with exactly that many packets. + * 3) Check the arp dropped stat to make sure that we have not dropped + * any packets as yet. + * 4) Add one more packet to the queue. + * 5) Make sure that only one packet was dropped. + * + * CAVEAT: The ARP timer will flush the queue after 1 second so it is + * important not to run this code in a fast loop or the test will + * fail. + * + * $FreeBSD$ + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/sysctl.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <net/if_arp.h> + +#define MSG_SIZE 1024 +#define PORT 6969 + +int +main(int argc, char **argv) +{ + + int sock; + int maxhold; + int wait; + size_t size = sizeof(maxhold); + struct sockaddr_in dest; + char message[MSG_SIZE]; + struct arpstat arpstat; + size_t len = sizeof(arpstat); + unsigned long dropped = 0; + + memset(&message, 1, sizeof(message)); + + if (sysctlbyname("net.link.ether.inet.maxhold", &maxhold, &size, + NULL, 0) < 0) { + perror("not ok 1 - sysctlbyname failed"); + exit(1); + } + +#ifdef DEBUG + printf("maxhold is %d\n", maxhold); +#endif /* DEBUG */ + + if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + perror("not ok 1 - could not open socket"); + exit(1); + } + + bzero(&dest, sizeof(dest)); + if (inet_pton(AF_INET, argv[1], &dest.sin_addr.s_addr) != 1) { + perror("not ok 1 - could not parse address"); + exit(1); + } + dest.sin_len = sizeof(dest); + dest.sin_family = AF_INET; + dest.sin_port = htons(PORT); + + if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len, + NULL, 0) < 0) { + perror("not ok 1 - could not get initial arp stats"); + exit(1); + } + + dropped = arpstat.dropped; +#ifdef DEBUG + printf("dropped before %ld\n", dropped); +#endif /* DEBUG */ + + /* + * Load up the queue in the ARP entry to the maximum. + * We should not drop any packets at this point. + */ + + while (maxhold > 0) { + if (sendto(sock, message, sizeof(message), 0, + (struct sockaddr *)&dest, sizeof(dest)) < 0) { + perror("not ok 1 - could not send packet"); + exit(1); + } + maxhold--; + } + + if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len, + NULL, 0) < 0) { + perror("not ok 1 - could not get new arp stats"); + exit(1); + } + +#ifdef DEBUG + printf("dropped after %ld\n", arpstat.dropped); +#endif /* DEBUG */ + + if (arpstat.dropped != dropped) { + printf("not ok 1 - Failed, drops changed:" + "before %ld after %ld\n", dropped, arpstat.dropped); + exit(1); + } + + dropped = arpstat.dropped; + + /* Now add one extra and make sure it is dropped. */ + if (sendto(sock, message, sizeof(message), 0, + (struct sockaddr *)&dest, sizeof(dest)) < 0) { + perror("not ok 1 - could not send packet"); + exit(1); + } + + if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len, + NULL, 0) < 0) { + perror("not ok 1 - could not get new arp stats"); + exit(1); + } + + if (arpstat.dropped != (dropped + 1)) { + printf("not ok 1 - Failed to drop one packet: before" + " %ld after %ld\n", dropped, arpstat.dropped); + exit(1); + } + + printf("ok\n"); + return (0); +} diff --git a/tools/regression/netinet/arphold/arphold.t b/tools/regression/netinet/arphold/arphold.t new file mode 100644 index 0000000..eb1b2a8 --- /dev/null +++ b/tools/regression/netinet/arphold/arphold.t @@ -0,0 +1,7 @@ +#!/bin/sh +# +# $FreeBSD$ + +make arphold 2>&1 > /dev/null + +./arphold 192.168.1.222 diff --git a/usr.bin/top/top.local.1 b/usr.bin/top/top.local.1 index a3f3540..cf2ba01 100644 --- a/usr.bin/top/top.local.1 +++ b/usr.bin/top/top.local.1 @@ -6,8 +6,8 @@ The '-H' option will toggle the display of kernel visible thread contexts. At runtime the 'H' key will toggle this mode. The default is OFF. .SH DESCRIPTION OF MEMORY -Mem: 9220K Active, 1032K Inact, 3284K Wired, 1MB Cache, 2M Buf, 1320K Free -Swap: 91M Total, 79M Free, 13% Inuse, 80K In, 104 K Out +Mem: 9220K Active, 1032K Inact, 3284K Wired, 1M Cache, 2M Buf, 1320K Free +Swap: 91M Total, 79M Free, 13% Inuse, 80K In, 104K Out .B K: Kilobyte @@ -19,23 +19,23 @@ Megabyte 1/100 .TP .B Active: -number of pages active +number of bytes active .TP .B Inact: -number of pages inactive +number of bytes inactive .TP .B Wired: -number of pages wired down, including cached file data pages +number of bytes wired down, including cached file data pages .TP .B Cache: -number of clean pages caching data that are available for +number of clean bytes caching data that are available for immediate reallocation .TP .B Buf: -number of pages used for BIO-level disk caching +number of bytes used for BIO-level disk caching .TP .B Free: -number of pages free +number of bytes free .TP .B Total: total available swap usage @@ -47,7 +47,7 @@ total free swap usage swap usage .TP .B In: -pages paged in from swap devices (last interval) +bytes paged in from swap devices (last interval) .TP .B Out: -pages paged out to swap devices (last interval) +bytes paged out to swap devices (last interval) diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index b9dcfe4..d25c4de 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -241,13 +241,14 @@ main(int ac, char **av) if (fname != NULL) { /* Use output file */ if ((trussinfo->outfile = fopen(fname, "w")) == NULL) errx(1, "cannot open %s", fname); + /* + * Set FD_CLOEXEC, so that the output file is not shared with + * the traced process. + */ + if (fcntl(fileno(trussinfo->outfile), F_SETFD, FD_CLOEXEC) == + -1) + warn("fcntl()"); } - /* - * Set FD_CLOEXEC, so that the output file is not shared with - * the traced process. - */ - if (fcntl(fileno(trussinfo->outfile), F_SETFD, FD_CLOEXEC) == -1) - warn("fcntl()"); /* * If truss starts the process itself, it will ignore some signals -- diff --git a/usr.sbin/bluetooth/Makefile b/usr.sbin/bluetooth/Makefile index ad193d0..594b440 100644 --- a/usr.sbin/bluetooth/Makefile +++ b/usr.sbin/bluetooth/Makefile @@ -2,6 +2,7 @@ # $FreeBSD$ SUBDIR= \ + ath3kfw \ bcmfw \ bt3cfw \ bthidcontrol \ diff --git a/usr.sbin/bluetooth/ath3kfw/Makefile b/usr.sbin/bluetooth/ath3kfw/Makefile new file mode 100644 index 0000000..0ff010f --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD$ + +PROG= ath3kfw +MAN= ath3kfw.8 +WARNS?= 6 +DPADD+= ${LIBUSB} +LDADD+= -lusb + +.include <bsd.prog.mk> diff --git a/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 b/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 new file mode 100644 index 0000000..be10b47 --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 @@ -0,0 +1,78 @@ +.\" Copyright (c) 2010 Maksim Yevmenkin <m_evmenkin@yahoo.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. +.\" +.\" 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$ +.\" +.Dd Novermber 9, 2010 +.Dt ATH3KFW 8 +.Os +.Sh NAME +.Nm ath3kfw +.Nd firmware download utility for Atheros AR3011 chip based Bluetooth USB devices +.Sh SYNOPSIS +.Nm +.Fl d Ar device_name +.Fl f Ar firmware_file_name +.Nm +.Fl h +.Sh DESCRIPTION +The +.Nm +utility downloads the specified firmware file to the specified +.Xr ugen 4 +device. +.Pp +This utility will +.Em only +work with Atheros AR3011 chip based Bluetooth USB devices. +The identification is currently based on USB vendor ID/product ID pair. +The vendor ID should be 0x0cf3 +.Pq Dv USB_VENDOR_ATHEROS2 +and the product ID should be 0x3000. +.Pp +Firmware files ath3k-1.fw and ath3k-2.fw can be obtained from the +linux-firmware RPM. +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl d Ar device_name +Specify +.Xr ugen 4 +device name. +.It Fl f Ar firmware_file_name +Specify firmware file name for download. +.It Fl h +Display usage message and exit. +.El +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr libusb 3 , +.Xr ugen 4 , +.Xr devd 8 +.Sh AUTHORS +.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com +.Sh BUGS +Most likely. +Please report if found. diff --git a/usr.sbin/bluetooth/ath3kfw/ath3kfw.c b/usr.sbin/bluetooth/ath3kfw/ath3kfw.c new file mode 100644 index 0000000..02d4501 --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/ath3kfw.c @@ -0,0 +1,287 @@ +/* + * ath3kfw.c + */ + +/*- + * Copyright (c) 2010 Maksim Yevmenkin <m_evmenkin@yahoo.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. + * + * 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 <errno.h> +#include <fcntl.h> +#include <libusb20_desc.h> +#include <libusb20.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include <unistd.h> + +#define ATH3KFW "ath3kfw" +#define ATH3KFW_VENDOR_ID 0x0cf3 +#define ATH3KFW_PRODUCT_ID 0x3000 +#define ATH3KFW_FW "/usr/local/etc/ath3k-1.fw" +#define ATH3KFW_BULK_EP 0x02 +#define ATH3KFW_REQ_DFU_DNLOAD 1 +#define ATH3KFW_MAX_BSIZE 4096 + +static int parse_ugen_name (char const *ugen, uint8_t *bus, + uint8_t *addr); +static int find_device (struct libusb20_backend *be, + uint8_t bus, uint8_t addr, + struct libusb20_device **dev); +static int download_firmware (struct libusb20_device *dev, + char const *firmware); +static void usage (void); + +/* + * Firmware downloader for Atheros AR3011 based USB Bluetooth devices + */ + +int +main(int argc, char **argv) +{ + uint8_t bus, addr; + char const *firmware; + struct libusb20_backend *be; + struct libusb20_device *dev; + int n; + + openlog(ATH3KFW, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_USER); + + bus = 0; + addr = 0; + firmware = ATH3KFW_FW; + + while ((n = getopt(argc, argv, "d:f:h")) != -1) { + switch (n) { + case 'd': /* ugen device name */ + if (parse_ugen_name(optarg, &bus, &addr) < 0) + usage(); + break; + + case 'f': /* firmware file */ + firmware = optarg; + break; + + case 'h': + default: + usage(); + break; + /* NOT REACHED */ + } + } + + be = libusb20_be_alloc_default(); + if (be == NULL) { + syslog(LOG_ERR, "libusb20_be_alloc_default() failed"); + return (-1); + } + + if (find_device(be, bus, addr, &dev) < 0) { + syslog(LOG_ERR, "ugen%d.%d is not recognized as " \ + "Atheros AR3011 based device " \ + "(possibly caused by lack of permissions)", bus, addr); + return (-1); + } + + if (download_firmware(dev, firmware) < 0) { + syslog(LOG_ERR, "could not download %s firmare to ugen%d.%d", + firmware, bus, addr); + return (-1); + } + + libusb20_be_free(be); + closelog(); + + return (0); +} + +/* + * Parse ugen name and extract device's bus and address + */ + +static int +parse_ugen_name(char const *ugen, uint8_t *bus, uint8_t *addr) +{ + char *ep; + + if (strncmp(ugen, "ugen", 4) != 0) + return (-1); + + *bus = (uint8_t) strtoul(ugen + 4, &ep, 10); + if (*ep != '.') + return (-1); + + *addr = (uint8_t) strtoul(ep + 1, &ep, 10); + if (*ep != '\0') + return (-1); + + return (0); +} + +/* + * Find USB device + */ + +static int +find_device(struct libusb20_backend *be, uint8_t bus, uint8_t addr, + struct libusb20_device **dev) +{ + struct LIBUSB20_DEVICE_DESC_DECODED *desc; + + *dev = NULL; + + while ((*dev = libusb20_be_device_foreach(be, *dev)) != NULL) { + if (libusb20_dev_get_bus_number(*dev) != bus || + libusb20_dev_get_address(*dev) != addr) + continue; + + desc = libusb20_dev_get_device_desc(*dev); + if (desc == NULL) + continue; + + if (desc->idVendor != ATH3KFW_VENDOR_ID || + desc->idProduct != ATH3KFW_PRODUCT_ID) + continue; + + break; + } + + return ((*dev == NULL)? -1 : 0); +} + +/* + * Download firmware + */ + +static int +download_firmware(struct libusb20_device *dev, char const *firmware) +{ + struct libusb20_transfer *bulk; + struct LIBUSB20_CONTROL_SETUP_DECODED req; + int fd, n, error; + uint8_t buf[ATH3KFW_MAX_BSIZE]; + + error = -1; + + if (libusb20_dev_open(dev, 1) != 0) { + syslog(LOG_ERR, "libusb20_dev_open() failed"); + return (error); + } + + if ((bulk = libusb20_tr_get_pointer(dev, 0)) == NULL) { + syslog(LOG_ERR, "libusb20_tr_get_pointer() failed"); + goto out; + } + + if (libusb20_tr_open(bulk, ATH3KFW_MAX_BSIZE, 1, ATH3KFW_BULK_EP) != 0) { + syslog(LOG_ERR, "libusb20_tr_open(%d, 1, %d) failed", + ATH3KFW_MAX_BSIZE, ATH3KFW_BULK_EP); + goto out; + } + + if ((fd = open(firmware, O_RDONLY)) < 0) { + syslog(LOG_ERR, "open(%s) failed. %s", + firmware, strerror(errno)); + goto out1; + } + + n = read(fd, buf, 20); + if (n != 20) { + syslog(LOG_ERR, "read(%s, 20) failed. %s", + firmware, strerror(errno)); + goto out2; + } + + LIBUSB20_INIT(LIBUSB20_CONTROL_SETUP, &req); + req.bmRequestType = LIBUSB20_REQUEST_TYPE_VENDOR; + req.bRequest = ATH3KFW_REQ_DFU_DNLOAD; + req.wLength = 20; + + if (libusb20_dev_request_sync(dev, &req, buf, NULL, 5000, 0) != 0) { + syslog(LOG_ERR, "libusb20_dev_request_sync() failed"); + goto out2; + } + + for (;;) { + n = read(fd, buf, sizeof(buf)); + if (n < 0) { + syslog(LOG_ERR, "read(%s, %d) failed. %s", + firmware, (int) sizeof(buf), strerror(errno)); + goto out2; + } + if (n == 0) + break; + + libusb20_tr_setup_bulk(bulk, buf, n, 3000); + libusb20_tr_start(bulk); + + while (libusb20_dev_process(dev) == 0) { + if (libusb20_tr_pending(bulk) == 0) + break; + + libusb20_dev_wait_process(dev, -1); + } + + if (libusb20_tr_get_status(bulk) != 0) { + syslog(LOG_ERR, "bulk transfer failed with status %d", + libusb20_tr_get_status(bulk)); + goto out2; + } + } + + error = 0; +out2: + close(fd); +out1: + libusb20_tr_close(bulk); +out: + libusb20_dev_close(dev); + + return (error); +} + +/* + * Display usage and exit + */ + +static void +usage(void) +{ + printf( +"Usage: %s -d ugenX.Y -f firmware_file\n" +"Usage: %s -h\n" \ +"Where:\n" \ +"\t-d ugenX.Y ugen device name\n" \ +"\t-f firmware image firmware image file name for download\n" \ +"\t-h display this message\n", ATH3KFW, ATH3KFW); + + exit(255); +} + diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c index 4bf67ea..273f221 100644 --- a/usr.sbin/sysinstall/install.c +++ b/usr.sbin/sysinstall/install.c @@ -692,7 +692,7 @@ nodisks: "may do so by typing: /usr/sbin/sysinstall."); } if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { - if (!msgYesNo("Would you like to configure any Ethernet network devices?")) { + if (!msgYesNo("Would you like to configure any Ethernet or PLIP network devices?")) { Device *tmp = tcpDeviceSelect(); if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) diff --git a/usr.sbin/sysinstall/menus.c b/usr.sbin/sysinstall/menus.c index 2015978..e2c8f5e 100644 --- a/usr.sbin/sysinstall/menus.c +++ b/usr.sbin/sysinstall/menus.c @@ -793,6 +793,8 @@ DMenu MenuMediaFTP = { VAR_FTP_PATH "=ftp://ftp2.se.freebsd.org" }, { " Sweden #3", "ftp3.se.freebsd.org", NULL, dmenuSetVariable, NULL, VAR_FTP_PATH "=ftp://ftp3.se.freebsd.org" }, + { " Sweden #4", "ftp4.se.freebsd.org", NULL, dmenuSetVariable, NULL, + VAR_FTP_PATH "=ftp://ftp4.se.freebsd.org" }, { " Sweden #5", "ftp5.se.freebsd.org", NULL, dmenuSetVariable, NULL, VAR_FTP_PATH "=ftp://ftp5.se.freebsd.org" }, @@ -882,7 +884,7 @@ DMenu MenuMediaFTP = { DMenu MenuNetworkDevice = { DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS, "Network interface information required", - "Please select the ethernet device to configure.\n\n" + "Please select the ethernet or PLIP device to configure.\n\n" "", "Press F1 to read network configuration manual", "network_device", |