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