Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Aug 2001 18:51:02 -0400 (EDT)
From:      Mikhail Teterin <mi@aldan.algebra.com>
To:        David Greenman <dg@FreeBSD.org>
Cc:        current@FreeBSD.org, ports@FreeBSD.org
Subject:   Re: cvs commit: src/lib/libc/sys mmap.2
Message-ID:  <200108232251.f7NMp3v43100@aldan.algebra.com>
In-Reply-To: <200108232239.f7NMdrM68937@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> dg          2001/08/23 15:39:53 PDT
> 
>   Modified files:
>     lib/libc/sys         mmap.2 
>   Log:
>   Killed reference to MAP_INHERIT which is not supported in FreeBSD.

BTW, GNU  Autoconf's AC_FUNC_MMAP macro  fails on -current,  which leads
the configure  (in ImageMagick,  for example)  to a  mistaken conclusion
there is no mmap support :-( Anybody cares to take a closer look?

Here is what they are doing (from config.log). Thanks,

	-mi

[...]
configure:8380: cc -o conftest -O -pipe -march=i686   -Wall -I/opt/include/libxml2 -I/opt/include/libxml2/libxml -I/opt/include/freetype2 -I/opt/include/freetype2 -I/usr/local/include -I/opt/include  -I/opt/include -I/opt/include/X11 -L/opt/lib -L/opt/lib  -L/opt/lib  -L/opt/lib conftest.c -lwmf -lXpm -lxml2 -ljbig -ltiff -lfreetype -ljpeg -lpng -llcms -lfpx -ldpstk -ldps -lXext -lXt  -lSM -lICE -lX11  -lbz2 -lz -lm -L/usr/local/lib 1>&5
configure: In function `main':
configure:8321: warning: implicit declaration of function `getpagesize'
configure:8330: warning: implicit declaration of function `rand'
configure:8331: warning: implicit declaration of function `umask'
configure:8335: warning: implicit declaration of function `write'
configure:8337: warning: implicit declaration of function `close'
configure:8368: warning: implicit declaration of function `read'
configure:8374: warning: implicit declaration of function `unlink'
configure: failed program was:
#line 8240 "configure"
#include "confdefs.h"

/* Thanks to Mike Haertel and Jim Avera for this test.
   Here is a matrix of mmap possibilities:
	mmap private not fixed
	mmap private fixed at somewhere currently unmapped
	mmap private fixed at somewhere already mapped
	mmap shared not fixed
	mmap shared fixed at somewhere currently unmapped
	mmap shared fixed at somewhere already mapped
   For private mappings, we should verify that changes cannot be read()
   back from the file, nor mmap's back from the file at a different
   address.  (There have been systems where private was not correctly
   implemented like the infamous i386 svr4.0, and systems where the
   VM page cache was not coherent with the filesystem buffer cache
   like early versions of FreeBSD and possibly contemporary NetBSD.)
   For shared mappings, we should conversely verify that changes get
   propogated back to all the places they're supposed to be.

   Grep wants private fixed already mapped.
   The main things grep needs to know about mmap are:
   * does it exist and is it safe to write into the mmap'd area
   * how to use it (BSD variants)  */
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>

/* This mess was copied from the GNU getpagesize.h.  */
#ifndef HAVE_GETPAGESIZE
# ifdef HAVE_UNISTD_H
#  include <unistd.h>
# endif

/* Assume that all systems that can run configure have sys/param.h.  */
# ifndef HAVE_SYS_PARAM_H
#  define HAVE_SYS_PARAM_H 1
# endif

# ifdef _SC_PAGESIZE
#  define getpagesize() sysconf(_SC_PAGESIZE)
# else /* no _SC_PAGESIZE */
#  ifdef HAVE_SYS_PARAM_H
#   include <sys/param.h>
#   ifdef EXEC_PAGESIZE
#    define getpagesize() EXEC_PAGESIZE
#   else /* no EXEC_PAGESIZE */
#    ifdef NBPG
#     define getpagesize() NBPG * CLSIZE
#     ifndef CLSIZE
#      define CLSIZE 1
#     endif /* no CLSIZE */
#    else /* no NBPG */
#     ifdef NBPC
#      define getpagesize() NBPC
#     else /* no NBPC */
#      ifdef PAGESIZE
#       define getpagesize() PAGESIZE
#      endif /* PAGESIZE */
#     endif /* no NBPC */
#    endif /* no NBPG */
#   endif /* no EXEC_PAGESIZE */
#  else /* no HAVE_SYS_PARAM_H */
#   define getpagesize() 8192	/* punt totally */
#  endif /* no HAVE_SYS_PARAM_H */
# endif /* no _SC_PAGESIZE */

#endif /* no HAVE_GETPAGESIZE */

#ifdef __cplusplus
extern "C" { void *malloc(unsigned); }
#else
char *malloc();
#endif

int
main()
{
	char *data, *data2, *data3;
	int i, pagesize;
	int fd;

	pagesize = getpagesize();

	/*
	 * First, make a file with some known garbage in it.
	 */
	data = malloc(pagesize);
	if (!data)
		exit(1);
	for (i = 0; i < pagesize; ++i)
		*(data + i) = rand();
	umask(0);
	fd = creat("conftestmmap", 0600);
	if (fd < 0)
		exit(1);
	if (write(fd, data, pagesize) != pagesize)
		exit(1);
	close(fd);

	/*
	 * Next, try to mmap the file at a fixed address which
	 * already has something else allocated at it.  If we can,
	 * also make sure that we see the same garbage.
	 */
	fd = open("conftestmmap", O_RDWR);
	if (fd < 0)
		exit(1);
	data2 = malloc(2 * pagesize);
	if (!data2)
		exit(1);
	data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1);
	if (data2 != mmap(data2, pagesize, PROT_READ | PROT_WRITE,
	    MAP_PRIVATE | MAP_FIXED, fd, 0L))
		exit(1);
	for (i = 0; i < pagesize; ++i)
		if (*(data + i) != *(data2 + i))
			exit(1);

	/*
	 * Finally, make sure that changes to the mapped area
	 * do not percolate back to the file as seen by read().
	 * (This is a bug on some variants of i386 svr4.0.)
	 */
	for (i = 0; i < pagesize; ++i)
		*(data2 + i) = *(data2 + i) + 1;
	data3 = malloc(pagesize);
	if (!data3)
		exit(1);
	if (read(fd, data3, pagesize) != pagesize)
		exit(1);
	for (i = 0; i < pagesize; ++i)
		if (*(data + i) != *(data3 + i))
			exit(1);
	close(fd);
	unlink("conftestmmap");
	exit(0);
}
[...]

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108232251.f7NMp3v43100>