diff options
Diffstat (limited to 'usr/src')
125 files changed, 1896 insertions, 1560 deletions
diff --git a/usr/src/cmd/mdb/common/modules/libc/libc.c b/usr/src/cmd/mdb/common/modules/libc/libc.c index 799d99cd6c..584aea7ad4 100644 --- a/usr/src/cmd/mdb/common/modules/libc/libc.c +++ b/usr/src/cmd/mdb/common/modules/libc/libc.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -520,15 +520,15 @@ d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) ulwp.ul_max_spinners, ulwp.ul_door_noreserve); - HD("queue_fifo c'w'defer e'detect' async_safe pad1[0] pad1[1]"); + HD("queue_fifo c'w'defer e'detect' async_safe pad1 save_state"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_queue_fifo), ulwp.ul_queue_fifo, ulwp.ul_cond_wait_defer, ulwp.ul_error_detection, ulwp.ul_async_safe, - ulwp.ul_pad1[0], - ulwp.ul_pad1[1]); + ulwp.ul_pad1, + ulwp.ul_save_state); HD("adapt'spin queue_spin critical sigdefer vfork"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %d\n", @@ -565,12 +565,12 @@ d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) prt_addr(ulwp.ul_schedctl_called, 1), prt_addr((void *)ulwp.ul_schedctl, 0)); - HD("bindflags pad2 stsd &ftsd"); + HD("bindflags libc_locks stsd &ftsd"); mdb_printf(OFFSTR, OFFSET(ul_bindflags)); mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", ulwp.ul_bindflags); - mdb_printf("%-10d ", ulwp.ul_pad2); + mdb_printf("%-10d ", ulwp.ul_libc_locks); mdb_printf("%s %s\n", prt_addr(ulwp.ul_stsd, 1), prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0)); diff --git a/usr/src/cmd/sgs/rtld/common/external.c b/usr/src/cmd/sgs/rtld/common/external.c index 4f1d8a4513..f47f900035 100644 --- a/usr/src/cmd/sgs/rtld/common/external.c +++ b/usr/src/cmd/sgs/rtld/common/external.c @@ -20,9 +20,10 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + #pragma ident "%Z%%M% %I% %E% SMI" /* @@ -163,19 +164,19 @@ * Solaris 10 CI_ATEXIT and CI_LCMESSAGES via _ld_libc() * CI_* via RTLDINFO and _ld_libc() - new libthread */ -#include "_synonyms.h" - -#include <sys/debug.h> -#include <synch.h> -#include <signal.h> -#include <thread.h> -#include <synch.h> -#include <strings.h> -#include <stdio.h> -#include <debug.h> -#include <libc_int.h> -#include "_elf.h" -#include "_rtld.h" + +#include "_synonyms.h" +#include <sys/debug.h> +#include <synch.h> +#include <signal.h> +#include <thread.h> +#include <synch.h> +#include <strings.h> +#include <stdio.h> +#include <debug.h> +#include <libc_int.h> +#include "_elf.h" +#include "_rtld.h" /* * This interface provides the unified process model communication between @@ -544,4 +545,79 @@ _thr_min_stack() #endif } +/* + * The following functions are cancellation points in libc. + * They are called from other functions in libc that we extract + * and use directly. We don't do cancellation while we are in + * the dynamic linker, so we redefine these to call the primitive, + * non-cancellation interfaces. + */ + +#pragma weak close = _close +int +_close(int fildes) +{ + extern int __close(int); + + return (__close(fildes)); +} + +#pragma weak fcntl = _fcntl +int +_fcntl(int fildes, int cmd, ...) +{ + extern int __fcntl(int, int, ...); + intptr_t arg; + va_list ap; + + va_start(ap, cmd); + arg = va_arg(ap, intptr_t); + va_end(ap); + return (__fcntl(fildes, cmd, arg)); +} + +#pragma weak open = _open +int +_open(const char *path, int oflag, ...) +{ + extern int __open(const char *, int, ...); + mode_t mode; + va_list ap; + + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + return (__open(path, oflag, mode)); +} + +#pragma weak openat = _openat +int +_openat(int fd, const char *path, int oflag, ...) +{ + extern int __openat(int, const char *, int, ...); + mode_t mode; + va_list ap; + + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + return (__openat(fd, path, oflag, mode)); +} + +#pragma weak read = _read +ssize_t +_read(int fd, void *buf, size_t size) +{ + extern ssize_t __read(int, void *, size_t); + return (__read(fd, buf, size)); +} + +#pragma weak write = _write +ssize_t +_write(int fd, const void *buf, size_t size) +{ + extern ssize_t __write(int, const void *, size_t); + return (__write(fd, buf, size)); +} + #endif /* EXPAND_RELATIVE */ diff --git a/usr/src/cmd/sgs/rtld/common/mapfile-vers b/usr/src/cmd/sgs/rtld/common/mapfile-vers index 5a9c286fb2..2915fce8ef 100644 --- a/usr/src/cmd/sgs/rtld/common/mapfile-vers +++ b/usr/src/cmd/sgs/rtld/common/mapfile-vers @@ -20,7 +20,7 @@ # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -93,18 +93,15 @@ SUNWprivate_1.2 { _environ; # PLT tracing getenv() support. environ; - _open; # Some routines are useful for support - _close; # libraries such as liblddbg (this - memcpy; # reduces the cost of debugging as the - snprintf; # library doesn't have its own - sprintf; # dependency on libc). - strcat; - strcmp; - strcpy; # Note that some of these functions - strlen; # (like sprintf) may have reduced - strrchr; # functionality over libc, as a simpler - strtok_r; # implementation is provided in ld.so.1. - _write; + memcpy; # Some routines are useful for support + snprintf; # libraries such as liblddbg. + sprintf; # Note that some of these functions + strcat; # (like sprintf) may have reduced + strcmp; # functionality over libc, as a simpler + strcpy; # implementation is provided in ld.so.1. + strlen; + strrchr; + strtok_r; ___errno; qsort; local: diff --git a/usr/src/cmd/truss/expound.c b/usr/src/cmd/truss/expound.c index 22f29b9d81..3b6369276c 100644 --- a/usr/src/cmd/truss/expound.c +++ b/usr/src/cmd/truss/expound.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -4954,7 +4954,7 @@ expound(private_t *pri, long r0, int raw) if (!err && pri->sys_nargs > 1) show_sigset(pri, (long)pri->sys_args[1], "sigmask"); break; - case SYS_waitsys: + case SYS_waitid: if (!err && pri->sys_nargs > 2) show_siginfo(pri, (long)pri->sys_args[2]); break; diff --git a/usr/src/cmd/truss/listopts.c b/usr/src/cmd/truss/listopts.c index b8a4dfabd7..e7b0250a5e 100644 --- a/usr/src/cmd/truss/listopts.c +++ b/usr/src/cmd/truss/listopts.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -237,9 +237,9 @@ syslist(char *str, /* string of syscall names */ goto def; case SYS_wait: /* set both if either */ - case SYS_waitsys: + case SYS_waitid: sysx = SYS_wait; - sys = SYS_waitsys; + sys = SYS_waitid; goto def; case SYS_lseek: /* set both if either */ @@ -290,8 +290,8 @@ syslist(char *str, /* string of syscall names */ } } else { (void) fprintf(stderr, - "%s: unrecognized syscall: %s\n", - command, name); + "%s: unrecognized syscall: %s\n", + command, name); rc = -1; } } @@ -365,8 +365,8 @@ siglist(private_t *pri, } } else { (void) fprintf(stderr, - "%s: unrecognized signal name/number: %s\n", - command, name); + "%s: unrecognized signal name/number: %s\n", + command, name); rc = -1; } } @@ -442,8 +442,8 @@ fltlist(char *str, /* string of fault names */ } } else { (void) fprintf(stderr, - "%s: unrecognized fault name/number: %s\n", - command, name); + "%s: unrecognized fault name/number: %s\n", + command, name); rc = -1; } } @@ -501,8 +501,8 @@ fdlist(char *str, /* string of filedescriptors */ } } else { (void) fprintf(stderr, - "%s: filedescriptor not in range[0..%d]: %s\n", - command, NOFILES_MAX-1, name); + "%s: filedescriptor not in range[0..%d]: %s\n", + command, NOFILES_MAX-1, name); rc = -1; } } @@ -595,7 +595,7 @@ liblist(char *arg, int hang) if (Dyp->nlibpat == maxpat) { maxpat *= 2; Dyp->libpat = my_realloc(Dyp->libpat, - maxpat * sizeof (char *), NULL); + maxpat * sizeof (char *), NULL); } Dyp->libpat[Dyp->nlibpat++] = pat; } @@ -646,7 +646,7 @@ liblist(char *arg, int hang) if (Dyp->nsympat == maxpat) { maxpat *= 2; Dyp->sympat = my_realloc(Dyp->sympat, - maxpat * sizeof (char *), NULL); + maxpat * sizeof (char *), NULL); } Dyp->sympat[Dyp->nsympat++] = pat; } diff --git a/usr/src/lib/common/inc/c_synonyms.h b/usr/src/lib/common/inc/c_synonyms.h index a4cbd44847..17cb17810e 100644 --- a/usr/src/lib/common/inc/c_synonyms.h +++ b/usr/src/lib/common/inc/c_synonyms.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -747,6 +747,7 @@ extern "C" { #define realpath _realpath #define remque _remque #define renameat _renameat +#define rename _rename #define resolvepath _resolvepath #define rmdir _rmdir #define rwlock_destroy _rwlock_destroy @@ -824,7 +825,6 @@ extern "C" { #define setutxent _setutxent #define sfconvert _sfconvert #define sgconvert _sgconvert -#define _sharefs __sharefs #define shmat _shmat #define shmctl64 _shmctl64 #define shmctl _shmctl @@ -1003,6 +1003,7 @@ extern "C" { #define vwarn _vwarn #define vwarnx _vwarnx #define wait3 _wait3 +#define wait4 _wait4 #define waitid _waitid #define waitpid _waitpid #define wait _wait diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile index 646d7f06c0..8b931d406f 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -139,7 +139,6 @@ SYSOBJS64= COMSYSOBJS= \ __clock_timer.o \ - __fcntl.o \ __getloadavg.o \ __rusagesys.o \ __signotify.o \ @@ -150,7 +149,6 @@ COMSYSOBJS= \ _nfssys.o \ _portfs.o \ _pset.o \ - _rename.o \ _rpcsys.o \ _sigaction.o \ _so_accept.o \ @@ -192,6 +190,7 @@ COMSYSOBJS= \ fchmod.o \ fchown.o \ fchroot.o \ + fcntl.o \ fdsync.o \ fpathconf.o \ fstat.o \ @@ -250,6 +249,7 @@ COMSYSOBJS= \ read.o \ readlink.o \ readv.o \ + rename.o \ resolvepath.o \ rmdir.o \ seteguid.o \ @@ -503,13 +503,12 @@ PORTGEN= \ realpath.o \ reboot.o \ regexpr.o \ - rename.o \ + remove.o \ rewinddir.o \ rindex.o \ scandir.o \ seekdir.o \ select.o \ - select_large_fdset.o \ setlabel.o \ setpriority.o \ settimeofday.o \ @@ -572,8 +571,6 @@ PORTGEN= \ valloc.o \ vlfmt.o \ vpfmt.o \ - wait3.o \ - wait4.o \ waitpid.o \ walkstack.o \ wdata.o \ @@ -793,15 +790,14 @@ PORTSYS= \ execle.o \ execv.o \ faccessat.o \ - fcntl.o \ fsmisc.o \ fstatat.o \ - fsync.o \ getpagesizes.o \ getpeerucred.o \ inst_sync.o \ issetugid.o \ label.o \ + libc_fcntl.o \ libc_link.o \ libc_open.o \ lockf.o \ diff --git a/usr/src/lib/libc/amd64/crt/cerror64.s b/usr/src/lib/libc/amd64/crt/cerror64.s deleted file mode 100644 index 5aceddc08a..0000000000 --- a/usr/src/lib/libc/amd64/crt/cerror64.s +++ /dev/null @@ -1,47 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - - .ident "%Z%%M% %I% %E% SMI" - - .file "%M%" - -/ C return sequence which sets errno, returns -1. - -#include <SYS.h> - - ENTRY(__cerror64) - cmpl $ERESTART, %eax - jne 1f - movl $EINTR, %eax -1: - pushl %eax - call _private___errno - popl %edx - movl %edx, (%eax) - movl $-1, %eax - movl %eax, %edx - ret - SET_SIZE(__cerror64) diff --git a/usr/src/lib/libc/amd64/sys/door.s b/usr/src/lib/libc/amd64/sys/door.s index e1df3c8db4..1e1789d911 100644 --- a/usr/src/lib/libc/amd64/sys/door.s +++ b/usr/src/lib/libc/amd64/sys/door.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,7 +34,6 @@ * weak aliases for public interfaces */ ANSI_PRAGMA_WEAK(_door_bind,function) - ANSI_PRAGMA_WEAK(_door_call,function) ANSI_PRAGMA_WEAK(_door_getparam,function) ANSI_PRAGMA_WEAK(_door_info,function) ANSI_PRAGMA_WEAK(_door_revoke,function) @@ -42,7 +41,6 @@ ANSI_PRAGMA_WEAK(_door_unbind,function) ANSI_PRAGMA_WEAK(door_bind,function) - ANSI_PRAGMA_WEAK(door_call,function) ANSI_PRAGMA_WEAK(door_getparam,function) ANSI_PRAGMA_WEAK(door_info,function) ANSI_PRAGMA_WEAK(door_revoke,function) diff --git a/usr/src/lib/libc/amd64/sys/uadmin.c b/usr/src/lib/libc/amd64/sys/uadmin.c index f8f2c0337b..8caf6d5bc3 100644 --- a/usr/src/lib/libc/amd64/sys/uadmin.c +++ b/usr/src/lib/libc/amd64/sys/uadmin.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -44,6 +45,7 @@ #include <sys/uadmin.h> #include <unistd.h> #include <string.h> +#include <pthread.h> #include <zone.h> static int @@ -102,6 +104,10 @@ uadmin(int cmd, int fcn, uintptr_t mdep) if (legal_arg(bargs) < 0) break; /* bad args */ + /* avoid cancellation in system() */ + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + NULL); + /* check for /stubboot */ if (stat("/stubboot/boot/grub/menu.lst", &sbuf) == 0) { altroot = "-R /stubboot "; diff --git a/usr/src/lib/libc/common/sys/_rename.s b/usr/src/lib/libc/common/sys/_rename.s deleted file mode 100644 index 417722b819..0000000000 --- a/usr/src/lib/libc/common/sys/_rename.s +++ /dev/null @@ -1,42 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - - -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - - .file "%M%" - -/* C library -- _rename */ -/* _rename() is the system call version of rename() */ - -#include "SYS.h" - - SYSCALL2_RVAL1(_rename,rename) - RETC - SET_SIZE(_rename) diff --git a/usr/src/lib/libc/common/sys/_so_accept.s b/usr/src/lib/libc/common/sys/_so_accept.s index cd94ffe1f8..b737628af8 100644 --- a/usr/src/lib/libc/common/sys/_so_accept.s +++ b/usr/src/lib/libc/common/sys/_so_accept.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,12 +31,11 @@ .file "%M%" -/* C library -- _so_accept */ -/* int _so_accept (int socket, struct sockaddr *name, int *namelen, */ -/* int vers); */ +/* C library -- __so_accept */ +/* int __so_accept(int sock, struct sockaddr *addr, int *addrlen, int vers) */ #include "SYS.h" - SYSCALL2_RVAL1(_so_accept,accept) + SYSCALL2_RVAL1(__so_accept,accept) RET - SET_SIZE(_so_accept) + SET_SIZE(__so_accept) diff --git a/usr/src/lib/libc/common/sys/_so_connect.s b/usr/src/lib/libc/common/sys/_so_connect.s index ede794d28c..2eb16007a7 100644 --- a/usr/src/lib/libc/common/sys/_so_connect.s +++ b/usr/src/lib/libc/common/sys/_so_connect.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- _so_connect */ -/* int _so_connect (int socket, struct sockaddr *name, int namelen, int vers); */ +/* C library -- __so_connect */ +/* int __so_connect(int sock, struct sockaddr *addr, int addrlen, int vers) */ #include "SYS.h" - SYSCALL2_RVAL1(_so_connect,connect) + SYSCALL2_RVAL1(__so_connect,connect) RET - SET_SIZE(_so_connect) + SET_SIZE(__so_connect) diff --git a/usr/src/lib/libc/common/sys/_so_recv.s b/usr/src/lib/libc/common/sys/_so_recv.s index 6fb1eaac52..2b92fe77d8 100644 --- a/usr/src/lib/libc/common/sys/_so_recv.s +++ b/usr/src/lib/libc/common/sys/_so_recv.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,10 +32,10 @@ .file "%M%" /* C library -- _so_recv */ -/* int _so_recv (int socket, void *buffer, size_t len, int flags); */ +/* int __so_recv(int sock, void *buffer, size_t len, int flags) */ #include "SYS.h" - SYSCALL2_RESTART_RVAL1(_so_recv,recv) + SYSCALL2_RESTART_RVAL1(__so_recv,recv) RET - SET_SIZE(_so_recv) + SET_SIZE(__so_recv) diff --git a/usr/src/lib/libc/common/sys/_so_recvfrom.s b/usr/src/lib/libc/common/sys/_so_recvfrom.s index 95b3d4ac99..d5b53892ad 100644 --- a/usr/src/lib/libc/common/sys/_so_recvfrom.s +++ b/usr/src/lib/libc/common/sys/_so_recvfrom.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,14 +31,14 @@ .file "%M%" -/* C library -- _so_recvfrom */ +/* C library -- __so_recvfrom */ /* - * int _so_recvfrom (int socket, void *buffer, size_t len, int flags, - * struct sockaddr *address, size_t *address_len); + * int __so_recvfrom(int sock, void *buffer, size_t len, int flags, + * struct sockaddr *addr, size_t *addrlen) */ #include "SYS.h" - SYSCALL2_RESTART_RVAL1(_so_recvfrom,recvfrom) + SYSCALL2_RESTART_RVAL1(__so_recvfrom,recvfrom) RET - SET_SIZE(_so_recvfrom) + SET_SIZE(__so_recvfrom) diff --git a/usr/src/lib/libc/common/sys/_so_recvmsg.s b/usr/src/lib/libc/common/sys/_so_recvmsg.s index 953faf6105..15b3e31fe0 100644 --- a/usr/src/lib/libc/common/sys/_so_recvmsg.s +++ b/usr/src/lib/libc/common/sys/_so_recvmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- _so_recvmsg */ -/* int _so_recvmsg (int socket, struct msghdr *msg, int flags); */ +/* C library -- __so_recvmsg */ +/* int __so_recvmsg(int sock, struct msghdr *msg, int flags) */ #include "SYS.h" - SYSCALL2_RESTART(_so_recvmsg,recvmsg) + SYSCALL2_RESTART_RVAL1(__so_recvmsg,recvmsg) RET - SET_SIZE(_so_recvmsg) + SET_SIZE(__so_recvmsg) diff --git a/usr/src/lib/libc/common/sys/_so_send.s b/usr/src/lib/libc/common/sys/_so_send.s index 706f02ac6d..285193b2be 100644 --- a/usr/src/lib/libc/common/sys/_so_send.s +++ b/usr/src/lib/libc/common/sys/_so_send.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- _so_send */ -/* int _so_send (int socket, void *buffer, size_t len, int flags); */ +/* C library -- __so_send */ +/* int __so_send(int socket, const void *buffer, size_t len, int flags) */ #include "SYS.h" - SYSCALL2_RESTART_RVAL1(_so_send,send) + SYSCALL2_RESTART_RVAL1(__so_send,send) RET - SET_SIZE(_so_send) + SET_SIZE(__so_send) diff --git a/usr/src/lib/libc/common/sys/_so_sendmsg.s b/usr/src/lib/libc/common/sys/_so_sendmsg.s index ce9cb079d2..2e19c716f3 100644 --- a/usr/src/lib/libc/common/sys/_so_sendmsg.s +++ b/usr/src/lib/libc/common/sys/_so_sendmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- _so_sendmsg */ -/* int _so_sendmsg (int socket, struct msghdr *msg, int flags); */ +/* C library -- __so_sendmsg */ +/* int __so_sendmsg(int sock, const struct msghdr *msg, int flags) */ #include "SYS.h" - SYSCALL2_RESTART_RVAL1(_so_sendmsg,sendmsg) + SYSCALL2_RESTART_RVAL1(__so_sendmsg,sendmsg) RET - SET_SIZE(_so_sendmsg) + SET_SIZE(__so_sendmsg) diff --git a/usr/src/lib/libc/common/sys/_so_sendto.s b/usr/src/lib/libc/common/sys/_so_sendto.s index 8c5374a9d6..cb5444ba28 100644 --- a/usr/src/lib/libc/common/sys/_so_sendto.s +++ b/usr/src/lib/libc/common/sys/_so_sendto.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,14 +31,14 @@ .file "%M%" -/* C library -- _so_sendto */ +/* C library -- __so_sendto */ /* - * int _so_sendto (int socket, void *buffer, size_t len, int flags, - * struct sockaddr *address, size_t address_len); + * int __so_sendto(int sock, const void *buffer, size_t len, int flags, + * const struct sockaddr *addr, int addrlen); */ #include "SYS.h" - SYSCALL2_RESTART_RVAL1(_so_sendto,sendto) + SYSCALL2_RESTART_RVAL1(__so_sendto,sendto) RET - SET_SIZE(_so_sendto) + SET_SIZE(__so_sendto) diff --git a/usr/src/lib/libc/common/sys/close.s b/usr/src/lib/libc/common/sys/close.s index c8fa248014..c88472019c 100644 --- a/usr/src/lib/libc/common/sys/close.s +++ b/usr/src/lib/libc/common/sys/close.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,12 +31,12 @@ .file "%M%" -/* C library -- close */ -/* int close(int fildes) */ +/* C library -- close */ +/* int __close(int fildes) */ #include "SYS.h" - ANSI_PRAGMA_WEAK2(_private_close,_close,function) - SYSCALL_RVAL1(close) + ANSI_PRAGMA_WEAK2(_private_close,__close,function) + SYSCALL2_RVAL1(__close,close) RETC - SET_SIZE(close) + SET_SIZE(__close) diff --git a/usr/src/lib/libc/common/sys/creat.s b/usr/src/lib/libc/common/sys/creat.s index fa6800ad11..45530500d0 100644 --- a/usr/src/lib/libc/common/sys/creat.s +++ b/usr/src/lib/libc/common/sys/creat.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,18 +35,18 @@ #if !defined(_LARGEFILE_SOURCE) /* C library -- creat */ -/* int creat(char *path, mode_t mode) */ +/* int __creat(char *path, mode_t mode) */ - SYSCALL_RVAL1(creat) + SYSCALL2_RVAL1(__creat,creat) RET - SET_SIZE(creat) + SET_SIZE(__creat) #else /* C library -- creat64 */ -/* int creat64(char *path, mode_t mode) */ +/* int __creat64(char *path, mode_t mode) */ - SYSCALL_RVAL1(creat64) + SYSCALL2_RVAL1(__creat64,creat64) RET - SET_SIZE(creat64) + SET_SIZE(__creat64) #endif diff --git a/usr/src/lib/libc/common/sys/__fcntl.s b/usr/src/lib/libc/common/sys/fcntl.s index 6628c7b4b6..df24860158 100644 --- a/usr/src/lib/libc/common/sys/__fcntl.s +++ b/usr/src/lib/libc/common/sys/fcntl.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,12 +29,11 @@ .file "%M%" /* - * int fcntl(int fildes, int cmd [, arg]) + * int __fcntl_syscall(int fildes, int cmd [, arg]) */ #include "SYS.h" - ANSI_PRAGMA_WEAK2(_private_fcntl,__fcntl,function) - SYSCALL2_RESTART_RVAL1(__fcntl,fcntl) + SYSCALL2_RESTART_RVAL1(__fcntl_syscall,fcntl) RET - SET_SIZE(__fcntl) + SET_SIZE(__fcntl_syscall) diff --git a/usr/src/lib/libc/common/sys/fdsync.s b/usr/src/lib/libc/common/sys/fdsync.s index 52e561346c..61775f9bd1 100644 --- a/usr/src/lib/libc/common/sys/fdsync.s +++ b/usr/src/lib/libc/common/sys/fdsync.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,12 +32,10 @@ .file "%M%" /* Underlying function for C library(fsync) and POSIX(fdatasync)*/ -/* int fdsync(int fildes,int flag) */ +/* int __fdsync(int fildes, int flag) */ #include "SYS.h" - ENTRY(__fdsync) - SYSTRAP_RVAL1(fdsync) - SYSCERROR + SYSCALL2_RVAL1(__fdsync,fdsync) RETC SET_SIZE(__fdsync) diff --git a/usr/src/lib/libc/common/sys/fstat.s b/usr/src/lib/libc/common/sys/fstat.s index 13ce8eb77b..00740c5cd0 100644 --- a/usr/src/lib/libc/common/sys/fstat.s +++ b/usr/src/lib/libc/common/sys/fstat.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -47,6 +46,7 @@ #if !defined(_LARGEFILE_SOURCE) + ANSI_PRAGMA_WEAK2(_private_fstat,fstat,function) SYSCALL_RVAL1(fstat) RETC SET_SIZE(fstat) @@ -56,6 +56,7 @@ /* C library -- fstat64 transitional large file API */ /* int fstat64 (int fildes, struct stat64 *buf) */ + ANSI_PRAGMA_WEAK2(_private_fstat64,fstat64,function) SYSCALL_RVAL1(fstat64) RETC SET_SIZE(fstat64) diff --git a/usr/src/lib/libc/common/sys/getmsg.s b/usr/src/lib/libc/common/sys/getmsg.s index 39e8aa2524..333aa6632a 100644 --- a/usr/src/lib/libc/common/sys/getmsg.s +++ b/usr/src/lib/libc/common/sys/getmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,12 +32,11 @@ .file "%M%" /* C library -- getmsg */ -/* int getmsg (int fd, struct strbuf *ctlptr, */ +/* int __getmsg(int fd, struct strbuf *ctlptr, */ /* struct strbuf *dataptr, int *flags) */ -#include <sys/asm_linkage.h> #include "SYS.h" - SYSCALL_RESTART_RVAL1(getmsg) + SYSCALL2_RESTART_RVAL1(__getmsg,getmsg) RET - SET_SIZE(getmsg) + SET_SIZE(__getmsg) diff --git a/usr/src/lib/libc/common/sys/getpmsg.s b/usr/src/lib/libc/common/sys/getpmsg.s index 9594e79111..c82d8b09c6 100644 --- a/usr/src/lib/libc/common/sys/getpmsg.s +++ b/usr/src/lib/libc/common/sys/getpmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,11 +32,11 @@ .file "%M%" /* C library -- getpmsg */ -/* int getpmsg (int fd, struct strbuf *ctlptr, */ +/* int __getpmsg(int fd, struct strbuf *ctlptr, */ /* struct strbuf *dataptr, int pri, int *flags) */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(getpmsg) + SYSCALL2_RESTART_RVAL1(__getpmsg,getpmsg) RET - SET_SIZE(getpmsg) + SET_SIZE(__getpmsg) diff --git a/usr/src/lib/libc/common/sys/ioctl.s b/usr/src/lib/libc/common/sys/ioctl.s index 6009bee136..94e2e3ceae 100644 --- a/usr/src/lib/libc/common/sys/ioctl.s +++ b/usr/src/lib/libc/common/sys/ioctl.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -41,6 +40,7 @@ #include "SYS.h" + ANSI_PRAGMA_WEAK2(_private_ioctl,ioctl,function) SYSCALL_RESTART_RVAL1(ioctl) RET SET_SIZE(ioctl) diff --git a/usr/src/lib/libc/common/sys/open.s b/usr/src/lib/libc/common/sys/open.s index df5386a726..2ebb074603 100644 --- a/usr/src/lib/libc/common/sys/open.s +++ b/usr/src/lib/libc/common/sys/open.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -38,9 +37,9 @@ /* C library -- open */ /* int open (const char *path, int oflag, [ mode_t mode ] ) */ - SYSCALL2_RVAL1(__open,open) + SYSCALL2_RVAL1(__open_syscall,open) RET - SET_SIZE(__open) + SET_SIZE(__open_syscall) #else /* @@ -48,8 +47,8 @@ * int open64 (const char *path, int oflag, [ mode_t mode ] ) */ - SYSCALL2_RVAL1(__open64,open64) + SYSCALL2_RVAL1(__open64_syscall,open64) RET - SET_SIZE(__open64) + SET_SIZE(__open64_syscall) #endif diff --git a/usr/src/lib/libc/common/sys/pause.s b/usr/src/lib/libc/common/sys/pause.s index e07ed61397..2da6f69639 100644 --- a/usr/src/lib/libc/common/sys/pause.s +++ b/usr/src/lib/libc/common/sys/pause.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,10 +32,10 @@ .file "%M%" /* C library - pause */ -/* int pause (void); */ +/* int __pause(void); */ #include "SYS.h" - SYSCALL_RVAL1(pause) + SYSCALL2_RVAL1(__pause,pause) RET - SET_SIZE(pause) + SET_SIZE(__pause) diff --git a/usr/src/lib/libc/common/sys/pread.s b/usr/src/lib/libc/common/sys/pread.s index 31207d81d6..0a08814dde 100644 --- a/usr/src/lib/libc/common/sys/pread.s +++ b/usr/src/lib/libc/common/sys/pread.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,24 +31,24 @@ .file "%M%" -/* C library -- pread */ -/* int pread (int fildes, void *buf, unsigned nbyte, off_t offset); */ +/* C library -- pread */ +/* ssize_t __pread(int, void *, size_t, off_t); */ #include "SYS.h" #if !defined(_LARGEFILE_SOURCE) - SYSCALL_RESTART_RVAL1(pread) + SYSCALL2_RESTART_RVAL1(__pread,pread) RET - SET_SIZE(pread) + SET_SIZE(__pread) #else /* C library -- pread64 transitional large file API */ -/* ssize_t pread(int, void *, size_t, off64_t); */ +/* ssize_t __pread(int, void *, size_t, off64_t); */ - SYSCALL_RESTART_RVAL1(pread64) + SYSCALL2_RESTART_RVAL1(__pread64,pread64) RET - SET_SIZE(pread64) + SET_SIZE(__pread64) #endif diff --git a/usr/src/lib/libc/common/sys/putmsg.s b/usr/src/lib/libc/common/sys/putmsg.s index 423e16f1a1..66ccec85e0 100644 --- a/usr/src/lib/libc/common/sys/putmsg.s +++ b/usr/src/lib/libc/common/sys/putmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,11 +32,11 @@ .file "%M%" /* C library -- putmsg */ -/* int putmsg (int fd, struct const strbuf *ctlptr, - struct const strbuf *dataptr, int *flags) */ +/* int __putmsg(int fd, struct const strbuf *ctlptr, */ +/* struct const strbuf *dataptr, int *flags) */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(putmsg) + SYSCALL2_RESTART_RVAL1(__putmsg,putmsg) RET - SET_SIZE(putmsg) + SET_SIZE(__putmsg) diff --git a/usr/src/lib/libc/common/sys/putpmsg.s b/usr/src/lib/libc/common/sys/putpmsg.s index f2a56f3006..e97587d007 100644 --- a/usr/src/lib/libc/common/sys/putpmsg.s +++ b/usr/src/lib/libc/common/sys/putpmsg.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,11 +32,11 @@ .file "%M%" /* C library -- putpmsg */ -/* int putpmsg (int fd, struct const strbuf *ctlptr, - struct const strbuf *dataptr, int *flags) */ +/* int __putpmsg(int fd, struct const strbuf *ctlptr, */ +/* struct const strbuf *dataptr, int *flags) */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(putpmsg) + SYSCALL2_RESTART_RVAL1(__putpmsg,putpmsg) RET - SET_SIZE(putpmsg) + SET_SIZE(__putpmsg) diff --git a/usr/src/lib/libc/common/sys/pwrite.s b/usr/src/lib/libc/common/sys/pwrite.s index cff21b3c20..61d8b67544 100644 --- a/usr/src/lib/libc/common/sys/pwrite.s +++ b/usr/src/lib/libc/common/sys/pwrite.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -28,24 +28,24 @@ .file "%M%" -/* C library -- pwrite */ -/* int pwrite (int fildes, const void *buf, unsigned nbyte, off_t offset); */ - #include "SYS.h" #if !defined(_LARGEFILE_SOURCE) - SYSCALL_RESTART_RVAL1(pwrite) +/* C library -- pwrite */ +/* ssize_t __pwrite(int, const void *, size_t, off_t); */ + + SYSCALL2_RESTART_RVAL1(__pwrite,pwrite) RET - SET_SIZE(pwrite) + SET_SIZE(__pwrite) #else -/* C library -- lseek64 transitional large file API */ -/* ssize_t pwrite(int, void *, size_t, off64_t); */ +/* C library -- pwrite64 transitional large file API */ +/* ssize_t __pwrite64(int, const void *, size_t, off64_t); */ - SYSCALL_RESTART_RVAL1(pwrite64) + SYSCALL2_RESTART_RVAL1(__pwrite64,pwrite64) RET - SET_SIZE(pwrite64) + SET_SIZE(__pwrite64) #endif diff --git a/usr/src/lib/libc/common/sys/read.s b/usr/src/lib/libc/common/sys/read.s index f124bc7b68..72db14e879 100644 --- a/usr/src/lib/libc/common/sys/read.s +++ b/usr/src/lib/libc/common/sys/read.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,10 +32,10 @@ .file "%M%" /* C library -- read */ -/* int read (int fildes, void *buf, unsigned nbyte); */ +/* ssize_t __read(int fildes, void *buf, size_t nbyte); */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(read) + SYSCALL2_RESTART_RVAL1(__read,read) RET - SET_SIZE(read) + SET_SIZE(__read) diff --git a/usr/src/lib/libc/common/sys/readv.s b/usr/src/lib/libc/common/sys/readv.s index c8990a99c2..3dd7136416 100644 --- a/usr/src/lib/libc/common/sys/readv.s +++ b/usr/src/lib/libc/common/sys/readv.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- readv */ -/* nt readv(int fildes, void *iovp[], int iovcnt[]) */ +/* C library -- readv */ +/* ssize_t __readv(int fd, const struct iovec *iovp, int iovcnt) */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(readv) + SYSCALL2_RESTART_RVAL1(__readv,readv) RET - SET_SIZE(readv) + SET_SIZE(__readv) diff --git a/usr/src/lib/libc/port/sys/fsync.c b/usr/src/lib/libc/common/sys/rename.s index b0278f3d95..ce31680d89 100644 --- a/usr/src/lib/libc/port/sys/fsync.c +++ b/usr/src/lib/libc/common/sys/rename.s @@ -19,32 +19,27 @@ * CDDL HEADER END */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ + .file "%M%" -/* - * fsync(int fd) - * fdatasync(int fd) - */ -#include "synonyms.h" -#include "libc.h" -#include <sys/file.h> - -int -_fsync(int fd) -{ - return (__fdsync(fd, FSYNC)); -} - -int -_fdatasync(int fd) -{ - return (__fdsync(fd, FDSYNC)); -} +/* C library -- rename */ +/* int rename(const char *old, const char *new); */ + +#include <sys/asm_linkage.h> + + ANSI_PRAGMA_WEAK(rename,function) + +#include "SYS.h" + + SYSCALL_RVAL1(rename) + RETC + SET_SIZE(rename) diff --git a/usr/src/lib/libc/common/sys/stat.s b/usr/src/lib/libc/common/sys/stat.s index ae624e6b89..e311c337f0 100644 --- a/usr/src/lib/libc/common/sys/stat.s +++ b/usr/src/lib/libc/common/sys/stat.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -47,6 +46,7 @@ #if !defined(_LARGEFILE_SOURCE) + ANSI_PRAGMA_WEAK2(_private_stat,stat,function) SYSCALL_RVAL1(stat) RETC SET_SIZE(stat) @@ -56,6 +56,7 @@ /* C library -- stat64 - transitional API */ /* int stat64 (const char *path, struct stat64 *buf); */ + ANSI_PRAGMA_WEAK2(_private_stat64,stat64,function) SYSCALL_RVAL1(stat64) RETC SET_SIZE(stat64) diff --git a/usr/src/lib/libc/common/sys/waitid.s b/usr/src/lib/libc/common/sys/waitid.s index 14f728d58e..5b4a6dc2f3 100644 --- a/usr/src/lib/libc/common/sys/waitid.s +++ b/usr/src/lib/libc/common/sys/waitid.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -38,8 +37,6 @@ #include "SYS.h" - SYSREENTRY(waitid) - SYSTRAP_RVAL1(waitsys) - SYSRESTART(.restart_waitid) + SYSCALL2_RESTART_RVAL1(__waitid,waitid) RETC - SET_SIZE(waitid) + SET_SIZE(__waitid) diff --git a/usr/src/lib/libc/common/sys/write.s b/usr/src/lib/libc/common/sys/write.s index 1e19de56ec..d69ccb5f86 100644 --- a/usr/src/lib/libc/common/sys/write.s +++ b/usr/src/lib/libc/common/sys/write.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,10 +32,10 @@ .file "%M%" /* C library -- write */ -/* int write (int fildes, const void *buf, unsigned nbyte); */ +/* ssize_t __write(int fildes, const void *buf, size_t nbyte); */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(write) + SYSCALL2_RESTART_RVAL1(__write,write) RET - SET_SIZE(write) + SET_SIZE(__write) diff --git a/usr/src/lib/libc/common/sys/writev.s b/usr/src/lib/libc/common/sys/writev.s index 0d13868a48..9c793aec78 100644 --- a/usr/src/lib/libc/common/sys/writev.s +++ b/usr/src/lib/libc/common/sys/writev.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,12 +18,12 @@ * * CDDL HEADER END */ + /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,11 +31,11 @@ .file "%M%" -/* C library -- writev */ -/* int writev(fd, iovp, iovcnt) */ +/* C library -- writev */ +/* ssize_t __writev(int fd, const struct iovec *iovp, int iovcnt) */ #include "SYS.h" - SYSCALL_RESTART_RVAL1(writev) + SYSCALL2_RESTART_RVAL1(__writev,writev) RET - SET_SIZE(writev) + SET_SIZE(__writev) diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com index 5e07b84f54..8e80952846 100644 --- a/usr/src/lib/libc/i386/Makefile.com +++ b/usr/src/lib/libc/i386/Makefile.com @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -41,7 +41,8 @@ CRTOBJS= \ cerror.o \ cerror64.o -DYNOBJS= +DYNOBJS= \ + _rtbootld.o FPOBJS= \ _D_cplx_div.o \ @@ -164,7 +165,6 @@ SYSOBJS64= \ COMSYSOBJS= \ __clock_timer.o \ - __fcntl.o \ __getloadavg.o \ __rusagesys.o \ __signotify.o \ @@ -175,7 +175,6 @@ COMSYSOBJS= \ _nfssys.o \ _portfs.o \ _pset.o \ - _rename.o \ _rpcsys.o \ _sigaction.o \ _so_accept.o \ @@ -217,6 +216,7 @@ COMSYSOBJS= \ fchmod.o \ fchown.o \ fchroot.o \ + fcntl.o \ fdsync.o \ fpathconf.o \ fstat.o \ @@ -275,6 +275,7 @@ COMSYSOBJS= \ read.o \ readlink.o \ readv.o \ + rename.o \ resolvepath.o \ rmdir.o \ seteguid.o \ @@ -536,7 +537,7 @@ PORTGEN= \ realpath.o \ reboot.o \ regexpr.o \ - rename.o \ + remove.o \ rewinddir.o \ rindex.o \ scandir.o \ @@ -601,8 +602,6 @@ PORTGEN= \ valloc.o \ vlfmt.o \ vpfmt.o \ - wait3.o \ - wait4.o \ waitpid.o \ walkstack.o \ wdata.o \ @@ -833,15 +832,14 @@ PORTSYS= \ execle.o \ execv.o \ faccessat.o \ - fcntl.o \ fsmisc.o \ fstatat.o \ - fsync.o \ getpagesizes.o \ getpeerucred.o \ inst_sync.o \ issetugid.o \ label.o \ + libc_fcntl.o \ libc_link.o \ libc_open.o \ lockf.o \ @@ -1062,7 +1060,6 @@ SRCS= \ $(LIBCBASE)/sys/uadmin.c # conditional assignments -$(DYNLIB) $(LIB_PIC) := DYNOBJS = _rtbootld.o $(DYNLIB) := CRTI = crti.o $(DYNLIB) := CRTN = crtn.o diff --git a/usr/src/lib/libc/i386/mapfile-vers b/usr/src/lib/libc/i386/mapfile-vers index f8e9f6508b..1a04ef290f 100644 --- a/usr/src/lib/libc/i386/mapfile-vers +++ b/usr/src/lib/libc/i386/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -924,6 +924,8 @@ SUNWprivate_1.1 { local: __systemcall6 = NODYNSORT; + _private_fstat64 = NODYNSORT; + _private_stat64 = NODYNSORT; _private_sysi86 = NODYNSORT; _seekdir64 = NODYNSORT; _telldir64 = NODYNSORT; diff --git a/usr/src/lib/libc/i386/sys/door.s b/usr/src/lib/libc/i386/sys/door.s index b2a42587d6..e161d3e858 100644 --- a/usr/src/lib/libc/i386/sys/door.s +++ b/usr/src/lib/libc/i386/sys/door.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,7 +34,6 @@ * weak aliases for public interfaces */ ANSI_PRAGMA_WEAK(_door_bind,function) - ANSI_PRAGMA_WEAK(_door_call,function) ANSI_PRAGMA_WEAK(_door_getparam,function) ANSI_PRAGMA_WEAK(_door_info,function) ANSI_PRAGMA_WEAK(_door_revoke,function) @@ -42,7 +41,6 @@ ANSI_PRAGMA_WEAK(_door_unbind,function) ANSI_PRAGMA_WEAK(door_bind,function) - ANSI_PRAGMA_WEAK(door_call,function) ANSI_PRAGMA_WEAK(door_getparam,function) ANSI_PRAGMA_WEAK(door_info,function) ANSI_PRAGMA_WEAK(door_revoke,function) diff --git a/usr/src/lib/libc/i386/sys/uadmin.c b/usr/src/lib/libc/i386/sys/uadmin.c index f8f2c0337b..8caf6d5bc3 100644 --- a/usr/src/lib/libc/i386/sys/uadmin.c +++ b/usr/src/lib/libc/i386/sys/uadmin.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -44,6 +45,7 @@ #include <sys/uadmin.h> #include <unistd.h> #include <string.h> +#include <pthread.h> #include <zone.h> static int @@ -102,6 +104,10 @@ uadmin(int cmd, int fcn, uintptr_t mdep) if (legal_arg(bargs) < 0) break; /* bad args */ + /* avoid cancellation in system() */ + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + NULL); + /* check for /stubboot */ if (stat("/stubboot/boot/grub/menu.lst", &sbuf) == 0) { altroot = "-R /stubboot "; diff --git a/usr/src/lib/libc/inc/libc.h b/usr/src/lib/libc/inc/libc.h index e3570f7d7d..11aec9371c 100644 --- a/usr/src/lib/libc/inc/libc.h +++ b/usr/src/lib/libc/inc/libc.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -238,7 +238,14 @@ extern int64_t _portfs(int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, /* * defined in xpg4.c */ -extern int __xpg4; +extern int __xpg4; /* global */ +extern int libc__xpg4; /* copy of __xpg4, private to libc */ + +/* + * defined in xpg6.c + */ +extern uint_t __xpg6; /* global */ +extern uint_t libc__xpg6; /* copy of __xpg6, private to libc */ /* * i18n prototypes - strong symbols (weak symbols are in libintl.h) @@ -343,7 +350,7 @@ extern int _doscan(FILE *, const char *, va_list); extern int _wcscoll(const wchar_t *, const wchar_t *); extern size_t _wcsxfrm(wchar_t *, const wchar_t *, size_t); extern wint_t _fputwc(wint_t, FILE *); -extern pid_t waitpid_cancel(pid_t, int *, int); + #ifdef __cplusplus } #endif diff --git a/usr/src/lib/libc/inc/mtlib.h b/usr/src/lib/libc/inc/mtlib.h index 5d3fbf1451..c6dbdb1f3a 100644 --- a/usr/src/lib/libc/inc/mtlib.h +++ b/usr/src/lib/libc/inc/mtlib.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -42,9 +42,6 @@ extern int _private_mutex_destroy(mutex_t *); extern int _private_mutex_lock(mutex_t *); extern int _private_mutex_trylock(mutex_t *); extern int _private_mutex_unlock(mutex_t *); -#define rmutex_lock _private_mutex_lock -#define rmutex_trylock _private_mutex_trylock -#define rmutex_unlock _private_mutex_unlock extern void lmutex_lock(mutex_t *); extern void lmutex_unlock(mutex_t *); extern int __rwlock_init(rwlock_t *, int, void *); @@ -62,6 +59,10 @@ extern void sig_mutex_unlock(mutex_t *); extern int sig_mutex_trylock(mutex_t *); extern int sig_cond_wait(cond_t *, mutex_t *); extern int sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); +extern void cancel_safe_mutex_lock(mutex_t *); +extern void cancel_safe_mutex_unlock(mutex_t *); +extern int cancel_safe_mutex_trylock(mutex_t *); +extern int cancel_active(void); /* the private libc thread-safe allocator */ extern void *lmalloc(size_t); @@ -81,9 +82,9 @@ extern int __mutex_unlock(mutex_t *); extern int _cond_init(cond_t *, int, void *); extern int _cond_destroy(cond_t *); -extern int _cond_wait(cond_t *, mutex_t *); -extern int _cond_timedwait(cond_t *, mutex_t *, const timespec_t *); -extern int _cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); +extern int __cond_wait(cond_t *, mutex_t *); +extern int __cond_timedwait(cond_t *, mutex_t *, const timespec_t *); +extern int __cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); extern int _cond_signal(cond_t *); extern int _cond_broadcast(cond_t *); diff --git a/usr/src/lib/libc/inc/stdiom.h b/usr/src/lib/libc/inc/stdiom.h index 108ee6c529..9befb8a3c6 100644 --- a/usr/src/lib/libc/inc/stdiom.h +++ b/usr/src/lib/libc/inc/stdiom.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -100,7 +100,7 @@ typedef unsigned char Uchar; -#define _flockrel(rl) rmutex_unlock(rl) +#define _flockrel(rl) cancel_safe_mutex_unlock(rl) #define MAXVAL (MAXINT - (MAXINT % BUFSIZ)) diff --git a/usr/src/lib/libc/inc/synonyms.h b/usr/src/lib/libc/inc/synonyms.h index e7e69a3ce7..ca8e25a41a 100644 --- a/usr/src/lib/libc/inc/synonyms.h +++ b/usr/src/lib/libc/inc/synonyms.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -860,6 +860,7 @@ extern "C" { #define regfree _regfree #define remque _remque #define renameat _renameat +#define rename _rename #define resetmnttab _resetmnttab #define resolvepath _resolvepath #define rmdir _rmdir @@ -942,7 +943,6 @@ extern "C" { #define s_fcntl _s_fcntl #define sfconvert _sfconvert #define sgconvert _sgconvert -#define _sharefs __sharefs #define shmat _shmat #define shmctl64 _shmctl64 #define shmctl _shmctl @@ -1146,6 +1146,7 @@ extern "C" { #define vwarn _vwarn #define vwarnx _vwarnx #define wait3 _wait3 +#define wait4 _wait4 #define waitid _waitid #define waitpid _waitpid #define wait _wait diff --git a/usr/src/lib/libc/inc/thr_uberdata.h b/usr/src/lib/libc/inc/thr_uberdata.h index c8ef313e16..e14714bec6 100644 --- a/usr/src/lib/libc/inc/thr_uberdata.h +++ b/usr/src/lib/libc/inc/thr_uberdata.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -508,7 +508,8 @@ typedef struct ulwp { char ul_cond_wait_defer; /* thread_cond_wait_defer */ char ul_error_detection; /* thread_error_detection */ char ul_async_safe; /* thread_async_safe */ - char ul_pad1[2]; + char ul_pad1; + char ul_save_state; /* bind_guard() interface to ld.so.1 */ int ul_adaptive_spin; /* thread_adaptive_spin */ int ul_queue_spin; /* thread_queue_spin */ volatile int ul_critical; /* non-zero == in a critical region */ @@ -529,7 +530,7 @@ typedef struct ulwp { uberflags_t *volatile ul_schedctl_called; /* ul_schedctl is set up */ volatile sc_shared_t *volatile ul_schedctl; /* schedctl data */ int ul_bindflags; /* bind_guard() interface to ld.so.1 */ - int ul_pad2; + uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */ tsd_t *ul_stsd; /* slow TLS for keys >= TSD_NFAST */ void *ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ td_evbuf_t ul_td_evbuf; /* event buffer */ @@ -905,7 +906,8 @@ typedef struct ulwp32 { char ul_cond_wait_defer; /* thread_cond_wait_defer */ char ul_error_detection; /* thread_error_detection */ char ul_async_safe; /* thread_async_safe */ - char ul_pad1[2]; + char ul_pad1; + char ul_save_state; /* bind_guard() interface to ld.so.1 */ int ul_adaptive_spin; /* thread_adaptive_spin */ int ul_queue_spin; /* thread_queue_spin */ int ul_critical; /* non-zero == in a critical region */ @@ -926,7 +928,7 @@ typedef struct ulwp32 { caddr32_t ul_schedctl_called; /* ul_schedctl is set up */ caddr32_t ul_schedctl; /* schedctl data */ int ul_bindflags; /* bind_guard() interface to ld.so.1 */ - int ul_pad2; + uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */ caddr32_t ul_stsd; /* slow TLS for keys >= TSD_NFAST */ caddr32_t ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ td_evbuf32_t ul_td_evbuf; /* event buffer */ @@ -1203,7 +1205,10 @@ extern void block_all_signals(ulwp_t *self); (ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) : \ __lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask, NULL))) +extern void set_cancel_pending_flag(ulwp_t *, int); +extern void set_cancel_eintr_flag(ulwp_t *); extern void set_parking_flag(ulwp_t *, int); +extern int cancel_active(void); extern void *_thr_setup(ulwp_t *); extern void _fpinherit(ulwp_t *); @@ -1219,6 +1224,9 @@ extern void sig_mutex_unlock(mutex_t *); extern int sig_mutex_trylock(mutex_t *); extern int sig_cond_wait(cond_t *, mutex_t *); extern int sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); +extern void cancel_safe_mutex_lock(mutex_t *); +extern void cancel_safe_mutex_unlock(mutex_t *); +extern int cancel_safe_mutex_trylock(mutex_t *); extern void _prefork_handler(void); extern void _postfork_parent_handler(void); extern void _postfork_child_handler(void); @@ -1253,10 +1261,10 @@ extern pid_t __forkallx(int); extern pid_t _private_getpid(void); extern uid_t _private_geteuid(void); extern int _kill(pid_t, int); -extern int _open(const char *, int, ...); -extern int _close(int); -extern ssize_t _read(int, void *, size_t); -extern ssize_t _write(int, const void *, size_t); +extern int _private_open(const char *, int, ...); +extern int _private_close(int); +extern ssize_t __read(int, void *, size_t); +extern ssize_t __write(int, const void *, size_t); extern void *_memcpy(void *, const void *, size_t); extern void *_memset(void *, int, size_t); extern int _memcmp(const void *, const void *, size_t); @@ -1303,6 +1311,7 @@ extern void _siglongjmp(sigjmp_buf, int); extern int _pthread_setspecific(pthread_key_t, const void *); extern void *_pthread_getspecific(pthread_key_t); extern void _pthread_exit(void *); +extern int _pthread_setcancelstate(int, int *); extern void _private_testcancel(void); /* belongs in <pthread.h> */ @@ -1333,14 +1342,19 @@ extern int __mutex_unlock(mutex_t *); extern int mutex_is_held(mutex_t *); extern int _cond_init(cond_t *, int, void *); -extern int _cond_wait(cond_t *, mutex_t *); -extern int _cond_timedwait(cond_t *, mutex_t *, const timespec_t *); -extern int _cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); extern int _cond_signal(cond_t *); extern int _cond_broadcast(cond_t *); extern int _cond_destroy(cond_t *); extern int cond_signal_internal(cond_t *); extern int cond_broadcast_internal(cond_t *); +/* cancellation points: */ +extern int _cond_wait(cond_t *, mutex_t *); +extern int _cond_timedwait(cond_t *, mutex_t *, const timespec_t *); +extern int _cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); +/* not cancellation points: */ +extern int __cond_wait(cond_t *, mutex_t *); +extern int __cond_timedwait(cond_t *, mutex_t *, const timespec_t *); +extern int __cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); extern int __rwlock_init(rwlock_t *, int, void *); extern int rw_read_is_held(rwlock_t *); diff --git a/usr/src/lib/libc/port/aio/aio.c b/usr/src/lib/libc/port/aio/aio.c index c1f7b51875..2e346907b9 100644 --- a/usr/src/lib/libc/port/aio/aio.c +++ b/usr/src/lib/libc/port/aio/aio.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -152,10 +152,13 @@ __uaio_init(void) { int ret = -1; int i; + int cancel_state; lmutex_lock(&__aio_initlock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (__aio_initbusy) - (void) _cond_wait(&__aio_initcv, &__aio_initlock); + (void) cond_wait(&__aio_initcv, &__aio_initlock); + (void) pthread_setcancelstate(cancel_state, NULL); if (__uaio_ok) { /* already initialized */ lmutex_unlock(&__aio_initlock); return (0); @@ -271,10 +274,13 @@ _kaio_init() { int error; sigset_t oset; + int cancel_state; lmutex_lock(&__aio_initlock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (__aio_initbusy) - (void) _cond_wait(&__aio_initcv, &__aio_initlock); + (void) cond_wait(&__aio_initcv, &__aio_initlock); + (void) pthread_setcancelstate(cancel_state, NULL); if (_kaio_ok) { /* already initialized */ lmutex_unlock(&__aio_initlock); return; @@ -488,8 +494,17 @@ aiocancel(aio_result_t *resultp) return (ret); } +/* ARGSUSED */ +static void +_aiowait_cleanup(void *arg) +{ + sig_mutex_lock(&__aio_mutex); + _aiowait_flag--; + sig_mutex_unlock(&__aio_mutex); +} + /* - * This must be asynch safe + * This must be asynch safe and cancel safe */ aio_result_t * aiowait(struct timeval *uwait) @@ -570,8 +585,12 @@ aiowait(struct timeval *uwait) kaio_errno = EINVAL; } else { sig_mutex_unlock(&__aio_mutex); + pthread_cleanup_push(_aiowait_cleanup, NULL); + _cancel_prologue(); kresultp = (aio_result_t *)_kaio(AIOWAIT, wait, dontblock); + _cancel_epilogue(); + pthread_cleanup_pop(0); sig_mutex_lock(&__aio_mutex); kaio_errno = errno; } diff --git a/usr/src/lib/libc/port/gen/atexit.c b/usr/src/lib/libc/port/gen/atexit.c index 69de21f524..d687f8d48c 100644 --- a/usr/src/lib/libc/port/gen/atexit.c +++ b/usr/src/lib/libc/port/gen/atexit.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -67,10 +67,9 @@ extern caddr_t _getfp(void); * that the registered functions actually return (no longjmp()s). * * Because exitfns_lock is declared to be a recursive mutex, we - * cannot use it with lmutex_lock()/lmutex_unlock() and we must use - * rmutex_lock()/rmutex_unlock() (which are defined to be simply - * mutex_lock()/mutex_unlock()). This means that atexit() and - * exit() are not async-signal-safe. We make them fork1-safe + * cannot use it with lmutex_lock()/lmutex_unlock() and we must + * use mutex_lock()/mutex_unlock(). This means that atexit() + * and exit() are not async-signal-safe. We make them fork1-safe * via the atexit_locks()/atexit_unlocks() functions, called from * libc_prepare_atfork()/libc_child_atfork()/libc_parent_atfork() */ @@ -82,13 +81,13 @@ extern caddr_t _getfp(void); void atexit_locks() { - (void) rmutex_lock(&__uberdata.atexit_root.exitfns_lock); + (void) _private_mutex_lock(&__uberdata.atexit_root.exitfns_lock); } void atexit_unlocks() { - (void) rmutex_unlock(&__uberdata.atexit_root.exitfns_lock); + (void) _private_mutex_unlock(&__uberdata.atexit_root.exitfns_lock); } /* @@ -109,13 +108,13 @@ _atexit(void (*func)(void)) arp = &__uberdata.atexit_root; else { arp = &self->ul_uberdata->atexit_root; - (void) rmutex_lock(&arp->exitfns_lock); + (void) _private_mutex_lock(&arp->exitfns_lock); } p->hdlr = func; p->next = arp->head; arp->head = p; if (self != NULL) - (void) rmutex_unlock(&arp->exitfns_lock); + (void) _private_mutex_unlock(&arp->exitfns_lock); return (0); } @@ -125,7 +124,7 @@ _exithandle(void) atexit_root_t *arp = &curthread->ul_uberdata->atexit_root; _exthdlr_t *p; - (void) rmutex_lock(&arp->exitfns_lock); + (void) _private_mutex_lock(&arp->exitfns_lock); arp->exit_frame_monitor = _getfp() + STACK_BIAS; p = arp->head; while (p != NULL) { @@ -134,7 +133,7 @@ _exithandle(void) lfree(p, sizeof (_exthdlr_t)); p = arp->head; } - (void) rmutex_unlock(&arp->exitfns_lock); + (void) _private_mutex_unlock(&arp->exitfns_lock); } /* @@ -288,7 +287,7 @@ _preexec_exit_handlers(Lc_addr_range_t range[], uint_t count) _exthdlr_t *o; /* previous node */ _exthdlr_t *p; /* this node */ - (void) rmutex_lock(&arp->exitfns_lock); + (void) _private_mutex_lock(&arp->exitfns_lock); o = NULL; p = arp->head; while (p != NULL) { @@ -307,7 +306,7 @@ _preexec_exit_handlers(Lc_addr_range_t range[], uint_t count) p = p->next; } } - (void) rmutex_unlock(&arp->exitfns_lock); + (void) _private_mutex_unlock(&arp->exitfns_lock); _preexec_tsd_unload(range, count); _preexec_atfork_unload(range, count); diff --git a/usr/src/lib/libc/port/gen/err.c b/usr/src/lib/libc/port/gen/err.c index 7af600f48f..3819d4881f 100644 --- a/usr/src/lib/libc/port/gen/err.c +++ b/usr/src/lib/libc/port/gen/err.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -35,6 +36,8 @@ #pragma weak vwarnx = _vwarnx #include "synonyms.h" +#include "file64.h" +#include "mtlib.h" #include <sys/types.h> #include <err.h> #include <stdio.h> @@ -42,6 +45,7 @@ #include <stdarg.h> #include <string.h> #include <errno.h> +#include "stdiom.h" /* Function exit/warning functions and global variables. */ @@ -51,12 +55,14 @@ static const char *progname; * warncore() is the workhorse of these functions. Everything else has * a warncore() component in it. */ -static void +static rmutex_t * warncore(FILE *fp, const char *fmt, va_list args) { const char *execname; + rmutex_t *lk; + + FLOCKFILE(lk, fp); - flockfile(fp); if (progname == NULL) { execname = getexecname(); if ((execname != NULL) && @@ -72,22 +78,26 @@ warncore(FILE *fp, const char *fmt, va_list args) if (fmt != NULL) { (void) vfprintf(fp, fmt, args); } + + return (lk); } /* Finish a warning with a newline and a flush of stderr. */ static void -warnfinish(FILE *fp) +warnfinish(FILE *fp, rmutex_t *lk) { (void) fputc('\n', fp); (void) fflush(fp); - funlockfile(fp); + FUNLOCKFILE(lk); } void _vwarnxfp(FILE *fp, const char *fmt, va_list args) { - warncore(fp, fmt, args); - warnfinish(fp); + rmutex_t *lk; + + lk = warncore(fp, fmt, args); + warnfinish(fp, lk); } void @@ -100,14 +110,15 @@ void _vwarnfp(FILE *fp, const char *fmt, va_list args) { int tmperr = errno; /* Capture errno now. */ + rmutex_t *lk; - warncore(fp, fmt, args); + lk = warncore(fp, fmt, args); if (fmt != NULL) { (void) fputc(':', fp); (void) fputc(' ', fp); } (void) fputs(strerror(tmperr), fp); - warnfinish(fp); + warnfinish(fp, lk); } void diff --git a/usr/src/lib/libc/port/gen/fdopendir.c b/usr/src/lib/libc/port/gen/fdopendir.c index 237d6a59ff..344c3af2be 100644 --- a/usr/src/lib/libc/port/gen/fdopendir.c +++ b/usr/src/lib/libc/port/gen/fdopendir.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -47,8 +47,6 @@ #include <errno.h> #include "libc.h" -extern int __fcntl(int fd, int cmd, intptr_t arg); - DIR * fdopendir(int fd) { @@ -64,7 +62,7 @@ fdopendir(int fd) * POSIX mandated behavior * close on exec if using file descriptor */ - if (__fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto fail; if (fstat64(fd, &sbuf) < 0) goto fail; diff --git a/usr/src/lib/libc/port/gen/getutx.c b/usr/src/lib/libc/port/gen/getutx.c index 3d8e69cf4e..fe0da52342 100644 --- a/usr/src/lib/libc/port/gen/getutx.c +++ b/usr/src/lib/libc/port/gen/getutx.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -82,6 +82,7 @@ #include <ctype.h> #include <stdlib.h> #include <sys/wait.h> +#include <pthread.h> #include <limits.h> #include <signal.h> #include <spawn.h> @@ -508,6 +509,7 @@ invoke_utmp_update(const struct utmpx *entryx) posix_spawnattr_t attr; int status; + int cancel_state; pid_t child; pid_t w; int i; @@ -587,9 +589,11 @@ invoke_utmp_update(const struct utmpx *entryx) goto out; } + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); do { w = waitpid(child, &status, 0); } while (w == -1 && errno == EINTR); + (void) pthread_setcancelstate(cancel_state, NULL); /* * We can get ECHILD if the process is ignoring SIGCLD. diff --git a/usr/src/lib/libc/port/gen/msync.c b/usr/src/lib/libc/port/gen/msync.c index 73c023f7ad..cf1e29031c 100644 --- a/usr/src/lib/libc/port/gen/msync.c +++ b/usr/src/lib/libc/port/gen/msync.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,13 +29,12 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #include "synonyms.h" #include <sys/types.h> #include <sys/mman.h> int -_msync(caddr_t addr, size_t len, int flags) +__msync(caddr_t addr, size_t len, int flags) { return (memcntl(addr, len, MC_SYNC, (caddr_t)(uintptr_t)flags, 0, 0)); } diff --git a/usr/src/lib/libc/port/gen/ndbm.c b/usr/src/lib/libc/port/gen/ndbm.c index 13ca8ce2ae..70a8e5e275 100644 --- a/usr/src/lib/libc/port/gen/ndbm.c +++ b/usr/src/lib/libc/port/gen/ndbm.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -50,6 +50,7 @@ #include <ndbm.h> #include <unistd.h> #include <string.h> +#include <pthread.h> /* add support for batched writing for NIS */ @@ -452,10 +453,22 @@ loop: datum dbm_firstkey(DBM *db) { + /* + * For some reason, the Posix specification (SUSv3) + * says that dbm_firstkey() is not a cancellation point. + * It really should be, but in order to pass the SUSv3 + * test suite we make it not a cancellation point. + * XXX: fix me when the SUSv3 specification gets fixed. + */ + int cancel_state; + datum rval; db->dbm_blkptr = 0L; db->dbm_keyptr = 0; - return (dbm_firsthash(db, 0L)); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); + rval = dbm_firsthash(db, 0L); + (void) pthread_setcancelstate(cancel_state, NULL); + return (rval); } datum @@ -496,7 +509,7 @@ dbm_slow_nextkey(DBM *db) where = (((off64_t)db->dbm_blkptr) * PBLKSIZ); if ((lseek64(db->dbm_pagf, where, L_SET) != where) || (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != - PBLKSIZ)) + PBLKSIZ)) (void) memset(db->dbm_pagbuf, 0, PBLKSIZ); #ifdef DEBUG else if (chkblk(db->dbm_pagbuf) < 0) @@ -557,7 +570,7 @@ dbm_do_nextkey(DBM *db, datum inkey) /* is this a manual firstkey request? */ if (db->dbm_blkptr == 0L && - db->dbm_keyptr == 0) + db->dbm_keyptr == 0) return (dbm_firsthash(db, 0L)); /* no -- get lastkey this is like dbm_access by blkptr */ @@ -569,7 +582,7 @@ dbm_do_nextkey(DBM *db, datum inkey) where = (((off64_t)db->dbm_blkptr) * PBLKSIZ); if ((lseek64(db->dbm_pagf, where, L_SET) != where) || (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != - PBLKSIZ)) + PBLKSIZ)) (void) memset(db->dbm_pagbuf, 0, PBLKSIZ); #ifdef DEBUG else if (chkblk(db->dbm_pagbuf) < 0) @@ -727,7 +740,7 @@ dbm_access(DBM *db, unsigned long hash) where = (((off64_t)b) * DBLKSIZ); if ((lseek64(db->dbm_dirf, where, L_SET) != where) || (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != - DBLKSIZ)) + DBLKSIZ)) (void) memset(db->dbm_dirbuf, 0, DBLKSIZ); } if ((db->dbm_dirbuf[i] & (1<<n)) == 0) break; @@ -747,7 +760,7 @@ dbm_access(DBM *db, unsigned long hash) where = (((off64_t)db->dbm_pagbno) * PBLKSIZ); if ((lseek64(db->dbm_pagf, where, L_SET) != where) || (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != - PBLKSIZ)) { + PBLKSIZ)) { db->dbm_flags |= _DBM_IOERR; } dbm_clrdirty(db); diff --git a/usr/src/lib/libc/port/gen/nss_common.c b/usr/src/lib/libc/port/gen/nss_common.c index d21f635d42..f7a77e278b 100644 --- a/usr/src/lib/libc/port/gen/nss_common.c +++ b/usr/src/lib/libc/port/gen/nss_common.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -52,6 +52,8 @@ #include <stdio.h> #include <string.h> #include <thread.h> +#include <synch.h> +#include <pthread.h> #include <sys/types.h> #include <sys/mman.h> #include <errno.h> @@ -145,24 +147,24 @@ void _nss_db_state_destr(struct nss_db_state *); /* ==== null definitions if !MTSAFE? Ditto lock field in nss_db_root_t */ -#define NSS_ROOTLOCK(r, sp) ((void) _private_mutex_lock(&(r)->lock), \ +#define NSS_ROOTLOCK(r, sp) (cancel_safe_mutex_lock(&(r)->lock), \ *(sp) = (r)->s) -#define NSS_UNLOCK(r) ((void) _private_mutex_unlock(&(r)->lock)) +#define NSS_UNLOCK(r) (cancel_safe_mutex_unlock(&(r)->lock)) #define NSS_CHECKROOT(rp, s) ((s) != (*(rp))->s && \ - ((void) _private_mutex_unlock(&(*(rp))->lock), \ - (void) _private_mutex_lock(&(s)->orphan_root.lock), \ + (cancel_safe_mutex_unlock(&(*(rp))->lock), \ + cancel_safe_mutex_lock(&(s)->orphan_root.lock), \ *(rp) = &(s)->orphan_root)) -#define NSS_RELOCK(rp, s) ((void) _private_mutex_lock(&(*(rp))->lock), \ +#define NSS_RELOCK(rp, s) (cancel_safe_mutex_lock(&(*(rp))->lock), \ NSS_CHECKROOT(rp, s)) #define NSS_STATE_REF_u(s) (++(s)->refcount) #define NSS_UNREF_UNLOCK(r, s) (--(s)->refcount != 0 \ ? ((void)NSS_UNLOCK(r)) \ - : (NSS_UNLOCK(r), (void)_nss_db_state_destr(s))) + : ((void)NSS_UNLOCK(r), (void)_nss_db_state_destr(s))) #define NSS_LOCK_CHECK(r, f, sp) (NSS_ROOTLOCK((r), (sp)), \ *(sp) == 0 && \ @@ -752,6 +754,7 @@ nss_get_backend_u(nss_db_root_t **rootpp, struct nss_db_state *s, int n_src) { struct nss_src_state *src = &s->src[n_src]; nss_backend_t *be; + int cancel_state; for (;;) { if (src->n_dormant > 0) { @@ -810,7 +813,10 @@ nss_get_backend_u(nss_db_root_t **rootpp, struct nss_db_state *s, int n_src) } src->n_waiting++; + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); (void) cond_wait(&src->wanna_be, &(*rootpp)->lock); + (void) pthread_setcancelstate(cancel_state, NULL); NSS_CHECKROOT(rootpp, s); src->n_waiting--; @@ -1290,9 +1296,9 @@ nss_setent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp) if (contextpp == 0) { return; } - (void) _private_mutex_lock(&contextpp->lock); + cancel_safe_mutex_lock(&contextpp->lock); nss_setent_u(rootp, initf, contextpp); - (void) _private_mutex_unlock(&contextpp->lock); + cancel_safe_mutex_unlock(&contextpp->lock); } nss_status_t @@ -1304,9 +1310,9 @@ nss_getent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp, if (contextpp == 0) { return (NSS_UNAVAIL); } - (void) _private_mutex_lock(&contextpp->lock); + cancel_safe_mutex_lock(&contextpp->lock); status = nss_getent_u(rootp, initf, contextpp, args); - (void) _private_mutex_unlock(&contextpp->lock); + cancel_safe_mutex_unlock(&contextpp->lock); return (status); } @@ -1316,9 +1322,9 @@ nss_endent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp) if (contextpp == 0) { return; } - (void) _private_mutex_lock(&contextpp->lock); + cancel_safe_mutex_lock(&contextpp->lock); nss_endent_u(rootp, initf, contextpp); - (void) _private_mutex_unlock(&contextpp->lock); + cancel_safe_mutex_unlock(&contextpp->lock); } /* diff --git a/usr/src/lib/libc/port/gen/rename.c b/usr/src/lib/libc/port/gen/remove.c index f2a5854521..bf76e3824b 100644 --- a/usr/src/lib/libc/port/gen/rename.c +++ b/usr/src/lib/libc/port/gen/remove.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,7 +29,6 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #include "synonyms.h" #include <sys/types.h> #include <sys/stat.h> @@ -52,9 +51,3 @@ remove(const char *filename) return (unlink(filename)); return (rmdir(filename)); } - -int -rename(const char *old, const char *new) -{ - return (_rename(old, new)); -} diff --git a/usr/src/lib/libc/port/gen/tcdrain.c b/usr/src/lib/libc/port/gen/tcdrain.c index 7e1b3f7bb6..78190fe231 100644 --- a/usr/src/lib/libc/port/gen/tcdrain.c +++ b/usr/src/lib/libc/port/gen/tcdrain.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,7 +29,6 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #include "synonyms.h" #include <sys/termios.h> #include <unistd.h> @@ -39,7 +38,7 @@ * wait until all output on the filedes is drained */ int -_tcdrain(int fildes) +__tcdrain(int fildes) { return (ioctl(fildes, TCSBRK, 1)); } diff --git a/usr/src/lib/libc/port/gen/truncate.c b/usr/src/lib/libc/port/gen/truncate.c index 9fae764f31..eff577845f 100644 --- a/usr/src/lib/libc/port/gen/truncate.c +++ b/usr/src/lib/libc/port/gen/truncate.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -54,6 +54,7 @@ #include <unistd.h> #include <stdio.h> #include <fcntl.h> +#include <pthread.h> #include <sys/types.h> int @@ -76,17 +77,19 @@ int _truncate(const char *path, off_t len) { + int rval = 0; + int cancel_state; int fd; - if ((fd = open(path, O_WRONLY)) == -1) { - return (-1); - } - - if (ftruncate(fd, len) == -1) { + /* + * truncate() is not a cancellation point, + * even though it calls open() and close(). + */ + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); + if ((fd = open(path, O_WRONLY)) == -1 || ftruncate(fd, len) == -1) + rval = -1; + if (fd >= 0) (void) close(fd); - return (-1); - } - - (void) close(fd); - return (0); + (void) pthread_setcancelstate(cancel_state, NULL); + return (rval); } diff --git a/usr/src/lib/libc/port/gen/wait3.c b/usr/src/lib/libc/port/gen/wait3.c deleted file mode 100644 index 00b25b15bc..0000000000 --- a/usr/src/lib/libc/port/gen/wait3.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - -/* - * Portions of this source code were derived from Berkeley 4.3 BSD - * under license from the Regents of the University of California. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "synonyms.h" - -/* - * Compatibility lib for BSD's wait3() - falls through to wait4(). - */ -#include <sys/types.h> -#include <sys/time.h> -#include <sys/times.h> -#include <wait.h> -#include <sys/resource.h> -#include <unistd.h> - -pid_t -_wait3(int *status, int options, struct rusage *rp) -{ - return (wait4(0, status, options, rp)); -} diff --git a/usr/src/lib/libc/port/gen/wait4.c b/usr/src/lib/libc/port/gen/wait4.c deleted file mode 100644 index 15ffdc92e4..0000000000 --- a/usr/src/lib/libc/port/gen/wait4.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T - * All Rights Reserved - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "synonyms.h" - -/* - * Compatibility lib for SunOS's wait4(). - */ - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/times.h> -#include <wait.h> -#include <sys/siginfo.h> -#include <sys/procset.h> -#include <sys/param.h> -#include <sys/resource.h> -#include <string.h> -#include <errno.h> - -/* - * Since sysV does not support rusage as in BSD, an approximate approach - * is: - * ... - * call times - * call waitid - * if ( a child is found ) - * call times again - * rusage ~= diff in the 2 times call - * ... - */ - -static int wstat(int, int); - -pid_t -wait4(pid_t pid, int *status, int options, struct rusage *rp) -{ - struct tms before_tms; - struct tms after_tms; - siginfo_t info; - int error; - int noptions; - idtype_t idtype; - - if (rp) - (void) memset(rp, 0, sizeof (struct rusage)); - (void) memset(&info, 0, sizeof (siginfo_t)); - - if (times(&before_tms) == (clock_t)-1) - return (-1); /* errno is set by times() */ - - /* - * SunOS's wait4() previously supported only WNOHANG & - * WUNTRACED. XPG4v2 mandates that wait3() (which calls - * wait4()) also support WCONTINUED. - */ - if (options & ~(WNOHANG|WUNTRACED|WCONTINUED)) { - errno = EINVAL; - return (-1); - } - noptions = options | WEXITED | WTRAPPED; - - /* - * Emulate undocumented 4.x semantics for 1186845 - */ - if (pid < 0) { - pid = -pid; - idtype = P_PGID; - } else if (pid == 0) - idtype = P_ALL; - else - idtype = P_PID; - - error = waitid(idtype, pid, &info, noptions); - if (error == 0) { - clock_t diffu; /* difference in usertime (ticks) */ - clock_t diffs; /* difference in systemtime (ticks) */ - clock_t hz; - - if ((options & WNOHANG) && (info.si_pid == 0)) - return (0); /* no child found */ - - if (rp) { - - if (times(&after_tms) == (clock_t)-1) - return (-1); /* errno set by times() */ - /* - * The system/user time is an approximation only !!! - */ - diffu = after_tms.tms_cutime - before_tms.tms_cutime; - diffs = after_tms.tms_cstime - before_tms.tms_cstime; - hz = CLK_TCK; - rp->ru_utime.tv_sec = diffu / hz; - rp->ru_utime.tv_usec = (diffu % hz) * (1000000 / hz); - rp->ru_stime.tv_sec = diffs / hz; - rp->ru_stime.tv_usec = (diffs % hz) * (1000000 / hz); - } - if (status) - *status = wstat(info.si_code, info.si_status); - return (info.si_pid); - } else { - return (-1); /* error number is set by waitid() */ - } -} - -/* - * Convert the status code to old style wait status - */ -static int -wstat(int code, int status) -{ - int stat = (status & 0377); - - switch (code) { - case CLD_EXITED: - stat <<= 8; - break; - case CLD_DUMPED: - stat |= WCOREFLG; - break; - case CLD_KILLED: - break; - case CLD_TRAPPED: - case CLD_STOPPED: - stat <<= 8; - stat |= WSTOPFLG; - break; - case CLD_CONTINUED: - stat = WCONTFLG; - break; - } - return (stat); -} diff --git a/usr/src/lib/libc/port/gen/waitpid.c b/usr/src/lib/libc/port/gen/waitpid.c index 993e046097..3a7d66330e 100644 --- a/usr/src/lib/libc/port/gen/waitpid.c +++ b/usr/src/lib/libc/port/gen/waitpid.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,14 +29,55 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ +/* + * All of these functions are cancellation points. + */ +#pragma weak waitpid = _waitpid +#pragma weak wait = _wait +#pragma weak wait4 = _wait4 +#pragma weak wait3 = _wait3 #include "synonyms.h" -#include <sys/types.h> #include <unistd.h> +#include <string.h> +#include <errno.h> #include <wait.h> +#include <sys/types.h> +#include <sys/siginfo.h> +#include <sys/times.h> +#include <sys/resource.h> + +/* + * Convert the siginfo_t code and status fields to an old style wait status. + */ +static int +wstat(int code, int status) +{ + int stat = (status & 0377); + + switch (code) { + case CLD_EXITED: + stat <<= 8; + break; + case CLD_DUMPED: + stat |= WCOREFLG; + break; + case CLD_KILLED: + break; + case CLD_TRAPPED: + case CLD_STOPPED: + stat <<= 8; + stat |= WSTOPFLG; + break; + case CLD_CONTINUED: + stat = WCONTFLG; + break; + } + return (stat); +} pid_t -_waitpid(pid_t pid, int *stat_loc, int options) +waitpid(pid_t pid, int *stat_loc, int options) { idtype_t idtype; id_t id; @@ -62,37 +103,91 @@ _waitpid(pid_t pid, int *stat_loc, int options) if ((error = waitid(idtype, id, &info, options)) < 0) return (error); - if (stat_loc) { - - int stat = (info.si_status & 0377); - - switch (info.si_code) { - case CLD_EXITED: - stat <<= 8; - break; - case CLD_DUMPED: - stat |= WCOREFLG; - break; - case CLD_KILLED: - break; - case CLD_TRAPPED: - case CLD_STOPPED: - stat <<= 8; - stat |= WSTOPFLG; - break; - case CLD_CONTINUED: - stat = WCONTFLG; - break; - } - - *stat_loc = stat; - } + if (stat_loc) + *stat_loc = wstat(info.si_code, info.si_status); return (info.si_pid); } pid_t -_wait(int *stat_loc) +wait(int *stat_loc) { return (waitpid(-1, stat_loc, 0)); } + +pid_t +wait4(pid_t pid, int *stat_loc, int options, struct rusage *rp) +{ + struct tms before_tms; + struct tms after_tms; + siginfo_t info; + int error; + int noptions; + idtype_t idtype; + + if (rp) + (void) memset(rp, 0, sizeof (struct rusage)); + (void) memset(&info, 0, sizeof (siginfo_t)); + + if (times(&before_tms) == (clock_t)-1) + return (-1); /* errno is set by times() */ + + /* + * SunOS's wait4() previously supported only WNOHANG & + * WUNTRACED. XPG4v2 mandates that wait3() (which calls + * wait4()) also support WCONTINUED. + */ + if (options & ~(WNOHANG|WUNTRACED|WCONTINUED)) { + errno = EINVAL; + return (-1); + } + noptions = options | WEXITED | WTRAPPED; + + /* + * Emulate undocumented 4.x semantics for 1186845 + */ + if (pid < 0) { + pid = -pid; + idtype = P_PGID; + } else if (pid == 0) { + idtype = P_ALL; + } else { + idtype = P_PID; + } + + error = waitid(idtype, pid, &info, noptions); + if (error == 0) { + clock_t diffu; /* difference in usertime (ticks) */ + clock_t diffs; /* difference in systemtime (ticks) */ + clock_t hz; + + if ((options & WNOHANG) && info.si_pid == 0) + return (0); /* no child found */ + + if (rp) { + if (times(&after_tms) == (clock_t)-1) + return (-1); /* errno set by times() */ + /* + * The system/user time is an approximation only !!! + */ + diffu = after_tms.tms_cutime - before_tms.tms_cutime; + diffs = after_tms.tms_cstime - before_tms.tms_cstime; + hz = CLK_TCK; + rp->ru_utime.tv_sec = diffu / hz; + rp->ru_utime.tv_usec = (diffu % hz) * (1000000 / hz); + rp->ru_stime.tv_sec = diffs / hz; + rp->ru_stime.tv_usec = (diffs % hz) * (1000000 / hz); + } + if (stat_loc) + *stat_loc = wstat(info.si_code, info.si_status); + return (info.si_pid); + } else { + return (-1); /* error number is set by waitid() */ + } +} + +pid_t +wait3(int *stat_loc, int options, struct rusage *rp) +{ + return (wait4(0, stat_loc, options, rp)); +} diff --git a/usr/src/lib/libc/port/gen/xpg4.c b/usr/src/lib/libc/port/gen/xpg4.c index f7140f12f3..2df91f6d38 100644 --- a/usr/src/lib/libc/port/gen/xpg4.c +++ b/usr/src/lib/libc/port/gen/xpg4.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,3 +34,5 @@ */ int __xpg4 = 0; + +int libc__xpg4; /* copy of __xpg4, private to libc */ diff --git a/usr/src/lib/libc/port/gen/xpg6.c b/usr/src/lib/libc/port/gen/xpg6.c index 333d87ed9e..d00ca8e1ce 100644 --- a/usr/src/lib/libc/port/gen/xpg6.c +++ b/usr/src/lib/libc/port/gen/xpg6.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -50,3 +50,5 @@ #include "xpg6.h" unsigned int __xpg6 = _C99SUSv3_mode_OFF; + +unsigned int libc__xpg6; /* copy of __xpg6, private to libc */ diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc index 284dae9086..d312d2cd39 100644 --- a/usr/src/lib/libc/port/llib-lc +++ b/usr/src/lib/libc/port/llib-lc @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -1050,22 +1050,11 @@ int usleep(unsigned n); /* valloc.c */ void *valloc(size_t size); -/* values-Xa.c */ - -/* values-Xc.c */ - -/* values-Xs.c */ - -/* values-Xt.c */ - -/* wait3.c */ -pid_t wait3(int *status, int options, struct rusage *rp); - -/* wait4.c */ -pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); - /* waitpid.c */ +pid_t wait(int *stat_loc); pid_t waitpid(pid_t pid, int *stat_loc, int options); +pid_t wait3(int *status, int options, struct rusage *rp); +pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); /* wcstombs.c */ size_t wcstombs(char *_RESTRICT_KYWD s, const wchar_t *_RESTRICT_KYWD pwcs, diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 7af69c0946..e89764af46 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -2241,6 +2241,7 @@ SUNWprivate_1.1 { _vwarnx; _vwarnxfp; _wait3; + _wait4; _walkcontext; _warn; _warnfp; @@ -2311,14 +2312,17 @@ SUNWprivate_1.1 { __imax_lldiv = NODYNSORT; _private_execve = NODYNSORT; _private_exit = NODYNSORT; + _private_fcntl = NODYNSORT; _private_forkallx = NODYNSORT; _private_forkx = NODYNSORT; + _private_fstat = NODYNSORT; _private_geteuid = NODYNSORT; _private_getcontext = NODYNSORT; _private_getgid = NODYNSORT; _private_getpid = NODYNSORT; _private_getrlimit = NODYNSORT; _private_getuid = NODYNSORT; + _private_ioctl = NODYNSORT; _private_lwp_mutex_lock = NODYNSORT; _private_lwp_mutex_unlock = NODYNSORT; _private_mmap = NODYNSORT; @@ -2341,6 +2345,7 @@ SUNWprivate_1.1 { _private_sigemptyset = NODYNSORT; _private_sigfillset = NODYNSORT; _private_sigismember = NODYNSORT; + _private_stat = NODYNSORT; _private_testcancel = NODYNSORT; _ti_thr_self = NODYNSORT; rw_read_is_held = NODYNSORT; diff --git a/usr/src/lib/libc/port/regex/wordexp.c b/usr/src/lib/libc/port/regex/wordexp.c index 0090d40fec..a60140ebff 100644 --- a/usr/src/lib/libc/port/regex/wordexp.c +++ b/usr/src/lib/libc/port/regex/wordexp.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -64,6 +64,7 @@ #endif /* WORDEXP_KSH93 */ #include <string.h> #include <sys/wait.h> +#include <pthread.h> #include <unistd.h> #include <wordexp.h> #include <stdio.h> @@ -113,6 +114,7 @@ wordexp(const char *word, wordexp_t *wp, int flags) int pv[2]; /* pipe from shell stdout */ FILE *fp; /* pipe read stream */ int serrno, tmpalloc; + int cancel_state; /* * Do absolute minimum necessary for the REUSE flag. Eventually @@ -291,10 +293,12 @@ wordexp(const char *word, wordexp_t *wp, int flags) (void) fclose(fp); /* kill shell if still writing */ wait_cleanup: + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); if (waitpid(pid, &status, 0) == -1) rv = WRDE_ERRNO; else if (rv == 0) rv = WEXITSTATUS(status); /* shell WRDE_* status */ + (void) pthread_setcancelstate(cancel_state, NULL); cleanup: if (rv == 0) @@ -357,6 +361,7 @@ wordexp(const char *word, wordexp_t *wp, int flags) posix_spawnattr_t attr; posix_spawn_file_actions_t fact; int error; + int cancel_state; static const char *sun_path = "/bin/ksh"; static const char *xpg4_path = "/usr/xpg4/bin/sh"; @@ -544,6 +549,7 @@ wordexp(const char *word, wordexp_t *wp, int flags) (void) fclose(fp); /* kill shell if still writing */ wait_cleanup: + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (waitpid(pid, &status, 0) == -1) { if (errno != EINTR) { if (rv == 0) @@ -551,6 +557,7 @@ wait_cleanup: break; } } + (void) pthread_setcancelstate(cancel_state, NULL); if (rv == 0) rv = WEXITSTATUS(status); /* shell WRDE_* status */ diff --git a/usr/src/lib/libc/port/rt/mqueue.c b/usr/src/lib/libc/port/rt/mqueue.c index ebab58a259..1b1ea65deb 100644 --- a/usr/src/lib/libc/port/rt/mqueue.c +++ b/usr/src/lib/libc/port/rt/mqueue.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -229,9 +229,9 @@ mq_init(mqhdr_t *mqhp, size_t msgsize, ssize_t maxmsg) */ mqhp->mq_headpp = sizeof (mqhdr_t); mqhp->mq_tailpp = mqhp->mq_headpp + - mqhp->mq_maxprio * sizeof (uint64_t); + mqhp->mq_maxprio * sizeof (uint64_t); mqhp->mq_freep = mqhp->mq_tailpp + - mqhp->mq_maxprio * sizeof (uint64_t); + mqhp->mq_maxprio * sizeof (uint64_t); currentp = mqhp->mq_freep; MQ_PTR(mqhp, currentp)->msg_next = 0; @@ -412,8 +412,8 @@ _mq_open(const char *path, int oflag, /* mode_t mode, mq_attr *attr */ ...) temp = (msgsize + MQ_ALIGNSIZE - 1) & ~(MQ_ALIGNSIZE - 1); total_size = sizeof (mqhdr_t) + - maxmsg * (temp + sizeof (msghdr_t)) + - 2 * _MQ_PRIO_MAX * sizeof (uint64_t); + maxmsg * (temp + sizeof (msghdr_t)) + + 2 * _MQ_PRIO_MAX * sizeof (uint64_t); if (total_size > SSIZE_MAX) { errno = ENOSPC; @@ -734,7 +734,7 @@ int _mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, uint_t msg_prio) { return (__mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, - NULL, ABS_TIME)); + NULL, ABS_TIME)); } int @@ -742,7 +742,7 @@ _mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, uint_t msg_prio, const timespec_t *abs_timeout) { return (__mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, - abs_timeout, ABS_TIME)); + abs_timeout, ABS_TIME)); } int @@ -750,18 +750,18 @@ _mq_reltimedsend_np(mqd_t mqdes, const char *msg_ptr, size_t msg_len, uint_t msg_prio, const timespec_t *rel_timeout) { return (__mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, - rel_timeout, REL_TIME)); + rel_timeout, REL_TIME)); } static void decrement_rblocked(mqhdr_t *mqhp) { - int canstate; + int cancel_state; - (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canstate); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (sem_wait(&mqhp->mq_rblocked) == -1) continue; - (void) pthread_setcancelstate(canstate, NULL); + (void) pthread_setcancelstate(cancel_state, NULL); } static ssize_t @@ -846,7 +846,7 @@ ssize_t _mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, uint_t *msg_prio) { return (__mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, - NULL, ABS_TIME)); + NULL, ABS_TIME)); } ssize_t @@ -854,7 +854,7 @@ _mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, uint_t *msg_prio, const timespec_t *abs_timeout) { return (__mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, - abs_timeout, ABS_TIME)); + abs_timeout, ABS_TIME)); } ssize_t @@ -862,7 +862,7 @@ _mq_reltimedreceive_np(mqd_t mqdes, char *msg_ptr, size_t msg_len, uint_t *msg_prio, const timespec_t *rel_timeout) { return (__mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, - rel_timeout, REL_TIME)); + rel_timeout, REL_TIME)); } /* @@ -875,7 +875,7 @@ cancel_if_necessary(thread_communication_data_t *tcdp, const struct sigevent *sigevp) { int do_cancel = !_pthread_attr_equal(tcdp->tcd_attrp, - sigevp->sigev_notify_attributes); + sigevp->sigev_notify_attributes); if (do_cancel) { /* @@ -891,7 +891,7 @@ cancel_if_necessary(thread_communication_data_t *tcdp, tcdp->tcd_notif.sigev_signo = 0; tcdp->tcd_notif.sigev_value = sigevp->sigev_value; tcdp->tcd_notif.sigev_notify_function = - sigevp->sigev_notify_function; + sigevp->sigev_notify_function; } return (do_cancel); diff --git a/usr/src/lib/libc/port/rt/pos4obj.c b/usr/src/lib/libc/port/rt/pos4obj.c index 86f5a07595..9c0e72e181 100644 --- a/usr/src/lib/libc/port/rt/pos4obj.c +++ b/usr/src/lib/libc/port/rt/pos4obj.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -56,7 +56,8 @@ static long int name_max = 0; int __open_nc(const char *path, int oflag, mode_t mode) { - int canstate, val; + int cancel_state; + int val; struct stat64 statbuf; /* @@ -70,9 +71,9 @@ __open_nc(const char *path, int oflag, mode_t mode) } } - (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canstate); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); val = open64(path, oflag, mode); - (void) pthread_setcancelstate(canstate, &canstate); + (void) pthread_setcancelstate(cancel_state, NULL); return (val); } @@ -80,11 +81,12 @@ __open_nc(const char *path, int oflag, mode_t mode) int __close_nc(int fildes) { - int canstate, val; + int cancel_state; + int val; - (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canstate); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); val = close(fildes); - (void) pthread_setcancelstate(canstate, &canstate); + (void) pthread_setcancelstate(cancel_state, NULL); return (val); } diff --git a/usr/src/lib/libc/port/rt/sigev_thread.c b/usr/src/lib/libc/port/rt/sigev_thread.c index 0ab6eaccdf..e048fc5196 100644 --- a/usr/src/lib/libc/port/rt/sigev_thread.c +++ b/usr/src/lib/libc/port/rt/sigev_thread.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -80,9 +80,10 @@ dprintf(const char *format, ...) va_start(alist, format); flockfile(stderr); + pthread_cleanup_push(funlockfile, stderr); (void) fputs("DEBUG: ", stderr); (void) vfprintf(stderr, format, alist); - funlockfile(stderr); + pthread_cleanup_pop(1); /* funlockfile(stderr) */ va_end(alist); } } @@ -317,24 +318,24 @@ aio_spawner(void *arg) case AIOAREAD: case AIOAWRITE: case AIOFSYNC: - { + { aiocb_t *aiocbp = (aiocb_t *)port_event.portev_object; function = aiocbp->aio_sigevent.sigev_notify_function; attrp = aiocbp->aio_sigevent.sigev_notify_attributes; break; - } + } #if !defined(_LP64) case AIOAREAD64: case AIOAWRITE64: case AIOFSYNC64: - { + { aiocb64_t *aiocbp = (aiocb64_t *)port_event.portev_object; function = aiocbp->aio_sigevent.sigev_notify_function; attrp = aiocbp->aio_sigevent.sigev_notify_attributes; break; - } + } #endif default: function = NULL; @@ -472,7 +473,7 @@ setup_sigev_handler(const struct sigevent *sigevp, subsystem_t caller) */ tcdp->tcd_attrp = &tcdp->tcd_user_attr; error = _pthread_attr_clone(tcdp->tcd_attrp, - sigevp->sigev_notify_attributes); + sigevp->sigev_notify_attributes); if (error) { tcdp->tcd_attrp = NULL; free_sigev_handler(tcdp); @@ -629,6 +630,7 @@ _aio_sigev_thread_init(struct sigevent *sigevp) thread_communication_data_t *tcdp; int port; + int cancel_state; int rc = 0; if (sigevp == NULL || @@ -637,8 +639,10 @@ _aio_sigev_thread_init(struct sigevent *sigevp) return (0); lmutex_lock(&sigev_aio_lock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (sigev_aio_busy) - (void) _cond_wait(&sigev_aio_cv, &sigev_aio_lock); + (void) cond_wait(&sigev_aio_cv, &sigev_aio_lock); + (void) pthread_setcancelstate(cancel_state, NULL); if ((tcdp = sigev_aio_tcd) != NULL) port = tcdp->tcd_port; else { diff --git a/usr/src/lib/libc/port/stdio/_filbuf.c b/usr/src/lib/libc/port/stdio/_filbuf.c index a1c4591e46..4b271cef2d 100644 --- a/usr/src/lib/libc/port/stdio/_filbuf.c +++ b/usr/src/lib/libc/port/stdio/_filbuf.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -121,13 +121,11 @@ _filbuf(FILE *iop) iop->_cnt = res - 1; return (*iop->_ptr++); } - else - { - iop->_cnt = 0; - if (res == 0) - iop->_flag |= _IOEOF; - else - iop->_flag |= _IOERR; - return (EOF); - } + + iop->_cnt = 0; + if (res == 0) + iop->_flag |= _IOEOF; + else if (!cancel_active()) + iop->_flag |= _IOERR; + return (EOF); } diff --git a/usr/src/lib/libc/port/stdio/_flsbuf.c b/usr/src/lib/libc/port/stdio/_flsbuf.c index a3f6e9cf68..bcbc7f1a5a 100644 --- a/usr/src/lib/libc/port/stdio/_flsbuf.c +++ b/usr/src/lib/libc/port/stdio/_flsbuf.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,7 +29,6 @@ #pragma ident "%Z%%M% %I% %E% SMI" - #pragma weak _flsbuf = __flsbuf #include "synonyms.h" #include "file64.h" @@ -71,17 +70,20 @@ _flsbuf(int ch, FILE *iop) /* flush (write) buffer, save ch, */ case _IONBF | _IOWRT: /* okay to do no-buffered case */ iop->_cnt = 0; uch = (unsigned char)ch; - if (write(GET_FD(iop), (char *)&uch, 1) != 1) - iop->_flag |= _IOERR; + if (write(GET_FD(iop), (char *)&uch, 1) != 1) { + if (!cancel_active()) + iop->_flag |= _IOERR; + return (EOF); + } goto out; } if (_wrtchk(iop) != 0) /* check, correct permissions */ return (EOF); } while (iop->_flag & (_IOLBF | _IONBF)); -flush_putc:; +flush_putc: (void) _xflsbuf(iop); (void) PUTC(ch, iop); /* recursive call */ -out:; - /* necessary for putc() */ +out: + /* necessary for putc() */ return ((iop->_flag & _IOERR) ? EOF : (unsigned char)ch); } diff --git a/usr/src/lib/libc/port/stdio/flockf.c b/usr/src/lib/libc/port/stdio/flockf.c index 57ff8bf9b8..ce5ee78a5d 100644 --- a/usr/src/lib/libc/port/stdio/flockf.c +++ b/usr/src/lib/libc/port/stdio/flockf.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -48,11 +48,8 @@ #include "stdiom.h" /* - * The rmutex_lock/unlock routines are only called (for stdio FILE - * locking in libc) by _flockget, _flockrel, flockfile, ftrylockfile, - * and funlockfile. _flockget and _flockrel are only called by the - * FLOCKFILE/FUNLOCKFILE macros in mtlib.h. rmutex_trylock(), as a - * special case, is called from GETIOP()/getiop() in _findiop(). + * _flockget and _flockrel are only called by the + * FLOCKFILE/FUNLOCKFILE macros in mtlib.h. */ /* @@ -65,7 +62,7 @@ _flockget(FILE *iop) rmutex_t *rl = IOB_LCK(iop); if (rl != NULL) - rmutex_lock(rl); + cancel_safe_mutex_lock(rl); return (rl); } @@ -75,7 +72,7 @@ ftrylockfile(FILE *iop) rmutex_t *rl = IOB_LCK(iop); if (rl != NULL) - return (rmutex_trylock(rl)); + return (_private_mutex_trylock(rl)); return (0); /* can't happen? */ } @@ -85,7 +82,7 @@ flockfile(FILE *iop) rmutex_t *rl = IOB_LCK(iop); if (rl != NULL) - rmutex_lock(rl); + _private_mutex_lock(rl); } void @@ -94,7 +91,7 @@ funlockfile(FILE *iop) rmutex_t *rl = IOB_LCK(iop); if (rl != NULL) - rmutex_unlock(rl); + _private_mutex_unlock(rl); } int diff --git a/usr/src/lib/libc/port/stdio/flush.c b/usr/src/lib/libc/port/stdio/flush.c index bd8328267c..a7d9fabdbb 100644 --- a/usr/src/lib/libc/port/stdio/flush.c +++ b/usr/src/lib/libc/port/stdio/flush.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -188,7 +188,7 @@ _flushlbf(void) /* fflush() all line-buffered streams */ int threaded = __libc_threaded; if (threaded) - (void) _private_mutex_lock(&_first_link_lock); + cancel_safe_mutex_lock(&_first_link_lock); lp = &__first_link; do { @@ -204,14 +204,14 @@ _flushlbf(void) /* fflush() all line-buffered streams */ (_IOLBF | _IOWRT)) { if (threaded) { rmutex_t *lk = FPLOCK(fp); - if (rmutex_trylock(lk) != 0) + if (cancel_safe_mutex_trylock(lk) != 0) continue; /* Recheck after locking */ if ((fp->_flag & (_IOLBF | _IOWRT)) == (_IOLBF | _IOWRT)) { (void) _fflush_u(fp); } - (void) rmutex_unlock(lk); + cancel_safe_mutex_unlock(lk); } else { (void) _fflush_u(fp); } @@ -220,7 +220,7 @@ _flushlbf(void) /* fflush() all line-buffered streams */ } while ((lp = lp->next) != NULL); if (threaded) - (void) _private_mutex_unlock(&_first_link_lock); + cancel_safe_mutex_unlock(&_first_link_lock); } /* allocate an unused stream; NULL if cannot */ @@ -255,7 +255,7 @@ _findiop(void) int threaded = __libc_threaded; if (threaded) - (void) _private_mutex_lock(&_first_link_lock); + cancel_safe_mutex_lock(&_first_link_lock); if (lastlink == NULL) { rescan: @@ -283,7 +283,7 @@ rescan: if (threaded) { ret = getiop(fp, FPLOCK(fp), FPSTATE(fp)); if (ret != NULL) { - (void) _private_mutex_unlock( + cancel_safe_mutex_unlock( &_first_link_lock); return (ret); } @@ -316,7 +316,7 @@ rescan: */ if ((pkgp = malloc(sizeof (Pkg))) == NULL) { if (threaded) - (void) _private_mutex_unlock(&_first_link_lock); + cancel_safe_mutex_unlock(&_first_link_lock); return (NULL); } @@ -346,9 +346,9 @@ rescan: * we need to use the reverse structure. */ if ((delta = 0x1000 - ((uintptr_t)pkgp & 0xfff)) <= - offsetof(Pkg, Pkgn.iob[FILE_ARY_SZ-1].xmagic) && + offsetof(Pkg, Pkgn.iob[FILE_ARY_SZ-1].xmagic) && delta % sizeof (struct xFILE) == - offsetof(Pkg, Pkgn.iob[0].xmagic)) { + offsetof(Pkg, Pkgn.iob[0].xmagic)) { /* Use reversed structure */ hdr = &pkgp->Pkgr.hdr; hdr->iobp = &pkgp->Pkgr.iob[0]; @@ -366,7 +366,7 @@ rescan: fp = hdr->iobp; for (i = 0; i < FILE_ARY_SZ; i++) _private_mutex_init(&fp[i]._lock, - USYNC_THREAD|LOCK_RECURSIVE, NULL); + USYNC_THREAD|LOCK_RECURSIVE, NULL); #else xfp = hdr->iobp; fp = &xfp->_iob; @@ -374,7 +374,7 @@ rescan: for (i = 0; i < FILE_ARY_SZ; i++) { xfp[i].xmagic = XMAGIC(&xfp[i]); _private_mutex_init(&xfp[i].xlock, - USYNC_THREAD|LOCK_RECURSIVE, NULL); + USYNC_THREAD|LOCK_RECURSIVE, NULL); } #endif /* _LP64 */ @@ -383,7 +383,7 @@ rescan: fp->_base = 0; fp->_flag = 0377; /* claim the fp by setting low 8 bits */ if (threaded) - (void) _private_mutex_unlock(&_first_link_lock); + cancel_safe_mutex_unlock(&_first_link_lock); return (fp); } @@ -551,10 +551,10 @@ _xflsbuf(FILE *iop) if (n > 0) { int fd = GET_FD(iop); - while ((num_wrote = - write(fd, base, (size_t)n)) != n) { + while ((num_wrote = write(fd, base, (size_t)n)) != n) { if (num_wrote <= 0) { - iop->_flag |= _IOERR; + if (!cancel_active()) + iop->_flag |= _IOERR; return (EOF); } n -= num_wrote; @@ -594,7 +594,7 @@ _fflush_l_iops(void) /* flush all buffers */ int threaded = __libc_threaded; if (threaded) - (void) _private_mutex_lock(&_first_link_lock); + cancel_safe_mutex_lock(&_first_link_lock); lp = &__first_link; @@ -627,7 +627,7 @@ _fflush_l_iops(void) /* flush all buffers */ if (threaded) { lk = FPLOCK(iop); - if (rmutex_trylock(lk) != 0) + if (cancel_safe_mutex_trylock(lk) != 0) continue; } @@ -651,11 +651,11 @@ _fflush_l_iops(void) /* flush all buffers */ } } if (threaded) - (void) rmutex_unlock(lk); + cancel_safe_mutex_unlock(lk); } } while ((lp = lp->next) != NULL); if (threaded) - (void) _private_mutex_unlock(&_first_link_lock); + cancel_safe_mutex_unlock(&_first_link_lock); return (res); } @@ -717,10 +717,10 @@ fclose(FILE *iop) FUNLOCKFILE(lk); if (__libc_threaded) - (void) _private_mutex_lock(&_first_link_lock); + cancel_safe_mutex_lock(&_first_link_lock); fcloses++; if (__libc_threaded) - (void) _private_mutex_unlock(&_first_link_lock); + cancel_safe_mutex_unlock(&_first_link_lock); return (res); } @@ -755,7 +755,7 @@ close_fd(FILE *iop) static FILE * getiop(FILE *fp, rmutex_t *lk, mbstate_t *mb) { - if (lk != NULL && rmutex_trylock(lk)) + if (lk != NULL && cancel_safe_mutex_trylock(lk) != 0) return (NULL); /* locked: fp in use */ if (fp->_flag == 0) { /* unused */ diff --git a/usr/src/lib/libc/port/stdio/fputs.c b/usr/src/lib/libc/port/stdio/fputs.c index 1ab3c57be5..e115d4012e 100644 --- a/usr/src/lib/libc/port/stdio/fputs.c +++ b/usr/src/lib/libc/port/stdio/fputs.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -121,13 +121,14 @@ fputs(const char *ptr, FILE *iop) int fd = GET_FD(iop); while ((num_wrote = write(fd, ptr, (size_t)count)) != count) { - if (num_wrote <= 0) { + if (num_wrote <= 0) { + if (!cancel_active()) iop->_flag |= _IOERR; - FUNLOCKFILE(lk); - return (EOF); - } - count -= num_wrote; - ptr += num_wrote; + FUNLOCKFILE(lk); + return (EOF); + } + count -= num_wrote; + ptr += num_wrote; } FUNLOCKFILE(lk); if (ptrlen <= INT_MAX) diff --git a/usr/src/lib/libc/port/stdio/fwrite.c b/usr/src/lib/libc/port/stdio/fwrite.c index 77b301228c..6ab340e26d 100644 --- a/usr/src/lib/libc/port/stdio/fwrite.c +++ b/usr/src/lib/libc/port/stdio/fwrite.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -112,7 +112,8 @@ _fwrite_unlocked(const void *ptr, size_t size, size_t count, FILE *iop) while ((n = write(fileno(iop), data, (size_t)bytes)) != bytes) { if (n == -1) { - iop->_flag |= _IOERR; + if (!cancel_active()) + iop->_flag |= _IOERR; return (0); } else { data += n; @@ -128,7 +129,8 @@ _fwrite_unlocked(const void *ptr, size_t size, size_t count, FILE *iop) */ while ((n = write(fileno(iop), dptr, s)) != s) { if (n == -1) { - iop->_flag |= _IOERR; + if (!cancel_active()) + iop->_flag |= _IOERR; return (written / size); } else { dptr += n; diff --git a/usr/src/lib/libc/port/stdio/popen.c b/usr/src/lib/libc/port/stdio/popen.c index 11071de5bc..899e19d05b 100644 --- a/usr/src/lib/libc/port/stdio/popen.c +++ b/usr/src/lib/libc/port/stdio/popen.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -80,6 +80,11 @@ cleanup(void *arg) extern const sigset_t maskset; extern void *reapchild(void *); /* see port/stdio/system.c */ + /* + * We have been cancelled. There is no need to restore + * the original sigmask after blocking all signals because + * pthread_exit() will block all signals while we exit. + */ (void) thr_sigsetmask(SIG_SETMASK, &maskset, NULL); (void) thr_create(NULL, 0, reapchild, arg, THR_DAEMON, NULL); } @@ -156,8 +161,8 @@ popen(const char *cmd, const char *mode) /* * These conditions may apply if a previous iob returned * by popen() was closed with fclose() rather than pclose(), - * or if close(fileno(iob)) was called. - * Accommodate these programming error. + * or if close(fileno(iob)) was called. Don't let these + * programming errors cause us to malfunction here. */ if ((fd = curr->fd) != myside && fd != yourside && fcntl(fd, F_GETFD) >= 0) @@ -168,10 +173,10 @@ popen(const char *cmd, const char *mode) if (yourside != stdio) { if (error == 0) error = posix_spawn_file_actions_adddup2(&fact, - yourside, stdio); + yourside, stdio); if (error == 0) error = posix_spawn_file_actions_addclose(&fact, - yourside); + yourside); } if (error == 0) error = posix_spawnattr_setflags(&attr, @@ -191,7 +196,7 @@ popen(const char *cmd, const char *mode) argvec[2] = (char *)cmd; argvec[3] = NULL; error = posix_spawn(&pid, shpath, &fact, &attr, - (char *const *)argvec, (char *const *)environ); + (char *const *)argvec, (char *const *)environ); (void) posix_spawnattr_destroy(&attr); (void) posix_spawn_file_actions_destroy(&fact); (void) close(yourside); @@ -211,6 +216,9 @@ popen(const char *cmd, const char *mode) return (iop); } +/* + * pclose() is a cancellation point. + */ int pclose(FILE *ptr) { @@ -228,9 +236,8 @@ pclose(FILE *ptr) } /* - * pclose() is a cancellation point. - * Call waitpid_cancel() rather than _waitpid() to make - * sure that we actually perform the cancellation logic. + * waitpid() is a cancellation point. + * This causes pclose() to be a cancellation point. * * If we have already been cancelled (pclose() was called from * a cancellation cleanup handler), attempt to reap the process @@ -238,6 +245,7 @@ pclose(FILE *ptr) */ if (_thrp_cancelled()) { + /* waitpid(..., WNOHANG) is not a cancellation point */ if (waitpid(pid, &status, WNOHANG) == pid) return (status); cleanup((void *)(uintptr_t)pid); @@ -246,7 +254,7 @@ pclose(FILE *ptr) } pthread_cleanup_push(cleanup, (void *)(uintptr_t)pid); - while (waitpid_cancel(pid, &status, 0) < 0) { + while (waitpid(pid, &status, 0) < 0) { if (errno != EINTR) { status = -1; break; @@ -268,10 +276,11 @@ _insert_nolock(pid_t pid, int fd, node_t *new) /* * curr->fd can equal fd if a previous iob returned by * popen() was closed with fclose() rather than pclose(), - * or if close(fileno(iob)) was called. - * Accommodate this programming error. + * or if close(fileno(iob)) was called. Don't let these + * programming errors cause us to malfunction here. */ if (curr->fd == fd) { + /* make a lame attempt to reap the forgotten child */ (void) waitpid(curr->pid, NULL, WNOHANG); curr->pid = pid; lfree(new, sizeof (node_t)); diff --git a/usr/src/lib/libc/port/stdio/system.c b/usr/src/lib/libc/port/stdio/system.c index 707134751d..cef2648ced 100644 --- a/usr/src/lib/libc/port/stdio/system.c +++ b/usr/src/lib/libc/port/stdio/system.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -73,11 +73,14 @@ void * reapchild(void *arg) { pid_t pid = (pid_t)(uintptr_t)arg; + int cancel_state; + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (waitpid(pid, NULL, 0) == -1) { if (errno != EINTR) break; } + (void) pthread_setcancelstate(cancel_state, NULL); return (NULL); } @@ -225,7 +228,7 @@ system(const char *cmd) argv[3] = NULL; if (error == 0) error = posix_spawn(&cu.pid, shpath, NULL, &attr, - (char *const *)argv, (char *const *)environ); + (char *const *)argv, (char *const *)environ); (void) posix_spawnattr_destroy(&attr); @@ -234,13 +237,11 @@ system(const char *cmd) status = -1; } else { /* - * system() is a cancellation point. - * Call waitpid_cancel() rather than _waitpid() to make - * sure that we actually perform the cancellation logic. + * system() is a cancellation point and so is waitpid(). */ pthread_cleanup_push(cleanup, &cu); do { - w = waitpid_cancel(cu.pid, &status, 0); + w = waitpid(cu.pid, &status, 0); } while (w == -1 && errno == EINTR); pthread_cleanup_pop(0); if (w == -1) diff --git a/usr/src/lib/libc/port/sys/fcntl.c b/usr/src/lib/libc/port/sys/libc_fcntl.c index 4c4b6f56f0..b474123486 100644 --- a/usr/src/lib/libc/port/sys/fcntl.c +++ b/usr/src/lib/libc/port/sys/libc_fcntl.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -35,7 +35,7 @@ #include <sys/filio.h> #include <sys/file.h> #include <sys/types.h> -#include <sys/fcntl.h> +#include <fcntl.h> #include <signal.h> #include <sys/stat.h> #include <sys/stropts.h> @@ -52,28 +52,36 @@ #include <stdlib.h> #include "libc.h" -extern int __fcntl(int fd, int cmd, intptr_t arg); +/* + * We must be careful to call only functions that are private + * to libc here, to avoid invoking the dynamic linker. + * This is important because _private_fcntl() is called from + * posix_spawn() after vfork() and we must never invoke the + * dynamic linker in a vfork() child. + */ + +extern int _private_ioctl(int, int, ...); +extern int __fcntl_syscall(int fd, int cmd, ...); #if !defined(_LP64) /* * XXX these hacks are needed for X.25 which assumes that s_fcntl and * s_ioctl exist in the socket library. - * There is no need for a _s_ioctl for other purposes. + * There is no need for _s_ioctl for other purposes. */ -#pragma weak s_fcntl = _fcntl -#pragma weak _s_fcntl = _fcntl +#pragma weak s_fcntl = __fcntl +#pragma weak _s_fcntl = __fcntl #pragma weak s_ioctl = _s_ioctl - int _s_ioctl(int fd, int cmd, intptr_t arg) { - return (ioctl(fd, cmd, arg)); + return (_private_ioctl(fd, cmd, arg)); } -/* End XXX */ #endif /* _LP64 */ +#pragma weak _private_fcntl = __fcntl int -_fcntl(int fd, int cmd, ...) +__fcntl(int fd, int cmd, ...) { int res; int pid; @@ -87,14 +95,14 @@ _fcntl(int fd, int cmd, ...) switch (cmd) { case F_SETOWN: pid = (int)arg; - return (ioctl(fd, FIOSETOWN, &pid)); + return (_private_ioctl(fd, FIOSETOWN, &pid)); case F_GETOWN: - if (ioctl(fd, FIOGETOWN, &res) < 0) + if (_private_ioctl(fd, FIOGETOWN, &res) < 0) return (-1); return (res); default: - return (__fcntl(fd, cmd, arg)); + return (__fcntl_syscall(fd, cmd, arg)); } } diff --git a/usr/src/lib/libc/port/sys/libc_open.c b/usr/src/lib/libc/port/sys/libc_open.c index 0ed9b559a3..1a9cc4a017 100644 --- a/usr/src/lib/libc/port/sys/libc_open.c +++ b/usr/src/lib/libc/port/sys/libc_open.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -41,21 +40,29 @@ #include <sys/stropts.h> #include <sys/stream.h> #include <sys/ptms.h> +#include "libc.h" #if !defined(_LP64) -extern int __open64(const char *fname, int oflag, mode_t mode); +extern int __open64_syscall(const char *fname, int oflag, mode_t mode); #endif -extern int __xpg4; /* defined in port/gen/xpg4.c; 0 if not xpg4/xpg4v2 */ - -extern int __open(const char *fname, int oflag, mode_t mode); +extern int __open_syscall(const char *fname, int oflag, mode_t mode); static void push_module(int fd); static int isptsfd(int fd); static void itoa(int i, char *ptr); +/* + * We must be careful to call only functions that are private + * to libc here, to avoid invoking the dynamic linker. + * This is important because _private_open() and _private_open64() + * are called from posix_spawn() after vfork() and we must never + * invoke the dynamic linker in a vfork() child. + */ + +#pragma weak _private_open = __open int -_open(const char *fname, int oflag, ...) +__open(const char *fname, int oflag, ...) { mode_t mode; int fd; @@ -71,8 +78,8 @@ _open(const char *fname, int oflag, ...) * the terminal interface. For a more detailed discussion, * see bugid 4025044. */ - fd = __open(fname, oflag, mode); - if (__xpg4 != 0 && fd >= 0 && isptsfd(fd)) + fd = __open_syscall(fname, oflag, mode); + if (libc__xpg4 != 0 && fd >= 0 && isptsfd(fd)) push_module(fd); return (fd); } @@ -80,10 +87,11 @@ _open(const char *fname, int oflag, ...) #if !defined(_LP64) /* * The 32-bit APIs to large files require this interposition. - * The 64-bit APIs just fall back to _open() above. + * The 64-bit APIs just fall back to __open() above. */ +#pragma weak _private_open64 = __open64 int -_open64(const char *fname, int oflag, ...) +__open64(const char *fname, int oflag, ...) { mode_t mode; int fd; @@ -99,8 +107,8 @@ _open64(const char *fname, int oflag, ...) * the terminal interface. For a more detailed discussion, * see bugid 4025044. */ - fd = __open64(fname, oflag, mode); - if (__xpg4 != 0 && fd >= 0 && isptsfd(fd)) + fd = __open64_syscall(fname, oflag, mode); + if (libc__xpg4 != 0 && fd >= 0 && isptsfd(fd)) push_module(fd); return (fd); } @@ -113,15 +121,31 @@ _open64(const char *fname, int oflag, ...) static int isptsfd(int fd) { +#if defined(_LP64) +#define _private_stat64 _private_stat +#define _private_fstat64 _private_fstat +#endif + extern int _private_stat64(const char *, struct stat64 *); + extern int _private_fstat64(int, struct stat64 *); char buf[TTYNAME_MAX]; + char *str1 = buf; + const char *str2 = "/dev/pts/"; struct stat64 fsb, stb; int oerrno = errno; int rval = 0; - if (fstat64(fd, &fsb) == 0 && S_ISCHR(fsb.st_mode)) { - (void) strcpy(buf, "/dev/pts/"); - itoa(minor(fsb.st_rdev), buf+strlen(buf)); - if (stat64(buf, &stb) == 0) + if (_private_fstat64(fd, &fsb) == 0 && S_ISCHR(fsb.st_mode)) { + /* + * Do this without strcpy() or strlen(), + * to avoid invoking the dynamic linker. + */ + while (*str2 != '\0') + *str1++ = *str2++; + /* + * Inline version of minor(dev), to avoid the dynamic linker. + */ + itoa(fsb.st_rdev & MAXMIN, str1); + if (_private_stat64(buf, &stb) == 0) rval = (stb.st_rdev == fsb.st_rdev); } errno = oerrno; @@ -157,6 +181,7 @@ itoa(int i, char *ptr) static void push_module(int fd) { + extern int _private_ioctl(int, int, ...); struct strioctl istr; int oerrno = errno; @@ -164,15 +189,15 @@ push_module(int fd) istr.ic_len = 0; istr.ic_timout = 0; istr.ic_dp = NULL; - if (ioctl(fd, I_STR, &istr) != -1) { - (void) ioctl(fd, __I_PUSH_NOCTTY, "ptem"); - (void) ioctl(fd, __I_PUSH_NOCTTY, "ldterm"); - (void) ioctl(fd, __I_PUSH_NOCTTY, "ttcompat"); + if (_private_ioctl(fd, I_STR, &istr) != -1) { + (void) _private_ioctl(fd, __I_PUSH_NOCTTY, "ptem"); + (void) _private_ioctl(fd, __I_PUSH_NOCTTY, "ldterm"); + (void) _private_ioctl(fd, __I_PUSH_NOCTTY, "ttcompat"); istr.ic_cmd = PTSSTTY; istr.ic_len = 0; istr.ic_timout = 0; istr.ic_dp = NULL; - (void) ioctl(fd, I_STR, &istr); + (void) _private_ioctl(fd, I_STR, &istr); } errno = oerrno; } diff --git a/usr/src/lib/libc/port/sys/lockf.c b/usr/src/lib/libc/port/sys/lockf.c index f1bb62a12f..eb6d41bcdf 100644 --- a/usr/src/lib/libc/port/sys/lockf.c +++ b/usr/src/lib/libc/port/sys/lockf.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,11 +29,10 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #include <sys/feature_tests.h> #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 -#define _lockf _lockf64 +#define __lockf __lockf64 #endif #include "synonyms.h" @@ -43,7 +42,7 @@ #include <fcntl.h> int -_lockf(int fildes, int function, off_t size) +__lockf(int fildes, int function, off_t size) { struct flock l; int rv; diff --git a/usr/src/lib/libc/port/sys/msgsys.c b/usr/src/lib/libc/port/sys/msgsys.c index d2db4da376..966bcc6975 100644 --- a/usr/src/lib/libc/port/sys/msgsys.c +++ b/usr/src/lib/libc/port/sys/msgsys.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,7 +29,6 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #pragma weak msgctl = _msgctl #pragma weak msgctl64 = _msgctl64 #pragma weak msgget = _msgget @@ -75,7 +74,7 @@ msgctl64(int msqid, int cmd, struct msqid_ds64 *buf) } ssize_t -_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) +__msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) { if (msgsz > INT_MAX) { sysret_t rval; @@ -97,7 +96,7 @@ _msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) } int -_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) +__msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) { if (msgsz > INT_MAX) { sysret_t rval; diff --git a/usr/src/lib/libc/port/sys/openat.c b/usr/src/lib/libc/port/sys/openat.c index 5549abf5d9..483a88a948 100644 --- a/usr/src/lib/libc/port/sys/openat.c +++ b/usr/src/lib/libc/port/sys/openat.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,19 +18,14 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" -#if !defined(_LP64) && _FILE_OFFSET_BITS == 64 -#pragma weak openat64 = _openat64 -#else -#pragma weak openat = _openat -#endif - #include "synonyms.h" #include <stdarg.h> #include <sys/types.h> @@ -40,29 +34,29 @@ #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 int -openat64(int fd, const char *name, int omode, ...) +__openat64(int fd, const char *name, int oflag, ...) { va_list ap; - mode_t cmode; + mode_t mode; - va_start(ap, omode); - cmode = va_arg(ap, mode_t); + va_start(ap, oflag); + mode = va_arg(ap, mode_t); va_end(ap); - return (syscall(SYS_fsat, 1, fd, name, omode, cmode)); + return (syscall(SYS_fsat, 1, fd, name, oflag, mode)); } #else int -openat(int fd, const char *name, int omode, ...) +__openat(int fd, const char *name, int oflag, ...) { va_list ap; - mode_t cmode; + mode_t mode; - va_start(ap, omode); - cmode = va_arg(ap, mode_t); + va_start(ap, oflag); + mode = va_arg(ap, mode_t); va_end(ap); - return (syscall(SYS_fsat, 0, fd, name, omode, cmode)); + return (syscall(SYS_fsat, 0, fd, name, oflag, mode)); } #endif diff --git a/usr/src/lib/libc/port/sys/sharefs.c b/usr/src/lib/libc/port/sys/sharefs.c index 241790aad6..42e0db738a 100644 --- a/usr/src/lib/libc/port/sys/sharefs.c +++ b/usr/src/lib/libc/port/sys/sharefs.c @@ -18,15 +18,14 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" -#pragma weak _sharefs = __sharefs - #include "synonyms.h" #include <sys/types.h> #include <sys/types32.h> diff --git a/usr/src/lib/libc/port/sys/signal.c b/usr/src/lib/libc/port/sys/signal.c index 4cd406e6fd..757dedd70b 100644 --- a/usr/src/lib/libc/port/sys/signal.c +++ b/usr/src/lib/libc/port/sys/signal.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -158,7 +158,7 @@ sigignore(int sig) } int -_sigpause(int sig) +__sigpause(int sig) { sigset_t set; int rval; diff --git a/usr/src/lib/libc/port/threads/assfail.c b/usr/src/lib/libc/port/threads/assfail.c index ac3e6a068f..dbb4b2dd4d 100644 --- a/usr/src/lib/libc/port/threads/assfail.c +++ b/usr/src/lib/libc/port/threads/assfail.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -112,7 +112,7 @@ common_panic(const char *head, const char *why) len1 = strlen(msg); if (msg[len1 - 1] != '\n') msg[len1++] = '\n'; - (void) _write(2, msg, len1); + (void) __write(2, msg, len1); Abort(msg); } @@ -228,7 +228,7 @@ lock_error(const mutex_t *mp, const char *who, void *cv, const char *msg) ultos((uint64_t)mcopy.mutex_ownerpid, 10, buf + strlen(buf)); } (void) strcat(buf, "\n\n"); - (void) _write(2, buf, strlen(buf)); + (void) __write(2, buf, strlen(buf)); if (udp->uberflags.uf_thread_error_detection >= 2) Abort(buf); assert_thread = NULL; @@ -312,7 +312,7 @@ rwlock_error(const rwlock_t *rp, const char *who, const char *msg) if (rwstate & URW_HAS_WAITERS) (void) strcat(buf, "\nand the lock appears to have waiters"); (void) strcat(buf, "\n\n"); - (void) _write(2, buf, strlen(buf)); + (void) __write(2, buf, strlen(buf)); if (udp->uberflags.uf_thread_error_detection >= 2) Abort(buf); assert_thread = NULL; @@ -352,7 +352,7 @@ thread_error(const char *msg) } (void) strcpy(buf, "\n*** _THREAD_ERROR_DETECTION: " - "thread usage error detected ***\n*** "); + "thread usage error detected ***\n*** "); (void) strcat(buf, msg); (void) strcat(buf, "\n*** calling thread is "); @@ -360,7 +360,7 @@ thread_error(const char *msg) (void) strcat(buf, " thread-id "); ultos((uint64_t)lwpid, 10, buf + strlen(buf)); (void) strcat(buf, "\n\n"); - (void) _write(2, buf, strlen(buf)); + (void) __write(2, buf, strlen(buf)); if (udp->uberflags.uf_thread_error_detection >= 2) Abort(buf); assert_thread = NULL; @@ -409,7 +409,7 @@ __assfail(const char *assertion, const char *filename, int line_num) (void) strcat(buf, ", line "); ultos((uint64_t)line_num, 10, buf + strlen(buf)); (void) strcat(buf, "\n"); - (void) _write(2, buf, strlen(buf)); + (void) __write(2, buf, strlen(buf)); /* * We could replace the call to Abort() with the following code * if we want just to issue a warning message and not die. diff --git a/usr/src/lib/libc/port/threads/cancel.c b/usr/src/lib/libc/port/threads/cancel.c index aa72981620..77605bcf42 100644 --- a/usr/src/lib/libc/port/threads/cancel.c +++ b/usr/src/lib/libc/port/threads/cancel.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -55,17 +55,21 @@ _pthread_cancel(thread_t tid) /* * Unlock self before cancelling. */ - ulwp_unlock(ulwp, udp); - ulwp->ul_nocancel = 0; /* cancellation is now possible */ - if (ulwp->ul_sigdefer) - ulwp->ul_cancel_pending = 1; - else + ulwp_unlock(self, udp); + self->ul_nocancel = 0; /* cancellation is now possible */ + if (self->ul_sigdefer == 0) do_sigcancel(); + else { + self->ul_cancel_pending = 1; + set_cancel_pending_flag(self, 0); + } } else if (ulwp->ul_cancel_disabled) { /* * Don't send SIGCANCEL if cancellation is disabled; * just set the thread's ulwp->ul_cancel_pending flag. * This avoids a potential EINTR for the target thread. + * We don't call set_cancel_pending_flag() here because + * we cannot modify another thread's schedctl data. */ ulwp->ul_cancel_pending = 1; ulwp_unlock(ulwp, udp); @@ -81,11 +85,11 @@ _pthread_cancel(thread_t tid) } /* - * pthread_setcancelstate: sets the state ENABLED or DISABLED - * If the state is being set as ENABLED, then it becomes - * a cancellation point only if the type of cancellation is - * ASYNCHRONOUS and a cancel request is pending. - * Disabling cancellation is not a cancellation point. + * pthread_setcancelstate: sets the state ENABLED or DISABLED. + * If the state is already ENABLED or is being set to ENABLED, + * the type of cancellation is ASYNCHRONOUS, and a cancel request + * is pending, then the thread is cancelled right here. + * Otherwise, pthread_setcancelstate() is not a cancellation point. */ #pragma weak pthread_setcancelstate = _pthread_setcancelstate int @@ -117,6 +121,7 @@ _pthread_setcancelstate(int state, int *oldstate) ulwp_unlock(self, udp); return (EINVAL); } + set_cancel_pending_flag(self, 0); /* * If this thread has been requested to be canceled and @@ -299,3 +304,119 @@ __pthread_cleanup_pop(int ex, _cleanup_t *clnup_info) if (ex) (*infop->func)(infop->arg); } + +/* + * Called when either self->ul_cancel_disabled or self->ul_cancel_pending + * is modified. Setting SC_CANCEL_FLG informs the kernel that we have + * a pending cancellation and we do not have cancellation disabled. + * In this situation, we will not go to sleep on any system call but + * will instead return EINTR immediately on any attempt to sleep, + * with SC_EINTR_FLG set in sc_flgs. Clearing SC_CANCEL_FLG rescinds + * this condition, but SC_EINTR_FLG never goes away until the thread + * terminates (indicated by clear_flags != 0). + */ +void +set_cancel_pending_flag(ulwp_t *self, int clear_flags) +{ + volatile sc_shared_t *scp; + + if (self->ul_vfork | self->ul_nocancel) + return; + enter_critical(self); + if ((scp = self->ul_schedctl) != NULL || + (scp = setup_schedctl()) != NULL) { + if (clear_flags) + scp->sc_flgs &= ~(SC_CANCEL_FLG | SC_EINTR_FLG); + else if (self->ul_cancel_pending && !self->ul_cancel_disabled) + scp->sc_flgs |= SC_CANCEL_FLG; + else + scp->sc_flgs &= ~SC_CANCEL_FLG; + } + exit_critical(self); +} + +/* + * Called from the PROLOGUE macro in scalls.c to inform subsequent + * code that a cancellation point has been called and that the + * current thread should cancel itself as soon as all of its locks + * have been dropped (see safe_mutex_unlock()). + */ +void +set_cancel_eintr_flag(ulwp_t *self) +{ + volatile sc_shared_t *scp; + + if (self->ul_vfork | self->ul_nocancel) + return; + enter_critical(self); + if ((scp = self->ul_schedctl) != NULL || + (scp = setup_schedctl()) != NULL) + scp->sc_flgs |= SC_EINTR_FLG; + exit_critical(self); +} + +/* + * Calling set_parking_flag(curthread, 1) informs the kernel that we are + * calling __lwp_park or ___lwp_cond_wait(). If we take a signal in + * the unprotected (from signals) interval before reaching the kernel, + * sigacthandler() will call set_parking_flag(curthread, 0) to inform + * the kernel to return immediately from these system calls, giving us + * a spurious wakeup but not a deadlock. + */ +void +set_parking_flag(ulwp_t *self, int park) +{ + volatile sc_shared_t *scp; + + enter_critical(self); + if ((scp = self->ul_schedctl) != NULL || + (scp = setup_schedctl()) != NULL) { + if (park) { + scp->sc_flgs |= SC_PARK_FLG; + /* + * We are parking; allow the __lwp_park() call to + * block even if we have a pending cancellation. + */ + scp->sc_flgs &= ~SC_CANCEL_FLG; + } else { + scp->sc_flgs &= ~(SC_PARK_FLG | SC_CANCEL_FLG); + /* + * We are no longer parking; restore the + * pending cancellation flag if necessary. + */ + if (self->ul_cancel_pending && + !self->ul_cancel_disabled) + scp->sc_flgs |= SC_CANCEL_FLG; + } + } else if (park == 0) { /* schedctl failed, do it the long way */ + __lwp_unpark(self->ul_lwpid); + } + exit_critical(self); +} + +/* + * Test if the current thread is due to exit because of cancellation. + */ +int +cancel_active(void) +{ + ulwp_t *self = curthread; + volatile sc_shared_t *scp; + int exit_soon; + + /* + * If there is a pending cancellation and cancellation + * is not disabled (SC_CANCEL_FLG) and we received + * EINTR from a recent system call (SC_EINTR_FLG), + * then we will soon be exiting. + */ + enter_critical(self); + exit_soon = + (((scp = self->ul_schedctl) != NULL || + (scp = setup_schedctl()) != NULL) && + (scp->sc_flgs & (SC_CANCEL_FLG | SC_EINTR_FLG)) == + (SC_CANCEL_FLG | SC_EINTR_FLG)); + exit_critical(self); + + return (exit_soon); +} diff --git a/usr/src/lib/libc/port/threads/pthr_barrier.c b/usr/src/lib/libc/port/threads/pthr_barrier.c index 8f1b7fb8e6..9d28323265 100644 --- a/usr/src/lib/libc/port/threads/pthr_barrier.c +++ b/usr/src/lib/libc/port/threads/pthr_barrier.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -133,7 +133,6 @@ _pthread_barrier_destroy(pthread_barrier_t *barrier) /* * pthread_barrier_wait() is not a cancellation point; - * call _cond_wait(), not cond_wait(). */ #pragma weak pthread_barrier_wait = _pthread_barrier_wait int @@ -142,22 +141,25 @@ _pthread_barrier_wait(pthread_barrier_t *barrier) mutex_t *mp = (mutex_t *)&barrier->__pthread_barrier_lock; cond_t *cvp = (cond_t *)&barrier->__pthread_barrier_cond; uint64_t cycle; + int cancel_state; (void) __mutex_lock(mp); if (--barrier->__pthread_barrier_current == 0) { barrier->__pthread_barrier_cycle++; barrier->__pthread_barrier_current = - barrier->__pthread_barrier_count; + barrier->__pthread_barrier_count; (void) __mutex_unlock(mp); (void) _cond_broadcast(cvp); return (PTHREAD_BARRIER_SERIAL_THREAD); } + (void) _pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); cycle = barrier->__pthread_barrier_cycle; do { (void) _cond_wait(cvp, mp); } while (cycle == barrier->__pthread_barrier_cycle); + (void) _pthread_setcancelstate(cancel_state, NULL); (void) __mutex_unlock(mp); return (0); diff --git a/usr/src/lib/libc/port/threads/scalls.c b/usr/src/lib/libc/port/threads/scalls.c index b2bc017ae9..1f96e43a7d 100644 --- a/usr/src/lib/libc/port/threads/scalls.c +++ b/usr/src/lib/libc/port/threads/scalls.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,7 +32,11 @@ #include <poll.h> #include <stropts.h> #include <dlfcn.h> +#include <wait.h> +#include <sys/socket.h> #include <sys/uio.h> +#include <sys/file.h> +#include <sys/door.h> /* * atfork_lock protects the pthread_atfork() data structures. @@ -76,18 +80,24 @@ fork_lock_exit(void) (void) _private_mutex_unlock(&curthread->ul_uberdata->fork_lock); } +/* + * Use cancel_safe_mutex_lock() to protect against being cancelled while + * holding callout_lock and calling outside of libc (via L10N plugins). + * We will honor a pending cancellation request when callout_lock_exit() + * is called, by calling cancel_safe_mutex_unlock(). + */ void callout_lock_enter(void) { ASSERT(curthread->ul_critical == 0); - (void) _private_mutex_lock(&curthread->ul_uberdata->callout_lock); + cancel_safe_mutex_lock(&curthread->ul_uberdata->callout_lock); } void callout_lock_exit(void) { ASSERT(curthread->ul_critical == 0); - (void) _private_mutex_unlock(&curthread->ul_uberdata->callout_lock); + cancel_safe_mutex_unlock(&curthread->ul_uberdata->callout_lock); } #pragma weak forkx = _private_forkx @@ -281,13 +291,15 @@ _forkall(void) } /* - * Hacks for system calls to provide cancellation - * and improve java garbage collection. + * For the implementation of cancellation at cancellation points. */ #define PROLOGUE \ { \ ulwp_t *self = curthread; \ - int nocancel = (self->ul_vfork | self->ul_nocancel); \ + int nocancel = \ + (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ + self->ul_critical | self->ul_sigdefer); \ + int abort = 0; \ if (nocancel == 0) { \ self->ul_save_async = self->ul_cancel_async; \ if (!self->ul_cancel_disabled) { \ @@ -296,6 +308,10 @@ _forkall(void) _pthread_exit(PTHREAD_CANCELED); \ } \ self->ul_sp = stkptr(); \ + } else if (self->ul_cancel_pending && \ + !self->ul_cancel_disabled) { \ + set_cancel_eintr_flag(self); \ + abort = 1; \ } #define EPILOGUE \ @@ -314,6 +330,10 @@ _forkall(void) */ #define PERFORM(function_call) \ PROLOGUE \ + if (abort) { \ + *self->ul_errnop = EINTR; \ + return (-1); \ + } \ if (nocancel) \ return (function_call); \ rv = function_call; \ @@ -336,7 +356,9 @@ _forkall(void) #define PROLOGUE_MASK(sigmask) \ { \ ulwp_t *self = curthread; \ - int nocancel = (self->ul_vfork | self->ul_nocancel); \ + int nocancel = \ + (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ + self->ul_critical | self->ul_sigdefer); \ if (!self->ul_vfork) { \ if (sigmask) { \ block_all_signals(self); \ @@ -387,7 +409,9 @@ _cancel_prologue(void) { ulwp_t *self = curthread; - self->ul_cancel_prologue = (self->ul_vfork | self->ul_nocancel); + self->ul_cancel_prologue = + (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | + self->ul_critical | self->ul_sigdefer) != 0; if (self->ul_cancel_prologue == 0) { self->ul_save_async = self->ul_cancel_async; if (!self->ul_cancel_disabled) { @@ -396,6 +420,9 @@ _cancel_prologue(void) _pthread_exit(PTHREAD_CANCELED); } self->ul_sp = stkptr(); + } else if (self->ul_cancel_pending && + !self->ul_cancel_disabled) { + set_cancel_eintr_flag(self); } } @@ -419,93 +446,101 @@ lwp_wait(thread_t tid, thread_t *found) int error; PROLOGUE - while ((error = __lwp_wait(tid, found)) == EINTR) - ; + if (abort) + return (EINTR); + while ((error = __lwp_wait(tid, found)) == EINTR && !cancel_active()) + continue; EPILOGUE return (error); } +#pragma weak read = _read ssize_t -read(int fd, void *buf, size_t size) +_read(int fd, void *buf, size_t size) { - extern ssize_t _read(int, void *, size_t); + extern ssize_t __read(int, void *, size_t); ssize_t rv; - PERFORM(_read(fd, buf, size)) + PERFORM(__read(fd, buf, size)) } +#pragma weak write = _write ssize_t -write(int fd, const void *buf, size_t size) +_write(int fd, const void *buf, size_t size) { - extern ssize_t _write(int, const void *, size_t); + extern ssize_t __write(int, const void *, size_t); ssize_t rv; - PERFORM(_write(fd, buf, size)) + PERFORM(__write(fd, buf, size)) } +#pragma weak getmsg = _getmsg int -getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, +_getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, int *flagsp) { - extern int _getmsg(int, struct strbuf *, struct strbuf *, int *); + extern int __getmsg(int, struct strbuf *, struct strbuf *, int *); int rv; - PERFORM(_getmsg(fd, ctlptr, dataptr, flagsp)) + PERFORM(__getmsg(fd, ctlptr, dataptr, flagsp)) } +#pragma weak getpmsg = _getpmsg int -getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, +_getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, int *bandp, int *flagsp) { - extern int _getpmsg(int, struct strbuf *, struct strbuf *, + extern int __getpmsg(int, struct strbuf *, struct strbuf *, int *, int *); int rv; - PERFORM(_getpmsg(fd, ctlptr, dataptr, bandp, flagsp)) + PERFORM(__getpmsg(fd, ctlptr, dataptr, bandp, flagsp)) } +#pragma weak putmsg = _putmsg int -putmsg(int fd, const struct strbuf *ctlptr, +_putmsg(int fd, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags) { - extern int _putmsg(int, const struct strbuf *, + extern int __putmsg(int, const struct strbuf *, const struct strbuf *, int); int rv; - PERFORM(_putmsg(fd, ctlptr, dataptr, flags)) + PERFORM(__putmsg(fd, ctlptr, dataptr, flags)) } int __xpg4_putmsg(int fd, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags) { - extern int _putmsg(int, const struct strbuf *, + extern int __putmsg(int, const struct strbuf *, const struct strbuf *, int); int rv; - PERFORM(_putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4)) + PERFORM(__putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4)) } +#pragma weak putpmsg = _putpmsg int -putpmsg(int fd, const struct strbuf *ctlptr, +_putpmsg(int fd, const struct strbuf *ctlptr, const struct strbuf *dataptr, int band, int flags) { - extern int _putpmsg(int, const struct strbuf *, + extern int __putpmsg(int, const struct strbuf *, const struct strbuf *, int, int); int rv; - PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags)) + PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags)) } int __xpg4_putpmsg(int fd, const struct strbuf *ctlptr, const struct strbuf *dataptr, int band, int flags) { - extern int _putpmsg(int, const struct strbuf *, + extern int __putpmsg(int, const struct strbuf *, const struct strbuf *, int, int); int rv; - PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4)) + PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4)) } #pragma weak nanosleep = _nanosleep @@ -515,7 +550,7 @@ _nanosleep(const timespec_t *rqtp, timespec_t *rmtp) int error; PROLOGUE - error = __nanosleep(rqtp, rmtp); + error = abort? EINTR : __nanosleep(rqtp, rmtp); EPILOGUE if (error) { errno = error; @@ -556,7 +591,7 @@ _clock_nanosleep(clockid_t clock_id, int flags, } restart: PROLOGUE - error = __nanosleep(&reltime, rmtp); + error = abort? EINTR : __nanosleep(&reltime, rmtp); EPILOGUE if (error == 0 && clock_id == CLOCK_HIGHRES) { /* @@ -606,16 +641,12 @@ unsigned int _sleep(unsigned int sec) { unsigned int rem = 0; - int error; timespec_t ts; timespec_t tsr; ts.tv_sec = (time_t)sec; ts.tv_nsec = 0; - PROLOGUE - error = __nanosleep(&ts, &tsr); - EPILOGUE - if (error == EINTR) { + if (_nanosleep(&ts, &tsr) == -1 && errno == EINTR) { rem = (unsigned int)tsr.tv_sec; if (tsr.tv_nsec >= NANOSEC / 2) rem++; @@ -631,47 +662,59 @@ _usleep(useconds_t usec) ts.tv_sec = usec / MICROSEC; ts.tv_nsec = (long)(usec % MICROSEC) * 1000; - PROLOGUE - (void) __nanosleep(&ts, NULL); - EPILOGUE + (void) _nanosleep(&ts, NULL); return (0); } +#pragma weak close = _close int -close(int fildes) +_close(int fildes) { extern void _aio_close(int); - extern int _close(int); + extern int __close(int); int rv; _aio_close(fildes); - PERFORM(_close(fildes)) + PERFORM(__close(fildes)) } +#pragma weak creat = _creat int -creat(const char *path, mode_t mode) +_creat(const char *path, mode_t mode) { - extern int _creat(const char *, mode_t); + extern int __creat(const char *, mode_t); int rv; - PERFORM(_creat(path, mode)) + PERFORM(__creat(path, mode)) } #if !defined(_LP64) +#pragma weak creat64 = _creat64 int -creat64(const char *path, mode_t mode) +_creat64(const char *path, mode_t mode) { - extern int _creat64(const char *, mode_t); + extern int __creat64(const char *, mode_t); int rv; - PERFORM(_creat64(path, mode)) + PERFORM(__creat64(path, mode)) } #endif /* !_LP64 */ +#pragma weak door_call = _door_call +int +_door_call(int d, door_arg_t *params) +{ + extern int __door_call(int, door_arg_t *); + int rv; + + PERFORM(__door_call(d, params)) +} + +#pragma weak fcntl = _fcntl int -fcntl(int fildes, int cmd, ...) +_fcntl(int fildes, int cmd, ...) { - extern int _fcntl(int, int, ...); + extern int __fcntl(int, int, ...); intptr_t arg; int rv; va_list ap; @@ -680,79 +723,102 @@ fcntl(int fildes, int cmd, ...) arg = va_arg(ap, intptr_t); va_end(ap); if (cmd != F_SETLKW) - return (_fcntl(fildes, cmd, arg)); - PERFORM(_fcntl(fildes, cmd, arg)) + return (__fcntl(fildes, cmd, arg)); + PERFORM(__fcntl(fildes, cmd, arg)) } +#pragma weak fdatasync = _fdatasync int -fdatasync(int fildes) +_fdatasync(int fildes) { - extern int _fdatasync(int); + extern int __fdsync(int, int); int rv; - PERFORM(_fdatasync(fildes)) + PERFORM(__fdsync(fildes, FDSYNC)) } +#pragma weak fsync = _fsync int -fsync(int fildes) +_fsync(int fildes) { - extern int _fsync(int); + extern int __fdsync(int, int); int rv; - PERFORM(_fsync(fildes)) + PERFORM(__fdsync(fildes, FSYNC)) } +#pragma weak lockf = _lockf int -lockf(int fildes, int function, off_t size) +_lockf(int fildes, int function, off_t size) { - extern int _lockf(int, int, off_t); + extern int __lockf(int, int, off_t); int rv; - PERFORM(_lockf(fildes, function, size)) + PERFORM(__lockf(fildes, function, size)) } #if !defined(_LP64) +#pragma weak lockf64 = _lockf64 int -lockf64(int fildes, int function, off64_t size) +_lockf64(int fildes, int function, off64_t size) { - extern int _lockf64(int, int, off64_t); + extern int __lockf64(int, int, off64_t); int rv; - PERFORM(_lockf64(fildes, function, size)) + PERFORM(__lockf64(fildes, function, size)) } #endif /* !_LP64 */ +#pragma weak msgrcv = _msgrcv ssize_t -msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) +_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) { - extern ssize_t _msgrcv(int, void *, size_t, long, int); + extern ssize_t __msgrcv(int, void *, size_t, long, int); ssize_t rv; - PERFORM(_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) + PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) +} + +#pragma weak msgsnd = _msgsnd +int +_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) +{ + extern int __msgsnd(int, const void *, size_t, int); + int rv; + + PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg)) } +#pragma weak msync = _msync int -msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) +_msync(caddr_t addr, size_t len, int flags) { - extern int _msgsnd(int, const void *, size_t, int); + extern int __msync(caddr_t, size_t, int); int rv; - PERFORM(_msgsnd(msqid, msgp, msgsz, msgflg)) + PERFORM(__msync(addr, len, flags)) } +#pragma weak open = _open int -msync(caddr_t addr, size_t len, int flags) +_open(const char *path, int oflag, ...) { - extern int _msync(caddr_t, size_t, int); + extern int __open(const char *, int, ...); + mode_t mode; int rv; + va_list ap; - PERFORM(_msync(addr, len, flags)) + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + PERFORM(__open(path, oflag, mode)) } +#pragma weak openat = _openat int -open(const char *path, int oflag, ...) +_openat(int fd, const char *path, int oflag, ...) { - extern int _open(const char *, int, ...); + extern int __openat(int, const char *, int, ...); mode_t mode; int rv; va_list ap; @@ -760,14 +826,30 @@ open(const char *path, int oflag, ...) va_start(ap, oflag); mode = va_arg(ap, mode_t); va_end(ap); - PERFORM(_open(path, oflag, mode)) + PERFORM(__openat(fd, path, oflag, mode)) } #if !defined(_LP64) +#pragma weak open64 = _open64 +int +_open64(const char *path, int oflag, ...) +{ + extern int __open64(const char *, int, ...); + mode_t mode; + int rv; + va_list ap; + + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + PERFORM(__open64(path, oflag, mode)) +} + +#pragma weak openat64 = _openat64 int -open64(const char *path, int oflag, ...) +_openat64(int fd, const char *path, int oflag, ...) { - extern int _open64(const char *, int, ...); + extern int __openat64(int, const char *, int, ...); mode_t mode; int rv; va_list ap; @@ -775,75 +857,82 @@ open64(const char *path, int oflag, ...) va_start(ap, oflag); mode = va_arg(ap, mode_t); va_end(ap); - PERFORM(_open64(path, oflag, mode)) + PERFORM(__openat64(fd, path, oflag, mode)) } #endif /* !_LP64 */ +#pragma weak pause = _pause int -pause(void) +_pause(void) { - extern int _pause(void); + extern int __pause(void); int rv; - PERFORM(_pause()) + PERFORM(__pause()) } +#pragma weak pread = _pread ssize_t -pread(int fildes, void *buf, size_t nbyte, off_t offset) +_pread(int fildes, void *buf, size_t nbyte, off_t offset) { - extern ssize_t _pread(int, void *, size_t, off_t); + extern ssize_t __pread(int, void *, size_t, off_t); ssize_t rv; - PERFORM(_pread(fildes, buf, nbyte, offset)) + PERFORM(__pread(fildes, buf, nbyte, offset)) } #if !defined(_LP64) +#pragma weak pread64 = _pread64 ssize_t -pread64(int fildes, void *buf, size_t nbyte, off64_t offset) +_pread64(int fildes, void *buf, size_t nbyte, off64_t offset) { - extern ssize_t _pread64(int, void *, size_t, off64_t); + extern ssize_t __pread64(int, void *, size_t, off64_t); ssize_t rv; - PERFORM(_pread64(fildes, buf, nbyte, offset)) + PERFORM(__pread64(fildes, buf, nbyte, offset)) } #endif /* !_LP64 */ +#pragma weak pwrite = _pwrite ssize_t -pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) +_pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { - extern ssize_t _pwrite(int, const void *, size_t, off_t); + extern ssize_t __pwrite(int, const void *, size_t, off_t); ssize_t rv; - PERFORM(_pwrite(fildes, buf, nbyte, offset)) + PERFORM(__pwrite(fildes, buf, nbyte, offset)) } #if !defined(_LP64) +#pragma weak pwrite64 = _pwrite64 ssize_t -pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) +_pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) { - extern ssize_t _pwrite64(int, const void *, size_t, off64_t); + extern ssize_t __pwrite64(int, const void *, size_t, off64_t); ssize_t rv; - PERFORM(_pwrite64(fildes, buf, nbyte, offset)) + PERFORM(__pwrite64(fildes, buf, nbyte, offset)) } #endif /* !_LP64 */ +#pragma weak readv = _readv ssize_t -readv(int fildes, const struct iovec *iov, int iovcnt) +_readv(int fildes, const struct iovec *iov, int iovcnt) { - extern ssize_t _readv(int, const struct iovec *, int); + extern ssize_t __readv(int, const struct iovec *, int); ssize_t rv; - PERFORM(_readv(fildes, iov, iovcnt)) + PERFORM(__readv(fildes, iov, iovcnt)) } +#pragma weak sigpause = _sigpause int -sigpause(int sig) +_sigpause(int sig) { - extern int _sigpause(int); + extern int __sigpause(int); int rv; - PERFORM(_sigpause(sig)) + PERFORM(__sigpause(sig)) } #pragma weak sigsuspend = _sigsuspend @@ -883,12 +972,17 @@ _sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout) int sig; PROLOGUE - sig = __sigtimedwait(set, &info, timeout); - if (sig == SIGCANCEL && - (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { - do_sigcancel(); - errno = EINTR; + if (abort) { + *self->ul_errnop = EINTR; sig = -1; + } else { + sig = __sigtimedwait(set, &info, timeout); + if (sig == SIGCANCEL && + (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { + do_sigcancel(); + *self->ul_errnop = EINTR; + sig = -1; + } } EPILOGUE if (sig != -1 && infop) @@ -920,60 +1014,109 @@ _sigqueue(pid_t pid, int signo, const union sigval value) } int -tcdrain(int fildes) +_so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version) { - extern int _tcdrain(int); + extern int __so_accept(int, struct sockaddr *, uint_t *, int); int rv; - PERFORM(_tcdrain(fildes)) + PERFORM(__so_accept(sock, addr, addrlen, version)) } -pid_t -wait(int *stat_loc) +int +_so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version) { - extern pid_t _wait(int *); - pid_t rv; + extern int __so_connect(int, struct sockaddr *, uint_t, int); + int rv; - PERFORM(_wait(stat_loc)) + PERFORM(__so_connect(sock, addr, addrlen, version)) } -pid_t -wait3(int *statusp, int options, struct rusage *rusage) +int +_so_recv(int sock, void *buf, size_t len, int flags) { - extern pid_t _wait3(int *, int, struct rusage *); - pid_t rv; + extern int __so_recv(int, void *, size_t, int); + int rv; - PERFORM(_wait3(statusp, options, rusage)) + PERFORM(__so_recv(sock, buf, len, flags)) } int -waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) +_so_recvfrom(int sock, void *buf, size_t len, int flags, + struct sockaddr *addr, int *addrlen) { - extern int _waitid(idtype_t, id_t, siginfo_t *, int); + extern int __so_recvfrom(int, void *, size_t, int, + struct sockaddr *, int *); int rv; - PERFORM(_waitid(idtype, id, infop, options)) + PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen)) } -/* - * waitpid_cancel() is a libc-private symbol for internal use - * where cancellation semantics is desired (see system()). - */ -#pragma weak waitpid_cancel = waitpid -pid_t -waitpid(pid_t pid, int *stat_loc, int options) +int +_so_recvmsg(int sock, struct msghdr *msg, int flags) +{ + extern int __so_recvmsg(int, struct msghdr *, int); + int rv; + + PERFORM(__so_recvmsg(sock, msg, flags)) +} + +int +_so_send(int sock, const void *buf, size_t len, int flags) +{ + extern int __so_send(int, const void *, size_t, int); + int rv; + + PERFORM(__so_send(sock, buf, len, flags)) +} + +int +_so_sendmsg(int sock, const struct msghdr *msg, int flags) { - extern pid_t _waitpid(pid_t, int *, int); - pid_t rv; + extern int __so_sendmsg(int, const struct msghdr *, int); + int rv; + + PERFORM(__so_sendmsg(sock, msg, flags)) +} + +int +_so_sendto(int sock, const void *buf, size_t len, int flags, + const struct sockaddr *addr, int *addrlen) +{ + extern int __so_sendto(int, const void *, size_t, int, + const struct sockaddr *, int *); + int rv; + + PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen)) +} + +#pragma weak tcdrain = _tcdrain +int +_tcdrain(int fildes) +{ + extern int __tcdrain(int); + int rv; + + PERFORM(__tcdrain(fildes)) +} + +#pragma weak waitid = _waitid +int +_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) +{ + extern int __waitid(idtype_t, id_t, siginfo_t *, int); + int rv; - PERFORM(_waitpid(pid, stat_loc, options)) + if (options & WNOHANG) + return (__waitid(idtype, id, infop, options)); + PERFORM(__waitid(idtype, id, infop, options)) } +#pragma weak writev = _writev ssize_t -writev(int fildes, const struct iovec *iov, int iovcnt) +_writev(int fildes, const struct iovec *iov, int iovcnt) { - extern ssize_t _writev(int, const struct iovec *, int); + extern ssize_t __writev(int, const struct iovec *, int); ssize_t rv; - PERFORM(_writev(fildes, iov, iovcnt)) + PERFORM(__writev(fildes, iov, iovcnt)) } diff --git a/usr/src/lib/libc/port/threads/sigaction.c b/usr/src/lib/libc/port/threads/sigaction.c index 8e52b04a8c..eecb8ebfa0 100644 --- a/usr/src/lib/libc/port/threads/sigaction.c +++ b/usr/src/lib/libc/port/threads/sigaction.c @@ -109,7 +109,8 @@ call_user_handler(int sig, siginfo_t *sip, ucontext_t *ucp) rwlock_t *rwlp = &udp->siguaction[sig].sig_lock; lrw_rdlock(rwlp); (void) _private_memcpy(&uact, (void *)sap, sizeof (uact)); - if (sig == SIGCANCEL && (sap->sa_flags & SA_RESETHAND)) + if ((sig == SIGCANCEL || sig == SIGAIOCANCEL) && + (sap->sa_flags & SA_RESETHAND)) sap->sa_sigaction = SIG_DFL; lrw_unlock(rwlp); } @@ -388,7 +389,8 @@ _libc_sigaction(int sig, const struct sigaction *nact, struct sigaction *oact) tact.sa_flags = SA_SIGINFO; else { tact.sa_flags |= SA_SIGINFO; - tact.sa_flags &= ~(SA_NODEFER | SA_RESETHAND); + tact.sa_flags &= + ~(SA_NODEFER | SA_RESETHAND | SA_RESTART); } tact.sa_sigaction = udp->sigacthandler; tact.sa_mask = maskset; @@ -437,28 +439,6 @@ setsigacthandler(void (*nsigacthandler)(int, siginfo_t *, void *), } /* - * Calling set_parking_flag(curthread, 1) informs the kernel that we are - * calling __lwp_park or ___lwp_cond_wait(). If we take a signal in - * the unprotected (from signals) interval before reaching the kernel, - * sigacthandler() will call set_parking_flag(curthread, 0) to inform - * the kernel to return immediately from these system calls, giving us - * a spurious wakeup but not a deadlock. - */ -void -set_parking_flag(ulwp_t *self, int park) -{ - volatile sc_shared_t *scp; - - enter_critical(self); - if ((scp = self->ul_schedctl) != NULL || - (scp = setup_schedctl()) != NULL) - scp->sc_park = park; - else if (park == 0) /* schedctl failed, do it the long way */ - __lwp_unpark(self->ul_lwpid); - exit_critical(self); -} - -/* * Tell the kernel to block all signals. * Use the schedctl interface, or failing that, use __lwp_sigmask(). * This action can be rescinded only by making a system call that @@ -688,12 +668,15 @@ signal_init() /* * Common code for cancelling self in _sigcancel() and pthread_cancel(). - * If the thread is at a cancellation point (ul_cancelable) then just - * return and let _canceloff() do the exit, else exit immediately if - * async mode is in effect. + * First record the fact that a cancellation is pending. + * Then, if cancellation is disabled or if we are holding unprotected + * libc locks, just return to defer the cancellation. + * Then, if we are at a cancellation point (ul_cancelable) just + * return and let _canceloff() do the exit. + * Else exit immediately if async mode is in effect. */ void -do_sigcancel() +do_sigcancel(void) { ulwp_t *self = curthread; @@ -702,8 +685,10 @@ do_sigcancel() self->ul_cancel_pending = 1; if (self->ul_cancel_async && !self->ul_cancel_disabled && + self->ul_libc_locks == 0 && !self->ul_cancelable) _pthread_exit(PTHREAD_CANCELED); + set_cancel_pending_flag(self, 0); } /* @@ -728,7 +713,7 @@ setup_cancelsig(int sig) act.sa_flags = SA_SIGINFO; else { act.sa_flags |= SA_SIGINFO; - act.sa_flags &= ~(SA_NODEFER | SA_RESETHAND); + act.sa_flags &= ~(SA_NODEFER | SA_RESETHAND | SA_RESTART); } act.sa_sigaction = udp->sigacthandler; act.sa_mask = maskset; diff --git a/usr/src/lib/libc/port/threads/spawn.c b/usr/src/lib/libc/port/threads/spawn.c index ddf74327b5..2e81ab0634 100644 --- a/usr/src/lib/libc/port/threads/spawn.c +++ b/usr/src/lib/libc/port/threads/spawn.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -76,7 +76,6 @@ extern pid_t _vforkx(int); #pragma unknown_control_flow(_vforkx) extern void *_private_memset(void *, int, size_t); extern int __lwp_sigmask(int, const sigset_t *, sigset_t *); -extern int __open(const char *, int, mode_t); extern int __sigaction(int, const struct sigaction *, struct sigaction *); extern int _private_close(int); extern int _private_execve(const char *, char *const *, char *const *); @@ -239,7 +238,8 @@ perform_file_actions(file_attr_t *fap) do { switch (fap->fa_type) { case FA_OPEN: - fd = __open(fap->fa_path, fap->fa_oflag, fap->fa_mode); + fd = _private_open(fap->fa_path, + fap->fa_oflag, fap->fa_mode); if (fd < 0) return (errno); if (fd != fap->fa_filedes) { @@ -255,7 +255,7 @@ perform_file_actions(file_attr_t *fap) break; case FA_DUP2: fd = _private_fcntl(fap->fa_filedes, F_DUP2FD, - fap->fa_newfiledes); + fap->fa_newfiledes); if (fd < 0) return (errno); break; @@ -359,7 +359,7 @@ _posix_spawn( * Much of posix_spawnp() blatently stolen from execvp() (port/gen/execvp.c). */ -extern int __xpg4; /* defined in xpg4.c; 0 if not xpg4-compiled program */ +extern int libc__xpg4; static const char * execat(const char *s1, const char *s2, char *si) @@ -400,7 +400,7 @@ _posix_spawnp( spawn_attr_t *sap = attrp? attrp->__spawn_attrp : NULL; file_attr_t *fap = file_actions? file_actions->__file_attrp : NULL; const char *pathstr = (strchr(file, '/') == NULL)? getenv("PATH") : ""; - int xpg4 = __xpg4; + int xpg4 = libc__xpg4; int error; /* this will be set by the child */ char path[PATH_MAX+4]; const char *cp; diff --git a/usr/src/lib/libc/port/threads/synch.c b/usr/src/lib/libc/port/threads/synch.c index 37b62f9ffe..d67d7b365d 100644 --- a/usr/src/lib/libc/port/threads/synch.c +++ b/usr/src/lib/libc/port/threads/synch.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -2000,6 +2000,17 @@ mutex_lock_impl(mutex_t *mp, timespec_t *tsp) return (mutex_lock_internal(mp, tsp, MUTEX_LOCK)); } +/* + * Of the following function names (all the same function, of course), + * only _private_mutex_lock() is not exported from libc. This means + * that calling _private_mutex_lock() within libc will not invoke the + * dynamic linker. This is critical for any code called in the child + * of vfork() (via posix_spawn()) because invoking the dynamic linker + * in such a case would corrupt the parent's address space. There are + * other places in libc where avoiding the dynamic linker is necessary. + * Of course, _private_mutex_lock() can be called in cases not requiring + * the avoidance of the dynamic linker too, and often is. + */ #pragma weak _private_mutex_lock = __mutex_lock #pragma weak mutex_lock = __mutex_lock #pragma weak _mutex_lock = __mutex_lock @@ -2389,7 +2400,7 @@ sig_cond_wait(cond_t *cv, mutex_t *mp) ASSERT(curthread->ul_sigdefer != 0); _private_testcancel(); - error = _cond_wait(cv, mp); + error = __cond_wait(cv, mp); if (error == EINTR && curthread->ul_cursig) { sig_mutex_unlock(mp); /* take the deferred signal here */ @@ -2409,7 +2420,7 @@ sig_cond_reltimedwait(cond_t *cv, mutex_t *mp, const timespec_t *ts) ASSERT(curthread->ul_sigdefer != 0); _private_testcancel(); - error = _cond_reltimedwait(cv, mp, ts); + error = __cond_reltimedwait(cv, mp, ts); if (error == EINTR && curthread->ul_cursig) { sig_mutex_unlock(mp); /* take the deferred signal here */ @@ -2419,6 +2430,52 @@ sig_cond_reltimedwait(cond_t *cv, mutex_t *mp, const timespec_t *ts) return (error); } +/* + * For specialized code in libc, like the stdio code. + * the following cancel_safe_*() locking primitives are used in + * order to make the code cancellation-safe. Cancellation is + * deferred while locks acquired by these functions are held. + */ +void +cancel_safe_mutex_lock(mutex_t *mp) +{ + (void) _private_mutex_lock(mp); + curthread->ul_libc_locks++; +} + +int +cancel_safe_mutex_trylock(mutex_t *mp) +{ + int error; + + if ((error = _private_mutex_trylock(mp)) == 0) + curthread->ul_libc_locks++; + return (error); +} + +void +cancel_safe_mutex_unlock(mutex_t *mp) +{ + ulwp_t *self = curthread; + + ASSERT(self->ul_libc_locks != 0); + + (void) _private_mutex_unlock(mp); + + /* + * Decrement the count of locks held by cancel_safe_mutex_lock(). + * If we are then in a position to terminate cleanly and + * if there is a pending cancellation and cancellation + * is not disabled and we received EINTR from a recent + * system call then perform the cancellation action now. + */ + if (--self->ul_libc_locks == 0 && + !(self->ul_vfork | self->ul_nocancel | + self->ul_critical | self->ul_sigdefer) && + cancel_active()) + _pthread_exit(PTHREAD_CANCELED); +} + static int shared_mutex_held(mutex_t *mparg) { @@ -3093,12 +3150,13 @@ cond_wait_common(cond_t *cvp, mutex_t *mp, timespec_t *tsp) } /* - * cond_wait() is a cancellation point but _cond_wait() is not. - * System libraries call the non-cancellation version. - * It is expected that only applications call the cancellation version. + * cond_wait() and _cond_wait() are cancellation points but __cond_wait() + * is not. Internally, libc calls the non-cancellation version. + * Other libraries need to use pthread_setcancelstate(), as appropriate, + * since __cond_wait() is not exported from libc. */ int -_cond_wait(cond_t *cvp, mutex_t *mp) +__cond_wait(cond_t *cvp, mutex_t *mp) { ulwp_t *self = curthread; uberdata_t *udp = self->ul_uberdata; @@ -3120,13 +3178,14 @@ _cond_wait(cond_t *cvp, mutex_t *mp) return (cond_wait_common(cvp, mp, NULL)); } +#pragma weak cond_wait = _cond_wait int -cond_wait(cond_t *cvp, mutex_t *mp) +_cond_wait(cond_t *cvp, mutex_t *mp) { int error; _cancelon(); - error = _cond_wait(cvp, mp); + error = __cond_wait(cvp, mp); if (error == EINTR) _canceloff(); else @@ -3134,23 +3193,25 @@ cond_wait(cond_t *cvp, mutex_t *mp) return (error); } +/* + * pthread_cond_wait() is a cancellation point. + */ #pragma weak pthread_cond_wait = _pthread_cond_wait int _pthread_cond_wait(cond_t *cvp, mutex_t *mp) { int error; - error = cond_wait(cvp, mp); + error = _cond_wait(cvp, mp); return ((error == EINTR)? 0 : error); } /* - * cond_timedwait() is a cancellation point but _cond_timedwait() is not. - * System libraries call the non-cancellation version. - * It is expected that only applications call the cancellation version. + * cond_timedwait() and _cond_timedwait() are cancellation points + * but __cond_timedwait() is not. */ int -_cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) +__cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) { clockid_t clock_id = cvp->cond_clockid; timespec_t reltime; @@ -3174,13 +3235,14 @@ _cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) return (error); } +#pragma weak cond_timedwait = _cond_timedwait int -cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) +_cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) { int error; _cancelon(); - error = _cond_timedwait(cvp, mp, abstime); + error = __cond_timedwait(cvp, mp, abstime); if (error == EINTR) _canceloff(); else @@ -3188,13 +3250,16 @@ cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) return (error); } +/* + * pthread_cond_timedwait() is a cancellation point. + */ #pragma weak pthread_cond_timedwait = _pthread_cond_timedwait int _pthread_cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) { int error; - error = cond_timedwait(cvp, mp, abstime); + error = _cond_timedwait(cvp, mp, abstime); if (error == ETIME) error = ETIMEDOUT; else if (error == EINTR) @@ -3203,26 +3268,25 @@ _pthread_cond_timedwait(cond_t *cvp, mutex_t *mp, const timespec_t *abstime) } /* - * cond_reltimedwait() is a cancellation point but _cond_reltimedwait() - * is not. System libraries call the non-cancellation version. - * It is expected that only applications call the cancellation version. + * cond_reltimedwait() and _cond_reltimedwait() are cancellation points + * but __cond_reltimedwait() is not. */ int -_cond_reltimedwait(cond_t *cvp, mutex_t *mp, const timespec_t *reltime) +__cond_reltimedwait(cond_t *cvp, mutex_t *mp, const timespec_t *reltime) { timespec_t tslocal = *reltime; return (cond_wait_common(cvp, mp, &tslocal)); } -#pragma weak cond_reltimedwait = _cond_reltimedwait_cancel +#pragma weak cond_reltimedwait = _cond_reltimedwait int -_cond_reltimedwait_cancel(cond_t *cvp, mutex_t *mp, const timespec_t *reltime) +_cond_reltimedwait(cond_t *cvp, mutex_t *mp, const timespec_t *reltime) { int error; _cancelon(); - error = _cond_reltimedwait(cvp, mp, reltime); + error = __cond_reltimedwait(cvp, mp, reltime); if (error == EINTR) _canceloff(); else @@ -3237,7 +3301,7 @@ _pthread_cond_reltimedwait_np(cond_t *cvp, mutex_t *mp, { int error; - error = _cond_reltimedwait_cancel(cvp, mp, reltime); + error = _cond_reltimedwait(cvp, mp, reltime); if (error == ETIME) error = ETIMEDOUT; else if (error == EINTR) diff --git a/usr/src/lib/libc/port/threads/thr.c b/usr/src/lib/libc/port/threads/thr.c index 74a69e44f2..3f11ad1f2f 100644 --- a/usr/src/lib/libc/port/threads/thr.c +++ b/usr/src/lib/libc/port/threads/thr.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -28,9 +28,11 @@ #include "lint.h" #include "thr_uberdata.h" +#include <pthread.h> #include <procfs.h> #include <sys/uio.h> #include <ctype.h> +#include "libc.h" #undef errno extern int errno; @@ -204,68 +206,26 @@ hash_out(ulwp_t *ulwp, uberdata_t *udp) } } +/* + * Retain stack information for thread structures that are being recycled for + * new threads. All other members of the thread structure should be zeroed. + */ static void ulwp_clean(ulwp_t *ulwp) { - ulwp->ul_self = NULL; - ulwp->ul_rval = NULL; - ulwp->ul_lwpid = 0; - ulwp->ul_pri = 0; - ulwp->ul_mappedpri = 0; - ulwp->ul_policy = 0; - ulwp->ul_pri_mapped = 0; - ulwp->ul_mutator = 0; - ulwp->ul_pleasestop = 0; - ulwp->ul_stop = 0; - ulwp->ul_dead = 0; - ulwp->ul_unwind = 0; - ulwp->ul_detached = 0; - ulwp->ul_stopping = 0; - ulwp->ul_sp = 0; - ulwp->ul_critical = 0; - ulwp->ul_cancelable = 0; - ulwp->ul_preempt = 0; - ulwp->ul_sigsuspend = 0; - ulwp->ul_cancel_pending = 0; - ulwp->ul_cancel_disabled = 0; - ulwp->ul_cancel_async = 0; - ulwp->ul_save_async = 0; - ulwp->ul_cursig = 0; - ulwp->ul_created = 0; - ulwp->ul_replace = 0; - ulwp->ul_schedctl_called = NULL; - ulwp->ul_errno = 0; - ulwp->ul_errnop = NULL; - ulwp->ul_clnup_hdr = NULL; - ulwp->ul_schedctl = NULL; - ulwp->ul_bindflags = 0; - (void) _private_memset(&ulwp->ul_td_evbuf, 0, - sizeof (ulwp->ul_td_evbuf)); - ulwp->ul_td_events_enable = 0; - ulwp->ul_qtype = 0; - ulwp->ul_usropts = 0; - ulwp->ul_startpc = NULL; - ulwp->ul_startarg = NULL; - ulwp->ul_wchan = NULL; - ulwp->ul_link = NULL; - ulwp->ul_sleepq = NULL; - ulwp->ul_mxchain = NULL; - ulwp->ul_epri = 0; - ulwp->ul_emappedpri = 0; - /* PROBE_SUPPORT begin */ - ulwp->ul_tpdp = NULL; - /* PROBE_SUPPORT end */ - ulwp->ul_siglink = NULL; - (void) _private_memset(ulwp->ul_ftsd, 0, - sizeof (void *) * TSD_NFAST); - ulwp->ul_stsd = NULL; - (void) _private_memset(&ulwp->ul_spinlock, 0, - sizeof (ulwp->ul_spinlock)); - ulwp->ul_spin_lock_spin = 0; - ulwp->ul_spin_lock_spin2 = 0; - ulwp->ul_spin_lock_sleep = 0; - ulwp->ul_spin_lock_wakeup = 0; - ulwp->ul_ex_unwind = NULL; + caddr_t stk = ulwp->ul_stk; + size_t mapsiz = ulwp->ul_mapsiz; + size_t guardsize = ulwp->ul_guardsize; + uintptr_t stktop = ulwp->ul_stktop; + size_t stksiz = ulwp->ul_stksiz; + + (void) _private_memset(ulwp, 0, sizeof (*ulwp)); + + ulwp->ul_stk = stk; + ulwp->ul_mapsiz = mapsiz; + ulwp->ul_guardsize = guardsize; + ulwp->ul_stktop = stktop; + ulwp->ul_stksiz = stksiz; } static int stackprot; @@ -700,7 +660,6 @@ _thrp_create(void *stk, size_t stksize, void *(*func)(void *), void *arg, return (error); } self->ul_nocancel = 0; /* cancellation is now possible */ - ulwp->ul_nocancel = 0; udp->uberflags.uf_mt = 1; if (new_thread) *new_thread = tid; @@ -942,6 +901,7 @@ _thr_exit_common(void *status, int unwind) self->ul_save_async = 0; self->ul_cancelable = 0; self->ul_cancel_pending = 0; + set_cancel_pending_flag(self, 1); if (cancelled && cleanuphndlr != NULL) (*cleanuphndlr)(); @@ -1341,8 +1301,7 @@ libc_init(void) self->ul_dreturn = 0x81ca0000; /* return %o0 */ #endif - self->ul_stktop = - (uintptr_t)uc.uc_stack.ss_sp + uc.uc_stack.ss_size; + self->ul_stktop = (uintptr_t)uc.uc_stack.ss_sp + uc.uc_stack.ss_size; (void) _private_getrlimit(RLIMIT_STACK, &rl); self->ul_stksiz = rl.rlim_cur; self->ul_stk = (caddr_t)(self->ul_stktop - self->ul_stksiz); @@ -1484,6 +1443,13 @@ libc_init(void) if (setmask) (void) restore_signals(self); + /* + * Make private copies of __xpg4 and __xpg6 so libc can test + * them after this point without invoking the dynamic linker. + */ + libc__xpg4 = __xpg4; + libc__xpg6 = __xpg6; + /* PROBE_SUPPORT begin */ if (self->ul_primarymap && __tnf_probe_notify != NULL) __tnf_probe_notify(); @@ -1879,7 +1845,7 @@ top: */ while (ulwp && !ulwp->ul_dead && !ulwp->ul_stop && (ulwp->ul_pleasestop & whystopped)) { - (void) _cond_wait(cvp, mp); + (void) __cond_wait(cvp, mp); for (ulwp = udp->thr_hash_table[ix].hash_bucket; ulwp != NULL; ulwp = ulwp->ul_hash) { if (ulwp->ul_lwpid == tid) @@ -2223,6 +2189,15 @@ do_exit_critical() ASSERT(self->ul_critical == 0); } +/* + * _ti_bind_guard() and _ti_bind_clear() are called by the dynamic linker + * (ld.so.1) when it has do do something, like resolve a symbol to be called + * by the application or one of its libraries. _ti_bind_guard() is called + * on entry to ld.so.1, _ti_bind_clear() on exit from ld.so.1 back to the + * application. The dynamic linker gets special dispensation from libc to + * run in a critical region (all signals deferred and no thread suspension + * or forking allowed), and to be immune from cancellation for the duration. + */ int _ti_bind_guard(int bindflag) { @@ -2231,6 +2206,9 @@ _ti_bind_guard(int bindflag) if ((self->ul_bindflags & bindflag) == bindflag) return (0); enter_critical(self); + self->ul_save_state = self->ul_cancel_disabled; + self->ul_cancel_disabled = 1; + set_cancel_pending_flag(self, 0); self->ul_bindflags |= bindflag; return (1); } @@ -2243,6 +2221,8 @@ _ti_bind_clear(int bindflag) if ((self->ul_bindflags & bindflag) == 0) return (self->ul_bindflags); self->ul_bindflags &= ~bindflag; + self->ul_cancel_disabled = self->ul_save_state; + set_cancel_pending_flag(self, 0); exit_critical(self); return (self->ul_bindflags); } @@ -2443,7 +2423,7 @@ _thr_setstate(thread_t tid, int flag, gregset_t rs) int getlwpstatus(thread_t tid, struct lwpstatus *sp) { - extern ssize_t _pread(int, void *, size_t, off_t); + extern ssize_t __pread(int, void *, size_t, off_t); char buf[100]; int fd; @@ -2451,15 +2431,15 @@ getlwpstatus(thread_t tid, struct lwpstatus *sp) (void) strcpy(buf, "/proc/self/lwp/"); ultos((uint64_t)tid, 10, buf + strlen(buf)); (void) strcat(buf, "/lwpstatus"); - if ((fd = _open(buf, O_RDONLY, 0)) >= 0) { - while (_pread(fd, sp, sizeof (*sp), 0) == sizeof (*sp)) { + if ((fd = _private_open(buf, O_RDONLY, 0)) >= 0) { + while (__pread(fd, sp, sizeof (*sp), 0) == sizeof (*sp)) { if (sp->pr_flags & PR_STOPPED) { - (void) _close(fd); + (void) _private_close(fd); return (0); } lwp_yield(); /* give him a chance to stop */ } - (void) _close(fd); + (void) _private_close(fd); } return (-1); } @@ -2467,7 +2447,7 @@ getlwpstatus(thread_t tid, struct lwpstatus *sp) int putlwpregs(thread_t tid, prgregset_t prp) { - extern ssize_t _writev(int, const struct iovec *, int); + extern ssize_t __writev(int, const struct iovec *, int); char buf[100]; int fd; long dstop_sreg[2]; @@ -2478,7 +2458,7 @@ putlwpregs(thread_t tid, prgregset_t prp) (void) strcpy(buf, "/proc/self/lwp/"); ultos((uint64_t)tid, 10, buf + strlen(buf)); (void) strcat(buf, "/lwpctl"); - if ((fd = _open(buf, O_WRONLY, 0)) >= 0) { + if ((fd = _private_open(buf, O_WRONLY, 0)) >= 0) { dstop_sreg[0] = PCDSTOP; /* direct it to stop */ dstop_sreg[1] = PCSREG; /* set the registers */ iov[0].iov_base = (caddr_t)dstop_sreg; @@ -2489,11 +2469,11 @@ putlwpregs(thread_t tid, prgregset_t prp) run_null[1] = 0; iov[2].iov_base = (caddr_t)run_null; iov[2].iov_len = sizeof (run_null); - if (_writev(fd, iov, 3) >= 0) { - (void) _close(fd); + if (__writev(fd, iov, 3) >= 0) { + (void) _private_close(fd); return (0); } - (void) _close(fd); + (void) _private_close(fd); } return (-1); } @@ -2558,8 +2538,9 @@ _thr_setmutator(thread_t tid, int enabled) uberdata_t *udp = self->ul_uberdata; ulwp_t *ulwp; int error; + int cancel_state; - enabled = enabled?1:0; + enabled = enabled? 1 : 0; top: if (tid == 0) { ulwp = self; @@ -2579,8 +2560,11 @@ top: lmutex_lock(&mutatorslock); if (mutatorsbarrier) { ulwp_unlock(ulwp, udp); + (void) _pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); while (mutatorsbarrier) (void) _cond_wait(&mutatorscv, &mutatorslock); + (void) _pthread_setcancelstate(cancel_state, NULL); lmutex_unlock(&mutatorslock); goto top; } @@ -2601,14 +2585,17 @@ void _thr_mutators_barrier(int enabled) { int oldvalue; + int cancel_state; lmutex_lock(&mutatorslock); /* * Wait if trying to set the barrier while it is already set. */ + (void) _pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); while (mutatorsbarrier && enabled) (void) _cond_wait(&mutatorscv, &mutatorslock); + (void) _pthread_setcancelstate(cancel_state, NULL); oldvalue = mutatorsbarrier; mutatorsbarrier = enabled; @@ -2751,11 +2738,15 @@ _thr_wait_mutator(thread_t tid, int dontwait) { uberdata_t *udp = curthread->ul_uberdata; ulwp_t *ulwp; + int cancel_state; int error = 0; + (void) _pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); top: - if ((ulwp = find_lwp(tid)) == NULL) + if ((ulwp = find_lwp(tid)) == NULL) { + (void) _pthread_setcancelstate(cancel_state, NULL); return (ESRCH); + } if (!ulwp->ul_mutator) error = EINVAL; @@ -2772,6 +2763,7 @@ top: } ulwp_unlock(ulwp, udp); + (void) _pthread_setcancelstate(cancel_state, NULL); return (error); } diff --git a/usr/src/lib/libc/sparc/Makefile b/usr/src/lib/libc/sparc/Makefile index 2089d2920a..5697b855c9 100644 --- a/usr/src/lib/libc/sparc/Makefile +++ b/usr/src/lib/libc/sparc/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -47,7 +47,8 @@ CRTOBJS= \ cerror64.o \ hwmuldiv.o -DYNOBJS= +DYNOBJS= \ + _rtbootld.o FPOBJS= \ _D_cplx_div.o \ @@ -181,7 +182,6 @@ SYSOBJS64= \ COMSYSOBJS= \ __clock_timer.o \ - __fcntl.o \ __getloadavg.o \ __rusagesys.o \ __signotify.o \ @@ -192,7 +192,6 @@ COMSYSOBJS= \ _nfssys.o \ _portfs.o \ _pset.o \ - _rename.o \ _rpcsys.o \ _sigaction.o \ _so_accept.o \ @@ -234,6 +233,7 @@ COMSYSOBJS= \ fchmod.o \ fchown.o \ fchroot.o \ + fcntl.o \ fdsync.o \ fpathconf.o \ fstat.o \ @@ -292,6 +292,7 @@ COMSYSOBJS= \ read.o \ readlink.o \ readv.o \ + rename.o \ resolvepath.o \ rmdir.o \ seteguid.o \ @@ -342,7 +343,6 @@ SYSOBJS= \ pipe.o \ ptrace.o \ syscall.o \ - syssun.o \ tls_get_addr.o \ uadmin.o \ umount.o \ @@ -561,7 +561,7 @@ PORTGEN= \ realpath.o \ reboot.o \ regexpr.o \ - rename.o \ + remove.o \ rewinddir.o \ rindex.o \ scandir.o \ @@ -627,8 +627,6 @@ PORTGEN= \ valloc.o \ vlfmt.o \ vpfmt.o \ - wait3.o \ - wait4.o \ waitpid.o \ walkstack.o \ wdata.o \ @@ -859,15 +857,14 @@ PORTSYS= \ execle.o \ execv.o \ faccessat.o \ - fcntl.o \ fsmisc.o \ fstatat.o \ - fsync.o \ getpagesizes.o \ getpeerucred.o \ inst_sync.o \ issetugid.o \ label.o \ + libc_fcntl.o \ libc_link.o \ libc_open.o \ lockf.o \ @@ -1082,7 +1079,6 @@ SRCS= \ $(LIBCBASE)/sys/ptrace.c # conditional assignments -$(DYNLIB) $(LIB_PIC) := DYNOBJS = _rtbootld.o $(DYNLIB) := CRTI = crti.o $(DYNLIB) := CRTN = crtn.o diff --git a/usr/src/lib/libc/sparc/mapfile-vers b/usr/src/lib/libc/sparc/mapfile-vers index a593fc9723..6319501512 100644 --- a/usr/src/lib/libc/sparc/mapfile-vers +++ b/usr/src/lib/libc/sparc/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -961,7 +961,6 @@ SUNWprivate_1.1 { _sys_index; _sys_nerr = NODYNSORT; _sys_num_err; - _syssun; __ucmpdi2; __udivdi3; __umoddi3; @@ -988,6 +987,8 @@ SUNWprivate_1.1 { local: __cerror = NODYNSORT; __cerror64 = NODYNSORT; + _private_fstat64 = NODYNSORT; + _private_stat64 = NODYNSORT; _seekdir64 = NODYNSORT; _telldir64 = NODYNSORT; }; diff --git a/usr/src/lib/libc/sparc/sys/door.s b/usr/src/lib/libc/sparc/sys/door.s index 3b1abf187e..2a2f4216c1 100644 --- a/usr/src/lib/libc/sparc/sys/door.s +++ b/usr/src/lib/libc/sparc/sys/door.s @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,7 +34,6 @@ * weak aliases for public interfaces */ ANSI_PRAGMA_WEAK(_door_bind,function) - ANSI_PRAGMA_WEAK(_door_call,function) ANSI_PRAGMA_WEAK(_door_getparam,function) ANSI_PRAGMA_WEAK(_door_info,function) ANSI_PRAGMA_WEAK(_door_revoke,function) @@ -42,7 +41,6 @@ ANSI_PRAGMA_WEAK(_door_unbind,function) ANSI_PRAGMA_WEAK(door_bind,function) - ANSI_PRAGMA_WEAK(door_call,function) ANSI_PRAGMA_WEAK(door_getparam,function) ANSI_PRAGMA_WEAK(door_info,function) ANSI_PRAGMA_WEAK(door_revoke,function) diff --git a/usr/src/lib/libc/sparc/sys/syssun.s b/usr/src/lib/libc/sparc/sys/syssun.s deleted file mode 100644 index 799a91d99a..0000000000 --- a/usr/src/lib/libc/sparc/sys/syssun.s +++ /dev/null @@ -1,44 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - - -/* Copyright (c) 1989 by Sun Microsystems, Inc. */ - -.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3.1.5 */ - -/* C library -- syssun (from sys3b2) */ -/* int syssun(cmd, ... ); */ - - .file "syssun.s" - -#include <sys/asm_linkage.h> - - ANSI_PRAGMA_WEAK(syssun,function) - -#include "SYS.h" - - SYSCALL(syssun) - RET - - SET_SIZE(syssun) diff --git a/usr/src/lib/libc/sparcv9/Makefile b/usr/src/lib/libc/sparcv9/Makefile index e71aef0883..3582c80351 100644 --- a/usr/src/lib/libc/sparcv9/Makefile +++ b/usr/src/lib/libc/sparcv9/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -164,7 +164,6 @@ SYSOBJS64= COMSYSOBJS= \ __clock_timer.o \ - __fcntl.o \ __getloadavg.o \ __rusagesys.o \ __signotify.o \ @@ -175,7 +174,6 @@ COMSYSOBJS= \ _nfssys.o \ _portfs.o \ _pset.o \ - _rename.o \ _rpcsys.o \ _sigaction.o \ _so_accept.o \ @@ -217,6 +215,7 @@ COMSYSOBJS= \ fchmod.o \ fchown.o \ fchroot.o \ + fcntl.o \ fdsync.o \ fpathconf.o \ fstat.o \ @@ -275,6 +274,7 @@ COMSYSOBJS= \ read.o \ readlink.o \ readv.o \ + rename.o \ resolvepath.o \ rmdir.o \ seteguid.o \ @@ -325,7 +325,6 @@ SYSOBJS= \ pipe.o \ sparc_utrap_install.o \ syscall.o \ - syssun.o \ tls_get_addr.o \ uadmin.o \ umount.o \ @@ -523,7 +522,7 @@ PORTGEN= \ realpath.o \ reboot.o \ regexpr.o \ - rename.o \ + remove.o \ rewinddir.o \ rindex.o \ scandir.o \ @@ -588,8 +587,6 @@ PORTGEN= \ valloc.o \ vlfmt.o \ vpfmt.o \ - wait3.o \ - wait4.o \ waitpid.o \ walkstack.o \ wdata.o \ @@ -804,15 +801,14 @@ PORTSYS= \ execle.o \ execv.o \ faccessat.o \ - fcntl.o \ fsmisc.o \ fstatat.o \ - fsync.o \ getpagesizes.o \ getpeerucred.o \ inst_sync.o \ issetugid.o \ label.o \ + libc_fcntl.o \ libc_link.o \ libc_open.o \ lockf.o \ @@ -1014,7 +1010,6 @@ SRCS= \ $(LIBCBASE)/gen/swapctxt.c # conditional assignments -# $(DYNLIB) $(LIB_PIC) := DYNOBJS = _rtbootld.o $(DYNLIB) := CRTI = crti.o $(DYNLIB) := CRTN = crtn.o diff --git a/usr/src/lib/libc/sparcv9/mapfile-vers b/usr/src/lib/libc/sparcv9/mapfile-vers index 44fa85ee0f..5c84dc96f6 100644 --- a/usr/src/lib/libc/sparcv9/mapfile-vers +++ b/usr/src/lib/libc/sparcv9/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -807,7 +807,6 @@ SUNWprivate_1.1 { _Q_cplx_lr_mul; _Q_cplx_mul; _QgetRD; - _syssun; _xregs_clrptr; __yday_to_month; diff --git a/usr/src/lib/libproc/common/pr_waitid.c b/usr/src/lib/libproc/common/pr_waitid.c index fdf57c29b2..06feaf9e8a 100644 --- a/usr/src/lib/libproc/common/pr_waitid.c +++ b/usr/src/lib/libproc/common/pr_waitid.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,9 +18,10 @@ * * CDDL HEADER END */ + /* - * Copyright (c) 1998-2000 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -43,7 +43,7 @@ */ int pr_waitid(struct ps_prochandle *Pr, - idtype_t idtype, id_t id, siginfo_t *infop, int options) + idtype_t idtype, id_t id, siginfo_t *infop, int options) { sysret_t rval; /* return value from waitid() */ argdes_t argd[4]; /* arg descriptors for waitid() */ @@ -94,7 +94,7 @@ pr_waitid(struct ps_prochandle *Pr, adp->arg_inout = AI_INPUT; adp->arg_size = 0; - error = Psyscall(Pr, &rval, SYS_waitsys, 4, &argd[0]); + error = Psyscall(Pr, &rval, SYS_waitid, 4, &argd[0]); if (error) { errno = (error > 0)? error : ENOSYS; diff --git a/usr/src/lib/libscf/common/lowlevel.c b/usr/src/lib/libscf/common/lowlevel.c index ce40d0e74f..a9265f9c1c 100644 --- a/usr/src/lib/libscf/common/lowlevel.c +++ b/usr/src/lib/libscf/common/lowlevel.c @@ -18,6 +18,7 @@ * * CDDL HEADER END */ + /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -76,14 +77,6 @@ struct _lwp_mutex; extern int _mutex_held(struct _lwp_mutex *); #define MUTEX_HELD(m) _mutex_held((struct _lwp_mutex *)(m)) -/* - * no cancellation, please - */ -struct _lwp_cond; -extern int _cond_wait(struct _lwp_cond *, struct _lwp_mutex *); -#define PTHREAD_COND_WAIT(cv, mx) \ - _cond_wait((struct _lwp_cond *)(cv), (struct _lwp_mutex *)(mx)) - #ifdef lint #define assert_nolint(x) (void)0 #else @@ -108,8 +101,14 @@ handle_hold_subhandles(scf_handle_t *h, int mask) assert(mask != 0 && (mask & ~RH_HOLD_ALL) == 0); (void) pthread_mutex_lock(&h->rh_lock); - while (h->rh_hold_flags != 0 && h->rh_holder != pthread_self()) - (void) PTHREAD_COND_WAIT(&h->rh_cv, &h->rh_lock); + while (h->rh_hold_flags != 0 && h->rh_holder != pthread_self()) { + int cancel_state; + + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) pthread_cond_wait(&h->rh_cv, &h->rh_lock); + (void) pthread_setcancelstate(cancel_state, NULL); + } if (h->rh_hold_flags == 0) h->rh_holder = pthread_self(); assert(!(h->rh_hold_flags & mask)); @@ -1029,8 +1028,14 @@ scf_handle_bind(scf_handle_t *handle) } /* wait until any active fd users have cleared out */ - while (handle->rh_fd_users > 0) - (void) PTHREAD_COND_WAIT(&handle->rh_cv, &handle->rh_lock); + while (handle->rh_fd_users > 0) { + int cancel_state; + + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) pthread_cond_wait(&handle->rh_cv, &handle->rh_lock); + (void) pthread_setcancelstate(cancel_state, NULL); + } /* check again, since we had to drop the lock */ if (handle_is_bound(handle)) { diff --git a/usr/src/lib/libscf/common/scf_type.c b/usr/src/lib/libscf/common/scf_type.c index 02067f2571..a8aed09f5a 100644 --- a/usr/src/lib/libscf/common/scf_type.c +++ b/usr/src/lib/libscf/common/scf_type.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,16 +18,20 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" +#ifndef NATIVE_BUILD +#include "c_synonyms.h" +#endif + #include <repcache_protocol.h> #include "scf_type.h" - #include <errno.h> #include <libgen.h> #include <libscf_priv.h> @@ -195,7 +198,7 @@ valid_uri(const char *str) return (0); if (regex(exp, str, uri[URI_SCHEME], uri[URI_AUTHORITY], uri[URI_PATH], - uri[URI_QUERY], uri[URI_FRAGMENT]) == NULL) { + uri[URI_QUERY], uri[URI_FRAGMENT]) == NULL) { return (0); } /* diff --git a/usr/src/lib/libsocket/socket/weaks.c b/usr/src/lib/libsocket/socket/weaks.c index ddca64c410..ffd794647e 100644 --- a/usr/src/lib/libsocket/socket/weaks.c +++ b/usr/src/lib/libsocket/socket/weaks.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -71,7 +71,6 @@ extern int _so_sendto(); extern int _so_getpeername(); extern int _so_getsockopt(); extern int _so_setsockopt(); -extern int _so_setsockname(); extern int _so_getsockname(); /* @@ -119,7 +118,7 @@ _recvfrom(int sock, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen) { return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2, - addr, addrlen)); + addr, addrlen)); } int @@ -145,7 +144,7 @@ _sendto(int sock, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen) { return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2, - addr, addrlen)); + addr, addrlen)); } int @@ -184,7 +183,7 @@ _getsockopt(int sock, int level, int optname, char *optval, int *optlen) break; case SCTP_DEFAULT_SEND_PARAM: bcopy(&((struct sctp_sndrcvinfo *) - optval)->sinfo_assoc_id, &id, sizeof (id)); + optval)->sinfo_assoc_id, &id, sizeof (id)); break; } @@ -200,7 +199,7 @@ _getsockopt(int sock, int level, int optname, char *optval, int *optlen) return (err); } else { return (_so_getsockopt(sock, level, optname, optval, optlen, - SOV_DEFAULT)); + SOV_DEFAULT)); } } @@ -208,7 +207,7 @@ int _setsockopt(int sock, int level, int optname, char *optval, int optlen) { return (_so_setsockopt(sock, level, optname, optval, optlen, - SOV_DEFAULT)); + SOV_DEFAULT)); } int @@ -247,7 +246,7 @@ __xnet_sendto(int sock, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen) { return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2, - addr, addrlen)); + addr, addrlen)); } int @@ -256,9 +255,9 @@ __xnet_getsockopt(int sock, int level, int option_name, { if (level == IPPROTO_SCTP) { return (_getsockopt(sock, level, option_name, option_value, - (int *)option_lenp)); + (int *)option_lenp)); } else { return (_so_getsockopt(sock, level, option_name, option_value, - option_lenp, SOV_XPG4_2)); + option_lenp, SOV_XPG4_2)); } } diff --git a/usr/src/lib/libumem/common/envvar.c b/usr/src/lib/libumem/common/envvar.c index bbdaf3a7e8..28f2d80a77 100644 --- a/usr/src/lib/libumem/common/envvar.c +++ b/usr/src/lib/libumem/common/envvar.c @@ -18,20 +18,21 @@ * * CDDL HEADER END */ + /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" +#include "c_synonyms.h" #include <ctype.h> #include <errno.h> #include <limits.h> #include <stdlib.h> #include <string.h> #include <dlfcn.h> - #include "umem_base.h" #include "vmem_base.h" diff --git a/usr/src/lib/libumem/common/getpcstack.c b/usr/src/lib/libumem/common/getpcstack.c index 48a51dfd04..1fd3c7e0a7 100644 --- a/usr/src/lib/libumem/common/getpcstack.c +++ b/usr/src/lib/libumem/common/getpcstack.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,20 +18,19 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" +#include "c_synonyms.h" #include "misc.h" - #include <ucontext.h> - #include <sys/frame.h> #include <sys/stack.h> - #include <stdio.h> #if defined(__sparc) || defined(__sparcv9) diff --git a/usr/src/lib/libumem/common/init_lib.c b/usr/src/lib/libumem/common/init_lib.c index 82f5e90687..797824e6d5 100644 --- a/usr/src/lib/libumem/common/init_lib.c +++ b/usr/src/lib/libumem/common/init_lib.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -30,9 +30,9 @@ * Initialization routines for the library version of libumem. */ +#include "c_synonyms.h" #include "umem_base.h" #include "vmem_base.h" - #include <unistd.h> #include <dlfcn.h> diff --git a/usr/src/lib/libumem/common/malloc.c b/usr/src/lib/libumem/common/malloc.c index 86c1b0fd0f..a309455cdd 100644 --- a/usr/src/lib/libumem/common/malloc.c +++ b/usr/src/lib/libumem/common/malloc.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,23 +18,23 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" -#include <unistd.h> +#if !defined(UMEM_STANDALONE) +#include "c_synonyms.h" +#endif +#include <unistd.h> #include <errno.h> - #include <string.h> - #include <sys/sysmacros.h> - #include "umem_base.h" - #include "misc.h" /* diff --git a/usr/src/lib/libumem/common/misc.h b/usr/src/lib/libumem/common/misc.h index 0ac9f62b2a..f1fdcc1812 100644 --- a/usr/src/lib/libumem/common/misc.h +++ b/usr/src/lib/libumem/common/misc.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,6 +32,7 @@ #include <sys/types.h> #include <sys/time.h> #include <thread.h> +#include <pthread.h> #include <stdarg.h> #ifdef __cplusplus diff --git a/usr/src/lib/libumem/common/stub_stand.c b/usr/src/lib/libumem/common/stub_stand.c index 7f37261638..add48bcc12 100644 --- a/usr/src/lib/libumem/common/stub_stand.c +++ b/usr/src/lib/libumem/common/stub_stand.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,8 +31,6 @@ */ #include <string.h> -#include <thread.h> - #include "misc.h" /*ARGSUSED*/ @@ -67,6 +64,13 @@ _cond_broadcast(cond_t *cvp) return (0); } +/*ARGSUSED*/ +int +_pthread_setcancelstate(int state, int *oldstate) +{ + return (0); +} + thread_t _thr_self(void) { diff --git a/usr/src/lib/libumem/common/umem.c b/usr/src/lib/libumem/common/umem.c index 9e762377ae..c740fddbbd 100644 --- a/usr/src/lib/libumem/common/umem.c +++ b/usr/src/lib/libumem/common/umem.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -603,12 +603,6 @@ caddr_t umem_min_stack; caddr_t umem_max_stack; -/* - * we use the _ versions, since we don't want to be cancelled. - * Actually, this is automatically taken care of by including "mtlib.h". - */ -extern int _cond_wait(cond_t *cv, mutex_t *mutex); - #define UMERR_MODIFIED 0 /* buffer modified while on freelist */ #define UMERR_REDZONE 1 /* redzone violation (write past end of buf) */ #define UMERR_DUPFREE 2 /* freed a buffer twice */ @@ -735,6 +729,8 @@ umem_remove_updates(umem_cache_t *cp) * Get it out of the active state */ while (cp->cache_uflags & UMU_ACTIVE) { + int cancel_state; + ASSERT(cp->cache_unext == NULL); cp->cache_uflags |= UMU_NOTIFY; @@ -746,7 +742,10 @@ umem_remove_updates(umem_cache_t *cp) ASSERT(umem_update_thr != thr_self() && umem_st_update_thr != thr_self()); - (void) _cond_wait(&umem_update_cv, &umem_update_lock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) cond_wait(&umem_update_cv, &umem_update_lock); + (void) pthread_setcancelstate(cancel_state, NULL); } /* * Get it out of the Work Requested state @@ -3047,9 +3046,16 @@ umem_init(void) * someone else beat us to initializing umem. Wait * for them to complete, then return. */ - while (umem_ready == UMEM_READY_INITING) - (void) _cond_wait(&umem_init_cv, + while (umem_ready == UMEM_READY_INITING) { + int cancel_state; + + (void) pthread_setcancelstate( + PTHREAD_CANCEL_DISABLE, &cancel_state); + (void) cond_wait(&umem_init_cv, &umem_init_lock); + (void) pthread_setcancelstate( + cancel_state, NULL); + } ASSERT(umem_ready == UMEM_READY || umem_ready == UMEM_READY_INIT_FAILED); (void) mutex_unlock(&umem_init_lock); diff --git a/usr/src/lib/libumem/common/umem_fail.c b/usr/src/lib/libumem/common/umem_fail.c index 000f98c366..7a4ab7466c 100644 --- a/usr/src/lib/libumem/common/umem_fail.c +++ b/usr/src/lib/libumem/common/umem_fail.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -30,6 +30,7 @@ * Failure routines for libumem (not standalone) */ +#include "c_synonyms.h" #include <sys/types.h> #include <signal.h> #include <stdarg.h> diff --git a/usr/src/lib/libumem/common/umem_update_thread.c b/usr/src/lib/libumem/common/umem_update_thread.c index 25abf20ae9..413f51d1f5 100644 --- a/usr/src/lib/libumem/common/umem_update_thread.c +++ b/usr/src/lib/libumem/common/umem_update_thread.c @@ -18,23 +18,20 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" +#include "c_synonyms.h" #include "umem_base.h" #include "vmem_base.h" #include <signal.h> -/* - * we use the _ version, since we don't want to be cancelled. - */ -extern int _cond_timedwait(cond_t *cv, mutex_t *mutex, const timespec_t *delay); - /*ARGSUSED*/ static void * umem_update_thread(void *arg) @@ -105,12 +102,16 @@ umem_update_thread(void *arg) * next update, or someone wakes us. */ if (umem_null_cache.cache_unext == &umem_null_cache) { + int cancel_state; timespec_t abs_time; abs_time.tv_sec = umem_update_next.tv_sec; abs_time.tv_nsec = umem_update_next.tv_usec * 1000; - (void) _cond_timedwait(&umem_update_cv, + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) cond_timedwait(&umem_update_cv, &umem_update_lock, &abs_time); + (void) pthread_setcancelstate(cancel_state, NULL); } } /* LINTED no return statement */ diff --git a/usr/src/lib/libumem/common/vmem.c b/usr/src/lib/libumem/common/vmem.c index 452e4d084f..76b9b5b30d 100644 --- a/usr/src/lib/libumem/common/vmem.c +++ b/usr/src/lib/libumem/common/vmem.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -219,12 +219,6 @@ uint32_t vmem_mtbf; /* mean time between failures [default: off] */ size_t vmem_seg_size = sizeof (vmem_seg_t); /* - * we use the _ version, since we don't want to be cancelled. - * Actually, this is automatically taken care of by including "mtlib.h". - */ -extern int _cond_wait(cond_t *cv, mutex_t *mutex); - -/* * Insert/delete from arena list (type 'a') or next-of-kin list (type 'k'). */ #define VMEM_INSERT(vprev, vsp, type) \ @@ -763,6 +757,8 @@ vmem_nextfit_alloc(vmem_t *vmp, size_t size, int vmflag) break; vsp = vsp->vs_anext; if (vsp == rotor) { + int cancel_state; + /* * We've come full circle. One possibility is that the * there's actually enough space, but the rotor itself @@ -787,7 +783,10 @@ vmem_nextfit_alloc(vmem_t *vmp, size_t size, int vmflag) 0, 0, NULL, NULL, vmflag & VM_UMFLAGS)); } vmp->vm_kstat.vk_wait++; - (void) _cond_wait(&vmp->vm_cv, &vmp->vm_lock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) cond_wait(&vmp->vm_cv, &vmp->vm_lock); + (void) pthread_setcancelstate(cancel_state, NULL); vsp = rotor->vs_anext; } } @@ -855,6 +854,8 @@ vmem_xalloc(vmem_t *vmp, size_t size, size_t align, size_t phase, (void) mutex_lock(&vmp->vm_lock); for (;;) { + int cancel_state; + if (vmp->vm_nsegfree < VMEM_MINFREE && !vmem_populate(vmp, vmflag)) break; @@ -974,7 +975,10 @@ vmem_xalloc(vmem_t *vmp, size_t size, size_t align, size_t phase, if (vmflag & VM_NOSLEEP) break; vmp->vm_kstat.vk_wait++; - (void) _cond_wait(&vmp->vm_cv, &vmp->vm_lock); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &cancel_state); + (void) cond_wait(&vmp->vm_cv, &vmp->vm_lock); + (void) pthread_setcancelstate(cancel_state, NULL); } if (vbest != NULL) { ASSERT(vbest->vs_type == VMEM_FREE); diff --git a/usr/src/lib/libumem/common/vmem_mmap.c b/usr/src/lib/libumem/common/vmem_mmap.c index a697eaf785..32a14d47c4 100644 --- a/usr/src/lib/libumem/common/vmem_mmap.c +++ b/usr/src/lib/libumem/common/vmem_mmap.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,17 +18,19 @@ * * CDDL HEADER END */ + /* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" +#include "c_synonyms.h" +#include <unistd.h> #include <errno.h> #include <sys/mman.h> #include <sys/sysmacros.h> - #include "vmem_base.h" #define ALLOC_PROT PROT_READ | PROT_WRITE | PROT_EXEC @@ -116,7 +117,7 @@ vmem_mmap_top_alloc(vmem_t *src, size_t size, int vmflags) vmem_t * vmem_mmap_arena(vmem_alloc_t **a_out, vmem_free_t **f_out) { - size_t pagesize = _sysconf(_SC_PAGESIZE); + size_t pagesize = sysconf(_SC_PAGESIZE); if (mmap_heap == NULL) { mmap_heap = vmem_init("mmap_top", CHUNKSIZE, diff --git a/usr/src/tools/tokenize/tokenize.sh b/usr/src/tools/tokenize/tokenize.sh index 7eeeb28850..9dc3d21488 100644 --- a/usr/src/tools/tokenize/tokenize.sh +++ b/usr/src/tools/tokenize/tokenize.sh @@ -3,9 +3,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ # CDDL HEADER END # # -# Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -47,8 +46,9 @@ echo 'end0' >> $infile outfile=`basename $1 .fth`.fcode ( unset LD_PRELOAD_32 LD_PRELOAD_64 + unset LD_BIND_NOW_32 LD_BIND_NOW_64 set -x - LD_PRELOAD=${mypath}/forth_preload.so.1 \ + LD_PRELOAD=${mypath}/forth_preload.so.1 LD_BIND_NOW=1 \ ${mypath}/forth ${mypath}/tokenize.exe \ -s "aout-header? off silent? on tokenize $infile $outfile" < /dev/null ) diff --git a/usr/src/uts/common/disp/shuttle.c b/usr/src/uts/common/disp/shuttle.c index a84014772f..62d118da75 100644 --- a/usr/src/uts/common/disp/shuttle.c +++ b/usr/src/uts/common/disp/shuttle.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,6 +37,7 @@ #include <sys/debug.h> #include <sys/sobject.h> #include <sys/cpuvar.h> +#include <sys/schedctl.h> #include <sys/sdt.h> static disp_lock_t shuttle_lock; /* lock on shuttle objects */ @@ -159,8 +161,8 @@ shuttle_resume(kthread_t *t, kmutex_t *l) * Make sure we didn't receive any important events while * we weren't looking */ - if (lwp && - (ISSIG(curthread, JUSTLOOKING) || MUSTRETURN(curproc, curthread))) + if (lwp && (ISSIG(curthread, JUSTLOOKING) || + MUSTRETURN(curproc, curthread) || schedctl_cancel_pending())) setrun(curthread); swtch_to(t); @@ -194,7 +196,8 @@ shuttle_swtch(kmutex_t *l) (void) new_mstate(curthread, LMS_SLEEP); disp_lock_exit_high(&shuttle_lock); mutex_exit(l); - if (ISSIG(curthread, JUSTLOOKING) || MUSTRETURN(curproc, curthread)) + if (ISSIG(curthread, JUSTLOOKING) || + MUSTRETURN(curproc, curthread) || schedctl_cancel_pending()) setrun(curthread); swtch(); /* diff --git a/usr/src/uts/common/fs/autofs/auto_subr.c b/usr/src/uts/common/fs/autofs/auto_subr.c index 87a8122fa1..d6b039e497 100644 --- a/usr/src/uts/common/fs/autofs/auto_subr.c +++ b/usr/src/uts/common/fs/autofs/auto_subr.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -51,6 +52,7 @@ #include <rpcsvc/autofs_prot.h> #include <nfs/rnode.h> #include <sys/utsname.h> +#include <sys/schedctl.h> /* * Autofs and Zones: @@ -479,7 +481,14 @@ auto_calldaemon( * handle, sleep and try again, if still * revoked we will get EBADF next time * through. + * + * If we have a pending cancellation and we don't + * have cancellation disabled, we will get EINTR + * forever, no matter how many times we retry, + * so just get out now if this is the case. */ + if (schedctl_cancel_pending()) + break; /* FALLTHROUGH */ case EAGAIN: /* process may be forking */ /* diff --git a/usr/src/uts/common/fs/doorfs/door_sys.c b/usr/src/uts/common/fs/doorfs/door_sys.c index ec9d650d99..15aadeb415 100644 --- a/usr/src/uts/common/fs/doorfs/door_sys.c +++ b/usr/src/uts/common/fs/doorfs/door_sys.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -514,6 +514,7 @@ door_call(int did, void *args) void *destarg; model_t datamodel; int gotresults = 0; + int cancel_pending; lwp = ttolwp(curthread); datamodel = lwp_getdatamodel(lwp); @@ -689,10 +690,14 @@ shuttle_return: * Premature wakeup. Find out why (stop, forkall, sig, exit ...) */ mutex_exit(&door_knob); /* May block in ISSIG */ - if (ISSIG(curthread, FORREAL) || - lwp->lwp_sysabort || MUSTRETURN(curproc, curthread)) { + cancel_pending = 0; + if (ISSIG(curthread, FORREAL) || lwp->lwp_sysabort || + MUSTRETURN(curproc, curthread) || + (cancel_pending = schedctl_cancel_pending()) != 0) { /* Signal, forkall, ... */ lwp->lwp_sysabort = 0; + if (cancel_pending) + schedctl_cancel_eintr(); mutex_enter(&door_knob); error = EINTR; /* @@ -1322,6 +1327,7 @@ door_return(caddr_t data_ptr, size_t data_size, door_node_t *dp; door_server_t *st; /* curthread door_data */ door_client_t *ct; /* caller door_data */ + int cancel_pending; st = door_my_server(1); @@ -1469,8 +1475,12 @@ out: st->d_caller = NULL; door_server_exit(curproc, curthread); mutex_exit(&door_knob); - if (ISSIG(curthread, FORREAL) || - lwp->lwp_sysabort || MUSTRETURN(curproc, curthread)) { + cancel_pending = 0; + if (ISSIG(curthread, FORREAL) || lwp->lwp_sysabort || + MUSTRETURN(curproc, curthread) || + (cancel_pending = schedctl_cancel_pending()) != 0) { + if (cancel_pending) + schedctl_cancel_eintr(); lwp->lwp_asleep = 0; lwp->lwp_sysabort = 0; return (set_errno(EINTR)); @@ -3008,6 +3018,7 @@ door_upcall(vnode_t *vp, door_arg_t *param) door_client_t *ct; /* curthread door_data */ door_server_t *st; /* server thread door_data */ int gotresults = 0; + int cancel_pending; if (vp->v_type != VDOOR) { if (param->desc_num) @@ -3105,9 +3116,13 @@ shuttle_return: * Premature wakeup. Find out why (stop, forkall, sig, exit ...) */ mutex_exit(&door_knob); /* May block in ISSIG */ - if (lwp && (ISSIG(curthread, FORREAL) || - lwp->lwp_sysabort || MUSTRETURN(curproc, curthread))) { + cancel_pending = 0; + if (lwp && (ISSIG(curthread, FORREAL) || lwp->lwp_sysabort || + MUSTRETURN(curproc, curthread) || + (cancel_pending = schedctl_cancel_pending()) != 0)) { /* Signal, forkall, ... */ + if (cancel_pending) + schedctl_cancel_eintr(); lwp->lwp_sysabort = 0; mutex_enter(&door_knob); error = EINTR; diff --git a/usr/src/uts/common/os/condvar.c b/usr/src/uts/common/os/condvar.c index fcc9d8aee7..dbcbb0dd0e 100644 --- a/usr/src/uts/common/os/condvar.c +++ b/usr/src/uts/common/os/condvar.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -249,6 +250,7 @@ cv_wait_sig(kcondvar_t *cvp, kmutex_t *mp) kthread_t *t = curthread; proc_t *p = ttoproc(t); klwp_t *lwp = ttolwp(t); + int cancel_pending; int rval = 1; int signalled = 0; @@ -265,13 +267,14 @@ cv_wait_sig(kcondvar_t *cvp, kmutex_t *mp) } ASSERT(curthread->t_schedflag & TS_DONT_SWAP); + cancel_pending = schedctl_cancel_pending(); lwp->lwp_asleep = 1; lwp->lwp_sysabort = 0; thread_lock(t); cv_block_sig(t, (condvar_impl_t *)cvp); thread_unlock_nopreempt(t); mutex_exit(mp); - if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t)) + if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending) setrun(t); /* ASSERT(no locks are held) */ swtch(); @@ -286,6 +289,10 @@ cv_wait_sig(kcondvar_t *cvp, kmutex_t *mp) } if (lwp->lwp_sysabort || MUSTRETURN(p, t)) rval = 0; + if (rval != 0 && cancel_pending) { + schedctl_cancel_eintr(); + rval = 0; + } lwp->lwp_asleep = 0; lwp->lwp_sysabort = 0; if (rval == 0 && signalled) /* avoid consuming the cv_signal() */ @@ -309,6 +316,7 @@ cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp, clock_t tim) kthread_t *t = curthread; proc_t *p = ttoproc(t); klwp_t *lwp = ttolwp(t); + int cancel_pending = 0; timeout_id_t id; clock_t rval = 1; clock_t timeleft; @@ -343,6 +351,7 @@ cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp, clock_t tim) /* * Set the timeout and wait. */ + cancel_pending = schedctl_cancel_pending(); id = realtime_timeout((void (*)(void *))setrun, t, timeleft); lwp->lwp_asleep = 1; lwp->lwp_sysabort = 0; @@ -350,7 +359,8 @@ cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp, clock_t tim) cv_block_sig(t, (condvar_impl_t *)cvp); thread_unlock_nopreempt(t); mutex_exit(mp); - if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || (tim - lbolt <= 0)) + if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending || + (tim - lbolt <= 0)) setrun(t); /* ASSERT(no locks are held) */ swtch(); @@ -383,6 +393,10 @@ out: } if (lwp->lwp_sysabort || MUSTRETURN(p, t)) rval = 0; + if (rval != 0 && cancel_pending) { + schedctl_cancel_eintr(); + rval = 0; + } lwp->lwp_asleep = 0; lwp->lwp_sysabort = 0; if (rval <= 0 && signalled) /* avoid consuming the cv_signal() */ @@ -404,6 +418,7 @@ cv_wait_sig_swap_core(kcondvar_t *cvp, kmutex_t *mp, int *sigret) kthread_t *t = curthread; proc_t *p = ttoproc(t); klwp_t *lwp = ttolwp(t); + int cancel_pending; int rval = 1; int signalled = 0; @@ -419,6 +434,7 @@ cv_wait_sig_swap_core(kcondvar_t *cvp, kmutex_t *mp, int *sigret) return (rval); } + cancel_pending = schedctl_cancel_pending(); lwp->lwp_asleep = 1; lwp->lwp_sysabort = 0; thread_lock(t); @@ -428,7 +444,7 @@ cv_wait_sig_swap_core(kcondvar_t *cvp, kmutex_t *mp, int *sigret) curthread->t_schedflag &= ~TS_DONT_SWAP; thread_unlock_nopreempt(t); mutex_exit(mp); - if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t)) + if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending) setrun(t); /* ASSERT(no locks are held) */ swtch(); @@ -445,6 +461,10 @@ cv_wait_sig_swap_core(kcondvar_t *cvp, kmutex_t *mp, int *sigret) } if (lwp->lwp_sysabort || MUSTRETURN(p, t)) rval = 0; + if (rval != 0 && cancel_pending) { + schedctl_cancel_eintr(); + rval = 0; + } lwp->lwp_asleep = 0; lwp->lwp_sysabort = 0; if (rval == 0) { @@ -646,7 +666,7 @@ cv_waituntil_sig(kcondvar_t *cvp, kmutex_t *mp, } else { if (timecheck == timechanged) { rval = cv_timedwait_sig(cvp, mp, - lbolt + timespectohz_adj(when, now)); + lbolt + timespectohz_adj(when, now)); } else { /* * Someone reset the system time; diff --git a/usr/src/uts/common/os/schedctl.c b/usr/src/uts/common/os/schedctl.c index 8a189b3c97..db6ee0e86e 100644 --- a/usr/src/uts/common/os/schedctl.c +++ b/usr/src/uts/common/os/schedctl.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -55,7 +56,6 @@ #include <vm/as.h> #include <fs/fs_subr.h> - /* * Page handling structures. This is set up as a list of per-page * control structures (sc_page_ctl), with p->p_pagep pointing to @@ -165,12 +165,13 @@ schedctl_lwp_cleanup(kthread_t *t) mutex_exit(&p->p_sc_lock); } + /* * Cleanup the list of schedctl shared pages for the process. * Called from exec() and exit() system calls. */ void -schedctl_proc_cleanup() +schedctl_proc_cleanup(void) { proc_t *p = curproc; sc_page_ctl_t *pagep; @@ -198,6 +199,7 @@ schedctl_proc_cleanup() } } + /* * Called by resume just before switching away from the current thread. * Save new thread state. @@ -248,6 +250,7 @@ schedctl_fork(kthread_t *pt, kthread_t *ct) mutex_exit(&pp->p_sc_lock); } + /* * Returns non-zero if the specified thread shouldn't be preempted at this time. * Called by ts_preempt, ts_tick, and ts_update. @@ -326,16 +329,54 @@ schedctl_finish_sigblock(kthread_t *t) /* + * Return non-zero if the current thread has declared that it has + * a cancellation pending and that cancellation is not disabled. + * If SIGCANCEL is blocked, we must be going over the wire in an + * NFS transaction (sigintr() was called); return zero in this case. + */ +int +schedctl_cancel_pending(void) +{ + sc_shared_t *tdp = curthread->t_schedctl; + + if (tdp != NULL && + (tdp->sc_flgs & SC_CANCEL_FLG) && + !tdp->sc_sigblock && + !sigismember(&curthread->t_hold, SIGCANCEL)) + return (1); + return (0); +} + + +/* + * Inform libc that the kernel returned EINTR from some system call + * due to there being a cancellation pending (SC_CANCEL_FLG set or + * we received an SI_LWP SIGCANCEL while in a system call), rather + * than because of some other signal. User-level code can try to + * recover from receiving other signals, but it can't recover from + * being cancelled. + */ +void +schedctl_cancel_eintr(void) +{ + sc_shared_t *tdp = curthread->t_schedctl; + + if (tdp != NULL) + tdp->sc_flgs |= SC_EINTR_FLG; +} + + +/* * Return non-zero if the current thread has declared that * it is calling into the kernel to park, else return zero. */ int -schedctl_is_park() +schedctl_is_park(void) { sc_shared_t *tdp = curthread->t_schedctl; if (tdp != NULL) - return (tdp->sc_park); + return ((tdp->sc_flgs & SC_PARK_FLG) != 0); /* * If we're here and there is no shared memory (how could * that happen?) then just assume we really are here to park. @@ -343,39 +384,40 @@ schedctl_is_park() return (1); } + /* * Declare thread is parking. * - * libc will set "sc_park = 1" before calling lwpsys_park(0, tid) in order - * to declare that the thread is calling into the kernel to park. + * libc will set "sc_flgs |= SC_PARK_FLG" before calling lwpsys_park(0, tid) + * in order to declare that the thread is calling into the kernel to park. * * This interface exists ONLY to support older versions of libthread which - * are not aware of the sc_park flag. + * are not aware of the SC_PARK_FLG flag. * - * Older versions of libthread which are not aware of the sc_park flag need to - * be modified or emulated to call lwpsys_park(4, ...) instead of + * Older versions of libthread which are not aware of the SC_PARK_FLG flag + * need to be modified or emulated to call lwpsys_park(4, ...) instead of * lwpsys_park(0, ...). This will invoke schedctl_set_park() before * lwp_park() to declare that the thread is parking. */ void -schedctl_set_park() +schedctl_set_park(void) { sc_shared_t *tdp = curthread->t_schedctl; - if (tdp != NULL) - tdp->sc_park = 1; + tdp->sc_flgs |= SC_PARK_FLG; } + /* - * Clear the shared sc_park flag on return from parking in the kernel. + * Clear the parking flag on return from parking in the kernel. */ void -schedctl_unpark() +schedctl_unpark(void) { sc_shared_t *tdp = curthread->t_schedctl; if (tdp != NULL) - tdp->sc_park = 0; + tdp->sc_flgs &= ~SC_PARK_FLG; } @@ -384,7 +426,7 @@ schedctl_unpark() */ void -schedctl_init() +schedctl_init(void) { /* * Amount of page that can hold sc_shared_t structures. If @@ -400,6 +442,7 @@ schedctl_init() sc_bitmap_words = howmany(sc_bitmap_len, BT_NBIPUL); } + int schedctl_shared_alloc(sc_shared_t **kaddrp, uintptr_t *uaddrp) { diff --git a/usr/src/uts/common/os/semaphore.c b/usr/src/uts/common/os/semaphore.c index 7f7e6235e3..ad25db33b3 100644 --- a/usr/src/uts/common/os/semaphore.c +++ b/usr/src/uts/common/os/semaphore.c @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,6 +33,7 @@ #include <sys/param.h> #include <sys/types.h> #include <sys/systm.h> +#include <sys/schedctl.h> #include <sys/semaphore.h> #include <sys/sema_impl.h> #include <sys/t_lock.h> @@ -253,6 +255,8 @@ sema_p_sig(ksema_t *sp) { kthread_t *t = curthread; klwp_t *lwp = ttolwp(t); + int cancel_pending; + int cancelled = 0; sema_impl_t *s; disp_lock_t *sqlp; @@ -261,6 +265,7 @@ sema_p_sig(ksema_t *sp) return (0); } + cancel_pending = schedctl_cancel_pending(); s = (sema_impl_t *)sp; sqlp = &SQHASH(s)->sq_lock; disp_lock_enter(sqlp); @@ -273,12 +278,12 @@ sema_p_sig(ksema_t *sp) lwp->lwp_asleep = 1; lwp->lwp_sysabort = 0; thread_unlock_nopreempt(t); - if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t)) + if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending) setrun(t); swtch(); t->t_flag &= ~T_WAKEABLE; - if (ISSIG(t, FORREAL) || - lwp->lwp_sysabort || MUSTRETURN(p, t)) { + if (ISSIG(t, FORREAL) || lwp->lwp_sysabort || + MUSTRETURN(p, t) || (cancelled = cancel_pending) != 0) { kthread_t *sq, *tp; lwp->lwp_asleep = 0; lwp->lwp_sysabort = 0; @@ -305,6 +310,8 @@ sema_p_sig(ksema_t *sp) } else { disp_lock_exit(sqlp); } + if (cancelled) + schedctl_cancel_eintr(); return (1); } lwp->lwp_asleep = 0; diff --git a/usr/src/uts/common/os/sig.c b/usr/src/uts/common/os/sig.c index bd6309dda0..8044529f83 100644 --- a/usr/src/uts/common/os/sig.c +++ b/usr/src/uts/common/os/sig.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -1376,6 +1376,14 @@ psig(void) sip = &lwp->lwp_siginfo; if (sqp) { bcopy(&sqp->sq_info, sip, sizeof (*sip)); + /* + * If we were interrupted out of a system call + * due to pthread_cancel(), inform libc. + */ + if (sig == SIGCANCEL && + sip->si_code == SI_LWP && + t->t_sysnum != 0) + schedctl_cancel_eintr(); } else if (sig == SIGPROF && sip->si_signo == SIGPROF && t->t_rprof != NULL && t->t_rprof->rp_anystate) { /* EMPTY */; diff --git a/usr/src/uts/common/sys/schedctl.h b/usr/src/uts/common/sys/schedctl.h index 9a118ce7e6..74a534d48c 100644 --- a/usr/src/uts/common/sys/schedctl.h +++ b/usr/src/uts/common/sys/schedctl.h @@ -18,8 +18,9 @@ * * CDDL HEADER END */ + /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -61,16 +62,22 @@ typedef struct sc_public { /* * The private portion of the sc_shared data is for * use by user-level threading support code in libc. + * Java has a contract to look at sc_state and sc_cpu (PSARC/2005/351). */ typedef struct sc_shared { volatile ushort_t sc_state; /* current LWP state */ volatile char sc_sigblock; /* all signals blocked */ - volatile char sc_park; /* calling lwp_park() */ + volatile uchar_t sc_flgs; /* set only by curthread; see below */ volatile processorid_t sc_cpu; /* last CPU on which LWP ran */ int sc_pad; sc_public_t sc_preemptctl; /* preemption control data */ } sc_shared_t; +/* sc_flgs */ +#define SC_PARK_FLG 0x01 /* calling lwp_park() */ +#define SC_CANCEL_FLG 0x02 /* cancel pending and not disabled */ +#define SC_EINTR_FLG 0x04 /* EINTR returned due to SC_CANCEL_FLG */ + /* * Possible state settings. These are same as the kernel thread states * except there is no zombie state. @@ -95,6 +102,8 @@ void schedctl_set_nopreempt(kthread_t *, short); void schedctl_set_yield(kthread_t *, short); int schedctl_sigblock(kthread_t *); void schedctl_finish_sigblock(kthread_t *); +int schedctl_cancel_pending(void); +void schedctl_cancel_eintr(void); int schedctl_is_park(void); void schedctl_set_park(void); void schedctl_unpark(void); diff --git a/usr/src/uts/common/sys/syscall.h b/usr/src/uts/common/sys/syscall.h index b04d0cf876..779672e7f5 100644 --- a/usr/src/uts/common/sys/syscall.h +++ b/usr/src/uts/common/sys/syscall.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -128,12 +128,10 @@ extern "C" { * msgsnap(...) :: msgsys(5, ...) * see <sys/msg.h> */ -#define SYS_syssun 50 #define SYS_sysi86 50 /* * subcodes: - * syssun(code, ...) - * see <sys/sys3b.h> + * sysi86(code, ...) */ #define SYS_acct 51 #define SYS_shmsys 52 @@ -301,7 +299,8 @@ extern "C" { #define SYS_fstatvfs 104 #define SYS_getloadavg 105 #define SYS_nfssys 106 -#define SYS_waitsys 107 +#define SYS_waitid 107 +#define SYS_waitsys SYS_waitid /* historical */ #define SYS_sigsendsys 108 #define SYS_hrtsys 109 #define SYS_sigresend 111 |