mmapping of /dev/zero always fails on darwin

2005-09-09 Thread Peter O'Gorman

Hi,
I just tried to use cvs-1.12.12 on Mac OS X, and it always dies. I traced 
the problem to pagealign_alloc.c, which attempts to mmap /dev/zero.



As you can see from this little snippet of gcc configure, you can't mmap 
/dev/zero on darwin.


   AC_CACHE_CHECK([whether mmap from /dev/zero works],
  gcc_cv_func_mmap_dev_zero,
  [# Add a system to this blacklist if it has mmap() but /dev/zero
   # does not exist, or if mmapping /dev/zero does not give anonymous
   # zeroed pages with both the following properties:
   # 1. If you map N consecutive pages in with one call, and then
   #unmap any subset of those pages, the pages that were not
   #explicitly unmapped remain accessible.
   # 2. If you map two adjacent blocks of memory and then unmap them
   #both at once, they must both go away.
   # Systems known to be in this category are Windows (all variants),
   # VMS, and Darwin.
   case "$host_os" in
 vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
gcc_cv_func_mmap_dev_zero=no ;;
 *)
gcc_cv_func_mmap_dev_zero=yes;;
   esac])

Thanks,
Peter


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: mmapping of /dev/zero always fails on darwin

2005-09-12 Thread Derek Price
Peter O'Gorman wrote:

> As you can see from this little snippet of gcc configure, you can't
> mmap /dev/zero on darwin.
>
>AC_CACHE_CHECK([whether mmap from /dev/zero works],
>   gcc_cv_func_mmap_dev_zero,
>   [# Add a system to this blacklist if it has mmap() but /dev/zero
># does not exist, or if mmapping /dev/zero does not give anonymous
># zeroed pages with both the following properties:
># 1. If you map N consecutive pages in with one call, and then
>#unmap any subset of those pages, the pages that were not
>#explicitly unmapped remain accessible.
># 2. If you map two adjacent blocks of memory and then unmap them
>#both at once, they must both go away.
># Systems known to be in this category are Windows (all variants),
># VMS, and Darwin.


I don't suppose you could come up with a configure test or a short C
program that fails to compile (preferrably) or run (if necessary) to
spot this, short of actually switching on the system name or something
similar?

Regards,

Derek

-- 
Derek R. Price
CVS Solutions Architect
Ximbiot 
v: +1 717.579.6168
f: +1 717.234.3125





___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: mmapping of /dev/zero always fails on darwin

2005-09-12 Thread Derek Price
Peter O'Gorman wrote:

> The test would have to be a run test, which would mean having a
> cross-compile alternative switching on the system name (this is why
> gcc switches on name).


All,

Generally, I choose to be pessimistic about test failures when
cross-compiling.  Anyone have an opinion about whether I should be
pessimistic always or just when the target system name matches gcc's
list of systems which fail this test?

> Hope this helps,


It does.  Thanks Peter.

Regards,

Derek

-- 
Derek R. Price
CVS Solutions Architect
Ximbiot 
v: +1 717.579.6168
f: +1 717.234.3125





___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: mmapping of /dev/zero always fails on darwin

2005-09-12 Thread Peter O'Gorman

Derek Price wrote:



I don't suppose you could come up with a configure test or a short C
program that fails to compile (preferrably) or run (if necessary) to
spot this, short of actually switching on the system name or something
similar?


The test would have to be a run test, which would mean having a 
cross-compile alternative switching on the system name (this is why gcc 
switches on name).


Just doing the same thing as gnulib does will show the failure:

int main(){
void * address = NULL;
static int fd =-1;
int ret = 0;
fd = open ("/dev/zero",O_RDONLY,666);
ret = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_FILE | 
MAP_PRIVATE, fd, 0);

if (ret != MAP_FAILED) return 0;
return 1;
}

Hope this helps,
Peter


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: mmapping of /dev/zero always fails on darwin

2005-09-14 Thread Bruno Haible
Derek Price wrote:
> Generally, I choose to be pessimistic about test failures when
> cross-compiling.  Anyone have an opinion about whether I should be
> pessimistic always or just when the target system name matches gcc's
> list of systems which fail this test?

Generally, I try to use this approach:
  1) Attempt to determine the presence of a feature/bug precisely, by running
 a test program if needed.
  2) When cross-compiling, try to approximate the decision through some
 #ifdefs or   case $host ... test.
 Don't be pessimistic always.

Reason for 1): This gives an incent to the vendors to add the features or
fix the bugs. If you always exclude some feature on, say, HP-UX, you will
not take advantage if it's fixed in HP-UX 12.

