gcc/libmudflap/testsuite/libmudflap.c/pass51-frag.c
Loren J. Rittle ab4daaf234 pass51-frag.c (MAP_FAILED): Define, if not in system header; use it.
2009-09-01  Loren J. Rittle  <ljrittle@acm.org>
	    Andreas Schwab  <schwab@linux-m68k.org>

	* testsuite/libmudflap.c/pass51-frag.c (MAP_FAILED): Define,
	if not in system header; use it.  On FreeBSD, must pass fd==-1
	with MAP_ANON flag.  Correct mmap error check.
	* testsuite/libmudflap.c/fail40-frag.c: Ditto.

Co-Authored-By: Andreas Schwab <schwab@linux-m68k.org>

From-SVN: r151277
2009-09-01 18:10:39 +00:00

45 lines
900 B
C

/* Test object-spanning accesses. This is most conveniently done with
mmap, thus the config.h specificity here. */
#include "../config.h"
#include <unistd.h>
#include <string.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
int main ()
{
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif
#ifdef HAVE_MMAP
void *p;
unsigned pg = getpagesize ();
int rc;
p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
return 1;
memset (p, 0, 4*pg);
rc = munmap (p, pg);
if (rc < 0) return 1;
memset (p+pg, 0, 3*pg);
rc = munmap (p+pg, pg);
if (rc < 0) return 1;
memset (p+2*pg, 0, 2*pg);
rc = munmap (p+2*pg, pg);
if (rc < 0) return 1;
memset (p+3*pg, 0, pg);
rc = munmap (p+3*pg, pg);
if (rc < 0) return 1;
#endif
return 0;
}