[go: up one dir, main page]

CN114356802A - Method and device, system and storage medium for directly accessing memory physical address - Google Patents

Method and device, system and storage medium for directly accessing memory physical address Download PDF

Info

Publication number
CN114356802A
CN114356802A CN202111510128.9A CN202111510128A CN114356802A CN 114356802 A CN114356802 A CN 114356802A CN 202111510128 A CN202111510128 A CN 202111510128A CN 114356802 A CN114356802 A CN 114356802A
Authority
CN
China
Prior art keywords
physical address
target memory
memory
address
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111510128.9A
Other languages
Chinese (zh)
Inventor
聂世忠
张瑞忠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Mgga Technology Co ltd
Original Assignee
Beijing Mgga Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Mgga Technology Co ltd filed Critical Beijing Mgga Technology Co ltd
Priority to CN202111510128.9A priority Critical patent/CN114356802A/en
Publication of CN114356802A publication Critical patent/CN114356802A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Storage Device Security (AREA)

Abstract

本发明提供一种直接访问内存物理地址的方法和装置、系统及存储介质。直接访问内存物理地址的方法应用于操作系统的内核外的应用模块,该方法包括:获取当前进程在用户空间对应的目标内存物理地址;根据映射关系将目标内存物理地址映射为目标内存虚拟地址;直接访问目标内存虚拟地址。该技术方案无需将数据拷贝到内核空间中,数据传输访问过程简单,程序开发效率更高,且可以避免系统瘫痪,从而安全性高。

Figure 202111510128

The present invention provides a method and device, a system and a storage medium for directly accessing a physical address of a memory. The method for directly accessing the physical address of the memory is applied to an application module outside the kernel of the operating system, and the method includes: acquiring the physical address of the target memory corresponding to the current process in the user space; mapping the physical address of the target memory to the virtual address of the target memory according to the mapping relationship; Directly access the target memory virtual address. The technical solution does not need to copy data into the kernel space, the data transmission and access process is simple, the program development efficiency is higher, and system paralysis can be avoided, so that the security is high.

Figure 202111510128

Description

直接访问内存物理地址的方法和装置、系统及存储介质Method and device, system and storage medium for directly accessing memory physical address

技术领域technical field

本发明涉及软件开发技术领域,更具体地涉及一种直接访问内存物理地址的方法和装置、系统及存储介质。The present invention relates to the technical field of software development, and more particularly to a method and device, a system and a storage medium for directly accessing a physical address of a memory.

背景技术Background technique

程序代码可以逻辑上直接控制物理地址,但是在具有操作系统的平台上,需要将代码分为两部分进行开发,一部分在内核空间、一部分在用户空间。在用户空间运行的程序代码需要通过内核空间才能访问物理地址。这种地址访问方式至少存在以下问题:The program code can logically directly control the physical address, but on a platform with an operating system, the code needs to be developed in two parts, one in the kernel space and one in the user space. Program code running in user space needs to go through kernel space to access physical addresses. This address access method has at least the following problems:

1.程序开发难度大。这是因为:内核空间程序代码量和模块数量都非常庞大,在原有硬件知识的基础上还需要掌握操作系统的知识,驱动的原理等,此外在调试内核程序时也比用户空间程序困难很多;1. Program development is difficult. This is because: the amount of code and the number of modules in the kernel space program is very large. On the basis of the original hardware knowledge, it is necessary to master the knowledge of the operating system, the principle of the driver, etc. In addition, it is much more difficult to debug the kernel program than the user space program;

2.移植性差。这是因为:针对裸机开发的程序想要移植到具有操作系统的平台上,就需要在内核空间和用户空间两个层面上进行重新开发,因此移植性差;2. Poor portability. This is because: if a program developed for bare metal is to be ported to a platform with an operating system, it needs to be redeveloped at both the kernel space and user space levels, so the portability is poor;

3.在对物理地址进行数据读写时需要将数据拷贝到内核空间,因此过程比较复杂;3. When reading and writing data to the physical address, the data needs to be copied to the kernel space, so the process is more complicated;

4.传统的地址访问方式需要针对内核进行程序开发,因此开发程序出问题时会导致整个系统瘫痪,故系统的可靠性比较差。4. The traditional address access method requires program development for the kernel, so when a problem occurs in the development program, the entire system will be paralyzed, so the reliability of the system is relatively poor.

发明内容SUMMARY OF THE INVENTION

考虑到上述问题而提出了本发明。本发明提供了一种直接访问内存物理地址的方法和装置、系统及存储介质。The present invention has been made in view of the above-mentioned problems. The present invention provides a method and device, a system and a storage medium for directly accessing a physical address of a memory.

根据本发明一方面,提供了一种直接访问内存物理地址的方法,应用于操作系统的内核外的应用模块,该方法包括:According to an aspect of the present invention, a method for directly accessing a physical address of a memory is provided, which is applied to an application module outside the kernel of an operating system, and the method includes:

获取当前进程在用户空间对应的目标内存物理地址;Get the physical address of the target memory corresponding to the current process in user space;

根据映射关系将目标内存物理地址映射为目标内存虚拟地址;Map the physical address of the target memory to the virtual address of the target memory according to the mapping relationship;

直接访问目标内存虚拟地址。Directly access the target memory virtual address.

示例性地,获取当前进程在用户空间对应的目标内存物理地址包括:Exemplarily, obtaining the physical address of the target memory corresponding to the current process in the user space includes:

获取预先配置的内存物理地址作为目标内存物理地址;或者,Get the preconfigured memory physical address as the target memory physical address; or,

获取随机分配的内存物理地址作为目标内存物理地址。Get the randomly allocated memory physical address as the target memory physical address.

示例性地,根据映射关系将目标内存物理地址映射为目标内存虚拟地址包括:Exemplarily, mapping the physical address of the target memory to the virtual address of the target memory according to the mapping relationship includes:

调用运行在内核空间内的内存管理单元;Call the memory management unit running in kernel space;

通过内存管理单元根据映射关系将目标内存物理地址映射为目标内存虚拟地址。The physical address of the target memory is mapped to the virtual address of the target memory according to the mapping relationship by the memory management unit.

示例性地,应用模块内预设有映射关系;Exemplarily, a mapping relationship is preset in the application module;

根据映射关系将目标内存物理地址映射为目标内存虚拟地址包括:Mapping the physical address of the target memory to the virtual address of the target memory according to the mapping relationship includes:

直接根据预设的映射关系将目标内存物理地址映射为目标内存虚拟地址。The target memory physical address is directly mapped to the target memory virtual address according to the preset mapping relationship.

示例性地,直接访问目标内存虚拟地址包括:Exemplarily, directly accessing the target memory virtual address includes:

在目标内存虚拟地址上读取数据以获得目标数据,将目标数据返回给当前进程;和/或read data at the target memory virtual address to obtain the target data, return the target data to the current process; and/or

直接向目标内存虚拟地址中写入目标数据。Write the target data directly to the target memory virtual address.

示例性地,在直接访问目标内存虚拟地址之后,方法还包括:Exemplarily, after directly accessing the target memory virtual address, the method further includes:

解除目标内存虚拟地址与目标内存物理地址之间的映射,以释放目标内存虚拟地址。Unmap between the target memory virtual address and the target memory physical address to free the target memory virtual address.

示例性地,获取当前进程在用户空间对应的目标内存物理地址,包括:Exemplarily, obtain the physical address of the target memory corresponding to the current process in the user space, including:

通过内核外的预设硬件驱动获取当前进程在用户空间对应的目标内存物理地址。Obtain the target memory physical address corresponding to the current process in the user space through a preset hardware driver outside the kernel.

根据本发明另一方面,提供一种直接访问内存物理地址的装置,包括:According to another aspect of the present invention, an apparatus for directly accessing a physical address of a memory is provided, comprising:

获取模块,用于获取当前进程在用户空间对应的目标内存物理地址;The acquisition module is used to acquire the physical address of the target memory corresponding to the current process in the user space;

映射模块,用于根据映射关系将目标内存物理地址映射为目标内存虚拟地址;The mapping module is used to map the physical address of the target memory to the virtual address of the target memory according to the mapping relationship;

访问模块,用于直接访问目标内存虚拟地址。The access module is used to directly access the target memory virtual address.

根据本发明又一方面,提供一种直接访问内存物理地址的系统,包括处理器和存储器,其中,存储器中存储有计算机程序指令,计算机程序指令被处理器运行时用于执行如上述直接访问内存物理地址的方法。According to yet another aspect of the present invention, there is provided a system for directly accessing a physical address of a memory, including a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the above-mentioned direct access to the memory when run. physical address method.

根据本发明再一方面,提供一种存储介质,在存储介质上存储了程序指令,程序指令在运行时用于执行如上述直接访问内存物理地址的方法。According to another aspect of the present invention, a storage medium is provided, on which program instructions are stored, and the program instructions are used to execute the above-mentioned method for directly accessing a physical address of a memory when running.

根据上述技术方案,通过在操作系统的内核外的应用模块实现用户空间层的物理地址和虚拟地址之间的转换,进一步实现在用户空间上对目标内存物理地址的直接访问。利用本技术方案,可以将裸机开发的程序直接拷贝到有操作系统的平台上,从而移植性好。并且,相对于传统技术,本技术方案无需将数据拷贝到内核空间中,数据传输访问过程简单,程序开发的效率更高。同时,避免了在内核开发程序遇到问题时可能导致整个系统瘫痪的风险,因此安全性更高。According to the above technical solution, the conversion between the physical address and the virtual address of the user space layer is realized by the application module outside the kernel of the operating system, and the direct access to the physical address of the target memory in the user space is further realized. By using the technical solution, the program developed by the bare metal can be directly copied to the platform with the operating system, so that the portability is good. Moreover, compared with the traditional technology, the technical solution does not need to copy data into the kernel space, the data transmission and access process is simple, and the program development efficiency is higher. At the same time, it avoids the risk that the entire system may be paralyzed when the kernel development program encounters a problem, so the security is higher.

附图说明Description of drawings

通过结合附图对本发明实施例进行更详细的描述,本发明的上述以及其它目的、特征和优势将变得更加明显。附图用来提供对本发明实施例的进一步理解,并且构成说明书的一部分,与本发明实施例一起用于解释本发明,并不构成对本发明的限制。在附图中,相同的参考标号通常代表相同部件或步骤。The above and other objects, features and advantages of the present invention will become more apparent from the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present invention, and constitute a part of the specification, and together with the embodiments of the present invention, they are used to explain the present invention, and do not limit the present invention. In the drawings, the same reference numbers generally refer to the same components or steps.

图1示出了根据本发明一个实施例的直接访问内存物理地址的方法的示意性流程图;1 shows a schematic flowchart of a method for directly accessing a physical address of a memory according to an embodiment of the present invention;

图2示出了根据本发明一个实施例的直接访问内存物理地址的装置的示意性框图;以及FIG. 2 shows a schematic block diagram of an apparatus for directly accessing a physical address of a memory according to an embodiment of the present invention; and

图3示出了根据本发明一个实施例的直接访问内存物理地址的系统的示意性框图。FIG. 3 shows a schematic block diagram of a system for directly accessing a physical address of a memory according to an embodiment of the present invention.

