mprotect()

Изменить защиту памяти

Прототип:

#include <sys/mman.h>
int mprotect( void *addr,
size_t len,
int prot );

Аргументы:

addr
The beginning of the range of addresses whose protection you want to change.
len
The length of the range of addresses, in bytes.
prot
The new access capabilities for the mapped memory region(s). You can combine the following bits, which are defined in <sys/mman.h>:
PROT_EXEC
the region can be executed.
PROT_NOCACHE
disable caching of the region (for example, to access dual ported memory).
PROT_NONE
the region can't be accessed.
PROT_READ
the region can be read.
PROT_WRITE
the region can be written.

Библиотека:

libc

Описание:

The mprotect() function changes the access protections on any mappings residing in the range starting at addr, and continuing for len bytes.

Возвращаемое значение:

0
Успешное завершение.
-1
Возникла ошибка. Код ошибки записан в errno.


Note: If mprotect() fails, the protections on some of the pages in the address range starting at addr and continuing for len bytes may have been changed.

Коды ошибок:

EACCES
The memory object wasn't opened for read, regardless of the protection specified. The memory object wasn't opened for write, and PROT_WRITE was specified for a MAP_SHARED type mapping.
EAGAIN
The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping, and there's insufficient memory resources to reserve for locking the private pages (if required).
ENOMEM
The addresses in the range starting at addr and continuing for len bytes are outside the range allowed for the address space of a process, or specify one or more pages that are not mapped. The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping, and locking the private pages (if required) would need more space than the system can supply to reserve for doing so.
ENOSYS
The function mprotect() isn't supported by this implementation.

Классификация:

POSIX 1003.1 MPR

Точка остановки потока
Нет
Обработчик прерываний
Нет
Обработчик сигналов
Да
В потоке
Да

Тематические ссылки:

mmap(), munmap(), shm_open(), shm_unlink()




Предыдущий раздел: Описание API системной библиотеки