A memory management system, cross-boundary detection method and storage medium

Through the memory management system and the out-of-bounds detection method, the characteristic information of the memory block is monitored in real time, and the application information of the call point is recorded using the red and black tree, which solves the problem of untimely memory out-of-bounds detection in the existing technology, realizes timely detection and positioning during the operation of the application, and improves detection efficiency and accuracy.

CN115509741BActive Publication Date: 2025-08-19CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202211083836.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-06
Publication Date
2025-08-19
Estimated Expiration
2042-09-06

AI Technical Summary

Technical Problem

In the prior art, memory out-of-bounds detection is not timely, and cross-bounds problems cannot be discovered and located in a timely manner during the operation of the application, which affects the stability and security of the application.

Method used

The memory management system and the out-of-bounds detection method are adopted to monitor the feature information of the memory block in real time through the combination of the memory operation interface, the memory pool and the red and black tree, and locate the call points with the risk of out-of-bounds risk, including the detection of the front and back feature parts of the memory block. The red and black tree is used to record the application information and number of applications of the call points to realize the out-of-bounds detection.

Benefits of technology

During the application operation, the memory cross-border detection is detected in a timely manner and the cross-border call point is automatically positioned, which improves the efficiency and accuracy of cross-border detection and does not affect the normal operation of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509741B_ABST
    Figure CN115509741B_ABST
Patent Text Reader

Abstract

The present application relates to a memory management system, an out-of-bounds detection method and a storage medium. The memory management system includes a memory operation interface, a memory pool and a red-black tree, and the out-of-bounds detection method includes: monitoring the first characteristic information of each memory block in the allocated memory linked list in the memory pool; searching for the damaged first characteristic information and the target memory block to which the damaged first characteristic information belongs; and determining the target call point with an out-of-bounds risk based on the position of the damaged first characteristic information in the target memory block. By adopting the memory management system and out-of-bounds detection method provided by the present application, the problem of untimely out-of-bounds detection in the prior art can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory detection technology, and in particular to a memory management system, a cross-boundary detection method, and a storage medium. Background Art

[0002] Memory, also known as internal storage, temporarily stores data used by the processor and data exchanged with external storage devices like hard drives. When an application starts running, the processor allocates some memory to the application to meet its data processing needs. Therefore, the health of the memory determines the stability of the application's operation.

[0003] However, during embedded software development, memory anomalies, such as memory out-of-bounds errors, are unavoidable. These issues are a common problem for software developers, and they are difficult to detect. Currently, memory health monitoring tools are available for testing memory. However, these tools require the application to be running in their context and must exit before they can detect memory anomalies.

[0004] It can be seen that, since the prior art can detect whether there is a memory out-of-bounds problem only after the application program exits, the prior art has the problem of delayed out-of-bounds detection. Summary of the Invention

[0005] Based on this, the present application provides a memory management system, an out-of-bounds detection method and a storage medium to improve the problem of untimely out-of-bounds detection in the prior art.

[0006] In the first aspect, the present application provides a memory management system, which includes: a memory operation interface for receiving memory operation instructions of a call point, wherein the memory operation interface includes a memory allocation interface and a memory release interface, and the memory operation instructions include memory allocation instructions and memory release instructions; a memory pool for allocating memory blocks to the call point, wherein the memory pool includes at least one memory block, each memory block includes first characteristic information, and the first characteristic information includes a front characteristic part located at the head of the memory block and / or a rear characteristic part located at the tail of the memory block; a red-black tree for recording second characteristic information of the call point, and the second characteristic information is used to indicate the application status of the call point.

[0007] In the second aspect, the present application provides an out-of-bounds detection method, which includes: monitoring the first characteristic information of each memory block in the allocated memory linked list in the memory pool; searching for the damaged first characteristic information and the target memory block to which the damaged first characteristic information belongs; and determining the target call point with an out-of-bounds risk based on the position of the damaged first characteristic information in the target memory block.

[0008] In combination with the second aspect, in a first feasible implementation of the second aspect, the step of determining a target call point with a risk of out-of-bounds according to the position of the destroyed first characteristic information in the target memory block includes: when the front characteristic part of the target memory block is destroyed, performing a forward search on the memory blocks whose physical addresses are smaller than the target memory block in sequence until a memory block whose front characteristic part is intact and whose rear characteristic part is destroyed is found, and taking the call point corresponding to the memory block whose front characteristic part is intact and whose rear characteristic part is destroyed as the target call point; when the front characteristic part of the target memory block is intact and whose rear characteristic part is destroyed, taking the call point corresponding to the target memory block as the target call point.

