Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mprotect(2) [ultrix man page]

mprotect(2)							System Calls Manual						       mprotect(2)

       mprotect - memory protection control

       #include <sys/mman.h>
       #include <sys/types.h>

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

       The system call changes the protection of portions of an application program's data memory.  Protection is performed on page cluster bound-
       aries.  The default protection for data memory on process invocation is user READ/WRITE.  The addr argument is the beginning address of the
       data block and must fall on a page cluster boundary.

       The  len  argument is the length of the data block, in bytes.  The length of the block is rounded up to a cluster boundary, and the size of
       the block to be protected is returned.

       The prot argument is the requested protection for the block of memory.  Protection values affect only the user process.	Protection  values
       are defined in <mman.h> as:
       /* protections are chosen from these bits, ORed together */
       #define PROT_READ       0x1     /* pages can be read */
       #define PROT_WRITE      0x2     /* pages can be written */
       #define PROT_EXEC       0x4     /* pages can be executed */
       Setting the prot argument to zero (0) indicates that the process cannot reference the memory block, without causing a fault.

       A  protected page faults if the protection is violated, and a SIGBUS signal is issued.  If the process has a handler defined for the SIGBUS
       signal, the code parameter, described in and is used to pass in the virtual address that faulted.

       The page cluster size may change in future versions of ULTRIX.  As a result, should be used to determine the correct len argument,  and	or
       should be used to determine the correct addr argument.

       If  the	user handles a SIGBUS signal, the signal handler must either abort the process or correct the condition that caused the protection
       fault (SIGBUS).	If some corrective action is not taken, an infinite loop results because the faulting instruction is  restarted.   If  the
       user permits the default SIGBUS handler to be used, the process aborts if a referenced page causes a fault.

       The  VAX  architecture  makes  the  following  implications; PROT_WRITE implies (PROT_WRITE | PROT_READ | PROT_EXEC), and PROT_READ implies

       Only the application can change the call's private data space.  This means that attempts to change text,  shared  memory,  or  stack  space
       causes a EACCES failure.

Return Values
       Upon  successful completion, the size of the protected memory block, in bytes, is returned.  Otherwise, a value of -1 is returned and errno
       is set to indicate the error.

       The call fails under the following conditions:

       [EALIGN]       The addr argument is not on a cluster boundary.

       [EINVAL]       The prot argument is not a valid protection mask.

       [EACCES]       The memory block is not fully contained within private data space.

See Also
       getpagesize(2), sbrk(2), sigvec(2), malloc(3), signal(3)


Check Out this Related Man Page

mprotect(2)							   System Calls 						       mprotect(2)

mprotect - set protection of memory mapping SYNOPSIS
#include <sys/mman.h> int mprotect(void *addr, size_t len, int prot); DESCRIPTION
The mprotect() function changes the access protections on the mappings specified by the range [addr, addr + len), rounding len up to the next multiple of the page size as returned by sysconf(3C), to be that specified by prot. Legitimate values for prot are the same as those permitted for mmap(2) and are defined in <sys/mman.h> as: PROT_READ /* page can be read */ PROT_WRITE /* page can be written */ PROT_EXEC /* page can be executed */ PROT_NONE /* page can not be accessed */ When mprotect() fails for reasons other than EINVAL, the protections on some of the pages in the range [addr, addr + len) may have been changed. If the error occurs on some page at addr2, then the protections of all whole pages in the range [addr, addr2] will have been modi- fied. RETURN VALUES
Upon successful completion, mprotect() returns 0. Otherwise, it returns -1 and sets errno to indicate the error. ERRORS
The mprotect() function will fail if: EACCES The prot argument specifies a protection that violates the access permission the process has to the underlying memory object. EINVAL The len argument has a value equal to 0, or addr is not a multiple of the page size as returned by sysconf(3C). 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. The mprotect() function may fail if: EAGAIN The address range [addr, addr + len) includes one or more pages that have been locked in memory and that were mapped MAP_PRIVATE; prot includes PROT_WRITE; and the system has insufficient resources to reserve memory for the private pages that may be created. These private pages may be created by store operations in the now-writable address range. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
mmap(2), plock(3C), mlock(3C), mlockall(3C), sysconf(3C), attributes(5), standards(5) SunOS 5.10 12 Jan 1998 mprotect(2)
Man Page