Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
MPROTECT(2)		  FreeBSD System Calls Manual		   MPROTECT(2)

NAME
     mprotect -- control the protection	of pages

SYNOPSIS
     #include <sys/mman.h>

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

DESCRIPTION
     The mprotect() system call	sets the access	protections for	the pages that
     contain the address range addr through addr + len - 1 (inclusive).	 If
     len is 0, no action is taken on the page that contains addr.

     The protections (region accessibility) are	specified in the prot argu-
     ment.  It should either be	PROT_NONE (no permissions) or the bitwise OR
     of	one or more of the following values:

	   PROT_EXEC	 Pages may be executed.
	   PROT_READ	 Pages may be read.
	   PROT_WRITE	 Pages may be written.

     Not all implementations will guarantee protection on a page basis;	the
     granularity of protection changes may be as large as an entire region.
     Nor will all implementations guarantee to give exactly the	requested per-
     missions; more permissions	may be granted than requested by prot.	How-
     ever, if PROT_WRITE was not specified then	the page will not be writable.

RETURN VALUES
     Upon successful completion, the value 0 is	returned; otherwise the
     value -1 is returned and the global variable errno	is set to indicate the
     error.

ERRORS
     mprotect()	will fail if:

     [EACCES]		The process does not have sufficient access to the un-
			derlying memory	object to provide the requested	pro-
			tection.

     [ENOMEM]		The process has	locked future pages with
			mlockall(MCL_FUTURE), a	page being protected is	not
			currently accessible, and making it accessible and
			locked would exceed process or system limits.

     [ENOTSUP]		The accesses requested in the prot argument are	not
			allowed.  In particular, PROT_WRITE | PROT_EXEC	map-
			pings are not permitted	in most	binaries (see
			kern.wxabort in	sysctl(2) for more information).

     [EINVAL]		The prot argument is invalid or	the specified address
			range would wrap around.

SEE ALSO
     madvise(2), msync(2), munmap(2)

STANDARDS
     The mprotect() function conforms to IEEE Std 1003.1-2008 ("POSIX.1").

HISTORY
     The mprotect() function has been available	since 4.3BSD Net/2.

CAVEATS
     The OpenBSD implementation	of mprotect() does not require addr to be
     page-aligned, although other implementations may.

FreeBSD	13.0		       December	21, 2019		  FreeBSD 13.0

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SEE ALSO | STANDARDS | HISTORY | CAVEATS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=mprotect&sektion=2&manpath=OpenBSD+6.9>

home | help