[0009] In combination with the second aspect, in a second possible implementation of the second aspect, after the step of determining the target call point with an out-of-bounds risk, it also includes: searching for second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application count, the application information includes the code file name, code line number and / or task identifier of the call point, and the application count is the number of memory blocks occupied by the call point; printing out the application information of the target call point to indicate that the target call point has an out-of-bounds risk.

[0010] In combination with the second aspect, in a third possible implementation of the second aspect, when a memory allocation instruction of a call point is received, the method also includes: allocating an unallocated target memory block in a memory pool to the call point, and hanging the target memory block into an allocated memory linked list; searching for the second characteristic information of the call point in a red-black tree, and if the search fails, recording the second characteristic information of the call point in the red-black tree; modifying the first characteristic information in the target memory block, and associating the first characteristic information with the second characteristic information of the call point in the red-black tree.

[0011] In combination with the third possible implementation method of the second aspect, in the fourth possible implementation method of the second aspect, when a memory allocation instruction is received at a call point, the method further includes: reading first characteristic information of the target memory block; and when the first characteristic information of the target memory block is destroyed, determining that there is a risk of memory out-of-bounds.

[0012] In combination with the second aspect, in the fifth possible implementation of the second aspect, when a memory release instruction of the call point is received, the method also includes: searching for the second characteristic information of the call point in the red-black tree; modifying the second characteristic information of the call point in the red-black tree; modifying the first characteristic information in the memory block corresponding to the call point, and hanging the memory block corresponding to the call point to the unallocated memory linked list in the memory pool.

[0013] On the third aspect, the present application provides a memory management system, which includes: a monitoring unit for monitoring the first characteristic information of each memory block in the allocated memory linked list in the memory pool; a positioning unit for finding the damaged first characteristic information and the target memory block to which the damaged first characteristic information belongs; a determination unit for determining the target call point with an out-of-bounds risk based on the position of the damaged first characteristic information in the target memory block.

[0014] In combination with the third aspect, in a first feasible implementation method of the third aspect, the determination unit is specifically used to: in a case where the front characteristic part of the target memory block is destroyed, forward search the memory blocks whose physical addresses are smaller than the target memory block in turn until a memory block whose front characteristic part is complete and whose rear characteristic part is destroyed is found, and the call point corresponding to the memory block whose front characteristic part is complete and whose rear characteristic part is destroyed is used as the target call point; in a case where the front characteristic part of the target memory block is complete and whose rear characteristic part is destroyed, the call point corresponding to the target memory block is used as the target call point.

[0015] In combination with the third aspect, in a second possible implementation of the third aspect, the memory management system also includes a prompt unit, which is used to: search for second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application times, the application information includes the code file name, code line number and / or task identifier of the call point, and the application times is the number of memory blocks occupied by the call point; print out the application information of the target call point to prompt that there is a risk of out-of-bounds at the target call point.

[0016] In combination with the third aspect, in a third possible implementation of the third aspect, the memory management system also includes an allocation unit, which is used to: allocate an unallocated target memory block in the memory pool to the call point, and hang the target memory block into an allocated memory linked list; search for the second characteristic information of the call point in the red-black tree, and if the search fails, record the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the target memory block, and associate the first characteristic information with the second characteristic information of the call point in the red-black tree.

[0017] In combination with the third possible implementation method of the third aspect, in the fourth possible implementation method of the third aspect, the determination unit is also used to: read the first characteristic information of the target memory block; and when the first characteristic information of the target memory block is destroyed, determine that there is a risk of memory out-of-bounds.

[0018] In combination with the third aspect, in a fifth possible implementation of the third aspect, the memory management system also includes a release unit, which is used to: search for the second characteristic information of the call point in the red-black tree; modify the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the memory block corresponding to the call point, and hang the memory block corresponding to the call point to the unallocated memory linked list in the memory pool.

[0019] In a fourth aspect, the present application also provides a memory management system, which includes a processor and a memory, and the processor and the memory are connected via a bus; the processor is used to execute multiple instructions; the memory is used to store multiple instructions, and the instructions are suitable for being loaded and executed by the processor such as the out-of-bounds detection method of the first aspect or any one of the embodiments of the first aspect.

[0020] In a fifth aspect, the present application also provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are suitable for being loaded and executed by a processor such as the out-of-bounds detection method of the first aspect or any one of the embodiments of the first aspect.

