X-Spam-Check-By: sourceware.org X-Cloudmark-Score: 0.000000 [] X-T2-Posting-ID: dCnToGxhL58ot4EWY8b+QGwMembwLoz1X2yB7MdtIiA= Date: Sat, 26 Nov 2005 22:47:01 +0100 From: Samuel Thibault To: cygwin AT cygwin DOT com Subject: Re: mmap() on 64K aligned address fails Message-ID: <20051126214701.GW5074@bouh.residence.ens-lyon.fr> Mail-Followup-To: cygwin AT cygwin DOT com References: <20051126180331 DOT GI5074 AT bouh DOT residence DOT ens-lyon DOT fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.9i-nntp X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com René Berber, le Sat 26 Nov 2005 15:19:06 -0600, a écrit : > Samuel Thibault wrote: > [snip] > > This seems odd. In the cygwin case, pagesize() would not be sufficient ?? > > No, in windows there is a requirement that mmap uses memory aligned to 64k (the > infamous granularity). Then the result of pagesize() is not sufficiently big: POSIX says that mmap() can return EINVAL if « the address [...] is not a multiple of the page size, or is considered invalid by the implementation ». Well, we could consider non-16-pages-alignment as `considered invalid', but I guess this expression was meant as `not in a mmap()-able area'. > > And anyway, it should rather be > > data2 = (char *) malloc (2 * 16 * pagesize); > > Not only 16 (since it is further 16*pagesize -aligned). > > It's enough to allocate 16 x pagesize to use one page for mmap-ing (like Corinna > said in one message 15/16 pages will not be aligned -- but one will). If you > see the intermediate results I printed, data2 is re-aligned to 64k correctly. Ah oops, didn't pay attention that the mmap was page-sized. 16 pages are still not enough: if malloc() returns 0x0001 for instance, you'll round up that to 16*pagesize, which is out the allocated area. 17 pages are necessary. BTW, I don't understand why using so complicated code: p += (align - ((long) p & (align-1))) & (align-1) Isn't p = ((long) p + (align-1)) & (align-1) both faster (tested) and more readable ? Regards, Samuel -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/