OSDynLoad_SetAllocator

Syntax

#include <cafe/os/OSDynLoad.h>

typedef int  (*OSDynLoad_pfMemAlloc)(int aMemBytes, int aMemAlign, void **appRetPtr);
typedef void (*OSDynLoad_pfMemFree)(void *pAddr);

int OSDynLoad_SetAllocator(OSDynLoad_pfMemAlloc aAlloc, OSDynLoad_pfMemFree  aFree);

Parameters

aAlloc Allocation function the loader should use to allocate chunks of read/write memory for module contents.
aFree Free function to be used for blocks of memory allocated by the aAlloc function.

Return Values

Returns an OSDYNLOAD_ERR_xxx error code (see OSDynLoad.h).

Description

Allows you to atomically set the allocator used by the loader to allocate read/write areas for the RPL files that are loaded.

The allocator function (OSDynLoad_pfMemAlloc) takes as arguments the number of bytes to allocate, the alignment, and a return pointer for the allocated block. A nonzero return code indicates an error. The alignment value may be negative. In this case, memory should be allocated at the highest address possible in whatever heap is used.

Calls to this function are atomic with respect to loaded files.

Memory allocated by the allocator is only ever freed using the corresponding deallocator. This is true even if the allocator/deallocator is changed after an initial allocation.

For example:

  1. Call SetAllocator(A,B).
  2. Load an RPL. Allocations are made by calling A.
  3. Call SetAllocator(C,D).
  4. Free the RPL loaded in (2).

In this case, deallocator B, set in step 1, is used to free the memory, not the one set in step 3.

Do Not Call From

None.

See Also

OSDynLoad_Acquire
OSDynLoad_AddNotifyCallback
OSDynLoad_DelNotifyCallback
OSDynLoad_FindExport
OSDynLoad_FindTag
OSDynLoad_GetAllocator
OSDynLoad_GetLoaderHeapStatistics
OSDynLoad_GetModuleName
OSDynLoad_IsModuleLoaded
OSDynLoad_Release

Revision History

2013/11/01 Added OSDynLoad_IsModuleLoaded.
2013/05/08 Automated cleanup pass.
2011/03/11 Initial version.


CONFIDENTIAL