Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Date: Thu, 3 Jul 2003 22:53:36 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: mmap() and gcc precompiled headers Message-ID: <20030703205336.GA9643@cygbert.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <3F0476DE DOT 9010103 AT agilent DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F0476DE.9010103@agilent.com> User-Agent: Mutt/1.4.1i On Thu, Jul 03, 2003 at 11:33:02AM -0700, Earl Chew wrote: > Corinna Vinschen wrote: > >On Thu, Jul 03, 2003 at 10:19:42AM -0400, Christopher Faylor wrote: > >>On Thu, Jul 03, 2003 at 11:47:28AM +0200, Corinna Vinschen wrote: > >>>Do you mean something like this: > >>> > >>> If addr is given, check if it's 64K aligned. If not, align and > >>> raise the memory requirement accordingly. Call MapViewOfFileEx > >>> with the aligned address. If it works, return the addr given as > >>> parameter, otherwise return MapViewOfFileEx(NULL). > > Patching gcc to use MAP_FIXED is possible, but I'm not sure that > it's really necessary, and there's another complication. IMO it's not a question of necessity but of correctness. > preferred_base = mmap (NULL, size, > PROT_READ | PROT_WRITE, MAP_PRIVATE, > f, offset); > > munmap(preferred_base, size); > > newbase = mmap (preferred_base, size, > PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, > f, offset); > > There's a good chance that this fails because preferred_base > is the fudged value from MapViewOfFileEx() and is no longer 64k > aligned (only 4k aligned), and MAP_FIXED contains a check > to ensure that the address is 64k aligned :-( It depends on offset being 0 or not. Is gcc using offset !=0? > So a patch to gcc to use MAP_FIXED would also require somehow > making gcc aware of the 64k alignment. No chance since it can't actually control the return value from mmap. So I guess we should actually try it with your suggested approach. > If addr is given, perform the 64k fixup. Essentially this means > undoing the mmap64() fudge that might have been done previously: > > caddr_t ret = rec->get_address () + (off - gran_off); > > (Adjust the size appropriately too.) Adjusting the size?!? We're just potentially moving the mapping addr, this shouldn't have any influence to len resp. gran_len. > In other words, addr -= (off - gran_off). This address should > now be 64k aligned. Error if it isn't. > > Use this address when calling MapViewOfFileEx(). If the call fails > and MAP_FIXED is not set, then try again with addr = 0. Yes, that's what I mentioned in my first reply. I think it's worth a try. I've checked in a patch. I've tested it and it looks pretty good. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:cygwin AT cygwin DOT com Red Hat, Inc. -- 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/