This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


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

RE: New autoconf tests - let's try this again


Results on Dynix/ptx 4.4.8:
---------------------------------------------------------------------------
No mmap from /dev/zero.
No mmap with MAP_ANON(YMOUS).
-rw-rw----   1 swbxc01  swift2        147 Jan 10 10:08 test1a.l
-rw-rw----   1 swbxc01  swift2        147 Jan 10 10:08 test1z.l
DYNIX/ptx hwcmcr1 4.0 V4.4.8 i386
----------------------------------------------------------------------------
/usr/home/swbxc01/mmt26444>cat test1z.l
/var/tmp/ccoZcvYa.o: In function `main':
/var/tmp/ccoZcvYa.o(.text+0xa7): undefined reference to `getpagesize'
collect2: ld returned 1 exit status
-----------------------------------------
/usr/home/swbxc01/mmt26444>cat test1a.l
/var/tmp/ccX9Ja3b.o: In function `main':
/var/tmp/ccX9Ja3b.o(.text+0x4f): undefined reference to `getpagesize'
collect2: ld returned 1 exit status
----------------------------------------------------------------------------
-
The above error is probably because in Dynix/ptx, to use syscalls, you need
to
use '-lseq'. Here the extract from 'man getpagesize':
----------------------------------------------------------------------------
---
NAME
          getpagesize - get system page size

     SYNOPSIS
          #include <unistd.h>
          int getpagesize(void);

     DESCRIPTION
          getpagesize returns the number of bytes in a page.  Page
          granularity is the granularity of many of the memory
          management calls.

          The page size is a system page size and may not be the same
          as the underlying hardware page size.

     SEE ALSO
          brk(2), getrlimit(2), mmap(2), mprotect(2), munmap(2),
          msync(2), sysconf(2), sbrk(2)

     NOTES
          This is a Sequent library routine.  To use it, specify the
          -lseq option to link with the Sequent library.  Since this
          is a Sequent extension, code using this routine may not be
          portable to other systems.
--------------------------------------------------------------------

Hope this helps.
Biswa.


