memoryProtect method

bool memoryProtect(
  1. Pointer<NativeType> pointer,
  2. MemoryProtection memoryProtection
)

Provides sodium_mprotect_*.

Depending on the memoryProtection argument, the corresponding mprotect function will be used.

See https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations

Implementation

bool memoryProtect(
  Pointer<NativeType> pointer,
  MemoryProtection memoryProtection,
) {
  int result;
  switch (memoryProtection) {
    case MemoryProtection.noAccess:
      result = sodium.sodium_mprotect_noaccess(pointer.cast());
    case MemoryProtection.readOnly:
      result = sodium.sodium_mprotect_readonly(pointer.cast());
    case MemoryProtection.readWrite:
      result = sodium.sodium_mprotect_readwrite(pointer.cast());
  }
  return result == 0;
}