This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fixincl mmap problem on Solaris


On Tue, Sep 05, 2000 at 10:08:50AM -0700, Bruce Korb wrote:
> Zack Weinberg wrote:
> > 
> >      The mmap() function allows [pa, pa + len) to  extend  beyond
> >      the  end  of  the object, ...
> >      [but] Any reference  to  addresses  beyond
> >      the  end of the object, however, will result in the delivery
> >      of a SIGBUS or SIGSEGV signal.  In other words, mmap()  can-
> >      not be used to implicitly extend the length of files.
> 
> Except that this is utter nonsense.  What is the possible point
> of extending the map beyond the end of the object if references
> to such addresses result in an addressing exception?

I'll only say that every mmap() implementation I have ever seen does
exactly this.

> > My suggestion would be to notice when the file size is an exact
> > multiple of the page size, and map a page of /dev/zero right after it
> > using MAP_FIXED.  If that fails, punt and read the file with read(2).
> 
> Way too much work.  Instead:
> 
>   data_map_size = stbf.st_size;
>   ...
> 
>   if ((data_map_size & (PAGESIZE-1)) == 0)
>      res = BAD_ADDR
>   else
>      res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
>                         MAP_PRIVATE, data_map_fd, 0);
>   if (res == (char*)BAD_ADDR)
>     {
>       curr_data_mapped = BOOL_FALSE;
>       res = load_file_data ( fdopen (data_map_fd, "r"));
>     }

Sure, that is indeed simpler.

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]