Memory management method and computer equipment

By obtaining the memory protection zone information and execution context at the end of the execution of the target program fragment, the illegal memory access location is automatically located, which solves the problems of insufficient positioning accuracy and versatility in the existing technology and realizes efficient and flexible illegal memory access detection.

CN120704882AActive Publication Date: 2025-09-26HENAN KUNLUN TECH CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202510820186.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-18
Publication Date
2025-09-26
Estimated Expiration
2045-06-18

AI Technical Summary

Technical Problem

The existing technology has poor accuracy and versatility in locating illegal memory accesses, which may lead to program crashes or data corruption and may cause security vulnerabilities. Existing methods are difficult to efficiently and accurately locate the location of illegal memory accesses.

Method used

By obtaining the memory protection zone information in the physical memory at the end of the execution of the target program fragment and obtaining the execution context information when an exception is detected, the location of the illegal memory access is determined based on this. This method does not require pattern matching and rule base, and automatically locates the illegal memory access location. It is suitable for general-purpose and real-time operating systems.

Benefits of technology

It improves the accuracy and versatility of locating illegal memory accesses, reduces false positives and missed negatives, and lowers performance overhead. It is applicable to various operating systems, including those with high real-time requirements, and does not rely on hardware memory management units.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704882A_ABST
    Figure CN120704882A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method and computer device.The method comprises the steps that in response to an execution ending event of a target program fragment, memory protection area information in a physical memory is obtained, and if it is detected that the memory protection area information is abnormal, execution context information corresponding to the target program fragment is obtained, and determining position information of illegal memory access based on the execution context information corresponding to the target program fragment. According to the method, the positioning accuracy and universality of illegal memory access can be improved, the performance overhead is reduced, and the system stability and security are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a memory management method and computer equipment. Background Art

[0002] Illegal memory access is often associated with memory out-of-bounds access, wild pointers, memory leaks, and asynchronous execution. It can cause program crashes or data corruption, and can also be exploited maliciously to cause security vulnerabilities, resulting in serious consequences. While relevant technologies can be used to locate the location of illegal memory access, their accuracy and versatility are limited. Summary of the Invention

[0003] The purpose of the embodiments of the present application is to provide a memory management method and computer device to improve the accuracy and versatility of locating illegal memory accesses.

[0004] In a first aspect, an embodiment of the present application provides a memory management method, comprising:

[0005] In response to an execution end event of the target program fragment, obtaining memory protection zone information in the physical memory;

[0006] If an abnormality in the memory protection zone information is detected, the execution context information corresponding to the target program fragment is obtained;

[0007] Based on execution context information corresponding to the target program fragment, location information of the illegal memory access is determined.

[0008] When the above technical solution is adopted, when the target program fragment ends execution, the memory protection zone information in the physical memory can be judged to determine whether the memory protection zone information is abnormal. If the memory protection zone information is detected to be abnormal, it means that an illegal memory access has occurred in the target program fragment within the memory protection zone. Therefore, the execution context information corresponding to the target program fragment can be obtained. Since the execution context corresponding to the target program fragment not only contains the execution context information of the target program fragment and each historical program fragment before the target program fragment, but also includes the execution context information of the abnormality detection of the memory protection zone information, the location information of the illegal memory access can be determined based on the execution context information corresponding to the target program fragment.

[0009] It can be seen that the method of the embodiment of the present application does not need to detect the running results of the target program fragment based on pattern matching and rule base, but instead performs anomaly detection on the memory protection zone information in the physical memory, and automatically determines the location information of the illegal memory access when the memory protection zone information is abnormal, providing a detailed basis for problem repair. Therefore, the method of the embodiment of the present application not only does not require developers to spend time debugging and troubleshooting the location of illegal memory access, but is also not prone to false alarms or missed alarms, and can cover complex memory operation scenarios.

[0010] Moreover, the embodiment of the present application can take the target program fragment execution end event as an opportunity, and when the memory protection zone information is detected to be abnormal, the memory management method can be automatically started, and there is no need to separately build a virtual machine and open up physical space to run the illegal memory access positioning program. Therefore, the performance overhead of the method of the embodiment of the present application is relatively small, and it is not only applicable to general-purpose operating systems with low real-time requirements, but also to real-time operating systems with relatively high real-time requirements. In addition, the method of the embodiment of the present application does not require the support of a hardware memory management unit, and can flexibly locate illegal memory accesses, which has high flexibility and convenience.

[0011] In one possible implementation, the physical memory includes multiple memory blocks. The memory blocks contain protection zones. The method further includes:

[0012] If it is detected that the protected area data of at least one of the multiple memory blocks is non-target data, it means that after executing the target program fragment, illegal access occurs in at least one protected area, and the protected area data stored therein is modified due to the illegal access. Therefore, it can be confirmed that the memory protected area information is abnormal, and the location of the illegal memory access can be started.

[0013] If it is detected that the protected area data in each of the multiple memory blocks are all target data, it means that after executing the target program fragment, no illegal access occurs in the physical memory. Therefore, it can be confirmed that the memory protection area information is normal, and the location of illegal memory access will not be started, thereby reducing unnecessary resource waste.

[0014] In a possible implementation, the plurality of memory blocks include a first memory block. Obtaining memory protection zone information in a physical memory corresponding to the target program fragment includes:

[0015] Acquire the protected area location information of the first memory block, and acquire the protected area data of the first memory block based on the protected area location information of the first memory block. At this point, it is possible to detect whether the protected area data of the first memory block is non-target data. If the protected area data of the first memory block is non-target data, it indicates that the protected area of ​​the first memory block may have been illegally accessed, and therefore, the illegal memory access can be located.

[0016] In one possible implementation, the first memory block further includes a data area, and the protection zone is located at an end of the data area. The protection zone location information of the first memory block includes: a physical address of the data area and an address length of the data area. Obtaining protection zone data of the first memory block based on the protection zone location information of the first memory block includes:

[0017] Determining a physical address of a protection zone based on a physical address of the data zone and an address length of the data zone;

[0018] The protection zone data of the first memory block is obtained from the physical memory based on the physical address of the protection zone.

[0019] In one possible implementation, the plurality of memory blocks further includes a second memory block. The method further includes:

[0020] If it is detected that the protected area data of the first memory block is the target data, it indicates that the protected area of ​​the first memory block has not been illegally accessed, and based on the positioning information of the second memory block, the positioning information of the protected area of ​​the second memory block is obtained;

[0021] The protection zone location information of the first memory block is updated based on the protection zone location information of the second memory block, so that the protection zone location information of the second memory block can be used as the protection zone location information of the first memory block.

[0022] In a possible implementation, the first memory block further includes a data area, and the protection area is located at an end of the data area. The method further includes:

[0023] If the data in the protected area of ​​the first memory block is detected to be non-target data, data area location information of the first memory block is output. The output data area location information of the first memory block can be used to more accurately determine the location of the data area of ​​the first memory block.

[0024] In one possible implementation, determining location information of an illegal memory access based on execution context information corresponding to a target program fragment includes:

[0025] Based on the execution context information corresponding to the target program fragment, the function call chain and register information of the target program fragment are determined; based on the function call chain and register information of the target program fragment, the location information of the illegal memory access is determined. Since the execution context information corresponding to the target program fragment covers the environment and state information of the execution of different program fragments, the function call chain and register information of the target program fragment can be obtained by parsing the context information corresponding to the target program fragment. Then, the function call chain and register information of the target program fragment can be used to determine the location information of the illegal memory access.

[0026] In one possible implementation, the execution context information corresponding to the target program fragment is obtained, including: when the target program fragment is an interrupt service program, since the system stack can save the interrupt scene, system call parameters and return values, the execution context information corresponding to the interrupt service program can be obtained from the system stack.

[0027] In one possible implementation, the execution context information corresponding to the target program fragment is obtained, including: when the target program fragment is the target program fragment of an application, since the task stack can save task local variables, function call parameters and return addresses, and save independent scenes during each task switch, the execution context information corresponding to the target program fragment of the application can be obtained from the task stack.

[0028] In one possible implementation, the method of an embodiment of the present application further includes: when the target program fragment is an interrupt service routine, if the memory protection zone information is detected to be normal, continuing execution of the application program interrupted by the interrupt service routine. This ensures that abnormal memory access does not occur during the execution of the interrupt service routine and that the application program interrupted by the interrupt service routine can run normally.

[0029] In one possible implementation, the method of an embodiment of the present application further includes: when the target program fragment is a target program fragment in an application, if the memory protection zone information is detected to be normal, executing the next program fragment in the application that follows the target program fragment. This ensures that the application continues to execute if the memory protection zone information is normal, allowing the application to execute normally without any illegal access.

[0030] In a second aspect, an embodiment of the present application further provides a memory management method, including:

[0031] In response to the memory request operation, a memory block is requested in the physical memory for the target program fragment, the memory block including a data area and a protection area, the protection area being located at the end of the data area;

[0032] Target data is stored in the protection area. When the target data is modified into non-target data, it is used to indicate that the protection area is illegally accessed. The data area is used to store the running data of the target program fragment.

[0033] In the memory management method of the embodiment of the present application, the memory block applied for the target program fragment includes not only a data area, but also a protection area. And the target data is also stored in the protection area. If the target data is modified to non-target data, it means that the data in the protection area is abnormal and it is possible to be illegally accessed. When the protection area is illegally accessed, the execution context information corresponding to the target program fragment is obtained, and then based on the execution context information corresponding to the target program fragment, the location information of the illegal memory access is determined.

[0034] It can be seen that the method of the embodiment of the present application does not need to detect the running results of the target program fragment based on pattern matching and rule base, but instead performs anomaly detection on the data in the protected area of ​​the memory block, and automatically determines the location information of the illegal memory access when the data in the protected area is abnormal, providing a detailed basis for problem repair. Therefore, the method of the embodiment of the present application not only does not require developers to spend time debugging and troubleshooting the location of illegal memory access, but is also not prone to false alarms or missed alarms, and can cover complex memory operation scenarios.

[0035] Moreover, the embodiment of the present application can take the target program fragment execution end event as an opportunity, and when a data anomaly is detected in the protected area, the memory management method can be automatically started, and there is no need to separately build a virtual machine and open up physical space to run the illegal memory access positioning program. Therefore, the performance overhead of the method of the embodiment of the present application is relatively small, and it is not only applicable to general-purpose operating systems with low real-time requirements, but also to real-time operating systems with relatively high real-time requirements. In addition, the method of the embodiment of the present application does not require the support of a hardware memory management unit, and can flexibly locate illegal memory accesses, which has high flexibility and convenience.

[0036] In one possible implementation, the method of the embodiment of the present application further includes:

[0037] In response to the memory release operation, releasing the memory block in the physical memory where the target program fragment is running;

[0038] The target data is stored in the data area of ​​the memory block. The target data is used to indicate that the released memory block is illegally accessed when the target data is modified to non-target data.

[0039] In the method of the embodiment of the present application, when releasing the memory block running the target program fragment in the physical memory, by storing the target data in the data area of ​​the memory block, it can be ensured that no abnormal access occurs after the memory block running the target program fragment is released.

[0040] In one possible implementation, multiple memory blocks exist in the physical memory, each of which is a memory block requested through a memory request operation or a memory block released through a memory release operation. The method of the embodiment of the present application further includes: obtaining protection zone location information for each memory block, the memory block information including the physical address of the data zone and the address length of the data zone, and determining a memory block linked list based on the memory block information of the multiple memory blocks.

[0041] In the method of the embodiment of the present application, the data in the protection zones of different memory blocks can be quickly accessed by traversing the memory block linked list, thereby improving the efficiency of abnormality detection in the protection zones of the memory blocks.

[0042] In a possible implementation, the plurality of memory blocks include a first memory block. Obtaining memory protection zone information in a physical memory corresponding to the target program fragment includes:

[0043] Obtaining the protected area location information of the first memory block;

[0044] The protection zone data of the first memory block is acquired based on the protection zone location information of the first memory block.

[0045] In a possible implementation, obtaining the protection zone data of the first memory block based on the protection zone location information of the first memory block includes:

[0046] Determining the physical address of the protection area based on the physical address of the data area and the address length of the data area;

[0047] The protection zone data of the first memory block is obtained from the physical memory based on the physical address of the protection zone.

[0048] In one possible implementation, the plurality of memory blocks further includes a second memory block. The method of the embodiment of the present application further includes:

[0049] If it is detected that the protected area data of the first memory block is the target data, obtaining the protected area positioning information of the second memory block based on the positioning information of the second memory block;

[0050] The protection zone location information of the first memory block is updated based on the protection zone location information of the second memory block.

[0051] In one possible implementation, the method of the embodiment of the present application further includes:

[0052] If it is detected that the protected area data of at least one of the plurality of memory blocks is non-target data, it is determined that the memory protected area information is abnormal;

[0053] If it is detected that the protected area data in each of the plurality of memory blocks is the target data, it is confirmed that the memory protected area information is normal.

[0054] In a third aspect, embodiments of the present application further provide a computer device comprising: a processor and a memory storing a program. The program comprises instructions that, when executed by the processor, cause the processor to perform the method according to the first aspect of the embodiments of the present application or any possible implementation of the first aspect.

[0055] In a fourth aspect, embodiments of the present application further provide a computer device comprising: a processor and a memory storing a program. The program comprises instructions that, when executed by the processor, cause the processor to perform the method according to the second aspect of the embodiments of the present application or any possible implementation of the second aspect.

[0056] In a fifth aspect, an embodiment of the present application further provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on a computer device, the processor of the computer device executes the method described in the first aspect of the embodiment of the present application or any possible implementation method of the first aspect.

[0057] In a sixth aspect, an embodiment of the present application further provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on a computer device, the processor of the computer device executes the method described in the second aspect of the embodiment of the present application or any possible implementation method of the second aspect.

[0058] In a seventh aspect, an embodiment of the present application further provides a computer program product, comprising a computer program, wherein the computer program, when executed by a processor, implements the method according to the first aspect or any possible implementation manner of the first aspect.

[0059] In an eighth aspect, an embodiment of the present application further provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on a computer device, the processor of the computer device executes the method described in the second aspect of the embodiment of the present application or any possible implementation method of the second aspect.

[0060] The beneficial effects brought about by the third to eighth aspects of the embodiments of the present application can refer to the beneficial effects of the method described in the first aspect of the embodiments of the present application or any possible implementation method of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Further details, features and advantages of the present application are claimed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:

[0062] Figure 1 A schematic diagram illustrating an example computer device in which the various methods described herein may be implemented according to an exemplary embodiment of the present application;

[0063] Figure 2 A schematic diagram showing a flow chart of a memory management method according to an embodiment of the present application is shown;

[0064] Figure 3 A schematic diagram showing the flow of the memory management method in the memory application process according to an embodiment of the present application is shown;

[0065] Figure 4 A schematic diagram showing the flow of the memory management method in the memory release process according to an embodiment of the present application is shown;

[0066] Figure 5A schematic diagram of a first memory block according to an embodiment of the present application is shown;

[0067] Figure 6 A schematic diagram of a memory block linked list structure is shown, taking three memory blocks as an example;

[0068] Figure 7 A schematic diagram of a function call stack parsing structure of an application program according to an embodiment of the present application is shown;

[0069] Figure 8 The embodiment of the present application is shown Figure 7 Schematic diagram of location information of illegal memory access as an example;

[0070] Figure 9 A schematic block diagram of functional modules of a memory management device according to an exemplary embodiment of the present application is shown;

[0071] Figure 10 A schematic block diagram of functional modules of another memory management device according to an exemplary embodiment of the present application is shown;

[0072] Figure 11 shows a schematic block diagram of a chip according to an exemplary embodiment of the present application;

[0073] Figure 12 A structural block diagram of an exemplary computer device that can be used to implement the embodiments of the present application is shown. DETAILED DESCRIPTION

[0074] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only and are not intended to limit the scope of protection of the present application.

[0075] It should be understood that the various steps described in the method embodiments of the present application can be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present application is not limited in this respect.

[0076] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0077] It should be noted that the modifications of "one" and "multiple" mentioned in this application are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".

[0078] Before introducing the embodiments of the present application, the following definitions are given for the relevant terms involved in the embodiments of the present application:

[0079] Function instrumentation is a technology that inserts detection points or monitoring points into software code to track and analyze the status, behavior, and performance indicators of the program during execution.

[0080] The memory protection zone refers to the specific storage blocks reserved before and after the memory allocation function returns the memory space to the caller for use. These reserved specific storage blocks are called "protected zones".

[0081] Interrupt handling means that when the system detects a pre-defined event during program execution, the operating system or runtime environment will temporarily suspend the execution of the current task and call the corresponding interrupt service routine to handle the event.

[0082] Exception handling means that when an unrecoverable error or abnormal situation is detected during program execution, the system captures and handles these exceptions through predefined mechanisms to avoid program crashes or greater system damage.

[0083] The function call stack is a data structure used to manage function calls and returns during program execution. It stores information such as the function's local variables, parameters, and return addresses. Each time a function is called, a new stack frame is created on the stack. When the function returns, the stack frame is destroyed.

[0084] Stack parsing refers to the analysis of the program call stack to extract information such as function call links, parameter passing relationships, and return addresses for debugging, performance optimization, or security auditing.

[0085] The Stack Pointer Register is a special register that indicates the top position of the current stack.

[0086] The execution context is all the information carried by a piece of code when it is executed. For example, when executing a program, the execution context refers to the collection of information about the current state of the program, including the execution location of the program code, the values ​​of variables, the function call stack, and other information related to the program operation.

[0087] An embodiment of the present application provides a memory management method, which can be applied to computer devices. The computer system may include a smartphone, a personal computer, a tablet computer, a vehicle-mounted device, a smart home appliance, an artificial intelligence device, etc., or it may be a system device, such as a server, which is not limited by the embodiment of the present application.

[0088] Figure 1 Schematic diagram of an example computer device in which the various methods described herein may be implemented according to an exemplary embodiment of the present application. Figure 1 As shown, the computer device 100 includes a communication module 101 , a sensor 102 , a user input module 103 , an output module 104 , a processor 105 , an audio and video input module 106 , a memory 107 and a power supply 108 .

[0089] like Figure 1 As shown, the communication module 101 may include at least one module that enables the computer device 100 to communicate with other computer devices 100. For example, the communication module 101 may include one or more of a wired network interface, a broadcast receiving module, a mobile communication module, a wireless Internet module, a local area communication module, and a location (or positioning) information module. These various modules have various implementations in the prior art and are not described in detail in this application.

[0090] like Figure 1 As shown, the sensor 102 can sense the current state of the system, such as open / closed state, position, contact with the user, direction, and acceleration / deceleration, and the sensor 102 can generate a sensing signal for controlling the operation of the system.

[0091] like Figure 1 As shown, the user input module 103 is used to receive input digital information, character information or contact touch operation / contactless gesture, as well as receive signal input related to user settings and function control of the system. The user input module 103 includes a touch panel and / or other input devices.

[0092] like Figure 1As shown, the output module 104 includes a display panel for displaying information input by the user, information provided to the user, or various menu interfaces of the system. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD) or an organic light-emitting diode (OLED). In some other embodiments, a touch panel can be covered on the display panel to form a touch display screen. In addition, the output module 104 can also include an audio output module, an alarm, and a tactile module.

[0093] like Figure 1 As shown, the audio and video input module 106 is used to input audio signals or video signals. The audio and video input module 106 may include a camera and a microphone.

[0094] like Figure 1 As shown, the power supply 108 may receive external power and internal power under the control of the processor 105 and provide power required for the operation of various components of the system.

[0095] like Figure 1 As shown, the processor 105 may indicate one or more processors. For example, the processor 105 may include one or more central processing units, or include a central processing unit and a graphics processing unit, or include an application processor and a coprocessor (such as a microcontroller unit or a neural network processor). When the processor 105 includes multiple processors, these multiple processors may be integrated on the same chip or each may be an independent chip. A processor may include one or more physical cores, where a physical core is the smallest processing module.

[0096] like Figure 1As shown, the memory 107 stores computer programs, which include application programs 1071 and operating system programs 1072. The memory 107 can be one or more of the following types: flash memory, hard disk type memory, micro multimedia card type memory, card memory (such as SD or XD memory), random access memory (RAM), static random access memory (SRAM), read only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk or optical disk. In some other embodiments, the memory 107 can also be a network storage device on the Internet, and the system can perform operations such as updating or reading on the memory on the Internet. The memory 107 also stores other data besides computer programs, which is not limited in the embodiments of the present application.

[0097] like Figure 1 As shown, the processor 105 is used to read the computer program in the memory 107 and then execute the method defined by the computer program. For example, the processor 105 reads the operating system program to run the operating system and implement various functions of the operating system on the system, or reads one or more application programs to run applications on the system.

[0098] It is understandable that Figure 1 The connection relationship between the various modules is only an example. The method provided in any embodiment of the present application can also be applied to systems with other connection methods, such as all modules being connected through a bus. The embodiments of the present application are not limited to this.

[0099] The memory management method of the embodiment of the present application can be applied not only to computer devices in general operating system scenarios, but also to embedded systems in real-time operating system environments, especially embedded systems with high requirements for system stability and reliability. Typical embedded systems include the following.

[0100] The first type is embedded control systems: such as embedded devices in industrial automation, aerospace and other fields. These devices usually run in resource-constrained environments and their tasks have strict real-time requirements.

[0101] The second type is embedded communication systems: such as wireless sensor network nodes and Internet of Things (IoT) devices, which need to ensure system stability and reliability under limited computing and memory resources.

[0102] The third type is safety-critical systems: such as automotive electronic control units (ECUs) and medical equipment. These systems are particularly sensitive to illegal memory access issues, and any undetected errors may lead to serious consequences.

[0103] Figure 2 The flow chart of the memory management method of the embodiment of the present application is shown. The method of the embodiment of the present application is described below with reference to the accompanying drawings. Figure 2 As shown, the memory management method 200 of the embodiment of the present application may include steps 201 to 203.

[0104] In step 201, in response to an event that the execution of a target program fragment ends, memory protection zone information in a physical memory is obtained.

[0105] The target program fragment of the embodiment of the present application can be an interrupt service program or a target program fragment of an application program. In addition, the application program can include multiple program fragments, and the target program fragment can be any one of the multiple program fragments.

[0106] Optionally, each program fragment can be regarded as a function or a group of functions. When the target program fragment is executed, the memory protection zone information in the physical memory of the application program can be automatically obtained.

[0107] Alternatively, the memory space may be allocated to the application program using dynamic memory application or manual method. The memory protection zone of the physical memory may be a memory space in the physical memory that is prohibited from being accessed by each program fragment included in the application program.

[0108] In step 202, if an abnormality in the memory protection zone information is detected, the execution context information corresponding to the target program fragment is obtained;

[0109] The memory protection zone information of the embodiment of the present application can be considered as the target data stored in the memory protection zone in the physical memory. If it is detected that the content stored in the memory protection zone is the target data, it means that the target program fragment has not made any illegal memory access in the memory protection zone, and therefore the memory protection zone information is normal; if it is detected that the content stored in the memory protection zone includes non-target data, it means that the target program fragment has made an illegal memory access in the memory protection zone, and therefore the memory protection zone information is abnormal.

[0110] Optionally, the physical memory of an embodiment of the present application may include multiple memory blocks, each of which contains a protected area. Target data may be filled in the protected area. If the protected area data included in at least one of the multiple memory blocks is non-target data, it indicates that illegal access has occurred in the protected area including the non-target data, resulting in modification of the target data in the protected area. Therefore, the memory protected area information may be considered abnormal. If the protected area data included in multiple memory blocks are all non-target data, the memory protected area information may be considered normal. It can be seen that the target data in the protected area is used to indicate that the released memory block has been illegally accessed when it is modified to non-target data.

[0111] For example, the plurality of memory blocks may be memory blocks that are all requested through a memory request operation, and the memory blocks may further include a data area, with the protection zone being located at the end of the data area. For another example, the plurality of memory blocks may be memory blocks that are released through a memory release operation, and the memory blocks may include a protection zone. The protection zone may be a data zone that runs the memory blocks before the memory blocks are released.

[0112] The execution context information corresponding to the target program fragment in the embodiment of the present application includes not only the execution context information of the target program fragment and each historical program fragment before the target program fragment, but also the execution context information of the exception detection of the memory protection zone information.

[0113] Optionally, when the target program fragment is an interrupt service program, the interrupt scene, system call parameters and return value need to be saved in the system stack. Therefore, when an abnormality in the memory protection zone information is detected, the execution context information corresponding to the interrupt service program can be obtained from the system stack.

[0114] If an application is interrupted by an interrupt service routine, execution can resume after detecting that the memory protection zone information is normal. For example, the current task's register status, program counter, and other information can be saved on the stack, and then the interrupt service routine can be executed. When the interrupt service routine terminates, the current task's execution context can be restored from the task stack to resume execution of the application interrupted by the interrupt service routine.

[0115] It can be seen that the method in the embodiment of the present application can not only ensure that abnormal memory access does not occur during the execution of the interrupt service program, but also ensure the normal operation of the application interrupted by the interrupt service program.

[0116] Optionally, when the target program fragment is the target program fragment of an application, since the task stack can save task local variables, function call parameters and return addresses, and save independent scenes during each task switch, the execution context information corresponding to the target program fragment of the application can be obtained from the task stack.

[0117] If the memory protection zone information is detected to be normal, the next program segment following the target program segment in the application program can be executed. In this way, if no illegal memory access occurs, the application program continues to execute without interruption. The process then returns to step 201 to reacquire the memory protection zone information in the physical memory. This allows for periodic testing of the memory protection zone information in the physical memory, thereby quickly detecting illegal memory accesses.

[0118] It can be seen that the method in the embodiment of the present application can ensure that the application continues to be executed when the memory protection zone information is normal, so that the application can be executed normally without illegal access.

[0119] Optionally, the function call stack stores the execution context information corresponding to the target program fragment. After the execution of the target program fragment is completed, the execution context information of the target program fragment can be pushed into the function call stack by pushing. After detecting whether the memory protection zone information is abnormal, the execution context information of the abnormality detection of the memory protection zone information can be pushed into the function call stack by pushing, and then the function call stack is parsed to obtain the execution context information corresponding to the target program fragment.

[0120] Step 203: Based on the execution context information corresponding to the target program fragment, the location information of the illegal memory access is determined. Since the context information corresponding to the target program fragment includes not only the execution context information of the target program fragment and each historical program fragment before the target program fragment, but also includes the execution context information of the abnormality detection of the memory protection zone information, the method of the embodiment of the present application does not need to detect the running result of the target program fragment based on pattern matching and rule base, but instead performs abnormality detection on the memory protection zone information in the physical memory, and automatically determines the location information of the illegal memory access when the memory protection zone information is abnormal, providing a detailed basis for problem repair. Therefore, the method of the embodiment of the present application not only does not require developers to spend time debugging and troubleshooting the location of illegal memory access, but is also less likely to generate false positives or false negatives, and can cover complex memory operation scenarios.

[0121] Moreover, the embodiment of the present application can take the target program fragment execution end event as an opportunity, and when the memory protection zone information abnormality is detected, the memory management method can be automatically started, and there is no need to separately build a virtual machine and open up physical space to run the illegal memory access positioning program. Therefore, the method of the embodiment of the present application has a small performance overhead, and is not only applicable to general-purpose operating systems with low real-time requirements, but also applicable to real-time operating systems with relatively high real-time requirements, which can improve the stability and security of the real-time operating system. In addition, the method of the embodiment of the present application does not require hardware memory management unit (Memory Management Unit, MMU) support, can flexibly perform illegal memory access positioning, and has high flexibility and convenience.

[0122] In one possible implementation, the method of the embodiment of the present application can insert code into the program during the program compilation phase.

[0123] Optionally, when the target program fragment is the target program fragment of an application, for any program fragment included in the application, which can be a function defined in a high-level language or assembly language, memory protection zone exception detection logic can be added at the exit position of the target function to ensure that illegal memory access can be discovered in the first time, thereby avoiding the spread of the problem and the occurrence of system crashes.

[0124] In one example, for a target function defined in a high-level language, the compiler option -finstrument-functions can be added to instrument the target function. This adds two hook function calls within the target function. For example, the _cyg_profile_func_enter function can be called at the target function's entry point, and the __cyg_profile_func_exit function can be called at the function's exit point. The memory check function mem_check() is then called at the function's exit point. This allows the application to use mem_check() to check the memory protection zone information of the application's physical memory while the application is running.

[0125] Optionally, for target program segments defined in assembly language, a memory check function mem_check() can be added by manual instrumentation. For example, if the target program segment is an interrupt service routine, which is defined in assembly language, the memory check function mem_check() can be added by manual instrumentation.

[0126] For example, the interrupt service program includes the interrupt handling function OsHwiDispatchHandle. The memory detection function mem_check() can be added to the interrupt handling function OsHwiDispatchHandle to check the memory blocks one by one, so that when the interrupt service program ends but before the interrupt returns, the memory protection zone information of the physical memory can be checked using mem_check().

[0127] In one possible implementation, the physical memory of an embodiment of the present application may include multiple memory blocks, and any protection block may contain a protection zone. In this case, the memory protection zone in the physical memory may actually include the protection zones of each memory block. Accordingly, the memory protection zone information includes the protection zone data stored in each memory block.

[0128] Optionally, the protection zone can be a released memory space, or a separately separated portion of the memory space applied for by the target program fragment. For example, when the plurality of memory blocks include a first memory block, the first memory block includes not only the protection zone but also a data zone, and the protection zone is located at the end of the data zone. The number of the protection zones can be one or two.

[0129] The present application also provides a memory management method that can manage memory blocks, set protection zones for memory blocks, and detect whether illegal access occurs in the protection zones of the memory blocks. The following describes the memory management method from two perspectives: the memory application process and the memory release process.

[0130] Figure 3 FIG. 1 shows a flow chart of the memory management method in the memory application process according to an embodiment of the present application. Figure 3 As shown, the memory management method 300 of the embodiment of the present application includes the following steps during the memory application process:

[0131] Step 301: In response to a memory request operation, a memory block is requested in the physical memory for the target program fragment. The memory block includes a data area and a protection area. The protection area is located at the end of the data area.

[0132] When a memory request function (e.g., malloc, calloc, ralloc) is detected, the embodiment of the present application can not only request a preset size of memory space from the physical memory and use it as a data area for storing the running data of the target program fragment, but also add a protection area of ​​a specified length at one or both ends of the data area so that the data area and the protection area constitute a memory block.

[0133] Step 302: Target data is stored within the protected area. This target data is used to indicate unauthorized access to the protected area if it is modified to non-target data. The target data can be pre-set data. When the protected area is illegally accessed, the target data within the protected area is modified. The modified non-target data is not fixed and can be modified based on actual circumstances.

[0134] Figure 4 FIG. 1 shows a flow chart of the memory management method in the memory release process according to an embodiment of the present application. Figure 4 As shown, the memory management method 400 of the embodiment of the present application includes the following steps during the memory application process:

[0135] Step 401: In response to a memory release operation, a memory block in the physical memory where the target program fragment is running is released. In the embodiment of the present application, when a memory release function (eg, free, delete) is detected, the memory block cannot be accessed by the target program fragment.

[0136] Step 402: Target data is stored in the data area of ​​the memory block. The target data is used to indicate that the released memory block is illegally accessed when the target data is modified to non-target data.

[0137] In the method of an embodiment of the present application, when releasing the memory block running the target program fragment in the physical memory, the target data is stored in the data area of ​​the memory block, and the data area can be used as a protection area of ​​the released memory block. By detecting whether the target data in the data area is modified, it is confirmed whether abnormal access may occur in the data area of ​​the memory block.

[0138] In an embodiment of the present application, if the target data is modified to non-target data, it indicates that the data in the protected area is abnormal and may be illegally accessed. When the protected area is illegally accessed, the execution context information corresponding to the target program fragment is obtained, and then the location information of the illegal memory access is determined based on the execution context information corresponding to the target program fragment.

[0139] It can be seen that the method of the embodiment of the present application does not need to detect the running results of the target program fragment based on pattern matching and rule base, but instead performs anomaly detection on the data in the protected area of ​​the memory block, and automatically determines the location information of the illegal memory access when the data in the protected area is abnormal, providing a detailed basis for problem repair. Therefore, the method of the embodiment of the present application not only does not require developers to spend time debugging and troubleshooting the location of illegal memory access, but is also not prone to false alarms or missed alarms, and can cover complex memory operation scenarios.

[0140] Moreover, the embodiment of the present application can take the target program fragment execution end event as an opportunity, and when a data anomaly is detected in the protected area, the memory management method can be automatically started, and there is no need to separately build a virtual machine and open up physical space to run the illegal memory access positioning program. Therefore, the performance overhead of the method of the embodiment of the present application is relatively small, and it is not only applicable to general-purpose operating systems with low real-time requirements, but also to real-time operating systems with relatively high real-time requirements. In addition, the method of the embodiment of the present application does not require the support of a hardware memory management unit, and can flexibly locate illegal memory accesses, which has high flexibility and convenience.

[0141] For example, Figure 5 FIG. 1 shows a schematic diagram of a first memory block according to an embodiment of the present application. Figure 5 As shown, a memory block 500 is dynamically allocated in a 4GB physical space (address space bits 0x00000000 to 0xFFFFFFFF) using the malloc function. The memory block 500 may include a data area 501, a first protection area 502, and a second protection area 503. The first protection area 502 is located on one side of the data area 501, and the second protection area 503 is located on the other side of the data area 501. The address lengths of the first protection area 502 and the second protection area 503 are both 64 bytes.

[0142] Optionally, target data may be filled in the protected area to serve as protected area data to verify whether the protected area is illegally accessed.

[0143] If it is detected that the protected area data of at least one of the multiple memory blocks is non-target data, it means that after executing the target program fragment, illegal access occurs in at least one protected area. Therefore, the memory protected area information can be confirmed to be abnormal, and the location of the illegal memory access can be started.

[0144] If it is detected that the protected area data in each of the multiple memory blocks are all target data, it means that no illegal access occurs in the physical memory after executing the target program fragment. Therefore, after confirming that the memory protection area information is normal, the next program fragment after the target program fragment can be executed without starting to locate the illegal memory access, thereby reducing unnecessary waste of resources.

[0145] When the multiple memory blocks include the first memory block, obtaining memory protection zone information in the physical memory includes: obtaining protection zone location information of the first memory block, and obtaining protection zone data of the first memory block based on the protection zone location information of the first memory block.

[0146] For example, the physical address of the protection zone can be determined based on the physical address of the data zone and the address length of the data zone, and then the protection zone data of the first memory block can be obtained from the physical memory based on the physical address of the protection zone. Figure 5As shown, the physical address of the data area 501 can be the starting address of the data area 501. Based on the starting address of the data area 501, the ending address of the first protection area 502 can be determined. Based on the starting address of the data area 501 and the address length of the data area 501, the starting address of the second protection area 503 can be determined.

[0147] At the same time, if Figure 5 As shown, the address lengths of the first protection zone 502 and the second protection zone 503 are both known (e.g., 64 bytes). Therefore, after determining the end address and actual length of the first protection zone 502, the address range of the first protection zone 502 and the address range of the second protection zone 503 can be accurately determined. Based on this, the protected area data of the first protection zone 502 and the protected area data of the second protection zone 503 can be read using the address range of the first protection zone 502 and the address range of the second protection zone 503. As long as either the protected area data of the first protection zone 502 or the protected area data of the second protection zone 503 is not the target data, the memory protection zone information is confirmed to be abnormal.

[0148] When it is detected that the protected area data of the first memory block is non-target data, it can be confirmed that the memory protected area information is abnormal. At this time, on the one hand, the illegal memory access is located, and on the other hand, the data area location information of the first memory block can be output (for example, the data area address of the first memory block is printed). In this way, the data area position of the first memory block can be more accurate. When it is detected that the protected area data of the first memory block is target data, it means that the protected area of ​​the first memory block has not been illegally accessed, and based on the location information of the second memory block, the protected area location information of the second memory block is obtained, and the protected area location information of the first memory block is updated based on the protected area location information of the second memory block. In this way, the protected area location information of the second memory block can be used as the protected area location information of the first memory block.

[0149] For example, when using the malloc function to dynamically allocate memory for an application, a protection zone of a certain length (e.g., 64 bytes) can be reserved at both ends of the allocated data area. Of course, if the allocated data area is used to store data such as global variables, a protection zone of a certain length (e.g., 64 bytes) can also be manually reserved at both ends of the data area. At the same time, the protected zone can also be filled with target data such as 0x5A, and the address length and physical address (e.g., starting address) of the data area can be recorded.

[0150] When running an application, the memory detection function mem_check() can be used to detect whether the protected area data of the first memory block is 0x5A. If the protected area data of the first memory block is not 0x5A, it means that the 0x5A stored in the protected area of ​​the first memory block has been modified due to illegal memory access. Therefore, the illegal memory access can be located. If the protected area data of the first memory block is 0x5A, the data area location information of the second memory block can be obtained based on the location information of the second memory block, and then the protected area location information of the second memory block can be obtained based on the location information of the second memory block. The protected area location information of the second memory block is used as the protected area location information of the first memory block, thereby achieving the purpose of updating the protected area data of the first memory block. In this way, the protected area data of the first memory block obtained using the updated protected area location information of the first memory block is actually the protected area data of the second memory block.

[0151] Optionally, it is considered that there may be multiple memory blocks in the physical memory. And the multiple memory blocks are all memory blocks applied for through a memory application operation or memory blocks released through a memory release operation. In order to improve the efficiency of data detection in the protected area of ​​each memory block, the protected area positioning information of each memory block can be obtained. The memory block information includes the physical address of the data area and the address length of the data area, and based on the memory block information of the multiple memory blocks, a memory block linked list is determined. It can be seen that the embodiment of the present application constructs each memory block into a memory block linked list, and then uses the memory detection function mem_check() to traverse and detect the memory block linked list, thereby quickly accessing the data in the protected areas of different memory blocks and efficiently realizing data detection in the protected areas of different memory blocks.

[0152] In one example, a memory block linked list constructed by multiple memory blocks applied for through a memory application operation can be defined as a working memory block linked list, and a memory block linked list constructed by memory blocks released through a memory release operation can be defined as a free memory block linked list.

[0153] In one example, for a memory block linked list, the memory block information stored in a memory block node of the memory block linked list includes an information structure of the memory block node. The information structure may include a pointer to the next memory block node, a starting address of the data area of ​​the current memory block, and an address length of the data area of ​​the current memory block. Examples are provided below with reference to the accompanying figures.

[0154] Figure 6 The schematic diagram of the memory block linked list structure is shown in FIG. Figure 6 As shown, the memory block linked list 600 includes a linked list head Head, a first memory block node 601, a second memory block node 602 and a third memory block node 603.

[0155] like Figure 6 As shown, the protection zone address of the first memory block can be determined by the data zone starting address and data zone address length of the first memory block saved in the first memory block node 601, and then the protection zone data of the first memory block can be obtained using the protection zone address of the first memory block. Then, the protection zone data of the first memory block can be detected using the memory detection function mem_check() to determine whether the protection zone data of the first memory block is non-target data or target data.

[0156] like Figure 6 As shown, if the memory detection function mem_check() detects that the protected area data of the first memory block is non-target data, an exception is triggered and the illegal memory access is located. If the memory detection function mem_check() detects that the protected area data of the first memory block is target data, the pointer of the second memory block node 602 stored in the first memory block node 601 can be used to obtain the data area starting address and data area address length of the second memory block from the second memory block node 602.

[0157] After obtaining the starting address of the data area and the length of the data area address of the second memory block, you can refer to the method of obtaining the protected area data of the first memory block, use the starting address of the data area and the length of the data area address of the second memory block to obtain the protected area data of the second memory block, and then use the memory detection function mem_check() to detect the protected area data of the second memory block to determine whether the protected area data of the second memory block is non-target data or target data.

[0158] like Figure 6 As shown, if the memory detection function mem_check() detects that the protected area data of the second memory block is non-target data, an exception is triggered and the illegal memory access is located. If the memory detection function mem_check() detects that the protected area data of the second memory block is target data, the pointer to the third memory block node 603 stored in the second memory block node 602 can be used to obtain the data area starting address and data area address length of the third memory block from the third memory block node 603.

[0159] After obtaining the starting address of the data area and the length of the data area address of the third memory block, you can refer to the method of obtaining the protected area data of the first memory block, and use the starting address of the data area and the length of the data area address of the third memory block to obtain the protected area data of the third memory block. Then use the memory detection function mem_check() to detect the protected area data of the third memory block to determine whether the protected area data of the third memory block is non-target data or target data.

[0160] like Figure 6As shown, if the memory check function mem_check() detects that the protected area data of the third memory block is non-target data, an exception is triggered and the illegal memory access is located. If the memory check function mem_check() detects that the protected area data of the third memory block is target data, it is confirmed that the memory protected area information in the physical memory is normal. The next function after the target function in the application program can be directly executed. Then, according to the relevant description above, after executing the next function after the target function, the memory check function mem_check() is used to recheck the memory block linked list 600.

[0161] It can be seen that by inserting functions at the end of each function and the end of interrupt processing, the memory detection function mem_check() can be called through the __cyg_profile_func_exit function to perform abnormal detection on the memory block list, so that the location information of the illegal memory access can be quickly and accurately located.

[0162] In one possible implementation, the location information of the illegal memory access is determined based on the execution context information corresponding to the target program fragment, including: determining the function call chain and register information of the target program fragment based on the execution context information corresponding to the target program fragment, and then determining the location information of the illegal memory access based on the function call chain and register information of the target program fragment.

[0163] Optionally, when the memory detection function mem_check() detects that the data in the protected area of ​​the memory block is non-target data, an exception is triggered, and then the current execution context of the application is pushed into the function call stack. At this time, the execution context corresponding to the target program fragment stored in the function call stack is the latest execution context. In addition, since the execution context information corresponding to the target program fragment covers the environment and state information of the execution of different program fragments, the function call stack can be parsed to obtain the function call chain and register information of the target program fragment (such as the top pointer of the call stack) from the execution context information corresponding to the target program fragment.

[0164] Figure 7 FIG. 1 shows a schematic diagram of a function call stack parsing structure of a target program fragment according to an embodiment of the present application. Figure 7 As shown, the function call information of the target program fragment may include a function call chain and register information. Figure 8 The embodiment of the present application is shown Figure 7 Schematic diagram of the location information of illegal memory access as an example. Figure 8 As shown, according to Figure 7 The function call information of the displayed target program fragment can be located at the TestTaskEntry function +416 position where the exception was triggered.

[0165] It can be seen that the embodiment of the present application performs function stubbing after the program fragment, so that at the end of the execution of each program fragment, the memory protection information is detected to see if it is abnormal. If the memory protection information is abnormal, the execution context information corresponding to the target program fragment is obtained to determine the location information of the illegal memory access. This illegal memory access location method has a relatively low performance overhead and can simultaneously achieve accurate tracking and location of illegal memory access in general-purpose operating systems and real-time operating systems, significantly reducing the risk of system crashes caused by memory overflow or out-of-bounds access, while reducing the time cost of developers in troubleshooting memory problems and significantly improving the efficiency of problem troubleshooting.

[0166] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of computer equipment. It is understandable that, in order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the units and algorithm steps of each example described in the embodiment applied for herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in a manner of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0167] The embodiment of the present application can divide the computer device into functional units according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. In actual implementation, there may be other division methods.

[0168] In the case of dividing each functional module according to each function, an exemplary embodiment of the present application provides a device for locating illegal memory access, which may be a computer device or a chip applied to a computer device. Figure 9 FIG1 shows a schematic block diagram of the functional modules of a memory management device according to an exemplary embodiment of the present application. Figure 9 As shown, the memory management device 900 includes:

[0169] An acquisition module 901 is configured to acquire memory protection zone information in a physical memory in response to an execution end event of a target program fragment;

[0170] The processing module 902 is configured to obtain execution context information corresponding to the target program fragment if an abnormality in the memory protection zone information is detected; and determine location information of the illegal memory access based on the execution context information corresponding to the target program fragment.

[0171] In a possible implementation, the physical memory includes multiple memory blocks, each of which contains a protection zone.

[0172] The processing module 902 is also used to confirm that the memory protection zone information is abnormal if it is detected that the protection zone data of at least one of the multiple memory blocks is non-target data; if it is detected that the protection zone data of each of the multiple memory blocks is target data, confirm that the memory protection zone information is normal.

[0173] In a possible implementation, the multiple memory blocks include a first memory block, and the acquisition module 901 is configured to acquire protection zone location information of the first memory block, and acquire protection zone data of the first memory block based on the protection zone location information of the first memory block.

[0174] In a possible implementation, the memory block further includes a data area, the protection area is located at an end of the data area, and the protection area location information of the first memory block includes: a physical address of the data area and an address length of the data area;

[0175] The acquisition module 901 is configured to determine the physical address of the protection zone based on the physical address of the data zone and the address length of the data zone; and acquire the protection zone data of the first memory block from the physical memory based on the physical address of the protection zone.

[0176] In one possible implementation, the multiple memory blocks also include a second memory block, and the acquisition module 901 is further used to obtain the protection zone positioning information of the second memory block based on the positioning information of the second memory block if it is detected that the protection zone data of the first memory block is the target data, and update the protection zone positioning information of the first memory block based on the protection zone positioning information of the second memory block.

[0177] In one possible implementation, the memory block also includes a data area, and the protection area is located at the end of the data area. The device 900 also includes an output module 903, which is used to output the data area positioning information of the first memory block if it is detected that the protection area data of the first memory block is non-target data.

[0178] In one possible implementation, the processing module 902 is also used to determine the function call chain and register information of the target program fragment based on the execution context information corresponding to the target program fragment, and then determine the location information of the illegal memory access based on the function call chain and register information of the target program fragment.

[0179] In a possible implementation, the acquisition module 901 is configured to acquire execution context information corresponding to the interrupt service routine from a system stack when the target program fragment is an interrupt service routine; or

[0180] When the target program fragment is a target program fragment of an application program, execution context information corresponding to the target program fragment of the application program is obtained from the task stack.

[0181] In a possible implementation, the processing module 902 is further configured to, when the target program segment is an interrupt service routine, continue executing the application program interrupted by the interrupt service routine if it is detected that the memory protection zone information is normal; or

[0182] When the target program fragment is a target program fragment in the application program, if it is detected that the memory protection zone information is normal, the next program fragment after the target program fragment in the application program is executed.

[0183] In the case of dividing each functional module according to each function, the exemplary embodiment of the present application provides another memory management method, which can be used for a computer device or a chip applied to a computer device. Figure 10 FIG. 1 shows a schematic block diagram of functional modules of another memory management device according to an exemplary embodiment of the present application. Figure 10 As shown, the memory management device 1000 includes:

[0184] The management module 1001 is configured to apply for a memory block in the physical memory for the target program fragment in response to a memory application operation, wherein the memory block includes a data area and a protection area, and the protection area is located at the end of the data area;

[0185] The storage module 1002 is used to store target data in the protection zone. When the target data is modified into non-target data, it is used to indicate that the protection zone is illegally accessed. The data zone is used to store the running data of the target program fragment.

[0186] In a possible implementation, the management module 1001 is further configured to release a memory block in the physical memory that runs the target program fragment in response to a memory release operation;

[0187] The storage module 1002 is further configured to store target data in the data area of ​​the memory block. The target data is used to indicate that the released memory block is illegally accessed when the target data is modified to non-target data.

[0188] Figure 11 FIG. 1 shows a schematic block diagram of a chip according to an exemplary embodiment of the present application. Figure 11As shown, the chip 1100 includes one or more (including two) processors 1101 and a communication interface 1102. The communication interface 1102 can support the computer device to perform the data sending and receiving steps in the above method, and the processor 1101 can support the computer device to perform the data processing steps in the above method.

[0189] Optional, such as Figure 11 As shown, the chip 1100 also includes a memory 1103. The memory 1103 may include a read-only memory and a random access memory, and provides operation instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory (NVRAM).

[0190] In some embodiments, as Figure 11 As shown, the processor 1101 performs corresponding operations by calling the operation instructions stored in the memory (the operation instructions may be stored in the operating system). The processor 1101 controls the processing operations of any one of the terminal devices, and the processor may also be called a central processing unit (CPU). The memory 1103 may include a read-only memory and a random access memory, and provides instructions and data to the processor 1101. A portion of the memory 1103 may also include NVRAM. For example, in an application, the memory, the communication interface, and the memory are coupled together through a bus system, wherein the bus system may include a power bus, a control bus, and a status signal bus in addition to a data bus. However, for the sake of clarity, in Figure 11 Various buses are labeled as bus system 1104.

[0191] The methods disclosed in the above embodiments of the present application can be applied to or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor or by software instructions. The above processor may be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA), or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The various methods, steps, and logic block diagrams in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods applied in conjunction with the embodiments of the present application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in a memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.

[0192] The exemplary embodiments of the present application further provide a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, wherein the computer program, when executed by the at least one processor, causes the computer device to perform a method according to an embodiment of the present application.

[0193] An exemplary embodiment of the present application further provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present application.

[0194] An exemplary embodiment of the present application further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor of a computer, it is used to cause the computer to perform the method according to the embodiment of the present application.

[0195] refer to Figure 12, a block diagram of a computer device 1200 that can be used as a server or client of the present application will now be described, which is an example of a hardware device that can be applied to various aspects of the present application. The computer device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The computer device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.

[0196] like Figure 12 As shown, computer device 1200 includes a computing unit 1201, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1202 or a computer program loaded from a storage unit 1208 into a random access memory (RAM) 1203. Various programs and data required for the operation of device 1200 can also be stored in RAM 1203. Computing unit 1201, ROM 1202, and RAM 1203 are connected to each other via a bus 1204. An input / output (I / O) interface 1205 is also connected to bus 1204.

[0197] like Figure 12 As shown, multiple components within computer device 1200 are connected to I / O interface 1205, including an input unit 1206, an output unit 1207, a storage unit 1208, and a communication unit 1209. Input unit 1206 can be any type of device capable of inputting information into computer device 1200. Input unit 1206 can receive input numeric or character information and generate key input signals related to user settings and / or function control of the computer device. Output unit 1207 can be any type of device capable of presenting information and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. Storage unit 1208 may include, but is not limited to, a magnetic disk or an optical disk. Communication unit 1209 allows computer device 1200 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver and / or chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0198] like Figure 12As shown, the computing unit 1201 can be various general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1201 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1201 performs the various methods and processes described above. For example, in some embodiments, the method of the embodiment of the present application can be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 1208. In some embodiments, part or all of the computer program can be loaded and / or installed on the computer device 1200 via the ROM 1202 and / or the communication unit 1209. In some embodiments, the computing unit 1201 can be configured to perform the method of the embodiment of the present application by any other appropriate means (e.g., by means of firmware).

[0199] The program code for implementing the methods of the present application can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow charts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0200] In the context of the present application, a machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can 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.

[0201] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0202] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.

[0203] Computer systems may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The client and server relationship arises through computer programs running on the respective computers and having a client-server relationship to each other.

[0204] In the above embodiments, they can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, they can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is performed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a terminal, a user device or other programmable device. The computer program or instruction can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program or instruction can be transmitted from one website, computer, server or data center to another website, computer, server or data center via wired or wireless means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, a hard disk, or a tape; it can also be an optical medium, such as a digital video disc (DVD); it can also be a semiconductor medium, such as a solid state drive (SSD).

[0205] Although the present application has been described with reference to specific features and embodiments thereof, it is apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely illustrative of the present application as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, the present application is intended to include such modifications and variations as fall within the scope of the claims of the present application and their equivalents.

Claims

1. A memory management method, characterized in that: include: In response to an execution end event of the target program segment, obtaining memory protection zone information in the physical memory; If an abnormality is detected in the memory protection zone information, acquiring execution context information corresponding to the target program fragment; Based on the execution context information corresponding to the target program fragment, location information of the illegal memory access is determined.

2. The method according to claim 1, characterized in that The physical memory includes a plurality of memory blocks, each of which contains a protection zone. The method further includes: If it is detected that the protected area data of at least one of the plurality of memory blocks is non-target data, confirming that the memory protected area information is abnormal; If it is detected that the protected area data of each of the plurality of memory blocks is target data, it is confirmed that the memory protected area information is normal.

3. The method according to claim 2, characterized in that The multiple memory blocks include a first memory block, and obtaining memory protection zone information in a physical memory corresponding to the target program fragment includes: Obtaining location information of the protection zone of the first memory block; The protection zone data of the first memory block is acquired based on the protection zone location information of the first memory block.

4. The method according to claim 3, characterized in that The memory block further includes a data area, the protection zone is located at an end of the data area, the protection zone location information of the first memory block includes: a physical address of the data area and an address length of the data area, and obtaining the protection zone data of the first memory block based on the protection zone location information of the first memory block includes: determining a physical address of the protection area based on the physical address of the data area and the address length of the data area; The protection zone data of the first memory block is obtained from the physical memory based on the physical address of the protection zone.

5. The method according to claim 3, characterized in that The plurality of memory blocks further include a second memory block, and the method further includes: If it is detected that the protected area data of the first memory block is target data, obtaining the protected area positioning information of the second memory block based on the positioning information of the second memory block; The protection zone location information of the first memory block is updated based on the protection zone location information of the second memory block.

6. The method according to claim 3, characterized in that The memory block further includes a data area, the protection area is located at an end of the data area, and the method further includes: If it is detected that the protected area data of the first memory block is non-target data, data area location information of the first memory block is output.

7. The method according to claim 1, characterized in that The determining, based on the execution context information corresponding to the target program fragment, the location information of the illegal memory access includes: Determining a function call chain and register information of the target program fragment based on the execution context information corresponding to the target program fragment; Based on the function call chain and register information of the target program fragment, the location information of the illegal memory access is determined.

8. The method according to any one of claims 1 to 7, characterized in that The acquiring of execution context information corresponding to the target program fragment includes: When the target program fragment is an interrupt service routine, acquiring execution context information corresponding to the interrupt service routine from a system stack; or When the target program fragment is a target program fragment of an application, execution context information corresponding to the target program fragment of the application is acquired from a task stack.

9. The method according to claim 8, characterized in that The method further comprises: When the target program segment is an interrupt service routine, if it is detected that the memory protection zone information is normal, the application program interrupted by the interrupt service routine is continued to be executed; or, When the target program fragment is a target program fragment in an application program, if it is detected that the memory protection zone information is normal, the next program fragment in the application program that follows the target program fragment is executed.

10. A memory management method, characterized in that: include: In response to the memory request operation, requesting a memory block in the physical memory for the target program fragment, the memory block including a data area and a protection area, the protection area being located at an end of the data area; Target data is stored in the protection zone. When the target data is modified into non-target data, it is used to indicate that the protection zone is illegally accessed. The data zone is used to store the running data of the target program fragment.

11. The method according to claim 10, characterized in that The method further comprises: In response to a memory release operation, releasing the memory block in the physical memory in which the target program fragment is running; The target data is stored in the data area of ​​the memory block, and the target data is used to indicate that the released memory block is illegally accessed when the target data is modified to the non-target data.

12. A computer device, characterized in that: include: processor; as well as, Memory for storing programs; The program includes instructions, which, when executed by a processor, cause the processor to perform the method according to any one of claims 1 to 9.

13. A computer device, characterized in that: include: processor; as well as, Memory for storing programs; The program includes instructions, which, when executed by a processor, cause the processor to perform the method according to claim 10 or 11.

Citation Information

Patent Citations

  • Method and system for internal memory monitoring management

    CN101110044A

  • Memory access abnormity monitoring method based on compact memory pool

    CN115080343A

  • Satellite-borne operating system-oriented RISCV processor abnormal context protection and recovery method

    CN119336452A

  • Memory cross-border positioning method and device and storage medium

    CN119718735A

  • Memory management method, device, equipment, storage medium and computer program product

    CN119759801A