Stack overflow elimination method based on task stack intelligent computing on a spaceborne computer

By using an intelligent computing method based on the Cortex-M7 core on the spaceborne computer to analyze function call relationships and accurately allocate task stack space, the stack overflow problem on the spaceborne computer was solved, improving system reliability and storage resource utilization.

CN116166464BActive Publication Date: 2026-05-12NANJING UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING UNIV OF SCI & TECH
Filing Date
2023-02-24
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing technologies make it difficult to efficiently determine the size of the task stack space on onboard computers, leading to stack overflow risks and wasted storage resources, as well as complex operations.

Method used

We employ an intelligent task stack calculation method based on the Cortex-M7 core. By analyzing function call relationships using disassemblers, we can intelligently calculate the task stack space size and accurately allocate the task stack size to eliminate stack overflow.

Benefits of technology

It improves the reliability of onboard computer software systems and the utilization rate of storage resources, reduces the risk of stack overflow, and simplifies the operation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116166464B_ABST
    Figure CN116166464B_ABST
Patent Text Reader

Abstract

The application discloses a stack overflow elimination method based on intelligent calculation of a task stack on a spaceborne computer, and is used for solving the program safety problem caused by stack overflow of a spaceborne electronic system, and also improves the utilization rate of spaceborne storage resources because the stack memory can be accurately allocated.The application is based on the instructions of using stack space such as function calling and stack pressing of a Cortex-M7 core and the specific process of function calling in the Cortex-M7 core, and uses a cross-compiler tool chain to disassemble an ELF file to generate a text file, uses C language on a clion platform to track the instruction flow in the disassembled text, analyzes the positioning points of function calling relations, analyzes the required task stack size of each level function by using the recursive thought, and thus the required function stack space of a specified task function is obtained.The application can effectively give all function calling relations of a specified function and the corresponding actually occupied stack space size, is an effective and convenient memory resource optimization auxiliary tool, and will produce good effects in practical application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electronic system security in the aerospace industry, specifically to a stack overflow elimination method based on intelligent computing of the task stack on a spaceborne computer. Background Technology

[0002] The onboard computer is one of the most crucial core systems of a microsatellite, responsible for mission execution, status monitoring, and ensuring stable system operation. Therefore, ensuring the robustness and reliability of the onboard software system is of great significance for guaranteeing the satellite's on-orbit performance. As embedded systems, microsatellites have relatively limited memory space, which becomes particularly strained when running software systems with complex calling relationships.

[0003] Currently, on-board software systems running operating systems allocate a sufficiently large stack space based on experience when creating tasks, and then repeatedly test and observe whether the software is normal. On the one hand, this method means that stack overflow may not be obviously manifested in the function in some cases, so the risk of stack overflow still exists; on the other hand, it will cause a waste of on-board storage resources.

[0004] The article "A Method for Setting the Maximum Stack Space of an Embedded System" uses a specific value to fill the stack space, then runs the software system, and finally observes the changes of the specific value in the stack space to determine the actual usage of the stack space. However, this method sometimes does not rewrite the values ​​in the allocated stack memory, resulting in inaccurate results and complex operation.

[0005] In the "Stack Space Statistics Method, Device and Medium", the process involves running any function of a software program to obtain the value of the processor's SP register; comparing the SP pointer, including comparing the SP register value with the stack space boundary and the dynamic variable at the top of the stack, and providing stack space usage information and updating the dynamic variable at the top of the stack based on the comparison results; compiling the software program to obtain the corresponding PUSH instruction, and adding an instruction to the PUSH instruction to perform the SP pointer comparison. This method requires repeating the above steps to obtain the maximum stack space required for the software program to run, making the operation relatively complex. Summary of the Invention

[0006] The purpose of this invention is to provide a stack overflow elimination method based on intelligent task stack calculation on a spaceborne computer. Based on the Cortex-M7 core, it uses the analysis of function call relationships to intelligently calculate the size of the task stack space to eliminate stack overflow, thereby improving the reliability of the spaceborne software system. At the same time, by accurately allocating the task stack size, it improves the utilization rate of spaceborne storage resources.

[0007] To achieve the objectives outlined above, the technical solution adopted by this invention is as follows:

[0008] A stack overflow elimination method based on task stack intelligent computing on a spaceborne computer, assuming a certain task... i / function Func i The maximum task stack space required at runtime is ST_Size_Max(1), characterized by the following specific steps:

[0009] Step 1: Obtain the assembly text file from the executable object file on the onboard computer using a disassembler.

[0010] Step 2: Search for the offset position of the specified task function in the obtained assembly text file, take this offset position as the starting position of the specified task function body, and treat the task function as a level 1 function.

[0011] Step 3: Parse each assembly instruction from this starting position.

