Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!cs.utexas.edu!
uunet!news.univie.ac.at!info.univie.ac.at!trick.ani.univie.ac.at!bernhard
From: bernh...@trick.ani.univie.ac.at (Bernhard Strassl)
Newsgroups: comp.os.linux.development
Subject: *NO* HELP w/ mprotect() ???
Date: 10 Sep 1993 07:14:06 GMT
Organization: Vienna University Computer Center, Austria
Lines: 83
Distribution: world
Message-ID: <26p9fu$dj9@infosrv.edvz.univie.ac.at>
NNTP-Posting-Host: trick.ani.univie.ac.at


Recently I saw two postings from people that asked for the
implementation of the mprotect() system call (I include the
SUN man page below).

I also need this call to get the 'Texas object storage' running
on my Linux PC at home (it seems to work fine on our SUNs here)
and I waited for an answer of some Linux guru.

But there was absolutely no response to these requests (at least
on our news server) so I call for help again:

Please can anyone who is familar with the implementation of the
Linux virtual memory management post/mail me the source for
such a function?
I had a look at the kernel mmap() sources (I run a very old 0.99pl6
version of Linux which has this function only partially working) and
I think it will not be much work for a person who knows how the
memory tables are organized. (I would have to spend too much time to 
find it out by myself.)

Many thanks in advance!

-bernhard

---------------------------------------------------------------
The Xm++ / CommonInteract Project
Vienna User Interface Group
Bernhard Strassl              University of Vienna
xmp...@ani.univie.ac.at       Dpt. for Applied Computer Science
                              and Information Systems
---------------------------------------------------------------



MPROTECT(2)               SYSTEM CALLS                MPROTECT(2)

NAME
     mprotect - set protection of memory mapping

SYNOPSIS
     #include <sys/mman.h>

     mprotect(addr, len, prot)
     caddr_t addr;
     int len, prot;

DESCRIPTION
     mprotect() changes the access protections  on  the  mappings
     specified  by the range [addr, addr + len) to be that speci-
     fied by prot.  Legitimate values for prot are  the  same  as
     those permitted for mmap(2).

RETURN VALUES
     mprotect() returns:

     0    on success.
     -1   on failure and sets errno to indicate the error.

ERRORS
     EACCES         prot specifies a  protection  which  violates
                    the  access permission the process has to the
                    underlying memory object.

     EINVAL         addr is not a multiple of the  page  size  as
                    returned by getpagesize(2).

     ENOMEM         Addresses in the range [addr, addr + len) are
                    invalid  for  the address space of a process,
                    or specify one or more pages  which  are  not
                    mapped.

     When mprotect() fails for reasons  other  than  EINVAL,  the
     protections  on some of the pages in the range [addr, addr +
     len) will have been changed.  If the error  occurs  on  some
     page  at  address  addr2,  then the protections of all whole
     pages in the range [addr, addr2) have been modified.

SEE ALSO
     getpagesize(2), mmap(2)

Sun Release 4.1   Last change: 21 January 1990                  1

Newsgroups: comp.os.linux.development
Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!europa.eng.gtefsd.com!
darwin.sura.net!dtix.dt.navy.mil!cs.umd.edu!ra!tantalus.nrl.navy.mil!eric
From: e...@tantalus.nrl.navy.mil (Eric Youngdale)
Subject: Re: *NO* HELP w/ mprotect() ???
Message-ID: <CD5L5u.Czp@ra.nrl.navy.mil>
Sender: use...@ra.nrl.navy.mil
Organization: Naval Research Laboratory
References: <26p9fu$dj9@infosrv.edvz.univie.ac.at>
Date: Fri, 10 Sep 1993 19:37:05 GMT
Lines: 38

In article <26p9fu$...@infosrv.edvz.univie.ac.at> 
bernh...@trick.ani.univie.ac.at (Bernhard Strassl) writes:
>
>Recently I saw two postings from people that asked for the
>implementation of the mprotect() system call (I include the
>SUN man page below).
>
>I also need this call to get the 'Texas object storage' running
>on my Linux PC at home (it seems to work fine on our SUNs here)
>and I waited for an answer of some Linux guru.
>
>But there was absolutely no response to these requests (at least
>on our news server) so I call for help again:
>
>Please can anyone who is familar with the implementation of the
>Linux virtual memory management post/mail me the source for
>such a function?
>I had a look at the kernel mmap() sources (I run a very old 0.99pl6
>version of Linux which has this function only partially working) and
>I think it will not be much work for a person who knows how the
>memory tables are organized. (I would have to spend too much time to 
>find it out by myself.)

	First of all, I would suggest that you get pl12 or pl13 (once it is
out).  There have been a number of changes to the memory manager recently which
would make it much easier to implent a mprotect function.  I suggest that you
start with mm/mmap.c in the function sys_munmap, and modify this to do the job.

	There will be two things you will need to do.  First you will need to
modify the protection stored in the vm_area_struct so that new pages faulted in
get the correct protection.  You will also need to sweep through and modify the
protections of all of the pages currently in memory in the current range.

	All in all, it should not be that hard.

-Eric
-- 
"When Gregor Samsa woke up one morning from unsettling dreams, he
found himself changed in his bed into a lawyer."