Compartir a través de


SharedMemory.SetProtect(Int32) Method

Definition

Sets the protection on the shared memory to the combination specified in prot, which is either a bitwise-or'd combination of android.system.OsConstants#PROT_READ, android.system.OsConstants#PROT_WRITE, android.system.OsConstants#PROT_EXEC from android.system.OsConstants, or android.system.OsConstants#PROT_NONE, to remove all further access.

[Android.Runtime.Register("setProtect", "(I)Z", "", ApiSince=27)]
public bool SetProtect (int prot);
[<Android.Runtime.Register("setProtect", "(I)Z", "", ApiSince=27)>]
member this.SetProtect : int -> bool

Parameters

prot
Int32

Any bitwise-or'ed combination of android.system.OsConstants#PROT_READ, android.system.OsConstants#PROT_WRITE, and android.system.OsConstants#PROT_EXEC; or android.system.OsConstants#PROT_NONE

Returns

Whether or not the requested protection was applied. Returns true on success, false if the requested protection was broader than the existing protection.

Attributes

Remarks

Sets the protection on the shared memory to the combination specified in prot, which is either a bitwise-or'd combination of android.system.OsConstants#PROT_READ, android.system.OsConstants#PROT_WRITE, android.system.OsConstants#PROT_EXEC from android.system.OsConstants, or android.system.OsConstants#PROT_NONE, to remove all further access.

Note that protection can only ever be removed, not added. By default shared memory is created with protection set to PROT_READ | PROT_WRITE | PROT_EXEC. The protection passed here also only applies to any mappings created after calling this method. Existing mmaps of the shared memory retain whatever protection they had when they were created.

A common usage of this is to share a read-only copy of the data with something else. To do that first create the read/write mapping with PROT_READ | PROT_WRITE, then call setProtect(PROT_READ) to remove write capability, then send the SharedMemory to another process. That process will only be able to mmap with PROT_READ.

Java documentation for android.os.SharedMemory.setProtect(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to