From owner-svn-src-stable@freebsd.org Thu Feb 13 03:13:35 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4A98424B7A2; Thu, 13 Feb 2020 03:13:35 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48J1mt65Hzz4NtM; Thu, 13 Feb 2020 03:13:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B1BBB4236; Thu, 13 Feb 2020 03:13:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01D3DYPc070605; Thu, 13 Feb 2020 03:13:34 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01D3DWs7070594; Thu, 13 Feb 2020 03:13:32 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202002130313.01D3DWs7070594@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 13 Feb 2020 03:13:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r357852 - in stable: 11/include 11/lib/libc/stdio 12/include 12/lib/libc/stdio X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/include 11/lib/libc/stdio 12/include 12/lib/libc/stdio X-SVN-Commit-Revision: 357852 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Feb 2020 03:13:35 -0000 Author: kevans Date: Thu Feb 13 03:13:29 2020 New Revision: 357852 URL: https://svnweb.freebsd.org/changeset/base/357852 Log: MFC r357284, r357419: stdio unlocked r357284: stdio: provide _unlocked variants of fflush, fputc, fputs, fread, fwrite fflush_unlocked is currently desired in ports by sysutils/metalog, and redefined as the locked fflush. fputc_unlocked, fputs_unlocked, fread_unlocked, and fwrite_unlocked are currently desired in ports by devel/elfutils, and redefined as the locked fputs, fread, and fwrite respectively. r357419: libc: provide fputc_unlocked Among the same justification as the other stdio _unlocked; in addition to an inline version in , we must provide a function in libc as well for the functionality. This fixes the lang/gcc* builds, which want to use the symbol from libc. Modified: stable/12/include/stdio.h stable/12/lib/libc/stdio/Makefile.inc stable/12/lib/libc/stdio/Symbol.map stable/12/lib/libc/stdio/fflush.3 stable/12/lib/libc/stdio/fflush.c stable/12/lib/libc/stdio/fputc.c stable/12/lib/libc/stdio/fputs.3 stable/12/lib/libc/stdio/fputs.c stable/12/lib/libc/stdio/fread.3 stable/12/lib/libc/stdio/fread.c stable/12/lib/libc/stdio/fwrite.c stable/12/lib/libc/stdio/putc.3 Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/include/stdio.h stable/11/lib/libc/stdio/Makefile.inc stable/11/lib/libc/stdio/Symbol.map stable/11/lib/libc/stdio/fflush.3 stable/11/lib/libc/stdio/fflush.c stable/11/lib/libc/stdio/fputc.c stable/11/lib/libc/stdio/fputs.3 stable/11/lib/libc/stdio/fputs.c stable/11/lib/libc/stdio/fread.3 stable/11/lib/libc/stdio/fread.c stable/11/lib/libc/stdio/fwrite.c stable/11/lib/libc/stdio/putc.3 Directory Properties: stable/11/ (props changed) Modified: stable/12/include/stdio.h ============================================================================== --- stable/12/include/stdio.h Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/include/stdio.h Thu Feb 13 03:13:29 2020 (r357852) @@ -347,7 +347,13 @@ int putchar_unlocked(int); void clearerr_unlocked(FILE *); int feof_unlocked(FILE *); int ferror_unlocked(FILE *); +int fflush_unlocked(FILE *); int fileno_unlocked(FILE *); +int fputc_unlocked(int, FILE *); +int fputs_unlocked(const char * __restrict, FILE * __restrict); +size_t fread_unlocked(void * __restrict, size_t, size_t, FILE * __restrict); +size_t fwrite_unlocked(const void * __restrict, size_t, size_t, + FILE * __restrict); #endif #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 @@ -508,10 +514,11 @@ extern int __isthreaded; * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 * B.8.2.7 for the rationale behind the *_unlocked() macros. */ +#define clearerr_unlocked(p) __sclearerr(p) #define feof_unlocked(p) __sfeof(p) #define ferror_unlocked(p) __sferror(p) -#define clearerr_unlocked(p) __sclearerr(p) #define fileno_unlocked(p) __sfileno(p) +#define fputc_unlocked(s, p) __sputc(s, p) #endif #if __POSIX_VISIBLE >= 199506 #define getc_unlocked(fp) __sgetc(fp) Modified: stable/12/lib/libc/stdio/Makefile.inc ============================================================================== --- stable/12/lib/libc/stdio/Makefile.inc Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/Makefile.inc Thu Feb 13 03:13:29 2020 (r357852) @@ -48,13 +48,17 @@ MLINKS+=ferror.3 ferror_unlocked.3 \ ferror.3 clearerr.3 ferror.3 clearerr_unlocked.3 \ ferror.3 feof.3 ferror.3 feof_unlocked.3 \ ferror.3 fileno.3 ferror.3 fileno_unlocked.3 -MLINKS+=fflush.3 fpurge.3 +MLINKS+=fflush.3 fflush_unlocked.3 \ + fflush.3 fpurge.3 MLINKS+=fgets.3 gets.3 MLINKS+=fgets.3 gets_s.3 MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3 MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 fopen.3 fmemopen.3 -MLINKS+=fputs.3 puts.3 -MLINKS+=fread.3 fwrite.3 +MLINKS+=fputs.3 fputs_unlocked.3 \ + fputs.3 puts.3 +MLINKS+=fread.3 fread_unlocked.3 \ + fread.3 fwrite.3 \ + fread.3 fwrite_unlocked.3 MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \ fseek.3 ftello.3 fseek.3 rewind.3 MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3 Modified: stable/12/lib/libc/stdio/Symbol.map ============================================================================== --- stable/12/lib/libc/stdio/Symbol.map Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/Symbol.map Thu Feb 13 03:13:29 2020 (r357852) @@ -171,6 +171,14 @@ FBSD_1.5 { gets_s; }; +FBSD_1.6 { + fflush_unlocked; + fputc_unlocked; + fputs_unlocked; + fread_unlocked; + fwrite_unlocked; +}; + FBSDprivate_1.0 { _flockfile; _flockfile_debug_stub; Modified: stable/12/lib/libc/stdio/fflush.3 ============================================================================== --- stable/12/lib/libc/stdio/fflush.3 Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fflush.3 Thu Feb 13 03:13:29 2020 (r357852) @@ -32,11 +32,12 @@ .\" @(#)fflush.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 25, 2017 +.Dd January 23, 2020 .Dt FFLUSH 3 .Os .Sh NAME .Nm fflush , +.Nm fflush_unlocked , .Nm fpurge .Nd flush a stream .Sh LIBRARY @@ -46,6 +47,8 @@ .Ft int .Fn fflush "FILE *stream" .Ft int +.Fn fflush_unlocked "FILE *stream" +.Ft int .Fn fpurge "FILE *stream" .Sh DESCRIPTION The function @@ -63,6 +66,16 @@ argument is flushes .Em all open output streams. +.Pp +The +.Fn fflush_unlocked +function is equivalent to +.Fn fflush , +except that the caller is responsible for locking the stream with +.Xr flockfile 3 +before calling it. +This function may be used to avoid the overhead of locking the stream and to +prevent races when multiple threads are operating on the same stream. .Pp The function .Fn fpurge Modified: stable/12/lib/libc/stdio/fflush.c ============================================================================== --- stable/12/lib/libc/stdio/fflush.c Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fflush.c Thu Feb 13 03:13:29 2020 (r357852) @@ -100,6 +100,8 @@ __fflush(FILE *fp) return (retval); } +__weak_reference(__fflush, fflush_unlocked); + int __sflush(FILE *fp) { Modified: stable/12/lib/libc/stdio/fputc.c ============================================================================== --- stable/12/lib/libc/stdio/fputc.c Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fputc.c Thu Feb 13 03:13:29 2020 (r357852) @@ -44,14 +44,24 @@ __FBSDID("$FreeBSD$"); #include "local.h" #include "libc_private.h" +#undef fputc_unlocked + int +fputc_unlocked(int c, FILE *fp) +{ + + /* Orientation set by __sputc() when buffer is full. */ + /* ORIENT(fp, -1); */ + return (__sputc(c, fp)); +} + +int fputc(int c, FILE *fp) { int retval; + FLOCKFILE_CANCELSAFE(fp); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(fp, -1); */ - retval = __sputc(c, fp); + retval = fputc_unlocked(c, fp); FUNLOCKFILE_CANCELSAFE(); return (retval); } Modified: stable/12/lib/libc/stdio/fputs.3 ============================================================================== --- stable/12/lib/libc/stdio/fputs.3 Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fputs.3 Thu Feb 13 03:13:29 2020 (r357852) @@ -32,11 +32,12 @@ .\" @(#)fputs.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd January 23, 2020 .Dt FPUTS 3 .Os .Sh NAME .Nm fputs , +.Nm fputs_unlocked , .Nm puts .Nd output a line to a stream .Sh LIBRARY @@ -46,6 +47,8 @@ .Ft int .Fn fputs "const char *str" "FILE *stream" .Ft int +.Fn fputs_unlocked "const char *str" "FILE *stream" +.Ft int .Fn puts "const char *str" .Sh DESCRIPTION The function @@ -57,6 +60,16 @@ to the stream pointed to by .\" The terminating .\" .Dv NUL .\" character is not written. +.Pp +The +.Fn fputs_unlocked +function is equivalent to +.Fn fputs , +except that the caller is responsible for locking the stream with +.Xr flockfile 3 +before calling it. +This function may be used to avoid the overhead of locking the stream and to +prevent races when multiple threads are operating on the same stream. .Pp The function .Fn puts Modified: stable/12/lib/libc/stdio/fputs.c ============================================================================== --- stable/12/lib/libc/stdio/fputs.c Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fputs.c Thu Feb 13 03:13:29 2020 (r357852) @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); * Write the given string to the given file. */ int -fputs(const char * __restrict s, FILE * __restrict fp) +fputs_unlocked(const char * __restrict s, FILE * __restrict fp) { int retval; struct __suio uio; @@ -61,11 +61,20 @@ fputs(const char * __restrict s, FILE * __restrict fp) uio.uio_resid = iov.iov_len = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; - FLOCKFILE_CANCELSAFE(fp); ORIENT(fp, -1); retval = __sfvwrite(fp, &uio); - FUNLOCKFILE_CANCELSAFE(); if (retval == 0) return (iov.iov_len > INT_MAX ? INT_MAX : iov.iov_len); + return (retval); +} + +int +fputs(const char * __restrict s, FILE * __restrict fp) +{ + int retval; + + FLOCKFILE_CANCELSAFE(fp); + retval = fputs_unlocked(s, fp); + FUNLOCKFILE_CANCELSAFE(); return (retval); } Modified: stable/12/lib/libc/stdio/fread.3 ============================================================================== --- stable/12/lib/libc/stdio/fread.3 Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fread.3 Thu Feb 13 03:13:29 2020 (r357852) @@ -32,12 +32,14 @@ .\" @(#)fread.3 8.2 (Berkeley) 3/8/94 .\" $FreeBSD$ .\" -.Dd March 8, 1994 +.Dd January 23, 2020 .Dt FREAD 3 .Os .Sh NAME .Nm fread , -.Nm fwrite +.Nm fread_unlocked , +.Nm fwrite , +.Nm fwrite_unlocked .Nd binary stream input/output .Sh LIBRARY .Lb libc @@ -46,7 +48,11 @@ .Ft size_t .Fn fread "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream" .Ft size_t +.Fn fread_unlocked "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream" +.Ft size_t .Fn fwrite "const void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream" +.Ft size_t +.Fn fwrite_unlocked "const void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream" .Sh DESCRIPTION The function .Fn fread @@ -69,6 +75,21 @@ bytes long, to the stream pointed to by .Fa stream , obtaining them from the location given by .Fa ptr . +.Pp +The +.Fn fread_unlocked +and +.Fn fwrite_unlocked +functions are equivalent to +.Fn fread +and +.Fn fwrite +respectively, except that the caller is responsible for locking the stream +with +.Xr flockfile 3 +before calling them. +These functions may be used to avoid the overhead of locking the stream +and to prevent races when multiple threads are operating on the same stream. .Sh RETURN VALUES The functions .Fn fread Modified: stable/12/lib/libc/stdio/fread.c ============================================================================== --- stable/12/lib/libc/stdio/fread.c Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fread.c Thu Feb 13 03:13:29 2020 (r357852) @@ -115,3 +115,5 @@ __fread(void * __restrict buf, size_t size, size_t cou fp->_p += resid; return (count); } + +__weak_reference(__fread, fread_unlocked); Modified: stable/12/lib/libc/stdio/fwrite.c ============================================================================== --- stable/12/lib/libc/stdio/fwrite.c Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/fwrite.c Thu Feb 13 03:13:29 2020 (r357852) @@ -52,7 +52,8 @@ __FBSDID("$FreeBSD$"); * Return the number of whole objects written. */ size_t -fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) +fwrite_unlocked(const void * __restrict buf, size_t size, size_t count, + FILE * __restrict fp) { size_t n; struct __suio uio; @@ -84,7 +85,6 @@ fwrite(const void * __restrict buf, size_t size, size_ uio.uio_iov = &iov; uio.uio_iovcnt = 1; - FLOCKFILE_CANCELSAFE(fp); ORIENT(fp, -1); /* * The usual case is success (__sfvwrite returns 0); @@ -93,6 +93,17 @@ fwrite(const void * __restrict buf, size_t size, size_ */ if (__sfvwrite(fp, &uio) != 0) count = (n - uio.uio_resid) / size; - FUNLOCKFILE_CANCELSAFE(); return (count); +} + +size_t +fwrite(const void * __restrict buf, size_t size, size_t count, + FILE * __restrict fp) +{ + size_t n; + + FLOCKFILE_CANCELSAFE(fp); + n = fwrite_unlocked(buf, size, count, fp); + FUNLOCKFILE_CANCELSAFE(); + return (n); } Modified: stable/12/lib/libc/stdio/putc.3 ============================================================================== --- stable/12/lib/libc/stdio/putc.3 Thu Feb 13 03:11:39 2020 (r357851) +++ stable/12/lib/libc/stdio/putc.3 Thu Feb 13 03:13:29 2020 (r357852) @@ -32,11 +32,12 @@ .\" @(#)putc.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd January 10, 2003 +.Dd January 23, 2020 .Dt PUTC 3 .Os .Sh NAME .Nm fputc , +.Nm fputc_unlocked , .Nm putc , .Nm putc_unlocked , .Nm putchar , @@ -50,6 +51,8 @@ .Ft int .Fn fputc "int c" "FILE *stream" .Ft int +.Fn fputc_unlocked "int c" "FILE *stream" +.Ft int .Fn putc "int c" "FILE *stream" .Ft int .Fn putc_unlocked "int c" "FILE *stream" @@ -97,11 +100,13 @@ to the named output .Fa stream . .Pp The -.Fn putc_unlocked +.Fn fputc_unlocked , +.Fn putc_unlocked , and .Fn putchar_unlocked functions are equivalent to -.Fn putc +.Fn fputc , +.Fn putc , and .Fn putchar respectively,