HeapMemory.asm

This file defines heap memory management functions of PwnOS.

See Also

Authors

  • Neil G.  Dickson
Summary
HeapMemory.asmThis file defines heap memory management functions of PwnOS.
Functions
InitializeHeapMemoryThis procedure allocates the heap memory, and initializes the header and first free range node.
AllocateAlignedMemoryThis procedure allocates a range of memory on the heap, aligned to a multiple of a power of 2 bytes.
AllocateMemoryThis procedure allocates a range of memory on the heap.
FreeMemoryThis procedure frees a range of memory that is allocated on the heap.
AddHeapMemoryAddressNodeThis procedure adds a node to the address tree.
AddHeapMemoryFreeNodeThis procedure adds a node to the free tree.
RemoveHeapMemoryFreeNodeThis procedure removes a node from the free tree.
RemoveHeapMemoryAddressNodeThis procedure removes a node from the address tree.
RebalanceHeapMemoryFreeNodeThis procedure rebalances from a node in the free tree.
RebalanceHeapMemoryAddressNodeThis procedure rebalances from a node in the address tree.
Gateway Functions of HeapMemory.asm
Functions
AllocateMemoryUGateway function for AllocateMemory
AllocateAlignedMemoryUGateway function for AllocateAlignedMemory
FreeMemoryUGateway function for FreeMemory

Functions

InitializeHeapMemory

This procedure allocates the heap memory, and initializes the header and first free range node.

This is intended to only be called by CreateProcess

Parameters

nPagesnumber of pages for heap and its trees
pHeapaddress of the heap memory header

AllocateAlignedMemory

This procedure allocates a range of memory on the heap, aligned to a multiple of a power of 2 bytes.

TODO: Still need to adjust size of last free range due to change in size of Address Tree TODO: Check for best fit instead of doing the faster option of rounding up size to multiple of alignment.

Parameters

nBytesnumber of bytes to allocate
Alignmentminimum required power of 2 bytes to which the memory range must be aligned
pHeapaddress of the heap memory header

Returns

  • address of memory range on the heap, or NULL if there is no free memory range large enough

AllocateMemory

This procedure allocates a range of memory on the heap.

TODO: Still need to adjust size of last free range due to change in size of Address Tree

Parameters

nBytesnumber of bytes to allocate
pHeapaddress of the heap memory header

Returns

  • address of memory range on the heap, or NULL if there is no free memory range large enough

FreeMemory

This procedure frees a range of memory that is allocated on the heap.

TODO: Still need to adjust size of last free range due to change in size of Address Tree

Parameters

Addressaddress of memory range on the heap
pHeapaddress of the heap memory header

AddHeapMemoryAddressNode

This procedure adds a node to the address tree.

Parameters

edxaddress of the node to add (not the address it represents)
eaxaddress of the node in the tree at which to start the search for placement
ebxaddress of heap memory header

AddHeapMemoryFreeNode

This procedure adds a node to the free tree.

Parameters

edxaddress of the node to add (not the address it represents)
eaxaddress of the node in the tree at which to start the search for placement
ebxaddress of heap memory header

RemoveHeapMemoryFreeNode

This procedure removes a node from the free tree.

Parameters

edxaddress of the node to remove (not the address it represents)
ebxaddress of heap memory header

RemoveHeapMemoryAddressNode

This procedure removes a node from the address tree.

Parameters

edxaddress of the node to remove (not the address it represents)
ebxaddress of heap memory header

RebalanceHeapMemoryFreeNode

This procedure rebalances from a node in the free tree.

Parameters

edxaddress of the node at which to start rebalancing (not the address it represents)
ebxaddress of heap memory header

Returns

eaxaddress of the node that is now in the position of the given node

RebalanceHeapMemoryAddressNode

This procedure rebalances from a node in the address tree.

Parameters

edxaddress of the node at which to start rebalancing (not the address it represents)
ebxaddress of heap memory header

Returns

eaxaddress of the node that is now in the position of the given node

Gateway Functions of HeapMemory.asm

Summary

Functions

AllocateMemoryU

Gateway function for AllocateMemory

TODO: Check parameter.

AllocateAlignedMemoryU

Gateway function for AllocateAlignedMemory

TODO: Check parameters.

FreeMemoryU

Gateway function for FreeMemory

TODO: Check parameter.

This procedure allocates a range of memory on the heap.
This procedure allocates a range of memory on the heap, aligned to a multiple of a power of 2 bytes.
This procedure frees a range of memory that is allocated on the heap.
This file defines constants, structures, and macros for heap memory management functions of PwnOS.
This procedure creates a new process.