/* * pmalloc_operation -- higher level wrapper for basic allocator API * * If successful function returns zero. Otherwise an error number is returned. */ int pmalloc_operation(struct palloc_heap *heap, uint64_t off, uint64_t *dest_off, size_t size, palloc_constr constructor, void *arg, struct operation_context *ctx) { #ifdef USE_VG_MEMCHECK uint64_t tmp; if (size && On_valgrind && dest_off == NULL) dest_off = &tmp; #endif int ret = palloc_operation(heap, off, dest_off, size, constructor, arg, ctx); if (ret) return ret; #ifdef USE_VG_MEMCHECK if (size && On_valgrind) { struct oob_header *pobj = OOB_HEADER_FROM_PTR((char *)heap->base + *dest_off); /* * The first few bytes of the oobh are unused and double as * an object guard which will cause valgrind to issue an error * whenever the unused memory is accessed. */ VALGRIND_DO_MAKE_MEM_NOACCESS(pobj->unused, sizeof(pobj->unused)); } #endif return 0; }
/* * pfree -- deallocates a memory block previously allocated by pmalloc * * A zero value is written persistently into the off variable. * * If successful function returns zero. Otherwise an error number is returned. */ void pfree(PMEMobjpool *pop, uint64_t *off) { struct operation_context *ctx = pmalloc_operation_hold_type(pop, OPERATION_INTERNAL, 1); int ret = palloc_operation(&pop->heap, *off, off, 0, NULL, NULL, 0, 0, 0, ctx); ASSERTeq(ret, 0); pmalloc_operation_release(pop); }
/* * prealloc -- resizes in-place a previously allocated memory block * * The block offset is written persistently into the off variable. * * If successful function returns zero. Otherwise an error number is returned. */ int prealloc(PMEMobjpool *pop, uint64_t *off, size_t size, uint64_t extra_field, uint16_t object_flags) { struct operation_context *ctx = pmalloc_operation_hold_type(pop, OPERATION_INTERNAL, 1); int ret = palloc_operation(&pop->heap, *off, off, size, NULL, NULL, extra_field, object_flags, 0, ctx); pmalloc_operation_release(pop); return ret; }
/* * pmalloc_construct -- allocates a new block of memory with a constructor * * The block offset is written persistently into the off variable, but only * after the constructor function has been called. * * If successful function returns zero. Otherwise an error number is returned. */ int pmalloc_construct(PMEMobjpool *pop, uint64_t *off, size_t size, palloc_constr constructor, void *arg, uint64_t extra_field, uint16_t object_flags, uint16_t class_id) { struct operation_context *ctx = pmalloc_operation_hold_type(pop, OPERATION_INTERNAL, 1); int ret = palloc_operation(&pop->heap, 0, off, size, constructor, arg, extra_field, object_flags, class_id, ctx); pmalloc_operation_release(pop); return ret; }