Memory detection method and device in running process of embedded operating system

By entering the exception handler and allocating backup space, the embedded operating system can perform full-area memory detection during operation, solving the problem of not being able to detect kernel-state space, and realizing timely discovery of memory errors and improving security.

CN119512838AActive Publication Date: 2025-02-25INTEWELL (GUANGZHOU) SOFEWARE TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411588897.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-08
Publication Date
2025-02-25
Estimated Expiration
2044-11-08

AI Technical Summary

Technical Problem

The embedded operating system cannot perform full-area memory self-test during operation, especially the kernel-state space cannot be covered, resulting in potential memory errors that are difficult to detect.

Method used

By entering the exception handler, obtain memory management permissions, allocate the backup space for memory detection, and migrate the data to the backup space after the detection is passed, detect the remaining memory again, and finally restore the data to the original location.

Benefits of technology

It realizes comprehensive detection of memory areas, can promptly detect potential memory errors, prevent security vulnerabilities caused by memory problems, and enhances the security of embedded operating systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512838A_ABST
    Figure CN119512838A_ABST
Patent Text Reader

Abstract

The invention relates to a memory detection method and device in the running process of an embedded operating system, equipment and a storage medium, and the method comprises the following steps: responding to the starting of a memory detection method, and entering an exception handling program to obtain memory management authority; distribution information of a current memory is obtained, the distribution information comprises a first space and a current free space, and the first space is a currently used space; distributing a backup space from the current free space of the memory according to the size of the first space; loading and starting a first memory detection program in the current free space of the memory after the backup space is allocated, and performing memory detection on the backup space or the backup space and the current free space of the memory after the first memory detection program is started by using the first memory detection program; after the first memory detection program passes detection, when it is judged that the backup space is larger than the first space, data in the first space is migrated into the backup space; loading and starting a second memory detection program in the backup space, and using the second memory detection program to carry out memory detection on the undetected space of the memory; and after the detection of the second memory detection program is completed, recovering the migrated data in the backup space to the first space. In this way, the problem that in the prior art, an embedded operating system cannot conduct full-area memory self-checking in the running process is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of embedded operating systems, and in particular to a memory detection method during the operation of an embedded operating system. Background Art

[0002] In the field of embedded real-time operating systems, especially those that support multiple processes and run in environments with extremely high security requirements (such as defense systems, rail traffic control systems, and nuclear power facility monitoring systems), the stability and reliability of memory are the cornerstones for ensuring the safe operation of the entire system. As the core resource for the operation of the operating system and its applications, the state of memory directly affects the stability and reliability of the system. Any memory failure may cause system abnormalities, data loss, or even catastrophic consequences. Therefore, comprehensive testing of memory is a key measure to ensure the stable operation of the system.

[0003] At present, after the embedded operating system is started, it only detects limited memory areas, which is mainly limited by the MMU (Memory Management Unit) or MPU (Memory Protection Unit). These hardware protection mechanisms effectively isolate the access of user space and kernel space, ensuring the security of the system, but at the same time, it also makes it impossible for the memory detection program in user state to directly access the physical address of the memory in kernel state. In other words, the existing memory detection mechanism often cannot cover all key memory areas, especially those protected kernel space.

[0004] Specifically, Figure 1 The memory layout of the embedded operating system shown in Figure 1 is mainly divided into two parts: user state space and kernel state space. The user state space includes multiple processes (process 1 to process n) and user state free space. Each process has its own independent memory space for storing program code, data, stack and other information. The user state free space is the memory area that is not allocated to any process. The kernel state space includes kernel state used space and kernel state free space. The kernel state used space refers to the memory area that has been occupied by the operating system kernel, while the kernel state free space is the memory area that has not been used by the kernel.

[0005] During the operation of the embedded operating system, since the kernel state space is in use, the kernel state used space and code segment cannot be tested for memory. This is because memory testing requires modifying the data in the memory. If the code segment and kernel state used space are written, it may cause the entire embedded operating system to exit abnormally. In addition, these areas are usually protected by the kernel state using MMU or MPU, so the self-test program cannot perform memory read and write operations. Summary of the invention

[0006] In view of the above problems in the prior art, the present application provides a memory detection method, device, equipment and storage medium during the operation of an embedded operating system, which solves the problem that the embedded operating system in the current technology cannot perform full-area memory self-check during operation.

