A memory detection method and device during operation of an embedded operating system
By entering the exception handler in the embedded operating system and using the two-step memory detection mechanism to detect and migrate data in the backup space, the problem of the existing technology that cannot perform full-area memory self-detection is solved, comprehensive detection of the memory area is achieved, and the security and stability of the system are enhanced.
Patent Information
- Application Number
- CN202411588897.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-11-08
AI Technical Summary
Existing embedded operating systems are unable to perform full-area memory self-checks on the kernel space during operation, resulting in potential memory errors not being discovered in a timely manner, affecting system stability and security.
By entering the exception handler to obtain memory management permissions, the system uses a two-step memory detection mechanism to first detect and migrate data in the backup space, then perform a full-area memory detection in the backup space, and finally restore the data to its original location to ensure that all memory areas are detected.
It achieves comprehensive detection of memory areas, timely discovers potential errors, enhances the security and stability of embedded operating systems, ensures that the system can be seamlessly restored to its previous state after detection, and improves user experience.
Smart Images

Figure CN119512838B_ABST
Abstract
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 supporting multiple processes and operating in highly security-critical environments (such as defense systems, rail transit control systems, and nuclear power facility monitoring systems), memory stability and reliability are the cornerstones of ensuring the safe operation of the entire system. As a core resource for operating systems and their applications, memory status directly impacts system stability and reliability. Any memory failure can lead to system anomalies, data loss, or even catastrophic consequences. Therefore, comprehensive memory testing is a key measure to ensure stable system operation.
[0003] Currently, after booting, embedded operating systems only check limited memory areas, primarily due to limitations imposed by the MMU (Memory Management Unit) or MPU (Memory Protection Unit). These hardware protection mechanisms effectively isolate access between user and kernel memory, ensuring system security. However, they also prevent user-mode memory checking programs from directly accessing kernel-mode memory physical addresses. This means that existing memory checking mechanisms often fail to cover all critical memory areas, particularly those protected kernel-mode memory.
[0004] Specifically, such as Figure 1 Figure 2 shows the memory layout of an embedded operating system. It is primarily divided into two parts: user space and kernel space. The user space includes multiple processes (process 1 through process n) and user free space. Each process has its own independent memory space for storing program code, data, stacks, and other information. The user free space is the memory area not allocated to any process. The kernel space consists of kernel used space and kernel free space. Kernel used space refers to the memory area already occupied by the operating system kernel, while kernel free space is the memory area not yet used by the kernel.
[0005] During the operation of an embedded operating system, since kernel-mode memory is already in use, memory checks cannot be performed on the kernel-mode used space and code segment. This is because memory checks require modifying data in memory. Writing to the code segment and kernel-mode used space could cause the entire embedded operating system to abnormally exit. Furthermore, these areas are typically protected by the kernel-mode MMU or MPU, making memory read and write operations impossible for self-test programs. 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-test during operation.
[0007] To achieve the above-mentioned object, the present application provides, in a first aspect, a memory detection method during the operation of an embedded operating system, the method comprising:
[0008] In response to the start of the memory detection method, entering the exception handling program to obtain memory management authority;
[0009] Obtaining 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. 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 its original location, 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.
[0016] As a possible implementation of the first aspect, the following also is included:
[0017] After the first memory detection program passes the detection, if 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 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 complete;
[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 when the first space is large, the present application can still ensure that the entire first space can be fully tested by dividing the first space, avoiding the problem of being unable to perform comprehensive testing 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 is included:
[0022] When entering the exception handling program, recording the current program running pointer of the embedded operating system;
[0023] After all 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 running of the corresponding program is restored according to the recorded program running pointer.
[0024] Recording the current program pointer ensures that the system can accurately restore to its pre-test state after the memory test is complete. This means that after the memory test, by restoring the recorded program pointer, the system can seamlessly resume previous tasks, ensuring task continuity. Furthermore, users will hardly notice the change in system state while the memory test is running, as the system can be restored to its previous state immediately after the test, improving the user experience.
[0025] As a possible implementation of the first aspect, the free space of the memory includes user-mode free space and kernel-mode 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-mode free space;
[0028] Alternatively, the backup space is allocated from the kernel state free space.
[0029] In this way, this 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 of the first aspect, before starting the memory detection method, 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, the memory detection method is ensured to be started at the appropriate time, avoiding 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.
[0034] As a possible implementation 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 test;
[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 easy 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, configured to respond to the start of the memory detection method and enter an exception handling program to obtain memory management authority;
[0041] an acquiring unit, configured to acquire current memory allocation information, including a first space and current free space, wherein the first space is currently used space;
[0042] an allocating 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, configured 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 if it is determined that the backup space is larger than the first space after the first memory detection program passes 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 configured to recover the migrated data in the backup space to the first space after the second memory detection program completes detection.
[0047] As a possible implementation of the second aspect, the apparatus further includes:
[0048] a partitioning unit, configured to, after the first memory detection program passes detection, divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space;
[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, the following operations: 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 complete;
[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 is caused to execute 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 having program instructions stored thereon, and 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 This is a schematic diagram of a memory partition diagram of an embedded operating system provided by this application;
[0056] Figure 2 This 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 This 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 This is a structural 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 sizes and shapes of the blocks in the above structural diagrams are for reference only and should not constitute an exclusive interpretation of the embodiments of the present invention. The relative positions and inclusion relationships between the blocks presented in the structural diagrams are merely schematic representations of the structural relationships between the blocks and do not limit the physical connection methods of the embodiments of the present invention. DETAILED DESCRIPTION
[0062] The technical solution provided by this 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 this application are mainly for illustrating possible implementation methods of the technical solution of this application and should not be interpreted as the sole limitation of the technical solution of this application. It is known to those skilled in the art that with the evolution of the system structure and the emergence of new business scenarios, the technical solution provided by this application is also applicable to similar technical problems.
[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art in the art of this application. In the event 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 this application.
[0064] The embodiment of the present application 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 the exception handling program to obtain memory management authority;
[0066] The purpose of the embedded operating system entering the exception handling program is to obtain memory management authority and record the current program running pointer of the embedded operating system (see the detailed description below).
[0067] S202: Acquire current memory allocation information, including a first space and current free space, where the first space is currently used space;
[0068] S203. Allocate 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, ensuring that the backup space has enough space to store data that needs to be backed up.
[0070] S204: 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;
[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: 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;
[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's worth noting that the first and second memory test programs are actually identical; they're only loaded twice during the memory test. Because read and write operations during the memory test overwrite existing data, whether the first memory test program exits normally or not has no impact on the test results of the second memory test program. This is because when the second memory test program begins testing the same portion of memory, it also performs read and write tests, which causes the data in that portion of memory to be overwritten again.
[0075] Preferably, when the second memory detection program is loaded, the first memory detection program is exited. In other words, 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. 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 its original location, 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.
[0077] In some embodiments, it further includes:
[0078] After the first memory detection program passes the detection, if 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 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 complete;
[0080] The second memory detection program is used to perform memory detection on the memory space that has not been detected.
[0081] The following will illustrate this through 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 of 512KB, the first space is divided into multiple first subspaces. Specifically, assuming that 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 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, and the second memory detection program is activated to detect the second subspace. After the detection is complete, the data in the backup space is restored to the second subspace. Furthermore, the process for the third and fourth first subspaces is the same as step 3 above, and any repetitions are omitted.
[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] From steps 1-5, it can be seen that in this 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 when the first space is large, the present application can still ensure that the entire first space can be fully tested by dividing the first space, avoiding the problem of being unable to perform comprehensive testing due to insufficient backup space, and improving the versatility and adaptability of the memory detection method.
[0092] In some embodiments, it further includes:
[0093] When entering the exception handling program, recording the current program running pointer of the embedded operating system;
[0094] After all 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 running of the corresponding program is restored according to the recorded program running pointer.
[0095] For example, after the embedded operating system enters the exception handler, the system saves the current program counter value, such as PC = 0x40005678, indicating that the next instruction to be executed is located at memory address 0x40005678. Furthermore, when the embedded operating system exits the exception handler, the system restores the previously saved program counter value PC = 0x40005678 to the corresponding register, meaning that the next instruction to be executed will be the one at address 0x40005678.
[0096] Recording the current program pointer ensures that the system can accurately restore to its pre-test state after the memory test is complete. This means that after the memory test, by restoring the recorded program pointer, the system can seamlessly resume previous tasks, ensuring task continuity. Furthermore, users will hardly notice the change in system state while the memory test is running, as the system can be restored to its previous state immediately after the test, improving the user experience.
[0097] In some embodiments, the free space of the memory includes user-mode free space and kernel-mode 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-mode free space;
[0100] Alternatively, 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] For example, 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, this 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, the method further 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 system's current task load is low, CPU usage is not high, and there is sufficient 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] Based on real-time monitoring data, the system intelligently chooses to initiate the memory check method during periods of low task load and low CPU usage. In other words, the memory check method isn't executed at a fixed time; instead, it's determined based on the system's current state. This ensures that the memory check method initiates at the appropriate time, avoiding resource occupancy during busy system conditions. This ensures that system resources are utilized effectively, rather than adding additional burden during busy periods, minimizing any impact on system performance.
[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 test;
[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 easy to implement, and reducing the complexity of the memory detection program.
[0115] In order to more clearly illustrate the above method, this application provides a specific embodiment.
[0116] like Figure 3 As shown, this embodiment is described by taking allocating backup space from user-mode free space as an example.
[0117] The embedded operating system includes kernel-mode space and user-mode space. The kernel-mode space includes kernel-used space and kernel-free space, and the user-mode space includes user-used space and user-free space.
[0118] The code segment stores the program's machine code, or executable instructions. Both user-mode applications and kernel-mode operating system code have their own code segment. In other words, the code segment resides in kernel-mode space or 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 has idle resources, the memory detection method is started, the embedded operating system enters the exception handling program, obtains the memory management authority, and 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 current memory allocation information, including a first space and current free space, where the first space is 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 further 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: 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;
[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 test 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 refers to the space in the operating system excluding the backup space.
[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 test process will overwrite the original data, whether the first memory test program exits normally or not will not affect the test results of the second memory test program. This is because when the second memory test program begins to test the same part of memory, it will also perform read and write tests, which will cause the data in the same part of memory to be overwritten again.
[0136] Preferably, when the second memory detection program is loaded, the first memory detection program is exited. In other words, 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 execution of the corresponding program according to the program execution pointer recorded in step 1;
[0139] Step 9: Based on the results of the memory test, the system generates a report on the current memory status and corresponding measures to maintain the health of the memory.
[0140] The corresponding measures include but are not limited to:
[0141] Bad memory block marking: The system marks detected bad blocks in the memory management table to prevent future use of these bad blocks. For example, marking can be done by setting a specific flag bit.
[0142] Application migration: If a problem is detected in a memory area being used by a program, 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 the administrator or user to take further action, such as replacing hardware or performing more detailed diagnosis.
[0144] Figure 5 1 is a structural diagram of a memory detection device during the operation of an embedded operating system provided by 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, the device comprising:
[0145] A response unit 501 is configured to respond to the start of the memory detection method and enter an exception handling program to obtain memory management authority;
[0146] An acquiring unit 502 is configured to acquire current memory allocation information, including a first space and current free space, where the first space is currently used space;
[0147] an allocating unit 503, configured to allocate a backup space from the current free space of the memory according to the size of the first space;
[0148] A first detection unit 504 is configured 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 is configured to migrate the data in the first space to the backup space if 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 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;
[0151] The recovery unit 507 is configured to recover the migrated data in the backup space to the first space after the second memory detection program completes detection.
[0152] In this way, the embedded operating system can obtain higher memory management permissions by entering the exception handler, bypassing the protection mechanism of the MMU or MPU, and thus being able 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 location, 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 further includes:
[0154] a partitioning unit, configured to, after the first memory detection program passes detection, divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space;
[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, the following operations: 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 complete;
[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 when faced with a large amount of used space, the present application can still ensure that the entire used space can be fully tested by dividing the first space, avoiding the problem of being unable to conduct a comprehensive test 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 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 within the processor 610, an external storage unit independent of the processor 610, or a component including both a storage unit within 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 gate 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. Alternatively, the processor 610 adopts one or more integrated circuits to execute relevant programs to implement the technical solutions provided in the embodiment 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 non-volatile random access memory. For example, the processor 610 may also store information about 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 subject in executing the method according to each embodiment 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 skilled 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 beyond the scope of this application.
[0167] Those skilled in the art will 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 this 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 merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, 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 separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[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, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method 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 having a computer program stored thereon. When the program is executed by a processor, the program 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 components, or any combination thereof.More specific examples (non-exhaustive list) of computer-readable storage media include: electrical connection 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-ROMs), optical storage devices, magnetic storage devices, or any suitable combination thereof.In this document, computer-readable storage media can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0174] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0175] Program code embodied on a 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] The computer program code for performing the operations 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" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving 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., through the Internet using an Internet service provider).
[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 must 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 specification and claims should not be construed as limiting to what is listed thereafter; it does not exclude other elements or steps. Thus, it should be interpreted as specifying the presence of the features, integers, steps, or components mentioned, but not excluding the presence or addition of one or more other features, integers, steps, or components, or groups thereof. Thus, the expression "a device comprising means A and B" should not be limited to a device consisting solely of components A and B.
[0180] References in this specification to "one embodiment" or "an embodiment" mean that a particular feature, structure, or characteristic described in connection 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 throughout this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. Furthermore, in one or more embodiments, the particular features, structures, or characteristics can be combined in any suitable 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 employed. 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 has been described in more detail through the above embodiments, the present application is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of protection of the present application, all of which fall within 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, entering the exception handling program to obtain memory management authority; Obtaining 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, wherein: Also includes: After the first memory detection program passes the detection, if 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 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 complete; 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, wherein: Also includes: When entering the exception handling program, recording the current program running pointer of the embedded operating system; After all 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 running of the corresponding program is restored according to the recorded program running pointer.
4. The memory detection method according to claim 1, wherein: 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-mode free space; Alternatively, 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, wherein: 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 test; 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, configured to respond to the start of the memory detection method and enter an exception handling program to obtain memory management authority; an acquiring unit, configured to acquire current memory allocation information, including a first space and current free space, wherein the first space is currently used space; an allocating 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, configured 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 if it is determined that the backup space is larger than the first space after the first memory detection program passes 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 configured to recover the migrated data in the backup space to the first space after the second memory detection program completes detection.
8. The memory detection device according to claim 7, wherein: Also includes: a partitioning unit, configured to, after the first memory detection program passes detection, divide the first space into a plurality of first subspaces when it is determined that the backup space is smaller than the first space; 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, the following operations: 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 complete; 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 is caused to execute 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