PMEM2_CONFIG_SET_PROTECTION(3)
π PMEM2_CONFIG_SET_PROTECTION(3) π
okay bestie, welcome to the PMDK Programmer's Manual β¨ this one lives in libpmem2 and it's literally just about telling your memory mapping what it's allowed to do. protection flags, but make it fashion π
πΈ NAME πΈ
pmem2_config_set_protection() β set a protection flags in pmem2_config structure.
β¨ SYNOPSIS β¨
#include <libpmem2.h>
struct pmem2_config;
#define PMEM2_PROT_EXEC (1U << 29)
#define PMEM2_PROT_READ (1U << 30)
#define PMEM2_PROT_WRITE (1U << 31)
#define PMEM2_PROT_NONE 0
int pmem2_config_set_protection(struct pmem2_config *cfg,
unsigned prot);
π¦ DESCRIPTION π¦
so the way that pmem2_config_set_protection() works is: it sets the protection flags that are gonna be used for memory mapping. your mapping's whole permission slip, basically π
the default value sitting in the pmem2_config structure is PMEM2_PROT_READ | PMEM2_PROT_WRITE. and that prot argument? it's describing the desired memory protection of the mapping. key word: desired π
β οΈ no cap, the memory protection cannot conflict with the file opening-mode. so don't come in here asking for write access when you opened the file read-only, bestie, it's not gonna work.
also, config should already be initialized before you call this. not me forgetting to init it π go peek at pmem2_config_new(3) for the details on that.
so the value you pass is either PROT_NONE or the bitwise OR of one or more of these iconic little flags:
PMEM2_PROT_EXECβ Pages may be executed.PMEM2_PROT_READβ Pages may be read.PMEM2_PROT_WRITEβ Pages may be written.PMEM2_PROT_NONEβ Pages may not be accessed. (yeah, zero access. the silent treatment π)
π₯ RETURN VALUE π₯
pmem2_config_set_protection() returns 0 on success, or a negative error code if it fails. that's it, that's the tea β
π ERRORS π
pmem2_config_set_protection() can fail with the following errors:
PMEM2_E_INVALID_PROT_FLAGβ some or all of the provided flags are not valid. like, you handed it a flag that does not exist. it's giving made-up flag energy, and the function is NOT having it π
π SEE ALSO π
libpmem2(7), pmem2_config_new(3), pmem2_map_new(3) and https://pmem.io π
and that's the whole page, babe π«Ά go forth and protect your mappings responsibly π
PMDK β 2025-07-24 β mwah, slay, periodt β¨
π¦ where this page comes from
- fedora 43: libpmem2-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2020-2023, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms