Function MPROTECT

Syntax

mprotect address length protection => error

Arguments and values

address -- A non-negative integer.

length -- A non-negative integer.

protection -- A non-negative fixnum.

error -- A fixnum.

Description

This function changes the protection of those memory page(s) of the calling process that contain any part of the address range in the interval [address, address+length-1]. The argument address must be aligned to a page boundary.

If the calling process tries to access memory in a manner that violates the protection, then the kernel generates a SIGSEGV signal for the process.

The argument protection is either +prot-none+ or the bitwise OR of the other values in the following list:

+prot-read+ The memory can be read.
+prot-write+ The memory can be modified.
+prot-exec+ The memory can be executed.

Errors

+eaccess+ The memory cannot be given the specified access. This can happen, for example, if you mmap a file to which you have read-only access, then ask mprotect to mark it +prot-write+.
+einval+ addrress is not a valid address, or not a multiple of the system page size.
+enomem+ Internal kernel structures could not be allocated.
+enomem+ Addresses in the range [address, address+length-1] are invalid for the address space of the process, or specify one or more pages that are not mapped. (Before kernel 2.4.19, the error +efault+ was incorrectly produced for these cases.)