This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: Update libmudflap support for FreeBSD
- From: Loren James Rittle <rittle at latour dot labs dot mot dot com>
- To: fche at redhat dot com, ljrittle at motorola dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 20 Aug 2009 18:36:15 -0500 (CDT)
- Subject: Re: PATCH: Update libmudflap support for FreeBSD
>> If someone can confirm that it is portable to pass -1 to mmap for the
>> fd when the MAP_ANON(YMOUS) flag is present, then I can simplify the
>> patch before committing it. [...]
Thanks for the speedy reply.
I also now verified it in mmap(2) for linux (wherein it says fd is
ignored in this case) and inside a random linux src tree (2.6.29 for
android) when providing the stranger OSF/1 system call interface and
other cases. Seems that FreeBSD is the only known platform to specify
that fd must be set to -1 in this case.
Therefore I shall commit the simplier version (ChangeLog as before):
Index: libmudflap/testsuite/libmudflap.c/pass51-frag.c
===================================================================
--- libmudflap/testsuite/libmudflap.c/pass51-frag.c (revision 150973)
+++ libmudflap/testsuite/libmudflap.c/pass51-frag.c (working copy)
@@ -13,14 +13,17 @@
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
+#ifndef MAP_FAILED
+#define MAP_FAILED NULL
+#endif
#ifdef HAVE_MMAP
void *p;
unsigned pg = getpagesize ();
int rc;
p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
- if (p == NULL)
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (p == MAP_FAILED)
return 1;
memset (p, 0, 4*pg);
Index: libmudflap/testsuite/libmudflap.c/fail40-frag.c
===================================================================
--- libmudflap/testsuite/libmudflap.c/fail40-frag.c (revision 150973)
+++ libmudflap/testsuite/libmudflap.c/fail40-frag.c (working copy)
@@ -14,6 +14,9 @@
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
+#ifndef MAP_FAILED
+#define MAP_FAILED NULL
+#endif
#ifdef HAVE_MMAP
volatile unsigned char *p;
unsigned num = getpagesize ();
@@ -23,8 +26,8 @@
/* Get a bit of usable address space. We really want an 2**N+1-sized object,
so the low/high addresses wrap when hashed into the lookup cache. So we
will manually unregister the entire mmap, then re-register a slice. */
- p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
- if (p == NULL)
+ p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (p == MAP_FAILED)
return 1;
/* Now unregister it, as if munmap was called. But don't actually munmap, so
we can write into the memory. */