mprotect problem

CHIH-PING CHEN <[email protected]>
Newsgroups gmane.linux.redhat.ia64.general
Message-ID <[email protected]>
Hi,

    I am having problem with mprotect on ia64. Does
anyone have any idea what's going wrong here? The
program is identical to the example provided in the
manpage for mprotect, except for some innocuous
castings and printf's. Thanks. 

~/ia64$ uname -a
Linux 2.4.3-12smp #1 SMP Fri Jun 8 13:06:07 EDT 2001
ia64 unknown
~/ia64$ cat mprot.c
       #include <stdio.h>
       #include <stdlib.h>
       #include <errno.h>
       #include <sys/mman.h>

       #include <limits.h>    /* for PAGESIZE */
       #ifndef PAGESIZE
       #define PAGESIZE 8192
       #endif

       int
       main(void)
       {
           char *p;
           char c;

           int pagesize = PAGESIZE;

           /* Allocate a buffer; it will have the
default
              protection of PROT_READ|PROT_WRITE. */
           p = (char*)malloc(1024+PAGESIZE-1);
           if (!p) {
               perror("Couldn't malloc(1024)");
               exit(errno);
           }

           /* Align to a multiple of PAGESIZE, assumed
to be a power of two */
           p = (char *)(((unsigned long) p +
PAGESIZE-1) & ~(PAGESIZE-1));

           c = p[666];         /* Read; ok */
           p[666] = 42;        /* Write; ok */

           /* Mark the buffer read-only. */
           if (mprotect(p, 1024, PROT_READ)) {
               perror("Couldn't mprotect");
               exit(errno);
           }

           printf("After mprotect...\n");

           c = p[666];         /* Read; ok */
           p[666] = 42;        /* Write; program dies
on SIGSEGV */

           exit(0);
       }
~/ia64$ g++ -g -o mp mprot.c
~/ia64$ mp
Couldn't mprotect: Invalid argument
~/ia64$ 

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.