From owner-svn-src-head@freebsd.org Fri Feb 8 08:43:23 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 368A814D87E0; Fri, 8 Feb 2019 08:43:23 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by mx1.freebsd.org (Postfix) with ESMTP id 171FC6F99F; Fri, 8 Feb 2019 08:43:19 +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 mail106.syd.optusnet.com.au (Postfix) with ESMTPS id 979F23D76BB; Fri, 8 Feb 2019 19:43:16 +1100 (AEDT) Date: Fri, 8 Feb 2019 19:43:15 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Will Andrews cc: Ed Maste , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r325728 - head/lib/libkvm In-Reply-To: Message-ID: <20190208190822.N858@besplex.bde.org> References: <201711112330.vABNUwXC077395@repo.freebsd.org> <20190205202145.A1080@besplex.bde.org> <20190206024025.X3175@besplex.bde.org> 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=P6RKvmIu c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=KlU3YLH_MOuymiYzc3sA:9 a=g6LFLHbxATuY_eKi:21 a=pcqAwT0wR9KJ7_pO:21 a=CjuIK1q_8ugA:10 X-Rspamd-Queue-Id: 171FC6F99F X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of brde@optusnet.com.au designates 211.29.132.42 as permitted sender) smtp.mailfrom=brde@optusnet.com.au X-Spamd-Result: default: False [-6.35 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; RCVD_IN_DNSWL_LOW(-0.10)[42.132.29.211.list.dnswl.org : 127.0.5.1]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:211.29.132.0/23]; FREEMAIL_FROM(0.00)[optusnet.com.au]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[optusnet.com.au]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCPT_COUNT_FIVE(0.00)[5]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[cached: extmail.optusnet.com.au]; NEURAL_HAM_SHORT(-0.83)[-0.833,0]; IP_SCORE(-3.21)[ip: (-8.71), ipnet: 211.28.0.0/14(-4.07), asn: 4804(-3.23), country: AU(-0.04)]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; 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]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Feb 2019 08:43:23 -0000 On Wed, 6 Feb 2019, Will Andrews wrote: > On Tue, Feb 5, 2019 at 10:25 AM Bruce Evans wrote: > >> Signed kp_offset seems wrong. Apart from it not reaching the top of 64- >> bit address spaces, adding unsigned kp_len to it gives an unsigned type. > > It's appropriate, because in this context, we return page information > including addresses that would be valid pointer references, but are not > included in the core file. Minidumps omit large numbers of physical pages, > so calls to kvm_walk_pages() will generate large numbers of kvm_page > instances that have an offset of -1. off_t was already used internally for the return type of _kvm_pt_find(). .offset is initalized to _kvm_pt_find() using especially large style bugs (most of _kvm_visit_cb() is written in an initalizer). off_t is very inappropriate for small offsets from C pointers. ptrdiff_t would be right for that, except C99 mis-specify by only requiring it to hold up to +-65535, so on perverse implementations with ptrdiff_t = int17_t, subtraction of pointers into an object with more than 65535 elements gives undefined behaviour. In practice, ptrdiff_t is not perversely implemented but system code like vm can't use it because it only covers half the address space. kvm should uses its own type for this so as to not have to worry about signedness problems or the bloat of off_t or the unportability of ptrdiff_t. I rather like APIs which abuse the sign bit for an out of band error value, but this is not very appropriate. time_t is such an API, if it is broken to POSIX spec (not opaque) and is signed (because buggy code expects that). But only bad code compares with -1. The error value is (time_t)-1, as sometimes needed in implementations where time_t is unsigned. Not quite similarly for mmap(). Its error value is MMAP_FAILED which is (void *)-1 in FreeBSD. Both of these values may be in band. -1 is 1 before the Epoch in a time_t. POSIX doesn;t require this to work, but some libraries support it. C99 and POSIX are missing the specifications of errno necessary to detect if an in-band error value is an error for these functions and most others. off_t is signed, so an uncast -1 works right as an error value for lseek(). This is not a feature. -1 is in band for lseek() on devices on 64-bit arches on FreeBSD (this is a POSIX extension. IIRC, POSIX allows anything for devices). The magic -1's for time_t and mmap() are at least documented. struct kvm_page and its member 'offset' and kvm_walk_pages() are undocumented. I think time_t and mmap() were misdesigned originally but were improved a little by specifying a cast or a macro. MMAP_FAILED can't be just (void *)-1 on systems where the compiler objects to this case. Bruce