Stack area management method of storage device and electronic device
Patent Information
- Application Number
- CN202611390150.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-09
- Publication Date
- 2026-10-13
AI Technical Summary
当采用固定大小的栈帧时,无法根据运行状态动态调整栈帧内容,可能导致栈溢出的风险,从而系统运行崩溃
[0014]综上所述,本发明提供一种存储设备的栈区管理方法及电子设备,栈区管理方法包括将栈区划分为固定大小的多个子栈单元,在函数调用时,获取未被占用的子栈单位个数;当未被占用的子栈单位个数小于预设个数时,选取多个已占用的子栈单元作为第一栈区,使未占用的子栈单元个数与第一栈区的个数之和达到预设个数,将第一栈区中的数据下刷至非易失性存储器,并释放第一栈区,再执行函数调用;当函数调用结束时,释放多个子栈单元,将释放后的多个子栈单元作为第二栈区,当第二栈区的子栈单元个数大于或等于第一栈区的子栈单元个数,则将非易失性存储器中的数据加载回第一栈区,执行下一次函数调用。通过本发明提供的栈区管理方法,使得系统在栈空间有限的条件下,能够效地扩展固件可用的栈空间容量,降低栈溢出的风险,并提升内存资源的利用率。
Smart Images

Figure CN122902946A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of storage technology, and in particular to a method for managing the stack area of a storage device and an electronic device. Background Technology
[0002] When a function call occurs, the CPU performs a stack push operation, creating a stack frame corresponding to the function. This stack frame stores information such as the return address, local variables, and registers. As the call depth increases, the stack space required for program execution also increases. When using a fixed-size stack frame, it is impossible to dynamically adjust the stack frame content according to the runtime state, which may lead to the risk of stack overflow, resulting in system crashes. Summary of the Invention
[0003] The purpose of this invention is to provide a stack area management method and electronic device for storage devices, which can reduce the risk of stack overflow during firmware operation and improve memory resource utilization.
[0004] This invention provides a stack area management method for a storage device, comprising at least: The stack area is divided into multiple sub-stack units with the same storage space size; When a function call is executed, obtain the number of unused substack units; If the number of unoccupied sub-stack units is less than a preset number, multiple occupied sub-stack units are selected as the first stack area, so that the sum of the number of unoccupied sub-stack units and the number of the first stack area reaches the preset number. The data in the first stack area is then flushed to non-volatile memory, the first stack area is released, and the function call is executed again. The multiple sub-stack units released after the function call ends are used as the second stack area. When the number of sub-stack units in the second stack area is greater than or equal to the number of sub-stack units in the first stack area, the data in the non-volatile memory is loaded back into the first stack area, and the next function call is executed.
[0005] In one embodiment of the present invention, the first stack area is a plurality of sub-stack units with consecutive storage locations, and the storage locations of the first stack area are consecutive to the storage locations of the unoccupied sub-stack units.
[0006] In one embodiment of the present invention, the second stack area is a plurality of sub-stack units with consecutive storage locations.
[0007] In one embodiment of the present invention, when a function call is executed, the stack management method further includes the following steps: Record the number of sub-stack units that have been occupied; and The number of unoccupied sub-stack units is obtained based on the number of occupied sub-stack units.
[0008] In one embodiment of the present invention, flushing the data in the first stack area to the non-volatile memory includes the following steps: Record the storage location of the first stack area; The data in the first stack area is flushed to the non-volatile memory, and a mapping table is established between the storage location of the first stack area and the storage location of the non-volatile memory.
[0009] In one embodiment of the present invention, after using the released plurality of sub-stack units as the second stack area, the stack area management method further includes the following steps: Determine whether the second stack area contains all the sub-stack units of the first stack area; When the second stack region contains all the sub-stack units of the first stack region, the number of sub-stack units in the second stack region is greater than or equal to the number of sub-stack units in the first stack region; and When the second stack area does not contain all the sub-stack units of the first stack area, the number of sub-stack units in the second stack area is less than the number of sub-stack units in the first stack area.
[0010] In one embodiment of the present invention, loading data from the non-volatile memory back into the first stack area includes the following steps: Based on the storage location of the first stack area in the mapping table, locate the storage location in the non-volatile memory, read data from the located storage location in the non-volatile memory, and write the read data into the first stack area.
[0011] In one embodiment of the present invention, when the number of sub-stack units in the second stack area is less than the number of sub-stack units in the first stack area, the stack area management method further includes the following steps: Monitor whether all sub-stack units in each of the first stack areas in the mapping table are unoccupied sub-stack units; If all sub-stack units of the first stack area are unoccupied in the mapping table, then the data in the non-volatile memory is loaded back to the storage location of the first stack area according to the mapping table, the mapping information corresponding to the first stack area is cleared, and the mapping table is updated; and If there is an occupied sub-stack unit in the mapping table for the first stack area, then continue to monitor whether all sub-stack units in each first stack area in the mapping table are unoccupied sub-stack units, until all data in the non-volatile memory is loaded back to the storage location of the first stack area.
[0012] In one embodiment of the present invention, the stack management method further includes the following steps: If the number of unoccupied sub-stack units is greater than or equal to the preset number, a function call is executed, the data required for the function call is written to the unoccupied sub-stack units, and the occupied sub-stack units are updated.
[0013] The present invention also provides an electronic device, the electronic device comprising: Memory, which stores computer programs; and The processor runs the computer program to implement the stack management method described in any of the above descriptions.
[0014] In summary, this invention provides a stack management method and electronic device for a storage device. The stack management method includes dividing the stack into multiple sub-stack units of a fixed size. During a function call, the number of unoccupied sub-stack units is obtained. When the number of unoccupied sub-stack units is less than a preset number, multiple occupied sub-stack units are selected as a first stack area, ensuring that the sum of the number of unoccupied sub-stack units and the number of units in the first stack area reaches a preset number. The data in the first stack area is then flushed to non-volatile memory, and the first stack area is released before executing the function call. When the function call ends, the multiple sub-stack units are released and used as a second stack area. When the number of sub-stack units in the second stack area is greater than or equal to the number of sub-stack units in the first stack area, the data in the non-volatile memory is loaded back into the first stack area, and the next function call is executed. Through the stack management method provided by this invention, the system can effectively expand the available stack space capacity of the firmware under limited stack space conditions, reduce the risk of stack overflow, and improve the utilization rate of memory resources.
[0015] Of course, any product implementing this invention does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of a stack area management method in one embodiment.
[0018] Figure 2 This is a schematic diagram of the stack area division in one embodiment.
[0019] Figure 3 This is a schematic diagram of steps S131 to S132 in one embodiment.
[0020] Figure 4 This is a schematic diagram of an electronic device in one embodiment.
[0021] Label Explanation: 11. Processor; 12. Memory; 100. Stack area; 110. Substack unit. Detailed Implementation
[0022] To facilitate understanding of this application, a more complete description will be provided below with reference to the accompanying drawings. Preferred embodiments of this application are shown in the drawings. However, this application can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the disclosure of this application.
[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein in the specification of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application.
[0024] In the description of this invention, it should be understood that the terms "center," "upper," "lower," "front," "rear," "left," and "right," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or component referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Similarly, the terms "high" and "low," indicating degree, are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or component referred to must have a high or low position, and therefore should not be construed as a limitation of the invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0025] Within the internal architecture of the storage controller, firmware is responsible for managing complex tasks such as data reading and writing, garbage collection, and wear leveling. The stability of the firmware directly affects the security of user data and the normal operation of the underlying hardware. During firmware execution, function calls are a common and fundamental program execution method to implement complex business logic. To maintain function calls at various levels during program execution, the system must allocate a dedicated stack space in memory. The stack space is a data structure that follows the Last-In-First-Out (LIFO) principle and is primarily used to store the context information of the currently executing function. When a function is called, the CPU performs a push operation, storing the function's return address, internally defined local variables, and the current state of the CPU registers into the stack space, forming the corresponding stack frame. When the function finishes execution and is ready to return to the previous caller, the CPU performs a pop operation, removing the corresponding stack frame data from the stack space, thereby releasing the corresponding memory resources, and restoring the execution state of the previous function based on the popped return address. The capacity and management mechanism of the stack space directly determine the function call depth and the scale of local variables that the system can support. As the call depth increases, the stack space required for program execution also increases. When using a fixed-size stack frame, it is impossible to dynamically adjust the stack frame content according to the running state, which may even lead to stack overflow and system crash. Therefore, this invention provides a stack area management method and electronic device for storage devices, which can reduce the risk of stack overflow during firmware operation and improve memory resource utilization.
[0026] Please see Figure 1 As shown, the present invention provides a stack area management method for a storage device, the stack area management method including steps S110 to S150.
[0027] Step S110: Divide the stack area into multiple sub-stack units with the same storage space size.
[0028] Please see Figure 2 As shown, in one embodiment of the present invention, during system initialization, the start address, end address, and preset fixed size of the stack area 100 are obtained. Starting from the start address of the stack area 100, the firmware divides the stack area into multiple sub-stack units 110 according to the preset fixed size. After division, each sub-stack unit 110 has a defined storage location, transforming the stack area 100 from a single continuous region into a discrete management structure that can be independently monitored, moved, and released at the unit level. This division forms the basis for subsequent flashing and reloading operations to be performed at the unit granularity. In this embodiment, the preset fixed size is, for example, 512 bytes, so the storage space size of each sub-stack unit 110 is, for example, 512 bytes.
[0029] Step S120: When executing a function call, obtain the number of unoccupied sub-stack units.
[0030] Please see Figure 2 As shown, in one embodiment of the present invention, when a function call is executed, the upper-level function calls the lower-level function, and the upper-level function enters stack area 100 between the upper-level and lower-level functions. The sub-stack unit occupied by the upper-level function is located at the bottom of stack area 100 and will not be accessed before the lower-level function returns, belonging to cold data that is accessed infrequently. The sub-stack unit 110 occupied by the lower-level function is located at the top of stack area 100 and belongs to hot data that is accessed frequently. In this embodiment, the upper-level functions are, for example, functions A and B, and the lower-level function is, for example, function C. Function A calls function B, and function B calls function C. Looking from the top of the stack to the bottom of the stack, function A occupies multiple consecutive sub-stack units 110 near the top of the stack, function B occupies multiple consecutive sub-stack units 110 adjacent to function A, and function C occupies multiple consecutive sub-stack units 110 adjacent to function B.
[0031] Please see Figure 1 and Figure 2 As shown, in one embodiment of the present invention, when a function call is executed, obtaining the number of unoccupied sub-stack units 110 includes recording the number of occupied sub-stack units 110 and obtaining the number of unoccupied sub-stack units 110 based on the number of occupied sub-stack units 110. In this embodiment, when a function call occurs during program execution, the sub-stack units 110 occupied by the function store the return address, local variables, and processor register contents of each function. By recording the number of occupied sub-stack units 110 in real time, the number of unoccupied sub-stack units 110 can be calculated, providing basic data for subsequent stack push monitoring and flush triggering.
[0032] Please see Figure 2 and Figure 3 As shown, in one embodiment of the present invention, after obtaining the number of unoccupied sub-stack units 110 in step S120, the stack area management method further includes determining whether the number of unoccupied sub-stack units 110 is less than a preset number. If the number of unoccupied sub-stack units 110 is less than the preset number, multiple occupied sub-stack units 110 are selected as the first stack area, so that the sum of the number of unoccupied sub-stack units 110 and the number of the first stack area reaches the preset number. The data in the first stack area is flushed to non-volatile memory, and the first stack area is released, and the function call continues to be executed. If the number of unoccupied sub-stack units 110 is greater than or equal to the preset number, the function call continues to be executed, the data required for the function call is written to the unoccupied sub-stack units 110, the occupied sub-stack units 110 are updated, and the number of unoccupied sub-stack units 110 is obtained. Specifically, this includes steps S131 to S132, and step S130.
[0033] Step S131: Determine if the number of unoccupied sub-stack units is less than a preset number. If the number of unoccupied sub-stack units is less than the preset number, proceed to step S130. If the number of unoccupied sub-stack units is greater than or equal to the preset number, proceed to step S132.
[0034] Step S130: Select multiple occupied sub-stack units as the first stack area, so that the sum of the number of unoccupied sub-stack units and the number of sub-stack units in the first stack area reaches a preset number, flush the data in the first stack area to non-volatile memory, release the first stack area, and then execute the function call.
[0035] Step S132: Execute the function call, write the data required for the function call into the unoccupied sub-stack unit, update the number of occupied sub-stack units, and return to step S110.
[0036] Please see Figure 2 and Figure 3 As shown, in one embodiment of the present invention, in step S130, the first stack area consists of multiple sub-stack units 110 with contiguous memory addresses, and the storage location of the first stack area is contiguous with the storage location of the unoccupied sub-stack units. In this embodiment, starting from the occupied sub-stack unit 110 adjacent to the unoccupied sub-stack unit 110, multiple occupied sub-stack units 110 are sequentially selected from the bottom of the stack area 100 along the direction of the top of the stack as the first stack area. The first stack area is, for example, the multiple sub-stack units 110 occupied by function A.
[0037] Please see Figure 2 and Figure 3As shown, in one embodiment of the present invention, in step S130, the preset number is set according to the number of sub-stack units 110 required for the function call. When the number of unoccupied sub-stack units 110 is less than the preset number, it indicates that the available capacity of the stack area is insufficient. A first stack area is selected so that the sum of the number of sub-stack units 110 and the number of unoccupied sub-stack units 110 in the first stack area reaches the preset number, ensuring that the function call executes normally. At this time, the data flushing process is executed, and the data in the first stack area is directly written to non-volatile memory for backup. After the data flushing is completed, the system releases the first stack area and marks the sub-stack units 110 in the first stack area as unoccupied sub-stack units 110. Therefore, after the flushing, the number of unoccupied sub-stack units 110 in the stack area 100 increases to the preset number. In this embodiment, the number of sub-stack units 110 required for the function call is, for example, 3, so the preset number is, for example, greater than or equal to 3. When there are, for example, two unoccupied sub-stack units 110, starting from the occupied sub-stack units 110 adjacent to the unoccupied sub-stack units 110, one or more occupied sub-stack units 110 are selected sequentially from the bottom of the stack area 100 along the stack top direction as the first stack area. The data of the first stack area is flushed to non-volatile memory, and the first stack area is released. At this time, the number of unoccupied sub-stack units 110 becomes more than or equal to three, to ensure that the function call is executed normally and the stack does not overflow.
[0038] Please see Figure 1 As shown, in one embodiment of the present invention, when data in the first stack area is flushed to non-volatile memory, the stack area management method further includes recording the storage location of the first stack area, flushing the data in the first stack area to non-volatile memory, and establishing a mapping table between the storage location of the first stack area and the storage location of the non-volatile memory. By establishing the mapping table, the data flushed to the non-volatile memory can be accurately located and retrieved at any time according to the mapping relationship, ensuring the reliable operation of the stack swapping mechanism in terms of data security and correctness. In this embodiment, as function calls are executed, the mapping table stores multiple mapping relationships between the first stack area and the non-volatile memory.
[0039] Please see Figure 2 and Figure 3As shown, in one embodiment of the present invention, in step S132, when a function call is executed, if the number of unoccupied sub-stack units 110 is greater than or equal to a preset number, it indicates that the number of available sub-stack units 110 in the stack area is sufficient to execute the function call normally. Then, the return address, local variables, and processor register contents required by the function call are written into the unoccupied sub-stack units 110, updating the number of occupied sub-stack units 110. In this embodiment, when the number of sub-stack units 110 required to execute the function call is, for example, 5, the preset number is, for example, 5. If the number of unoccupied sub-stack units 110 is greater than or equal to 5, the function call is executed normally, and the number of occupied sub-stack units 110 is updated simultaneously to accurately obtain the number of unoccupied sub-stack units 110 in subsequent function calls.
[0040] Step S140: When the function call ends, the multiple sub-stack units released at the end of the function call are used as the second stack area.
[0041] Please see Figure 1 and Figure 2 As shown, in one embodiment of the present invention, after releasing the first stack area in step S130, in step S140, when the function call finishes execution and returns, the sub-stack units 110 originally occupied by each function are released, and the released sub-stack units 110 are used as the second stack area. The second stack area consists of multiple sub-stack units 110 with contiguous memory addresses. In this embodiment, when function C finishes execution and returns to function B, and when function B returns to function A, the sub-stack units 110 occupied by function C and function B are released, and the second stack area consists of multiple contiguous sub-stack units 110 occupied by function B and function C.
[0042] Please see Figure 1 and Figure 2 As shown, in one embodiment of the present invention, after using the released multiple sub-stack units 110 as the second stack area, the stack area management method further includes determining whether the second stack area contains all the sub-stack units 110 of the first stack area. When the second stack area contains all the sub-stack units 110 of the first stack area, the number of sub-stack units 110 in the second stack area is greater than or equal to the number of sub-stack units 110 in the first stack area. When the second stack area does not contain all the sub-stack units 110 of the first stack area, the number of sub-stack units 110 in the second stack area is less than the number of sub-stack units 110 in the first stack area.
[0043] Step S150: When the number of sub-stack units in the second stack area is greater than or equal to the number of sub-stack units in the first stack area, the data in the non-volatile memory is loaded back into the first stack area, and the next function call is executed.
[0044] Please see Figure 1 and Figure 2As shown, in one embodiment of the present invention, loading data from non-volatile memory back to the first stack area includes locating the storage location in the non-volatile memory according to the storage location of the first stack area in the mapping table, reading data from the located storage location in the non-volatile memory, and writing the read data to the first stack area. In this embodiment, when the number of sub-stack units 110 in the second stack area is greater than or equal to the number of sub-stack units 110 in the first stack area, it indicates that the storage location corresponding to the first stack area is not occupied. Then, according to the mapping relationship recorded in the mapping table, the data previously flushed to the non-volatile memory is rewritten to the first stack area to ensure the integrity and continuity of data during subsequent execution.
[0045] Please see Figure 1 and Figure 2 As shown, in one embodiment of the present invention, when the number of sub-stack units 110 in the second stack area is less than the number of sub-stack units 110 in the first stack area, the mapping table is used to monitor whether all sub-stack units 110 in each first stack area are unoccupied. If all sub-stack units 110 in the first stack area are unoccupied in the mapping table, the data in the non-volatile memory is loaded back to the storage location of the first stack area according to the mapping table, the mapping information of the corresponding first stack area is cleared, and the mapping table is updated. If any sub-stack units 110 in the first stack area are occupied in the mapping table, the monitoring of whether all sub-stack units 110 in each first stack area are unoccupied continues until all the data in the non-volatile memory is loaded back to the storage location of the first stack area. In this embodiment, when the second stack area does not contain all the sub-stack units 110 of the first stack area, it indicates that part of the space in the first stack area is occupied. Therefore, all first stack areas recorded in the mapping table are monitored, and it is determined whether all sub-stack units 110 of each first stack area are unoccupied. When all the recorded sub-stack units 110 of a first stack area are unoccupied, the data in the non-volatile memory is loaded back into the first stack area according to the mapping relationship in the mapping table, and the mapping information of the corresponding first stack area is cleared, and the mapping table is updated. When the recorded sub-stack units 110 of a first stack area are occupied, all first stack areas recorded in the mapping table are continuously monitored until all the data in the non-volatile memory is loaded back into the first stack area.
[0046] Please see Figure 4 As shown, the present invention provides an electronic device, which includes a processor 11, a memory 12, and a computer program stored in the memory 12 and executable on the processor 11. The processor 11 executes the stack management method described above.
[0047] Please see Figure 4As shown, the memory 12 includes at least one type of readable storage medium, including flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of an electronic device, such as a portable hard drive. In other embodiments, the memory 12 can be an external storage device of the electronic device, such as a plug-in portable hard drive, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc. Furthermore, the memory 12 can include both internal and external storage units of the electronic device. The memory 12 can be used not only to store application software and various types of data installed on the electronic device, but also to temporarily store data that has been output or will be output.
[0048] Please see Figure 4 As shown, in some embodiments, the processor 11 can be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units, microprocessors, digital processing chips, graphics processors, and various control chips. The processor 11 is the control unit of the electronic device, connecting various components of the entire electronic device through various interfaces and lines. It executes programs or modules stored in the memory 12 and calls data stored in the memory 12 (such as programs for stack management methods) to perform various functions of the electronic device and process data.
[0049] In some embodiments, the processor 11 executes the operating system of the electronic device and various installed applications. The processor 11 executes the applications to implement the steps in the stack management method described above.
[0050] In some embodiments, the computer program may be divided into one or more modules, one or more of which are stored in the memory 12 and executed by the processor 11 to perform the present invention. The one or more modules may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in an electronic device.
[0051] This invention provides a stack management method and electronic device for a storage device. The stack management method includes dividing the stack into multiple sub-stack units of a fixed size. During a function call, the number of unoccupied sub-stack units is obtained. If the number of unoccupied sub-stack units is less than a preset number, multiple occupied sub-stack units are selected as a first stack area, ensuring that the sum of the number of unoccupied sub-stack units and the number of units in the first stack area reaches the preset number. Data in the first stack area is then flushed to non-volatile memory, and the first stack area is released before executing the function call. When the function call ends, multiple sub-stack units are released and used as a second stack area. If the number of sub-stack units in the second stack area is greater than or equal to the number of sub-stack units in the first stack area, data in the non-volatile memory is loaded back into the first stack area, and the next function call is executed. The stack management method provided by this invention enables the system to effectively expand the available stack space capacity of the firmware under limited stack space conditions, reducing the risk of stack overflow and improving the utilization rate of memory resources.
[0052] The embodiments of the present invention disclosed above are merely illustrative of the invention. The embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this specification. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the invention, thereby enabling those skilled in the art to better understand and utilize the invention. The invention is limited only by the claims and their full scope and equivalents.
Claims
1. A method for managing the stack area of a storage device, characterized in that, At least including: The stack area is divided into multiple sub-stack units with the same storage space size; When a function call is executed, obtain the number of unused substack units; If the number of unoccupied sub-stack units is less than a preset number, select multiple occupied sub-stack units as the first stack area, so that the sum of the number of unoccupied sub-stack units and the number of the first stack area reaches the preset number, flush the data in the first stack area to non-volatile memory, release the first stack area, and then execute the function call. as well as The multiple sub-stack units released after the function call ends are used as the second stack area. When the number of sub-stack units in the second stack area is greater than or equal to the number of sub-stack units in the first stack area, the data in the non-volatile memory is loaded back into the first stack area, and the next function call is executed.
2. The stack area management method according to claim 1, characterized in that, The first stack area consists of multiple sub-stack units with consecutive storage locations, and the storage locations of the first stack area are consecutive to the storage locations of the unoccupied sub-stack units.
3. The stack area management method according to claim 1, characterized in that, The second stack area consists of multiple sub-stack units with consecutive storage locations.
4. The stack area management method according to claim 1, characterized in that, When a function call is executed, the stack management method further includes the following steps: Record the number of sub-stack units that have been occupied; and The number of unoccupied sub-stack units is obtained based on the number of occupied sub-stack units.
5. The stack area management method according to claim 1, characterized in that, Flush the data in the first stack area to the non-volatile memory, which includes the following steps: Record the storage location of the first stack area; The data in the first stack area is flushed to the non-volatile memory, and a mapping table is established between the storage location of the first stack area and the storage location of the non-volatile memory.
6. The stack area management method according to claim 1, characterized in that, After using the released sub-stack units as the second stack area, the stack area management method further includes the following steps: Determine whether the second stack area contains all the sub-stack units of the first stack area; When the second stack region contains all the sub-stack units of the first stack region, the number of sub-stack units in the second stack region is greater than or equal to the number of sub-stack units in the first stack region; and When the second stack area does not contain all the sub-stack units of the first stack area, the number of sub-stack units in the second stack area is less than the number of sub-stack units in the first stack area.
7. The stack area management method according to claim 1, characterized in that, Loading the data from the non-volatile memory back into the first stack area includes the following steps: Based on the storage location of the first stack area in the mapping table, locate the storage location in the non-volatile memory, read data from the located storage location in the non-volatile memory, and write the read data into the first stack area.
8. The stack area management method according to claim 6, characterized in that, When the number of sub-stack units in the second stack area is less than the number of sub-stack units in the first stack area, the stack area management method further includes the following steps: Monitor whether all sub-stack units in each of the first stack areas in the mapping table are unoccupied sub-stack units; If all sub-stack units of the first stack area are unoccupied in the mapping table, then the data in the non-volatile memory is loaded back to the storage location of the first stack area according to the mapping table, the mapping information corresponding to the first stack area is cleared, and the mapping table is updated; and If there is an occupied sub-stack unit in the mapping table for the first stack area, then continue to monitor whether all sub-stack units in each first stack area in the mapping table are unoccupied sub-stack units, until all data in the non-volatile memory is loaded back to the storage location of the first stack area.
9. The stack area management method according to claim 1, characterized in that, The stack management method also includes the following steps: If the number of unoccupied sub-stack units is greater than or equal to the preset number, a function call is executed, the data required for the function call is written to the unoccupied sub-stack units, and the occupied sub-stack units are updated.
10. An electronic device, characterized in that, The electronic device includes: Memory, which stores computer programs; and The processor runs the computer program to implement the stack management method as described in any one of claims 1 to 9.