tw_cli_mem.c.svn-base
资源名称:cli.rar [点击查看]
上传用户:hujq123
上传日期:2016-04-10
资源大小:153k
文件大小:6k
源码类别:
Telnet服务器
开发平台:
Unix_Linux
- /*
- * Copyright (C) 2002 Koninklijke Philips Electronics N.V.,
- * All Rights Reserved.
- *
- * This source code and any compilation or derivative thereof is the
- * proprietary information of Koninklijke Philips Electronics N.V.
- * and is confidential in nature.
- * Under no circumstances is this software to be exposed to or placed
- * under an Open Source License of any type without the expressed
- * written permission of Koninklijke Philips Electronics N.V.
- *
- *###########################################################
- */
- /*!
- * file tw_cli_mem.c
- *
- * brief -
- *
- */
- /*-----------------------------------------------------------*
- *
- * %version: 3 %
- * instance: DS_6
- * %date_created: Fri Feb 21 08:04:35 2003 %
- *
- *###########################################################
- */
- /****************************************************************************
- *
- * Filename : tw_cli_mem.c
- * Purpose : CLI command objects and functions to support MEM commands.
- *
- *
- *****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tmtypes.h>
- #include "tw_cli.h"
- /*** 2nd level CLI Command Option - mem "check"
- ***/
- static int CliCoVoproc_MemCheck(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemCheck =
- {
- "check",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "check memory allocation list",
- NULL,
- CliCoVoproc_MemCheck,
- NULL
- };
- /*** 2nd level CLI Command Option - mem "detail"
- ***/
- static int CliCoVoproc_MemDetail(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemDetail =
- {
- "detail",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display details on all allocated memory blocks",
- NULL,
- CliCoVoproc_MemDetail,
- NULL
- };
- /*** 2nd level CLI Command Option - mem "summary"
- ***/
- static int CliCoVoproc_MemSummary(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemSummary =
- {
- "summary",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display summary of all allocated memory blocks",
- NULL,
- CliCoVoproc_MemSummary,
- NULL
- };
- /*** 2nd level CLI Command Option - mem "task"
- ***/
- static int CliCoVoproc_MemTask(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemTask =
- {
- "task",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display summary on a per task basis",
- NULL,
- CliCoVoproc_MemTask,
- NULL
- };
- /*** 2nd level CLI Command Option - mem "test"
- ***/
- static int CliCoVoproc_MemTest(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemTest =
- {
- "test",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "test memory wrapper error detection",
- NULL,
- CliCoVoproc_MemTest,
- NULL
- };
- /*** 2nd level CLI Command Option - mem "dump"
- ***/
- static int CliCoVoproc_MemDump(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_MemDump =
- {
- "dump",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "dislay contents of memory 0xADDR {LEN} {1 | 2 | 4}",
- NULL,
- NULL,
- CliCoVoproc_MemDump
- };
- /*** 1st level CLI Command Option - "mem"
- ***/
- Cli_CmdStruct_t *CliRcoOptionList_Mem[] =
- {
- &CliCo_MemCheck,
- &CliCo_MemDetail,
- &CliCo_MemSummary,
- &CliCo_MemTask,
- &CliCo_MemTest,
- &CliCo_MemDump,
- NULL
- };
- Cli_CmdStruct_t CliRco_Mem =
- {
- "mem",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- CliRcoOptionList_Mem,
- "Memory wrapper manipulation command",
- NULL,
- NULL,
- NULL
- };
- static int CliCoVoproc_MemTest(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- char *tp ;
- Cli_Printf(pSess, "test malloc() return of NULLn") ;
- tp = malloc(0x40000000) ;
- if (tp != NULL)
- {
- Cli_Printf(pSess, "ERROR: malloc did not return NULLn") ;
- }
- Cli_Printf(pSess, "test realloc() return of NULLn") ;
- tp = malloc(8) ;
- tp = realloc(tp, 0x40000000) ;
- if (tp != NULL)
- {
- Cli_Printf(pSess, "ERROR: realloc did not return NULLn") ;
- }
- Cli_Printf(pSess, "test free() of NULLn") ;
- free(NULL) ;
- Cli_Printf(pSess, "test free() of staticn") ;
- free((char *) &CliCo_MemTest) ;
- Cli_Printf(pSess, "test free() of textn") ;
- free((char *) free) ;
- Cli_Printf(pSess, "test free() of non-sdramn") ;
- free((char *) 0x80000000) ;
- Cli_Printf(pSess, "test clobbered prologuen") ;
- tp = malloc(8) ;
- tp[-1] = 0 ;
- free(tp) ;
- Cli_Printf(pSess, "test clobbered epiloguen") ;
- tp = malloc(8) ;
- tp[8] = 0 ;
- free(tp) ;
- return 0;
- }
- static int CliCoVoproc_MemDetail(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- TwMem_PrintDetail((Cli_Printf_t) Cli_Printf, (void *) pSess) ;
- return 0;
- }
- static int CliCoVoproc_MemCheck(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- UInt errors ;
- Cli_Printf(pSess, "scanning allocation listn") ;
- errors = TwMem_Check() ;
- if (errors != 0)
- {
- Cli_Printf(pSess, "TwMem_Check detected %d errorsn", errors) ;
- }
- else
- {
- Cli_Printf(pSess, "TwMem_Check passedn") ;
- }
- return 0;
- }
- static int CliCoVoproc_MemSummary(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- TwMem_PrintSummary((Cli_Printf_t) Cli_Printf, (void *) pSess) ;
- return 0;
- }
- static int CliCoVoproc_MemTask(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- TwMem_PrintTaskSummary((Cli_Printf_t) Cli_Printf, (void *) pSess) ;
- return 0;
- }
- static int CliCoVoproc_MemDump(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- UInt32 Addr;
- int Len;
- int Width;
- Cli_PrintFormat_e eFormat;
- int Params;
- Len = 128;
- Width = 1;
- Params = sscanf(CmdStr + Ptr, "0x%x %d %d", &Addr, &Len, &Width);
- if (Params < 1 || Len == 0 || Len > 10000 ||
- (Width != 1 && Width != 2 && Width != 4))
- {
- Cli_Printf(pSess, badParamStr);
- Cli_Printf(pSess, "Example Usage: mem dump 0xffc904 128 4n");
- return 0;
- }
- if (Width == 4)
- {
- eFormat = CLI_PRINT_DATA_FORMAT_HEX32;
- }
- else if (Width == 2)
- {
- eFormat = CLI_PRINT_DATA_FORMAT_HEX16;
- }
- else
- {
- eFormat = CLI_PRINT_DATA_FORMAT_HEX8;
- }
- Cli_PrintData(pSess, (void *)Addr, Len, eFormat, False);
- return 0;
- }