[0021] In summary, the present application provides a memory management system, an out-of-bounds detection method, and a storage medium, wherein the out-of-bounds detection method is applied to the memory management system. The memory management system of the present application monitors the first characteristic information of each memory block in the allocated memory linked list to realize out-of-bounds detection of memory during the operation of the application. During this process, there is no need to exit the application, and the operation of the application will not be affected, so the functional implementation of the application will not be affected. In general, the memory management system and out-of-bounds detection method provided by the present application can improve the problem of untimely out-of-bounds detection in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 is a schematic block diagram of a memory management system in one embodiment;

[0023] Figure 2 1 is a flow chart of a method for detecting a boundary crossing in one embodiment;

[0024] Figure 3 A schematic block diagram of a memory management system provided by this application;

[0025] Figure 4 This is a structural block diagram of a memory management system provided by this application. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0027] Since the embodiments of the present application involve relatively many professional terms, in order to facilitate understanding, the relevant terms and concepts that may be involved in the embodiments of the present application are first introduced below.

[0028] 1. Memory out of bounds

[0029] A memory out-of-bounds error, also known as a memory access out-of-bounds error, refers to accessing memory outside of the requested space. Reading out-of-bounds memory produces random and unpredictable results; writing out-of-bounds memory may corrupt other data. Memory out-of-bounds errors are difficult to detect because they are not syntax errors and cannot be detected by the compiler. Furthermore, memory out-of-bounds errors cannot be fundamentally avoided, only prevented.

[0030] 2. Memory allocation instructions

[0031] Memory allocation instructions, such as the malloc instruction, are used to request memory space for an application's call point. malloc stands for memory allocation, also known as dynamic memory allocation in Chinese. It allocates a contiguous memory block of a specified size and returns the address of the allocated memory block as a void* type.

[0032] 3. Memory release instructions

[0033] Memory release instructions, such as the free instruction, are used to free memory space for an application's call point. The free instruction is used to release a contiguous block of memory of a specified size obtained using malloc.

[0034] 4. Red Black Tree

[0035] A red-black tree is a self-balancing binary search tree with high read performance and higher efficiency in inserting or deleting nodes. In this application, a red-black tree is used to store application information and application times of application call points to improve data search and storage efficiency.

[0036] It should be noted that the processors referred to in this application may include, but are not limited to, a central processing unit (CPU), a general-purpose processor, a coprocessor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The processor can implement the methods described in this application, such as responding to memory operation instructions at the call point of the application, and this application will not elaborate on this.

[0037] It should also be noted that the diagrams provided in this embodiment are only for schematically illustrating the basic concept of the present invention. Therefore, the diagrams only show the components related to the present invention and are not drawn according to the number, shape and size of the components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complex. The structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no technical significance. Any structural modification, change in proportional relationship or adjustment of size should still fall within the scope of the technical content disclosed in the present invention without affecting the efficacy and purpose of the present invention. At the same time, the directions or positional relationships indicated by terms such as "upper," "lower," "left," "right," "center," "longitudinal," "lateral," "horizontal," "inner," "outer," "radial," and "circumferential" in this specification are based on the directions or positional relationships shown in the accompanying drawings and are intended only to simplify the description. They do not indicate or imply that the devices or components referred to must have a specific direction, be constructed, or operate in a specific direction. Changes or adjustments to their relative relationships, without substantially changing the technical content, should be considered within the scope of the present invention. Therefore, they should not be construed as limiting the present invention. In addition, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0038] Currently, the existing technology can only detect whether the memory has crossed the boundary after the application is exited. It is impossible to realize timely detection of memory during the program running without affecting the normal operation of the application. Therefore, the existing technology still has the problem of delayed cross-bounds detection.

[0039] To this end, the present application provides a memory management system and a cross-border detection method, which can improve the problem of delayed cross-border detection in the prior art. Among them, the cross-border detection method is applied to a memory management system, which includes a memory operation interface, a memory pool, and a red-black tree. Specifically:

[0040] like Figure 1 As shown, the memory management system includes a memory operation interface, a memory pool, and a red-black tree. Specifically, the memory operation interface 110 is used to receive memory operation instructions from the call point. The memory operation interface includes a memory allocation interface and a memory release interface. The memory operation instructions include memory allocation instructions and memory release instructions. The memory pool 120 is used to allocate memory blocks to the call point. The memory pool includes at least one memory block. Each memory block includes first feature information. The first feature information includes a front feature portion located at the head of the memory block and / or a back feature portion located at the tail of the memory block (each portion is 16 bytes). The first feature information includes a feature code, usage information, and index information. The feature code includes the starting point and end point of the memory block. The usage information includes the memory size, whether it has been allocated, whether it has been released, and release point information. The index information is used to find the corresponding second feature information in the red-black tree. The red-black tree 130 is used to record the second feature information of the call point. The second feature information is used to indicate the application status of the call point. The second feature information includes application information and application count. The application information includes the code file name, code line number, and / or task identifier of the call point. The application count is the number of memory blocks occupied by the call point. It's important to note that when a memory block is unallocated, some fields in its signature information are empty. Specific values, such as the call point index and task ID, are added only after the memory block is allocated. Accordingly, some fields in the memory block's signature information, such as the signature code, are always active.