具体实施方式Detailed ways

为了使得本发明的目的、技术方案和优点更为明显,下面将参照附图详细描述根据本发明的示例实施例。显然,所描述的实施例仅仅是本发明的一部分实施例,而不是本发明的全部实施例,应理解,本发明不受这里描述的示例实施例的限制。基于本发明中描述的本发明实施例,本领域技术人员在没有付出创造性劳动的情况下所得到的所有其它实施例都应落入本发明的保护范围之内。In order to make the objects, technical solutions and advantages of the present invention more apparent, exemplary embodiments according to the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of the embodiments of the present invention, and it should be understood that the present invention is not limited by the example embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of the present invention.

为了至少部分地解决上述问题,本发明实施例提供一种直接访问内存物理地址的方法。该方法应用于操作系统的内核外的应用模块,例如在linux系统的用户空间直接读写指定内存物理地址。示例性地,用户空间是普通应用程序可访问的内存区域。在linux操作系统中,将较低的3G字节(从虚拟地址0x00000000到0xBFFFFFFF),供各个进程使用,称为用户空间。而内核空间是操作系统内核访问的区域,独立于普通的应用程序,是受保护的内存空间。在linux操作系统中,将最高的1G字节(从虚拟地址0xC0000000到0xFFFFFFFF),供内核使用,称为内核空间。In order to at least partially solve the above problem, an embodiment of the present invention provides a method for directly accessing a physical address of a memory. The method is applied to application modules outside the kernel of the operating system, for example, directly reading and writing the specified memory physical address in the user space of the Linux system. Illustratively, user space is an area of memory accessible to normal applications. In the linux operating system, the lower 3G bytes (from the virtual address 0x00000000 to 0xBFFFFFFF) are used by each process, which is called user space. The kernel space is an area accessed by the operating system kernel, which is independent of ordinary applications and is a protected memory space. In the Linux operating system, the highest 1G byte (from virtual address 0xC0000000 to 0xFFFFFFFF) is used by the kernel, which is called kernel space.

现有技术中,位于用户空间的应用程序想要将数据写入给一个硬件设备,或者说,写入到该硬件设备对应的物理地址中时,通常需要在内核空间执行下述步骤:步骤S1,内核空间将用户空间发送来的访问控制请求中的物理地址映射为虚拟地址;步骤S2,内核空间将写入的数据保存在该虚拟地址中;步骤S3,内核空间将用户空间对应的虚拟地址内的数据复制拷贝至硬件设备的物理地址映射在内核空间的虚拟地址中。由于硬件设备在内核空间的虚拟地址和其实际物理地址之间存在映射关系,因此,在步骤S3中实现了将数据拷贝至硬件设备的物理地址中。In the prior art, when an application program located in the user space wants to write data to a hardware device, or in other words, when writing to the physical address corresponding to the hardware device, the following steps are usually performed in the kernel space: Step S1 , the kernel space maps the physical address in the access control request sent from the user space to a virtual address; step S2, the kernel space saves the written data in the virtual address; step S3, the kernel space stores the virtual address corresponding to the user space The physical address of the data copied to the hardware device is mapped in the virtual address of the kernel space. Since the hardware device has a mapping relationship between the virtual address in the kernel space and its actual physical address, the data is copied to the physical address of the hardware device in step S3.

如前所述,间接通过内核空间访问物理地址来写入数据到硬件设备的方法较为复杂,还存在诸如开发难度大、可能导致系统瘫痪等问题。与现有技术不同,本发明实施例的直接访问内存物理地址的方法则是通过内核空间外的应用模块来实现。例如,可以直接在用户空间层内设置一个适配层,并通过该适配层来实现对内存物理地址的直接访问,这样可以在用户空间内实现将目标数据写入硬件设备的物理地址内或从硬件设备的物理地址读取数据。As mentioned above, the method of indirectly accessing the physical address through the kernel space to write data to the hardware device is relatively complicated, and there are also problems such as difficulty in development and system paralysis. Different from the prior art, the method for directly accessing the physical address of the memory according to the embodiment of the present invention is implemented by an application module outside the kernel space. For example, an adaptation layer can be set directly in the user space layer, and the direct access to the physical address of the memory can be realized through the adaptation layer, so that the target data can be written into the physical address of the hardware device in the user space or Read data from the physical address of the hardware device.

下面参考图1,图1示出了本发明一个实施例的直接访问内存物理地址的方法1000的示意性流程图。如图1所示,直接访问内存物理地址的方法1000包括以下步骤S1100、步骤S1200和步骤S1300。Referring to FIG. 1 below, FIG. 1 shows a schematic flowchart of a method 1000 for directly accessing a physical address of a memory according to an embodiment of the present invention. As shown in FIG. 1 , the method 1000 for directly accessing a physical address of a memory includes the following steps S1100 , S1200 and S1300 .

可以理解,物理地址空间是真实存在于计算机中的实体,在每一台计算机中保持唯一独立性。而虚拟地址并不真实存在于计算机中,每个进程都被分配有自己的虚拟空间,而且只能访问自己被分配使用的空间。某一进程数据对应的虚拟地址与物理地址存在一种映射关系。It can be understood that the physical address space is an entity that actually exists in the computer, and maintains unique independence in each computer. The virtual address does not really exist in the computer, each process is allocated its own virtual space, and can only access the space allocated and used by itself. There is a mapping relationship between the virtual address corresponding to a certain process data and the physical address.

步骤S1100,获取当前进程在用户空间对应的目标内存物理地址。Step S1100: Obtain the target memory physical address corresponding to the current process in the user space.

示例性地,获取当前进程在用户空间对应的目标内存物理地址(步骤S1100)可以包括:通过内核外的预设硬件驱动获取当前进程在用户空间对应的目标内存物理地址。例如,在用户空间,可以包含一个预设的硬件驱动,可以通过该硬件驱动获取当前进程在用户空间对应的目标内存物理地址。可选地,可以响应于用户针对在操作界面上的“查询物理地址”控件的点击操作,运行该硬件驱动。Exemplarily, acquiring the physical address of the target memory corresponding to the current process in the user space (step S1100 ) may include: acquiring the physical address of the target memory corresponding to the current process in the user space through a preset hardware driver outside the kernel. For example, in the user space, a preset hardware driver may be included, and the target memory physical address corresponding to the current process in the user space may be obtained through the hardware driver. Optionally, the hardware driver may be executed in response to the user's click operation on the "query physical address" control on the operation interface.

通过内核外的硬件驱动可以构建用户空间与外部硬件设备之间的联系,使得用户空间无需调用内核程序即可自行获取硬件设备的目标内存物理地址。The connection between the user space and the external hardware device can be established through the hardware driver outside the kernel, so that the user space can obtain the target memory physical address of the hardware device without calling the kernel program.

步骤S1200,根据映射关系将目标内存物理地址映射为目标内存虚拟地址。Step S1200: Map the physical address of the target memory to the virtual address of the target memory according to the mapping relationship.

由于直接使用物理地址,不便于进行进程地址空间的隔离;且物理内存空间是有限的,将物理地址转化为虚拟地址可以实现多个进程分时复用共享。在本发明实施例中,应用于操作系统的内核外的应用模块,包括:地址转换子模块,可以通过该地址转换子模块中预设的映射关系将目标内存物理地址映射为目标内存虚拟地址。Because the physical address is directly used, it is not convenient to isolate the process address space; and the physical memory space is limited, converting the physical address into a virtual address can realize time-sharing multiplexing and sharing of multiple processes. In this embodiment of the present invention, an application module outside the kernel of the operating system includes: an address translation submodule, which can map a physical address of the target memory to a virtual address of the target memory through a preset mapping relationship in the address translation submodule.

映射关系可以根据用户空间中物理内存和地址空间的大小来设定。可以是物理地址到虚拟地址的一一映射即线性映射,也可以是线性映射和非线性映射相结合。例如,可以将用户空间划分为线性映射区和非线性映射区。根据应用目标不同,非线性映射区又可以分动态内存映射(vmalloc)区、可持久映射区和临时映射区三部分。不同的非线性映射分区又可以采用不同的映射关系。将当前进程的目标内存物理地址根据相应的映射关系映射为目标内存虚拟地址。The mapping relationship can be set according to the size of the physical memory and address space in the user space. It can be a one-to-one mapping from physical addresses to virtual addresses, that is, linear mapping, or a combination of linear mapping and nonlinear mapping. For example, the user space can be divided into a linear mapping area and a non-linear mapping area. According to different application goals, the nonlinear mapping area can be divided into three parts: dynamic memory mapping (vmalloc) area, persistent mapping area and temporary mapping area. Different nonlinear mapping partitions can adopt different mapping relationships. Map the physical address of the target memory of the current process to the virtual address of the target memory according to the corresponding mapping relationship.

步骤S1300,直接访问目标内存虚拟地址。Step S1300, directly accessing the target memory virtual address.

示例性地,直接访问目标内存虚拟地址包括:在目标内存虚拟地址上读取数据以获得目标数据,将目标数据返回给当前进程;和/或直接向目标内存虚拟地址中写入目标数据。Exemplarily, directly accessing the virtual address of the target memory includes: reading data at the virtual address of the target memory to obtain the target data, returning the target data to the current process; and/or directly writing the target data to the virtual address of the target memory.

当仅需要读取数据时,该步骤S1300可以仅包括在目标内存虚拟地址上读取数据以获得目标数据,将目标数据返回给当前进程。由于目标内存虚拟地址映射到目标内存物理地址,因此,从目标内存虚拟地址读取目标数据相当于从目标内存物理地址读取目标数据。When only data needs to be read, the step S1300 may only include reading data at the target memory virtual address to obtain the target data, and returning the target data to the current process. Since the target memory virtual address is mapped to the target memory physical address, reading target data from the target memory virtual address is equivalent to reading target data from the target memory physical address.

当仅需要写入数据时,该步骤S1300仅包括直接向目标内存虚拟地址中写入目标数据。由于目标内存虚拟地址映射到目标内存物理地址,因此,向目标内存虚拟地址写入目标数据相当于向目标内存物理地址写入目标数据。When only data needs to be written, this step S1300 only includes writing the target data directly into the target memory virtual address. Since the target memory virtual address is mapped to the target memory physical address, writing target data to the target memory virtual address is equivalent to writing target data to the target memory physical address.

当该进程包括读取和写入数据时,该步骤S1300包括在目标内存虚拟地址上读取数据以获得目标数据,将目标数据返回给当前进程,以及向目标内存虚拟地址中写入目标数据。When the process includes reading and writing data, step S1300 includes reading data at the target memory virtual address to obtain the target data, returning the target data to the current process, and writing the target data into the target memory virtual address.

根据上述技术方案,通过在操作系统的内核外的应用模块实现用户空间层的物理地址和虚拟地址之间的转换,进一步实现在用户空间上对目标内存物理地址的直接访问。利用本技术方案,可以将裸机开发的程序直接拷贝到有操作系统的平台上,从而移植性好。并且,相对于传统技术,本技术方案无需将数据拷贝到内核空间中,数据传输访问过程简单,程序开发的效率更高。同时,避免了在内核开发程序遇到问题时可能导致整个系统瘫痪的风险,因此安全性更高。According to the above technical solution, the conversion between the physical address and the virtual address of the user space layer is realized by the application module outside the kernel of the operating system, and the direct access to the physical address of the target memory in the user space is further realized. By using the technical solution, the program developed by the bare metal can be directly copied to the platform with the operating system, so that the portability is good. Moreover, compared with the traditional technology, the technical solution does not need to copy data into the kernel space, the data transmission and access process is simple, and the program development efficiency is higher. At the same time, it avoids the risk that the entire system may be paralyzed when the kernel development program encounters a problem, so the security is higher.

示例性地,获取当前进程在用户空间对应的目标内存物理地址(步骤S1100)可以包括:获取预先配置的内存物理地址作为目标内存物理地址;或者,获取随机分配的内存物理地址作为目标内存物理地址。Exemplarily, acquiring the target memory physical address corresponding to the current process in the user space (step S1100) may include: acquiring a preconfigured memory physical address as the target memory physical address; or acquiring a randomly allocated memory physical address as the target memory physical address .

预先配置的内存物理地址,例如根据进程的不同类型将其设置在不同的内存物理地址子空间内。示例性地,假设根据预设的配置规则,当前进程的类型应配置于内存物理地址子空间A内,则可以将当前进程的内存物理地址设置在A中最后一个已配置的进程对应的目标内存物理地址的后面。可选地,也可以采用随机分配的方式,将随机分配的内存物理地址作为当前进程的目标内存物理地址。Pre-configured memory physical addresses, for example, set them in different memory physical address subspaces according to different types of processes. Exemplarily, assuming that according to the preset configuration rules, the type of the current process should be configured in the memory physical address subspace A, then the memory physical address of the current process can be set in the target memory corresponding to the last configured process in A. after the physical address. Optionally, a random allocation method may also be adopted, and the randomly allocated memory physical address may be used as the target memory physical address of the current process.

通过上述技术方案,可以通过预先配置或者随机分配的方式获取当前进程在用户空间对应的目标内存物理地址。可以根据用户空间的大小、进程的属性或者用户的使用需求采用不同的配置内存物理地址的方式,以便于进程有效加载和运行。Through the above technical solution, the physical address of the target memory corresponding to the current process in the user space can be obtained by pre-configuration or random allocation. Different ways of configuring the physical address of the memory can be adopted according to the size of the user space, the attributes of the process or the usage requirements of the user, so as to facilitate the efficient loading and running of the process.

示例性地,根据映射关系将目标内存物理地址映射为目标内存虚拟地址(步骤S1200)可以包括:步骤S1210,调用运行在内核空间内的内存管理单元MMU;步骤S1220,通过内存管理单元MMU根据映射关系将目标内存物理地址映射为目标内存虚拟地址。内核空间包括内存管理单元(MMU),用来实现物理地址和虚拟地址的映射,既可以将物理地址转换成虚拟地址,也可以将虚拟地址转换成物理地址。Exemplarily, mapping the physical address of the target memory to the virtual address of the target memory according to the mapping relationship (step S1200) may include: step S1210, calling the memory management unit MMU running in the kernel space; step S1220, using the memory management unit MMU according to the mapping Relationships map target memory physical addresses to target memory virtual addresses. The kernel space includes a memory management unit (MMU), which is used to implement the mapping of physical addresses and virtual addresses, and can convert physical addresses into virtual addresses and virtual addresses into physical addresses.

示例性地,操作系统的内核外的应用模块内预设有映射关系;根据映射关系将目标内存物理地址映射为目标内存虚拟地址(步骤S1200)可以包括:直接根据预设的映射关系将目标内存物理地址映射为目标内存虚拟地址。Exemplarily, a mapping relationship is preset in an application module outside the kernel of the operating system; mapping the physical address of the target memory to a virtual address of the target memory according to the mapping relationship (step S1200) may include: directly mapping the target memory according to the preset mapping relationship. Physical addresses are mapped to target memory virtual addresses.

根据上述技术方案,将内存物理地址与内存虚拟地址之间的映射关系直接设置在用户空间中,可以直接根据该映射关系将目标内存物理地址映射为目标内存虚拟地址。相对于将映射关系设置在内核空间的技术方案,本实施例可以缩短寻找目标内存虚拟地址的路径。According to the above technical solution, the mapping relationship between the physical memory address and the virtual memory address is directly set in the user space, and the physical address of the target memory can be mapped to the virtual address of the target memory directly according to the mapping relationship. Compared with the technical solution of setting the mapping relationship in the kernel space, this embodiment can shorten the path for finding the virtual address of the target memory.

示例性地,在直接访问目标内存虚拟地址之后,直接访问内存物理地址的方法1000还可以包括:解除目标内存虚拟地址与目标内存物理地址之间的映射,以释放目标内存虚拟地址。Exemplarily, after directly accessing the target memory virtual address, the method 1000 for directly accessing the memory physical address may further include: unmapping between the target memory virtual address and the target memory physical address to release the target memory virtual address.

可选地,可以使用munmap()函数解除虚拟内存到物理内存的映射。当进程结束或利用exec相关函数来执行其他程序时,映射内存会自动解除。由此,释放的目标内存虚拟地址可供其他进程使用,因此可以提高虚拟内存的使用效率。Optionally, virtual memory to physical memory can be unmapped using the munmap() function. When the process ends or uses exec-related functions to execute other programs, the mapped memory will be automatically released. As a result, the freed target memory virtual address can be used by other processes, so the use efficiency of the virtual memory can be improved.

