From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5230 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: thoughts on reallocarray, explicit_bzero? Date: Wed, 11 Jun 2014 08:59:12 -0400 Message-ID: <20140611125912.GQ179@brightrain.aerifal.cx> References: <20140519153130.GA519@muslin> <20140519162556.GY12324@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1402491572 30192 80.91.229.3 (11 Jun 2014 12:59:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Jun 2014 12:59:32 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5235-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 11 14:59:27 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Wui7i-0006fu-CM for gllmg-musl@plane.gmane.org; Wed, 11 Jun 2014 14:59:26 +0200 Original-Received: (qmail 19849 invoked by uid 550); 11 Jun 2014 12:59:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 19841 invoked from network); 11 Jun 2014 12:59:25 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:5230 Archived-At: On Wed, Jun 11, 2014 at 09:59:56AM +0000, Thorsten Glaser wrote: > Szabolcs Nagy port70.net> writes: > > > static size_t sizemul(size_t a, size_t b) > > { > > return b>1 && a>1 && a>-1/b ? -1 : a*b; > > } > > There is no -1 in size_t. (And *you* complain about OpenBSD checks…) The standard way (especially for generic programming, but it's usable anywhere) to get the max value for an unsigned type is to convert -1. b and a*b both have type size_t, so... > > i don't see how the openbsd explicit_bzero stops the > > compiler to do optimizations.. > > On OpenBSD: by being in libc which is not built with LTO. > I’ve wondered about how to do this either. Maybe: Yeah, that's a poor hack. We still probably have some places where "extern" is used as a compiler barrier, but it's wrong, and I'm working to identify and remove them all. > void > explicit_bzero(void *s, size_t n) > { > bzero(s, n); > __lto_boundary > } > > Then you #define __lto_boundary to something like > __asm__ volatile ("" : : : "memory"); > or > __sync_synchronize(); > or some C11 barrier function. These are not sufficient. It would probably need to be: __asm__ volatile ("" : : "r"(s) : "memory"); or similar. This is because volatility and memory-clobber only provide a barrier with respect to objects which exist in memory, and at the point of the asm (after transformations which do not disturb the observable behavior of the program), the pointed-to object with automatic storage does not exist. Rich