• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/statfs.h>
33 #include <sys/mount.h>
34 #include "proc_fs.h"
35 
36 #ifdef LOSCFG_SHELL_CMD_DEBUG
37 #include "los_vm_map.h"
38 #include "los_vm_dump.h"
39 #include "los_vm_lock.h"
40 #include "los_process_pri.h"
41 
42 #ifdef LOSCFG_KERNEL_VM
43 
OsVmDumpSeqSpaces(struct SeqBuf * seqBuf)44 STATIC VOID OsVmDumpSeqSpaces(struct SeqBuf *seqBuf)
45 {
46     LosVmSpace *space = NULL;
47     LosVmMapRegion *region = NULL;
48     LosRbNode *pstRbNode = NULL;
49     LosRbNode *pstRbNodeNext = NULL;
50     UINT32 pssPages = 0;
51     UINT32 spacePages;
52     UINT32 regionPages;
53     LosProcessCB *pcb = NULL;
54     LOS_DL_LIST *aspaceList = LOS_GetVmSpaceList();
55     LosMux *aspaceListMux = OsGVmSpaceMuxGet();
56 
57     (VOID)LOS_MuxAcquire(aspaceListMux);
58     LOS_DL_LIST_FOR_EACH_ENTRY(space, aspaceList, LosVmSpace, node) {
59         (VOID)LOS_MuxAcquire(&space->regionMux);
60         spacePages = OsCountAspacePages(space);
61         pcb = OsGetPIDByAspace(space);
62         if (pcb == NULL) {
63             (VOID)LOS_MuxRelease(&space->regionMux);
64             continue;
65         }
66         (VOID)LosBufPrintf(seqBuf, "\r\n PID    aspace     name       base       size     pages \n");
67         (VOID)LosBufPrintf(seqBuf, " ----   ------     ----       ----       -----     ----\n");
68         (VOID)LosBufPrintf(seqBuf, " %-4d %#010x %-10.10s %#010x %#010x %d\n",
69                            pcb->processID, space, pcb->processName, space->base, space->size, spacePages);
70         (VOID)LosBufPrintf(seqBuf,
71             "\r\n\t region      name                base       size       mmu_flags      pages   pg/ref\n");
72         (VOID)LosBufPrintf(seqBuf,
73             "\t ------      ----                ----       ----        ---------      -----   -----\n");
74 
75         RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)
76             region = (LosVmMapRegion *)pstRbNode;
77             regionPages = OsCountRegionPages(space, region, &pssPages);
78             CHAR *flagsStr = OsArchFlagsToStr(region->regionFlags);
79             if (flagsStr == NULL) {
80                 break;
81             }
82             (VOID)LosBufPrintf(seqBuf, "\t %#010x  %-19.19s %#010x %#010x  %-15.15s %4d    %4d\n",
83                 region, OsGetRegionNameOrFilePath(region), region->range.base,
84                 region->range.size, flagsStr, regionPages, pssPages);
85             (VOID)LOS_MemFree(m_aucSysMem0, flagsStr);
86             (VOID)OsRegionOverlapCheck(space, region);
87         RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
88         (VOID)LOS_MuxRelease(&space->regionMux);
89     }
90     (VOID)LOS_MuxRelease(aspaceListMux);
91 }
92 
VmmProcFill(struct SeqBuf * m,void * v)93 static int VmmProcFill(struct SeqBuf *m, void *v)
94 {
95     (void)v;
96     OsVmDumpSeqSpaces(m);
97 
98     return 0;
99 }
100 
101 static const struct ProcFileOperations VMM_PROC_FOPS = {
102     .write      = NULL,
103     .read       = VmmProcFill,
104 };
105 
ProcVmmInit(void)106 void ProcVmmInit(void)
107 {
108     struct ProcDirEntry *pde = CreateProcEntry("vmm", 0, NULL);
109     if (pde == NULL) {
110         PRINT_ERR("create /proc/vmm error!\n");
111         return;
112     }
113 
114     pde->procFileOps = &VMM_PROC_FOPS;
115 }
116 #endif
117 #endif
118