根据本发明另一方面,提供一种直接访问内存物理地址的装置200。图2示出了根据本发明实施例的直接访问内存物理地址的装置200的示意性框图。如图2所示,该装置200包括获取模块210、映射模块220和访问模块230。所述各个模块可分别执行上文中结合图1描述的直接访问内存物理地址的方法的各个步骤/功能。以下仅对该直接访问内存物理地址的装置200的各部件的主要功能进行描述,而省略以上已经描述过的细节内容。According to another aspect of the present invention, an apparatus 200 for directly accessing a physical address of a memory is provided. FIG. 2 shows a schematic block diagram of an apparatus 200 for directly accessing a physical address of a memory according to an embodiment of the present invention. As shown in FIG. 2 , the apparatus 200 includes an acquisition module 210 , a mapping module 220 and an access module 230 . Each of the modules can respectively execute various steps/functions of the method for directly accessing a physical address of a memory described above in conjunction with FIG. 1 . Only the main functions of the components of the apparatus 200 for directly accessing the physical address of the memory will be described below, and the details that have been described above will be omitted.

获取模块210用于获取当前进程在用户空间对应的目标内存物理地址。The obtaining module 210 is configured to obtain the target memory physical address corresponding to the current process in the user space.

映射模块220用于根据映射关系将目标内存物理地址映射为目标内存虚拟地址。The mapping module 220 is configured to map the physical address of the target memory into a virtual address of the target memory according to the mapping relationship.

访问模块230用于直接访问目标内存虚拟地址。The access module 230 is used to directly access the target memory virtual address.

示例性地,获取模块210可以包括:第一获取子模块,用于获取预先配置的内存物理地址作为目标内存物理地址;或者,获取随机分配的内存物理地址作为目标内存物理地址。Exemplarily, the obtaining module 210 may include: a first obtaining submodule, configured to obtain a preconfigured memory physical address as the target memory physical address; or obtain a randomly allocated memory physical address as the target memory physical address.

示例性地,映射模块220可以包括调用子模块,用于调用运行在内核空间内的预设进程;映射模块220还可以包括第一映射子模块,用于通过预设进程根据映射关系将目标内存物理地址映射为目标内存虚拟地址。Exemplarily, the mapping module 220 may include a calling sub-module for calling a preset process running in the kernel space; the mapping module 220 may also include a first mapping sub-module for calling the target memory according to the mapping relationship through the preset process. Physical addresses are mapped to target memory virtual addresses.

示例性地,应用模块内预设有映射关系;映射模块220可以包括:第二映射子模块,用于直接根据预设的映射关系将目标内存物理地址映射为目标内存虚拟地址。Exemplarily, a mapping relationship is preset in the application module; the mapping module 220 may include: a second mapping sub-module for directly mapping the physical address of the target memory to the virtual address of the target memory according to the preset mapping relationship.

示例性地,访问模块230可以包括第一访问子模块和/或第二访问子模块。其中,第一访问子模块用于在目标内存虚拟地址上读取数据以获得目标数据,将目标数据返回给当前进程。第二访问子模块用于直接向目标内存虚拟地址中写入目标数据。For example, the access module 230 may include a first access sub-module and/or a second access sub-module. Wherein, the first access sub-module is used for reading data at the virtual address of the target memory to obtain the target data, and returning the target data to the current process. The second access submodule is used for directly writing target data into the target memory virtual address.

示例性地,该装置200还包括解除模块,用于解除目标内存虚拟地址与目标内存物理地址之间的映射,以释放目标内存虚拟地址。Exemplarily, the apparatus 200 further includes a release module configured to release the mapping between the virtual address of the target memory and the physical address of the target memory, so as to release the virtual address of the target memory.

示例性地,获取模块210可以包括:第二获取子模块,用于通过内核外的预设硬件驱动获取当前进程在用户空间对应的目标内存物理地址。Exemplarily, the obtaining module 210 may include: a second obtaining sub-module, configured to obtain the target memory physical address corresponding to the current process in the user space through a preset hardware driver outside the kernel.

根据本发明又一方面,提供一种直接访问内存物理地址的系统300。图3示出了根据本发明实施例的直接访问内存物理地址的系统300的示意性框图。如图3所示,该系统300包括处理器310和存储器320,其中,存储器320中存储有计算机程序指令,计算机程序指令被处理器310运行时用于执行上述的直接访问内存物理地址的方法100。According to yet another aspect of the present invention, a system 300 for directly accessing a physical address of a memory is provided. FIG. 3 shows a schematic block diagram of a system 300 for directly accessing memory physical addresses according to an embodiment of the present invention. As shown in FIG. 3 , the system 300 includes a processor 310 and a memory 320, wherein the memory 320 stores computer program instructions, and the computer program instructions are used to execute the above-mentioned method 100 for directly accessing a physical address of a memory when the computer program instructions are run by the processor 310. .

根据本发明再一方面,提供一种存储介质,在存储介质上存储了程序指令,程序指令在运行时用于执行上述的直接访问内存物理地址的方法100。所述存储介质例如可以包括智能电话的存储卡、平板电脑的存储部件、个人计算机的硬盘、只读存储器(ROM)、可擦除可编程只读存储器(EPROM)、便携式紧致盘只读存储器(CD-ROM)、USB存储器、或者上述存储介质的任意组合。According to another aspect of the present invention, a storage medium is provided, and program instructions are stored on the storage medium, and the program instructions are used to execute the above-mentioned method 100 for directly accessing a physical address of a memory when running. The storage medium may include, for example, a memory card of a smartphone, a storage component of a tablet computer, a hard disk of a personal computer, read only memory (ROM), erasable programmable read only memory (EPROM), portable compact disk read only memory (CD-ROM), USB memory, or any combination of the above storage media.

