|
From: <sv...@va...> - 2009-03-23 08:36:42
|
Author: sewardj
Date: 2009-03-23 08:36:33 +0000 (Mon, 23 Mar 2009)
New Revision: 9491
Log:
Generate a proper invalid page to jump to, rather than assuming
0xE000000 is invalid.
Modified:
branches/DARWIN/memcheck/tests/badjump.c
Modified: branches/DARWIN/memcheck/tests/badjump.c
===================================================================
--- branches/DARWIN/memcheck/tests/badjump.c 2009-03-22 13:28:44 UTC (rev 9490)
+++ branches/DARWIN/memcheck/tests/badjump.c 2009-03-23 08:36:33 UTC (rev 9491)
@@ -1,18 +1,38 @@
-
+char* get_bad_place ( void );
int main ( void )
{
#if defined(__powerpc64__) || defined(_AIX)
/* on ppc64-linux, a function pointer points to a function
descriptor, not to the function's entry point. Hence to get
- uniform behaviour on all supported targets - a jump to 0xE000000
- - the following is needed. */
+ uniform behaviour on all supported targets - a jump to an
+ unmapped page - the following is needed. */
unsigned long long int fake_fndescr[3];
- fake_fndescr[0] = 0xE000000;
+ fake_fndescr[0] = (unsigned long long int)get_bad_place();
fake_fndescr[1] = 0;
fake_fndescr[2] = 0;
return ((int(*)(void)) fake_fndescr) ();
#else
- char* p = (char*)0xE000000;
+ char* p = get_bad_place();
return ((int(*)(void)) p) ();
#endif
}
+
+#include <sys/mman.h>
+#include <assert.h>
+#include <unistd.h>
+
+/* map a page, then unmap it, then return that address. That
+ guarantees to give an address which will fault when accessed,
+ without making any assumptions about the layout of the address
+ space. */
+
+char* get_bad_place ( void )
+{
+ long pagesz = sysconf(_SC_PAGE_SIZE);
+ assert(pagesz == 4096 || pagesz == 65536);
+ void* ptr = mmap(0, pagesz, PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
+ assert(ptr != (void*)-1);
+ int r = munmap(ptr, pagesz);
+ assert(r == 0);
+ return ptr;
+}
|