Search

CN-116166464-B - Method for eliminating stack overflow based on task stack intelligent calculation on spaceborne computer

CN116166464BCN 116166464 BCN116166464 BCN 116166464BCN-116166464-B

Abstract

The invention discloses a stack overflow eliminating method based on task stack intelligent calculation on a satellite-borne computer, which is used for solving the program safety problem caused by stack overflow of a satellite-borne electronic system, and simultaneously, the utilization rate of satellite-borne storage resources is improved because stack memory can be accurately allocated. According to the method, according to instructions of a Cortex-M7 kernel, such as function call and stack pressing, which use stack space and the specific process of function call in the Cortex-M7 kernel, an ELF file is disassembled by utilizing a cross compiling tool chain to generate a text file, an instruction stream in the disassembled text is tracked by utilizing a C language at a clion platform, positioning points of function call relations are analyzed, and the size of a task stack required by each level of function is analyzed by utilizing a recursion idea, so that the function stack space required by a specified task function is obtained. The invention can effectively give out all function calling relations of the designated functions and the corresponding stack space size occupied in practice, is an effective and convenient auxiliary tool for optimizing the memory resources, and can generate good effect in practical application.

Inventors

  • YU YONGJUN
  • WANG YINGCHAO
  • DENG HANYU

Assignees

  • 南京理工大学

Dates

Publication Date
20260512
Application Date
20230224

Claims (3)

  1. 1. A stack overflow elimination method based on Task stack intelligent computation on a spaceborne computer is provided, and a maximum Task stack space required by a Task i /a function Func i in running is set as ST_Size_Max (1), and is characterized by comprising the following specific steps: step 1, obtaining an assembly text file from an executable object file on a spaceborne computer through a disassembly tool; Searching an offset position of a designated task function in the obtained assembly text file, taking the offset position as a starting position of a designated task function body, and taking the task function as a1 st-stage function; Step 3, analyzing each assembly instruction from the initial position; step 4, if the instruction is in the form of sub sp and size, describing that the instruction is a stack framing instruction, describing that a new function stack with size of size is created in the instruction, and preparing for calling a subfunction below, so that the stack space size required by the framing needs to be accumulated into the task stack space size required by a specified task/function; Step 5, if the instruction is in the form of' push { register1, register2,. & gt}, describing that the instruction is a push instruction, describing that at the instruction, register data are stored into a stack space, and accumulating the stack space size required by the push into the task stack space size required by a specified task/function; step 6, if the instruction is a sub-function call instruction, returning to the step 3 by taking the sub-function as a designated function, taking the sub-function as an object to be analyzed, taking the sub-function body as an analysis starting position, and iteratively calculating the Size ST_Size (i+1) of a function stack space required by the i+1st function; Step 7, if the function pointer call instruction is a function pointer call instruction, backtracking the instruction, finding the offset position of the function pointed by the function pointer in the assembly text file, repeating the step 3 by taking the function as a designated function, taking the sub-function as an object to be analyzed, taking the sub-function body as an analysis starting position, and iteratively calculating the Size ST_Size (i+1) of the function stack space required by the next-stage function; And 8, when the analysis of the certain function body of the (i+1) th level is finished, if the ST_Size (i+1) is larger than the maximum task stack space Size required by the called sub-function of the (i+1) th level, the calculation formula is as follows: ST_Size(i+1); the ST_Size_Max (i+1) is the maximum task stack space Size required by each sub-function called in the ith+1 level, and the ST_Size (i+1) is the task stack space Size required by the current resolved ith+1 level function; Step 9, the calculation formula of the stack space required by the ith grade of certain function is as follows: ; Wherein st_size_max (i+1) is the maximum task stack space Size required by each sub-function called in the i+1 stage, st_size (i) is the task stack space Size required by the function currently being parsed; and 10, repeating the steps 3-9 until the appointed task function body is ended, and obtaining the ST_Size (1), namely the stack space Size of the appointed task.
  2. 2. The method for eliminating stack overflow based on intelligent calculation of task stacks on a spaceborne computer according to claim 1, wherein in step 4, the stack space size required by the framing is accumulated into the task stack space size required by the designated task/function, and the calculation mode is as follows: ; Wherein, the _Size (i) is the task stack space required for the ith task/function, and fs_size is the task stack space required for framing in the ith function.
  3. 3. The method for eliminating stack overflow based on intelligent calculation of task stacks on a spaceborne computer according to claim 1, wherein in step 5, the stack space size required by the stacking is accumulated into the task stack space size required by the appointed task/function, and the calculation mode is as follows: ; Wherein, the The_Size (i) is the task stack space required by the ith task/function, and the PS_Size is the task stack space required by stacking in the ith function.