尽管这里已经参考附图描述了示例实施例,应理解上述示例实施例仅仅是示例性的,并且不意图将本发明的范围限制于此。本领域普通技术人员可以在其中进行各种改变和修改,而不偏离本发明的范围和精神。所有这些改变和修改意在被包括在所附权利要求所要求的本发明的范围之内。Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above-described example embodiments are exemplary only, and are not intended to limit the scope of the invention thereto. Various changes and modifications can be made therein by those of ordinary skill in the art without departing from the scope and spirit of the invention. All such changes and modifications are intended to be included within the scope of the invention as claimed in the appended claims.

本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of the present invention.

应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-described embodiments illustrate rather than limit the invention, and that alternative embodiments may be devised by those skilled in the art without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. do not denote any order. These words can be interpreted as names.

以上所述,仅为本发明的具体实施方式或对具体实施方式的说明,本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。本发明的保护范围应以权利要求的保护范围为准。The above is only the specific embodiment of the present invention or the description of the specific embodiment, and the protection scope of the present invention is not limited thereto. Any changes or substitutions should be included within the protection scope of the present invention. The protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1.一种直接访问内存物理地址的方法,其特征在于,应用于操作系统的内核外的应用模块,包括:1. a method for directly accessing memory physical address, is characterized in that, is applied to the application module outside the kernel of operating system, comprises: 获取当前进程在用户空间对应的目标内存物理地址;Get the physical address of the target memory corresponding to the current process in user space; 根据映射关系将所述目标内存物理地址映射为目标内存虚拟地址;mapping the physical address of the target memory to a virtual address of the target memory according to the mapping relationship; 直接访问所述目标内存虚拟地址。Directly access the target memory virtual address. 2.如权利要求1所述的方法,其特征在于,所述获取当前进程在用户空间对应的目标内存物理地址包括:2. The method according to claim 1, wherein the obtaining the target memory physical address corresponding to the current process in the user space comprises: 获取预先配置的内存物理地址作为所述目标内存物理地址;或者,Obtain a preconfigured memory physical address as the target memory physical address; or, 获取随机分配的内存物理地址作为所述目标内存物理地址。A randomly allocated memory physical address is obtained as the target memory physical address. 3.如权利要求1所述的方法,其中,所述根据映射关系将所述目标内存物理地址映射为目标内存虚拟地址包括:3. The method of claim 1, wherein the mapping the target memory physical address to the target memory virtual address according to the mapping relationship comprises: 调用运行在内核空间内的内存管理单元;Call the memory management unit running in kernel space; 通过所述内存管理单元根据所述映射关系将所述目标内存物理地址映射为所述目标内存虚拟地址。The target memory physical address is mapped to the target memory virtual address by the memory management unit according to the mapping relationship. 4.如权利要求1所述的方法,其中,所述应用模块内预设有所述映射关系;4. The method of claim 1, wherein the mapping relationship is preset in the application module; 所述根据映射关系将所述目标内存物理地址映射为目标内存虚拟地址包括:The mapping of the target memory physical address to the target memory virtual address according to the mapping relationship includes: 直接根据所述预设的映射关系将所述目标内存物理地址映射为目标内存虚拟地址。The target memory physical address is directly mapped to the target memory virtual address according to the preset mapping relationship. 5.如权利要求1所述的方法,所述直接访问所述目标内存虚拟地址包括:5. The method of claim 1, wherein the directly accessing the target memory virtual address comprises: 在所述目标内存虚拟地址上读取数据以获得目标数据,将所述目标数据返回给所述当前进程;和/或reading data at the target memory virtual address to obtain target data, returning the target data to the current process; and/or 直接向所述目标内存虚拟地址中写入目标数据。Write target data directly into the target memory virtual address. 6.如权利要求1所述的方法,在所述直接访问所述目标内存虚拟地址之后,所述方法还包括:6. The method of claim 1, after the direct access to the target memory virtual address, the method further comprises: 解除所述目标内存虚拟地址与所述目标内存物理地址之间的映射,以释放所述目标内存虚拟地址。Unmapping between the target memory virtual address and the target memory physical address to release the target memory virtual address. 7.如权利要求1所述的方法,所述获取当前进程在用户空间对应的目标内存物理地址,包括:7. The method of claim 1, wherein the acquisition of the target memory physical address corresponding to the current process in the user space comprises: 通过内核外的预设硬件驱动获取所述当前进程在所述用户空间对应的目标内存物理地址。The target memory physical address corresponding to the current process in the user space is acquired through a preset hardware driver outside the kernel. 8.一种直接访问内存物理地址的装置,包括:8. A device for directly accessing a physical address of memory, comprising: 获取模块,用于获取当前进程在用户空间对应的目标内存物理地址;The acquisition module is used to acquire the physical address of the target memory corresponding to the current process in the user space; 映射模块,用于根据映射关系将所述目标内存物理地址映射为目标内存虚拟地址;a mapping module for mapping the physical address of the target memory to a virtual address of the target memory according to the mapping relationship; 访问模块,用于直接访问所述目标内存虚拟地址。The access module is used to directly access the virtual address of the target memory. 9.一种直接访问内存物理地址的系统,包括处理器和存储器,其中,所述存储器中存储有计算机程序指令,所述计算机程序指令被所述处理器运行时用于执行如权利要求1至7任一项所述的直接访问内存物理地址的方法。9. A system for directly accessing a physical address of a memory, comprising a processor and a memory, wherein the memory stores computer program instructions, the computer program instructions being used by the processor to execute the steps of claims 1 to 10 when executed by the processor. 7. The method for directly accessing the physical address of the memory according to any one of the items. 10.一种存储介质,在所述存储介质上存储了程序指令,所述程序指令在运行时用于执行如权利要求1至7任一项所述的直接访问内存物理地址的方法。10 . A storage medium on which program instructions are stored, the program instructions are used to execute the method for directly accessing a physical address of a memory according to any one of claims 1 to 7 when running. 11 .
CN202111510128.9A 2021-12-10 2021-12-10 Method and device, system and storage medium for directly accessing memory physical address Pending CN114356802A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111510128.9A CN114356802A (en) 2021-12-10 2021-12-10 Method and device, system and storage medium for directly accessing memory physical address

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111510128.9A CN114356802A (en) 2021-12-10 2021-12-10 Method and device, system and storage medium for directly accessing memory physical address

