Memory management method and device, limited equipment, terminal, storage medium and program

By dividing the virtual machine management memory area in resource-constrained devices and allocating memory space on demand, WebAssembly's low memory utilization rate on smart card security chips is solved, improving memory utilization and system stability.

CN119088560AActive Publication Date: 2024-12-06BEIJING TONGFANG MICROELECTRONICS
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411201259.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-06
Estimated Expiration
2044-08-29

AI Technical Summary

Technical Problem

Resource-constrained devices such as smart card security chips face the problem of limited memory resources when applying WebAssembly technology, resulting in low memory utilization, affecting product compatibility and system stability.

Method used

By dividing the memory area managed by the virtual machine into a first memory area, a buffer common area and a second memory area, it is used to store the virtual machine stack, indirect access variable stack and application RAM data, and allocate memory from the buffer common area as needed. space, improve memory utilization.

Benefits of technology

It effectively improves the memory utilization rate of resource-constrained devices, reduces the chance of system crash caused by insufficient memory, and enhances the robustness and compatibility of the operating system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088560A_ABST
    Figure CN119088560A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a memory management method and device, limited equipment, a terminal, a storage medium and a program.The memory management method is applied to the resource limited equipment and comprises the steps that a memory area managed by a virtual machine is divided into a first memory area, a buffer public area and a second memory area; wherein the first memory area and the second memory area are used memory areas at the two ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area distribute memory space from the buffer public area according to needs; storing and managing a virtual machine stack and an indirect access variable stack through the first memory area; and storing and managing application RAM data through the second memory area. According to the technical scheme, the memory utilization rate of the operating system of the resource-constrained equipment can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the technical field of virtual machine memory management, and in particular to a memory management method, apparatus, restricted device, terminal, storage medium and program. Background Art

[0002] WebAssembly (Wasm for short) is a method of using non-JavaScript (a lightweight, interpreted or just-in-time compiled programming language with function priority) code and running it in a browser. These codes can be C, C++ or Rust (a modern system programming language that focuses on security, speed and concurrency), etc. After being loaded into the client browser, they can run at a speed close to native speed. Resource-constrained devices (referred to as constrained devices) have less RAM resources. If Wasm technology is applied to resource-constrained devices such as smart card security chips, it is necessary to efficiently use limited memory resources to provide customers with more available memory resources, thereby improving product compatibility. Summary of the invention

[0003] The embodiments of the present invention provide a memory management method, apparatus, restricted device, terminal, storage medium and program, which can improve the memory utilization rate of the operating system of the resource-restricted device.

[0004] According to one aspect of the present invention, there is provided a memory management method, which is applied to a resource-constrained device, comprising:

[0005] The memory area managed by the virtual machine is divided into a first memory area, a buffer common area and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed;

[0006] The first memory area is used to store and manage a virtual machine stack and an indirect access variable stack; wherein the virtual machine stack is used to store function call parameters, local variables, operands and call function stack frame information; the indirect access variable stack is used to store elements of a function's local array variables, local structures and elements of union variables; and the indirect access variable stack memory space is allocated to the function in the virtual machine stack;

[0007] The application RAM data is stored and managed through the second memory area.

[0008] According to another aspect of the present invention, there is provided a memory management apparatus, which is configured in a resource-constrained device and includes:

[0009] A memory area division module is used to divide the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed;

[0010] A first memory area storage management module is used to store and manage a virtual machine stack and an indirect access variable stack through the first memory area; wherein the virtual machine stack is used to store function call parameters, local variables, operands and call function stack frame information; the indirect access variable stack is used to store elements of a function's local array variables, local structures and elements of union variables; and the indirect access variable stack memory space is allocated to the function in the virtual machine stack;

[0011] The second memory area storage management module is used to store and manage application RAM data through the second memory area.

[0012] According to another aspect of the present invention, a restricted device is provided, wherein an operating system is installed on the restricted device, a runtime environment is executed in the operating system, and the restricted device comprises:

[0013] at least one processor; and

[0014] a memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the memory management method described in any embodiment of the present invention.

[0016] According to another aspect of the present invention, a terminal is provided, comprising the restricted device according to any one of the embodiments of the present invention.

[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the memory management method described in any embodiment of the present invention when executed.

[0018] According to another aspect of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the memory management method according to any embodiment of the present invention is implemented.

[0019] The embodiment of the present invention divides the memory area managed by the virtual machine of the resource-constrained device into a first memory area, a buffer common area and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed; further, the virtual machine stack and the indirect access variable stack are stored and managed by the first memory area, and application RAM data are stored and managed by the second memory area, thereby effectively improving the memory utilization rate of the operating system of the resource-constrained device.

[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 is a flow chart of a memory management method provided by an embodiment of the present invention;

[0023] Figure 2 It is a structural schematic diagram of a memory area managed by a virtual machine provided by an embodiment of the present invention;

[0024] Figure 3 is a flow chart of a memory management method provided by an embodiment of the present invention;

[0025] Figure 4 It is a structural schematic diagram of a memory area managed by a virtual machine provided by an embodiment of the present invention;

[0026] Figure 5 is a flow chart of a memory management method provided by an embodiment of the present invention;

[0027] Figure 6 It is a flowchart of a memory management method provided by an embodiment of the present invention;

[0028] Figure 7 is a schematic diagram of a memory management device provided by an embodiment of the present invention;

[0029] Figure 8 A schematic diagram of the structure of a restricted device provided by an embodiment of the present invention;

[0030] Fig. 9 is a structural diagram of a terminal provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0033] Figure 1 This is a flowchart of a memory management method provided by an embodiment of the present invention. This embodiment is applicable to resource-constrained devices that manage memory by dividing the memory area managed by the virtual machine into different areas. The method can be executed by a memory management device. The device can be implemented by software and / or hardware, and can generally be integrated in a restricted device. The restricted device can be integrated in a terminal device. The embodiment of the present invention does not limit the specific device type of the restricted device. Optionally, a multi-application smart card operating system (Multi-Application Smartcard Operation System, AOS) can be installed in the restricted device. The multi-application smart card operating system refers to an operating system that supports multiple applications and post-download and runs on a resource-constrained security chip. Optionally, the restricted device may include, but is not limited to, smart cards, USBKEY (hardware device with USB interface), ESAM (Embedded Secure Access Module) and SE (Secure Element) and other products. Accordingly, if Figure 1 As shown, the method includes the following operations:

[0034] S110, dividing the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed.

[0035] For resource-constrained devices, the memory area managed by the virtual machine may be a RAM (Random Access Memory) memory area. The first memory area may be a used memory area at one end of the memory area managed by the virtual machine, and the second memory area may be a used memory area at the other end of the memory area managed by the virtual machine. Correspondingly, the buffer common area may be an unused memory area in the middle of the memory area managed by the virtual machine.

[0036] It can be understood that the first memory area and the second memory area are respectively memory areas composed of the starting memory address of the memory area managed by the virtual machine and a continuous memory distribution space. Optionally, the first memory area may correspond to a memory area starting from the starting memory address of the memory area managed by the virtual machine, and the second memory area may correspond to a memory area starting from the ending memory address of the memory area managed by the virtual machine. Alternatively, the first memory area may correspond to a memory area starting from the ending memory address of the memory area managed by the virtual machine, and the second memory area may correspond to a memory area starting from the starting memory address of the memory area managed by the virtual machine. The embodiment of the present invention does not limit the relative positions of the first memory area and the second memory area in the memory area managed by the virtual machine.

[0037] Figure 2 Schematic diagram of a memory area managed by a virtual machine provided by an embodiment of the present invention. Figure 2 As shown, the first memory area, the buffer common area and the second memory area are sequentially connected to obtain a complete memory area managed by the virtual machine, or the second memory area, the buffer common area and the first memory area are sequentially connected to obtain a complete memory area managed by the virtual machine.

[0038] S120. Store and manage a virtual machine stack and an indirect access variable stack through the first memory area.

[0039] In the embodiment of the present invention, the virtual machine adopts a stack structure to store and manage the virtual machine stack. The virtual machine stack is used to store stack frames, which store function call parameters, local variables, operands, and calling function stack frame information. When the virtual machine executes a function call instruction, a stack frame is created for the function. When the virtual machine executes a function return instruction, the stack frame corresponding to the function is destroyed.

[0040] The indirect access variable stack may be a local structure type data area of ​​the currently running function, which is used to store elements of the function's local array variables, local structures, and elements of union variables.

[0041] The indirect access variable stack memory space is allocated to the function in the virtual machine stack.

[0042] S130. Store and manage application RAM data through the second memory area.

[0043] The application RAM data may be the data type that the application needs to occupy the RAM memory for storage. Exemplarily, in the embodiment of the present invention, the application RAM data may include but is not limited to temporary static variable data, temporary dynamic variable data and module global data.

[0044] Correspondingly, after the memory area managed by the virtual machine is divided into a first memory area, a buffer common area and a second memory area, the first memory area is used to store and manage the virtual machine stack and the indirect access variable stack, and the second memory area is used to store and manage application RAM data.

[0045] That is, the embodiment of the present invention divides the memory areas at both ends of the RAM memory managed by the virtual machine into two continuous memories to manage the corresponding data, wherein one end of the memory area centrally stores and manages the virtual machine stack and the indirect access variable stack, and the other end of the memory area centrally stores and manages the application RAM data. The first memory area and the second memory area are allocated and used from both ends of the RAM memory managed by the virtual machine to the middle, and the middle part is the buffer common area, which can maximize the use of the limited RAM resources of the resource-constrained device. Only when the newly allocated memory space in the first memory area is larger than the memory space in the buffer common area, or the newly allocated memory space in the second memory area is larger than the memory space in the buffer common area, the system cannot continue to run due to insufficient memory space in the buffer common area, reducing the probability of the system being unable to run due to insufficient space allocation due to a certain type of fixed memory space, thereby improving the robustness of the operating system. It can be seen that the above-mentioned memory management method applied to resource-constrained devices can maximize the use of RAM resources and improve product compatibility.

[0046] The embodiment of the present invention divides the memory area managed by a virtual machine of a resource-constrained device into a first memory area, a buffer common area, and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed; further, the first memory area is used to store and manage the virtual machine stack and the indirect access variable stack, and the second memory area is used to store and manage application RAM data, thereby improving the memory utilization rate of the operating system of the resource-constrained device.

[0047] Figure 3 is a flow chart of a memory management method provided by an embodiment of the present invention. This embodiment is specific based on the above embodiment. In this embodiment, temporary static variable data and temporary dynamic variable data are used as application RAM data, and a specific optional implementation method of storing and managing temporary static variable data and temporary dynamic variable data through a second memory area is provided. Figure 3 As shown, the method of this embodiment may include:

[0048] S210: Divide the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area.

[0049] Among them, the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed.

[0050] S220. Store and manage a virtual machine stack and an indirect access variable stack through the first memory area.

[0051] Figure 4 Schematic diagram of a memory area managed by a virtual machine provided by an embodiment of the present invention. Figure 4 As shown, the area at the A end of the virtual machine managed memory area can be used as the first memory area, and the area at the B end of the virtual machine managed memory area can be used as the second memory area. Accordingly, the virtual machine stack and the indirect access variable stack can be used as a continuous memory allocated from the A end of the virtual machine managed memory to the B end of the virtual machine managed memory, and the module global data, temporary dynamic variable data, and temporary static variable data can be used as a continuous memory allocated from the B end of the virtual machine managed memory to the A end of the virtual machine managed memory, and the middle area of ​​the virtual machine managed memory that has not been allocated for use is used as a buffer common area.

[0052] In an optional embodiment of the present invention, the application RAM data may include temporary static variable data and temporary dynamic variable data. Accordingly, the method may include the following operations:

[0053] S230: After the system starts running, a newly added second memory area is acquired from the buffer common area starting from the second memory area toward the first memory area.

[0054] The newly added second memory area may be a memory area obtained from the buffer common area close to the starting position of the second memory area.

[0055] S240: Use the newly added second memory area as a memory space for temporary static variable data of all applications and initialize it.

[0056] Among them, the temporary static variable data (AOS Static transient Resource, ASR) belongs only to the application itself, and the allocated data storage space is exclusively occupied by the application. When the RTE (Runtime Environment, Runtime Environment) is reset or powered off, the temporary static variable data is reset to 0.

[0057] In an embodiment of the present invention, after a program in a resource-constrained device is started and executed, memory space in a newly added second memory area can be allocated and initialized for all temporary static variable data of applications starting from the second memory area of ​​the RAM memory managed by the virtual machine toward the first memory area.

[0058] In a specific example, Figure 4 As shown, after the program in the resource-constrained device starts running, memory space can be allocated and initialized for all application temporary static variable data starting from end B to end A of the virtual machine management memory according to the sum of the memory space occupied by all application temporary static variable data.

[0059] S250: When an application is selected on a logical channel for the first time, a first starting position for allocating temporary dynamic variable data memory space to the selected application is determined at a position of the buffer common area close to the second memory area.

[0060] Among them, the logical channel may refer to a concept for establishing a communication connection with a smart card, which allows multiple independent communication channels to be established between the host and the smart card at the same time, each channel has its own command and response stream, and is isolated from each other. The selected application may be an application that has been selected. Temporary dynamic variable data (AOSDynamictransient Resource, ADR) belongs to the application, but its data space allocation is only executed when the application is selected. When the last application of the same module on multiple logical channels is deselected, the space occupied by the temporary dynamic variable data of the application is recycled, and the RTE clears the temporary dynamic variable data of the module. After reset or power failure, when the application is not selected, the temporary dynamic variable data does not exist. After the application is selected, even if the space occupied by the temporary dynamic variable data of the application is zero, it is considered that the virtual machine management application RAM data already contains temporary dynamic variable data. The first starting position may be the starting position of the allocation of memory space for temporary dynamic variable data in the RAM memory managed by the virtual machine.

[0061] For resource-constrained devices, when RTE receives a select application command, if the command content matches the application AID (Application Identifier), it is an explicitly selected application, and RTE should activate this application as the selected application. When a logical channel is opened through the MANAGE CHANNEL (MANAGE CHANNEL command is used to open a new logical channel from a logical channel, or close a specified logical channel from a logical channel) instruction, after RTE receives the logical channel opening command, in addition to performing necessary logical channel management, it should also check whether there is an implicitly selected application on the new logical channel. If so, the implicitly selected application should be activated by default, that is, the implicitly selected application. When the application is activated, RTE should distribute the subsequent received commands to the currently activated application for execution and processing.

[0062] S260: Allocate and initialize the temporary dynamic variable data memory space for the selected application from the first starting position toward the first memory area.

[0063] In an embodiment of the present invention, when an application is selected on a logical channel for the first time, the first starting position for allocating temporary dynamic variable data memory space to the selected application can be determined at a position in the buffer common area close to the second memory area, that is, the position of the temporary static variable data memory area close to the first memory area is taken as the first starting position, and temporary dynamic variable data memory space is allocated and initialized for the selected application in the direction of the first memory area.

[0064] In an optional embodiment of the present invention, determining the first starting position for allocating temporary dynamic variable data memory space to the selected application at a position of the buffer common area close to the second memory area may include: when it is determined that there is no temporary dynamic variable data memory space, taking the memory position of the temporary static variable data memory space close to the direction of the first memory area as the first starting position; when it is determined that there is already a temporary dynamic variable data memory space and an existing module global data memory space, moving the existing module global data memory space as a whole in the direction of the first memory area; taking the memory position of the existing temporary dynamic variable data memory space close to the direction of the first memory area as the first starting position.

[0065] The module global resource (MGR) may be global data that is visible to the entire module and can be modified by the application program in the module. Exemplarily, the module global data may be the global data of the application program and the application program global variable stack.

[0066] In a specific example, continue to refer to Figure 4 The example shows that when an application is selected on a logical channel for the first time, temporary dynamic variable data is allocated to the application. Specifically, if the virtual machine management memory does not have temporary dynamic variable data memory, the temporary static variable data memory area close to the virtual machine management memory A end position can be used as the first starting position, and starting from the first starting position, the temporary dynamic variable data memory space is allocated to the selected application in the direction of the virtual machine management memory A end and initialized. If the virtual machine management memory already has temporary dynamic variable data memory space, and the module global data memory space already exists, the existing module global data memory area can be first moved to the virtual machine management memory A end as a whole, and the existing temporary dynamic variable data memory area close to the virtual machine management memory A end position is used as the first starting position, and starting from the first starting position, the temporary dynamic variable data memory space is allocated to the selected application in the direction of the virtual machine management memory A end. It should be noted that when the existing module global data memory area is moved to the virtual machine management memory A end as a whole, it is necessary to maintain the continuity of the module global data memory area and the temporary dynamic variable data memory area after this allocation. After allocating the temporary dynamic variable data memory space to the selected application, the temporary dynamic variable data memory space allocated this time is initialized.

[0067] The above technical solution divides the memory area managed by the virtual machine of the resource-constrained device into a first memory area, a buffer common area, and a second memory area; further stores and manages the virtual machine stack and the indirect access variable stack through the first memory area, and stores and manages the application RAM data through the second memory area. When the application RAM data is stored and managed through the second memory area, the memory space corresponding to the temporary static variable data and the temporary dynamic variable data can be divided therefrom, and the storage is continuously allocated in sequence, which can maximize the use of the limited RAM resources of the resource-constrained device and reduce the probability of the system failing to operate due to insufficient space due to the allocation of a certain type of fixed memory space, thereby improving the memory utilization rate of the operating system of the resource-constrained device and the robustness of the operating system.

[0068] Figure 5 is a flow chart of a memory management method provided by an embodiment of the present invention. This embodiment is specific based on the above embodiment. In this embodiment, temporary static variable data, temporary dynamic variable data and module global data are simultaneously used as application RAM data, and a specific optional implementation method of storing and managing temporary static variable data, temporary dynamic variable data and module global data through a second memory area is provided. Accordingly, Figure 5 As shown, the method of this embodiment may include:

[0069] S310: Divide the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area.

[0070] Among them, the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed.

[0071] S320. Store and manage a virtual machine stack and an indirect access variable stack through the first memory area.

[0072] S330: After the system starts running, a newly added second memory area is acquired from the buffer common area starting from the second memory area toward the first memory area.

[0073] S340: Use the newly added second memory area as a memory space for temporary static variable data of all applications and initialize it.

[0074] S350: When an application is selected on a logical channel for the first time, a first starting position for allocating temporary dynamic variable data memory space to the selected application is determined at a position of the buffer common area close to the second memory area.

[0075] S360: Allocate and initialize the temporary dynamic variable data memory space for the selected application from the first starting position toward the first memory area.

[0076] S370. On any logical channel, when the virtual machine first calls the module program of the application module corresponding to the application, a second starting position of the memory space for allocating module global data and module global data management information to the called application module is determined at a position in the buffer common area close to the second memory area.

[0077] S380: Allocate and initialize the module global data and module global data management information memory space to the called application module from the second starting position toward the first memory area.

[0078] Among them, the application module refers to an independent module that implements a specific application function or service and has an application entry function. These modules are usually divided according to functions or business logic, and applications can be created in the application modules. The module program belongs to a module program set, and the module program set can be a collection for storing all program code information or module program data in a specific module. The called application module is also the application module called by the virtual machine. The module global data management information space can be a management module global data system overhead, used to record the space of the corresponding module global data, the module to which it belongs, and the logical channel information to which it belongs. The second starting position can be the starting position in the RAM memory managed by the virtual machine for allocating module global data and module global data management information memory space.

[0079] In an embodiment of the present invention, when a virtual machine calls a module program of an application module corresponding to an application for the first time on any logical channel, a second starting position for allocating module global data and module global data management information memory space to the called application module can be determined at a position in the buffer common area close to the second memory area, that is, the position in the temporary dynamic variable data memory area close to the first memory area can be used as the second starting position, and the module global data and module global data management information memory space can be allocated to the called application module in the direction of the first memory area and initialized.

[0080] In an optional embodiment of the present invention, determining the second starting position of allocating module global data and module global data management information memory space to the called application module at a position of the buffer common area close to the second memory area may include: when it is determined that there is no memory space for module global data, taking the memory position of the memory space for temporary dynamic variable data close to the direction of the first memory area as the second starting position; when it is determined that there is already a memory space for module global data, taking the memory position of the memory space for the existing module global data close to the direction of the first memory area as the second starting position.

[0081] In a specific example, continue to refer to Figure 4 The example illustrates that when an application is selected on a logical channel for the first time, the module program of the application module corresponding to the application module that executes the application needs to allocate module global data for the application. Specifically, if the virtual machine management memory does not yet have module global data memory, the temporary dynamic variable data memory area can be used as the starting point near the A end of the virtual machine management memory, and the module global data and module global data management information memory space can be allocated and initialized for the called application module in the direction of the A end of the virtual machine management memory. If there is already a memory space for module global data, the existing module global data memory area can be used as the starting point near the A end of the virtual machine management memory, and the module global data and module global data management information memory space can be allocated and initialized for the called application module in the direction of the A end of the virtual machine management memory.

[0082] In an optional embodiment of the present invention, the virtual machine calls the module program of the application module corresponding to the application for the first time, which may include: the application is selected on the logical channel for the first time, and the module program of the selected application module is called through the function call related bytecode; or, on any logical channel, the module program of the application module corresponding to the application is called for the first time through the function call related bytecode.

[0083] Optionally, the first time a virtual machine calls a module program of an application module corresponding to an application means the first time a module program of an application module is called through a function call related bytecode, which may include two scenarios, one of which is that an application is selected on a logical channel for the first time, and when a module program of the selected application module is called through a function call related bytecode, a second starting position of a memory space for allocating module global data and module global data management information to the called application module may be determined at a location in the buffer common area close to the second memory area, and the memory space for allocating module global data and module global data management information to the called application module from the second starting position toward the first memory area and initialized. The second scenario is that on any logical channel, when a module program of an application module corresponding to an application is called through a function call related bytecode for the first time, module global data is allocated to the application, and a second starting position of a memory space for allocating module global data and module global data management information to the called application module may be determined at a location in the buffer common area close to the second memory area, and the memory space for allocating module global data and module global data management information to the called application module from the second starting position toward the first memory area and initialized.

[0084] In an optional embodiment of the present invention, the memory management method may also include: when deselection is applied on any logical channel, reclaiming the memory space of all module global data and module global data management information matching the current logical channel while maintaining the continuity of all remaining module global data and module global data management information memory, and maintaining the continuity of the module global data memory space and the temporary dynamic variable data memory space.

[0085] Application deselection can also be called application cancellation. Application deselection means that when RTE activates an application, it should first deactivate the currently activated application. When closing a logical channel through the MANAGE CHANNEL command, RTE should perform application deselection.

[0086] It is understandable that, on any logical channel, when the application is deselected, it is necessary to reclaim all module global data and module global data management information memory spaces that match the current logical channel. In the process of reclaiming all module global data and module global data management information memory spaces that match the current logical channel, it is necessary to pay attention to maintaining the continuity of all remaining module global data and module global data management information memory, and at the same time maintaining the continuity of the module global data memory space and the temporary dynamic variable data memory space.

[0087] In an optional embodiment of the present invention, the memory management method may further include: when the application is deselected on the logical channel for the last time, reclaiming the memory space of the temporary dynamic variable data of the deselected application while maintaining the continuity of all remaining temporary dynamic variable data memory, maintaining the continuity of the module global data memory area and the temporary dynamic variable data memory area, and maintaining the continuity of the temporary dynamic variable data memory area and the temporary static variable data memory area.

[0088] The deselected application may be an application that executes an application deselection process.

[0089] It is understandable that when the application is deselected on the logical channel for the last time, that is, when the last application of the same module on multiple logical channels is deselected, the temporary dynamic variable data memory space of the deselected application needs to be reclaimed. In the process of reclaiming the temporary dynamic variable data memory space of the deselected application, it is necessary to maintain the continuity of all remaining temporary dynamic variable data memories, maintain the continuity of the module global data memory area and the temporary dynamic variable data memory area, and maintain the continuity of the temporary dynamic variable data memory area and the temporary static variable data memory area.

[0090] In order to more clearly illustrate the technical solution provided by the embodiment of the present invention, the memory management method provided by the embodiment of the present invention is described below with reference to specific examples. Figure 6is a flow chart of a memory management method provided by an embodiment of the present invention. In a specific example, Figure 6 As shown, after the system is running, the temporary static variable data of the application can be allocated at the starting position of the B end of the virtual machine management memory. If application 1 to which module 1 belongs is selected on logical channel 0, the system can first execute the application selection process. At this time, starting from the temporary static variable data memory area close to the A end position of the virtual machine management memory, a temporary dynamic variable data memory space is allocated to the selected application in the direction of the A end of the virtual machine management memory: ADR-C0M1A1. Then, the system calls the module 1 module program. At this time, starting from the temporary dynamic variable data memory area close to the A end position of the virtual machine management memory, that is, ADR-C0M1A1 close to the A end position of the virtual machine management memory, the module global data memory and its management information memory space can be allocated to the called application module in the direction of the A end of the virtual machine management memory: MGR-C0M1A1, the MGR-C0M1A1 memory is initialized, and its space, the module to which it belongs, and the logical channel information to which it belongs are recorded in the management information memory.

[0091] Further, such as Figure 6 As shown, if application 1 to which module 2 belongs is selected on logical channel 1, the system first executes the application selection process. At this time, the existing temporary dynamic variable data memory area can be close to the virtual machine management memory A end position, that is, ADR-C0M1A1 close to the virtual machine management memory A end position as the starting point, and the temporary dynamic variable data memory space can be allocated to the selected application in the direction of the virtual machine management memory A end. The existing module global data memory area MGR-C0M1A1 can be moved as a whole to the virtual machine management memory A end. During the moving process, the continuity of the module global data memory area and the temporary dynamic variable data memory area after this allocation must be maintained. Therefore, the capacity of the moved memory space can be the capacity of the temporary dynamic variable data memory space allocated to the selected application. After the move is completed, the required memory area between MGR-C0M1A1 and ADR-C0M1A1 is obtained: ADR-C1M2A1, and then the temporary dynamic variable data memory ADR-C1M2A1 space allocated this time is initialized. Afterwards, the system calls the module 2 module program. At this time, starting from the existing module global data memory area close to the A end of the virtual machine management memory, that is, MGR-C0M1A1 close to the A end of the virtual machine management memory, the module global data memory and its management information memory space are allocated to the called application module in the direction of the A end of the virtual machine management memory: MGR-C1M2A1, the MGR-C1M2A1 memory is initialized, and its space, the module to which it belongs, and the logical channel information to which it belongs are recorded in the management information memory.

[0092] Furthermore, logical channel 0 has selected application 1 to which module 1 belongs to access the module program interface function of module 3 application 1 during operation. On logical channel 0, when the module program of the corresponding application module of module 3 application 1 is called for the first time, it is necessary to allocate module global data and module global data management information memory space for the called application module. At this time, starting from the existing module global data memory area close to the A end position of the virtual machine management memory, that is, the module global data memory MGR-C1M2A1 close to the A end position of the virtual machine management memory, allocate module global data memory and its management information memory space to the called application module in the direction of the A end of the virtual machine management memory: MGR-C0M3A1, initialize the MGR-C0M3A1 memory, and record its space, the module to which it belongs, and the logical channel information to which it belongs in the management information memory.

[0093] Further, logical channel 1 selects application 1 to which module 2 belongs. At this time, the module global data memory and its management information memory space MGR-C1M2A1 of application 1 to which module 2 belongs can be firstly recovered, and the module global data memory and its management information memory MGR-C0M3A1 can be moved as a whole to the virtual machine management memory B end, and the continuity of the module global data memory and its management information memory MGR-C0M3A1 and the module global data memory and its management information memory MGR-C0M1A1 can be maintained during the moving process. Afterwards, the temporary dynamic variable data memory space ADR-C1M2A1 of application 1 to which module 2 belongs is recovered, and the entire module global data memory area, namely, the module global data memory and its management information memory MGR-C0M3A1 and the module global data memory and its management information memory MGR-C0M1A1 can be moved as a whole to the virtual machine management memory B end, and the continuity of the module global data memory area and the temporary dynamic variable data memory area can be maintained during the moving process.

[0094] Further, logical channel 0 selects application 1 to which module 2 belongs. First, the system executes to select application 1 to which module 1 belongs, and reclaims all module global data memories and management information memory spaces of the module with the attribute of logical channel 0, namely, reclaims module global data memories and management information memory MGR-C0M3A1 and module global data memories and management information memory MGR-C0M1A1. Further, the temporary dynamic variable data memory space ADR-C0M1A1 of application 1 to which module 1 belongs is reclaimed. Thereafter, the system executes the process of selecting application 1 to which module 2 belongs, starting with the temporary static variable data memory area close to the A end of the virtual machine management memory, and allocating temporary dynamic variable data memory space ADR-C0M2A1 to the selected application in the direction of the A end of the virtual machine management memory. Finally, the system calls the module 2 module program. At this time, the temporary dynamic variable data memory area is close to the A end of the virtual machine management memory, that is, ADR-C0M2A1 is close to the A end of the virtual machine management memory as the starting point, and the module global data memory and its management information memory space are allocated to the called application module in the direction of the A end of the virtual machine management memory: MGR-C0M2A1.

[0095] The above technical solution can realize the formation of a continuous memory of three kinds of memory, namely module global data, temporary dynamic variable data and temporary static variable data. The probability of change of the three kinds of memory, namely module global data, temporary dynamic variable data and temporary static variable data, is from large to small. Therefore, the memory with a large probability of change is placed close to the buffer common area, which can reduce the space and number of times of moving RAM memory when a certain type of memory space changes. At the same time, the above technical solution continuously allocates the module global data management information and the module global data memory, which can improve the efficiency of module global data memory management of multiple applications on a single logical channel.

[0096] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are in compliance with the relevant laws and regulations and do not violate public order and good morals.

[0097] It should be noted that any arrangement and combination of the technical features in the above embodiments also falls within the protection scope of the present invention.

[0098] Figure 7 is a schematic diagram of a memory management device provided by an embodiment of the present invention, wherein the memory management device is configured in a resource-constrained device, such as Figure 7 As shown, the device includes: a memory area division module 410, a first memory area storage management module 420 and a second memory area storage management module 430, wherein:

[0099] The memory area division module 410 is used to divide the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed;

[0100] A first memory area storage management module 420, used for managing the virtual machine stack and indirectly accessing the variable stack through the first memory area storage;

[0101] The second memory area storage management module 430 is used to store and manage application RAM data through the second memory area.

[0102] The embodiment of the present invention divides the memory area managed by the virtual machine of the resource-constrained device into a first memory area, a buffer common area and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed; further, the virtual machine stack and the indirect access variable stack are stored and managed by the first memory area, and application RAM data are stored and managed by the second memory area, thereby effectively improving the memory utilization rate of the operating system of the resource-constrained device.

[0103] Optionally, the application RAM data includes module global data, and the second memory area storage management module 430 is also used to: on any logical channel, when the virtual machine calls the module program of the application module corresponding to the application for the first time, determine the second starting position of the memory space for allocating module global data and module global data management information to the called application module at the position of the buffer common area close to the second memory area; allocate the module global data and module global data management information memory space to the called application module from the second starting position toward the first memory area and initialize them.

[0104] Optionally, the second memory area storage management module 430 is also used for: when it is determined that there is no memory space for module global data, using the memory position of the memory space for temporary dynamic variable data close to the direction of the first memory area as the second starting position; when it is determined that there is already memory space for module global data, using the memory position of the memory space for the existing module global data close to the direction of the first memory area as the second starting position.

[0105] Optionally, the virtual machine calls the module program of the application module corresponding to the application for the first time, including: the application is selected on the logical channel for the first time, and the module program of the selected application module is called through the function call related bytecode; or, on any logical channel, the module program of the application module corresponding to the application is called for the first time through the function call related bytecode.

[0106] Optionally, the application RAM data includes temporary static variable data, and the second memory area storage management module 430 is also used to: after the system starts running, obtain a newly added second memory area from the buffer common area starting from the second memory area in the direction of the first memory area; use the newly added second memory area as the memory space for temporary static variable data of all applications and initialize it.

[0107] Optionally, the second memory area storage management module 430 is also used for: when an application is selected on a logical channel for the first time, determining a first starting position for allocating temporary dynamic variable data memory space to the selected application at a position of the buffer common area close to the second memory area; allocating the temporary dynamic variable data memory space to the selected application from the first starting position toward the first memory area and initializing it.

[0108] Optionally, the second memory area storage management module 430 is also used for: when it is determined that there is no temporary dynamic variable data memory space, using the memory position of the temporary static variable data memory space close to the direction of the first memory area as the first starting position; when it is determined that there is a temporary dynamic variable data memory space and an existing module global data memory space, moving the existing module global data memory space as a whole in the direction of the first memory area; using the memory position of the existing temporary dynamic variable data memory space close to the direction of the first memory area as the first starting position.

[0109] Optionally, the above-mentioned memory management method may also include a first memory space recovery module, which is used to: when deselection is applied on any logical channel, reclaim the memory space of all module global data and module global data management information matching the current logical channel while maintaining the continuity of all remaining module global data and module global data management information memory, and maintaining the continuity of the module global data memory space and the temporary dynamic variable data memory space.

[0110] Optionally, the above-mentioned memory management method may further include a second memory space recovery module, which is used to: when the application is deselected on the logical channel for the last time, reclaim the memory space of the temporary dynamic variable data of the deselected application while maintaining the continuity of all remaining temporary dynamic variable data memory, maintaining the continuity of the module global data memory area and the temporary dynamic variable data memory area, and maintaining the continuity of the temporary dynamic variable data memory area and the temporary static variable data memory area.

[0111] The above memory management device can execute the memory management method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not described in detail in this embodiment, please refer to the memory management method provided by any embodiment of the present invention.

[0112] Since the memory management device described above is a device that can execute the memory management method in the embodiment of the present invention, based on the memory management method described in the embodiment of the present invention, the technical personnel in this field can understand the specific implementation of the memory management device of this embodiment and its various variations, so how the memory management device implements the memory management method in the embodiment of the present invention is not described in detail here. As long as the technical personnel in this field implement the device adopted by the memory management method in the embodiment of the present invention, it belongs to the scope of protection of this application.

[0113] Figure 8 A schematic diagram of the structure of a restricted device 10 that can be used to implement an embodiment of the present invention is shown.

[0114] like Figure 8 As shown, the limited device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a non-volatile memory (NVM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by the at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the non-volatile memory (NVM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the limited device 10 can also be stored. The processor 11, the NVM 12 and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0115] The I / O interface 15 in the restricted device 10 may include: ISO7816, ISO14443, eSPI (Enhanced Serial Peripheral Interface) and SPI (Serial Peripheral Interface), etc.

[0116] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, for example, executes a memory management method as described in various embodiments of the present invention, which is executed by a runtime environment in an embedded operating system, and the embedded operating system is installed in a restricted device, and the method includes:

[0117] The memory area managed by the virtual machine is divided into a first memory area, a buffer common area and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed;

[0118] The virtual machine stack and the indirect access variable stack are stored and managed through the first memory area;

[0119] The application RAM data is stored and managed through the second memory area.

[0120] In some embodiments, a memory management method as described in various embodiments of the present invention may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the restricted device 10 via the NVM 12. When the processor 11 executes the computer program stored in the NVM 12 or the computer program loaded into the random access memory (RAM) 13 by the storage unit 18, one or more steps of a memory management method as described in various embodiments of the present invention described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute a memory management method as described in various embodiments of the present invention in any other appropriate manner (for example, by means of firmware).

[0121] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0122] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0123] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0124] Fig. 9 is a structural diagram of a terminal provided according to an embodiment of the present invention. Fig. 9 Said terminal includes the restricted device 1010 as described in any embodiment of the present invention.

[0125] The restricted device 1010 may be an embedded security element, a smart card, an SE, an embedded device, etc.

[0126] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0127] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A memory management method, characterized in that: Applicable to resource-constrained devices, including: The memory area managed by the virtual machine is divided into a first memory area, a buffer common area and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed; The first memory area is used to store and manage a virtual machine stack and an indirect access variable stack; wherein the virtual machine stack is used to store function call parameters, local variables, operands and call function stack frame information; the indirect access variable stack is used to store elements of a function's local array variables, local structures and elements of union variables; and the indirect access variable stack memory space is allocated to the function in the virtual machine stack; The second memory area is used to store and manage application volatile storage medium RAM data.

2. The method according to claim 1, characterized in that The application RAM data includes module global data, and the storing and managing the application RAM data through the second memory area includes: On any logical channel, when the virtual machine first calls a module program of an application module corresponding to an application, a second starting position of allocating module global data and module global data management information memory space to the called application module is determined at a position of the buffer common area close to the second memory area; The module global data and module global data management information memory space are allocated to the called application module from the second starting position toward the first memory area and initialized.

3. The method according to claim 1, characterized in that The application RAM data includes temporary static variable data, and the storing and managing the application RAM data through the second memory area includes: After the system starts running, starting from the second memory area toward the first memory area, a newly added second memory area is acquired from the buffer common area; The newly added second memory area is used as a memory space for temporary static variable data of all applications and initialized.

4. The method according to claim 3, characterized in that The application RAM data includes temporary dynamic variable data, and after the newly added second memory area is used as the memory space for temporary static variable data of all applications and initialized, it also includes: When an application is selected on the logical channel for the first time, a first starting position for allocating temporary dynamic variable data memory space to the selected application is determined at a position of the buffer common area close to the second memory area; The temporary dynamic variable data memory space is allocated to the selected application from the first starting position toward the first memory area and initialized.

5. The method according to any one of claims 1 to 4, characterized in that: Also includes: When deselection is applied on any logical channel, the memory space of all module global data and module global data management information matching the current logical channel is reclaimed under the premise of maintaining the continuity of all remaining module global data and module global data management information memory, and maintaining the continuity of module global data memory space and temporary dynamic variable data memory space.

6. A memory management device, characterized in that: Configuration on resource-constrained devices, including: A memory area division module is used to divide the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area; wherein the first memory area and the second memory area are used memory areas at both ends of the memory area managed by the virtual machine; the buffer common area is an unused memory area in the middle of the memory area managed by the virtual machine; the first memory area and the second memory area allocate memory space from the buffer common area as needed; A first memory area storage management module is used to store and manage a virtual machine stack and an indirect access variable stack through the first memory area; wherein the virtual machine stack is used to store function call parameters, local variables, operands and call function stack frame information; the indirect access variable stack is used to store elements of a function's local array variables, local structures and elements of union variables; and the indirect access variable stack memory space is allocated to the function in the virtual machine stack; The second memory area storage management module is used to store and manage application RAM data through the second memory area.

7. A restricted device, characterized in that: The restricted device has an operating system installed thereon, a runtime environment executed therein, and the restricted device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the memory management method according to any one of claims 1 to 5.

8. A terminal, characterized in that: Comprising a restricted device as claimed in claim 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the memory management method of any one of claims 1-5 when executed.

10. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the memory management method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Management method and device for indirect access variable stack

    CN116541132A

  • Memory management method and system, desktop computer and computer storage medium

    CN118312320A

  • Tracking memory modifications at cache line granularity

    US20230367712A1

  • Safety in automotive hosted hypervisor systems for secure monitor calls using shared buffers

    WO2024158483A1