Modifies access protections for memory mapping.
Standard C Library (libc.a)
#include <sys/types.h> #include <sys/mman.h>
int mprotect ( addr, len, prot)
The mprotect subroutine modifies the access protection of a mapped file region or anonymous memory region created by the mmap subroutine.
When successful, the mprotect subroutine returns 0. Otherwise, it returns -1 and sets the errno global variable to indicate the error.
Note: The return value for mprotect is 0 if it fails because the region given was not created by mmap unless XPG 1170 behavior is requested by setting the environment variable XPG_SUS_ENV to ON.
Attention: If the mprotect subroutine is unsuccessful because of a condition other than that specified by the EINVAL error code, the access protection for some pages in the (addr, addr + len) range may have been changed.
If the mprotect
subroutine is unsuccessful, the errno global variable may be set to
one of the following values:
|EACCES||The prot parameter specifies a protection that conflicts with the access permission set for the underlying file.|
|EINVAL||The prot parameter is invalid, or the addr parameter is not a multiple of the page size as returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter.|
|ENOMEM||The application has requested X/Open UNIX95 Specification compliant behavior and addresses in the range are invalid for the address space of the process or specify one or more pages which are not mapped.|