Publications (1)

Publication Number Publication Date
CN114356802A true CN114356802A (en) 2022-04-15

Family

ID=81098569

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111510128.9A Pending CN114356802A (en) 2021-12-10 2021-12-10 Method and device, system and storage medium for directly accessing memory physical address

Country Status (1)

Country Link
CN (1) CN114356802A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115437811A (en) * 2022-09-20 2022-12-06 斑马网络技术有限公司 Inter-process communication method, device, equipment and storage medium
CN115617274A (en) * 2022-10-27 2023-01-17 亿铸科技(杭州)有限责任公司 Memory computing device with bad block management function and operation method
CN115755828A (en) * 2022-10-24 2023-03-07 上海华兴数字科技有限公司 Parameter calibration method, device, vehicle ECU and vehicle
WO2023226885A1 (en) * 2022-05-26 2023-11-30 华为技术有限公司 Memory access method and related device
CN117609122A (en) * 2023-11-03 2024-02-27 摩尔线程智能科技(上海)有限责任公司 Data transmission system and method, electronic equipment and storage medium
CN117785493A (en) * 2024-02-28 2024-03-29 苏州元脑智能科技有限公司 Hardware resource access methods, devices and servers for embedded systems

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6349355B1 (en) * 1997-02-06 2002-02-19 Microsoft Corporation Sharing executable modules between user and kernel threads
CN104050101A (en) * 2014-05-29 2014-09-17 汉柏科技有限公司 Method for realizing user-state receiving and transmission of messages for ARM (Advanced RISC Machine) CPU (Central Processing Unit)

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6349355B1 (en) * 1997-02-06 2002-02-19 Microsoft Corporation Sharing executable modules between user and kernel threads
CN104050101A (en) * 2014-05-29 2014-09-17 汉柏科技有限公司 Method for realizing user-state receiving and transmission of messages for ARM (Advanced RISC Machine) CPU (Central Processing Unit)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023226885A1 (en) * 2022-05-26 2023-11-30 华为技术有限公司 Memory access method and related device
CN115437811A (en) * 2022-09-20 2022-12-06 斑马网络技术有限公司 Inter-process communication method, device, equipment and storage medium
CN115755828A (en) * 2022-10-24 2023-03-07 上海华兴数字科技有限公司 Parameter calibration method, device, vehicle ECU and vehicle
CN115617274A (en) * 2022-10-27 2023-01-17 亿铸科技(杭州)有限责任公司 Memory computing device with bad block management function and operation method
CN117609122A (en) * 2023-11-03 2024-02-27 摩尔线程智能科技(上海)有限责任公司 Data transmission system and method, electronic equipment and storage medium
CN117785493A (en) * 2024-02-28 2024-03-29 苏州元脑智能科技有限公司 Hardware resource access methods, devices and servers for embedded systems
CN117785493B (en) * 2024-02-28 2024-05-07 苏州元脑智能科技有限公司 Hardware resource access method, device and server of embedded system

Similar Documents

Publication Publication Date Title
CN114356802A (en) Method and device, system and storage medium for directly accessing memory physical address
US10282192B1 (en) Updating device code through a bus
US9152824B2 (en) Method and system for automatically preserving persistent storage
US10452562B2 (en) File access method and related device
EP3764237A1 (en) System startup method and apparatus, electronic device and storage medium
US20100070544A1 (en) Virtual block-level storage over a file system
CN101477477B (en) Kernel spacing isolation method, spacing management entity and system
US20080229046A1 (en) Unified support for solid state storage
CN103412822B (en) Operation Nonvolatile memory and the method and relevant apparatus of data manipulation
US12038908B2 (en) Blockchain data storage method, system, device, and readable storage medium
WO2008048388A2 (en) Virtual memory card controller
CN100424659C (en) Method and apparatus for determining object security using physical address based security configuration
CN109753347B (en) System and method for realizing driving
US20060112267A1 (en) Trusted platform storage controller
CN114691391A (en) Super-calling method and device for kernel mode program of enhanced packet filter
CN110019248A (en) Technology for the more storage format database access of dynamic
CN108334453B (en) A file debugging method, device, terminal device and storage medium
WO2025161674A1 (en) Network message processing method and apparatus, and computer device and storage medium
US20110271064A1 (en) Storage device and method for accessing the same
CN108108133B (en) Method and equipment for changing usable capacity of nvme SSD (solid State disk) hard disk user
CN107844360B (en) A method and device for executing application code on a hard disk
EP2266032B1 (en) Improved input/output control and efficiency in an encrypted file system
CN118227231A (en) Partition management method, device, terminal equipment and readable storage medium
JP2021536643A (en) Hybrid memory system interface
CN114385552B (en) A method and device for integrating file pages in memory

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination