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

📄 dce2_memory.c

📁 snort2.8.4版本
💻 C
📖 第 1 页 / 共 2 页
字号:
                dce2_memory.cl_act_max = dce2_memory.cl_act;            break;        case DCE2_MEM_TYPE__CL_FRAG:            dce2_memory.cl_frag += size;            if (dce2_memory.cl_frag > dce2_memory.cl_frag_max)                dce2_memory.cl_frag_max = dce2_memory.cl_frag;            break;        default:            return;    }    dce2_memory.cl_total += size;    if (dce2_memory.cl_total > dce2_memory.cl_total_max)        dce2_memory.cl_total_max = dce2_memory.cl_total;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/void DCE2_UnRegMem(uint32_t size, DCE2_MemType mtype){    switch (mtype)    {        case DCE2_MEM_TYPE__CONFIG:            dce2_memory.config -= size;            break;        case DCE2_MEM_TYPE__ROPTION:            dce2_memory.roptions -= size;            break;        case DCE2_MEM_TYPE__RT:            dce2_memory.rt -= size;            break;        case DCE2_MEM_TYPE__INIT:            dce2_memory.init -= size;            break;        case DCE2_MEM_TYPE__SMB_SSN:            dce2_memory.smb_total -= size;            dce2_memory.smb_ssn -= size;            break;        case DCE2_MEM_TYPE__SMB_SEG:            dce2_memory.smb_total -= size;            dce2_memory.smb_seg -= size;            break;        case DCE2_MEM_TYPE__SMB_UID:            dce2_memory.smb_total -= size;            dce2_memory.smb_uid -= size;            break;        case DCE2_MEM_TYPE__SMB_TID:            dce2_memory.smb_total -= size;            dce2_memory.smb_tid -= size;            break;        case DCE2_MEM_TYPE__SMB_FID:            dce2_memory.smb_total -= size;            dce2_memory.smb_fid -= size;            break;        case DCE2_MEM_TYPE__SMB_UT:            dce2_memory.smb_total -= size;            dce2_memory.smb_ut -= size;            break;        case DCE2_MEM_TYPE__SMB_PM:            dce2_memory.smb_total -= size;            dce2_memory.smb_pm -= size;            break;        case DCE2_MEM_TYPE__TCP_SSN:            dce2_memory.tcp_total -= size;            dce2_memory.tcp_ssn -= size;            break;        case DCE2_MEM_TYPE__CO_SEG:            dce2_memory.co_total -= size;            dce2_memory.co_seg -= size;            break;        case DCE2_MEM_TYPE__CO_FRAG:            dce2_memory.co_total -= size;            dce2_memory.co_frag -= size;            break;        case DCE2_MEM_TYPE__CO_CTX:            dce2_memory.co_total -= size;            dce2_memory.co_ctx -= size;            break;        case DCE2_MEM_TYPE__UDP_SSN:            dce2_memory.udp_total -= size;            dce2_memory.udp_ssn -= size;            break;        case DCE2_MEM_TYPE__CL_ACT:            dce2_memory.cl_total -= size;            dce2_memory.cl_act -= size;            break;        case DCE2_MEM_TYPE__HTTP_SSN:            dce2_memory.http_total -= size;            dce2_memory.http_ssn -= size;            break;        case DCE2_MEM_TYPE__CL_FRAG:            dce2_memory.cl_total -= size;            dce2_memory.cl_frag -= size;            break;        default:            DCE2_Log("%s(%d) => Invalid memory type\n", __FILE__, __LINE__);            break;    }    switch (mtype)    {        case DCE2_MEM_TYPE__CONFIG:        case DCE2_MEM_TYPE__ROPTION:        case DCE2_MEM_TYPE__RT:        case DCE2_MEM_TYPE__INIT:            break;        default:            dce2_memory.rtotal -= size;    }    dce2_memory.total -= size;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/static int DCE2_CheckMemcap(uint32_t size, DCE2_MemType mtype){    switch (mtype)    {        case DCE2_MEM_TYPE__CONFIG:        case DCE2_MEM_TYPE__ROPTION:        case DCE2_MEM_TYPE__RT:        case DCE2_MEM_TYPE__INIT:            break;        default:            if ((dce2_memory.rtotal + size) > DCE2_GcMemcap())            {                DCE2_Alert(NULL, DCE2_EVENT__MEMCAP);                dce2_mem_state = DCE2_MEM_STATE__MEMCAP;                return DCE2_MEMCAP_EXCEEDED;            }            break;    }    return DCE2_MEMCAP_OK;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/void * DCE2_Alloc(uint32_t size, DCE2_MemType mtype){    void *mem;    if (dce2_mem_state == DCE2_MEM_STATE__MEMCAP)        return NULL;    if (DCE2_CheckMemcap(size, mtype) != DCE2_MEMCAP_OK)        return NULL;    mem = calloc(1, (size_t)size);    if (mem == NULL)        DCE2_Die("DCE2_Alloc() => Out of memory!\n");    DCE2_RegMem(size, mtype);    return mem;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/void DCE2_Free(void *mem, uint32_t size, DCE2_MemType mtype){    if (mem == NULL)        return;    DCE2_UnRegMem(size, mtype);    free(mem);    if (dce2_mem_state == DCE2_MEM_STATE__MEMCAP)        dce2_mem_state = DCE2_MEM_STATE__OKAY;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/void * DCE2_ReAlloc(void *old_mem, uint32_t old_size, uint32_t new_size, DCE2_MemType mtype){    void *new_mem;    DCE2_Ret status;    if (dce2_mem_state == DCE2_MEM_STATE__MEMCAP)        return NULL;    if (old_mem == NULL)    {        DCE2_Log("%s(%d) => old memory passed in was NULL.\n", __FILE__, __LINE__);        return NULL;    }    else if (new_size < old_size)    {        DCE2_Log("%s(%d) => New size is less than old size.\n", __FILE__, __LINE__);        return NULL;    }    else if (new_size == old_size)    {        return old_mem;    }    if (DCE2_CheckMemcap(new_size - old_size, mtype) == DCE2_MEMCAP_EXCEEDED)        return NULL;    new_mem = DCE2_Alloc(new_size, mtype);    if (new_mem == NULL)        return NULL;    status = DCE2_Memcpy(new_mem, old_mem, old_size,                         new_mem, (void *)((uint8_t *)new_mem + new_size));    if (status != DCE2_RET__SUCCESS)    {        DCE2_Log("%s(%d) => Memcpy failed.\n", __FILE__, __LINE__);        DCE2_Free(new_mem, new_size, mtype);        return NULL;    }    DCE2_Free(old_mem, old_size, mtype);    return new_mem;}/******************************************************************** * Function: * * Purpose: * * Arguments: * * Returns: * ********************************************************************/void DCE2_MemInit(void){    memset(&dce2_memory, 0, sizeof(dce2_memory));}

⌨️ 快捷键说明

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