Allowing Other Tasks to Write to Your Memory


When a task owns memory, other tasks cannot write to that memory unless the task gives them permission. To give another task permission to write to one or more of your memory pages, or to revoke write permission that was previously granted, call ControlMem():

Err ControlMem( void *p, int32 size, int32 cmd, Item task )
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. The p argument, a pointer to a memory location, and the size argument, the amount of the contiguous memory, in bytes, beginning at the memory location specified by the p argument, specify which memory control status to change. If p and size arguments specify any part of a page, changes are made to the entire page. The task argument specifies which task to change the control status for. You can make multiple calls to ControlMem() to change the control status for more than one task. The cmd argument is a constant that specifies the change to be made to the control status. The possible values are given below:

(One other possible value, MEMC_GIVE, is described in the next section.)

For a task to change the control status of memory pages with ControlMem(), it must own that memory, with one exception: a task that has write access to memory it doesn't own can relinquish its write access using MEMC_NOWRITE as the value of the cmd argument.

A task can use ControlMem() to prevent itself from writing to memory that it owns, which is useful during debugging.