JPH08249206A - Computer with stack area destruction detection function - Google Patents

Computer with stack area destruction detection function

Info

Publication number
JPH08249206A
JPH08249206A JP7052951A JP5295195A JPH08249206A JP H08249206 A JPH08249206 A JP H08249206A JP 7052951 A JP7052951 A JP 7052951A JP 5295195 A JP5295195 A JP 5295195A JP H08249206 A JPH08249206 A JP H08249206A
Authority
JP
Japan
Prior art keywords
stack area
function
stack
register
program
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.)
Pending
Application number
JP7052951A
Other languages
Japanese (ja)
Inventor
Hitoshi Haruyama
仁 春山
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.)
Toshiba Corp
Original Assignee
Toshiba Corp
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 Toshiba Corp filed Critical Toshiba Corp
Priority to JP7052951A priority Critical patent/JPH08249206A/en
Publication of JPH08249206A publication Critical patent/JPH08249206A/en
Pending legal-status Critical Current

Links

Landscapes

  • Storage Device Security (AREA)
  • Executing Machine-Instructions (AREA)
  • Debugging And Monitoring (AREA)

Abstract

PURPOSE: To detect the abnormality of a function at the time of return to a calling origin when the abnormal function for destructing the stack area of the calling origin is called. CONSTITUTION: This computer for performing operations while securing and releasing the stack area for performing a fixed processing by a program within a program memory, storing a base pointer for indicating the bottom part of the stack area in a register 5 inside a CPU and the program memory 8c and operating the program while changing the base painter inside the register 5 by using storage 8c inside the program memory is provided with auxiliary preservation means 13 and 11 different from the storage part 8c for preserving the base pointer and comparing and reporting means 10 and 12 for comparing register contents 8c and 5 with the contents 11 of the auxiliary preservation means when the operation of the program is returned from a new stack area 9 to a certain stack area 8 and reporting that effect when they do not match with each other.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明は、スタック領域単位でプ
ログラムの動作が進行する計算機におけるスタック領域
破壊検出機能付き計算機に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a computer with a stack area destruction detection function in a computer in which a program operation progresses in stack area units.

【0002】[0002]

【従来の技術】計算機の動作においては、プログラムメ
モリの低い方から(下から)順に動作領域すなわちスタ
ック領域を確保していき、各スタック領域に対してデー
タ入出力を行って関数等を実行することが一般に行われ
てる。
2. Description of the Related Art In the operation of a computer, an operation area, that is, a stack area is secured in order from the lowest program memory (from the bottom), and data is input / output to / from each stack area to execute a function or the like. Is generally done.

【0003】各スタック領域は、対応する関数等の動作
が終了すれば解放され、当該スタック領域からさらに関
数等が呼び出されれば、新たなスタック領域がその上に
確保される。
Each stack area is released when the operation of the corresponding function or the like ends, and a new stack area is secured on the stack area when another function or the like is called from the stack area.

【0004】このようにスタック領域の確保・解放によ
り処理を進行させる計算機の中でも、特に、関数内のス
タック変数領域を「EBPレジスタ−オフセット」の形
で処理を行うようにプログラムをコンパイルするコンパ
イラを用いた計算機がある。
Among the computers that advance processing by securing / releasing the stack area in this way, in particular, a compiler that compiles a program so that the stack variable area in the function is processed in the form of "EBP register-offset" There is a calculator used.

【0005】この計算機においては、CPU(あるいは
MPU;マイクロプロセッサユニット)内にベースポイ
ンタ用レジスタとしてのEBPレジスタとスタックポイ
ンタ用レジスタとしてのESPレジスタとが用意され、
EBPレジスタとESPレジスタとにより、プログラム
の動作進行が保証される。そして、新たなスタック領域
が確保される際に、EBPレジスタ等の値が呼出し側の
スタック領域の上の部分に保存される。
In this computer, an EBP register as a base pointer register and an ESP register as a stack pointer register are prepared in the CPU (or MPU; microprocessor unit).
The EBP register and the ESP register guarantee the progress of the program operation. Then, when a new stack area is secured, the value of the EBP register or the like is saved in the upper portion of the calling side stack area.

【0006】図5はこのような計算機におけるスタック
領域の確保・解放を伴うプログラム処理の進行を説明す
る図である。図5(a)〜(d)は、プログラムメモリ
の状態を示しており、図中の下側が上記説明におけるメ
モリの低い方(下)であり、上側が上記説明におけるメ
モリの上である。まず、図5(a)において、プログラ
ムは関数Aのスタック31で関数Aの処理を行ってお
り、計算結果等の入出力もこのスタック31に対して行
われている。
FIG. 5 is a diagram for explaining the progress of program processing accompanied by securing / releasing a stack area in such a computer. 5A to 5D show the state of the program memory, the lower side of the figure is the lower side (lower) of the memory in the above description, and the upper side is the memory above. First, in FIG. 5A, the program is processing the function A on the stack 31 of the function A, and the input / output of calculation results and the like is also performed on the stack 31.

【0007】したがって、このとき、CPU内のEBP
レジスタには、関数Aのスタック31の一番下を指し示
すアドレスA1が保存されており、一方、ESPレジス
タには、動作中のスタック領域の一番上を指し示すアド
レスA2が保存されている。
Therefore, at this time, the EBP in the CPU
The register stores the address A1 that points to the bottom of the stack 31 of the function A, while the ESP register stores the address A2 that points to the top of the stack area in operation.

【0008】つまり、ベースポインタであるEBPレジ
スタの内容は、常に処理に対応するスタックの一番下の
アドレス(スタック領域の底部)を指し示すのであり、
スタックポインタであるESPレジスタの内容は、常に
対応するスタックの一番上のアドレス(当該スタックの
上に次のスタックのためのパラメータ等が積まれている
ときはその一番上)を指し示すものである。
That is, the content of the EBP register, which is the base pointer, always points to the bottom address (bottom of the stack area) of the stack corresponding to the processing,
The contents of the ESP register, which is the stack pointer, always indicates the top address of the corresponding stack (the top address when the parameters for the next stack are stacked on the stack). is there.

【0009】計算機は、この両レジスタの内容から動作
時に必要なアドレス等を確保でき、これにより高速動作
が担保されている。ここで、図5(b)に示すように、
仮に関数A内から関数Bを呼び出すと、関数B用のスタ
ック領域を確保する前に、関数Aのスタック31の一番
上のアドレスA2の上に、関数Bを処理するためのパラ
メータ32、関数Aへの戻り番地33、関数AのEBP
領域34が順に保存されていく。このようにメモリ領域
の新たな確保が行われる度に、ESPレジスタ内容は、
アドレスA3、アドレスA4、アドレスA5と変更され
ていく。
The computer can secure an address and the like necessary for operation from the contents of these two registers, thereby ensuring high-speed operation. Here, as shown in FIG.
If the function B is called from inside the function A, the parameter 32 for processing the function B, the function 32 on the address A2 at the top of the stack 31 of the function A, and the function B are allocated before the stack area for the function B is secured. Return address 33 to A, EBP of function A
The area 34 is saved in order. Each time a new memory area is secured in this way, the contents of the ESP register are
The addresses are changed to address A3, address A4, and address A5.

【0010】そして、関数AのEBP領域34が確保さ
れて、EBPレジスタ内容すなわちアドレスA1がこの
領域34に保存されると、ESPレジスタの内容すなわ
ちアドレスA5がEBPレジスタに保存され、関数Bの
スタック領域の確保処理に移る。
When the EBP area 34 of the function A is secured and the EBP register content, that is, the address A1 is stored in this area 34, the content of the ESP register, that is, the address A5 is stored in the EBP register and the stack of the function B is stored. Move to area reservation processing.

【0011】図5(c)は、関数Bのスタック35が確
保され、関数Bが処理されている状況を示す。ここで、
CPU内のEBPレジスタには、関数Bのスタック35
の一番下を指し示すアドレスA5が保存されており、一
方、ESPレジスタには、動作中のスタック領域の一番
上を指し示すアドレスA6が保存されている。
FIG. 5C shows a situation in which the stack 35 of the function B is secured and the function B is being processed. here,
The EBP register in the CPU has a stack 35 of the function B.
The address A5 pointing to the bottom of the stack is stored, while the ESP register stores the address A6 pointing to the top of the stack area in operation.

【0012】このとき、さらに新たな関数等が呼び出さ
れれば、図5(a),(b)と同様な処理を経て、新た
なスタック領域が関数Bのスタック35の上に確保され
ることになる。
At this time, if a new function or the like is called, a new stack area is secured on the stack 35 of the function B through the same processing as in FIGS. 5A and 5B. Become.

【0013】一方、関数Bについての処理が終了する
と、スタック35は、解放され、処理対象が関数Aに戻
ることになる。つまり、図5(d)に示すように、アド
レスA1を保存する関数AのEBP領域34の内容がE
BPレジスタに移され、ESPレジスタの内容は、関数
Aのスタック31の一番上を示すアドレスA2に変更さ
れる。さらに、CPUは、関数Aにおける戻り番地を、
関数Aへの戻り番地33から受け取ってこの番地から関
数Aについての処理を再開することになる。
On the other hand, when the processing for the function B is completed, the stack 35 is released and the processing target returns to the function A. That is, as shown in FIG. 5D, the content of the EBP area 34 of the function A storing the address A1 is E.
It is moved to the BP register, and the contents of the ESP register are changed to the address A2 indicating the top of the stack 31 of the function A. Further, the CPU sets the return address in the function A to
Upon receiving from the return address 33 to the function A, the processing for the function A is restarted from this address.

【0014】以上が、「EBPレジスタ−オフセット」
の形で処理を行うようにコンパイルされたプログラムに
おける、新たなスタック領域が確保される際に、EBP
レジスタ等の値が呼出し側のスタック領域の上の部分に
保存されるときの処理方法である。このような処理方法
は、EBPレジスタ及びESPレジスタに相当するレジ
スタを備えたCPUを用いた計算機において一般的に用
いられている手法である。特に、プログラム言語として
C言語を用いた場合は、上記処理方法が用いられる。
The above is the "EBP register-offset".
When a new stack area is secured in a program compiled to perform processing in the form of
This is the processing method when the value of a register or the like is saved in the upper part of the stack area of the calling side. Such a processing method is a method generally used in a computer using a CPU having registers corresponding to the EBP register and the ESP register. In particular, when the C language is used as the programming language, the above processing method is used.

【0015】[0015]

【発明が解決しようとする課題】ところで、上記処理方
法によりプログラムの処理がなされているとき、あるス
タック領域で、そのスタック領域の容量を越えてデータ
の書込みが行われた場合、メモリの上から下に向ってデ
ータの書込みが行われていくので、呼出し元のスタック
領域の内容が破壊されてしまうことになる。この場合、
呼出し元のスタック領域とは、呼出し元が例えば関数A
であれば、関数AのEBP領域34、関数Aへの戻り番
地33、関数Bを処理するためのパラメータ32及び関
数Aのスタック31からなる領域を示している。
By the way, when a program is processed by the above processing method, if data is written in a certain stack area in excess of the capacity of the stack area, the data is written from the top of the memory. Since the data is written downward, the contents of the caller's stack area will be destroyed. in this case,
The caller's stack area is, for example, the function A
If so, it indicates an area composed of the EBP area 34 of the function A, the return address 33 to the function A, the parameter 32 for processing the function B, and the stack 31 of the function A.

【0016】図6は、関数Bのスタック35への書込み
により関数AのEBP領域34、関数Aへの戻り番地3
3、関数Bを処理するためのパラメータ32の内容が破
壊された場合を示す説明図である。
In FIG. 6, the EBP area 34 of the function A is written to the stack 35 of the function B, and the return address 3 to the function A is 3.
FIG. 3 is an explanatory diagram showing a case where the content of the parameter 32 for processing the function B is destroyed.

【0017】この場合、関数Aへの戻り番地33が失わ
れているので、CPUは戻り番地を受け取ることができ
ず、関数Bからの戻りとして異常な番地に移行しようと
する。したがって、異常発生をすぐに検出することがで
きる。つまり、この場合は、関数Bに不具合があるとす
ぐに判明する。
In this case, since the return address 33 to the function A is lost, the CPU cannot receive the return address and tries to shift to an abnormal address as a return from the function B. Therefore, the occurrence of abnormality can be immediately detected. That is, in this case, it is immediately known that the function B has a defect.

【0018】一方、関数Bのスタック35を越えて書込
みが行われる場合であっても、関数Aへの戻り番地33
が破壊されない場合もある。図7は、関数Bのスタック
35への書込みにより関数AのEBP領域34のみが破
壊された場合を示す説明図である。
On the other hand, even when writing is performed beyond the stack 35 of the function B, the return address 33 to the function A is returned.
May not be destroyed. FIG. 7 is an explanatory diagram showing a case where only the EBP area 34 of the function A is destroyed by writing the function B to the stack 35.

【0019】図7に示すように、例えば1バイトのみ関
数Bのスタック35を越えてメモリの下側まで書込みが
行われたとき、関数AのEBP領域34の内容は異常値
となるが、関数Aへの戻り番地33及び関数Bを処理す
るためのパラメータ32の内容は正常なままである。
As shown in FIG. 7, for example, when only one byte is written over the stack 35 of the function B to the lower side of the memory, the content of the EBP area 34 of the function A becomes an abnormal value, but the function The contents of the return address 33 to A and the parameter 32 for processing the function B remain normal.

【0020】したがって、関数Bから関数Aに戻ると
き、EBPレジスタには異常な内容が入力されるが、関
数Aへの戻りそのものは正常に行われる。そして、関数
A内での処理は正常に続けられ、次に、EBPレジスタ
を使用するとき、例えば関数Aからさらに呼び出し元の
スタック領域に戻るなどのときに、初めてメモリアクセ
ス異常が発生し、異常が検出される。
Therefore, when returning from the function B to the function A, an abnormal content is input to the EBP register, but the return itself to the function A is normally performed. Then, the processing in the function A continues normally, and when the EBP register is used next time, for example, when returning from the function A to the stack area of the calling source, a memory access error occurs for the first time, and the error occurs. Is detected.

【0021】このときの異常発生は、関数Aの処理中に
起こるので、プログラマは、関数Bに原因があって当該
異常が発生したと特定することは困難である。したがっ
て、異常発生原因すなわち関数Bの不具合の検出までに
かなりの時間及び労力が必要であり、さらに、習熟した
プログラマでなければ異常原因がわからない等の問題点
があった。
Since the occurrence of the abnormality at this time occurs during the processing of the function A, it is difficult for the programmer to specify that the abnormality has occurred due to the function B. Therefore, it takes a considerable amount of time and labor to detect the cause of the abnormality, that is, the malfunction of the function B, and there is a problem that the cause of the abnormality cannot be known unless the programmer is a proficient programmer.

【0022】本発明は、このような実情を考慮してなさ
れたもので、呼出し元のスタック領域を破壊する異常な
関数等を呼び出したとき、当該関数等の異常を呼出し元
への戻り時に検出することを可能としたスタック領域破
壊検出機能付き計算機を提供することを目的とする。
The present invention has been made in consideration of such a situation, and when an abnormal function or the like that destroys the stack area of the caller is called, the abnormality of the function or the like is detected when returning to the caller. It is an object of the present invention to provide a computer with a stack area destruction detection function that enables the above.

【0023】[0023]

【課題を解決するための手段】上記課題を解決するため
に、本発明は、計算機プログラムにおける一定の処理を
行うためのスタック領域をプログラムメモリ内で確保・
解放しながら動作し、また、プログラムの動作を保証す
るためにスタック領域の底部を指し示すベースポインタ
をCPU内のレジスタに記憶し、そして、あるスタック
領域での処理動作中に新たなスタック領域を確保する場
合、プログラムメモリ内におけるあるスタック領域と新
たなスタック領域との境界附近にあるスタック領域のベ
ースポインタを保存した後に新たなスタック領域を確保
し、さらに、新たなスタック領域の底部を指し示す新た
なベースポインタをレジスタに記憶させて新たなスタッ
ク領域でのプログラムにおける他の一定の処理を行い、
一方、プログラムの動作が新たなスタック領域からある
スタック領域に戻るときに、境界付近に保存されたベー
スポインタをレジスタに戻してからプログラムの動作を
継続させる計算機にあって、プログラムメモリ内の境界
付近とは異なる、あるスタック領域のベースポインタを
保存する補助保存手段と、プログラムの動作が新たなス
タック領域からあるスタック領域に戻ったときに、この
ときのレジスタ内容と補助保存手段の内容とを比較し
て、これらが一致しない場合、その旨を報知する比較報
知手段とを備えたスタック領域破壊検出機能付き計算機
である。
In order to solve the above problems, the present invention secures a stack area in a program memory for performing a certain process in a computer program.
It operates while being released, and stores a base pointer that points to the bottom of the stack area in a register in the CPU to guarantee the operation of the program, and secures a new stack area during processing operation in a certain stack area. In this case, after saving the base pointer of the stack area near the boundary between a certain stack area and the new stack area in the program memory, a new stack area is secured, and a new stack area that indicates the bottom of the new stack area is created. Store the base pointer in a register to perform other constant processing in the program in the new stack area,
On the other hand, when a program operation returns from a new stack area to a certain stack area, the base pointer saved near the boundary is returned to the register and then the program operation continues Auxiliary saving means that saves the base pointer of a certain stack area, which is different from the above, and when the program operation returns from the new stack area to a certain stack area, compares the register contents at this time with the contents of the auxiliary saving means. Then, when these do not match, the computer with a stack area destruction detection function is provided with a comparison notifying means for notifying that effect.

【0024】[0024]

【作用】したがって、まず、本発明のスタック領域破壊
検出機能付き計算機においては、計算機プログラムにお
ける一定の処理を行うためのスタック領域が必要に応じ
てプログラムメモリ内で確保・解放されて動作してい
る。
Therefore, first, in the computer with the stack area destruction detection function of the present invention, the stack area for performing a certain process in the computer program is secured and released in the program memory as necessary to operate. .

【0025】このとき、スタック領域は、例えば関数を
実行するためのデータ入出力領域として用いられ、関数
の呼出し、戻り等に応じて確保・解放されている。そし
て、このスタック領域の確保・解放の際に、プログラム
の動作を保証するためのスタック領域の底部を指し示す
ベースポインタがCPU内のレジスタに対して入力され
ている。
At this time, the stack area is used, for example, as a data input / output area for executing a function, and is secured / released in accordance with the function call, return, and the like. Then, at the time of securing / releasing the stack area, a base pointer pointing to the bottom of the stack area for guaranteeing the operation of the program is input to the register in the CPU.

【0026】例えば、あるスタック領域での処理動作中
に新たなスタック領域を確保する場合、すなわち他の関
数等を呼び出すとき、まず、プログラムメモリ内におけ
るあるスタック領域と新たなスタック領域との境界附近
に、このときにレジスタ内に記憶されている上記あるス
タック領域のベースポインタが保存される。
For example, when a new stack area is secured during a processing operation in a certain stack area, that is, when another function is called, first, the boundary between the certain stack area and the new stack area in the program memory is first approached. At this time, the base pointer of the certain stack area stored in the register at this time is saved.

【0027】次に、新たなスタック領域が確保され、新
たなスタック領域の底部を指し示す新たなベースポイン
タがレジスタに記憶されて、新たなスタック領域でのプ
ログラムにおける他の一定の処理、すなわち目的の関数
の実行が行われる。
Next, a new stack area is secured, a new base pointer pointing to the bottom of the new stack area is stored in a register, and other constant processing in the program in the new stack area, that is, the target The function is executed.

【0028】一方、当該関数の実行が終了し、プログラ
ムの動作が新たなスタック領域からあるスタック領域に
戻るときには、上記境界付近に保存されたベースポイン
タを上記レジスタに戻してから呼出し元でのプログラム
動作が継続させる。
On the other hand, when the execution of the function ends and the operation of the program returns from a new stack area to a certain stack area, the base pointer saved near the boundary is returned to the register and then the program at the calling source. Let the operation continue.

【0029】上記計算機においては、呼び出された側の
新たなスタック領域を用いる関数等に、例えば確保され
たスタック領域の大きさを越えて書込みを行うような異
常があると、上記境界附近に保存されたベースポインタ
が破壊されてしまう。
In the above computer, if there is an abnormality such as writing over the size of the secured stack area in a function that uses the new stack area on the called side, the data is saved near the boundary. The created base pointer will be destroyed.

【0030】そこで、本発明では、プログラムメモリ内
の境界付近のものとは異なる補助保存手段によって、上
記あるスタック領域のベースポインタが保存される。そ
して、プログラムの動作が新たなスタック領域からある
スタック領域に戻ったとき、比較報知手段によって、こ
のときのレジスタ内容と補助保存手段の内容とが比較さ
れ、これらが一致しない場合、その旨が報知される。し
たがって、プログラムの実行に際して、呼び出された関
数等による呼出し元のスタック領域破壊を容易に検出す
ることができる。
Therefore, in the present invention, the base pointer of the certain stack area is stored by the auxiliary storage means different from that near the boundary in the program memory. Then, when the operation of the program returns from a new stack area to a certain stack area, the comparison and notification means compares the register contents at this time with the contents of the auxiliary storage means, and if they do not match, the fact is notified. To be done. Therefore, when the program is executed, it is possible to easily detect the stack area destruction of the caller due to the called function or the like.

【0031】[0031]

【実施例】以下、本発明の実施例について説明する。図
1は本発明に係るスタック領域破壊検出機能付き計算機
の一実施例を示す構成図である。
Embodiments of the present invention will be described below. FIG. 1 is a block diagram showing an embodiment of a computer with a stack area destruction detection function according to the present invention.

【0032】このスタック領域破壊検出機能付き計算機
は、システムバス1に接続され、各種処理を行うCPU
2と、プログラム動作のためのプログラムメモリ3を少
なくとも保存するシステムバス1に接続されたメモリ4
と、その他の図示しない周辺要素とからなっている。
This computer with a stack area destruction detection function is a CPU that is connected to the system bus 1 and performs various processes.
2 and a memory 4 connected to the system bus 1 for storing at least a program memory 3 for program operation
And other peripheral elements (not shown).

【0033】また、特にこだわらないかぎり、本計算機
を動作させるプログラムはC言語で記述されているもの
とする。CPU2には、EBPレジスタ5とESPレジ
スタ6とが具備されており、これらの各レジスタ5,6
は、従来例で説明した通り、それぞれベースポインタの
レジスタ及びスタックポインタのレジスタとして機能す
る。
Unless otherwise specified, the program for operating this computer is written in C language. The CPU 2 is provided with an EBP register 5 and an ESP register 6, and these registers 5 and 6 are provided.
Respectively function as a base pointer register and a stack pointer register, as described in the conventional example.

【0034】プログラムメモリ3には、スタックAまで
のスタック部7と、スタックA部8と、スタックB部9
とが確保されており、これらの領域はメモリの下側から
順に確保されている。
In the program memory 3, the stack unit 7 up to the stack A, the stack A unit 8 and the stack B unit 9 are stacked.
Are secured, and these areas are secured in order from the lower side of the memory.

【0035】なお、従来例で説明した通り、これらの各
スタック部、又、図示しないスタック部は、プログラム
の処理にしたがって確保、解放されるものである。ま
た、スタックA部8は、関数Aのスタック8aと、戻り
番地・パラメータ部8bと、スタックAのEBP保存部
8cとによって構成されている。
As explained in the conventional example, each of these stack parts, and a stack part not shown in the figure, are secured and released according to the processing of the program. The stack A unit 8 includes a stack 8a for the function A, a return address / parameter unit 8b, and an EBP storage unit 8c for the stack A.

【0036】ここで、関数Aのスタック8aは、従来例
の関数Aのスタック31に対応するものである。また、
戻り番地・パラメータ部8bは、従来例の関数Bを処理
するためのパラメータ32及び関数Aへの戻り番地33
と同様な構成を有するものである。さらに、スタックA
のEBP保存部8cも、従来例の関数AのEBP領域3
4と同様な構成を有する。
Here, the stack 8a of the function A corresponds to the stack 31 of the function A of the conventional example. Also,
The return address / parameter section 8b includes a parameter 32 for processing the function B of the conventional example and a return address 33 to the function A.
It has the same configuration as. Furthermore, stack A
The EBP saving unit 8c of the EBP area 3 of the function A of the conventional example also
It has the same configuration as that of No. 4.

【0037】また、スタックB部9も、関数Bのスタッ
ク9aにスタックA部8と同様な保存・比較・通知部1
0,11,12等を備え、また、図示しないその他のス
タック部も必要に応じてスタックA部8と同様な保存・
比較・通知部10,11,12等を備えている。なお、
これらの各スタックの構成状態は、プログラムの動作状
況によって決まる。
Further, the stack B unit 9 also stores in the stack 9a of the function B the same storage / comparison / notification unit 1 as the stack A unit 8.
0, 11, 12, etc., and other stack parts not shown in the figure are stored and stored in the same manner as the stack A part 8 if necessary.
The comparison / notification units 10, 11, 12 and the like are provided. In addition,
The configuration status of each of these stacks depends on the operating status of the program.

【0038】ここで、関数Aのスタック8aには、EB
P取込・比較部10とチェック用EBP保存部11と異
常通知部12とが設けられている。なお、関数Bのスタ
ック9a等の他の各スタック部が存在する場合には同様
な構成が設けられる。
Here, in the stack 8a of the function A, the EB
A P capture / comparison unit 10, a check EBP storage unit 11, and an abnormality notification unit 12 are provided. A similar configuration is provided when other stack parts such as the stack 9a of the function B exist.

【0039】一方、スタックA部までのスタック部7に
は、EBPレジスタ読込部13が設けられている。EB
P取込・比較部10は、例えば関数Bのように新たなス
タック部を作成することになる関数等を呼び出す直前
に、そのときのEBPレジスタ5の内容,具体的にはア
ドレスA1を取り込み、チェック用EBP保存部11に
保存するようになっている。そして、関数B処理の終了
後、チェック用EBP保存部11の内容とEBPレジス
タ5の内容とを比較し、これらが一致していなければ異
常通知部12に通知されるようになっている。
On the other hand, the EBP register reading section 13 is provided in the stack section 7 up to the stack A section. EB
The P capture / comparison unit 10 captures the contents of the EBP register 5 at that time, specifically, the address A1 immediately before calling a function or the like that creates a new stack unit such as the function B, It is adapted to be stored in the check EBP storage unit 11. After the end of the function B processing, the contents of the check EBP storage unit 11 and the contents of the EBP register 5 are compared, and if they do not match, the abnormality notification unit 12 is notified.

【0040】図2は関数A内におけるEBP取込・比較
部10等の具体的なプログラム例を示す図である。つま
り、図2に示すように、プログラム行P1においてEB
Pレジスタ読込部13の一例であるGetEBP()を
用いて、チェック用EBP保存部11の一例であるSa
veEBPにEBPレジスタ5の内容を保存する。
FIG. 2 is a diagram showing a concrete program example of the EBP fetch / comparison section 10 in the function A. That is, as shown in FIG. 2, in the program line P1, EB
Using GetEBP () which is an example of the P register reading unit 13, Sa which is an example of the check EBP storage unit 11 is used.
The contents of the EBP register 5 are saved in veEBP.

【0041】次のプログラム行P2において関数Bを実
行させ、関数B終了後、すなわち、EBPレジスタ5が
スタックAのEBP保存部8cの値を受け取った後に、
プログラム行P3の前段P3aにおいて、当該EBPレ
ジスタ5の内容(GetEBP())とチェック用EB
P保存部11の内容(SaveEBP)とを比較するよ
うになっている。そして、SaveEBP!=GetE
BP()すなわち、一致していなければ、異常通知部1
2の一例であるプログラム行P3の後段P3bを実行し
て、異常通知を出力する。
In the next program line P2, the function B is executed, and after the function B is completed, that is, after the EBP register 5 receives the value of the EBP storage unit 8c of the stack A,
In the previous stage P3a of the program line P3, the contents of the EBP register 5 (GetEBP ()) and the check EB
The contents of the P storage unit 11 (SaveEBP) are compared. And SaveEBP! = GetE
BP (), that is, if they do not match, the abnormality notification unit 1
The second stage P3b, which is an example of the program line P3, is executed to output the abnormality notification.

【0042】一方、EBPレジスタ読込部13の一例と
しての関数GetEBP()は、アセンブラ言語で作成
されており、EBPレジスタ5の内容を読込めるように
なっている。ここで、アセンブラ言語で記述するのは、
CPU内のハードウェアレジスタの値をそのまま読込む
ためである。また、C言語へのインターフェースとして
は、この関数の戻り値がEBPレジスタを示すように設
計することにより、C言語ライクな関数として使用する
ことが可能となっている。
On the other hand, the function GetEBP (), which is an example of the EBP register reading unit 13, is created in the assembler language and can read the contents of the EBP register 5. Here, what is written in assembler language is
This is because the value of the hardware register in the CPU is read as it is. Further, as an interface to the C language, by designing the return value of this function to indicate the EBP register, it can be used as a C language-like function.

【0043】図3はEBPレジスタ読込部13の具体的
なプログラム例を示す図である。また、図1において
は、EBPレジスタ読込部13は、スタックAまでのス
タック部7に設けられているとしたが、例えば他領域に
あるスタック部として設けられてもよい。つまり、EB
Pレジスタ読込部13は、関数B等の書込みによって破
壊されない領域に設けられていればよい。
FIG. 3 is a diagram showing a specific program example of the EBP register reading unit 13. Further, in FIG. 1, the EBP register reading unit 13 is provided in the stack unit 7 up to the stack A, but may be provided as a stack unit in another area, for example. That is, EB
The P register reading unit 13 may be provided in an area that is not destroyed by writing the function B or the like.

【0044】なお、EBPレジスタ読込部13とチェッ
ク用EBP保存部11とによって補助保存手段の一例が
構成されており、EBP取込・比較部10と異常通知部
12とによって比較報知手段の一例が構成されている。
The EBP register reading unit 13 and the checking EBP storage unit 11 constitute an example of an auxiliary storage unit, and the EBP import / comparison unit 10 and the abnormality notification unit 12 constitute an example of a comparison notification unit. It is configured.

【0045】次に、以上のように構成された本実施例の
スタック領域破壊検出機能付き計算機の動作について説
明する。図4は本実施例の動作を示す流れ図である。
Next, the operation of the computer with the stack area destruction detection function of this embodiment constructed as described above will be explained. FIG. 4 is a flow chart showing the operation of this embodiment.

【0046】図4において、まず、関数Aが実行されて
いる(ST1)。次に、関数Aの実行中で関数Bを呼び
出したいとき、呼び出し前にEBPレジスタ5の内容を
読込みチェック用EBP保存部11に保存する(ST
2)。
In FIG. 4, first, the function A is executed (ST1). Next, when it is desired to call the function B while the function A is being executed, the contents of the EBP register 5 are stored in the read check EBP storage unit 11 before the call (ST
2).

【0047】そして、関数Bを実行する(ST3)が、
関数Bのスタック9aを確保するときに、従来例で説明
したように、関数Aのスタック8aの上に関数Aへの戻
り番地等及び関数AのEBPがそれぞれ戻り番地・パラ
メータ部8b及びスタックAのEBP保存部8cに保存
される。
Then, the function B is executed (ST3).
When the stack 9a of the function B is secured, the return address to the function A and the EBP of the function A are provided on the stack 8a of the function A and the return address / parameter section 8b and the stack A, respectively, as described in the conventional example. Is stored in the EBP storage unit 8c.

【0048】関数Bの実行が終了するとき、スタックA
のEBP保存部8cの値がEBPレジスタ5に入力され
る。そこで、関数A内のEBP取込・比較部10は、関
数Aの処理を再開する前に、このときのEBPレジスタ
5の内容を読込み(ST4)、これを先に保存しておい
た関数Aのスタック8aのチェック用EBP保存部11
の内容と比較する(ST5)。
When the execution of the function B ends, the stack A
The value of the EBP storage unit 8c is input to the EBP register 5. Therefore, the EBP fetching / comparing unit 10 in the function A reads the contents of the EBP register 5 at this time before restarting the processing of the function A (ST4), and saves the previously stored function A Check EBP storage unit 11 of stack 8a
(ST5).

【0049】ここで、当該EBPレジスタ5の内容とチ
ェック用EBP保存部11の内容とが異なっていれば、
少なくともスタックAのEBP保存部8cの内容が破壊
されていると判定できるので、関数Bは、呼出し元のス
タック領域を破壊する異常な関数である旨の通知を行う
(ST6)。
Here, if the contents of the EBP register 5 and the contents of the check EBP storage unit 11 are different,
Since it can be determined that at least the contents of the EBP storage unit 8c of the stack A are destroyed, the function B notifies that it is an abnormal function that destroys the stack area of the caller (ST6).

【0050】一方、上記各内容が同じであれば、呼出し
元のスタック領域は破壊されていないので、処理を継続
する(ST7)。上述したように、本実施例によるスタ
ック領域破壊検出機能付き計算機は、新たなスタック部
として関数Bのスタック9aを確保する際に、EBPレ
ジスタ読込部13によって、スタックAのEBP保存部
8cとは別のチェック用EBP保存部11にEBPレジ
スタ5の内容を保存し、関数Bから関数Aに戻った直後
に、EBP取込・比較部10によって、スタックAのE
BP保存部8cの内容を戻されたEBPレジスタ5内容
とチェック用EBP保存部11内容とを比較し、両者が
一致しないときには、異常通知部12とによってその旨
を報知するようにしたので、呼出し元のスタック領域を
破壊する異常な関数が呼び出したとき、この異常な関数
を検出し、呼出し元スタック領域が破壊されたことを通
知することができる。
On the other hand, if the above contents are the same, the stack area of the caller has not been destroyed, so the processing is continued (ST7). As described above, in the computer with the stack area destruction detection function according to the present embodiment, when the stack 9a of the function B is secured as a new stack unit, the EBP register reading unit 13 causes the EBP storage unit 8c of the stack A to The contents of the EBP register 5 are saved in another check EBP saving unit 11, and immediately after returning from the function B to the function A, the EBP fetching / comparing unit 10 causes the E of the stack A to be deleted.
The contents of the returned BP storage unit 8c are compared with the contents of the returned EBP register 5 and the contents of the check EBP storage unit 11, and when the two do not match, the abnormality notification unit 12 notifies the fact. When an abnormal function that destroys the original stack area is called, the abnormal function can be detected and the fact that the caller stack area has been destroyed can be notified.

【0051】また、図2、図3のプログラム例に示すよ
うに、上記各手段は非常に短いプログラムで実現できる
ので、プログラム実行速度をあまり落とすことなく、上
記機能を実現することができる。特に、EBPレジスタ
読込部13は、アセンブラ言語で記述することにより、
機械語の2命令しか必要とせず、プログラム実行速度に
対する悪影響はほとんどない。
Further, as shown in the program examples of FIGS. 2 and 3, each of the above means can be realized by a very short program, so that the above functions can be realized without reducing the program execution speed so much. In particular, the EBP register reading unit 13 is written in assembler language,
Since only two machine language instructions are required, there is almost no adverse effect on the program execution speed.

【0052】したがって、上記異常を起こす関数等を少
ない労力でかつ短時間で検出することができる。さら
に、本実施例の装置を用いれば、習熟度の低いプログラ
マであってもの容易に当該異常を検出することができ
る。
Therefore, it is possible to detect a function or the like that causes the above abnormality with a small labor and in a short time. Furthermore, by using the apparatus of the present embodiment, even a programmer with a low proficiency level can easily detect the abnormality.

【0053】また、本実施例においては、EBPレジス
タ読込部13をアセンブラ言語で作成したが、プログラ
マの便宜を図るためC言語で作成してもよい。この場
合、プログラム全体が、プログラマにとって扱い易いも
のとなる。
Further, in this embodiment, the EBP register reading unit 13 is made in assembler language, but it may be made in C language for the convenience of the programmer. In this case, the entire program becomes easy for the programmer to handle.

【0054】さらに、本実施例においては、異常通知部
12をスタックA部8内に設けたが、これは、スタック
Aまでのスタック部7等の他の記憶領域に設けてもよ
く、関数を呼び出す形で処理してもよい。なお、本発明
は、上記各実施例に限定されるものでなく、その要旨を
逸脱しない範囲で種々に変形することが可能である。
Further, in the present embodiment, the abnormality notifying section 12 is provided in the stack A section 8. However, it may be provided in another storage area such as the stack section 7 up to the stack A, and the function You may process by calling. It should be noted that the present invention is not limited to the above-described embodiments, but can be variously modified without departing from the scope of the invention.

【0055】[0055]

【発明の効果】以上詳記したように本発明によれば、E
BPレジスタの内容をEBP保存部とは別の他の保存部
に記憶し、関数戻り時に両者を比較するようにしたの
で、呼出し元のスタック領域を破壊する異常な関数等を
呼び出したとき、当該関数等の異常を呼出し元への戻り
時に検出することを可能としたスタック領域破壊検出機
能付き計算機を提供する。
As described above in detail, according to the present invention, E
The contents of the BP register are stored in another storage unit other than the EBP storage unit, and the two are compared when the function returns, so when an abnormal function that destroys the stack area of the calling source is called, Provided is a computer with a stack area destruction detection function capable of detecting an abnormality such as a function when returning to a caller.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明に係るスタック領域破壊検出機能付き計
算機の一実施例を示す構成図。
FIG. 1 is a configuration diagram showing an embodiment of a computer with a stack area destruction detection function according to the present invention.

【図2】同実施例における関数A内におけるEBP取込
・比較部の具体的なプログラム例を示す図。
FIG. 2 is a diagram showing a specific program example of an EBP import / comparison unit in a function A in the embodiment.

【図3】同実施例におけるEBPレジスタ読込部の具体
的なプログラム例を示す図。
FIG. 3 is a diagram showing a specific program example of an EBP register reading unit in the embodiment.

【図4】同実施例の動作を示す流れ図。FIG. 4 is a flowchart showing the operation of the embodiment.

【図5】従来の計算機におけるスタック領域の確保・解
放を伴うプログラム処理の進行を説明する図。
FIG. 5 is a diagram for explaining the progress of program processing that involves securing and releasing a stack area in a conventional computer.

【図6】従来の計算機における関数Bのスタックへの書
込みによる関数Aについてのスタック領域の一部が破壊
された場合を示す説明図。
FIG. 6 is an explanatory diagram showing a case where a part of the stack area for the function A is destroyed by writing the function B to the stack in the conventional computer.

【図7】従来の計算機における関数Bのスタックへの書
込みによる関数AのEBP領域のみが破壊された場合を
示す説明図。
FIG. 7 is an explanatory diagram showing a case where only the EBP area of the function A is destroyed by writing the function B to the stack in the conventional computer.

【符号の説明】[Explanation of symbols]

1…システムバス、2…CPU、3…プログラムメモ
リ、5…EBPレジスタ、6…ESPレジスタ、7…ス
タックAまでのスタック部、8…スタックA部、9…ス
タックB部、10…EBP取込・比較部、11…チェッ
ク用EBP保存部、12…異常通知部、13…EBPレ
ジスタ読込部。
1 ... System bus, 2 ... CPU, 3 ... Program memory, 5 ... EBP register, 6 ... ESP register, 7 ... Stack part up to stack A, 8 ... Stack A part, 9 ... Stack B part, 10 ... EBP import -Comparison unit, 11 ... Check EBP storage unit, 12 ... Abnormality notification unit, 13 ... EBP register reading unit.

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】 計算機プログラムにおける一定の処理を
行うためのスタック領域をプログラムメモリ内で確保・
解放しながら動作し、また、前記プログラムの動作を保
証するために前記スタック領域の底部を指し示すベース
ポインタをCPU内のレジスタに記憶し、そして、ある
スタック領域での処理動作中に新たなスタック領域を確
保する場合、前記プログラムメモリ内における前記ある
スタック領域と前記新たなスタック領域との境界附近に
前記あるスタック領域のベースポインタを保存した後に
前記新たなスタック領域を確保し、さらに、前記新たな
スタック領域の底部を指し示す新たなベースポインタを
前記レジスタに記憶させて前記新たなスタック領域での
前記プログラムにおける他の一定の処理を行い、一方、
前記プログラムの動作が前記新たなスタック領域から前
記あるスタック領域に戻るときに、前記境界付近に保存
されたベースポインタを前記レジスタに戻してから前記
プログラムの動作を継続させる計算機にあって、 前記プログラムメモリ内の前記境界付近とは異なる、前
記あるスタック領域のベースポインタを保存する補助保
存手段と、 前記プログラムの動作が前記新たなスタック領域から前
記あるスタック領域に戻ったときに、このときの前記レ
ジスタ内容と前記補助保存手段の内容とを比較して、こ
れらが一致しない場合、その旨を報知する比較報知手段
とを備えたことを特徴とするスタック領域破壊検出機能
付き計算機。
1. A stack area is secured in a program memory for performing a certain process in a computer program.
It operates while being released, and stores a base pointer pointing to the bottom of the stack area in a register in the CPU in order to guarantee the operation of the program, and a new stack area is stored during a processing operation in a certain stack area. To secure the new stack area after storing the base pointer of the certain stack area near the boundary between the certain stack area and the new stack area in the program memory. A new base pointer pointing to the bottom of the stack area is stored in the register to perform some other constant processing in the program in the new stack area, while:
A computer which, when the operation of the program returns from the new stack area to the certain stack area, returns the base pointer stored near the boundary to the register and then continues the operation of the program, Auxiliary storage means for storing a base pointer of the certain stack area, which is different from the vicinity of the boundary in the memory, and when the operation of the program returns from the new stack area to the certain stack area. A computer with a stack area destruction detection function, comprising: a register notifying unit that compares the register contents with the contents of the auxiliary storage unit and, if they do not match, informs to that effect.
JP7052951A 1995-03-13 1995-03-13 Computer with stack area destruction detection function Pending JPH08249206A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP7052951A JPH08249206A (en) 1995-03-13 1995-03-13 Computer with stack area destruction detection function

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP7052951A JPH08249206A (en) 1995-03-13 1995-03-13 Computer with stack area destruction detection function

Publications (1)

Publication Number Publication Date
JPH08249206A true JPH08249206A (en) 1996-09-27

Family

ID=12929197

Family Applications (1)

Application Number Title Priority Date Filing Date
JP7052951A Pending JPH08249206A (en) 1995-03-13 1995-03-13 Computer with stack area destruction detection function

Country Status (1)

Country Link
JP (1) JPH08249206A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007148529A (en) * 2005-11-24 2007-06-14 Nippon Telegr & Teleph Corp <Ntt> Buffer overflow detection device, buffer overflow detection method, and buffer overflow detection program
JP2010198147A (en) * 2009-02-24 2010-09-09 Mitsubishi Heavy Ind Ltd Protection method for data in stack area in computer memory
JP2012216111A (en) * 2011-04-01 2012-11-08 Silex Technology Inc Directory scanning program
JP2020533683A (en) * 2017-09-15 2020-11-19 エイアールエム リミテッド Call path dependent authentication

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007148529A (en) * 2005-11-24 2007-06-14 Nippon Telegr & Teleph Corp <Ntt> Buffer overflow detection device, buffer overflow detection method, and buffer overflow detection program
JP2010198147A (en) * 2009-02-24 2010-09-09 Mitsubishi Heavy Ind Ltd Protection method for data in stack area in computer memory
JP2012216111A (en) * 2011-04-01 2012-11-08 Silex Technology Inc Directory scanning program
JP2020533683A (en) * 2017-09-15 2020-11-19 エイアールエム リミテッド Call path dependent authentication

Similar Documents

Publication Publication Date Title
KR101249693B1 (en) Selecting subroutine return mechanisms
JPH0682320B2 (en) Data processing device
JPH08249206A (en) Computer with stack area destruction detection function
KR100280590B1 (en) Electronic device
JP2001265620A (en) Program debugging system for rom
JPS60159951A (en) Tracing system in information processing device
JPH0731617B2 (en) Program runaway detection method
JP2671160B2 (en) Exception handling method
JPS61141047A (en) Saving system of trouble information
JP3263999B2 (en) Program content analyzer
WO1990005951A1 (en) Method of handling unintended software interrupt exceptions
JPH0782460B2 (en) How to check the recording medium
EP1104899A2 (en) Data processing apparatus and method of controlling the same
JP2504151B2 (en) Data processing device
JP2833933B2 (en) In-circuit emulator
JPH04167146A (en) Address tracing system for information processor
JPH05334118A (en) Preceding detection system for program step to be cause of program interruption
JP2000353109A (en) Emulator and emulation system
JPH07210421A (en) Debugging method in thread environment
JPH01201728A (en) Program correcting system
JPS5958550A (en) Instruction fetch trap control system
JPH09160800A (en) Emulator
JP2001265619A (en) Data tracing system
JPH02244345A (en) Information processor
JPS59153247A (en) Debugging device