---
name: "pmem2_config_set_protection"
section: "3"
platform: "linux"
package: "libpmem2-dev"
version: "1.13.1-1.1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/pmem2_config_set_protection"
---

# pmem2\_config\_set\_protection(3)

set a protection flags in pmem2\_config structure.

## 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

The **pmem2\_config\_set\_protection**() function sets the protection flags which will be used for memory mapping. The default value in pmem2\_config structure is **PMEM2\_PROT\_READ \|** **PMEM2\_PROT\_WRITE**. The *argument describes the desired memory protection of the* *mapping. The memory protection cannot conflict with the file* *opening-mode.* \*config\* should be already initialized, please see [**pmem2\_config\_new**(3)](/pmem2_config_new/3.md) for details.

It is either PROT\_NONE or the bitwise OR of one or more of the following 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. On Windows this flag is not supported.

## RETURN VALUE

The **pmem2\_config\_set\_protection**() function returns 0 on success or a negative error code on failure.

## ERRORS

The **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.

## SEE ALSO

[**libpmem2**(7)](/libpmem2/7.md), [**pmem2\_config\_new**(3)](/pmem2_config_new/3.md), [**pmem2\_map\_new**(3)](/pmem2_map_new/3.md) and **\<https://pmem.io\>**