[0007] To achieve the above-mentioned purpose, the first aspect of the present application provides a memory detection method during the operation of an embedded operating system, the method comprising:

[0008] In response to the initiation of the memory detection method, an exception handling program is entered to obtain memory management authority;

[0009] Acquire current memory allocation information, including a first space and current free space, where the first space is currently used space;

[0010] Allocating a backup space from the current free space of the memory according to the size of the first space;

[0011] Loading and starting a first memory detection program in the current free space of the memory after the backup space is allocated, and using the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started;

[0012] After the first memory detection program passes the detection, if it is determined that the backup space is larger than the first space, the data in the first space is migrated to the backup space;

[0013] Loading and starting a second memory detection program in the backup space, and using the second memory detection program to perform a memory detection on the memory space that has not been detected;

[0014] After the second memory detection program is completed, the migrated data in the backup space is restored to the first space.

[0015] In this way, the embedded operating system can obtain higher memory management permissions by entering the exception handler, and can bypass the protection mechanism of the MMU or MPU, so that it can access and operate the entire memory space. Specifically, the present application adopts a two-detection mechanism. During the detection process, the backup space is first detected. When it is ensured that the backup space is correct and sufficient to accommodate the used data, the used data is migrated to the backup space, and then the memory detection program is reloaded and started in the backup space, and the remaining memory is detected again. Finally, the migrated data is restored to the original position, thereby completing the entire memory detection process. Therefore, the present application realizes a comprehensive detection of the memory area, can promptly discover potential memory errors, prevent security vulnerabilities caused by memory problems, and enhance the security of the embedded operating system.

[0016] As a possible implementation of the first aspect, the following also includes:

[0017] After the first memory detection program passes the detection, when it is determined that the backup space is smaller than the first space, the first space is divided into a plurality of first subspaces;

[0018] Loading and starting a second memory detection program in the backup space, and sequentially executing the following steps for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed;

[0019] The second memory detection program is used to perform memory detection on the memory space that has not been detected.

[0020] In this way, even if the first space is large, the present application can still divide the first space to ensure that the entire first space can be fully detected, avoiding the problem of inability to perform comprehensive detection due to insufficient backup space, and improving the versatility and adaptability of the memory detection method.

[0021] As a possible implementation of the first aspect, the following also includes:

[0022] When entering the exception handling program, recording the current program running pointer of the embedded operating system;

[0023] After all the spaces of the memory have been detected and the data in the first space has been restored, the exception handling program is exited, and the operation of the corresponding program is restored according to the recorded program operation pointer.

[0024] In this way, recording the current program running pointer can ensure that after the memory test is completed, the system can accurately restore to the state before the test. In other words, after the memory test is completed, by restoring the recorded program running pointer, the system can seamlessly continue to execute the previous task, ensuring the continuity of the task. In addition, the user will hardly notice the change in the system state when the system is performing a memory test, because the system can be restored to the previous running state immediately after the test, thereby improving the user experience.

[0025] As a possible implementation of the first aspect, the free space of the memory includes user state free space and kernel state free space;

[0026] The allocating a backup space from the current free space of the memory includes:

[0027] Allocate the backup space from the user state free space;

[0028] Or, the backup space is allocated from the kernel state free space.

[0029] In this way, the present application allows the selection of backup space from user-mode free space or kernel-mode free space, making the detection process more flexible and able to make the best choice based on the current system status and available resources, thereby improving the flexibility of the design to meet the needs of different scenarios.

[0030] As a possible implementation manner of the first aspect, before the memory detection method is started, the method further includes:

[0031] Obtaining the current running state of the embedded operating system;

[0032] When the running state corresponds to having idle resources, the memory detection method is started.

[0033] In this way, it is ensured that the memory detection method is started at the appropriate time to avoid occupying resources when the system is busy, so that system resources are reasonably utilized instead of adding extra burden when the system is busy, thereby minimizing the impact on the normal operation of the system.

[0034] As a possible implementation manner of the first aspect, detecting the memory includes:

[0035] Read and write memory space;

[0036] If the read data is consistent with the written data, it is determined that the memory space has passed the detection;

[0037] If the read data is inconsistent with the written data, it is determined that the memory space test has failed.

