CN1851648A - Stack overflow protection method in operation for embedded system - Google Patents

Stack overflow protection method in operation for embedded system Download PDF

Info

Publication number
CN1851648A
CN1851648A CN 200610051625 CN200610051625A CN1851648A CN 1851648 A CN1851648 A CN 1851648A CN 200610051625 CN200610051625 CN 200610051625 CN 200610051625 A CN200610051625 A CN 200610051625A CN 1851648 A CN1851648 A CN 1851648A
Authority
CN
China
Prior art keywords
function
code
stack
space
call
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN 200610051625
Other languages
Chinese (zh)
Other versions
CN100426237C (en
Inventor
陈天洲
沙峰
谢斌
赵懿
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CNB2006100516256A priority Critical patent/CN100426237C/en
Publication of CN1851648A publication Critical patent/CN1851648A/en
Application granted granted Critical
Publication of CN100426237C publication Critical patent/CN100426237C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

Said method includes 1, compiler analysing scanning original program, generating program function call list for optimizing unreel function; 2, compiler detecting code and stack use state in function inserting operation, and feeding back information for processing code in inserting operation; 3, compiler processing code in functional inserting stack operation; 4, adopting functional unreel technology optimizing inserted code in function. The present invention does not insert code in nested function, greatly reduces code quantity, capable of dynamically detecting warehouse space in application program operation and doing relevant processing, excluding overflow possibility to ensure system safe operation.

Description

A kind of stack overflow protection method in operation for embedded system
Technical field
The present invention relates to embedded system program technique of compiling field, particularly relate to a kind of stack overflow protection method in operation for embedded system.
Background technology
Obtained significant progress nearest two, 30 years built-in fields, the development of many industries has be unable to do without the participation of built-in field, as: automobile, aviation, heavy industry, robot, intelligent house keeper etc. are numerous.The demand of these industry built-in fields has been impelled the development of embedded system, has also proposed more and more higher requirement simultaneously.
Present embedded system mainly is divided into high-end embedded system and low side embedded system two big classes, so-called high-endly embeddedly is meant that those have high processing rate, the systems that use more, and there is senior hardware device in these systems.And low side is meant the general systems in aspect such as processing speed, function.Often there is the problem of space constraint in these systems on internal memory.So they are used in different environment because different characteristics is arranged, and different function and efficient is provided.
All there is the problem of low memory greatly in the embedded system of low side, and the reason that causes this problem is mainly from two aspects: the one, and the restriction on the hardware technology, the 2nd, the restriction on the cost.Low memory has seriously influenced the safety that runs on the program in the system.Exception error can take place to the internal memory space requirement than higher program in some under the situation of not having warning, finally cause system crash.Though the problem odds such for small programs is very little, as long as such possibility is arranged, just there is hidden danger in system so.
For many years, the research that restriction causes storehouse to overflow at embedded system memory has a lot, but wherein some is too theoretical, and feasibility is too poor.As: the internal memory compression.The purpose of internal memory compression is exactly to store more information in limited space, but data compression time and data decompression time that this method costs a lot of money, so plant effective very poor in the time application.
Summary of the invention
The objective of the invention is to overcome deficiency of the prior art, a kind of stack overflow protection method in operation for embedded system is provided.
The technical scheme that the present invention solves its technical matters employing is as follows:
Stack overflow protection method in operation for embedded system may further comprise the steps:
(1) compiler analysis scan original program, generator program function call table uses during for the backrush function optimization;
(2) compiler inserts when operation detection of code in function, detects the user mode of storehouse, and return message, handles the code use during for the operation of inserting;
Handle code when (3) compiler inserts the storehouse operation in function:
If not having when operation exception error takes place then handles code and do not do anything;
During wrong generation:
A, there is available space more than needed at the place if program is found the stack space bottom, then adjusts the position of stack register and the position of storehouse reference register, thereby enlarges stack space, and the data in the former stack of translation simultaneously are at the bottom of the new stack; Recovery causes the state before the wrong function call, and re-executes function call;
B, do not find to seek available space at whole memory headroom in useful space in stack space bottom;
If in whole memory headroom, have and use the space, then utilize Memory Allocation to call, distribute an internal memory, and connect together by data structure and former storehouse, form new storehouse, and the data in the former stack of translation arrive at the bottom of the new stack; Recovery causes the state before the wrong function call, and re-executes function call;
If c does not have free space in whole memory headroom, then program is suspended, and is placed into once more in the operating system task formation when by the time free space being arranged and moves;
(4) adopt function backrush technology, optimize the code that in function, inserts:
To generic function, be left intact;
To the function of nesting allocation, carry out function backrush optimization, from the function call table, form and call the path, thus with in the path function in the code that inserts simplify in the function that merges to top layer the simplified code amount.
The present invention compares with background technology, and the useful effect that has is:
The present invention handles the place that begins that code is inserted into each function when detection of code is with operation when adopting technique of compiling to move, when nested function occurring and call, adopt detection of code backrush technology, only in initial call function, insert code, and need not in each nested function, to insert code.So just reduced size of code greatly.By such method just can be when application program be moved the detection of dynamic stack space, and do corresponding processing, get rid of the possibility that the storehouse operation is overflowed take place, the system that finally guarantees can move under the prerequisite of safety.
Description of drawings
Fig. 1 is the schematic flow sheet of the inventive method.
Embodiment
Below in conjunction with the drawings and specific embodiments content of the present invention is described in detail.
When implementing stack overflow protection method in operation for embedded system, concrete mode is as follows:
The first step, compiler analysis scan original program, generator program function call table:
The core of this method is detection of code and a program stack processing code when inserting operation in application code.But need different insertion methods for different functions.If common single function call, then normal the insertion just can.But for the function of nesting allocation, situation is just different, compares simple function and calls just complicated many.Following code is exactly two kinds of different situations:
void?fun() void?fun1()
{ {
// inner no function call fun2 (); // call function fun2 ()
} }
For fun () and fun1 (), be exactly two kinds of different situations, need different processing.So there is the function call table to be analyzed, the function call table that obtains is used by following step.
Second step, detection of code when in function, inserting operation:
The main function of detection of code is to detect the user mode of storehouse when program run during operation, judges when whether the storehouse operation takes place and overflows, and need do following detection:
Whether with stack pointer have intersection, illustrate that overflow error took place when storehouse moved if having to intersect if detecting the downward growth position of heap.If do not intersect then illustrate that running status does not well have mistake.The information of returning is as follows:
(1) wrong, return error message, comprise the position and the function call information that causes mistake of heap at that time: function local variable, parameter.
(2) correct information is returned in inerrancy.Be left intact.
Code is inserted into beginning place of program function by compiler, so that detect immediately after the routine call function.
In the 3rd step, handle code when in function, inserting operation:
The function of handling code during operation is according to the result that second step was returned storehouse to be handled, if the result that returns of second step without any problem this partial code be left intact.If overflow error takes place during the return results explanation storehouse operation in second step, then do and check that the storehouse bottom has or not unnecessary free space:
(1) redundant space is arranged, then adjust the storehouse bottom position, the outwards expansion of storehouse bottom.This moment, skew took place in data in the stack position at the bottom of with respect to stack that is stored in originally of storehouse inside, so the data in the original stack must be moved at the bottom of the stack, and reset stack base pointer position at the bottom of the stack, stack pointer re-executes the instruction of the initiation mistake of being carried out by second step to when the position, top of setting out in advance to make arrangements.Trigger wrong function call and will be called again by such, and the set data of calling when causing mistake have been carried out record in second step, these records are used to return to the error condition back.Just can call again after expanding and cause calling of mistake in storehouse, so just mistake can be recovered, guarantee the storehouse security of program run.
(1) do not have redundant space, then the available internal memory space is sought by system call by system in whole free memory,
(2) in whole internal memory, free memory is arranged, then distributes an internal memory, and this piece internal memory coupled together at the bottom of by data structure and original stack and the former stack of translation in data to new stack bottom, reset stack base pointer and stack pointer.
(3) do not have free memory in whole memory headroom, then this program is suspended, and could be put once more as carrying out in the operating system task formation after free memory is arranged by the time.
The 4th step, insert code backrush technology, optimize and insert code:
The insertion of the code in the first step and second step is not optimize, and the size of code that inserts by first, second two step is very big, so to also increased the size of code of program when providing the storehouse overflow protection for program.An effective method is to be optimized inserting code.Situation about optimizing mainly is divided into two parts:
(1) simple function optimization:
Simple function is meant that inside does not have the function of other function calls, such function, inside all is simple code, there is not nested function to call, when so compiler inserts code at this class function, only need in function simple handle when detection of code and operation when inserting operation code just can, so need not optimization.
(2) nested function optimization:
Referring to during nested function has other function call in the function, so so whole function call can relate to the many places function call, can be because the insertion code of this function need insert a large amount of codes.Main method is the function call table that utilizes the first step to generate, classification simple function nested function.Call part at nested function,, find out the function call path according to the function call table.Whichever function all is that simple function is piled up and formed, so in the function call path, according to the function call table, find out the function call path., optimize and merge rollback a code that inserts each function the path from the bottom beginning of function call path to top layer function.So just reduce the size of code that inserts, improved availability.
At last, it is also to be noted that what more than enumerate only is specific embodiments of the invention.Obviously, the invention is not restricted to above examples of implementation, many distortion can also be arranged.All distortion that those of ordinary skill in the art can directly derive or associate from content disclosed by the invention all should be thought protection scope of the present invention.

Claims (1)

1, a kind of stack overflow protection method in operation for embedded system may further comprise the steps:
(1) compiler analysis scan original program, generator program function call table uses during for the backrush function optimization;
(2) compiler inserts when operation detection of code in function, detects the user mode of storehouse, and return message, handles the code use during for the operation of inserting;
Handle code when (3) compiler inserts the storehouse operation in function:
If not having when operation exception error takes place then handles code and do not do anything;
During wrong generation:
A, there is available space more than needed at the place if program is found the stack space bottom, then adjusts the position of stack register and the position of storehouse reference register, thereby enlarges stack space, and the data in the former stack of translation simultaneously are at the bottom of the new stack; Recovery causes the state before the wrong function call, and re-executes function call;
B, do not find to seek available space at whole memory headroom in useful space in stack space bottom;
If in whole memory headroom, have and use the space, then utilize Memory Allocation to call, distribute an internal memory, and connect together by data structure and former storehouse, form new storehouse, and the data in the former stack of translation arrive at the bottom of the new stack; Recovery causes the state before the wrong function call, and re-executes function call;
If c does not have free space in whole memory headroom, then program is suspended, and is placed into once more in the operating system task formation when by the time free space being arranged and moves;
(4) adopt function backrush technology, optimize the code that in function, inserts:
To generic function, be left intact;
To the function of nesting allocation, carry out function backrush optimization, from the function call table, form and call the path, thus with in the path function in the code that inserts simplify in the function that merges to top layer the simplified code amount.
CNB2006100516256A 2006-05-25 2006-05-25 Stack overflow protection method in operation for embedded system Expired - Fee Related CN100426237C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2006100516256A CN100426237C (en) 2006-05-25 2006-05-25 Stack overflow protection method in operation for embedded system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2006100516256A CN100426237C (en) 2006-05-25 2006-05-25 Stack overflow protection method in operation for embedded system

Publications (2)

Publication Number Publication Date
CN1851648A true CN1851648A (en) 2006-10-25
CN100426237C CN100426237C (en) 2008-10-15

Family

ID=37133127

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2006100516256A Expired - Fee Related CN100426237C (en) 2006-05-25 2006-05-25 Stack overflow protection method in operation for embedded system

Country Status (1)

Country Link
CN (1) CN100426237C (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102063325A (en) * 2011-01-06 2011-05-18 哈尔滨工业大学 Method for implementing multi-task real-time operating system embedded into 51 series singlechip
CN101216774B (en) * 2008-01-03 2012-09-05 中国科学院计算技术研究所 Optimizing method for using idle register analog as rapid overflow space
CN103116532A (en) * 2011-11-16 2013-05-22 通用汽车环球科技运作有限责任公司 Recovering from stack corruption faults in embedded software systems
CN104679645A (en) * 2013-11-28 2015-06-03 中国航空工业集团公司航空动力控制系统研究所 Method for detecting stack space allowance on real time

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
FR2786285B1 (en) * 1998-11-24 2001-02-02 Secap DEVICE AND METHOD FOR PROTECTING AGAINST BATTERY OVERFLOWS IN A MEMORY AND FRANKING MACHINE IMPLEMENTING THEM
JP2003167737A (en) * 2001-11-30 2003-06-13 Nec Corp Stack use method
US6996677B2 (en) * 2002-11-25 2006-02-07 Nortel Networks Limited Method and apparatus for protecting memory stacks
CN1300676C (en) * 2004-10-27 2007-02-14 上海大学 Stack area expanding method

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101216774B (en) * 2008-01-03 2012-09-05 中国科学院计算技术研究所 Optimizing method for using idle register analog as rapid overflow space
CN102063325A (en) * 2011-01-06 2011-05-18 哈尔滨工业大学 Method for implementing multi-task real-time operating system embedded into 51 series singlechip
CN102063325B (en) * 2011-01-06 2013-04-03 哈尔滨工业大学 Method for implementing multi-task real-time operating system embedded into 51 series singlechip
CN103116532A (en) * 2011-11-16 2013-05-22 通用汽车环球科技运作有限责任公司 Recovering from stack corruption faults in embedded software systems
CN103116532B (en) * 2011-11-16 2016-01-20 通用汽车环球科技运作有限责任公司 Damage in fault from the storehouse embedded software system and recover
CN104679645A (en) * 2013-11-28 2015-06-03 中国航空工业集团公司航空动力控制系统研究所 Method for detecting stack space allowance on real time

Also Published As

Publication number Publication date
CN100426237C (en) 2008-10-15

Similar Documents

Publication Publication Date Title
CN1475909A (en) realization of isertion type system soft ware patch and control method
CN1251076C (en) Acceleration of method call in virtual machine
CN100346303C (en) Class loading implementation method in Java operation system
CN100347676C (en) PowerPC processor based vehicular operating system interrupt management method
CN1851648A (en) Stack overflow protection method in operation for embedded system
CN1728106A (en) Method for positioning malfunction of application program
CN1945571A (en) Method for re-setting up catalogue structure and restoring data in FAI volume
CN100342353C (en) Process mapping realization method in embedded type operation system
CN1361489A (en) Automatic circular daily record information storing method and system
CN1920793A (en) Device and method for implementing test scenarios replay in different voice environment
CN1735865A (en) Method and apparatus for handling threads in a data processing system
CN1235142C (en) Embedded sorftware task endless loop monitoring method
CN101034369A (en) Software anti-interference method and device
CN101079734A (en) A hot plug configuration recovery method of rack device
CN1510575A (en) High-efficient administration method for database connection
CN1896957A (en) Method for leaking memory of positioning virtual operation system
CN1890637A (en) Methods and apparatus to dynamically insert prefetch instructions based on garbage collector analysis and layout of objects
CN1212569C (en) Multiple-thread automatic test method
CN1838074A (en) Method and system for acquiring function parameter on 64-bit windows operating system
CN1889459A (en) Journal formatting unit and method in safety management center system
CN1801033A (en) Computer virus checking and killing method based on data stream
CN101075219A (en) Method and system for processing interruption
CN1916814A (en) Method for sending command to portable storage device
CN101030134A (en) Device and method for processing dynamic scheduling related to mono-transmitting flow process line data
CN100549958C (en) A kind of class file stowage and system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20081015

Termination date: 20110525