Reason for 2): Cross-compilation is quite frequent in the Linux camp.
(That was actually the original market of cygnus.com.) Don't penalize them.
On the other hand, you probably don't need to care about people cross-
compiling to NetBSD or AIX - hardly anyone does this.

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] mmapping of /dev/zero always fails on darwin

2005-09-13 Thread Bruno Haible
Peter O'Gorman wrote:
> As you can see from this little snippet of gcc configure, you can't mmap 
> /dev/zero on darwin.
> 
> AC_CACHE_CHECK([whether mmap from /dev/zero works],
>gcc_cv_func_mmap_dev_zero,
>[# Add a system to this blacklist if it has mmap() but /dev/zero
> # does not exist, or if mmapping /dev/zero does not give anonymous
> # zeroed pages with both the following properties:
> # 1. If you map N consecutive pages in with one call, and then
> #unmap any subset of those pages, the pages that were not
> #explicitly unmapped remain accessible.
> # 2. If you map two adjacent blocks of memory and then unmap them
> #both at once, they must both go away.
> # Systems known to be in this category are Windows (all variants),
> # VMS, and Darwin.
> case "$host_os" in
>   vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
>  gcc_cv_func_mmap_dev_zero=no ;;
>   *)
>  gcc_cv_func_mmap_dev_zero=yes;;
> esac])

But gnulib's pagealign_alloc is not doing case 1 and not doing case 2.
It calls mmap() on N pages at once, and then ultimately munmap() on the
same N pages at once.

Also, GNU clisp uses mmap() with more complicated cases than this, including
mprotect() and partial munmap()s, and it works fine on Darwin.

> I just tried to use cvs-1.12.12 on Mac OS X, and it always dies. I traced 
> the problem to pagealign_alloc.c, which attempts to mmap /dev/zero.

How did you track that down to pagealign_alloc.c?

I'd rather guess that mmap() on MacOS X works fine but either
  - pagealign_alloc.c has a bug, or
  - CVS has some memory related bugs, and you don't happen to see them
when pagealign_alloc uses malloc() instead of mmap() - because of the
way malloc() internally does its bookkeeping.

Can you exclude these?

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: mmapping of /dev/zero always fails on darwin

2005-09-13 Thread Bruno Haible
Peter O'Gorman wrote:
> Just doing the same thing as gnulib does will show the failure:
>
> int main(){
>  void * address = NULL;
>  static int fd =-1;
>  int ret = 0;
>  fd = open ("/dev/zero",O_RDONLY,666);
>  ret = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_FILE | 
> MAP_PRIVATE, fd, 0);
>  if (ret != MAP_FAILED) return 0;
> return 1;
> }

Are you sure that this is what gnulib does? Darwin's  defines
MAP_ANON, then gnulib's m4/mmap-anon.m4 macro ought to add
  #define MAP_ANONYMOUS MAP_ANON
  #define HAVE_MAP_ANONYMOUS 1
to config.h, and then lib/pagealign_alloc.c should be doing

  mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

Is pagealign_alloc.c doing this or not?

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: mmapping of /dev/zero always fails on darwin

2005-09-13 Thread Derek Price
Peter O'Gorman wrote:

> Peter O'Gorman wrote:
>
>> Looks like the cvs folks need to update their gnulib.
>
>
> Of course, they have done this, and I feel silly.


Yes, they have.  :)  That fix should be released with 1.12.13, which
shouldn't be very far away.

Regards,

Derek

-- 
Derek R. Price
CVS Solutions Architect
Ximbiot 
v: +1 717.579.6168
f: +1 717.234.3125





___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: mmapping of /dev/zero always fails on darwin

2005-09-13 Thread Peter O'Gorman

Bruno Haible wrote:

Are you sure that this is what gnulib does? Darwin's  defines
MAP_ANON, then gnulib's m4/mmap-anon.m4 macro ought to add
  #define MAP_ANONYMOUS MAP_ANON
  #define HAVE_MAP_ANONYMOUS 1
to config.h, and then lib/pagealign_alloc.c should be doing

  mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

Is pagealign_alloc.c doing this or not?


Ah ha!

Looks like the cvs folks need to update their gnulib.



Sorry for the noise,
Peter



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: mmapping of /dev/zero always fails on darwin

2005-09-13 Thread Peter O'Gorman

Peter O'Gorman wrote:

Looks like the cvs folks need to update their gnulib.


Of course, they have done this, and I feel silly.

Peter


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib