X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fruntime%2Fstorage%2Fmprotect.lc;h=1cef887330d5242dd3999b749d8b27f8102f06c5;hb=967cc47f37cb93a5e2b6df7822c9a646f0428247;hp=dabf3c4180e9a52e625eaa73f2b3668b33d04834;hpb=769ce8e72ae626356ce57162b7ff448c0ef7e700;p=ghc-hetmet.git diff --git a/ghc/runtime/storage/mprotect.lc b/ghc/runtime/storage/mprotect.lc index dabf3c4..1cef887 100644 --- a/ghc/runtime/storage/mprotect.lc +++ b/ghc/runtime/storage/mprotect.lc @@ -7,7 +7,7 @@ %* * %************************************************************************ -Is @mprotect@ POSIX now? +Is @mprotect@ POSIX now? [Yup, POSIX.4 -- sof] \begin{code} #if STACK_CHECK_BY_PAGE_FAULT @@ -45,23 +45,35 @@ Is @mprotect@ POSIX now? # endif #if defined(sunos4_TARGET_OS) -extern int getpagesize PROTO((void)); -extern int mprotect PROTO((caddr_t, size_t, int)); +int getpagesize PROTO((void)); +int mprotect PROTO((caddr_t, size_t, int)); #endif +#if defined(aix_TARGET_OS) +/* PROT_NONE doesn't work on aix, PROT_READ works and should suit the job */ +#define PROT_NONE PROT_READ +#endif + /* Needed for FreeBSD (SDM, 96/03) */ #ifndef PROT_NONE #define PROT_NONE 0 #endif +/* For VirtualProtect() and its flags */ +#if defined(cygwin32_TARGET_OS) +#include +#endif + void -unmapMiddleStackPage(addr_, size) -char * /*caddr_t*/ addr_; +unmapMiddleStackPage(addr, size) +char * /*caddr_t*/ addr; int size; { int pagesize = GETPAGESIZE(); - caddr_t addr = addr_; - caddr_t middle = (caddr_t) (((W_) (addr + size / 2)) / pagesize * pagesize); + char * middle = (char *) (((W_) (addr + size / 2)) / pagesize * pagesize); +#if defined(cygwin32_TARGET_OS) + unsigned int old_prot; +#endif # ifdef STK_CHK_DEBUG fprintf(stderr, "pagesize: %x\nstack start: %08lx\nstack size: %08lx\nstack middle: %08lx\n", @@ -72,7 +84,14 @@ int size; fprintf(stderr, "Stack too small; stack overflow trap disabled.\n"); return; } +/* mprotect() is broken in beta18, so we use the native Win32 + call instead +*/ +#if defined(cygwin32_TARGET_OS) + if (VirtualProtect(middle, pagesize, PAGE_NOACCESS, &old_prot) == 0) { +#else if (mprotect(middle, pagesize, PROT_NONE) == -1) { +#endif perror("mprotect"); EXIT(EXIT_FAILURE); }