[0012] Step 4: If the instruction is in the form of "subsp,size", it means that it is a stack framing instruction. This means that a new function stack of size size is created in this instruction to prepare for the subsequent call of subfunctions. Therefore, the stack space required for this framing needs to be added to the stack space required for the specified task / function.

[0013] Step 5: If the instruction is in the form of "push{register1,register2,…}", it means that it is a push instruction, which means that register data is stored in the stack space at this instruction. Therefore, the stack space required for this push is added to the stack space required by the specified task / function.

[0014] Step 6: If it is a subfunction call instruction, return to step 3 with the subfunction as the specified function, and use the subfunction as the parsed object and the subfunction body as the parsing start position to iteratively calculate the function stack space size ST_Size(i+1) required for the (i+1)th level function.

[0015] Step 7: If it is a function pointer call instruction, backtrack the instruction, find the offset position of the function pointed to by the function pointer in the assembly text file, repeat step 3 with this function as the specified function, and use this sub-function as the parsing object, with the sub-function body as the parsing start position, iteratively calculate the function stack space size ST_Size(i+1) required for the next level function.

[0016] Step 8: When the parsing of a function body at level i+1 ends, if ST_Size(i+1) is greater than the maximum task stack space required by the sub-function called in level i+1.

[0017] Step 9: The formula for calculating the stack space required by a function at level i is as follows:

[0018] ST_Size(i)←ST_Size(i)+ST_Size_Max(i+1)

[0019] Where ST_Size_Max(i+1) is the maximum task stack space required by each sub-function called in level i+1, and ST_Size(i) is the task stack space required by the currently parsed function.

[0020] Step 10: Repeat steps 3 to 9 until the specified task function body ends, and obtain ST_Size(1), which is the stack space size of the specified task.

[0021] Compared with the prior art, the significant advantages of this invention are:

[0022] (1) The results can be determined once after the program is compiled, without the need for repeated testing, which improves the efficiency of calculation and the convenience of actual operation.

[0023] (2) By directly specifying a suitable task stack space during task creation, there is no need to specify a large amount of storage space for testing, which saves storage resources on the onboard computer to a certain extent.

[0024] (3) While ensuring ease of operation, this invention improves the utilization rate of storage resources on the onboard computer and greatly reduces the risk of stack overflow during program execution. Attached Figure Description

[0025] Figure 1 This is a view of the stack changes when function P calls Q.

[0026] Figure 2 This is a flowchart of the stack overflow elimination method based on intelligent computing of the task stack on the onboard computer of the present invention. Detailed Implementation

[0027] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0028] Combination Figure 1 and Figure 2 A stack overflow elimination method based on task stack intelligent computing on a spaceborne computer, assuming a certain task... i / function Func i The maximum task stack space required at runtime is ST_Size_Max(1), and the implementation steps are as follows:

[0029] Step 1: Obtain the assembly text file from the executable object file on the onboard computer using a disassembler.

[0030] Step 2: Search for the offset position of the specified task function in the assembly text file obtained in Step 1, take this offset position as the starting position of the specified task function body, and treat the task function as a level 1 function.

[0031] Step 3: Parse each assembly instruction from this starting position.

[0032] Step 4: If the instruction is in the form of "subsp,size", it indicates a stack framing instruction. This means that a new function stack of size size is created in this instruction to prepare for subsequent subfunction calls. Therefore, the stack space required for this framing needs to be added to the stack space required for the specified task / function. The calculation method is as follows:

[0033] ST_Size(i)←ST_Size(i)+FS_Size

[0034] Where ST_Size(i) is the task stack space required for the i-th level task / function, and FS_Size is the task stack space required for framing in the i-th level function.

[0035] Step 5: If the instruction is in the form of "push{register1,register2,…}", it indicates a push instruction, meaning that register data is being stored on the stack at this instruction. Therefore, the stack space required for this push is added to the total stack space required for the specified task / function. The calculation method is as follows:

[0036] ST_Size(i)←ST_Size(i)+PS_Size

[0037] Where ST_Size(i) is the task stack space required for the i-th level task / function, and PS_Size is the task stack space required for pushing tasks onto the stack in the i-th level function.

[0038] Step 6: If it is a subfunction call instruction, return to step 3 with the subfunction as the specified function, and use the subfunction as the parsed object and the subfunction body as the parsing start position to iteratively calculate the function stack space size ST_Size(i+1) required for the (i+1)th level function.

[0039] Step 7: If it is a function pointer call instruction, backtrack the instruction, find the offset position of the function pointed to by the function pointer in the assembly text file, repeat step 3 with this function as the specified function, and use this sub-function as the parsing object, with the sub-function body as the parsing start position, iteratively calculate the function stack space size ST_Size(i+1) required for the next level function.

[0040] Step 8: When the parsing of a function body at level i+1 ends, if ST_Size(i+1) is greater than the maximum task stack space required by the called sub-function at level i+1, the calculation formula is as follows:

