Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
Functions
Memory Management

Allocate and free heap or buffer pool memory. More...

Functions

int bfpalloc (uint bufsize, uint nbuf)
 
syscall bfpfree (int poolid)
 
syscall buffree (void *buffer)
 
void * bufget_ (int poolid, const char *file, const char *func)
 
syscall memfree (void *memptr, uint nbytes)
 
void * memget (uint nbytes)
 
void * stkget (uint nbytes)
 

Detailed Description

Allocate and free heap or buffer pool memory.

Function Documentation

int bfpalloc ( uint  bufsize,
uint  nbuf 
)

Acquire heap storage and subdivide into buffers.

Parameters
bufsizeSize of individual buffers, in bytes.
nbufNumber of buffers in the pool.
Returns
On success, returns an identifier for the buffer pool that can be passed to bufget() or bfpfree(). On failure, returns ::SYSERR.
syscall bfpfree ( int  poolid)

Frees the memory allocated for a buffer pool.

Parameters
poolidIdentifier of the buffer pool to free, as returned by bfpalloc().
Returns
::OK if the buffer pool was valid and was successfully freed; otherwise ::SYSERR. If poolid specified a valid buffer pool, then this function can only return ::SYSERR as a result of memory corruption.
syscall buffree ( void *  buffer)

Return a buffer to its buffer pool.

Parameters
bufferAddress of buffer to free, as returned by bufget().
Returns
::OK if buffer was successfully freed; otherwise ::SYSERR. ::SYSERR can only be returned as a result of memory corruption or passing an invalid buffer argument.
void* bufget_ ( int  poolid,
const char *  file,
const char *  func 
)

Allocate a buffer from a buffer pool. If no buffers are currently available, this function wait until one is, usually rescheduling the thread. The returned buffer must be freed with buffree() when the calling code is finished with it.

Parameters
poolidIdentifier of the buffer pool, as returned by bfpalloc().
Returns
If poolid does not specify a valid buffer pool, returns ::SYSERR; otherwise returns a pointer to the resulting buffer.
syscall memfree ( void *  memptr,
uint  nbytes 
)

Frees a block of heap-allocated memory.

Parameters
memptrPointer to memory block allocated with memget().
nbytesLength of memory block, in bytes. (Same value passed to memget().)
Returns
::OK on success; ::SYSERR on failure. This function can only fail because of memory corruption or specifying an invalid memory block.
void* memget ( uint  nbytes)

Allocate heap memory.

Parameters
nbytesNumber of bytes requested.
Returns
::SYSERR if nbytes was 0 or there is no memory to satisfy the request; otherwise returns a pointer to the allocated memory region. The returned pointer is guaranteed to be 8-byte aligned. Free the block with memfree() when done with it.
void* stkget ( uint  nbytes)

Allocate stack memory.

Parameters
nbytesNumber of bytes requested.
Returns
::SYSERR if nbytes was 0 or there is no memory to satisfy the request; otherwise returns a pointer to the topmost (highest address) word of the allocated memory region. The intention is that this is the base of a stack growing down. Free the stack with stkfree() when done with it.