更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_vm_map.h
浏览该文件的文档.
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/**
33 * @defgroup los_vm_map vm mapping management
34 * @ingroup kernel
35 */
36
37#ifndef __LOS_VM_MAP_H__
38#define __LOS_VM_MAP_H__
39
40#include "los_typedef.h"
41#include "los_arch_mmu.h"
42#include "los_mux.h"
43#include "los_rbtree.h"
44#include "los_vm_syscall.h"
45#include "los_vm_zone.h"
46#include "los_vm_common.h"
47
48struct Vnode;
49#ifdef __cplusplus
50#if __cplusplus
51extern "C" {
52#endif /* __cplusplus */
53#endif /* __cplusplus */
54#if 0 // @note_#if0
55file结构体来自 ..\third_party\NuttX\include\nuttx\fs\fs.h
56struct file //打开文件的基本表示形式
57{
58 unsigned int f_magicnum; /* file magic number */
59 int f_oflags; /* Open mode flags */
60 FAR struct inode *f_inode; /* Driver interface */
61 loff_t f_pos; /* File position */
62 unsigned long f_refcount; /* reference count */
63 char *f_path; /* File fullpath */
64 void *f_priv; /* Per file driver private data */
65 const char *f_relpath; /* realpath */
66 struct page_mapping *f_mapping; /* mapping file to memory */
67 void *f_dir; /* DIR struct for iterate the directory if open a directory */
68};
69
70struct page_mapping {
71 LOS_DL_LIST page_list; /* all pages */
72 SPIN_LOCK_S list_lock; /* lock protecting it */
73 LosMux mux_lock; /* mutex lock */
74 unsigned long nrpages; /* number of total pages */
75 unsigned long flags;
76 Atomic ref; /* reference counting */
77 struct file *host; /* owner of this mapping */
78};
79#endif
80/* If the kernel malloc size is less than 16k, use heap, otherwise use physical pages */
81#define KMALLOC_LARGE_SIZE (PAGE_SIZE << 2)
82
83typedef struct VmMapRange {//线性区范围结构体
84 VADDR_T base; /**< vm region base addr | 线性区基地址*/
85 UINT32 size; /**< vm region size | 线性区大小*/
87
88struct VmMapRegion;
90struct VmFileOps;
91typedef struct VmFileOps LosVmFileOps;
92struct VmSpace;
93typedef struct VmSpace LosVmSpace;
94/// 缺页结构信息体
95typedef struct VmFault {
96 UINT32 flags; /*! FAULT_FLAG_xxx flags | 缺页标识*/
97 unsigned long pgoff; /*! Logical page offset based on region | 基于线性区的逻辑页偏移量*/
98 VADDR_T vaddr; /*! Faulting virtual address | 产生缺页的虚拟地址*/
99 VADDR_T *pageKVaddr; /*! KVaddr of pagefault's vm page's paddr | page cache中的虚拟地址*/
101/// 虚拟内存文件操作函数指针,上层开发可理解为 class 里的方法,注意是对线性区的操作 , 文件操作 见于g_commVmOps
102struct VmFileOps {
103 void (*open)(struct VmMapRegion *region); ///< 打开
104 void (*close)(struct VmMapRegion *region); ///< 关闭
105 int (*fault)(struct VmMapRegion *region, LosVmPgFault *pageFault); ///< 缺页,OsVmmFileFault
106 void (*remove)(struct VmMapRegion *region, LosArchMmu *archMmu, VM_OFFSET_T offset); ///< 删除 OsVmmFileRemove
107};
108
109/*!
110 线性区描述符,内核通过线性区管理虚拟地址,而线性地址就是虚拟地址
111 在内核里,用户空间的进程要访问内存或磁盘里的数据要通过映射的方式将内存的物理地址和用户空间的虚拟地址联系起来.
112 用户通过访问这样的虚拟地址就可以访问到实际的物理地址,也就是实际的物理内存. 映射在实现虚拟地址到物理地址中扮演
113 重要角色. 内核中映射分为文件映射和匿名映射. 文件映射就是磁盘中的数据通过文件系统映射到内存再通过文件映射映射到
114 虚拟空间.这样,用户就可以在用户空间通过 open ,read, write 等函数区操作文件内容. 匿名映射就是用户空间需要分配一定
115 的物理内存来存储数据,这部分内存不属于任何文件,内核就使用匿名映射将内存中的 某段物理地址与用户空间一一映射,
116 这样用户就可用直接操作虚拟地址来范围这段物理内存. 至于实际的代码,文件映射的操作就是: open,read,write,close,mmap...
117 操作的虚拟地址都属于文件映射. malloc 分配的虚拟地址属于匿名映射.
118*/
120 LosRbNode rbNode; /**< region red-black tree node | 红黑树节点,通过它将本线性区挂在VmSpace.regionRbTree*/
121 LosVmSpace *space; ///< 所属虚拟空间,虚拟空间由多个线性区组成
122 LOS_DL_LIST node; /**< region dl list | 链表节点,通过它将本线性区挂在VmSpace.regions上 ,但最新版本没有regions了,可以删除了 */
123 LosVmMapRange range; /**< region address range | 记录线性区的范围*/
124 VM_OFFSET_T pgOff; /**< region page offset to file | 以文件开始处的偏移量, 必须是分页大小的整数倍, 通常为0, 表示从文件头开始映射。*/
125 UINT32 regionFlags; /**< region flags: cow, user_wired | 线性区标签*/
126 UINT32 shmid; /**< shmid about shared region | shmid为共享线性区id,id背后就是共享线性区*/
127 UINT8 forkFlags; /**< vm space fork flags: COPY, ZERO, | 线性区标记方式*/
128 UINT8 regionType; /**< vm region type: ANON, FILE, DEV | 映射类型是匿名,文件,还是设备,所谓匿名可理解为内存映射*/
129 union {
130 struct VmRegionFile {// <磁盘文件 , 物理内存, 用户进程虚拟地址空间 >
131 int f_oflags; ///< 读写标签
132 struct Vnode *vnode;///< 文件索引节点
133 const LosVmFileOps *vmFOps;///< 文件处理各操作接口,open,read,write,close,mmap
134 } rf;
135 //匿名映射是指那些没有关联到文件页,如进程堆、栈、数据段和任务已修改的共享库等与物理内存的映射
136 struct VmRegionAnon {//<swap区 , 物理内存, 用户进程虚拟地址空间 >
137 LOS_DL_LIST node; /**< region LosVmPage list | 线性区虚拟页链表*/
138 } ra;
139 struct VmRegionDev {//设备映射,也是一种文件
140 LOS_DL_LIST node; /**< region LosVmPage list | 线性区虚拟页链表*/
141 const LosVmFileOps *vmFOps; ///< 操作设备像操作文件一样方便.
142 } rd;
144};
145/// 虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
146typedef struct VmSpace {
147 LOS_DL_LIST node; /**< vm space dl list | 节点,通过它挂到全局虚拟空间 g_vmSpaceList 链表上*/
148 LosRbTree regionRbTree; /**< region red-black tree root | 采用红黑树方式管理本空间各个线性区*/
149 LosMux regionMux; /**< region list mutex lock | 虚拟空间操作红黑树互斥锁*/
150 VADDR_T base; /**< vm space base addr | 虚拟空间的基地址,线性区的分配范围,常用于判断地址是否在内核还是用户空间*/
151 UINT32 size; /**< vm space size | 虚拟空间大小*/
152 VADDR_T heapBase; /**< vm space heap base address | 堆区基地址,指向堆区起点*/
153 VADDR_T heapNow; /**< vm space heap base now | 堆顶地址,指向堆区终点,do_brk()直接修改堆的大小返回新的堆区结束地址, heapNow >= heapBase*/
154 LosVmMapRegion *heap; /**< heap region | 传说中的堆区,用于满足进程的动态内存需求,大家熟知的malloc,realloc,free其实就是在操作这个区*/
155 VADDR_T mapBase; /**< vm space mapping area base | 虚拟空间映射区基地址,L1,L2表存放在这个区 */
156 UINT32 mapSize; /**< vm space mapping area size | 虚拟空间映射区大小,映射区是个很大的区。*/
157 LosArchMmu archMmu; /**< vm mapping physical memory | MMU记录<虚拟地址,物理地址>的映射情况 */
158#ifdef LOSCFG_DRIVERS_TZDRIVER
159 VADDR_T codeStart; /**< user process code area start | 代码区开始位置 */
160 VADDR_T codeEnd; /**< user process code area end | 代码区结束位置 */
161#endif
162} LosVmSpace;
163
164#define VM_MAP_REGION_TYPE_NONE (0x0) ///< 初始化使用
165#define VM_MAP_REGION_TYPE_ANON (0x1) ///< 匿名映射线性区
166#define VM_MAP_REGION_TYPE_FILE (0x2) ///< 文件映射线性区
167#define VM_MAP_REGION_TYPE_DEV (0x4) ///< 设备映射线性区
168#define VM_MAP_REGION_TYPE_MASK (0x7) ///< 映射线性区掩码
169
170/* the high 8 bits(24~31) should reserved, shm will use it */
171#define VM_MAP_REGION_FLAG_CACHED (0<<0) ///< 缓冲区
172#define VM_MAP_REGION_FLAG_UNCACHED (1<<0) ///< 非缓冲区
173#define VM_MAP_REGION_FLAG_UNCACHED_DEVICE (2<<0) /* only exists on some arches, otherwise UNCACHED */
174#define VM_MAP_REGION_FLAG_STRONGLY_ORDERED (3<<0) /* only exists on some arches, otherwise UNCACHED */
175#define VM_MAP_REGION_FLAG_CACHE_MASK (3<<0) ///< 缓冲区掩码
176#define VM_MAP_REGION_FLAG_PERM_USER (1<<2) ///< 用户空间永久区,PERM表示常驻区,可理解为非栈,非堆区
177#define VM_MAP_REGION_FLAG_PERM_READ (1<<3) ///< 永久可读取区
178#define VM_MAP_REGION_FLAG_PERM_WRITE (1<<4) ///< 永久可写入区
179#define VM_MAP_REGION_FLAG_PERM_EXECUTE (1<<5) ///< 永久可被执行区
180#define VM_MAP_REGION_FLAG_PROT_MASK (0xF<<2) ///< 访问权限掩码
181#define VM_MAP_REGION_FLAG_NS (1<<6) /* NON-SECURE */
182#define VM_MAP_REGION_FLAG_SHARED (1<<7) ///< MAP_SHARED:把对该内存段的修改保存到磁盘文件中 详见 OsCvtProtFlagsToRegionFlags ,要和 VM_MAP_REGION_FLAG_SHM区别理解
183#define VM_MAP_REGION_FLAG_PRIVATE (1<<8) ///< MAP_PRIVATE:内存段私有,对它的修改值仅对本进程有效,详见 OsCvtProtFlagsToRegionFlags。
184#define VM_MAP_REGION_FLAG_FLAG_MASK (3<<7) ///< 掩码
185#define VM_MAP_REGION_FLAG_STACK (1<<9) ///< 线性区的类型:栈区
186#define VM_MAP_REGION_FLAG_HEAP (1<<10) ///< 线性区的类型:堆区
187#define VM_MAP_REGION_FLAG_DATA (1<<11) ///< data数据区 编译在ELF中
188#define VM_MAP_REGION_FLAG_TEXT (1<<12) ///< 代码区
189#define VM_MAP_REGION_FLAG_BSS (1<<13) ///< bbs数据区 由运行时动态分配,bss段(Block Started by Symbol segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域。
190#define VM_MAP_REGION_FLAG_VDSO (1<<14) ///< VDSO(Virtual Dynamic Shared Object,虚拟动态共享库)由内核提供的虚拟.so文件,它不在磁盘上,而在内核里,内核将其映射到一个地址空间中,被所有程序共享,正文段大小为一个页面。
191#define VM_MAP_REGION_FLAG_MMAP (1<<15) ///< 映射区,虚拟空间内有专门用来存储<虚拟地址-物理地址>映射的区域
192#define VM_MAP_REGION_FLAG_SHM (1<<16) ///< 共享内存区, 被多个进程线性区映射
193#define VM_MAP_REGION_FLAG_FIXED (1<<17) ///< 线性区被填满
194#define VM_MAP_REGION_FLAG_FIXED_NOREPLACE (1<<18) ///< 线性区不被替换
195#define VM_MAP_REGION_FLAG_INVALID (1<<19) /* indicates that flags are not specified */
196/// 从外部权限标签转化为线性区权限标签
197STATIC INLINE UINT32 OsCvtProtFlagsToRegionFlags(unsigned long prot, unsigned long flags)
198{
199 UINT32 regionFlags = 0;
200
201 regionFlags |= VM_MAP_REGION_FLAG_PERM_USER; //必须是用户空间区
202 regionFlags |= (prot & PROT_READ) ? VM_MAP_REGION_FLAG_PERM_READ : 0; //映射区可被读
203 regionFlags |= (prot & PROT_WRITE) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE) : 0;
204 regionFlags |= (prot & PROT_EXEC) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE) : 0;
205 regionFlags |= (flags & MAP_SHARED) ? VM_MAP_REGION_FLAG_SHARED : 0;
206 regionFlags |= (flags & MAP_PRIVATE) ? VM_MAP_REGION_FLAG_PRIVATE : 0;
207 regionFlags |= (flags & MAP_FIXED) ? VM_MAP_REGION_FLAG_FIXED : 0;
208 regionFlags |= (flags & MAP_FIXED_NOREPLACE) ? VM_MAP_REGION_FLAG_FIXED_NOREPLACE : 0;
209
210 return regionFlags;
211}
212/// 虚拟地址是否在内核空间
213STATIC INLINE BOOL LOS_IsKernelAddress(VADDR_T vaddr)
214{
215 return ((vaddr >= (VADDR_T)KERNEL_ASPACE_BASE) &&
216 (vaddr <= ((VADDR_T)KERNEL_ASPACE_BASE + ((VADDR_T)KERNEL_ASPACE_SIZE - 1))));
217}
218/// 给定地址范围是否都在内核空间中
219STATIC INLINE BOOL LOS_IsKernelAddressRange(VADDR_T vaddr, size_t len)
220{
221 return (vaddr + len > vaddr) && LOS_IsKernelAddress(vaddr) && (LOS_IsKernelAddress(vaddr + len - 1));
222}
223/// 获取线性区的结束地址
225{
226 return (region->range.base + region->range.size - 1);
227}
228/// 获取线性区大小
229STATIC INLINE size_t LOS_RegionSize(VADDR_T start, VADDR_T end)
230{
231 return (end - start + 1);
232}
233/// 是否为文件映射区
235{
236 return region->regionType == VM_MAP_REGION_TYPE_FILE;
237}
238/// permanent 用户进程永久/常驻区
240{
241 return ((region->regionFlags & VM_MAP_REGION_FLAG_PROT_MASK) ==
242 (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ));
243}
244/// 是否为私有线性区
246{
247 return ((region->regionFlags & VM_MAP_REGION_FLAG_FLAG_MASK) == VM_MAP_REGION_FLAG_PRIVATE);
248}
249/// 设置线性区为文件映射
250STATIC INLINE VOID LOS_SetRegionTypeFile(LosVmMapRegion* region)
251{
252 region->regionType = VM_MAP_REGION_TYPE_FILE;
253}
254/// 是否为设备映射线性区 /dev/...
256{
257 return region->regionType == VM_MAP_REGION_TYPE_DEV;
258}
259/// 设为设备映射线性区
260STATIC INLINE VOID LOS_SetRegionTypeDev(LosVmMapRegion* region)
261{
262 region->regionType = VM_MAP_REGION_TYPE_DEV;
263}
264/// 是否为匿名swap映射线性区
266{
267 return region->regionType == VM_MAP_REGION_TYPE_ANON;
268}
269/// 设为匿名swap映射线性区
270STATIC INLINE VOID LOS_SetRegionTypeAnon(LosVmMapRegion* region)
271{
272 region->regionType = VM_MAP_REGION_TYPE_ANON;
273}
274/// 虚拟地址是否在用户空间
275STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
276{
277 return ((vaddr >= USER_ASPACE_BASE) &&
278 (vaddr <= (USER_ASPACE_BASE + (USER_ASPACE_SIZE - 1))));
279}
280/// 虚拟地址[vaddr,vaddr + len]是否在用户空间
281STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
282{
283 return (vaddr + len > vaddr) && LOS_IsUserAddress(vaddr) && (LOS_IsUserAddress(vaddr + len - 1));
284}
285
286//是否是一个动态分配的地址(通过vmalloc申请的)
288{
289 return ((vaddr >= VMALLOC_START) &&
290 (vaddr <= (VMALLOC_START + (VMALLOC_SIZE - 1))));
291}
292/// 是否为一个空线性区
293STATIC INLINE BOOL OsIsVmRegionEmpty(LosVmSpace *vmSpace)
294{
295 if (vmSpace->regionRbTree.ulNodes == 0) {
296 return TRUE;
297 }
298 return FALSE;
299}
300
304VOID OsInitMappingStartUp(VOID);
305VOID OsKSpaceInit(VOID);
306BOOL LOS_IsRangeInSpace(const LosVmSpace *space, VADDR_T vaddr, size_t size);
307STATUS_T LOS_VmSpaceReserve(LosVmSpace *space, size_t size, VADDR_T vaddr);
308INT32 OsUserHeapFree(LosVmSpace *vmSpace, VADDR_T addr, size_t len);
309VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len);
310VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags);
311LosVmMapRegion *OsCreateRegion(VADDR_T vaddr, size_t len, UINT32 regionFlags, unsigned long offset);
312BOOL OsInsertRegion(LosRbTree *regionRbTree, LosVmMapRegion *region);
316LosVmMapRegion *LOS_RegionRangeFind(LosVmSpace *vmSpace, VADDR_T addr, size_t len);
318PADDR_T LOS_PaddrQuery(VOID *vaddr);
319LosVmMapRegion *LOS_RegionAlloc(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags, VM_OFFSET_T pgoff);
320STATUS_T OsRegionsRemove(LosVmSpace *space, VADDR_T vaddr, size_t size);
321STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T vaddr, size_t size);
322LosVmMapRegion *OsVmRegionDup(LosVmSpace *space, LosVmMapRegion *oldRegion, VADDR_T vaddr, size_t size);
326STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags);
327BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb);
329STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
331STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size);
333/**
334 * thread safety
335 * it is used to malloc continuous virtual memory, no sure for continuous physical memory.
336 */
337VOID *LOS_VMalloc(size_t size);
338VOID LOS_VFree(const VOID *addr);
339
340/**
341 * thread safety
342 * these is used to malloc or free kernel memory.
343 * when the size is large and close to multiples of pages,
344 * will alloc pmm pages, otherwise alloc bestfit memory.
345 */
347VOID *LOS_KernelMallocAlign(UINT32 size, UINT32 boundary);
348VOID *LOS_KernelRealloc(VOID *ptr, UINT32 size);
349VOID LOS_KernelFree(VOID *ptr);
350
351#ifdef __cplusplus
352#if __cplusplus
353}
354#endif /* __cplusplus */
355#endif /* __cplusplus */
356
357#endif /* __LOS_VM_MAP_H__ */
358
https://blog.csdn.net/qq_38410730/article/details/81036768
volatile INT32 Atomic
Definition: los_atomic.h:102
unsigned long PADDR_T
Definition: los_typedef.h:207
signed int INT32
Definition: los_typedef.h:60
unsigned long VADDR_T
Definition: los_typedef.h:208
unsigned long VM_OFFSET_T
Definition: los_typedef.h:212
unsigned char UINT8
Definition: los_typedef.h:55
int STATUS_T
Definition: los_typedef.h:215
unsigned int UINT32
Definition: los_typedef.h:57
size_t BOOL
Definition: los_typedef.h:88
VOID LOS_VFree(const VOID *addr)
STATIC INLINE BOOL OsIsVmRegionEmpty(LosVmSpace *vmSpace)
是否为一个空线性区
Definition: los_vm_map.h:293
STATIC INLINE BOOL LOS_IsKernelAddress(VADDR_T vaddr)
虚拟地址是否在内核空间
Definition: los_vm_map.h:213
STATIC INLINE size_t LOS_RegionSize(VADDR_T start, VADDR_T end)
获取线性区大小
Definition: los_vm_map.h:229
INT32 OsUserHeapFree(LosVmSpace *vmSpace, VADDR_T addr, size_t len)
STATIC INLINE BOOL LOS_IsKernelAddressRange(VADDR_T vaddr, size_t len)
给定地址范围是否都在内核空间中
Definition: los_vm_map.h:219
LosVmSpace * LOS_CurrSpaceGet(VOID)
获取当前进程空间结构体指针
Definition: los_vm_map.c:112
STATIC INLINE BOOL LOS_IsRegionTypeDev(LosVmMapRegion *region)
是否为设备映射线性区 /dev/...
Definition: los_vm_map.h:255
STATIC INLINE VOID LOS_SetRegionTypeFile(LosVmMapRegion *region)
设置线性区为文件映射
Definition: los_vm_map.h:250
PADDR_T LOS_PaddrQuery(VOID *vaddr)
通过虚拟地址查询映射的物理地址
Definition: los_vm_map.c:550
STATIC INLINE BOOL LOS_IsVmallocAddress(VADDR_T vaddr)
Definition: los_vm_map.h:287
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
STATIC INLINE BOOL LOS_IsRegionTypeFile(LosVmMapRegion *region)
是否为文件映射区
Definition: los_vm_map.h:234
LosMux * OsGVmSpaceMuxGet(VOID)
struct VmFault LosVmPgFault
缺页结构信息体
STATUS_T OsRegionsRemove(LosVmSpace *space, VADDR_T vaddr, size_t size)
BOOL LOS_IsRegionFileValid(LosVmMapRegion *region)
映射类型为文件的线性区是否有效
Definition: los_vm_map.c:512
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
Definition: los_vm_map.h:281
BOOL LOS_IsRangeInSpace(const LosVmSpace *space, VADDR_T vaddr, size_t size)
LosVmSpace * LOS_SpaceGet(VADDR_T vaddr)
获取虚拟地址对应的进程空间结构体指针
Definition: los_vm_map.c:117
STATIC INLINE BOOL LOS_IsRegionPermUserReadOnly(LosVmMapRegion *region)
permanent 用户进程永久/常驻区
Definition: los_vm_map.h:239
LosVmSpace * OsCreateUserVmSpace(VOID)
创建用户进程空间
Definition: los_vm_map.c:281
struct VmMapRange LosVmMapRange
LosVmSpace * LOS_GetVmallocSpace(VOID)
获取内核堆空间的全局变量
Definition: los_vm_map.c:140
STATIC INLINE VOID LOS_SetRegionTypeAnon(LosVmMapRegion *region)
设为匿名swap映射线性区
Definition: los_vm_map.h:270
STATIC INLINE VADDR_T LOS_RegionEndAddr(LosVmMapRegion *region)
获取线性区的结束地址
Definition: los_vm_map.h:224
STATIC INLINE VOID LOS_SetRegionTypeDev(LosVmMapRegion *region)
设为设备映射线性区
Definition: los_vm_map.h:260
STATIC INLINE BOOL LOS_IsRegionTypeAnon(LosVmMapRegion *region)
是否为匿名swap映射线性区
Definition: los_vm_map.h:265
VOID * LOS_KernelMalloc(UINT32 size)
struct VmSpace LosVmSpace
虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
Definition: los_vm_map.h:93
STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
虚拟地址是否在用户空间
Definition: los_vm_map.h:275
LOS_DL_LIST * LOS_GetVmSpaceList(VOID)
获取进程空间链表指针 g_vmSpaceList中挂的是进程空间 g_kVmSpace, g_vMallocSpace,所有用户进程的空间(独有一个进程空间)
Definition: los_vm_map.c:135
LosVmMapRegion * OsVmRegionDup(LosVmSpace *space, LosVmMapRegion *oldRegion, VADDR_T vaddr, size_t size)
STATUS_T OsIsRegionCanExpand(LosVmSpace *space, LosVmMapRegion *region, size_t size)
LosVmMapRegion * OsCreateRegion(VADDR_T vaddr, size_t len, UINT32 regionFlags, unsigned long offset)
创建一个线性区
Definition: los_vm_map.c:531
STATIC INLINE UINT32 OsCvtProtFlagsToRegionFlags(unsigned long prot, unsigned long flags)
从外部权限标签转化为线性区权限标签
Definition: los_vm_map.h:197
LosVmMapRegion * LOS_RegionFind(LosVmSpace *vmSpace, VADDR_T addr)
查找线性区 根据起始地址在进程空间内查找是否存在
Definition: los_vm_map.c:414
VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len)
分配指定长度的线性区
Definition: los_vm_map.c:436
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
Definition: los_vm_map.c:318
LosVmSpace * LOS_GetKVmSpace(VOID)
内核空间只有g_kVmSpace一个,所有的内核进程都共用一个内核空间
Definition: los_vm_map.c:130
STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags)
STATIC INLINE BOOL LOS_IsRegionFlagPrivateOnly(LosVmMapRegion *region)
是否为私有线性区
Definition: los_vm_map.h:245
VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags)
分配指定开始地址和长度的线性区
Definition: los_vm_map.c:485
STATUS_T LOS_RegionFree(LosVmSpace *space, LosVmMapRegion *region)
释放进程空间指定线性区
Definition: los_vm_map.c:694
LosVmMapRegion * LOS_RegionAlloc(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags, VM_OFFSET_T pgoff)
Definition: los_vm_map.c:581
BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb)
OsUserVmSpaceInit 用户空间的TTB表是动态申请得来,每个进程有属于自己的L1,L2表 初始化用户进程虚拟空间,主要划分数据区,堆区,映射区和创建mmu
Definition: los_vm_map.c:265
VOID * LOS_KernelRealloc(VOID *ptr, UINT32 size)
VOID OsInitMappingStartUp(VOID)
OsInitMappingStartUp 开始初始化mmu
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space)
BOOL OsInsertRegion(LosRbTree *regionRbTree, LosVmMapRegion *region)
向红黑树中插入线性区
Definition: los_vm_map.c:521
VOID LOS_KernelFree(VOID *ptr)
VOID * LOS_VMalloc(size_t size)
LosVmMapRegion * LOS_RegionRangeFind(LosVmSpace *vmSpace, VADDR_T addr, size_t len)
查找线性区 根据地址区间在进程空间内查找是否存在
Definition: los_vm_map.c:425
VOID OsKSpaceInit(VOID)
内核虚拟空间初始化
Definition: los_vm_map.c:250
STATUS_T LOS_VmSpaceReserve(LosVmSpace *space, size_t size, VADDR_T vaddr)
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size)
STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T vaddr, size_t size)
VOID * LOS_KernelMallocAlign(UINT32 size, UINT32 boundary)
内存管理单元(英语:memory management unit,缩写为MMU),有时称作分页内存管理单元(英语:paged memory management unit,缩写为PMMU)。
Definition: los_arch_mmu.h:86
Definition: los_mux.h:73
ULONG_T ulNodes
Definition: los_rbtree.h:66
缺页结构信息体
Definition: los_vm_map.h:95
unsigned long pgoff
Definition: los_vm_map.h:97
VADDR_T * pageKVaddr
Definition: los_vm_map.h:99
VADDR_T vaddr
Definition: los_vm_map.h:98
UINT32 flags
Definition: los_vm_map.h:96
虚拟内存文件操作函数指针,上层开发可理解为 class 里的方法,注意是对线性区的操作 , 文件操作 见于g_commVmOps
Definition: los_vm_map.h:102
int(* fault)(struct VmMapRegion *region, LosVmPgFault *pageFault)
缺页,OsVmmFileFault
Definition: los_vm_map.h:105
void(* open)(struct VmMapRegion *region)
打开
Definition: los_vm_map.h:103
void(* close)(struct VmMapRegion *region)
关闭
Definition: los_vm_map.h:104
void(* remove)(struct VmMapRegion *region, LosArchMmu *archMmu, VM_OFFSET_T offset)
删除 OsVmmFileRemove
Definition: los_vm_map.h:106
UINT32 size
Definition: los_vm_map.h:85
VADDR_T base
Definition: los_vm_map.h:84
struct VmMapRegion::@4::VmRegionFile rf
union VmMapRegion::@4 unTypeData
const LosVmFileOps * vmFOps
文件处理各操作接口,open,read,write,close,mmap
Definition: los_vm_map.h:133
UINT32 regionFlags
Definition: los_vm_map.h:125
LosVmSpace * space
所属虚拟空间,虚拟空间由多个线性区组成
Definition: los_vm_map.h:121
LosRbNode rbNode
Definition: los_vm_map.h:120
UINT32 shmid
Definition: los_vm_map.h:126
struct VmMapRegion::@4::VmRegionDev rd
struct VmMapRegion::@4::VmRegionAnon ra
UINT8 forkFlags
Definition: los_vm_map.h:127
UINT8 regionType
Definition: los_vm_map.h:128
LOS_DL_LIST node
Definition: los_vm_map.h:122
LosVmMapRange range
Definition: los_vm_map.h:123
struct Vnode * vnode
文件索引节点
Definition: los_vm_map.h:132
VM_OFFSET_T pgOff
Definition: los_vm_map.h:124
int f_oflags
读写标签
Definition: los_vm_map.h:131
虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
Definition: los_vm_map.h:146
VADDR_T base
Definition: los_vm_map.h:150
VADDR_T codeStart
Definition: los_vm_map.h:159
LosVmMapRegion * heap
Definition: los_vm_map.h:154
LosRbTree regionRbTree
Definition: los_vm_map.h:148
VADDR_T codeEnd
Definition: los_vm_map.h:160
VADDR_T mapBase
Definition: los_vm_map.h:155
VADDR_T heapBase
Definition: los_vm_map.h:152
LosMux regionMux
Definition: los_vm_map.h:149
LOS_DL_LIST node
Definition: los_vm_map.h:147
VADDR_T heapNow
Definition: los_vm_map.h:153
LosArchMmu archMmu
Definition: los_vm_map.h:157
UINT32 mapSize
Definition: los_vm_map.h:156
UINT32 size
Definition: los_vm_map.h:151
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
loff_t f_pos
struct page_mapping * f_mapping
char * f_path
void * f_priv
unsigned long f_refcount
const char * f_relpath
int f_oflags
unsigned int f_magicnum
FAR struct inode * f_inode
void * f_dir
unsigned long nrpages
SPIN_LOCK_S list_lock
LOS_DL_LIST page_list
struct file * host
unsigned long flags
@note_why 全量代码中也没查到源码中对其操作
ARG_NUM_3 int
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void