⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erc.c

📁 test file nucleus source
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      NU_TIMEOUT                          If timeout on service        *//*      NU_POOL_DELETED                     If memory pool deleted       *//*                                            during suspension          *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         DATE                    REMARKS                               *//*                                                                       *//*************************************************************************/STATUS ERC_Allocate_Memory(NU_MEMORY_POOL *pool_ptr, VOID **ptr,                           UNSIGNED size, UNSIGNED suspend,                            unsigned long line, const char* file){    ER_DEBUG_ALLOCATION **debug_ptr;    STATUS status = NU_SUCCESS;    /* If the allocation is not from the pool specified in the        NU_DEBUG_POOL macro then allocate memory normally (no meta-data) */    if(&NU_DEBUG_POOL != pool_ptr)        return(DMCE_Allocate_Memory(pool_ptr, ptr, size, suspend));    /* This call allocates memory for a structure that will contain the        users data and the meta-data used to find memory problems */    status = DMCE_Allocate_Memory(pool_ptr, ptr,        (sizeof(ER_DEBUG_ALLOCATION) + size + 4), suspend);    if (status != NU_SUCCESS)        return status;    /* From here out, debug_ptr is used because it is typed.  In the end       ptr will be set to point to debug_ptr->data, where the user will       put the data. */    debug_ptr = (ER_DEBUG_ALLOCATION **)ptr;    /* Record file and line where the application made the allocation */    (*debug_ptr)->line = line;    (*debug_ptr)->file = file;    /* Set "HEAD" and "FOOT" boundary markers */    memcpy((*debug_ptr)->head,ERD_MemoryAllocationHead,4);    memcpy(&((*debug_ptr)->data[size]),ERD_MemoryAllocationFoot,4);    /* Record the size */    (*debug_ptr)->size = size;    /* This links debug_ptr to a linked list that holds all the       ER_DEBUG_ALLOCATION structures. */    ERC_Append_Debug_Allocation((*debug_ptr));    (*debug_ptr)->AllocSequenceCounter = ERD_AllocationSequenceCounter++;    ERD_TotalMemoryAllocated += size;    ERD_TotalMemoryAllocations++;    ERD_AllocationCount++;    if (ERD_MaxTotalMemoryAllocated < ERD_TotalMemoryAllocated)        ERD_MaxTotalMemoryAllocated = ERD_TotalMemoryAllocated;    if (ERD_MaxTotalMemoryAllocations < ERD_TotalMemoryAllocations)        ERD_MaxTotalMemoryAllocations = ERD_TotalMemoryAllocations;    /* Return pointer to the data field of debug allocation by reference */    (*ptr) = (*debug_ptr)->data;   return(status);}/*************************************************************************//*                                                                       *//* FUNCTION                                                              *//*                                                                       *//*      ERC_Deallocate_Memory                                              *//*                                                                       *//* DESCRIPTION                                                           *//*                                                                       *//*      This function tracks additional information regarding the memory *//*      deallocation.                                                    *//*                                                                       *//* CALLED BY                                                             *//*                                                                       *//*      Application                                                      *//*                                                                       *//* CALLS                                                                 *//*                                                                       *//*      ERC_Memory_To_Debug                                              *//*      ERC_Remove_Debug_Allocation                                      *//*      DMCE_Deallocate_Memory                                           *//*                                                                       *//* INPUTS                                                                *//*                                                                       *//*      ptr                                 Pointer to dynamic memory    *//*                                                                       *//* OUTPUTS                                                               *//*                                                                       *//*      NU_SUCCESS                                                       *//*      NU_INVALID_POINTER                  Returned when ptr is null or *//*                                            when there is no           *//*                                            corresponding              *//*                                            ER_DEBUG_ALLOCATION        *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         DATE                    REMARKS                               *//*                                                                       *//*************************************************************************/STATUS ERC_Deallocate_Memory(VOID *ptr){    ER_DEBUG_ALLOCATION *target;    STATUS status;    if (ptr == NULL)        return(NU_INVALID_POINTER);    /* Find the NU_DEBUG_ALLOCATION ptr refers to.  After this call,        (&(target->data) == ptr) or (target == NULL). */    target = ERC_Memory_To_Debug(ptr);    /* Remove target from the linked list of ER_DEBUG_ALLOCATIONs */    status = ERC_Remove_Debug_Allocation(target);    if ((status != 0) || (target == NULL))        return(NU_INVALID_POINTER);            /* Maintain status variables */    ERD_TotalMemoryAllocated -= target->size;    ERD_TotalMemoryAllocations--;    ERD_AllocationCount--;    return(DMCE_Deallocate_Memory(target));}#endif /* NU_DEBUG_MEMORY *//**************************************************************************  This routine should appear last in this file and must *NOT* use the  NU_ASSERT macro.**************************************************************************/#ifdef NU_ASSERT                  /* Don't use NU_ASSERT past this point */#undef NU_ASSERT#define NU_ASSERT(ignore) ((void) 0)#endif#ifdef NU_ASSERT2#undef NU_ASSERT2#define NU_ASSERT2(ignore) ((void) 0)#endif/*************************************************************************//*                                                                       *//* FUNCTION                                                              *//*                                                                       *//*      ERC_Assert                                                       *//*                                                                       *//* DESCRIPTION                                                           *//*                                                                       *//*      This public routine is called when an assertion made by the      *//*      NU_ASSERT (or NU_ASSERT2) macro fails.  By default, this routine *//*      simply counts the number of failed assertions.  A breakpoint can *//*      be set in the routine to observe failed assertions, or the       *//*      routine can be customized to perform some action, such as        *//*      printing the failed assertion as a message, etc.                 *//*                                                                       *//* CALLED BY                                                             *//*                                                                       *//*      NU_ASSERT macro                                                  *//*      NU_ASSERT2 macro                                                 *//*                                                                       *//* CALLS                                                                 *//*                                                                       *//*      None                                                             *//*                                                                       *//* INPUTS                                                                *//*                                                                       *//*      test               Pointer to string of failed assertion test    *//*      name               File name of file containing failed assertion *//*      line               Location of failed assertion in above file    *//*                                                                       *//* OUTPUTS                                                               *//*                                                                       *//*      None                                                             *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*          NAME            DATE                    REMARKS              *//*                                                                       *//*      Todd C. Larsen    09-01-1998        Created initial revision     *//*                                                                       *//*************************************************************************/#ifdef NU_DEBUGvoid ERC_Assert(CHAR *test, CHAR *name, UNSIGNED line){NU_SUPERV_USER_VARIABLES#ifdef  NU_ENABLE_HISTORY    /* Make an entry that corresponds to this function in the system history       log.  */    HIC_Make_History_Entry(NU_ASSERT_ID, (UNSIGNED) test,                        (UNSIGNED) name, line);#endif    /* Switch to supervisor mode */    NU_SUPERVISOR_MODE();    /* Set breakpoint here to catch failed assertions. */    ERD_Assert_Count += 1;    /* Return to user mode */    NU_USER_MODE();}#endif /* NU_DEBUG */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -