libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
securemem.h File Reference
#include <cstddef>
#include <promeki/core/namespace.h>
#include <promeki/core/platform.h>
#include <promeki/core/error.h>
Include dependency graph for securemem.h:

Go to the source code of this file.

Functions

PROMEKI_NAMESPACE_BEGIN void secureZero (void *ptr, size_t size)
 Securely zeros a memory region, guaranteed not to be optimized away.
 
Error secureLock (void *ptr, size_t size)
 Locks a memory region into physical RAM, preventing it from being swapped to disk.
 
Error secureUnlock (void *ptr, size_t size)
 Unlocks a memory region previously locked with secureLock().
 

Detailed Description

See LICENSE file in the project root folder for license information.

Function Documentation

◆ secureLock()

Error secureLock ( void ptr,
size_t  size 
)
inline

Locks a memory region into physical RAM, preventing it from being swapped to disk.

Also marks the region as excluded from core dumps on Linux (MADV_DONTDUMP).

Parameters
ptrPointer to the memory region to lock.
sizeSize of the region in bytes.
Returns
Error::Ok on success, or the system error on failure (e.g. NoMem for RLIMIT_MEMLOCK exceeded, NoPermission for missing CAP_IPC_LOCK).

◆ secureUnlock()

Error secureUnlock ( void ptr,
size_t  size 
)
inline

Unlocks a memory region previously locked with secureLock().

Reverses the effects of secureLock(), allowing the OS to swap the pages and include them in core dumps again.

Parameters
ptrPointer to the memory region to unlock.
sizeSize of the region in bytes.
Returns
Error::Ok on success, or the system error on failure.