Runtime memory management method and device, operating system, virtual machine, equipment and terminal

By establishing module memory links and parsing memory addresses when selecting applications, the problems of inter-module variable positioning addressing and secure isolation in resource-constrained devices are solved, and memory access efficiency is improved.

CN119127075APending Publication Date: 2024-12-13BEIJING CEC HUADA ELECTRONIC DESIGN CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411198420.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

In resource-constrained devices, there are difficulties in variable positioning addressing and secure isolation of variable data between multiple modules or the same modules. The prior art causes memory access efficiency by dynamic allocation of memory space in real time.

Method used

By calling the entry function when selecting an application, establishing a module memory link, parsing the memory address in the bytecode, determining the actual memory space start address of the target module, and achieving secure isolation of variable data and efficient memory access.

Benefits of technology

It solves the problems of variable positioning and addressing and security isolation between multiple modules, improves memory access efficiency, and ensures the secure isolation of variable data between logical channels and intermodule.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127075A_ABST
    Figure CN119127075A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a runtime memory management method and device, an operating system, a virtual machine, equipment and a terminal.The method comprises the steps that when an application is selected, an entry function of the current selected application is called, and module memory links of all modules imported by the current selected application are established; when the current selected application code is executed, in the processing process that the virtual machine executes the target data instruction to access the byte code corresponding to the memory address, the memory address included in the byte code is analyzed, and module information of a target module where the access memory is located and the memory type are obtained; determining an initial address of an actual memory space of the target module according to module information and a memory type of the target module and the module memory link; and performing address space access according to the initial address of the actual memory space of the target module. According to the technical scheme, safe isolation of variable data between logic channels and between modules can be ensured, and meanwhile the memory access efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of memory management technology, and in particular to a runtime memory management method, apparatus, operating system, virtual machine, equipment, terminal, medium and program. Background Art

[0002] Wasm (WebAssembly) is a method of using non-JavaScript (JS for short, a lightweight, interpreted or just-in-time compiled programming language with function priority) script code and running it in a browser. Non-JavaScript code includes C language, C++ or Rust (Rust Programming Language, a memory-safe programming language focusing on performance and concurrency). After the non-JavaScript code is loaded into the client browser, it can run at a speed close to native. The program code of the program module is compiled through the binary intermediate representation (binary intermediate representation) wasm technology, and the module program data can be obtained after conversion through the conversion tool. The module program data can be loaded into a resource-constrained device that supports the wasm virtual machine platform, such as a smart card security chip. The RAM (Random Access Memory) resources of resource-constrained devices are limited. After the conversion tool converts the program code, since the starting position of the global variables in the program data of different modules is the same, the compilation allocation starting address pre-set in the conversion tool is also the same, resulting in the same starting address of the global variables of each module after conversion. Therefore, it is necessary to solve the problem of variable location and addressing between multiple modules or the same module, as well as the problem of safe isolation between logical channels of variable data and between modules. Summary of the invention

[0003] Embodiments of the present invention provide a runtime memory management method, apparatus, operating system, virtual machine, device, terminal, medium and program, which can ensure the secure isolation of variable data between logical channels and modules, while improving memory access efficiency.

[0004] According to one aspect of the present invention, there is provided a runtime memory management method, comprising:

[0005] When selecting an application, calling the entry function of the currently selected application, and establishing module memory links of all modules imported by the currently selected application; wherein the module memory link is a process of memory space allocation, memory address positioning, and memory access control of the global data memory or local data memory accessed by the binary executable file program when running;

[0006] When the currently selected application code is executed, in the bytecode processing process corresponding to the memory address accessed by the virtual machine executing the target data instruction, the memory address included in the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed;

[0007] Determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link;

[0008] The address space is accessed according to the starting address of the actual memory space of the target module.

[0009] According to another aspect of the present invention, there is provided a runtime memory management device, comprising:

[0010] A module memory link establishment module is used to call the entry function of the currently selected application when selecting an application, and establish module memory links for all modules imported by the currently selected application; wherein the module memory link is a process of memory space allocation, memory address positioning, and memory access control of the global data memory or local data memory accessed by the binary executable file program when running;

[0011] A first memory address parsing module is used for parsing the memory address included in the bytecode into module information and memory type of the target module where the memory is located during the bytecode processing corresponding to the memory address accessed by the virtual machine when the currently selected application code is executed;

[0012] A starting address determination module, used to determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link;

[0013] The address space access module is used to perform address space access according to the starting address of the actual memory space of the target module.

[0014] According to another aspect of the present invention, an operating system is provided, wherein a runtime environment is executed in the operating system, and the operating system executes the runtime memory management method described in any embodiment of the present invention through the runtime environment.

[0015] According to another aspect of the present invention, a virtual machine is provided, wherein the virtual machine runs on an operating system, wherein a runtime environment is executed in the operating system, and the operating system executes the runtime memory management method described in any embodiment of the present invention through the runtime environment.

[0016] According to another aspect of the present invention, an electronic device is provided, on which the above-mentioned operating system is installed, and the electronic device includes:

[0017] at least one processor; and

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

[0019] 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 runtime memory management method described in any embodiment of the present invention.

[0020] According to another aspect of the present invention, a terminal is provided, comprising the electronic device mentioned above.

[0021] 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 runtime memory management method described in any embodiment of the present invention when executed.

[0022] 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 runtime memory management method according to any embodiment of the present invention is implemented.

[0023] The embodiment of the present invention establishes module memory links of all modules imported by the currently selected application by calling the entry function of the currently selected application when selecting an application. When the currently selected application code is executed, the virtual machine executes the target memory instruction to access the memory address, and in the corresponding bytecode processing process, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is to be accessed, thereby determining the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link information, and then performing address space access according to the starting address of the actual memory space of the target module, solving the existing variable location addressing problem between multiple modules or the same module, and the problem of safe isolation of variable data between logical channels and modules, and ensuring the safe isolation of variable data between logical channels and modules, while improving memory access efficiency.

[0024] 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

[0025] 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.

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

[0027] Figure 2 is a flowchart of another runtime memory management method provided by an embodiment of the present invention;

[0028] Figure 3 is a flowchart of another runtime memory management method provided by an embodiment of the present invention;

[0029] Figure 4 is a schematic diagram of a runtime memory management device provided by an embodiment of the present invention;

[0030] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention;

[0031] Figure 6 is a structural diagram of a terminal provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0032] 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.

[0033] 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.

[0034] Figure 1 is a flowchart of a runtime memory management method provided by an embodiment of the present invention. This embodiment is applicable to the case where a module memory link is established to locate the variable of the addressing module when selecting an application. The method can be executed by a runtime memory management device, which can be implemented by software and / or hardware and can generally be integrated in an electronic device. The electronic device can be a terminal device. The embodiment of the present invention does not limit the specific device type of the electronic device. Accordingly, Figure 1 As shown, the method includes the following operations:

[0035] S110. When an application is selected, an entry function of the currently selected application is called to establish module memory links of all modules imported by the currently selected application.

[0036] Among them, the currently selected application is the currently selected application. The entry function is the entry point for the virtual machine to start, and the application entry function can be defined in the module. The module can include an application executable code container in the binary file, including the instructions, data and metadata of the application, which can be directly run by the operating system. The module memory link can be the memory space allocation, memory address positioning and memory access control process of the global data memory or local data memory accessed by the binary executable file program when running.

[0037] In resource-constrained devices, after an application is explicitly selected through the SELECT command, the application is considered to be activated on the current logical channel. Applications should be selected implicitly or explicitly. When the RTE (Runtime Environment) receives a SELECT command, if the command content matches the application AID (Application Identifier), the application is explicitly selected, and the RTE should activate this application as the selected application. When an application is selected when the MANAGE CHANNEL command opens a logical channel, it is an implicitly selected application. After the application selection is successful, the application should become the currently selected application. An application can be selected on multiple logical channels, not just on one logical channel. That is, the same application can be selected by multiple different SELECT commands on multiple logical channels, and can be in different states at the same time.

[0038] Module memory linking is one of the processing steps in the module loading process. Module loading refers to the process in which the application installer loads the binary loadable file into the AOS (Multi-Application Smartcard Operation System) to complete the conversion of the link in the card into a binary executable file, including module function linking and module memory linking. When the binary loadable file is loaded into the AOS, the module function linking can be executed. When the binary loadable file is loaded into the AOS, the module memory linking can also be executed. When loading the binary loadable file data segment, apply for memory to store the data segment data and record the data segment memory address to complete the memory link in the loading phase.

[0039] In the prior art, when solving the variable location and addressing problem between multiple modules or the same module, and the security isolation problem between logical channels and modules of variable data, the commonly used technical means is to dynamically allocate memory space for the variable data of the module called by the application in real time when the application calls the module during the application running process. The above memory management method needs to be triggered when the module is called, so it will reduce the access efficiency of the application to the memory when it is running.

[0040] In an embodiment of the present invention, when the RTE in a resource-constrained device selects an application, after calling the entry function of the currently selected application, a module memory link of all modules imported by the currently selected application can be established. It can be seen that the embodiment of the present invention can allocate memory space for the variable data of all modules imported by the selected application when the application is selected, which belongs to a way of pre-allocating memory for the variable data of the module. Therefore, when the application is selected, the memory space is allocated for the variable data of all modules imported by the selected application, which can avoid the real-time dynamic allocation of memory space for the variable data of the called module during the application operation. It can not only solve the problem of variable location addressing between multiple modules or the same module, and the problem of security isolation between logical channels and modules of variable data, but also improve the memory access efficiency at runtime.

[0041] It should be noted that when there are multiple logical channels, a module memory link of all modules imported by the selected application on each opened logical channel can be established.

[0042] S120. When the application code is currently selected for execution, the virtual machine executes the target memory instruction to access the memory address. During the corresponding bytecode processing, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed.

[0043] Wherein, the target memory instruction may be an instruction type such as a memory data loading instruction or a memory data storage instruction, as long as it is an instruction type that can involve memory access, and the embodiment of the present invention does not limit the specific instruction type of the target memory instruction. Exemplarily, the memory data loading instruction may include, but is not limited to, i32.load, i32.load8_s, i32.load8_u, i32.load16_s, and i32.load16_u, etc., and the memory data storage instruction may include, but is not limited to, i32.store, i32.store8, i32.store16, memory.copy, and memory.fill, etc. The target module may be the module that the currently selected application is to access through the target memory instruction during the code execution process. The module information may be information that can reflect the module type, such as a module identifier, etc. The memory type may include a global data space and an indirect access variable stack. Wherein, the global data space may include two types: a module global variable memory area and a module read-only data heap area. The module global data memory area can store global data. Global data refers to data defined in the AOS application and visible to the entire module. Its scope is limited to a specific module, also known as global variables. This type of data is usually used to share information within the module, but is not visible or accessible in other modules. The heap area can store module read-only data (also known as module read-only variables). Module read-only data can be global data that is visible to the entire module but can only be read and not modified. It is usually used to store constants, configuration information, or other values ​​that will not change during the running of the application. The indirect access variable stack is used to store part of the method call information of the AOS application, including combined type data information such as local arrays and structures.

[0044] After the currently selected application is selected, the target memory instruction can be executed during the execution of the application code by the virtual machine, and the memory address will be accessed during the execution of the target memory instruction. Specifically, after each module function is compiled, a series of bytecodes will be formed. During the bytecode processing, the virtual machine can parse the memory address obtained by the preliminary parsing of the bytecode to obtain the module information and memory type of the target module where the memory is accessed, so as to link the target module to the actual memory address.

[0045] S130. Determine a starting address of an actual memory space of the target module according to the module information and memory type of the target module and the module memory link.

[0046] S140. Perform address space access according to the starting address of the actual memory space of the target module.

[0047] The actual memory space refers to the physical memory space on the device that can actually be used to store or run data.

[0048] Correspondingly, after determining the module information and memory type of the target module, the starting address of the actual memory space of the target module can be further determined in combination with the established module memory link, so as to perform address space access based on the starting address of the actual memory space of the target module and realize the location addressing problem of the variable data of the target module.

[0049] In the embodiment of the present invention, memory space can be arranged for different modules according to the actual memory usage, and the data segment and global segment of the binary executable file can be defined. The binary executable file is generated by the application installer and can be directly processed and executed by the executor, including the executable module. In the application module conversion process, the binary intermediate file of the application module and one or more library module link files can be used as input, and the application converter converts and outputs the binary loadable file and link file of the application module. The binary intermediate representation is a file generated by the application compiler compiling the source code, following the unified technical standards, so that different language compilers generate a unified intermediate file. On the basis of the binary link file, the external function link information of the converted binary intermediate file is provided to the application converter, so as to generate the final binary loadable file. The binary loadable file is loaded into the AOS, that is, the binary executable file. The data segment of the binary intermediate file can store memory initialization data, which mainly includes two parts of information: memory offset (where to start initializing the memory) and initial data. The memory offset refers to the offset of a certain address in the segment relative to the segment head address (segment address) after the memory is segmented. The memory offset is also specified by an expression. The global segment of the binary intermediate file can include all global variable information defined in the module. When the binary loadable file is loaded into AOS, the module memory link is executed. When loading the binary loadable file data segment, apply for memory to store the data segment data and record the data segment memory address to complete the memory link in the loading stage. It can be seen that by arranging the memory space according to the actual memory usage, defining the data segment and the global segment to establish the module memory link, the variable location addressing problem between multiple modules or the same module, as well as the security isolation problem between the logical channels and modules of the variable data can be solved.

[0050] In a specific example, when the virtual machine executes the application code of the currently selected application, it can execute memory data loading instructions such as i32.load, i32.load8_s, i32.load8_u, i32.load16_s and i32.load16_u, etc., or memory data storage instructions i32.store, i32.store8, i32.store16, memory.copy and memory.fill, etc., and the memory address will be accessed when executing the above target memory instructions. Since each module function will form a series of bytecodes after compilation, in the bytecode processing corresponding to the target memory instruction accessing the memory address, the memory address carried in the bytecode can be parsed to obtain the module and memory type of the target module where the memory is accessed, and then linked to the actual memory address. The target memory instruction will have a memory offset information, which is also called an offset, which refers to the distance between the actual address of the storage unit and the segment address of the segment where it is located. The memory offset information included in the target memory instruction may be the operand memarg.offset of the instruction, or it may be the value popped from the operand stack. At the same time, the target memory instruction generally requires a memory base address addr, which is pushed into the operand stack through other numerical instructions. For example, the base address pushed into the operand stack by i32.const_0 is 0, and the base address information pushed into the operand stack by const.addr_u8 includes module information and base address value. The module information is such as module identification, and the information format of the base address value can be, for example, ((module identification << 16) | module base address). The memory address can be obtained by adding the base address addr to the memory offset such as memarg.offset. Correspondingly, the base address and the memory offset of the bytecode are the memory type of the final parsing of the bytecode.

[0051] However, some bytecodes do not need to configure the base address, and directly use the value popped from the operand stack as the memory offset, such as the memory.copy and memory.fill instructions. This is because before these bytecodes are executed, the bytecodes related to the memory variable base address operation have been executed, for example, i32.const_0—>local.get_2—>i32.add, and finally the calculated memory offset is pushed into the operand stack to be passed to the memory.copy and memory.fill instructions.

[0052] Correspondingly, after determining the module information and memory type of the target module, the module memory link information can be searched based on the module information and memory type of the target module to determine the starting address of the actual memory space of the target module, and then the address space access can be performed according to the starting address of the actual memory space of the target module.

[0053] In an optional embodiment of the present invention, the runtime memory management method may also include: when the currently selected application code is executed, during the bytecode processing process of the virtual machine executing the API (Application Programming Interface) calling the corresponding bytecode, the memory address passed in the function parameter passing process is parsed to obtain the module information and memory type where the accessed memory is located; according to the module information and memory type of the target module and the module memory link, the starting address of the actual memory space of the target module is determined; and the address space is accessed according to the starting address of the actual memory space of the target module.

[0054] It is understandable that during the process of the virtual machine executing the application code, the virtual machine may also execute API calls. For example, when the virtual machine executes the bytecodes of function calls such as call_u16, call_outer_u8, call_inner_u8, and call_indirect, the function parameters are pointers, arrays, and structure types, and the parameters are actually memory offsets. When calling the function, the parameters of the memory offset have been pushed into the operand stack through bytecode operations. Correspondingly, during the bytecode processing corresponding to the execution of the API call by the virtual machine, the memory address passed in the function parameter passing process can also be parsed to obtain the module information and memory type of the target module where the memory is accessed, and then according to the module information and memory type of the target module and the module memory link, the starting address of the actual memory space of the target module is determined, and the address space is accessed according to the starting address of the actual memory space of the target module.

[0055] The embodiment of the present invention establishes module memory links of all modules imported by the currently selected application by calling the entry function of the currently selected application when selecting an application. When the currently selected application code is executed, the virtual machine executes the target memory instruction to access the memory address, and in the corresponding bytecode processing process, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is to be accessed, thereby determining the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link information, and then performing address space access according to the starting address of the actual memory space of the target module, solving the existing variable location addressing problem between multiple modules or the same module, and the problem of safe isolation of variable data between logical channels and modules, and ensuring the safe isolation of variable data between logical channels and modules, while improving memory access efficiency.

[0056] Figure 2is a flowchart of another runtime memory management method provided by an embodiment of the present invention. This embodiment is specific based on the above embodiment. In this embodiment, multiple specific optional implementation methods for establishing module memory links for all modules imported by the currently selected application are provided. Figure 2 As shown, the method of this embodiment may include:

[0057] S210: When an application is selected, the entry function of the currently selected application is called to find all other modules imported by the module code of the currently selected application, and record information of all imported modules.

[0058] In an embodiment of the present invention, a module memory link of all modules imported by the currently selected application can be established in real time when an application is selected. Specifically, when an application is selected, after calling the entry function of the currently selected application, all other modules imported by the module code where the currently selected application is located can be found, and all imported module information can be recorded. Optionally, the recorded module information can include, but is not limited to: the identifier of the imported module and the module global data (rwdata) space size of the imported module.

[0059] S220 , when an application is selected, memory space is sequentially allocated to the recorded import module and the module where the selected application is located, and information on the allocated memory space is recorded.

[0060] At the same time, when the application is selected, memory space can be allocated sequentially for the recorded import modules and the module where the currently selected application is located, and the information related to the allocated memory space can be recorded. Exemplarily, the information of the allocated memory space can include but is not limited to: the starting address of each memory space and / or the starting offset of the memory space of each module. Among them, the starting offset of the memory space can be understood as an offset based on the pre-defined starting address of the memory space.

[0061] S230: Establish an association between the module information and the memory space information allocated to the module to obtain the module memory link information.

[0062] Correspondingly, after recording the relevant information of the memory space allocated for the currently selected application, the association between the module information of the target module and the memory space information allocated by the module can be established, thereby obtaining the information of the module memory link. Exemplarily, a mapping method between the module identifier of the module and the starting address or offset address of the module's memory space can be established to obtain the information of the module memory link. For example, an association can be established by establishing a corresponding relationship between the module identifier and the module's memory space (such as the starting address or offset address of the module's memory space). The embodiment of the present invention does not limit the association method between the module information and the memory space information allocated by the module.

[0063] The above technical solution dynamically establishes an association between module information and the memory space information allocated by the module as the module memory link information when the application entry function is called. When the application entry function is called, the dynamically established module memory link information may be updated, which can save RAM space and thus save memory resources.

[0064] Therefore, when an application is selected, when the entry function of the application on the current logical channel is called, all other modules imported by the module code of the currently selected application are found, and after recording the information of all imported modules, it is possible to first check whether the module memory link information has been established for the currently selected application or the module in which it is located. If it has been established, there is no need to update the module memory link information, and the command dispatch can be directly issued; otherwise, memory space should be allocated based on the module information of the currently selected application, and an association between the module information and the memory space information allocated by the module should be established to obtain the module memory link information, and record the application or module associated with the current module memory link information.

[0065] In an optional embodiment of the present invention, the establishment of module memory links for all modules imported by the currently selected application may also include: accessing module information to search for the module memory links; wherein the module information may include module management information or NVM (Non-Volatile Memory) space.

[0066] The module information may include two types: module management information or NVM space. The module management information may be used to manage the memory allocation information of the application.

[0067] In the embodiment of the present invention, the module memory links of all modules imported by the currently selected application can also be established by accessing the module information to search for the module memory link information. It is understandable that before searching for the module memory link information, the module memory link needs to be established in advance for each application.

[0068] In an optional embodiment of the present invention, before accessing the module management information to search for the module memory link, it may also include: determining a target generation method for the memory link of the module to which the application belongs according to the application publishing method; and generating information on the module memory link of the application using the target generation method.

[0069] The application publishing mode may be the publishing type of the binary file where the application module is located, which may include two publishing modes: pre-installed (masked) and post-downloaded. The target generation mode may be the mode of generating information of memory links of different types of application generation modules.

[0070] In the embodiment of the present invention, different application release modes have different modes for generating module memory link information. Therefore, before configuring the module memory link information of the generated application, it is necessary to analyze and determine the application release mode, thereby determining the target generation mode of the module memory link matched by the application according to the application release mode, and generating the module memory link information of the application using the matching target generation mode for each type of application.

[0071] In an optional embodiment of the present invention, the application publishing method may include post-downloading the application; the information of the module memory link of the application generated by the target generation method may include: during the download process of the binary executable file of the post-download application, based on the information of all modules imported by the binary executable file import segment, generating the logical allocation information of the memory space of each module; and storing the memory space allocation information of each module in the module information of the currently downloaded module.

[0072] Among them, the post-download application can be an application that needs to be installed and executed through the AOS application installer. The AOS application installer can load the binary loadable file of the post-download application into the operating system to become a binary executable file, and install the module contained in the binary executable file as an application instance, register and initialize it, and make it a selectable and executable application instance. The binary executable file is generated by the AOS application installer. Files that can be directly processed and executed by the executor include executable modules. The binary loadable file is loaded into AOS and becomes a binary executable file. The binary loadable file contains information about the executable module, including the import, function, global, export, element and code information of the application. Accordingly, after the binary loadable file is loaded into AOS to become a binary executable file, the import segment included in the binary executable file can be decoded into import function information representing the module component. The current download module can be a module of the binary executable file of the current download post-download application.

[0073] For the post-download application, in the binary executable file download process of the post-download application, a preliminary link can be performed based on the import mudule_aid (i.e., module AID) of the binary executable file import segment. The link process is to locate the module identified by mudule_aid based on the import module mudule_aid information, and cache all the module information located by the analysis, which may include the internal representation of the module, the content of the module management information (e.g., the module registry), or the storage location of the module management information. Among them, the internal representation of the module can be the identification of the module in the device, i.e., the module identification. Further, all the information located to the module can be read, and the information of its global segment can be obtained according to the binary executable file of the post-download application, and the size of the rwdata (module global data) variable can be calculated, and then the memory space is allocated to the rwdata variable to generate the memory space allocation information of each module. Further, the memory space allocation information of each module can be stored in the module management information or NVM space of the current download module. It should be noted that if the memory space allocation information of each module needs to be stored in the NVM space, it is necessary to establish an association between the corresponding NVM space and the currently downloaded module in order to query the corresponding NVM space to obtain the module memory link information.

[0074] In an optional embodiment of the present invention, the application publishing method may include presetting applications; the information of module memory links of the application generated by the target generation method may include: in the process of generating a mask file, generating information on the logical allocation of memory space for each module imported by the application module import segment; and outputting the memory space allocation information of each module as generation data of module information to the mask file for storage.

[0075] Among them, the preset application can be an application pre-loaded and set in the system, and the application does not need to be loaded through the AOS application installer. The module memory link of the preset application can be stored in the mask data file. The binary loadable file corresponding to the preset application is outside the device, and the corresponding mask data file is generated through the mask tool. The mask data can be compiled with other operating system codes to form a production file and preset in the operating system. On the device, you only need to complete the installation of the instance (application) of the preset application module.

[0076] Correspondingly, for preset applications, in the process of generating a mask file through the Mask tool, the memory space allocation information of all modules imported by the application module (including the application module itself) can be generated to generate the module memory link of the preset application, and then the memory space allocation information of each module can be used as the generation data of the module information and output to the mask file for storage.

[0077] In an optional embodiment of the present invention, the generation of memory space allocation information for each module may include: obtaining the global segment information of the module, calculating the space size of the global segment module global data; allocating memory space to the module global data, and recording the first memory space allocation information; allocating memory space to all local variables of all imported modules, and recording the second memory space allocation information.

[0078] The first memory space allocation information may be the memory space allocation information for calculating the global variables of the non-imported module, and the second memory space allocation information may be the memory space allocation information for calculating the global variables of the imported module.

[0079] Specifically, whether for a post-download application or a preset application, when generating the memory space allocation information for each module, the size of the rwdata variable (module global data) can be calculated for each module, and then the first memory space allocation information can be allocated to the rwdata variable, and the information related to this allocation can be recorded. For example, the memory address, space size or memory offset allocated to the module rwdata variable (module global data) can be recorded. At the same time, the second memory space allocation information can be allocated to the rwdata variables of all imported modules, and the space allocation related information can be recorded. For example, the memory offset allocated to the rwdata variables of the imported modules can be recorded. The above-mentioned memory space allocated to the rwdata variables of the modules can specifically be RAM space.

[0080] The above method of accessing module information to search for module memory links is used to establish module memory links for all modules imported by the currently selected application. When the application entry function is called, it is no longer necessary to dynamically establish the association between the module information and the memory space information allocated by the module as the information of the module memory link. It is only necessary to search for the pre-configured module memory link information based on the module management information or NVM space, etc., which can be directly read and used. In order to further speed up the access speed, the pre-configured module memory link information can also be read into the RAM data structure for cache, and the application or module associated with the module memory link information is recorded. When the entry function of the application on the logical channel currently processing the command is about to be called, the module memory link information of the application or the module is read out, and the command is directly dispatched, which can further improve the efficiency of memory access.

[0081] S240. When the application code is currently selected for execution, during the bytecode processing corresponding to the target memory instruction executed by the virtual machine to access the memory address, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed, or, during the bytecode processing corresponding to the execution of the API call by the virtual machine, the memory address passed in the function parameter passing process is parsed to obtain the module information and memory type of the target module where the memory is accessed.

[0082] S250. Determine a starting address of an actual memory space of the target module according to the module information and memory type of the target module and the module memory link.

[0083] S260. Perform address space access according to the starting address of the actual memory space of the target module.

[0084] The above technical solution, by adopting a variety of optional methods to establish module memory links for all modules imported by the currently selected application, enriches the method of establishing module memory links for all modules imported by the currently selected application, which can not only ensure the safe isolation of variable data between logical channels and modules, but also further improve memory access efficiency.

[0085] Figure 3 is a flowchart of another runtime memory management method provided by an embodiment of the present invention. This embodiment is specific based on the above embodiment. In this embodiment, a specific optional implementation method for determining the starting address of the actual memory space of the target module to access the address space is provided. Figure 3 As shown, the method of this embodiment may include:

[0086] S310: When an application is selected, the entry function of the currently selected application is called to establish module memory links of all modules imported by the currently selected application.

[0087] S320. When the application code is currently selected for execution, during the bytecode processing corresponding to the target memory instruction executed by the virtual machine to access the memory address, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed, or, during the bytecode processing corresponding to the execution of the API call by the virtual machine, the memory address passed in the function parameter passing process is parsed to obtain the module information and memory type of the target module where the memory is accessed.

[0088] S330. Determine the access space type according to the module information and memory address of the target module.

[0089] In the embodiment of the present invention, the access space type may include two types: memory space and indirect access variable stack.

[0090] In an optional embodiment of the present invention, before determining the access space type according to the module information and memory address of the target module, it may also include: when it is determined that the module information of the target module is the first module information, determining that the target module is the current module; or, when it is determined that the module information of the target module is the second module information, determining that the target module is the designated module.

[0091] The first module information may be information identifying the current module, for example, it may be 0 or other types of identifiers that can identify the current module. The current module may be the module currently executing the function. The second module information may be information identifying the specified module, for example, it may be a non-zero identifier or other types of identifiers that can identify the specified module. The specified module may be the module specified by the current module, that is, the module imported by the current module.

[0092] When the bytecode of some target memory instructions is executed, such as memory data loading instructions such as i32.load, i32.load8_s, i32.load8_u, i32.load16_s and i32.load16_u, or memory data storage instructions such as i32.store, i32.store8 and i32.store16, the value of the memory address is parsed, and the virtual machine can determine the module where the memory is accessed based on the module information of the parsed target module. If the module information of the target module is determined to be the first module information such as 0, it indicates that the current module is accessed; if the module information of the target module is determined to be the second module information such as non-0, it indicates that the specified module is accessed.

[0093] S340, determine whether the access space type is memory space, if so, execute S350, otherwise, execute S360.

[0094] In the embodiment of the present invention, the access space type of the target module is different, and the method of determining the starting address of the actual memory space of the target module is also different.

[0095] In an optional embodiment of the present invention, determining that the access space type is a memory space may include: if the memory address is smaller than the size of the read-only variable area in the module information of the target module, determining that the memory address points to the heap area of ​​the module read-only data; if the memory address is greater than or equal to the size of the read-only variable area in the module information of the target module, determining that the memory address points to the module global data memory area.

[0096] In an embodiment of the present invention, the RAM memory space can be divided into a module global data memory and an indirect access variable stack. The virtual machine needs to determine the variable offset pointed to by the access address based on the module information and the memory address. If the access address points to the module read-only data, the data should be searched in the module read-only data area; if the access address points to the module global data, the data should be searched in the module global data memory area in combination with the logical channel information.

[0097] Generally, if the memory address of the target module is smaller than the size of the read-only variable area in the module information of the target module, it can be determined that the memory address of the target module points to the heap area of ​​the module's read-only data; if the memory address of the target module is greater than or equal to the size of the read-only variable area in the module information of the target module, it can be determined that the memory address of the target module points to the module's global data memory area.

[0098] In a specific example, assume that the memory offset of the module variable in the module information starts with a fixed value, such as 0x10, and then arrange all RO (Read-Only) type variables / data in sequence, and then arrange the global data memory area RW (Read-Write) type variables / data. The global_section structure of the global segment in the binary executable file corresponding to the module includes two structural items, rodata_base (indicating the starting address of the module read-only data in the memory space) and rwdata_base (indicating the starting address of the module global data in the memory space), which records the logical memory starting address of each type of module data in the memory space. The virtual machine parses the memory address of the target module. If the memory address obtained by parsing is smaller than the size of the read-only variable (also called read-only data) area in the module information of the target module, that is, the memory address obtained by parsing belongs to the range of [rodata_base, rwdata_base), then it is determined that the parsed memory address points to the heap area of ​​the module read-only data, indicating that the access data type is a read-only variable. Correspondingly, if the memory address obtained by parsing is greater than or equal to the size of the read-only variable area in the module information of the target module, that is, the memory address obtained by parsing belongs to the range of [rwdata_base, data_end), then it is determined that the parsed memory address points to the module global data memory area, indicating that the access data type is a global variable (also called global data), which is stored in the global data memory area.

[0099] In an optional embodiment of the present invention, determining that the access space type is an indirect access variable stack may include: if the memory address is greater than or equal to the size of the global variable area in the module information of the target module, determining that the memory address points to the indirect access variable stack.

[0100] Continuing with the above example, the virtual machine parses the offset of the memory address of the target module. If the memory address obtained by parsing is greater than or equal to the size of the global variable area in the module information of the target module, that is, the parsed memory address is greater than rwdata_base, it is determined that the memory address points to the indirect access variable stack, and the access data type may be the indirect access variable stack. In the embodiment of the present invention, the memory space of the local structure type data is the indirect access variable stack.

[0101] S350, searching for the module memory link, determining the memory space type of the target module, taking the starting address of the memory space of the target module as the starting address of the actual memory space, and performing address space access according to the starting address of the actual memory space of the target module.

[0102] In an embodiment of the present invention, if it is determined that the access space type of the target module is memory space, when the address space access is performed according to the starting address of the actual memory space of the target module, the module memory link can be searched to determine the memory space type of the target module, and then the starting address of the memory space of the target module is used as the starting address of the actual memory space.

[0103] In an optional embodiment of the present invention, if the target module is the current module, then performing address space access based on the starting address of the actual memory space of the target module may include: caching the starting address of the actual memory space of the current module; offsetting the current memory space by the starting address of the actual memory space of the current module based on the module information, memory type and module memory link of the target module to obtain the actual memory address of the accessed data; and performing address space access based on the actual memory address of the accessed data.

[0104] The actual memory space may be a physical memory space. The current memory space may be the starting address of the physical space of the module where the accessed data is located, generally the module where the currently executed bytecode is located. The actual memory address is also the starting address of the actual physical space.

[0105] If the target module is determined to be the current module, when the address space is accessed according to the starting address of the actual memory space of the target module, in order to speed up the positioning and addressing, the starting address of the actual memory space of the current module can be cached, or the actual memory space or pointer of the current module can also be cached. Further, according to the module information, memory type and module memory link of the target module, the memory space information allocated to the current module is queried to obtain the starting address of the actual memory space of the current module, and then the current memory space is offset by the starting address of the actual memory space of the current module to obtain the actual memory address of the access data of the current module, and the address space access can be performed based on the actual memory address of the access data.

[0106] In an optional embodiment of the present invention, if the target module is a designated module, then performing address space access based on the starting address of the actual memory space of the target module may include: offsetting the current memory space by the starting address of the actual memory space of the designated module based on the module information, memory type and module memory link of the target module to obtain the actual memory address of the accessed data; and performing address space access based on the actual memory address of the accessed data.

[0107] Correspondingly, if the target module is determined to be a specified module and the access space type is determined to be memory space, the module memory link can be searched according to the module information and memory type of the target module to determine the starting address of the actual memory space of the specified module, thereby offsetting the current memory space by the starting address of the actual memory space of the specified module to obtain the actual memory address of the accessed data, and then performing address space access based on the actual memory address of the accessed data.

[0108] In a specific example, continuing to use the above example as an example, if it is determined that the memory address of the target module (which can be the current module or the specified module) points to the heap area of ​​the module read-only data, the virtual machine obtains the starting address of the memory space of the target module read-only data. Generally, the starting address of the read-only variable in the NVM is recorded in the module management information of the NVM. After obtaining the starting address rodata_base of the memory space of the read-only data of the target module, the starting address of the actual memory space of the target module can be offset on the basis of the current memory space, that is, the offset of the current memory address of the target module relative to rodata_base is accumulated on the basis of the current memory space, and the actual memory address of the access data in the target module can be located to access rodata. If it is determined that the memory address points to the module global data memory area, the virtual machine obtains the starting address of the memory space of the target module global data, and offsets the current memory space to the starting address of the actual memory space of the target module, that is, the offset of the current memory address of the target module relative to rwdata_base is accumulated on the basis of the current memory space, and the actual memory address of the access data in the target module can be located to access rwdata memory.

[0109] S360: Determine that the access space type is an indirect access variable stack, obtain an actual memory address of the current indirect access variable stack, and perform address space access according to the actual memory address of the current indirect access variable stack.

[0110] In an embodiment of the present invention, if it is determined that the access space type of the target module is an indirect access variable stack, then when the address space access is performed according to the starting address of the actual memory space of the target module, the actual memory address of the current indirect access variable stack can be obtained, thereby performing the address space access according to the actual memory address of the current indirect access variable stack.

[0111] In an optional embodiment of the present invention, the address space access based on the actual memory address of the current indirect access variable stack may include: obtaining the actual physical memory space of the current indirect access variable stack; based on the highest address value of the actual physical memory space, offsetting the memory address relative to the set maximum space limit value of the indirect access variable stack toward a lower address to locate the actual memory address of the current indirect access variable stack; or, based on the starting address of the actual physical memory space, offsetting the memory address relative to the set base address of the indirect access variable stack to locate the actual memory address of the current indirect access variable stack; and performing address space access based on the actual memory address of the current indirect access variable stack.

[0112] The actual physical memory space may be the memory directly available in the current indirect access variable stack, which is the physical space actually used to store the data and instructions of the executing program when the computer is running. The value of the highest address of the indirect access variable stack can be set according to demand, and the embodiment of the present invention does not limit the specific value of the maximum space limit of the indirect access variable stack.

[0113] Specifically, the virtual machine can first obtain the information of the actual physical memory space of the current indirect access variable stack, such as including but not limited to the space size, memory end address or memory start address, etc. In general, the indirect access variable stack is multiplexed by multiple modules, and is also multiplexed by multiple logical channels, which is a memory space. After obtaining the actual physical memory space of the current indirect access variable stack, the memory address of the target module can be offset to the low address relative to the offset of the indirect access variable stack maximum space limit value set on the basis of the value of the highest address of the actual physical memory space of the current indirect access variable stack (such as 64k), so as to locate the actual memory address of the current indirect access variable stack. Alternatively, it is also possible to offset the memory address of the target module relative to the offset of the indirect access variable stack base address set on the basis of the starting address of the actual physical memory space of the current indirect access variable stack, so as to locate the actual memory address of the current indirect access variable stack. After locating the actual memory address of the current indirect access variable stack, the address space access can be performed according to the actual memory address of the current indirect access variable stack.

[0114] The above technical solution implements the management of RAM memory space, and divides the RAM memory space into a global data space and a space for an indirect access variable stack, wherein the global data space includes read-only variables and global variables. When the application is running, a method for establishing module memory links for all modules imported by the currently selected application is provided. When the virtual machine executes the bytecode of the target memory instruction to access the global variable, physical space mapping is performed according to the offset of the global variable, and the space where the global variable data is located is determined to be the indirect access variable stack, the global memory space or the NVM, which solves the existing variable location and addressing problems between multiple modules or the same module, and the problem of secure isolation of variable data between logical channels and modules, and can ensure the secure isolation of variable data between logical channels and modules, while improving memory access efficiency.

[0115] 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.

[0116] 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.

[0117] Figure 4 is a schematic diagram of a runtime memory management device provided by an embodiment of the present invention, such as Figure 4 As shown, the device includes: a module memory link establishment module 410, a first memory address parsing module 420, a start address determination module 430 and an address space access module 440, wherein:

[0118] The module memory link establishment module 410 is used to call the entry function of the currently selected application when selecting an application, and establish the module memory links of all modules imported by the currently selected application;

[0119] The first memory address parsing module 420 is used for parsing the memory address obtained by preliminary parsing of the bytecode during the corresponding bytecode processing process when the currently selected application code is executed, and obtaining the module information and memory type of the target module where the memory is accessed;

[0120] A starting address determination module 430, configured to determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link;

[0121] The address space access module 440 is used to perform address space access according to the starting address of the actual memory space of the target module.

[0122] The embodiment of the present invention establishes module memory links of all modules imported by the currently selected application by calling the entry function of the currently selected application when selecting an application. When the currently selected application code is executed, the virtual machine executes the target memory instruction to access the memory address, and in the corresponding bytecode processing process, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is to be accessed, thereby determining the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link information, and then performing address space access according to the starting address of the actual memory space of the target module, solving the existing variable location addressing problem between multiple modules or the same module, and the problem of safe isolation of variable data between logical channels and modules, and ensuring the safe isolation of variable data between logical channels and modules, while improving memory access efficiency.

[0123] Optionally, the runtime memory management device may also include a second memory address parsing module, which is used to parse the memory address passed in the function parameter passing process during the bytecode processing corresponding to the application programming interface API call executed by the virtual machine when the currently selected application code is executed, so as to obtain the module information and memory type of the target module where the memory is accessed; a starting address determination module, which is used to determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link; and an address space access module, which is used to perform address space access according to the starting address of the actual memory space of the target module.

[0124] Optionally, the starting address determination module is also used to: determine the access space type based on the module information and memory address of the target module; when it is determined that the access space type is the memory space, search the module memory link to determine the memory space type of the target module; and use the memory space starting address of the target module as the starting address of the actual memory space.

[0125] Optionally, the starting address determination module is also used to: when it is determined that the module information of the target module is the first module information, determine the target module as the current module; or, when it is determined that the module information of the target module is the second module information, determine the target module as the designated module.

[0126] Optionally, if the target module is the current module, the address space access module is also used to: cache the starting address of the actual memory space of the current module; offset the current memory space by the starting address of the actual memory space of the current module according to the module information, memory type and module memory link of the target module to obtain the actual memory address of the accessed data; and perform address space access based on the actual memory address of the accessed data.

[0127] Optionally, if the target module is a designated module, the address space access module is also used to: offset the current memory space by the starting address of the actual memory space of the designated module according to the module information, memory type and module memory link of the target module, to obtain the actual memory address of the accessed data; and perform address space access based on the actual memory address of the accessed data.

[0128] Optionally, the starting address determination module is also used to: if the memory address is smaller than the size of the read-only variable area in the module information of the target module, determine that the memory address points to the heap area of ​​the module read-only data; if the memory address is greater than or equal to the size of the read-only variable area in the module information of the target module, determine that the memory address points to the module global data memory area.

[0129] Optionally, the starting address determination module is also used to: determine the access space type based on the module information and memory address of the target module; when it is determined that the access space type is an indirect access variable stack, obtain the actual memory address of the current indirect access variable stack; the address space access module is also used to: perform address space access based on the actual memory address of the current indirect access variable stack.

[0130] Optionally, the starting address determination module is further used to: if the memory address is greater than or equal to the size of the global variable area in the module information of the target module, determine that the memory address points to the indirect access variable stack.

[0131] Optionally, the address space access module is also used to: obtain the actual physical memory space of the current indirect access variable stack; based on the highest address value of the actual physical memory space, offset the memory address relative to the set maximum space limit value of the indirect access variable stack toward a lower address, and locate the actual memory address of the current indirect access variable stack; or, based on the starting address of the actual physical memory space, offset the memory address relative to the set base address of the indirect access variable stack, and locate the actual memory address of the current indirect access variable stack; perform address space access based on the actual memory address of the current indirect access variable stack.

[0132] Optionally, the module memory link establishment module is also used to: when an application is selected, search for all other modules imported by the module code where the currently selected application is located, and record information about all imported modules; when an application is selected, sequentially allocate memory space to the recorded imported modules and the module where the currently selected application is located, and record information about the allocated memory space; establish an association between the module information and the memory space information allocated by the module to obtain information about the module memory link.

[0133] Optionally, the module memory link establishment module is further used to: access module information to search for information of the module memory link; wherein the module information includes module management information or NVM space.

[0134] Optionally, the runtime memory management device also includes a module memory link information generation module, which is used to: determine a target generation method for memory links of modules to which an application belongs according to an application publishing method; and generate module memory link information of the application using the target generation method.

[0135] Optionally, the application publishing method includes post-downloading the application; the module memory link information generation module is also used to: during the binary executable file download process of the post-download application, generate the memory space logical allocation information of each module according to the information of all modules imported by the binary executable file import segment; and store the memory space allocation information of each module in the module information of the currently downloaded module.

[0136] Optionally, the application publishing method includes presetting applications; the module memory link information generation module is also used to: generate information on the logical allocation of memory space for each module imported by the application module import segment during the process of generating a mask file; and output the memory space allocation information of each module as module information generation data to the mask file for storage.

[0137] Optionally, the module memory link information generation module is also used to: obtain the global segment information of the module, calculate the space size of the global segment module global data; allocate memory space to the module global data, and record the information of the first memory space allocation; allocate memory space to all local variables of all imported modules, and record the information of the second memory space allocation.

[0138] The above runtime memory management device can execute the runtime 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 runtime memory management method provided by any embodiment of the present invention.

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

[0140] An embodiment of the present invention further provides an operating system, in which a runtime environment is executed. The operating system executes the runtime memory management method provided by any embodiment of the present invention through the runtime environment.

[0141] An embodiment of the present invention further provides a virtual machine, which runs on an operating system. A runtime environment is executed in the operating system, and the operating system executes the runtime memory management method provided by any embodiment of the present invention through the runtime environment.

[0142] Figure 5 A schematic structural diagram of an electronic device 10 that can be used to implement an embodiment of the present invention is shown.

[0143] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 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 electronic device 10 can also be stored. The processor 11, the ROM 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.

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

[0145] 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, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, for example, executes a runtime memory management method as described in various embodiments of the present invention, which is executed by a runtime environment in an operating system, and the operating system is installed in an electronic device, and the method includes:

[0146] When selecting an application, calling the entry function of the currently selected application, and establishing module memory links of all modules imported by the currently selected application;

[0147] When the currently selected application code is executed, the virtual machine executes the target memory instruction to access the memory address. During the corresponding bytecode processing, the memory address obtained by the preliminary parsing of the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed;

[0148] Determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link;

[0149] The address space is accessed according to the starting address of the actual memory space of the target module.

[0150] In some embodiments, a runtime 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 16. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of a runtime 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 runtime memory management method as described in various embodiments of the present invention in any other appropriate manner (e.g., by means of firmware).

[0151] 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.

[0152] Optionally, the electronic device includes a resource-constrained device. The resource-constrained device includes: a smart card, a SE (Secure Element), a security chip or an embedded device.

[0153] 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.

[0154] 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.

[0155] Figure 6 is a structural diagram of a terminal provided according to an embodiment of the present invention. Figure 6 Said terminal comprises the electronic device 10 as described in any embodiment of the present invention.

[0156] 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.

[0157] 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 runtime memory management method, characterized in that: include: When selecting an application, calling the entry function of the currently selected application, and establishing module memory links of all modules imported by the currently selected application; wherein the module memory link is a process of memory space allocation, memory address positioning, and memory access control of the global data memory or local data memory accessed by the binary executable file program when running; When the currently selected application code is executed, in the bytecode processing process corresponding to the memory address accessed by the virtual machine executing the target data instruction, the memory address included in the bytecode is parsed to obtain the module information and memory type of the target module where the memory is accessed; Determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link; The address space is accessed according to the starting address of the actual memory space of the target module.

2. The method according to claim 1, characterized in that Also includes: When the currently selected application code is executed, during the bytecode processing corresponding to the application programming interface API call executed by the virtual machine, the memory address passed in the function parameter passing process is parsed to obtain the module information and memory type of the target module where the memory is accessed; Determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link; The address space is accessed according to the starting address of the actual memory space of the target module.

3. The method according to claim 1 or 2, characterized in that: The step of determining the starting address of the actual memory space of the target module according to the module information and the memory type of the target module and the module memory link comprises: Determine the access space type according to the module information and memory address of the target module; In the case where it is determined that the access space type is a memory space, searching for the module memory link to determine the memory space type of the target module; The starting address of the memory space of the target module is used as the starting address of the actual memory space.

4. The method according to claim 3, characterized in that Also includes: Determine the access space type according to the module information and memory address of the target module; When it is determined that the access space type is an indirect access variable stack, obtaining an actual memory address of the current indirect access variable stack; Address space access is performed according to the actual memory address of the current indirect access variable stack.

5. The method according to claim 1, characterized in that: The step of establishing module memory links for all modules imported by the currently selected application includes: When an application is selected, all other modules imported by the module code of the currently selected application are found, and information of all imported modules is recorded; When an application is selected, memory space is allocated to the recorded import module and the module where the currently selected application is located in sequence, and the allocated memory space information is recorded; An association is established between the module information and the memory space information allocated to the module to obtain the module memory link information.

6. A runtime memory management device, characterized in that: include: A module memory link establishment module is used to call the entry function of the currently selected application when selecting an application, and establish module memory links for all modules imported by the currently selected application; wherein the module memory link is a process of memory space allocation, memory address positioning, and memory access control of the global data memory or local data memory accessed by the binary executable file program when running; A first memory address parsing module is used for parsing the memory address included in the bytecode into module information and memory type of the target module where the memory is located during the bytecode processing corresponding to the memory address accessed by the virtual machine when the currently selected application code is executed; A starting address determination module, used to determine the starting address of the actual memory space of the target module according to the module information and memory type of the target module and the module memory link; The address space access module is used to perform address space access according to the starting address of the actual memory space of the target module.

7. An operating system, characterized in that: A runtime environment is executed in the operating system, and the operating system executes the runtime memory management method of any one of claims 1 to 5 through the runtime environment.

8. A virtual machine, characterized in that: The virtual machine runs on an operating system, a runtime environment is executed in the operating system, and the operating system executes the runtime memory management method of any one of claims 1 to 5 through the runtime environment.

9. An electronic device, characterized in that: The electronic device is installed with the operating system according to claim 7, and the electronic device comprises: 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 runtime memory management method according to any one of claims 1 to 5.

10. A terminal, characterized in that: Contains the electronic device as claimed in claim 9.