*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->HP-UX 11i man pages -> mprotect (2)              


 mprotect(2)                                                     mprotect(2)

 NAME    [Toc]    [Back]
      mprotect - set or check protection of memory mapping

 SYNOPSIS    [Toc]    [Back]
      #include <sys/mman.h>

      int mprotect(void *addr, size_t len, int prot);

 DESCRIPTION    [Toc]    [Back]
      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(), to be that
      specified by prot.  Legitimate values for prot are the same as those
      permitted for mmap() and are defined in <sys/mman.h>:

           PROT_READ      Page can be read.

           PROT_WRITE     Page can be written.

           PROT_EXEC      Page can be executed.

           PROT_NONE      Page cannot be accessed.

           PROT_CHECK     Check page effective permissions

      If PROT_CHECK flag is specified, mprotect() checks the access
      protections on the mappings specified with the rest of prot value to
      see if the requested permissions are set.

      If the address range does not correspond to one created by a
      successful call to mmap(), mprotect() returns an error.

      If the address range being modified corresponds to a mapped file that
      was mapped with MAP_SHARED, mprotect() grants write access permission
      only if the file descriptor used to map the file was opened for
      writing.  If the address range corresponds to a mapped file that was
      mapped with the MAP_PRIVATE or the MAP_ANONYMOUS flag, mprotect()
      grants all requested access permissions.

      When mprotect() fails for reasons other than [EINVAL], the protections
      on some of the pages in the range [addr, addr+len] may have been

      For example, if an error occurs on some page at an addr2, then
      mprotect() may have modified the protections of all whole pages in the
      range [addr,addr2].

 RETURN VALUE    [Toc]    [Back]
      Upon successful completion, mprotect() returns 0.  Otherwise, it
      returns -1 and sets errno to indicate the error.

 Hewlett-Packard Company            - 1 -   HP-UX 11i Version 2: August 2003

 mprotect(2)                                                     mprotect(2)

 ERRORS    [Toc]    [Back]
      The mprotect() function will fail if:

           [EACCES]       The prot argument specifies a protection that
                          violates, or is different than (in the case where
                          flag PROT_CHECK is present), the access permission
                          the process has to the underlying memory object.

           [EINVAL]       prot is invalid, or addr is not a multiple of the
                          page size as returned by sysconf(_SC_PAGE_SIZE).

           [EFAULT]       The range specified by [addr, addr+len] (from, and
                          including, addr to, but not including, addr+len)
                          is invalid for the address space of a process, or
                          the range specifies one or more unmapped pages.

           [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.

           [EAGAIN]       The prot argument specifies PROT_WRITE over a
                          MAP_PRIVATE mapping and there are insufficient
                          memory resources to reserve for locking the
                          private page.

 AUTHOR    [Toc]    [Back]
      mprotect() was developed by HP, AT&T, and OSF.

 SEE ALSO    [Toc]    [Back]
      mmap(2), sysconf(2), <sys/mman.h>.

      mprotect(): AES, SVID3

 CHANGE HISTORY    [Toc]    [Back]
      First released in Issue 4, Version 2.

 Hewlett-Packard Company            - 2 -   HP-UX 11i Version 2: August 2003
[ Back ]
 Similar pages
Name OS Title
mprotect IRIX set protection of memory mapping
vm_map_check_protection FreeBSD check memory protection for a vm_map
vm_map_protect FreeBSD apply protection bits to a virtual memory region
mman HP-UX memory mapping definitions
mprotect Tru64 Modify access protections of memory mapping
kernacc FreeBSD check memory regions for accessibility
useracc FreeBSD check memory regions for accessibility
mvalid Tru64 Check memory region for validity
pmap_protect FreeBSD set physical page protection
mprotect NetBSD control the protection of pages
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service