[0041] The out-of-bounds detection method of the present application is implemented during the operation of the application, and can improve the problem of untimely out-of-bounds detection in the prior art. Specifically, when the memory management system implements the out-of-bounds detection method, it first monitors the first information of each memory block in the allocated memory linked list to monitor the target memory block where the first characteristic information is destroyed, and then by determining the position of the destroyed first characteristic information in the target memory block, the memory block at risk of out-of-bounds can be determined, thereby determining the corresponding target memory block at risk of out-of-bounds. It can be seen that the present application realizes timely out-of-bounds detection of memory during the operation of the application. During this process, there is no need to exit the application, and it will not affect the operation of the application, so it will not affect the functional implementation of the application. In addition, the out-of-bounds detection method provided by the present application can also automatically locate the out-of-bounds call point.

[0042] It should be noted that in addition to out-of-bounds detection, the memory management system can also implement functions such as memory pool initialization, red-black tree creation, and response to memory operation instructions. Next, this application will explain some of the functions that the memory management system can implement, specifically:

[0043] When the application starts running, the memory management system first initializes the memory. That is, the memory management system creates a memory pool including multiple memory blocks based on the usage characteristics of the application, and the memory blocks with the same memory size in the multiple memory blocks are stored in the same linked list, the unallocated memory linked list. The memory blocks in the same unallocated memory linked list have the same size, which makes it possible to quickly obtain free memory blocks from the corresponding unallocated memory linked list according to the memory size required by the call point when allocating memory blocks for the application's call point. In addition, when there are not enough memory blocks in the memory pool, the memory management system can also dynamically allocate memory from the system memory automatically and hang it in the corresponding unallocated memory linked list according to the size of the memory block.

[0044] When the application starts running, the memory management system also creates a red-black tree, which is used to store the second characteristic information of the application's call point. When responding to the memory operation instructions of the memory management system, the memory management system not only allocates and releases memory blocks, but also modifies the red-black tree accordingly. It should be noted that the purpose of this application to record the application information and application count of the call point through the red-black tree is to improve the efficiency of cross-boundary detection by improving the search efficiency. For example, when responding to a memory allocation instruction, the application information of the call point can be searched in the red-black tree to quickly find out whether the call point has an application record, thereby modifying the application count of the call point, so that the memory management system can detect whether there is a risk of memory leakage. This will be described in detail later.

[0045] After an application begins running, the application's call point sends a memory operation instruction to the memory management system through the memory management system's memory operation interface, instructing the memory pool in the memory management system to allocate or release a memory block for the application's call point. When the memory allocation interface (malloc) receives a memory allocation instruction from the call point, the memory pool allocates a memory block for the call point, essentially retrieving a free memory block from the unallocated memory list and placing it in the allocated memory list. When the memory allocation interface (free) receives a memory release instruction from the call point, the memory pool releases a memory block for the call point, essentially removing the memory block occupied by the call point from the allocated memory list and re-attaching it to the unallocated memory list. The memory allocation interface and memory release interface can be encapsulated in a memory management module, which abstracts the memory allocation interface (malloc) and memory release interface (free). This memory management module replaces the system's memory management interface, allowing applications to request and release memory through the memory management module's interface. When an application calls the memory management module's interface, the interface automatically and implicitly transmits the call point's request information (such as the file name, line number, and task ID) to the memory management system.

[0046] In one embodiment, Figure 2 As shown, based on the above description, this application provides a cross-border detection method, which is applied to Figure 1 The memory management system shown in the figure is described using the execution entity as an example, and includes the following steps:

[0047] 201: Monitor first feature information of each memory block in the allocated memory linked list in the memory pool.

[0048] Among them, after the application starts running, the memory management system can periodically monitor the first characteristic information of the allocated memory linked list through a lowest priority thread, and the first characteristic information includes a front characteristic part and a back characteristic part. It should be noted that when the memory management system performs the monitoring operation, it can monitor the first characteristic information of each memory block in the allocated memory linked list in the memory pool in a sequential monitoring manner, that is, in the order from the head to the tail of the allocated memory linked list; it can also monitor the first characteristic information of each memory block in the allocated memory linked list in the memory pool in a reverse monitoring manner, that is, in the reverse order from the tail to the head of the allocated memory linked list; it can also monitor the first characteristic information of each memory block in the allocated memory linked list in the memory pool in a random monitoring manner. This application does not limit the specific method of monitoring.

[0049] 202: Searching for the destroyed first characteristic information and the target memory block to which the destroyed first characteristic information belongs.

[0050] The memory management system searches for the damaged first characteristic information in the allocated memory linked list. If found, the memory block to which the damaged first characteristic information belongs is located, and the memory block is used as the target memory block.

[0051] 203: Determine a target call point with an out-of-bounds risk based on the location of the damaged first feature information in the target memory block.

[0052] Among them, the memory management system determines the target call point with the risk of crossing the boundary based on the position of the destroyed first characteristic information in the target memory block. Specifically, if the front characteristic part of the target memory block is destroyed, the call point corresponding to the memory block located before the target memory block in the physical address is the target call point with the risk of crossing the boundary; if the front characteristic part of the target memory block is correct and the rear characteristic part is destroyed, the call point corresponding to the target memory block is the target call point with the risk of crossing the boundary. It should be noted that the memory management system can determine the corresponding call point based on the first characteristic information in the memory block, because the index information in the first characteristic information of the memory block points to the position of the application information of the corresponding call point in the red-black tree, so the memory management system can find the application information of the call point recorded in the red-black tree according to the index information to determine the corresponding call point.

[0053] In one implementable manner, the above-mentioned step of determining the target call point with an out-of-bounds risk based on the position of the damaged first feature information in the target memory block includes: when the front feature part of the target memory block is damaged, forward searching the memory blocks whose physical addresses are smaller than the target memory block in sequence until a memory block with a complete front feature part is found, and taking the call point corresponding to the memory block with a complete front feature part as the target call point; when the front feature part of the target memory block is complete and the rear feature part is damaged, taking the call point corresponding to the target memory block as the target call point.

[0054] Among them, if the front feature part of the target memory block is destroyed, it means that the physical address of the memory block occupied by the call point with the risk of crossing the boundary is smaller than the target memory block, and is located in front of the target memory block in the physical address. Therefore, when the front feature part of the target memory block is destroyed, the memory blocks with physical addresses smaller than the target memory block are searched forward in sequence until the memory block with the complete front feature part is found, and the call point corresponding to the memory block with the complete front feature part is used as the target call point. If the front feature part of the target memory block is complete and the rear feature part is destroyed, it means that the call point corresponding to the target memory block is the target call point with the risk of crossing the boundary. Therefore, when the front feature part of the target memory block is complete and the rear feature part is destroyed, the call point corresponding to the target memory block is used as the target call point.

[0055] In one feasible manner, after the step of determining the target call point with an out-of-bounds risk, the memory management system may also: search for second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application times, the application information includes the code file name, code line number and / or task identifier of the call point, and the application times is the number of memory blocks occupied by the call point; print out the application information of the target call point to indicate that the target call point has an out-of-bounds risk.

[0056] Among them, because the memory management system obtains the application information of the call point through the interface of the memory management module while allocating memory blocks to the call point, and records the application information of the call point in the red-black tree, the application information of each call point that is occupying the memory block is recorded in the red-black tree, so that the memory management system can find the application information of the target call point in the red-black tree and print out the application information of the target call point to prompt the user that the target call point has an out-of-bounds risk. In addition, the application information includes the code file name, code line number and task identifier, so that the user can quickly locate the target call point with an out-of-bounds risk based on the application information and take effective countermeasures.

[0057] In one practicable manner, the memory management system can also receive and respond to memory operation instructions of the call point through the memory operation interface to implement memory allocation and memory release. Memory allocation means that when the memory management system receives a memory allocation instruction of the call point through the memory allocation interface, it allocates a free memory block to the call point. Memory release means that when the memory management system receives a memory release instruction of the call point through the memory release interface, it releases the memory block occupied by the call point as a free memory block. Next, this application will explain the process of memory allocation and memory release in detail, specifically:

[0058] Memory allocation process: When receiving a memory allocation instruction from a call point, the memory management system allocates an unallocated target memory block in the memory pool to the call point and hangs the target memory block in the allocated memory linked list; searches for the second feature information of the call point in the red-black tree. If the search fails, the second feature information of the call point is recorded in the red-black tree; modifies the first feature information in the target memory block and associates the first feature information with the second feature information of the call point in the red-black tree.

[0059] Among them, when the memory operation instruction is a memory allocation instruction, the memory management system obtains an idle memory block from the unallocated memory linked list as the target memory block, allocates it to the call point, and hangs the target memory block in the allocated memory linked list. On the one hand, the memory management system modifies the first characteristic information in the target memory block, changing the "allocated" in the first characteristic information to "yes". On the other hand, the memory management system searches the application information of the call point in the red-black tree to find the leaf node corresponding to the call point. The leaf node records the second characteristic information of the call point (including application information and application count). If the application information of the call point is found in the red-black tree, the application count of the call point is increased by one. If the application information of the call point is not found in the red-black tree, a new leaf node is created in the red-black tree, and the application information and application count of the call point are recorded in the newly created leaf node. Finally, the first characteristic information is associated with the second characteristic information of the call point in the red-black tree, that is, the position of the application information and application count of the call point in the red-black tree is recorded in the index information of the characteristic information, so that the application information and application count of the call point recorded in the red-black tree can be quickly found later through the index information.

[0060] Memory release process: When receiving the memory release instruction of the call point, the memory management system searches for the second feature information of the call point in the red-black tree; modifies the second feature information of the call point in the red-black tree; modifies the first feature information in the memory block corresponding to the call point, and hangs the memory block corresponding to the call point to the unallocated memory linked list in the memory pool.

[0061] Among them, when the memory operation instruction is a memory release instruction, the memory management system first obtains the application information of the call point through the interface of the memory management module, and then searches the application information and application times of the call point in the red-black tree, and reduces the application times of the call point by one. If the application times of the call point is equal to zero after reduction by one, it means that there are no other occupied memory blocks at the call point. Therefore, on the one hand, the application information and application times of the call point are deleted from the red-black tree, and on the other hand, the first feature information in the memory block corresponding to the call point is modified, for example, whether it has been allocated in the first feature information is modified to "no", the index information is cleared, whether it has been released is marked as released, and the application information of the released call point is recorded at the release point information. Finally, the memory management system re-hangs the released memory block to the unallocated memory linked list in the memory pool. Among them, whether it has been released and the release point information in the first feature information are used to determine whether the memory block has been released repeatedly.

[0062] In one practicable manner, when a memory allocation instruction is received from a call point, the memory management system reads the first characteristic information of the target memory block; when the first characteristic information of the target memory block is destroyed, it is determined that there is a risk of memory out-of-bounds.

[0063] Among them, when the memory operation instruction is a memory allocation instruction, the memory management system allocates a free memory block to the call point, and uses the free memory block as the target memory block, and detects whether the feature code and usage information in the feature information of the target memory block are damaged, such as whether the feature code is consistent with the preset string, whether the usage information is correct, etc. When the memory operation instruction is a memory release instruction, the memory management system uses the memory block allocated to the call point as the target memory block. At this time, in addition to detecting whether the feature code and usage information in the feature information are damaged, the memory management system can also detect the index information of the call point, such as whether the index information of the call point is valid, etc. It can be seen that this embodiment can perform memory out-of-bounds detection in real time during memory allocation, further improving the detection efficiency and real-time performance of memory.

[0064] In summary, this application implements timely memory out-of-bounds detection during the running of an application. During this process, there is no need to exit the application, and the running of the application will not be affected, thus not affecting the functional implementation of the application. This can improve the problem of untimely out-of-bounds detection in the prior art. In addition, the out-of-bounds detection method provided by this application can also automatically locate the out-of-bounds call point, thereby improving the efficiency of out-of-bounds detection.

[0065] In one embodiment, the present invention also provides a memory management system. Figure 3 . The embodiment of the present invention can divide the functional units of the device according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation. Figure 3 As shown, the memory management system includes a monitoring unit 310, a positioning unit 320 and a determination unit 330. Specifically: the monitoring unit 310 is used to monitor the first characteristic information of each memory block in the allocated memory linked list in the memory pool; the positioning unit 320 is used to find the damaged first characteristic information and the target memory block to which the damaged first characteristic information belongs; the determination unit 330 is used to determine the target call point with an out-of-bounds risk based on the position of the damaged first characteristic information in the target memory block.

[0066] In one practicable manner, the determination unit 330 is specifically used to: in a case where the front feature part of the target memory block is destroyed, forward search the memory blocks whose physical addresses are smaller than the target memory block in sequence until a memory block whose front feature part is intact and whose rear feature part is destroyed is found, and the call point corresponding to the memory block whose front feature part is intact and whose rear feature part is destroyed is used as the target call point; in a case where the front feature part of the target memory block is intact and whose rear feature part is destroyed, the call point corresponding to the target memory block is used as the target call point.

[0067] In one practicable manner, the memory management system further includes a prompt unit 340, which is used to: search for second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application times, the application information includes the code file name, code line number and / or task identifier of the call point, and the application times is the number of memory blocks occupied by the call point; print out the application information of the target call point to prompt that the target call point has a risk of crossing the boundary.

[0068] In one practicable manner, the memory management system also includes an allocation unit 350, which is used to: allocate an unallocated target memory block in the memory pool to the call point, and hang the target memory block in the allocated memory linked list; search for the second characteristic information of the call point in the red-black tree, and if the search fails, record the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the target memory block, and associate the first characteristic information with the second characteristic information of the call point in the red-black tree.

[0069] In an practicable manner, the determining unit 330 is further configured to: read the first characteristic information of the target memory block; and determine that there is a memory out-of-bounds risk when the first characteristic information of the target memory block is destroyed.

[0070] In one practicable manner, the memory management system also includes a release unit 360, which is used to: search for the second characteristic information of the call point in the red-black tree; modify the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the memory block corresponding to the call point, and hang the memory block corresponding to the call point to the unallocated memory linked list in the memory pool.

[0071] In summary, the memory management system first monitors the first characteristic information of the memory block through the monitoring unit 310, then determines the target memory block to which the damaged first characteristic information belongs through the positioning unit 320, and finally determines the target call point with a risk of out-of-bounds based on the position of the damaged first characteristic information in the target memory block through the determination unit 330. It can be seen that the memory management system and out-of-bounds detection method provided by this application can improve the problem of delayed out-of-bounds detection in the prior art.

[0072] In one embodiment, the present application also provides a memory management system, see Figure 4 . The memory management system can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, portable wearable devices and servers. The server can be implemented as an independent server or a server cluster composed of multiple servers. The memory management system in this embodiment as shown in the figure may include: a processor 410 and a memory 420. The above-mentioned processor 410 and memory 420 are connected via a bus 430. The processor 410 is used to execute multiple instructions; the memory 420 is used to store multiple instructions, which are suitable for being loaded by the processor 410 and executed as the out-of-bounds detection method in the above-mentioned embodiment.

[0073] Among them, the processor 410 can be an electronic control unit (ECU), a central processing unit (CPU), a general processor, a coprocessor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The processor 410 can also be a combination that realizes computing functions, such as a combination of one or more microprocessors, a combination of DSP and microprocessors, etc. In this embodiment, the processor 410 can adopt a single-chip microcomputer, and various control functions can be realized by programming the single-chip microcomputer. For example, in this embodiment, the collection, processing and demodulation functions of the capacity of the battery cell and the cumulative total charge amount are realized. The processor has the advantages of strong computing power and fast processing speed. Specifically: the processor 410 is used to execute the function of the monitoring unit 310, which is used to monitor the first characteristic information of each memory block in the allocated memory linked list in the memory pool; it is also used to execute the function of the positioning unit 320, which is used to find the damaged first characteristic information and the target memory block to which the damaged first characteristic information belongs; it is also used to execute the function of the determination unit 330, which is used to determine the target call point with an out-of-bounds risk based on the position of the damaged first characteristic information in the target memory block.

[0074] In one practicable manner, the processor 410 is specifically used to: in a case where the front feature part of the target memory block is destroyed, forward search the memory blocks whose physical addresses are smaller than the target memory block in sequence until a memory block whose front feature part is intact and whose rear feature part is destroyed is found, and use the call point corresponding to the memory block whose front feature part is intact and whose rear feature part is destroyed as the target call point; in a case where the front feature part of the target memory block is intact and whose rear feature part is destroyed, use the call point corresponding to the target memory block as the target call point.

[0075] In one practicable manner, the processor 410 is also used to execute the function of the prompt unit 340, which is used to: search for the second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application times, the application information includes the code file name, code line number and / or task identifier of the call point, and the application times is the number of memory blocks occupied by the call point; print out the application information of the target call point to prompt that there is a risk of out-of-bounds at the target call point.

[0076] In one practicable manner, the processor 410 is also used to execute the functions of the allocation unit 350, which is used to: allocate an unallocated target memory block in the memory pool to the call point, and hang the target memory block in the allocated memory linked list; search for the second characteristic information of the call point in the red-black tree, and if the search fails, record the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the target memory block, and associate the first characteristic information with the second characteristic information of the call point in the red-black tree.

[0077] In one practicable manner, the processor 410 is further configured to: read the first characteristic information of the target memory block; and determine that there is a risk of memory out-of-bounds when the first characteristic information of the target memory block is destroyed.

[0078] In one practicable manner, the processor 410 is also used to execute the functions of the release unit 360, which is used to: search for the second characteristic information of the call point in the red-black tree; modify the second characteristic information of the call point in the red-black tree; modify the first characteristic information in the memory block corresponding to the call point, and hang the memory block corresponding to the call point to the unallocated memory linked list in the memory pool.

[0079] In one embodiment, the present application further provides a computer-readable storage medium storing a plurality of instructions suitable for a processor to load and execute the method of any of the aforementioned embodiments. A processor 410 is configured to execute the plurality of instructions; a memory 420 is configured to store the plurality of instructions suitable for the processor 410 to load and execute the method for uploading a fault as described in the aforementioned embodiment.

[0080] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0081] The above embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A cross-bounds detection method, applied to a memory management system, characterized in that: include: During the running of the application, the first characteristic information of each memory block in the allocated memory linked list in the memory pool is periodically monitored by the lowest priority thread in a sequential monitoring or reverse monitoring manner to determine whether it is destroyed; Searching for the destroyed first characteristic information and the target memory block to which the destroyed first characteristic information belongs; In the case where the front feature portion of the target memory block is destroyed, forward searching is performed on memory blocks whose physical addresses are smaller than the target memory block in sequence until a memory block whose front feature portion is intact and whose rear feature portion is destroyed is found, and the call point corresponding to the memory block whose front feature portion is intact and whose rear feature portion is destroyed is used as the target call point; In a case where the front feature portion of the target memory block is intact and the rear feature portion is destroyed, the call site corresponding to the target memory block is used as the target call site.

2. The method according to claim 1, characterized in that After determining the target call point with risk of out-of-bounds, it also includes: Searching for second characteristic information of the target call point in the red-black tree, wherein the second characteristic information includes application information and application count, the application information includes the code file name, code line number and / or task identifier of the call point, and the application count is the number of memory blocks occupied by the call point; Print out the application information of the target call point to prompt that the target call point has a risk of crossing the boundary.

3. The method according to claim 1, characterized in that In the case of receiving a memory allocation instruction at the call site, the method further includes: Allocating an unallocated target memory block in the memory pool to the call site, and hanging the target memory block into the allocated memory linked list; Searching for the second characteristic information of the call point in the red-black tree, and if the search fails, recording the second characteristic information of the call point in the red-black tree; The first characteristic information in the target memory block is modified, and the first characteristic information is associated with the second characteristic information of the call point in the red-black tree.

4. The method according to claim 3, characterized in that In the case of receiving a memory allocation instruction at the call site, the method further includes: Reading first characteristic information of the target memory block; When the first characteristic information of the target memory block is destroyed, it is determined that there is a risk of memory crossing the boundary.

5. The method according to claim 1, wherein In the case of receiving a memory release instruction at the call site, the method further includes: Searching for second characteristic information of the call point in the red-black tree; Modify the second characteristic information of the call point in the red-black tree; The first characteristic information in the memory block corresponding to the call point is modified, and the memory block corresponding to the call point is hung in the unallocated memory linked list in the memory pool.

6. A memory management system, characterized in that: include: a monitoring unit configured to periodically monitor, in a sequential or reverse order manner, by a lowest priority thread during program execution, whether first characteristic information of each memory block in an allocated memory linked list in a memory pool is destroyed; a positioning unit, configured to search for the destroyed first characteristic information and a target memory block to which the destroyed first characteristic information belongs; A determination unit is used to, when the front feature part of the target memory block is destroyed, sequentially perform a forward search on memory blocks whose physical addresses are smaller than the target memory block until a memory block whose front feature part is intact and whose rear feature part is destroyed is found, and use the call point corresponding to the memory block whose front feature part is intact and whose rear feature part is destroyed as the target call point; when the front feature part of the target memory block is intact and whose rear feature part is destroyed, use the call point corresponding to the target memory block as the target call point.

7. A memory management system, characterized in that: The system includes a processor and a memory, which are connected via a bus; the processor is used to execute multiple instructions; the memory is used to store the multiple instructions, and the instructions are suitable for being loaded by the processor and executing the cross-border detection method as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the cross-border detection method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Memory leak detecting method and memory leak detecting device

    CN104572460A

  • Memory management method and system

    CN105183542A

  • Memory management method and system adopting analysis-feedback-tuning mode

    CN106547617A

  • Memory fault detection method and device

    CN110457150A