Controls memory permissions and ownership.
Err ControlMem( void *p, int32 size, int32 cmd, Item task )
When a task allocates memory, it becomes the owner of that memory. Other tasks cannot write to the memory unless they are given permission by its owner. A task can give another task permission to write to one or more of its memory pages, revoke write permission that was previously granted, or transfer ownership of memory to another task or the system by calling ControlMem()
.
Each page of memory has a control status that specifies which task owns the memory and which tasks can write to it. Calls to ControlMem()
change the control status for entire pages. If the p and size arguments (which specify the memory to change) specify any part of a page, the changes apply to the entire page.
A task can grant write permission for a page that it owns (or for some number of contiguous pages) to any number of tasks. To accomplish this, the task must make a separate call to ControlMem()
for each task that is to be granted write permission.
A task that calls ControlMem()
must own the memory whose control status it is changing, with one exception: A task that has write access to memory it doesn't own can relinquish its write access (by using MEMC_NOWRITE as the value of the cmd argument). If a task transfers ownership of memory it still retains write access.
The possible values of “cmd” are:
The procedure returns 0 if the change was successful or an error code (a negative value) if an error occurs. Possible error codes include:
SWI implemented in kernel folio V20.
A task can use ControlMem()
to prevent itself from writing to memory it owns.
A task must own the memory for its I/O buffers.
A task can use ControlMem()
to return ownership of memory pages to the system, thereby returning them to the system-wide free memory pool. You can do this by using 0 as the value of the task argument.
A task can use ControlMem()
to unshare or write protect memory from all other tasks. Specify 0 for the task for this to happen.
We would like to support making a piece of memory writable by all other tasks by using task==0 and MEMC_OKWRITE, but this is not implemented yet.
ScavengeMem
(), AllocMemBlocks()