Previous section.

Common Security: CDSA and CSSM, Version 2 (with corrigenda)
Copyright © 2000 The Open Group

Application Memory Functions

Introduction

Memory management between applications and CSSM, and between applications and add-in service providers, differs by necessity. Before selecting and loading a particular version of CSSM, applications are required to provide memory management functions as input to each get-operation. These functions operate on heap space owned by the application. Corresponding free-operations are provided to relieve applications of the burden of walking complex data structures. Once a version of CSSM has been selected and loaded by the application, some memory structures can be allocated on CSSM's heap. Corresponding free-operations are defined, but they must be used by the application to free those structures when they are no longer needed.

When a service provider is selected and attached using CSSM_ModuleAttach(), the application must provide a set of memory management functions and heap space for data structures that will be returned by the add-in module as part of its service. When requesting specific services, an application can provide pre-allocated memory as input for the function call. This requires that the application know the memory size required by the service provider. This is not always possible. Supplying a heap and memory management frees the application from specifying memory block sizes. The memory that the application receives is in its heap space. When the application no longer requires the memory, it is responsible for freeing it.

A memory function table is passed from the application to add-in service modules through the CSSM_xxx_Attach functions associated with each add-in.

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 void * (CSSMAPI *CSSM_MALLOC)
    ( uint32 size,
    void * allocref);

typedef void (CSSMAPI *CSSM_FREE) (void * memblock, void * allocref);

typedef void * (CSSMAPI *CSSM_REALLOC) (void * memblock, uint32 size, void * allocref);

typedef void * (CSSMAPI *CSSM_CALLOC) (uint32 num, uint32 size, void * allocref);

typedef struct cssm_memory_funcs { CSSM_MALLOC malloc_func; CSSM_FREE free_func; CSSM_REALLOC realloc_func; CSSM_CALLOC calloc_func; void *AllocRef; } CSSM_MEMORY_FUNCS, *CSSM_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.

Contents Next section Index