PMEM2_MAP_NEW(3)
β¨ pmem2_map_new(3) β¨ β the PMDK Programmer's Manual's cutest little mapping maker π
okay bestie, sit down, hydrate, because we're about to make a mapping in your virtual address space and it's genuinely giving main character energy π«Ά
πΈ NAME πΈ
pmem2_map_new() β creates a mapping β¨
π SYNOPSIS π
#include <libpmem2.h>
struct pmem2_config;
struct pmem2_source;
struct pmem2_map;
int pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *config,
const struct pmem2_source *source);
π DESCRIPTION π
So the pmem2_map_new() function creates a brand new mapping in the virtual address space of the calling process. iconic behavior fr fr. to pull this off it needs two things: a configuration config of the mapping, and the data source source. that's the duo. the it-girl and her bestie π
Optionally, the mapping can be created at the offset of the virtual memory reservation set in the configuration config. see pmem2_config_set_vm_reservation(3) for details π
For a mapping to succeed, the config structure must have the granularity parameter set to the appropriate level. no granularity, no mapping, periodt. see pmem2_config_set_required_store_granularity(3) and libpmem2(7) for more details π
If pmem2_map_new() succeeds in creating a new mapping, it instantiates a new *struct pmem2_map* object describing the mapping. the pointer to this freshly created object gets stored in the user-provided variable you passed via the map_ptr pointer. slay β¨ If the mapping fails, the variable pointed by map_ptr will contain a NULL value and an appropriate error value will be returned. for a list of possible return values please see RETURN VALUE π
β οΈ every singlestruct pmem2_mapobject created viapmem2_map_new()has to be destroyed using thepmem2_map_delete()function. like, it's not optional, it's a lifestyle. for details please seepmem2_map_delete(3). don't leave your mappings orphaned bestie π
π RETURN VALUE π
pmem2_map_new() returns 0 on success or a negative error code on failure. that's it, that's the vibe check π
π₯ ERRORS π₯
pmem2_map_new() can fail with the following errors:
PMEM2_E_GRANULARITY_NOT_SETβ the store granularity for the mapping was not set in the providedconfigstructure. please seepmem2_config_set_required_store_granularity(3)andlibpmem2(7). you forgot the granularity bestie, we've all been there πPMEM2_E_MAP_RANGEβoffset + lengthis too big to represent it usingsize_tdata type. too much. unhinged amounts of range πPMEM2_E_MAP_RANGEβ end of the mapping (offset + length) is outside of the file. the file is too small. tiny file, big dreams πPMEM2_E_SOURCE_EMPTYβ mapped file has size equal to0. nothing there. empty. ghosted π«₯PMEM2_E_MAPPING_EXISTSβ if the object exists before the function call. it was already there, no cap πPMEM2_E_OFFSET_UNALIGNEDβ argument unaligned,offsetis not a multiple of the alignment required for specific*source. please seepmem2_source_alignment(3)β¨PMEM2_E_LENGTH_UNALIGNEDβ argument unaligned,lengthis not a multiple of the alignment required for specific*source. please seepmem2_source_alignment(3)β¨PMEM2_E_SRC_DEVDAX_PRIVATEβ device DAX mapped withMAP_PRIVATE. nope, not doing that πPMEM2_E_ADDRESS_UNALIGNEDβ when mapping device DAX to a virtual memory reservation and the base mapping address (reservation address + reservation offset) is not aligned to the device DAX granularity. please seepmem2_config_set_vm_reservation(3)πPMEM2_E_ADDRESS_UNALIGNEDβ when mapping to a virtual memory reservation and the region for the mapping exceeds reservation size. please seepmem2_config_set_vm_reservation(3)πPMEM2_E_NOSUPPβ when config-provided protection flags combination is not supported. that combo? not on the menu π«PMEM2_E_NO_ACCESSβ there is a conflict between mapping protection and file opening mode. they're beefing π€
It can also return -EACCES, -EAGAIN, -EBADF, -ENFILE, -ENODEV, -ENOMEM, -EPERM, -ETXTBSY from the underlying mmap(2) function. It is used with and without MAP_ANONYMOUS π
-EACCES may be returned only if the file descriptor points to an append-only file π
It can also return all errors from the underlying pmem2_source_size() and pmem2_source_alignment() functions.
π¦ SEE ALSO π¦
mmap(2), open(3), pmem2_config_set_required_store_granularity(3), pmem2_source_alignment(3), pmem2_source_from_fd(3), pmem2_source_size(3), pmem2_map_delete(3), pmem2_config_set_vm_reservation(3), libpmem2(7) and <https://pmem.io> π
okay that's the whole page bestie, you ate that π«Ά this was the PMDK Programmer's Manual, PMDK - version, dated 2025-07-24 β go forth and map responsibly, and remember: delete your mappings, hydrate, and stan libpmem2 π
β¨π
π¦ 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 2019-2023, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms