sys_mprotect  [mm/mprotect.c]


Controls allowable accesses to a region of memory.

This system call specifies the desired protection for the memory page(s) containing part or all of the specified interval. If an access is disallowed by the protection given it, the program receives a SIGSEGV.

Arguments

eax 125
ebx Starting address of memory region.
ecx Length of the memory region.
edx Protection flags:
PROT_NONE The memory cannot be accessed at all.
PROT_READ The memory can be read.
PROT_WRITE The memory can be written to.
PROT_EXEC The memory can contain executing code.
PROT_SEM *to be documented*
PROT_GROWSDOWN *to be documented*
PROT_GROWSUP *to be documented*

Return values

If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:

-EACCES The memory cannot be given the specified access. This can happen, for example, if you sys_mmap a file to which you have read-only access, then ask sys_mprotect to mark it PROT_WRITE.
-EFAULT The memory cannot be accessed.
-EINVAL ebx is not a valid pointer, or not a multiple of PAGESIZE.
-ENOMEM Internal kernel structures could not be allocated. Or: addresses in the given range are invalid for the address space of the process, or specify one or more pages that are not mapped.

Remarks

The new protection replaces any existing protection. For example, if the memory had previously been marked PROT_READ, and sys_mprotect is then called with PROT_WRITE, it will no longer be readable.

It is always legal to call sys_mprotect on any address in a process' address space (except for the kernel vsyscall area). In particular it can be used to change existing code mappings to be writable.

Compatibility

n/a