aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2000-09-08 16:14:08 +0000
committerDave Love2000-09-08 16:14:08 +0000
commit8b05edb34e43fd3b6871bc3c313ddc8e0d89e176 (patch)
tree345d93388dff0538889b3f007c454a757626c366
parent53c94d4d993d759322dbd3a880760a04c9b69308 (diff)
downloademacs-8b05edb34e43fd3b6871bc3c313ddc8e0d89e176.tar.gz
emacs-8b05edb34e43fd3b6871bc3c313ddc8e0d89e176.zip
(AC_FUNC_MMAP): Use fixed version from development
autoconf.
-rw-r--r--aclocal.m4146
1 files changed, 146 insertions, 0 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index f10d11c5500..0800cbbddd4 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -355,4 +355,150 @@ AC_DEFUN(AC_SYS_LARGEFILE,
355 fi 355 fi
356 ]) 356 ])
357 357
358undefine([AC_FUNC_MMAP])dnl
359dnl The autoconf 2.13 version loses on OSF, at least,
360dnl by messing up the declaration of malloc.
361AC_DEFUN([AC_FUNC_MMAP],
362[AC_CHECK_HEADERS(stdlib.h unistd.h sys/stat.h)
363AC_CHECK_FUNCS(getpagesize)
364AC_CACHE_CHECK(for working mmap, ac_cv_func_mmap_fixed_mapped,
365[AC_TRY_RUN(
366[/* Thanks to Mike Haertel and Jim Avera for this test.
367 Here is a matrix of mmap possibilities:
368 mmap private not fixed
369 mmap private fixed at somewhere currently unmapped
370 mmap private fixed at somewhere already mapped
371 mmap shared not fixed
372 mmap shared fixed at somewhere currently unmapped
373 mmap shared fixed at somewhere already mapped
374 For private mappings, we should verify that changes cannot be read()
375 back from the file, nor mmap's back from the file at a different
376 address. (There have been systems where private was not correctly
377 implemented like the infamous i386 svr4.0, and systems where the
378 VM page cache was not coherent with the file system buffer cache
379 like early versions of FreeBSD and possibly contemporary NetBSD.)
380 For shared mappings, we should conversely verify that changes get
381 propogated back to all the places they're supposed to be.
382
383 Grep wants private fixed already mapped.
384 The main things grep needs to know about mmap are:
385 * does it exist and is it safe to write into the mmap'd area
386 * how to use it (BSD variants) */
387#include <sys/types.h>
388#include <fcntl.h>
389#include <sys/mman.h>
390
391#if STDC_HEADERS || HAVE_STDLIB_H
392# include <stdlib.h>
393#else
394char *malloc ();
395#endif
396#if HAVE_UNISTD_H
397# include <unistd.h>
398#endif
399#if HAVE_SYS_STAT_H
400# include <sys/stat.h>
401#endif
402
403/* This mess was copied from the GNU getpagesize.h. */
404#if !HAVE_GETPAGESIZE
405/* Assume that all systems that can run configure have sys/param.h. */
406# if !HAVE_SYS_PARAM_H
407# define HAVE_SYS_PARAM_H 1
408# endif
409
410# ifdef _SC_PAGESIZE
411# define getpagesize() sysconf(_SC_PAGESIZE)
412# else /* no _SC_PAGESIZE */
413# if HAVE_SYS_PARAM_H
414# include <sys/param.h>
415# ifdef EXEC_PAGESIZE
416# define getpagesize() EXEC_PAGESIZE
417# else /* no EXEC_PAGESIZE */
418# ifdef NBPG
419# define getpagesize() NBPG * CLSIZE
420# ifndef CLSIZE
421# define CLSIZE 1
422# endif /* no CLSIZE */
423# else /* no NBPG */
424# ifdef NBPC
425# define getpagesize() NBPC
426# else /* no NBPC */
427# ifdef PAGESIZE
428# define getpagesize() PAGESIZE
429# endif /* PAGESIZE */
430# endif /* no NBPC */
431# endif /* no NBPG */
432# endif /* no EXEC_PAGESIZE */
433# else /* no HAVE_SYS_PARAM_H */
434# define getpagesize() 8192 /* punt totally */
435# endif /* no HAVE_SYS_PARAM_H */
436# endif /* no _SC_PAGESIZE */
437
438#endif /* no HAVE_GETPAGESIZE */
439
440int
441main ()
442{
443 char *data, *data2, *data3;
444 int i, pagesize;
445 int fd;
446
447 pagesize = getpagesize ();
448
449 /* First, make a file with some known garbage in it. */
450 data = (char *) malloc (pagesize);
451 if (!data)
452 exit (1);
453 for (i = 0; i < pagesize; ++i)
454 *(data + i) = rand ();
455 umask (0);
456 fd = creat ("conftestmmap", 0600);
457 if (fd < 0)
458 exit (1);
459 if (write (fd, data, pagesize) != pagesize)
460 exit (1);
461 close (fd);
462
463 /* Next, try to mmap the file at a fixed address which already has
464 something else allocated at it. If we can, also make sure that
465 we see the same garbage. */
466 fd = open ("conftestmmap", O_RDWR);
467 if (fd < 0)
468 exit (1);
469 data2 = (char *) malloc (2 * pagesize);
470 if (!data2)
471 exit (1);
472 data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1);
473 if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
474 MAP_PRIVATE | MAP_FIXED, fd, 0L))
475 exit (1);
476 for (i = 0; i < pagesize; ++i)
477 if (*(data + i) != *(data2 + i))
478 exit (1);
479
480 /* Finally, make sure that changes to the mapped area do not
481 percolate back to the file as seen by read(). (This is a bug on
482 some variants of i386 svr4.0.) */
483 for (i = 0; i < pagesize; ++i)
484 *(data2 + i) = *(data2 + i) + 1;
485 data3 = (char *) malloc (pagesize);
486 if (!data3)
487 exit (1);
488 if (read (fd, data3, pagesize) != pagesize)
489 exit (1);
490 for (i = 0; i < pagesize; ++i)
491 if (*(data + i) != *(data3 + i))
492 exit (1);
493 close (fd);
494 unlink ("conftestmmap");
495 exit (0);
496}], ac_cv_func_mmap_fixed_mapped=yes, ac_cv_func_mmap_fixed_mapped=no,
497ac_cv_func_mmap_fixed_mapped=no)])
498if test $ac_cv_func_mmap_fixed_mapped = yes; then
499 AC_DEFINE(HAVE_MMAP, 1,
500 [Define if you have a working `mmap' system call.])
501fi
502])# AC_FUNC_MMAP
503
358) dnl ifelse 504) dnl ifelse