From owner-svn-src-all@freebsd.org Fri Sep 27 20:24:07 2019 Return-Path: Delivered-To: svn-src-all@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 5217412BE31; Fri, 27 Sep 2019 20:24:07 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 46g3D546b6z4H2q; Fri, 27 Sep 2019 20:24:04 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id C8FC0361B01; Sat, 28 Sep 2019 06:24:00 +1000 (AEST) Date: Sat, 28 Sep 2019 06:23:58 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Konstantin Belousov cc: Mateusz Guzik , Warner Losh , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r352795 - head/lib/libc/sys In-Reply-To: <20190927184623.GM44691@kib.kiev.ua> Message-ID: <20190928051802.Y3006@besplex.bde.org> References: <201909271611.x8RGBl0H036116@repo.freebsd.org> <20190927184623.GM44691@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=FNpr/6gs c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=6I5d2MoRAAAA:8 a=2Z3r3uBQAAAA:20 a=ELv_8EtWw7of5XQUhMEA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 X-Rspamd-Queue-Id: 46g3D546b6z4H2q X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of brde@optusnet.com.au designates 211.29.132.249 as permitted sender) smtp.mailfrom=brde@optusnet.com.au X-Spamd-Result: default: False [-2.30 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; RCVD_COUNT_TWO(0.00)[2]; RWL_MAILSPIKE_POSSIBLE(0.00)[249.132.29.211.rep.mailspike.net : 127.0.0.17]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[optusnet.com.au]; R_SPF_ALLOW(-0.20)[+ip4:211.29.132.0/23]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; DMARC_NA(0.00)[optusnet.com.au]; IP_SCORE_FREEMAIL(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; IP_SCORE(0.00)[ip: (-5.35), ipnet: 211.28.0.0/14(-3.27), asn: 4804(-2.41), country: AU(0.01)]; FREEMAIL_TO(0.00)[gmail.com]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[249.132.29.211.list.dnswl.org : 127.0.5.1]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[optusnet.com.au]; ASN(0.00)[asn:4804, ipnet:211.28.0.0/14, country:AU]; FREEMAIL_CC(0.00)[gmail.com] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Sep 2019 20:24:07 -0000 On Fri, 27 Sep 2019, Konstantin Belousov wrote: > On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote: >> On 9/27/19, Warner Losh wrote: >>> Author: imp >>> Date: Fri Sep 27 16:11:47 2019 >>> New Revision: 352795 >>> URL: https://svnweb.freebsd.org/changeset/base/352795 >>> >>> Log: >>> Document varadic args as int, since you can't have short varadic args >>> (they are >>> promoted to ints). >>> >>> - `mode_t` is `uint16_t` (`sys/sys/_types.h`) >>> - `openat` takes variadic args >>> - variadic args cannot be 16-bit, and indeed the code uses int >>> - the manpage currently kinda implies the argument is 16-bit by saying >>> `mode_t` >>> >>> Prompted by Rust things: https://github.com/tailhook/openat/issues/21 >>> Submitted by: Greg V at unrelenting >>> Differential Revision: https://reviews.freebsd.org/D21816 >>> >>> Modified: >>> head/lib/libc/sys/mq_open.2 >>> head/lib/libc/sys/open.2 >>> >>> Modified: head/lib/libc/sys/mq_open.2 >>> ============================================================================== >>> --- head/lib/libc/sys/mq_open.2 Fri Sep 27 15:28:30 2019 (r352794) >>> +++ head/lib/libc/sys/mq_open.2 Fri Sep 27 16:11:47 2019 (r352795) >>> @@ -133,7 +133,7 @@ Create a message queue. >>> It requires two additional arguments: >>> .Fa mode , >>> which is of type >>> -.Vt mode_t , >>> +.Vt int , >>> and >>> .Fa attr , >>> which is a pointer to an >>> >>> Modified: head/lib/libc/sys/open.2 >>> ============================================================================== >>> --- head/lib/libc/sys/open.2 Fri Sep 27 15:28:30 2019 (r352794) >>> +++ head/lib/libc/sys/open.2 Fri Sep 27 16:11:47 2019 (r352795) >>> @@ -61,7 +61,7 @@ In this case >>> and >>> .Fn openat >>> require an additional argument >>> -.Fa "mode_t mode" , >>> +.Fa "int mode" , >>> and the file is created with mode >>> .Fa mode >>> as described in >> >> But opengroup says it is mode_t. Perhaps it is mode_t which needs >> to be changed? POSIX needed to be changed before it became standard in 1988, but it is too late now. Types shorter than int shouldn't be used in APIs since they cause ABI and API problems. Especially in 1988 when non-prototyped functions were common. Non-prototyped functions use the default promotions much like variadic functions. open() is variadic, so its mode_t arg is always promoted, but 'int chmod(const char *path, mode_t mode)' is just wrong since in 1988 prototypes were not required and the prototype matching the K&R API was 'int chmod(const char *path, __default_promotion_of(mode_t) mode)'. > Yes, users must pass mode_t, and the man page is written for users. > Implementation needs to be aware of the implicit promotion and handle > it accordingly. > > In theory, mode_t might be wider than int. Indeed. mode_t can also be the same size as int, but unsigned. This happens naturally if int is 16 bits, which POSIX allowed before 2001. In V7, mode_t was really a 16-bit u_int, but it was type-punned to int. When mode_t is u_int or wider than int, then the promotion is null, and variadic and K&R do it consistently (but the arg type before the call must be precisely mode_t, not int). The POSIX list recently discussed a related problem with variadic pid_t args for fcntl(). For F_SETOWN, the original arg type should be pid_t as for mode_t for open(). Howver, F_GETOWN only returns int, so pids larger than INT_MAX cannot work and making pid_t different from int is just foot shooting. Bruce