Previous section.

Common Security: CDSA and CSSM
Copyright © 1997 The Open Group

Application Memory Functions

Introduction

When CSSM or add-in modules return memory structures to applications, that memory is maintained by the application. Instead of using a model where the application passes memory blocks to the add-in modules to work on, the CSSM model requires the application to supply memory functions. This frees the application from any requirement to specify memory block sizes to the CSSM and the add-ins. The memory that the application receives is in its process space, and this prevents the application from walking through the memory of the CSSM or the add-in modules. When the application no longer requires the memory, it is responsible for freeing it.

Applications will register memory functions with the add-in modules during attach time and with CSSM during initialization. A memory function table will be passed from the application to add-in modules through the CSSM_xxx_Attach functions associated with each add-in. The CSSM_Init function is where the CSSM will receive the application's memory function.

CSSM_API_MEMORY_FUNCS Data Structure

This structure is used by applications to supply memory functions for the CSSM and the add-in modules. The functions are used when memory needs to be allocated by the CSSM or add-ins for returning data structures to the applications.
typedef struct cssm_api_memory_funcs {
  void * (*malloc_func) (uint32 Size, void *AllocRef);
  void (*free_func) (void *MemPtr, void *AllocRef);
  void * (*realloc_func) (void *MemPtr, uint32 Size, void *AllocRef);
  void * (*calloc_func) (uint32 Num, uint32 Size, void *AllocRef);
  void *AllocRef;
} CSSM_API_MEMORY_FUNCS, *CSSM_API_MEMORY_FUNCS_PTR

Definition

malloc_func

Pointer to function that returns a void pointer to the allocated memory block of at least size bytes from heap AllocRef.

free_func

Pointer to function that deallocates a previously-allocated memory block (memblock) from heap AllocRef.

realloc_func

Pointer to function that returns a void pointer to the reallocated memory block (memblock) of at least size bytes from heap AllocRef.

calloc_func

Pointer to function that returns a void pointer to an array of num elements of length size initialized to zero from heap AllocRef.

AllocRef

Indicates the memory heap the function operates on.


Why not acquire a nicely bound hard copy?
Click here to return to the publication details or order a copy of this publication.
You should also read the legal notice explaining the terms and conditions relating to the CDSA documentation.

Contents Next section Index