[0038] In this way, the integrity of the memory space is verified through simple read and write operations, making the logic of memory detection more intuitive and easier to implement, and reducing the complexity of the memory detection program.

[0039] To achieve the above-mentioned purpose, the second aspect of the present application provides a memory detection device during the operation of an embedded operating system, the device comprising:

[0040] A response unit, used to respond to the start of the memory detection method and enter the exception handling program to obtain memory management authority;

[0041] An acquisition unit, used to acquire allocation information of current memory, including a first space and current free space, wherein the first space is a currently used space;

[0042] an allocation unit, configured to allocate a backup space from the current free space of the memory according to the size of the first space;

[0043] A first detection unit is used to load and start a first memory detection program in the current free space of the memory after the backup space is allocated, and use the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started;

[0044] a migration unit, configured to migrate data in the first space to the backup space when it is determined that the backup space is larger than the first space after the first memory detection program passes the detection;

[0045] A second detection unit, configured to load and start a second memory detection program in the backup space, and use the second memory detection program to perform a memory detection on the memory space that has not been detected;

[0046] The recovery unit is used to recover the migrated data in the backup space to the first space after the detection of the second memory detection program is completed.

[0047] As a possible implementation manner of the second aspect, the device further includes:

[0048] a division unit, configured to divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space after the first memory detection program passes the detection;

[0049] an execution unit, configured to load and start a second memory detection program in the backup space, and sequentially execute, for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed;

[0050] The third detection unit is used to use the second memory detection program to perform memory detection on the memory space that has not been detected.

[0051] To achieve the above-mentioned object, the third aspect of the present application provides a computing device, including:

[0052] processor, and

[0053] A memory having program instructions stored thereon, wherein when the program instructions are executed by the processor, the processor executes any memory detection method described in the first aspect.

[0054] To achieve the above-mentioned purpose, the fourth aspect of the present application provides a storage medium on which program instructions are stored. When the program instructions are executed by a computer, the computer executes any memory detection method described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 It is a schematic diagram of a memory partition diagram of an embedded operating system provided by the present application;

[0056] Figure 2 It is a flowchart of the steps of a memory detection method during the operation of an embedded operating system provided by the present application;

[0057] Figure 3 It is a memory detection state jump diagram provided by this application;

[0058] Figure 4 It is a schematic diagram of the entire memory space provided by this application;

[0059] Figure 5 It is a structural schematic diagram of a memory detection device during the operation of an embedded operating system provided by the present application;

[0060] Figure 6 It is a structural schematic diagram of a computing device provided in an embodiment of the present application.

[0061] It should be understood that the size and shape of each block diagram in the above structural diagram are for reference only and should not constitute an exclusive interpretation of the embodiment of the present invention. The relative position and inclusion relationship between the blocks presented in the structural diagram are only schematic representations of the structural association between the blocks, and do not limit the physical connection method of the embodiment of the present invention. DETAILED DESCRIPTION

[0062] The technical solution provided by the present application is further described below with reference to the accompanying drawings and examples. It should be understood that the system structure and business scenarios provided in the examples of the present application are mainly to illustrate the possible implementation methods of the technical solution of the present application and should not be interpreted as the only limitation on the technical solution of the present application. It is known to those of ordinary skill in the art that with the evolution of the system structure and the emergence of new business scenarios, the technical solution provided by the present application is also applicable to similar technical problems.

[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present application. In case of any inconsistency, the meaning described in this specification or the meaning derived from the contents recorded in this specification shall prevail. In addition, the terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.

[0064] The present application embodiment provides a memory detection method during the operation of an embedded operating system, such as Figure 2 As shown, the method includes:

[0065] S201, in response to the start of the memory detection method, entering an exception handling program to obtain memory management authority;

[0066] The purpose of the embedded operating system entering the exception handling program is to obtain the memory management authority and record the current program running pointer of the embedded operating system (see the detailed description below).

[0067] S202, obtaining allocation information of current memory, including a first space and current free space, where the first space is currently used space;

[0068] S203, allocating a backup space from the current free space of the memory according to the size of the first space;

[0069] The backup space is larger than the first space, which ensures that the backup space has enough space to store the data that needs to be backed up.

[0070] S204, loading and starting a first memory detection program in the current free space of the memory after the backup space is allocated, and using the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started;

[0071] S205: after the first memory detection program passes the detection, if it is determined that the backup space is larger than the first space, migrate the data in the first space to the backup space;

[0072] S206, loading and starting a second memory detection program in the backup space, and using the second memory detection program to perform a memory detection on the memory space that has not been detected;

[0073] S207: After the second memory detection program completes detection, the migrated data in the backup space is restored to the first space.

[0074] It is worth noting that the first memory detection program and the second memory detection program are actually the same program, which is only loaded twice during the memory detection process. Since the read and write operations during the memory detection process will overwrite the original data, whether the first memory detection program exits normally or not will not affect the detection result of the second memory detection program. This is because when the second memory detection program starts to detect the part of memory, it will also perform read and write tests, which will cause the data in the part of memory to be overwritten again.

[0075] Preferably, when the second memory detection program is loaded, the first memory detection program is exited. That is, after the first memory detection program is finished, the first memory detection program is exited.

[0076] In this way, the embedded operating system can obtain higher memory management permissions by entering the exception handler, and can bypass the protection mechanism of the MMU or MPU, so that it can access and operate the entire memory space. Specifically, the present application adopts a two-detection mechanism. During the detection process, the backup space is first detected. When it is ensured that the backup space is correct and sufficient to accommodate the used data, the used data is migrated to the backup space, and then the memory detection program is reloaded and started in the backup space, and the remaining memory is detected again. Finally, the migrated data is restored to the original position, thereby completing the entire memory detection process. Therefore, the present application realizes a comprehensive detection of the memory area, can promptly discover potential memory errors, prevent security vulnerabilities caused by memory problems, and enhance the security of the embedded operating system.

[0077] In some embodiments, it also includes:

[0078] After the first memory detection program passes the detection, when it is determined that the backup space is smaller than the first space, the first space is divided into a plurality of first subspaces;

[0079] Loading and starting a second memory detection program in the backup space, and sequentially executing the following steps for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed;

[0080] The second memory detection program is used to perform memory detection on the memory space that has not been detected.

[0081] This will be explained below using a specific example.

[0082] For example, the currently used space (ie, the first space) of the embedded operating system is 1 MB, and the backup space is 512 KB. Now, a comprehensive detection needs to be performed on the first space.

[0083] Step 1: Since the first space is 1MB, which is larger than the backup space 512KB, the first space is divided into multiple first subspaces. Specifically, assuming that the size of each first subspace is 256KB (smaller than the backup space), the first space needs to be divided into 4 first subspaces, 1MB / 256KB=4.

[0084] Step 2, reload and start the second memory detection program into the backup space;

[0085] Step 3, for the first first subspace: migrate the data in the first subspace to the backup space, start the second memory detection program to detect the first subspace, and after the detection is completed, restore the data in the backup space to the first subspace.

[0086] Step 4: Repeat step 3 to perform detection and data recovery on the remaining three first subspaces in turn.

[0087] Specifically, for the second first subspace: the data in the second subspace is migrated to the backup space, the second memory detection program is started to detect the second subspace, and after the detection is completed, the data in the backup space is restored to the second subspace. And, for the third and fourth first subspaces, the same as the above step 3, the repeated parts are not repeated.

[0088] Step 5: Use the second memory detection program to perform a memory detection on the memory space that has not been detected.

[0089] It should be noted that the space occupied by the first memory detection program has not been detected, so this step is required to complete the detection of the entire memory area.

[0090] It can be seen from steps 1-5 that in the present application, when the first space is large, a comprehensive detection of all memories can still be achieved through multiple detection mechanisms.

[0091] In this way, even if the first space is large, the present application can still divide the first space to ensure that the entire first space can be fully detected, avoiding the problem of inability to perform comprehensive detection due to insufficient backup space, and improving the versatility and adaptability of the memory detection method.

[0092] In some embodiments, it also includes:

[0093] When entering the exception handling program, recording the current program running pointer of the embedded operating system;

[0094] After all the spaces of the memory have been detected and the data in the first space has been restored, the exception handling program is exited, and the operation of the corresponding program is restored according to the recorded program operation pointer.

[0095] For example, after the embedded operating system enters the exception handler, the system will save the current program counter value, such as PC = 0x40005678, which indicates that the next instruction to be executed is located at the memory address 0x40005678. And when the embedded operating system exits the exception handler, the system restores the previously saved program counter value PC = 0x40005678 to the corresponding register, that is, the next instruction to be executed will be the one at the address 0x40005678.

[0096] In this way, recording the current program running pointer can ensure that after the memory test is completed, the system can accurately restore to the state before the test. In other words, after the memory test is completed, by restoring the recorded program running pointer, the system can seamlessly continue to execute the previous task, ensuring the continuity of the task. In addition, the user will hardly notice the change in the system state when the system is performing a memory test, because the system can be restored to the previous running state immediately after the test, thereby improving the user experience.

[0097] In some embodiments, the free space of the memory includes user state free space and kernel state free space;

[0098] The allocating a backup space from the current free space of the memory includes:

[0099] Allocate the backup space from the user state free space;

[0100] Or, the backup space is allocated from the kernel state free space.

[0101] Exemplarily, selecting user-mode free space as backup space can avoid potential risks caused by kernel-mode operations.

[0102] Exemplarily, if the kernel state free space is larger, the kernel state free space may be selected to speed up the detection speed.

[0103] In this way, the present application allows the selection of backup space from user-mode free space or kernel-mode free space, making the detection process more flexible and able to make the best choice based on the current system status and available resources, thereby improving the flexibility of the design to meet the needs of different scenarios.

[0104] In some embodiments, before the memory detection method is started, it also includes:

[0105] Obtaining the current running state of the embedded operating system;

[0106] When the running state corresponds to having idle resources, the memory detection method is started.

[0107] Among them, idle resources refer to conditions such as the current system task load is low, the CPU usage is not high, and there is enough free memory.

[0108] For example, you can choose to start the memory detection method during non-working hours at night or during the time of day when the system load is the lowest.

[0109] In this way, based on the real-time monitoring data, the system intelligently chooses to start the memory detection method during the period when the task load is low and the CPU usage is not high. In other words, the memory detection method is not executed at a fixed time point, but decides when to start the detection based on the current actual state of the system. This ensures that the memory detection method is started at the right time to avoid occupying resources when the system is busy, so that system resources are reasonably utilized instead of adding additional burden when the system is busy, minimizing the impact on the normal operation of the system.

[0110] In some embodiments, the detection of the memory includes:

[0111] Read and write memory space;

[0112] If the read data is consistent with the written data, it is determined that the memory space has passed the detection;

[0113] If the read data is inconsistent with the written data, it is determined that the memory space test has failed.

[0114] In this way, the integrity of the memory is verified through simple read and write operations, making the logic of memory detection more intuitive and easier to implement, and reducing the complexity of the memory detection program.

[0115] In order to more clearly illustrate the above method, the present application provides a specific embodiment.

[0116] like Figure 3 As shown, this embodiment is described by taking the allocation of backup space from user-mode free space as an example.

[0117] The embedded operating system includes kernel state space and user state space. The kernel state space includes kernel used space and kernel free space, and the user state space includes user used space and user free space.

[0118] In addition, the code segment stores the machine code of the program, that is, the executable instructions. Whether it is a user-mode application or a kernel-mode operating system code, it has its own code segment. In other words, the code segment is located in the kernel-mode space or the user-mode space.

[0119] The global data segment stores static variables, constants, and other data that needs to be maintained throughout the program. The global data segment can also exist in user space or kernel space, depending on whether the data is used by user-mode applications or by the kernel-mode operating system.

[0120] Step 1: When the embedded operating system running state corresponds to having idle resources, the memory detection method is started, the embedded operating system enters the exception handling program, obtains the memory management authority, and at the same time, records the current program running pointer of the embedded operating system;

[0121] Step 2: calling the memory management program of the operating system to obtain the current memory allocation information, including the first space and the current free space, where the first space is the currently used space;

[0122] The first space is the sum of the kernel used space and the user used space;

[0123] The current free space is the sum of kernel free space and user free space.

[0124] In addition, the first space may specifically include: kernel used space, user used space, code segment, and global data segment.

[0125] Step 3: Allocate a backup space from the current free space of the memory according to the size of the first space, wherein the backup space is larger than the first space;

[0126] At this time, the distribution of all memory space is as follows Figure 4 As shown, the specific corresponding Figure 4 The top picture.

[0127] Step 4: loading and starting a first memory detection program in the current free space of the memory after the backup space is allocated, and using the first memory detection program to perform a memory detection on the backup space;

[0128] At this time, the distribution of all memory space is as follows Figure 4 As shown, the specific corresponding Figure 4 The middle picture.

[0129] Specifically, read and write operations are performed on the backup space, and the read data is compared with the written data to see if they are consistent. If they are consistent, it is considered that the test has passed; if they are inconsistent, it is considered that the test has failed.

[0130] Step 5: After the detection is passed, the data in the first space is migrated to the backup space;

[0131] Step 6: reload the second memory detection program in the backup space and start it, and use the started reloaded second memory detection program to perform memory detection on the memory space that has not been detected;

[0132] At this time, the distribution of all memory space is as follows Figure 4 As shown, the specific corresponding Figure 4 The bottom picture.

[0133] The undetected space is the space other than the backup space in the operating system.

[0134] In addition, the detection method is the same as the detection method of step 4. Specifically, read and write operations are performed on the space that has not been detected, and the read data is compared with the written data to see if they are consistent. If they are consistent, the detection is considered to have passed; if they are inconsistent, the detection is considered to have failed.

[0135] It is worth noting that since the read and write operations during the memory detection process will overwrite the original data, whether the first memory detection program exits normally or not will not affect the detection result of the second memory detection program. This is because when the second memory detection program starts to detect the part of memory, it will also perform read and write tests, which will cause the data in the part of memory to be overwritten again.

[0136] Preferably, when the second memory detection program is loaded, the first memory detection program is exited. That is, after the first memory detection program is finished, the first memory detection program is exited.

[0137] Step 7: After the detection is completed, the migrated data in the backup space is restored to the first space;

[0138] Step 8, exit the exception handling program, and resume the operation of the corresponding program according to the program running pointer recorded in step 1;

[0139] Step 9: Based on the results of the memory detection, the system generates a report on the current memory status and corresponding measures to maintain the healthy status of the memory.

[0140] The corresponding measures include but are not limited to:

[0141] Bad memory block marking: For detected bad blocks, the system will mark them in the memory management table to prevent them from being used again in the future. For example, the marking method can be to set a specific flag bit.

[0142] Application migration: If a problem is detected in a memory area that a program is using, the system may migrate the program's data to a healthy memory area to ensure the normal operation of the program.

[0143] Warning notification: For serious memory problems, the system may issue a warning notification to remind administrators or users to take further actions, such as replacing hardware or performing more detailed diagnosis.

[0144] Figure 5 1 is a structural schematic diagram of a memory detection device during the operation of an embedded operating system provided in an embodiment of the present application. The embodiment of the present application provides a memory detection device 500 during the operation of an embedded operating system, and the device includes:

[0145] A response unit 501 is used to respond to the start of the memory detection method and enter an exception handling program to obtain memory management authority;

[0146] The acquisition unit 502 is used to acquire the allocation information of the current memory, including the first space and the current free space, where the first space is the currently used space;

[0147] The allocation unit 503 is used to allocate a backup space from the current free space of the memory according to the size of the first space;

[0148] The first detection unit 504 is used to load and start a first memory detection program in the current free space of the memory after the backup space is allocated, and use the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started;

[0149] A migration unit 505, configured to migrate the data in the first space to the backup space when it is determined that the backup space is larger than the first space after the first memory detection program passes the detection;

[0150] A second detection unit 506 is used to load and start a second memory detection program in the backup space, and use the second memory detection program to perform a memory detection on the memory space that has not been detected;

[0151] The recovery unit 507 is configured to recover the migrated data in the backup space to the first space after the detection of the second memory detection program is completed.

[0152] In this way, the embedded operating system can obtain higher memory management permissions by entering the exception handler, and can bypass the protection mechanism of the MMU or MPU, so as to access and operate the entire memory space. Specifically, during the detection process, by detecting the backup space, when it is ensured that the backup space is correct and sufficient to accommodate the used data, the used data is migrated to the backup space, and then the memory detection program is reloaded and started in the backup space to detect the remaining memory, and finally the migrated data is restored to the original position, thereby completing the entire memory detection process. Therefore, the present application realizes a comprehensive detection of the memory area, can timely discover potential memory errors, prevent security vulnerabilities caused by memory problems, and enhance the security of the embedded operating system.

[0153] In some embodiments, it also includes:

[0154] a division unit, configured to divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space after the first memory detection program passes the detection;

[0155] an execution unit, configured to load and start a second memory detection program in the backup space, and sequentially execute, for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed;

[0156] The third detection unit is used to use the second memory detection program to perform memory detection on the memory space that has not been detected.

[0157] In this way, even in the case of a large amount of used space, the present application can still ensure that the entire used space can be fully detected by dividing the first space, avoiding the problem of being unable to perform comprehensive detection due to insufficient backup space, and improving the versatility and adaptability of the memory detection method.

[0158] Figure 6600 is a schematic structural diagram of a computing device 600 provided in an embodiment of the present application. The computing device can be used as a memory detection device to execute the optional embodiments of the above-mentioned memory detection method. The computing device can be a terminal or a chip or chip system inside the terminal. Figure 6 As shown, the computing device 600 includes: a processor 610 , a memory 620 , and a communication interface 630 .

[0159] It should be understood that Figure 6 The communication interface 630 in the computing device 600 shown may be used to communicate with other devices, and may specifically include one or more transceiver circuits or interface circuits.

[0160] The processor 610 may be connected to a memory 620. The memory 620 may be used to store the program code and data. Therefore, the memory 620 may be a storage unit inside the processor 610, or an external storage unit independent of the processor 610, or a component including a storage unit inside the processor 610 and an external storage unit independent of the processor 610.

[0161] Optionally, the computing device 600 may further include a bus. The memory 620 and the communication interface 630 may be connected to the processor 610 via the bus. The bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 A line without an arrow is used to represent the bus, but this does not mean that there is only one bus or one type of bus.

[0162] It should be understood that in the embodiment of the present application, the processor 610 can adopt a central processing unit (CPU). The processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. Or the processor 610 uses one or more integrated circuits to execute related programs to implement the technical solutions provided in the embodiments of the present application.

[0163] The memory 620 may include a read-only memory and a random access memory, and provides instructions and data to the processor 610. A portion of the processor 610 may also include a nonvolatile random access memory. For example, the processor 610 may also store information on the device type.

[0164] When the computing device 600 is running, the processor 610 executes the computer-executable instructions in the memory 620 to perform any operation step of the above method and any optional embodiment thereof.

[0165] It should be understood that the computing device 600 according to the embodiment of the present application can correspond to the corresponding subjects in the methods according to the embodiments of the present application, and the above-mentioned and other operations and / or functions of each module in the computing device 600 are respectively for implementing the corresponding processes of each method of the present embodiment. For the sake of brevity, they will not be repeated here.

[0166] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. 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] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0168] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0169] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0170] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0171] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0172] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it is used to execute the above method, which includes at least one of the solutions described in the above embodiments.

[0173] The computer storage medium of the embodiment of the present application can adopt any combination of one or more computer-readable media. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples (non-exhaustive lists) of computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing programs, which can be used by instruction execution systems, devices or devices or used in combination with them.

[0174] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0175] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0176] Computer program code for performing the operation of the present application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).

[0177] In addition, the words "first, second, third, etc." or module A, module B, module C and other similar terms in the specification and claims are only used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that the specific order or sequence can be interchanged where permitted so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0178] In the above description, the numbers representing the steps, such as S110, S120, etc., do not necessarily mean that the steps will be executed in this manner. If permitted, the order of the steps can be interchanged or they can be executed simultaneously.

[0179] The term "comprising" as used in the description and claims should not be interpreted as being limited to what is listed thereafter; it does not exclude other elements or steps. Therefore, it should be interpreted as specifying the presence of the features, integers, steps or components mentioned, but does not exclude the presence or addition of one or more other features, integers, steps or components and groups thereof. Therefore, the expression "a device comprising means A and B" should not be limited to a device consisting of components A and B only.

[0180] References to "one embodiment" or "an embodiment" in this specification mean that a particular feature, structure, or characteristic described in conjunction with the embodiment is included in at least one embodiment of the present application. Therefore, the phrases "in one embodiment" or "in an embodiment" appearing in various places in this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. In addition, in one or more embodiments, the particular features, structures, or characteristics can be combined in any appropriate manner, as would be apparent to one of ordinary skill in the art from this disclosure.

[0181] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may also include more other equivalent embodiments without departing from the concept of the present application, all of which belong to the scope of protection of the present application.

Claims

1. A memory detection method during the operation of an embedded operating system, characterized in that: The method comprises: In response to the start of the memory detection method, an exception handling program is entered to obtain memory management authority; Acquire current memory allocation information, including a first space and current free space, where the first space is currently used space; Allocating a backup space from the current free space of the memory according to the size of the first space; Loading and starting a first memory detection program in the current free space of the memory after the backup space is allocated, and using the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started; After the first memory detection program passes the detection, if it is determined that the backup space is larger than the first space, the data in the first space is migrated to the backup space; Loading and starting a second memory detection program in the backup space, and using the second memory detection program to perform a memory detection on the memory space that has not been detected; After the second memory detection program is completed, the migrated data in the backup space is restored to the first space.

2. The memory detection method according to claim 1, characterized in that: Also includes: After the first memory detection program passes the detection, when it is determined that the backup space is smaller than the first space, the first space is divided into a plurality of first subspaces; Loading and starting a second memory detection program in the backup space, and sequentially executing the following steps for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed; The second memory detection program is used to perform memory detection on the memory space that has not been detected.

3. The memory detection method according to claim 1, characterized in that: Also includes: When entering the exception handling program, recording the current program running pointer of the embedded operating system; After all the spaces of the memory have been detected and the data in the first space has been restored, the exception handling program is exited, and the operation of the corresponding program is restored according to the recorded program operation pointer.

4. The memory detection method according to claim 1, characterized in that: The free space of the memory includes user state free space and kernel state free space; The allocating a backup space from the current free space of the memory includes: Allocate the backup space from the user state free space; Or, the backup space is allocated from the kernel state free space.

5. The memory detection method according to claim 1 or 2, characterized in that: Before the memory detection method is started, the method further includes: Obtaining the current running state of the embedded operating system; When the running state corresponds to having idle resources, the memory detection method is started.

6. The memory detection method according to claim 1, characterized in that: The detection of the memory includes: Read and write memory space; If the read data is consistent with the written data, it is determined that the memory space has passed the detection; If the read data is inconsistent with the written data, it is determined that the memory space test has failed.

7. A memory detection device during the operation of an embedded operating system, characterized in that: The device comprises: A response unit, used to respond to the start of the memory detection method and enter the exception handling program to obtain memory management authority; An acquisition unit, used to acquire allocation information of current memory, including a first space and current free space, wherein the first space is a currently used space; an allocation unit, configured to allocate a backup space from the current free space of the memory according to the size of the first space; A first detection unit is used to load and start a first memory detection program in the current free space of the memory after the backup space is allocated, and use the first memory detection program to perform a memory detection on the backup space, or on the backup space and the current free space of the memory after the first memory detection program is started; a migration unit, configured to migrate data in the first space to the backup space when it is determined that the backup space is larger than the first space after the first memory detection program passes the detection; A second detection unit, configured to load and start a second memory detection program in the backup space, and use the second memory detection program to perform a memory detection on the memory space that has not been detected; The recovery unit is used to recover the migrated data in the backup space to the first space after the detection of the second memory detection program is completed.

8. The memory detection device according to claim 7, characterized in that: Also includes: a division unit, configured to divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space after the first memory detection program passes the detection; an execution unit, configured to load and start a second memory detection program in the backup space, and sequentially execute, for the multiple first subspaces: migrating data in a current first subspace to the backup space, performing a memory detection on the current first subspace using the second memory detection program, and restoring the migrated data in the backup space to the current first subspace after the detection is completed; The third detection unit is used to use the second memory detection program to perform memory detection on the memory space that has not been detected.

9. A computing device, characterized in that include: processor, and A memory having program instructions stored thereon, wherein when the program instructions are executed by the processor, the processor executes the memory detection method according to any one of claims 1 to 6.

10. A storage medium, characterized in that: Program instructions are stored thereon, and when the program instructions are executed by a computer, the computer executes the memory detection method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • RAM detection method and system

    CN105788646A

  • A memory diagnostic method and apparatus

    CN109086162A

  • Memory detection model training method and memory detection method and device

    CN110598802A

  • Computer memory dynamic test system

    CN114328134A

  • Memory testing method and device, readable storage medium and electronic equipment

    CN114765051A