Description

Method for eliminating stack overflow based on task stack intelligent calculation on spaceborne computer Technical Field The invention relates to the field of electronic system safety in the field of aerospace, in particular to a stack overflow eliminating method based on task stack intelligent calculation on a spaceborne computer. Background The satellite-borne computer is one of the core systems of the micro-nano satellite, is responsible for task implementation and state monitoring of the micro-nano satellite and ensures stable operation of the system, so that the key property and the reliability of the satellite-borne software system are ensured, and the method has important significance for ensuring the on-orbit flight effect of the satellite. As the micro-nano satellite of the embedded system, the memory space adopted is relatively limited, and when a software system with complex calling relationship needs to be operated on the satellite, the memory resource is particularly tense. When a task is created, a satellite software system running an operating system allocates enough stack space according to experience, and then tests and observes whether the software is normal or not repeatedly. In the method for setting the maximum stack space of an embedded system, a certain specific value is used for filling the stack space, then a software system is operated, and finally, the change condition of the specific value in the stack space is observed to determine the actual use condition of the stack space. The method comprises the steps of carrying out stack space use condition prompt and updating of stack top dynamic variables according to comparison results respectively, compiling the software program, obtaining corresponding PUSH instructions, adding instructions for executing the SP pointer comparison in the PUSH instructions, and obtaining the maximum stack space required by the running of the software program functions by repeatedly executing the steps. Disclosure of Invention The invention aims to provide a stack overflow eliminating method based on intelligent calculation of a task stack on a spaceborne computer, which is based on a Cortex-M7 kernel and uses an analysis function call relation to intelligently calculate the space size of the task stack so as to eliminate the stack overflow phenomenon, thereby improving the reliability of an on-board software system, and simultaneously improving the utilization rate of on-board storage resources by accurately distributing the size of the task stack. In order to achieve the above outlined objects, the technical solution adopted by the present invention is as follows: A stack overflow elimination method based on Task stack intelligent computation on a spaceborne computer is provided, and a maximum Task stack space required by a Task i/a function Func i in running is set as ST_Size_Max (1), and is characterized by comprising the following specific steps: and step 1, obtaining an assembly text file from the executable object file on the spaceborne computer through a disassembly tool. And 2, searching an offset position of the designated task function in the obtained assembly text file, taking the offset position as a starting position of a designated task function body, and taking the task function as a1 st-stage function. And 3, analyzing each assembly instruction from the starting position. If the instruction is in the form of "subsp, size", it is indicated as stack framing instruction, and it is indicated that a new function stack with size of size is created in the instruction, so that preparation is made for calling the subfunction, so that the stack space size required by this framing needs to be accumulated into the task stack space size required by the specified task/function. Step 5. If the instruction is in the form of "push { register1, register2,. }, it is described as a push instruction, where register data is stored into the stack space, so that the stack space size required by the push is accumulated into the task stack space size required by the specified task/function. And 6, if the function is a sub-function call instruction, returning to the step 3 by taking the sub-function as a designated function, taking the sub-function as an object to be analyzed, taking the sub-function body as an analysis starting position, and iteratively calculating the Size ST_Size (i+1) of the function stack space required by the i+1st function. And 7, if the instruction is a function pointer calling instruction, backtracking the instruction, finding the offset position of the function pointed by the function pointer in the assembly text file, repeating the step 3 by taking the function as a designated function, taking the sub-function as an object to be analyzed, taking the sub-function body as an analysis starting position, and iteratively calculating the Size ST_Size (i+1) of the function stack space required by the next-stage function. And 8, when the analy