2 % (c) The AQUA Project, Glasgow University, 1995
4 %************************************************************************
6 \section[mprotect.lc]{Memory Protection}
8 %************************************************************************
10 Is @mprotect@ POSIX now?
13 #if STACK_CHECK_BY_PAGE_FAULT
15 /* #define STK_CHK_DEBUG */
19 # ifdef HAVE_SYS_TYPES_H
20 # include <sys/types.h>
23 # ifdef HAVE_SYS_MMAN_H
24 # include <sys/mman.h>
27 # if defined(_SC_PAGE_SIZE) && !defined(_SC_PAGESIZE)
28 /* Death to HP-UX. What are standards for, anyway??? */
29 # define _SC_PAGESIZE _SC_PAGE_SIZE
32 # if defined(_SC_PAGESIZE)
33 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
35 # if defined(HAVE_GETPAGESIZE)
36 # define GETPAGESIZE() getpagesize()
38 # if defined(linux_TARGET_OS) || defined(linuxaout_TARGET_OS)
39 # /* it has it, but it is in BSD land; easier to just say so */
40 # define GETPAGESIZE() getpagesize()
47 #if defined(sunos4_TARGET_OS)
48 extern int getpagesize PROTO((void));
49 extern int mprotect PROTO((caddr_t, size_t, int));
52 /* Needed for FreeBSD (SDM, 96/03) */
58 unmapMiddleStackPage(addr_, size)
59 char * /*caddr_t*/ addr_;
62 int pagesize = GETPAGESIZE();
64 caddr_t middle = (caddr_t) (((W_) (addr + size / 2)) / pagesize * pagesize);
67 fprintf(stderr, "pagesize: %x\nstack start: %08lx\nstack size: %08lx\nstack middle: %08lx\n",
68 pagesize, addr, size, middle);
71 if (middle < addr || middle + pagesize > addr + size) {
72 fprintf(stderr, "Stack too small; stack overflow trap disabled.\n");
75 if (mprotect(middle, pagesize, PROT_NONE) == -1) {
79 if (install_segv_handler()) {
80 fprintf(stderr, "Can't install SIGSEGV handler for stack overflow check.\n");
85 #endif /* STACK_CHECK_BY_PAGE_FAULT */