From owner-freebsd-stable@freebsd.org Wed Oct 21 15:18:56 2020 Return-Path: Delivered-To: freebsd-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 3055E44E4DD for ; Wed, 21 Oct 2020 15:18:56 +0000 (UTC) (envelope-from nikolay.kostirya@i11.co) Received: from mx.i11.co (mx.i11.co [159.69.78.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CGYzy5Hz9z4Qdc for ; Wed, 21 Oct 2020 15:18:54 +0000 (UTC) (envelope-from nikolay.kostirya@i11.co) Received: from [91.206.111.188] (helo=localhost) by mx.i11.co with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kVFt6-00060F-O5 for freebsd-stable@freebsd.org; Wed, 21 Oct 2020 15:18:52 +0000 Date: Wed, 21 Oct 2020 18:18:50 +0300 From: Nick Kostirya To: freebsd-stable@freebsd.org Subject: Re: mmap and MAP_STACK Message-ID: <20201021181850.49126cdf@i11.co> In-Reply-To: <20201021141657.GJ2643@kib.kiev.ua> References: <20201021165311.186bd606@i11.co> <20201021141657.GJ2643@kib.kiev.ua> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i386-portbld-freebsd12.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4CGYzy5Hz9z4Qdc X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.61 / 15.00]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[i11.co:s=omicron]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:159.69.78.69]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-0.99)[-0.994]; DKIM_TRACE(0.00)[i11.co:+]; DMARC_POLICY_ALLOW(-0.50)[i11.co,reject]; NEURAL_HAM_SHORT(-0.62)[-0.617]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:159.69.0.0/16, country:DE]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-stable] X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Oct 2020 15:18:56 -0000 On Wed, 21 Oct 2020 17:16:57 +0300 Konstantin Belousov wrote: > On Wed, Oct 21, 2020 at 04:53:11PM +0300, Nick Kostirya via freebsd-stable wrote: > > Hello. > > I have question about mmap. > > > > void *OSMem::AllocateDataArea(size_t &space) > > { > > // Round up to an integral number of pages. > > space = (space + pageSize-1) & ~(pageSize-1); > > int fd = -1; // This value is required by FreeBSD. Linux doesn't care > > int flags = MAP_PRIVATE | MAP_ANON; > > #ifdef MAP_STACK > > if (memUsage == UsageStack) flags |= MAP_STACK; // OpenBSD seems to require this > > #endif > > void *result = mmap(0, space, PROT_READ|PROT_WRITE, flags, fd, 0); > > // Convert MAP_FAILED (-1) into NULL > > if (result == MAP_FAILED) > > return 0; > > return result; > > } > > > > > > When MAP_STACK is used, "insufficient memory" error occurs. > > When MAP_STACK removed, it is all right. > > > > Please tell me why. > Show ktrace/kdump output of the mmap(2) without and with MAP_STACK. > > Or provide a minimal self-contained C source that demonstrates your > issue. kdump with MAP_STACK. 87183 polyimport CALL mmap(0,0x1000,0x3,0x1402,0xffffffff,0,0) 87183 polyimport RET mmap -1 errno 22 Invalid argument kdump without MAP_STACK. 93712 polyimport CALL mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0) 93712 polyimport RET mmap 547053568/0x209b6000