> -----Original Message-----
> From: Zack Weinberg [mailto:zackw@stanford.edu]
> Sent: 09 January 2001 17:50
> To: gcc@gcc.gnu.org
> Cc: cygwin@sources.redhat.com
> Subject: New autoconf tests - let's try this again
> 
> 
> The previous generation of this test script got a bunch of spurious
> failures (code 7) because it didn't try hard enough to get two
> consecutive maps allocated next to each other.  This one should work
> better - I still can't get a success on HP/UX, though (clues
> appreciated).
> 
> If you tried the previous version of this script and got "buggy"
> reports, I'd appreciate it if you would try this one.
> 
> [Russ - SGI cc doesn't work on the raptors.]
> 
> zw
> 
> #! /bin/sh
> 
> mkdir mmt$$ || exit 1
> cd mmt$$ || exit 1
> 
> if test -z "$CC"; then
>   if command -v cc >/dev/null 2>&1; then
>     CC=cc
>   elif command -v gcc >/dev/null 2>&1; then
>     CC=gcc
>   else
>     echo "Cannot find compiler, set CC in environment"
>     exit 1
>   fi
> fi
> 
> cat >testcore.h <<EOF
> /* Test by Richard Henderson and Alexandre Oliva.
>    Check whether mmap MAP_ANONYMOUS or mmap from /dev/zero works. */
> #include <sys/types.h>
> #include <sys/param.h>
> #include <sys/mman.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <stdio.h>
> 
> #ifndef MAP_ANON
> # ifdef MAP_ANONYMOUS
> #  define MAP_ANON MAP_ANONYMOUS
> # else
> #  define MAP_ANON 0
> # endif
> #endif
> 
> #ifndef MAP_FAILED
> # define MAP_FAILED -1
> #endif
> 
> #undef perror_exit
> #define perror_exit(str, val) \
>   do { perror(str); exit(val); } while (0)
> 
> static char *
> anonmap (size, loc)
>      size_t size;
>      char *loc;
> {
>   int flags;
> #ifndef USE_MAP_ANON
>   static int devzero = -1;
> #endif
> 
>   if (loc)
>     flags = MAP_PRIVATE|MAP_FIXED;
>   else
>     flags = MAP_PRIVATE;
> 
> #ifdef USE_MAP_ANON
>   return (char *) mmap (loc, size, PROT_READ|PROT_WRITE, 
> flags|MAP_ANON, -1, 0);
> #else
>   if (devzero == -1)
>     {
>       devzero = open ("/dev/zero", O_RDWR);
>       if (devzero < 0)
> 	perror_exit ("open /dev/zero", 64);
>     }
>   return (char *) mmap (loc, size, PROT_READ|PROT_WRITE, 
> flags, devzero, 0);
> #endif
> }
> EOF
> 
> cat >test1.c <<EOF
> #include "testcore.h"
> 
> int
> main()
> {
>   int pg = getpagesize ();
>   char *x = anonmap (pg, 0);
> 
>   if (x == (char *) MAP_FAILED)
>     perror_exit("mmap", 1);
> 
>   *(int *)x += 1;
> 
>   if (munmap(x, pg) < 0)
>     perror_exit("munmap", 2);
> 
>   exit(0);
> }
> EOF
> 
> if $CC test1.c -o test1z.x >test1z.l 2>&1 && ./test1z.x 
> >>test1z.l 2>&1
> then echo "Have mmap from /dev/zero."
>      have_dev_zero=y
> else echo "No mmap from /dev/zero."
> fi
> 
> if $CC test1.c -DUSE_MAP_ANON -o test1a.x >test1a.l 2>&1 \
>     && ./test1a.x >>test1a.l 2>&1
> then echo "Have mmap with MAP_ANON(YMOUS)."
>      have_map_anon=y
> else echo "No mmap with MAP_ANON(YMOUS)."
> fi
> 
> cat >test2.c <<EOF
> #include "testcore.h"
> #include <signal.h>
> #include <setjmp.h>
> 
> /* Some versions of cygwin mmap require that munmap is called with the
>    same parameters as mmap.  GCC expects that this is not the case.
>    Test for various forms of this problem.  Warning - icky 
> signal games.  */
> static jmp_buf r;
> static size_t pg;
> 
> static void
> sigsegv (unused)
>      int unused;
> {
>   longjmp (r, 1);
> }
> 
> /* 1. If we map a 2-page region and unmap its second page, 
> the first page
>    must remain.  */
> void
> test_1 ()
> {
>   char *x = anonmap (pg * 2, 0);
>   if (x == (char *)MAP_FAILED)
>     perror_exit ("test 1 mmap", 1);
> 
>   signal (SIGSEGV, sigsegv);
>   if (setjmp (r))
>     perror_exit ("test 1 fault", 2);
> 
>   x[0] = 1;
>   x[pg] = 1;
> 
>   munmap (x + pg, pg);
>   x[0] = 2;
> 
>   if (setjmp (r))
>     {
>       munmap (x, pg);
>       return;
>     }
>   x[pg] = 1;
>   perror_exit ("test 1 no fault", 3);
> }
> 
> /* 2. If we map a 2-page region and unmap its first page, the second
>    page must remain.  */
> void
> test_2 ()
> {
>   char *x = anonmap (pg * 2, 0);
>   if (x == (char *)MAP_FAILED)
>     perror_exit ("test 2 mmap", 4);
> 
>   signal (SIGSEGV, sigsegv);
>   if (setjmp (r))
>     perror_exit ("test 2 fault", 5);
> 
>   x[0] = 1;
>   x[pg] = 1;
> 
>   munmap (x, pg);
>   x[pg] = 2;
> 
>   if (setjmp (r))
>     {
>       munmap (x + pg, pg);
>       return;
>     }
>   x[0] = 1;
>   perror_exit ("test 2 no fault", 6);
> }
> 
> /* 3. If we map two consecutive 1-page regions and unmap them 
> both with
>    one munmap, both must go away.  */
> 
> void
> test_3 ()
> {
>   char *x, *y;
>   x = anonmap (pg, 0);
>   if (x == (char *)MAP_FAILED)
>     perror_exit ("test 3 mmap 1", 7);
>   y = anonmap (pg, x+pg);
>   if (y == (char *)MAP_FAILED || x + pg != y)
>     perror_exit ("test 3 mmap 2", 7);
> 
>   signal (SIGSEGV, sigsegv);
>   if (setjmp (r))
>     perror_exit ("test 3 fault", 8);
> 
>   x[0] = 1;
>   x[pg] = 1;
> 
>   munmap (x, pg * 2);
> 
>   if (setjmp (r) == 0)
>     {
>       x[0] = 1;
>       perror_exit ("test 3 no fault 1", 9);
>     }
>   
>   signal (SIGSEGV, sigsegv);
>   if (setjmp (r) == 0)
>     {
>       x[pg] = 1;
>       perror_exit ("test 3 no fault 2", 10);
>     }
> }
> 
> 
> int
> main ()
> {
>   pg = getpagesize ();
> 
>   test_1();
>   test_2();
>   test_3();
> 
>   exit(0);
> }
> EOF
> 
> if test -n "$have_dev_zero"; then
>   if $CC test2.c  -o test2z.x >test2z.l 2>&1 \
>      && ./test2z.x >>test2z.l 2>&1
>   then echo "mmap of /dev/zero works."
>   else echo "mmap of /dev/zero is buggy. ($?)"
>   fi
> fi
> 
> if test -n "$have_map_anon"; then 
>   if $CC test2.c -DUSE_MAP_ANON -o test2a.x >test2a.l 2>&1 \
>      && ./test2a.x >>test2a.l 2>&1
>   then echo "mmap with MAP_ANON(YMOUS) works."
>   else echo "mmap with MAP_ANON(YMOUS) is buggy. ($?)"
>   fi
> fi
> 
> ls -l *.l
> uname -a
> 

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


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