[ Previous | Next | Contents | Home | Search ]
AIX Version 4.3 Kernel and Subsystems Technical Reference, Volume 1

xmalloc Kernel Service

Purpose

Allocates memory.

Syntax

#include <sys/types.h>
#include <sys/errno.h>
#include <sys/malloc.h>
caddr_t xmalloc (size, align, heap)
int size;
int align;
caddr_t heap;

Parameters

size Specifies the number of bytes to allocate.
align Specifies the alignment characteristics for the allocated memory.
heap Specifies the address of the heap from which the memory is to be allocated.

Description

The xmalloc kernel service allocates an area of memory out of the heap specified by the heap parameter. This area is the number of bytes in length specified by the size parameter and is aligned on the byte boundary specified by the align parameter. The align parameter is actually the log base 2 of the desired address boundary. For example, an align value of 4 requests that the allocated area be aligned on a 2^4 (16) byte boundary.

Two heaps are provided in the kernel segment for use by kernel extensions. The kernel extensions should use the kernel_heap value when allocating memory that is not pinned. They should also use the pinned_heap value when allocating memory that is pinned. In particular, the pinned_heap value should be specified when allocating memory that is to be always pinned or pinned for long periods of time. The memory is pinned upon successful return from the xmalloc kernel service. When allocating memory that can be pageable (or only pinned for short periods of time), the kernel_heap value should be specified. The pin and unpin kernel services should be used to pin and unpin memory from the heap when required.

Kernel extensions can use these services to allocate memory out of the kernel heaps. For example, the xmalloc (128,3,kernel_heap) kernel service allocates a 128-byte double word aligned area out of the kernel heap.

A kernel extension must use the xmfree kernel service to free the allocated memory. If it does not, subsequent allocations eventually are unsuccessful.

The xmalloc kernel service has two compatibility interfaces: malloc and palloc.

Execution Environment

The xmalloc kernel service can be called from the process environment only.

Return Values

Upon successful completion, the xmalloc kernel service returns the address of the allocated area. A null pointer is returned under the following circumstances:

Implementation Specifics

The xmalloc kernel service is part of Base Operating System (BOS) Runtime.

The following additional interfaces to the xmalloc kernel service are provided:

Related Information

The xmfree kernel service.

Memory Kernel Services in AIX Kernel Extensions and Device Support Programming Concepts.


[ Previous | Next | Contents | Home | Search ]