[0041] ST_Size_Maxi+1=ST_Size(i+1)

[0042] Where ST_Size_Max(i+1) is the maximum task stack space required by each sub-function called in level i+1 (initially 0), and ST_Size(i+1) is the task stack space required by the currently parsed function.

[0043] Step 9: The formula for calculating the stack space required by a function at level i is as follows:

[0044] ST_Size(i)←ST_Size(i)+ST_Size_Max(i+1)

[0045] Where ST_Size_Max(i+1) is the maximum task stack space required by each sub-function called in level i+1, and ST_Size(i) is the task stack space required by the currently parsed function.

[0046] Step 10: Iterate through steps 3 to 9 until the specified task function body ends, and obtain ST_Size(1), which is the stack space size of the specified task.

[0047] This invention proposes a method for eliminating stack overflows on a spaceborne computer, which can be implemented through embedded programs. Using cross-compilation tools, embedded programs written on a PC are processed through preprocessing, compilation, assembly, and linking into machine instructions that can run on the spaceborne computer. Then, a programmer writes these instructions into the spaceborne computer's internal storage device, ready to run upon power-up. The assembly process converts a preprocessed and compiled source file into machine language code, resulting in a relocatable object file. Each .c type source file in the embedded program undergoes this process, yielding multiple relocatable object files. These relocatable object files are linked to obtain machine language code that can be directly run by the spaceborne computer—the executable object file. In fact, neither the relocatable object file nor the executable object file is a directly displayable text file; rather, it is a non-displayable binary file. Therefore, to parse the executable object file, a disassembler in the cross-compilation toolchain is needed to convert it into a directly displayable text file. The C++ program then parses the task stack instructions based on the text file converted from the executable object file and ARM assembly instructions.

[0048] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for eliminating stack overflow based on intelligent computing of task stack on a spaceborne computer, assuming a certain task... i / function Func i The maximum task stack space required at runtime is ST_Size_Max(1), characterized in that... The specific steps are as follows: Step 1: Obtain the assembly text file from the executable object file on the onboard computer using a disassembler; Step 2: Search for the offset position of the specified task function in the obtained assembly text file, take this offset position as the starting position of the specified task function body, and treat the task function as a level 1 function; Step 3: Parse each assembly instruction from this starting position; Step 4: If the instruction is in the form of "sub sp, size", it means that it is a stack framing instruction. This means that a new function stack of size size is created in this instruction to prepare for the subsequent sub-function call. Therefore, the stack space required for this framing needs to be added to the stack space required for the specified task / function. Step 5: If the instruction is in the form of "push {register1, register2, …}", it means that it is a push instruction, which means that register data is stored in the stack space at this instruction. Therefore, the stack space required for this push is added to the stack space required by the specified task / function. Step 6: If it is a subfunction call instruction, return to step 3 with the subfunction as the specified function, and use the subfunction as the parsed object and the subfunction body as the parsing start position to iteratively calculate the function stack space required for the (i+1)th level function ST_Size(i+1); Step 7: If it is a function pointer call instruction, backtrack the instruction, find the offset position of the function pointed to by the function pointer in the assembly text file, repeat step 3 with the function as the specified function, and use the sub-function as the parsing object, with the sub-function body as the parsing start position, iteratively calculate the function stack space size ST_Size(i+1) required for the next level function; Step 8: When the parsing of a function body at level i+1 ends, if ST_Size(i+1) is greater than the maximum task stack space required by the called sub-function at level i+1, the calculation formula is as follows: ST_Size(i+1); Where ST_Size_Max(i+1) is the maximum task stack space required by each sub-function called in level i+1, and ST_Size(i+1) is the task stack space required by the currently parsed level i+1 function; Step 9: The formula for calculating the stack space required by a function at level i is as follows: ; Where ST_Size_Max(i+1) is the maximum task stack space required by each sub-function called in level i+1, and ST_Size(i) is the task stack space required by the currently parsed function; Step 10: Repeat steps 3 to 9 until the specified task function body ends, and obtain ST_Size(1), which is the stack space size of the specified task.

2. The stack overflow elimination method based on task stack intelligent computing on a spaceborne computer according to claim 1, characterized in that, In step 4, the stack space required for this frame assembly is added to the stack space required for the specified task / function. The calculation method is as follows: ; in, _Size(i) is the task stack space required for the i-th level task / function, and FS_Size is the task stack space required for framing in the i-th level function.

3. The stack overflow elimination method based on task stack intelligent computing on a spaceborne computer according to claim 1, characterized in that, In step 5, the stack space required for this push is added to the stack space required for the specified task / function. The calculation method is as follows: ; in, _Size(i) is the task stack space required for the i-th level task / function, and PS_Size is the task stack space required for pushing tasks onto the stack in the i-th level function.