📄 erc.c
字号:
/* contains the memory allocation specified by the caller (target). */
/* */
/* CALLED BY */
/* */
/* ERC_Deallocate_Memory */
/* */
/* CALLS */
/* */
/* memcmp (CLIB_memcmp) */
/* ERC_System_Error */
/* */
/* INPUTS */
/* */
/* target memory allocation to find */
/* */
/* OUTPUTS */
/* */
/* ER_DEBUG_ALLOCATION ER_DEBUG_ALLOCATION that contains*/
/* target. */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/*************************************************************************/
static ER_DEBUG_ALLOCATION *ERC_Memory_To_Debug(VOID *target)
{
INT dataOffset;
ER_DEBUG_ALLOCATION *walk;
ER_DEBUG_ALLOCATION *to_find;
dataOffset = (INT)(((ER_DEBUG_ALLOCATION *)0)->data);
to_find = (ER_DEBUG_ALLOCATION *)(((UNSIGNED_CHAR *)target) - dataOffset);
/* Invalid pointer, report no match found */
if((target == NULL) && (to_find == NULL))
return(NULL);
for (walk = ERD_RecentAllocation; ((walk != to_find) && (walk != NULL));
walk = walk->prev);
/* if no match was found */
if (walk != NULL)
{
/* Has the "HEAD" or "FOOT" been disturbed by a rouge pointer? */
if (memcmp((void *)ERD_MemoryAllocationHead,(void *)walk->head,4) != 0)
ERC_System_Error(NU_MEMORY_CORRUPT);
if (memcmp((void *)ERD_MemoryAllocationFoot,(void *)&(walk->data[walk->size]),4) != 0)
ERC_System_Error(NU_MEMORY_CORRUPT);
}
return(walk);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* ERC_Remove_Debug_Allocation */
/* */
/* DESCRIPTION */
/* */
/* This function removes an ER_DEBUG_ALLOCATION from the linked list*/
/* */
/* CALLED BY */
/* */
/* ERC_Deallocate_Memory */
/* */
/* CALLS */
/* */
/* none */
/* */
/* INPUTS */
/* */
/* target ER_DEBUG_ALLOCATION to remove */
/* */
/* OUTPUTS */
/* */
/* STATUS status of the operation */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/*************************************************************************/
static STATUS ERC_Remove_Debug_Allocation(ER_DEBUG_ALLOCATION *target)
{
ER_DEBUG_ALLOCATION *walk;
if (target == NULL)
return(NU_INVALID_POINTER);
/* If the list is empty nothing can be removed! */
if (ERD_RecentAllocation == NULL)
return(NU_EMPTY_DEBUG_ALLOCATION_LIST);
/* If there is only one item on the list. */
if (ERD_RecentAllocation->prev == NULL)
{
/* If the only item on the list is the one to be removed...*/
if (ERD_RecentAllocation == target)
{
ERD_RecentAllocation = NULL;
return(NU_SUCCESS);
}
else
return(NU_INVALID_DEBUG_ALLOCATION);
}
if (ERD_RecentAllocation == target)
{
ERD_RecentAllocation->prev = target->prev;
return(NU_SUCCESS);
}
/* Walk the entire list until walk->prev is the target. */
walk = ERD_RecentAllocation;
while (NU_TRUE)
{
if (walk->prev == target)
break;
if (walk->prev == NULL)
break;
walk = walk->prev;
}
/* target is last item on the list */
if (walk->prev == target)
{
walk->prev = target->prev;
return(NU_SUCCESS);
}
return(NU_INVALID_DEBUG_ALLOCATION);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* ERC_Append_Debug_Allocation */
/* */
/* DESCRIPTION */
/* */
/* This function appends an ER_DEBUG_ALLOCATION to the linked list. */
/* */
/* CALLED BY */
/* */
/* ERC_Allocate_Memory */
/* */
/* CALLS */
/* */
/* none */
/* */
/* INPUTS */
/* */
/* new_guy ER_DEBUG_ALLOCATION to append */
/* */
/* OUTPUTS */
/* */
/* STATUS status of the operation */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/*************************************************************************/
static STATUS ERC_Append_Debug_Allocation(ER_DEBUG_ALLOCATION *new_guy)
{
/* Either this is the first ER_DEBUG_ALLOCATION ever to be appended
or this is the first on a list that shrank to 0 element. */
if (ERD_AllocationCount == 0)
{
ERD_RecentAllocation = new_guy;
ERD_RecentAllocation->prev = NULL;
}
else
{
new_guy->prev = ERD_RecentAllocation;
ERD_RecentAllocation = new_guy;
}
return(NU_SUCCESS);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* ERC_Allocate_Memory */
/* */
/* DESCRIPTION */
/* */
/* This function tracks additional information regarding the memory */
/* allocation */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* CALLS */
/* */
/* ERC_Append_Debug_Allocation */
/* DMCE_Allocate_Memory */
/* memcpy */
/* */
/* INPUTS */
/* */
/* pool_ptr Memory pool pointer */
/* return_pointer Pointer to the destination */
/* memory pointer */
/* size Number of bytes requested */
/* suspend Suspension option if full */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS If service is successful */
/* NU_NO_MEMORY Memory not available */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -