Stack protection method and device for embedded real-time operating system and storage medium
By configuring an inaccessible region at the end of the target task stack in the embedded real-time operating system and using the memory protection unit hardware mechanism to restrict access, the system crashes and security vulnerabilities caused by stack overflows are resolved, thereby improving the system's reliability and security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGSHA HAIGE BEIDOU INFORMATION TECH CO LTD
- Filing Date
- 2026-03-26
- Publication Date
- 2026-04-21
AI Technical Summary
Existing stack protection technologies in embedded real-time operating systems suffer from high response latency, large resource consumption, and an inability to dynamically adapt to the stack space requirements of different tasks, leading to system crashes, memory pollution, and security vulnerabilities.
By configuring an inaccessible region at the end of the target task stack in the memory protection unit, access is restricted using hardware mechanisms, the stack protection space is dynamically configured, the interrupt stack space is defined independently, and the memory protection unit is used to trigger hardware exceptions to prevent illegal access.
It achieves low-latency, high-efficiency stack protection, improves the reliability and security of embedded real-time operating systems, avoids system crashes and security vulnerabilities, and adapts to the stack space requirements of different tasks.
Smart Images

Figure CN121902129A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and specifically to a stack protection method, apparatus, and storage medium for an embedded real-time operating system. Background Technology
[0002] With the rapid development of satellite navigation technology, satellite navigation has become the most important navigation and positioning method today. Therefore, satellite navigation system software has increasingly higher requirements for real-time performance, stability, and reliability. The core advantage of embedded operating systems is real-time multi-task scheduling, but this characteristic also makes the use of the stack more complex. The stack, as the core memory area for task execution, is used to store local variables, function call contexts, and interrupt scenarios. Due to the limited hardware resources of embedded devices, the task stack of real-time operating systems typically uses a static allocation method. When the task stack space overflows, it will overwrite adjacent memory areas (such as other task stacks and kernel data areas), leading to system crashes, scheduling anomalies, and seriously affecting system reliability and security. Existing stack protection technologies mostly rely on software detection (such as stack pointer boundary checks), which suffers from high response latency and high system resource consumption. Some hardware-level protection schemes are not optimized for the task switching characteristics of real-time operating systems and cannot dynamically adapt to the stack space requirements of different tasks. Therefore, a more efficient and dynamic stack protection scheme is needed. Summary of the Invention
[0003] The purpose of this application is to provide a stack protection method, apparatus, and storage medium for an embedded real-time operating system.
[0004] To achieve the above objectives, the first aspect of this application provides a stack protection method for an embedded real-time operating system, comprising: When switching to the target task using the task switching function, the stack protection configuration function is called; Configure the inaccessible region at the end of the target task stack corresponding to the target task in the memory protection unit using the stack protection configuration function; Once the inaccessible zone is configured, execute the target task.
[0005] In this embodiment of the application, when the target task is determined by executing the task switching function, calling the stack protection configuration function includes: traversing multiple ready tasks through the task switching function to determine the current highest priority ready task as the target task; and calling the stack protection configuration function when the target task is determined.
[0006] In this embodiment of the application, configuring an inaccessible region at the end of the target task stack corresponding to the target task in the memory protection unit through the stack protection configuration function includes: obtaining the protection unit region table entry of the target task stack through the stack protection configuration function; configuring the protection unit region table entry according to the protection unit start address, protection unit end address, protection unit size and region access permission of the target task stack, wherein the region access permission is inaccessible; and writing the configured protection unit region table entry into the designated area of the memory protection unit to complete the configuration of the inaccessible region.
[0007] In this embodiment of the application, configuring the protection unit area table entry according to the protection zone start address, protection zone end address, protection zone size and area access permissions of the target task stack includes: aligning the protection zone start address according to the first preset alignment requirements to obtain the aligned address; configuring the protection unit area table entry according to the aligned address, protection zone end address, protection zone size and area access permissions.
[0008] In this embodiment of the application, the stack protection method further includes: defining the interrupt stack space of the operating system during the operating system initialization phase, wherein the interrupt stack space and the task stack space are independent of each other.
[0009] In this embodiment of the application, defining the interrupt stack space of the operating system includes: defining the interrupt stack space based on a second preset alignment requirement and a preset interrupt stack size.
[0010] In this embodiment of the application, defining the interrupt stack space based on the second preset alignment requirement and the preset interrupt stack size includes: determining the starting address of the interrupt stack space according to the second preset alignment requirement; determining the termination address to be aligned according to the sum of the starting address and the preset interrupt stack size; and determining the termination address of the interrupt stack space according to the preset alignment requirement and the termination address to be aligned.
[0011] In this embodiment of the application, when an inaccessible area is accessed, a hardware exception is triggered through the memory protection unit to prevent access.
[0012] A second aspect of this application provides a stack protection device for an embedded real-time operating system, comprising: a processor configured to execute a stack protection method for an embedded real-time operating system according to a first aspect of this application.
[0013] A third aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, cause the processor to execute the stack protection method for an embedded real-time operating system provided in the first aspect of this application.
[0014] Through the above technical solution, the stack protection method for embedded real-time operating systems provided in this application can call the stack protection configuration function during task switching in the real-time operating system. This configures an inaccessible region at the end of the target task's stack as an independent stack protection space for the target task's stack. The hardware mechanism of the memory protection unit restricts access to this inaccessible region. This solves the problems of system crashes, memory pollution, and security vulnerabilities caused by stack overflows in real-time operating systems. It is suitable for real-time operating systems, dynamically configures the stack protection region during task switching, and can adapt to the stack space requirements of different tasks. By configuring the inaccessible region at the end of the target task's stack in the memory protection unit, stack protection can be achieved through the memory protection unit without occupying additional runtime resources or requiring software polling detection. This results in low response latency and improves the reliability and security of the embedded real-time operating system.
[0015] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0016] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings: Figure 1 The illustration shows a schematic flowchart of a stack protection method for an embedded real-time operating system according to an embodiment of this application; Figure 2 The illustration shows a flowchart of another stack protection method for an embedded real-time operating system according to an embodiment of this application; Figure 3 The diagram illustrates the internal structure of a computer device according to an embodiment of this application. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0018] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0019] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0020] The acquisition, transmission, storage, use, and processing of data in this application comply with relevant laws and regulations. Furthermore, it should be noted that certain software, components, models, and other existing industry solutions may be mentioned in the embodiments of this application. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0021] Existing stack protection technologies largely rely on software detection (such as stack pointer boundary checks), which suffers from high response latency and excessive system resource consumption. Some hardware-level protection schemes are not optimized for the task switching characteristics of real-time operating systems and cannot dynamically adapt to the stack space requirements of different tasks. Therefore, existing stack protection technologies cannot meet the stack protection needs under real-time multi-task scheduling in real-time operating systems. Satellite navigation system software, due to its real-time navigation requirements, has significant demands for system real-time performance, stability, and reliability. Based on this, this application proposes a stack protection method for embedded real-time operating systems that can achieve real-time dynamic stack protection functionality.
[0022] Figure 1 The illustration shows a schematic flowchart of a stack protection method for an embedded real-time operating system according to an embodiment of this application. Figure 1 As shown, this application provides a stack protection method for an embedded real-time operating system, which can be executed by the processor of an embedded device employing an ARM architecture and a memory protection unit. This embedded device can be, for example, a vehicle-mounted positioning terminal. The stack protection method for an embedded real-time operating system provided in this application includes: S102. When switching to the target task using the task switching function, call the stack protection configuration function; S104. Configure the inaccessible region at the end of the target task stack corresponding to the target task in the memory protection unit through the stack protection configuration function; S106. If the inaccessible zone configuration is complete, execute the target task.
[0023] The stack protection method for embedded real-time operating systems provided in this application can call a stack protection configuration function during task switching in the real-time operating system. This allocates an inaccessible region at the end of the target task's stack as an independent stack protection space for the target task's stack, utilizing the hardware mechanism of the memory protection unit to restrict access to this inaccessible region. This stack protection method for embedded real-time operating systems can solve the problems of system crashes, memory pollution, and security vulnerabilities caused by stack overflows in real-time operating systems. It is suitable for real-time operating systems, dynamically configuring the stack protection region during task switching, and can adapt to the stack space requirements of different tasks. By configuring the inaccessible region at the end of the target task's stack in the memory protection unit, stack protection can be achieved through the memory protection unit without consuming additional runtime resources or requiring software polling detection. This results in low response latency and improves the reliability and security of the embedded real-time operating system.
[0024] In some embodiments of this application, when an inaccessible region is accessed, a hardware exception is triggered by the memory protection unit to prevent access. If a task stack overflows and accesses an inaccessible region, the memory protection unit will trigger a hardware exception. The system can capture this exception and perform a reset or alarm process to avoid system malfunctions.
[0025] In some embodiments of this application, the stack protection method for an embedded real-time operating system may further include: defining an interrupt stack space of the operating system during the operating system initialization phase, wherein the interrupt stack space and the task stack space are independent of each other.
[0026] Based on the above steps, an independent interrupt stack space can be allocated for the interrupt service routine of the embedded real-time operating system, ensuring its independent partition in memory and avoiding uncontrollable stack consumption problems caused by interrupts and tasks sharing the stack. The interrupt stack space can be used for stack storage and exception handling of the interrupt service routine. Specifically, the interrupt stack space can be defined through the ld linker script.
[0027] In some embodiments of this application, defining the interrupt stack space of the operating system includes: defining the interrupt stack space based on a second preset alignment requirement and a preset interrupt stack size.
[0028] In some embodiments of this application, defining the interrupt stack space based on a second preset alignment requirement and a preset interrupt stack size includes: determining the starting address of the interrupt stack space according to the second preset alignment requirement; determining the termination address to be aligned based on the sum of the starting address and the preset interrupt stack size; and determining the termination address of the interrupt stack space based on the preset alignment requirement and the termination address to be aligned. Based on the above steps, the address of the interrupt stack space can satisfy the preset alignment requirement, which can be determined based on the processor's memory access needs.
[0029] In some embodiments of this application, step S102 may include: traversing multiple ready tasks through a task switching function to determine the current highest priority ready task as the target task; and, if the target task is determined, calling the stack protection configuration function.
[0030] See Figure 2 In some embodiments of this application, step S104 may include: S202. Obtain the protection unit area table entries of the target task stack through the stack protection configuration function; S204. Configure the protection unit area table entries according to the protection zone start address, protection zone end address, protection zone size and area access permissions of the target task stack, wherein the area access permissions are inaccessible. S206. Write the configured protection unit area table entries into the specified area of the memory protection unit to complete the configuration of the inaccessible area.
[0031] Based on the above steps, the protection unit region table entries can be configured according to the start address, end address, size, and access permissions of the protection zone of the target task stack. This determines the memory address and access permissions required by the memory protection unit to protect the target task stack. The configured protection unit region table entries are then written into the designated area of the memory protection unit to complete the configuration of the inaccessible area.
[0032] Specifically, the configured protection unit area table entries can be written to a designated area of the memory protection unit through the hardware configuration interface of the memory protection unit.
[0033] In some embodiments of this application, step S204 may include: aligning the start address of the protected area according to a first preset alignment requirement to obtain an aligned address; configuring the protected unit region table entry according to the aligned address, the end address of the protected area, the size of the protected area, and the region access permissions. Based on the above steps, the aligned address and the end address of the protected area that satisfy the first preset alignment requirement can be used to create a protected unit region table entry. Specifically, the first preset alignment requirement can be set according to the regional alignment requirements of the memory protected unit.
[0034] In some embodiments of this application, the protection unit region table entries may be defined in a system header file. The system header file may define configuration parameters for the memory protection unit, which may include: memory access attributes, stack protection region size, and address alignment parameters representing a first preset alignment requirement and / or a second preset alignment requirement.
[0035] Specifically, the configuration parameters of memory protection units defined in the system header file may include: access attributes (read / write / execute permissions) of different memory regions (such as task stack area, kernel data area, code area); the size of the stack protection region; and the alignment mask and alignment value of the starting address of the memory protection unit region.
[0036] In some embodiments of this application, a stack protection method for an embedded real-time operating system includes: during the operating system initialization phase, determining the starting address of the interrupt stack space according to a second preset alignment requirement; determining the termination address to be aligned according to the sum of the starting address and the preset interrupt stack size; determining the termination address of the interrupt stack space according to the preset alignment requirement and the termination address to be aligned, thereby defining the interrupt stack space of the operating system, wherein the interrupt stack space and the task stack space are independent of each other. When switching to the target task using a task switching function, a stack protection configuration function is called; the protection unit region table entry of the target task stack is obtained through the stack protection configuration function; the starting address of the protection zone is aligned according to the first preset alignment requirement to obtain the aligned address; the protection unit region table entry is configured according to the aligned address, the ending address of the protection zone, the size of the protection zone, and the region access permission, wherein the region access permission is inaccessible; the configured protection unit region table entry is written to a designated area of the memory protection unit to complete the configuration of the inaccessible region; when the inaccessible region is configured, the target task is executed; when the inaccessible region is accessed, a hardware exception is triggered through the memory protection unit to prevent access.
[0037] The stack protection method for embedded real-time operating systems provided in this application defines the interrupt stack space through the linker script, configures the memory access attributes and stack protection area size of the memory protection unit in the header file, and dynamically sets the inaccessible area of the target task stack through a dedicated stack protection configuration function. When the real-time operating system switches tasks, the stack protection configuration function is called, which can allocate an independent stack protection space for each target task to be executed, and restrict access to the inaccessible area using the hardware mechanism of the memory protection unit. The stack protection method for embedded real-time operating systems provided in this application can solve the problems of system crashes, memory pollution, and security vulnerabilities caused by stack overflows in real-time operating systems. However, current software detection schemes have poor real-time performance and high resource consumption. Stack protection implemented using the hardware mechanism of the memory protection unit is achieved only through the linker script and memory management unit configuration, without consuming additional runtime resources or requiring software polling detection, resulting in low response latency. It is suitable for real-time operating systems. Dynamically configuring the stack protection area during task switching can adapt to the stack space requirements of different tasks, improving the reliability and security of embedded systems.
[0038] As an example, an implementation of the stack protection method for an embedded real-time operating system provided in this application may include: defining an interrupt stack space through a linker script, writing an ld linker script to allocate an independent interrupt stack space for the interrupt service routine of the real-time operating system, avoiding the uncontrollable stack consumption problem caused by interrupts and tasks sharing the stack. The starting address and size of the interrupt stack space are statically defined through the linker script to ensure its independent partitioning in memory. Configuration parameters for the memory protection unit are defined in the system header file, including: access attributes (read / write / execute permissions) of different memory regions (such as the task stack area, kernel data area, and code area); the size of the stack protection region; the alignment mask and alignment value of the region starting address of the memory protection unit; and configuring the task stack memory protection unit table entries.
[0039] When a real-time operating system (such as FreeRTOS) performs a task switch, it triggers a call to the stack protection configuration function, configuring the end region of the stack of the currently switched task as an inaccessible area of the memory protection unit, thereby protecting the target task's stack. When the task stack overflows and attempts to access the protected area, the memory protection unit triggers a hardware exception to prevent illegal memory access.
[0040] The stack protection configuration function for configuring the inaccessible protected region of the target task stack is as follows: If the system enables the memory protection unit, the system obtains the memory protection unit region table entry corresponding to the target task stack; sets the start address, end address, region size, and access attributes of the memory protection unit region table entry; and calls the memory protection unit hardware configuration interface to apply the above configuration. When switching tasks, the system automatically configures the stack protection region for the newly running task. If the task stack overflows and accesses the protected region, the memory protection unit will trigger a hardware exception. The system can catch this exception and perform a reset or alarm to avoid system malfunctions.
[0041] In summary, the stack protection method for embedded real-time operating systems provided in this application can define interrupt stack space through the linker script, allocate independent interrupt stack space for the interrupt service routines of the real-time operating system, and ensure its independent partitioning in memory; configure memory protection unit parameters in the header file, including: access attributes (read / write / execute permissions) of different memory regions (such as task stack area, kernel data area, code area); configure inaccessible protected areas of the task stack based on the stack protection configuration function; this method can dynamically activate stack protection during task switching. When the real-time operating system performs task switching, it calls the stack protection area configuration function to configure the end area of the stack of the target task being switched as an inaccessible area, thereby achieving stack protection for that task; when the task stack overflows and accesses the protected area, the memory protection unit triggers a hardware exception to prevent illegal memory access.
[0042] It should be understood that although the steps in the flowcharts of the embodiments of this application are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.
[0043] This application also provides a stack protection device for an embedded real-time operating system, including a processor configured to execute the stack protection method for an embedded real-time operating system provided in this application. Understandably, the memory protection unit is an integral part of the processor, and the processor's processing area is protected through the memory protection unit.
[0044] This application also provides a machine-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform a stack protection method for an embedded real-time operating system according to any one of the embodiments of this application.
[0045] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 3 As shown. The computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements a stack protection method for an embedded real-time operating system. The display screen A04 can be a liquid crystal display (LCD) or an e-ink display. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0046] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0047] In one embodiment, the stack protection device for an embedded real-time operating system provided in this application can be implemented as a computer program, which can be implemented in the form of, for example... Figure 3 The device operates on the computer shown. The computer device's memory can store various program modules that constitute the stack protection device for the embedded real-time operating system. The computer program, composed of the various program modules, causes the processor to execute the steps in the stack protection method for the embedded real-time operating system described in the various embodiments of this application.
[0048] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0049] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0050] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0051] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0052] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0053] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0054] Computer-readable media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0055] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0056] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A stack protection method for an embedded real-time operating system, characterized in that, The stack protection method includes: If the target task is determined by the task switching function, the stack protection configuration function is called. The stack protection configuration function is used to configure an inaccessible region at the end of the target task stack corresponding to the target task in the memory protection unit; Once the inaccessible area is configured, execute the target task.
2. The stack protection method according to claim 1, characterized in that, When the target task is determined by executing the task switching function, the call to the stack protection configuration function includes: The task switching function iterates through multiple ready tasks to determine the current highest priority ready task as the target task. Once the target task is determined, the stack protection configuration function is invoked.
3. The stack protection method according to claim 1, characterized in that, The configuration of the inaccessible region at the end of the target task stack corresponding to the target task in the memory protection unit through the stack protection configuration function includes: The protection unit area table entry of the target task stack is obtained through the stack protection configuration function; Configure the protection unit area table entry according to the protection zone start address, protection zone end address, protection zone size and area access permission of the target task stack, wherein the area access permission is inaccessible; Write the configured protection unit area table entry into the designated area of the memory protection unit to complete the configuration of the inaccessible area.
4. The stack protection method according to claim 3, characterized in that, The step of configuring the protection unit area table entries based on the protection zone start address, protection zone end address, protection zone size, and area access permissions of the target task stack includes: The starting address of the protected area is aligned according to the first preset alignment requirement to obtain the aligned address; Configure the protection unit area table entry based on the aligned address, the protection zone end address, the protection zone size, and the area access permissions.
5. The stack protection method according to claim 1, characterized in that, The stack protection method also includes: During the operating system initialization phase, the interrupt stack space of the operating system is defined, wherein the interrupt stack space is independent of the task stack space.
6. The stack protection method according to claim 5, characterized in that, The definition of the interrupt stack space of the operating system includes: The interrupt stack space is defined based on the second preset alignment requirement and the preset interrupt stack size.
7. The stack protection method according to claim 6, characterized in that, The definition of the interrupt stack space based on the second preset alignment requirement and the preset interrupt stack size includes: The starting address of the interrupt stack space is determined according to the second preset alignment requirement; The termination address to be aligned is determined based on the sum of the starting address and the preset interrupt stack size; The termination address of the interrupt stack space is determined based on the preset alignment requirements and the termination address to be aligned.
8. The stack protection method according to claim 1, characterized in that, If access is attempted in the inaccessible area, a hardware exception is triggered through the memory protection unit to prevent access.
9. A stack protection device for an embedded real-time operating system, characterized in that, include: The processor is configured to execute the stack protection method for an embedded real-time operating system according to any one of claims 1 to 8.
10. A machine-readable storage medium storing instructions thereon, characterized in that, When executed by a processor, this instruction causes the processor to be configured to perform the stack protection method for an embedded real-time operating system according to any one of claims 1 to 8.
Citation Information
Patent Citations
Embedded system stack overflow protection method, electronic equipment and readable storage medium
CN116643907A
Task stack protection method and device, electronic equipment, chip and medium
CN120371390A