There is a libunwind test-case that used to work fine but fails with
recent kernels (e.g., 2.6.23-rc2). The problem is exhibited by the
attached test program. It attempts to map the page right after the
register-backing-store area with a no-access page. The mmap call
succeeds, but the kernel incorrectly maps the no-access page not at
the desired location, but at the next page. If I specify MAP_FIXED,
the mmap() call succeeds, but I don't think MAP_FIXED should be
necessary here. Anybody can think of any patches that would explain
this change of behavior?
--david
--
Mosberger Consulting LLC, http://www.mosberger-consulting.com/
#include <ia64intrin.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
uintptr_t
get_bsp (void)
{
#ifdef __INTEL_COMPILER
return __getReg (_IA64_REG_AR_BSP);
#else
return (uintptr_t) __builtin_ia64_bsp ();
#endif
}
int
main (int argc, char **argv)
{
uintptr_t guard_page_addr, bsp = get_bsp ();
size_t page_size = getpagesize ();
char buf[8192];
ssize_t nread;
void *ret;
int fd;
guard_page_addr = (bsp + page_size - 1) & -page_size;
printf("guard_page_addr = 0x%lx\n", (unsigned long) guard_page_addr);
ret = mmap((void *) guard_page_addr, page_size, PROT_NONE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (ret != (void *) guard_page_addr) {
fprintf(stderr, "mmap() returned %p, expected 0x%lx\n",
ret, guard_page_addr);
if (ret == MAP_FAILED)
perror ("mmap");
}
fd = open("/proc/self/maps", O_RDONLY);
nread = read(fd, buf, sizeof(buf));
write(1, buf, nread);
return 0;
}