CN100487658C - Method for detecting memory accessing outside - Google Patents

Method for detecting memory accessing outside Download PDF

Info

Publication number
CN100487658C
CN100487658C CNB2006101032630A CN200610103263A CN100487658C CN 100487658 C CN100487658 C CN 100487658C CN B2006101032630 A CNB2006101032630 A CN B2006101032630A CN 200610103263 A CN200610103263 A CN 200610103263A CN 100487658 C CN100487658 C CN 100487658C
Authority
CN
China
Prior art keywords
memory
information
protection
memory block
address
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.)
Active
Application number
CNB2006101032630A
Other languages
Chinese (zh)
Other versions
CN101110042A (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.)
ZTE Corp
Original Assignee
ZTE 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 ZTE Corp filed Critical ZTE Corp
Priority to CNB2006101032630A priority Critical patent/CN100487658C/en
Publication of CN101110042A publication Critical patent/CN101110042A/en
Application granted granted Critical
Publication of CN100487658C publication Critical patent/CN100487658C/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The utility model discloses a method to examine the over-step of memory access. When the memory block applied from the memory pool is used by the application program, the over-step of memory access can be examined. The main procedures comprise: the address information of the transfer code is added on the top of the applied memory block for the application program and the protective characters and the length information of the free space is added in the rear. Also, the protective marks are added in the free space, so as to examine the over-step of memory access when the memory is released from the application program and prompt the related abnormal information, including the address information of the transfer code. The method of the utility model makes a little change on the existing memory management system, which has the advantages of easy application and useful practicability.

Description

A kind of method that detects memory accessing outside
Technical field
The present invention relates to a kind of method that detects memory accessing outside, specifically, refer to detect in the embedded real time system application program especially and in the process of using the memory block of being applied for, whether exist internal memory to write the situation of crossing the border, and the relevant abnormal information of prompting.
Background technology
In embedded real time system, application program is quite high to the frequency of utilization of internal memory, especially needs to apply for continually and releasing memory.And the dynamic memory management method that embedded real-time operating system provides is at generalized case, the interface of internal memory application and release is provided for application program, on the one hand, the execution efficiency ratio of calling these interfaces is lower, on the other hand, frequently call these interface applications and releasing memory and can form too much memory fragmentation, not only efficient is carried out in influence, also causes the internal memory waste.
At present, when in embedded real time system, carrying out applied software development, in most cases, can be on the operating system basis form the EMS memory management process that is fit to self-demand, the memory management interfaces of operating system is encapsulated, offer application program and use.Such EMS memory management process may be diversified, but generally have some basic common traits: at first create a memory pool by the application memory interface of one or many call operation system, memory pool is made up of the memory block of various fixed sizes, the memory block of general identical size is formed a zone, safeguards memory pool by chained list or other data structure; During the application program internal memory, distribute a free memory piece that is not less than the size of applying for to it.The memory block that is distributed is often greater than apply for size, and the part that exceeds the application size in the memory block is the free area, and application program should not visited this zone.
Application program obtains an internal memory pointer behind memory block, can carry out read-write operation to the memory block zone by this pointer.Under a lot of situations, because the carelessness that program code is write can cause the memory accessing outside problem, such as, write the fashionable address realm that exceeds the memory block of applying for, covered other region of memory, may cause program run unusual.Sometimes, though do not exceed the address realm of memory block, exceeded the size of applying for, just covered the free area in the memory block, this situation not necessarily causes program run unusual, but belongs to the program code mistake equally, also is hidden danger in the program run as untimely discovery.
In the prior art, for solving the memory accessing outside problem, attempt to detect in real time the memory accessing outside situation, require the internal storage access operation of application program all to be undertaken by the interface of special encapsulation, in interface, the memory address and the scope of visit are checked, and then judged whether to exist visit to cross the border.Advantage is can detect the memory overwriting situation in real time to a certain extent, but following shortcoming is arranged: at first, application program all needs to be undertaken by package interface to the read-write operation of internal memory, will inevitably reduce running efficiency of system greatly, and this is unacceptable to embedded real time system; Secondly, application program is arbitrarily to the use-pattern of application internal memory, can also can deposit the data of certain data structure directly by internal memory pointer visit address wherein, if all need be undertaken, cause great inconvenience can for writing of program code by package interface; At last, realize that this internal-memory detection method need provide special EMS memory management process, it can not be applied in other EMS memory management process easily.
Summary of the invention
Technical matters to be solved by this invention is to provide a kind of method that detects memory accessing outside, to solve the memory accessing outside problem, especially refer to detect in the embedded real time system application program and in the process of using the memory block of being applied for, whether exist internal memory to write the situation of crossing the border, and the relevant abnormal information of prompting.
In order to address the above problem, the invention provides a kind of method that detects memory accessing outside, use in the process of the memory block of from memory pool, applying in application program, whether detection exists internal memory to write the situation of crossing the border, and it comprises the steps:
When (1) creating memory pool, if free space size of initialization is the memory block of Size, then needing full memory space for its distribution is that free space size Size adds the front-end information that need add by this memory block and the tail end information big or small sum that taken up space, wherein, described tail end information comprises protection word information, free area length information;
(2) during the application program internal memory, if for it finds a suitable memory block, then the protection word in the tail end information of described memory block is set at the protection mark, with the free area length setting is the value that memory block size Size deducts the user applies size, if free area length is non-vanishing, then, fill the protection mark at predeterminable area from described free area start address;
(3) during the application program releasing memory, whether the protection word that detects in the tail end information is the protection mark of setting, if not, then point out the abnormal information of memory accessing outside; If the protection word is the protection mark of setting, then detect the zone of having filled the protection mark in the free area, when finding that the somewhere is not the protection mark of setting, the abnormal information of prompting memory accessing outside.
Further, method of the present invention, its step further comprises in (1): described front-end information comprises header information, application code address information, and described memory block free space is divided into user data area and free area when reality is used;
Step further comprises in (2): fill in header information in the front-end information of described memory block, and will apply for that code address is set at the code address that calls the application memory interface that is obtained;
Step further comprises in (3): comprise application code address information in the abnormal information of described prompting memory accessing outside.
Further, in its described step (2),, then in application code address information, only need record-shifted address if application program has only a code segment; If application program comprises a plurality of code segments, the further sector address of record code in application code address information then.
Further, method of the present invention, in its described step (2), the protection that the protection word in the tail end information is set is labeled as special uncommon numerical value; The protection of filling in the free area is labeled as special uncommon numerical value; In the free area, fill the length of the presumptive area of protection mark, determine with strategy according to actual needs.
Method of the present invention, it further comprises:
(4) the application code address information that comprises in the abnormal information according to described prompting memory accessing outside, in program code, position, determine that described memory block applies for wherein, and and then determine the situation of crossing the border that writes that exists in the described memory block use.
Further, the described code address that calls the application memory interface of its step (2) obtains by an interface function, and this interface function is when calling in certain function F uncA, and its rreturn value is the address of calling the code of FuncA; Its described interface function is recalled backward according to function call chain in the storehouse, obtains the return address when calling the FuncA function, and with this return address as FuncA function calls code address.
The starting point of the method for the invention, not to detect the memory accessing outside situation in real time, whether exist internal memory to write the situation of crossing the border but when the application program releasing memory, detect in the use of this memory block, can not influence in the existing internal storage management system application program fully the use of internal memory.The method of the invention is not only checked memory block tail part protection word, also checks the free area, has carried out checking very completely; Secondly, when the method for the invention is pointed out the abnormal information of memory accessing outside, comprised application code address information, can position in program code according to this information, determine that this memory block applies for wherein, and then analyze to determine the situation of crossing the border that writes that exists in the memory block use, be very easy to the software developer and analyze problem in the code.Method of the present invention is very little to the change of existing EMS memory management process, can be easy to be applied in the existing internal storage management system, has very strong practicality.
Description of drawings
Fig. 1 is the synoptic diagram of the memory block information of the described existing EMS memory management process maintenance of the embodiment of the invention;
Fig. 2 is the synoptic diagram after the described memory block of the embodiment of the invention increases the protection information of front end and tail end.
Embodiment
Below in conjunction with accompanying drawing, the described technical scheme of the embodiment of the invention is described in further detail.
As shown in Figure 1, in the existing internal storage management system, generally front-end information is arranged in the definition of memory block front end, be used to administer and maintain memory block, and do not define or seldom define tail end information in the memory block rear end, for embodiment describes for simplicity, hypothesis did not define tail end information during the back was described, however, method of the present invention is equally applicable to define the EMS memory management process of tail end information.
As shown in Figure 2, the method for the invention increases application code address information 103 in the structure of existing front-end information.Generally speaking, in embedded real time system, application program has only a code segment, therefore only needs record-shifted address.If application program comprises a plurality of code segments, then also need in application code address information, increase the sector address of record code.For embodiment describes for simplicity, hypothesis had only a code segment during the back was described.The C language definition of new front-end information structure is exemplified as:
typedef?struct?tagHead
{
... the existing header information member of/* */
unsigned?long?GetEIP;
}?THead;
The type of GetEIP can determine that example is the definition in 32 bit CPU systems as mentioned above according to cpu type.
Method of the present invention increases tail end protection information at the memory block tail end, comprises protection word 104 and free area length 105.Organization definition is exemplified as:
typedef?struct?tagTail
{
unsigned?long?TailTag;
unsigned?short?UnusedSize;
}?TTail;
Front end and tail end protection information according to increase of the present invention when creating memory pool, need to do certain change on existing EMS memory management process basis, concrete grammar is as follows:
When (1) free space size of initialization was the memory block of Size, the memory headroom that actual needs distributes was THead size, TTail size and Size sum.
(2) GetEIP among the THead is set at 0.
(3) TailTag among the TTail is set at MEM_TAIL_TAG (tail end protection mark), UnusedSize among the TTail is set at 0.MEM_TAIL_TAG is a more special uncommon numerical value, as 0xFCFCFCFC etc.
According to method of the present invention, the application memory interface need be set protection information at the memory block front end and the tail end that are application assigned, and step is as follows:
(1) suppose that the memory size that application program will be applied for is UsedSize, reality be its distribution memory block size for Size (Size 〉=UsedSize).
(2) call the interface that obtains current function call code address and obtain the code address (application code address 103) that calls this application memory interface, the GetEIP among the THead is set at application code address information.See hereinafter description for details about the interface description of obtaining current function call code address.
(3) TailTag among the TTail is set at MEM_TAIL_TAG, UnusedSize is set at Size-UsedSize.
(4) according to the memory block header information address and the big or small UsedSize that applies for, calculate free area 102 start addresses.According to UnsedSize and actual conditions needs; determine the protection length ProtectSize in the free area 102, such as, ProtectSize equals UnusedSize in the Debug version; and in the Release version for raising the efficiency, restriction ProtectSize can not surpass predetermined maximum value.102 start addresses from the free area are set at MEM_UNUSED_TAG (idle protection mark) with each byte in the region of memory of ProtectSize size.MEM_UNUSED_TAG is a more special uncommon numerical value, as 0xFC etc.
According to method of the present invention, whether the releasing memory interface need exist internal memory to write the situation of crossing the border according to protecting word 104 and free area 105 detect in the tail end information, and step is as follows:
(1) can calculate memory block header information 101 addresses according to the internal memory pointer in the input parameter, generally can obtain memory block available size Size, calculate the tail end message address according to header information 101 addresses and internal memory available size Size again according to header information 101.
(2) read protection word 104 in the tail end information according to the tail end message address; whether check protection word 104 is predefined value (MEM_TAIL_TAG); if; continue step (3); otherwise the abnormal information of prompting memory accessing outside is comprising the application code address GetEIP that obtains from front-end information.
(3), calculate free area 102 start addresses, and determine free area protection length ProtectSize according to same policy in the application memory interface according to the UnusedSize among the tail end information TTail.102 start addresses from the free area check one by one whether the value of each byte in the zone of ProtectSize size is predefined value (MEM_UNUSED_TAG).If finding the value of certain byte is not MEM_UNUSED_TAG, then point out the abnormal information of memory accessing outside, comprising the application code address GetEIP that from front-end information, obtains.
According to method of the present invention, an interface that obtains current function call code address need be provided, its function and realization are described below:
If this interface function is called GetEIPFunc, its function is that its rreturn value is the address of calling the code of FuncA when GetEIPFunc calls in certain function F uncA.
Its implementation is according to function call chain in the storehouse, recalls backward, obtains the return address when calling the FuncA function, and we see this return address as FuncA function calls code address.Specific implementation is different and different according to cpu type and compiler.
Above-mentioned embodiment describes the present invention with preferred embodiment, should not be regarded as limitation of the scope of the invention.Equally, according to the description of technical scheme of the present invention and preferred embodiment thereof, can make various possible being equal to and change or replacement, and all these changes or replacement all should belong to the protection domain of claim of the present invention.

Claims (7)

  1. Whether 1, a kind of method that detects memory accessing outside is used in the process of the memory block of applying for from memory pool in application program, detect to exist internal memory to write the situation of crossing the border, and it is characterized in that, comprises the steps:
    When (1) creating memory pool, if free space size of initialization is the memory block of Size, then needing full memory space for its distribution is that free space size Size adds the front-end information that need add by this memory block and the tail end information big or small sum that taken up space, wherein, described front-end information comprises header information, application code address information, and described tail end information comprises protection word information, free area length information;
    (2) during the application program internal memory, if for it finds a suitable memory block, then the protection word in the tail end information of described memory block is set at the protection mark, with the free area length setting is the value that memory block size Size deducts the user applies size, if free area length is non-vanishing, then, fill the protection mark at predeterminable area from described free area start address;
    (3) during the application program releasing memory, whether the protection word that detects in the tail end information is the protection mark of setting, if not, then point out the abnormal information of memory accessing outside; If the protection word is the protection mark of setting, then detect the zone of having filled the protection mark in the free area, when finding that the somewhere is not the protection mark of setting, the abnormal information of prompting memory accessing outside.
  2. 2, the method for claim 1 is characterized in that, step further comprises in (1): described memory block free space is divided into user data area and free area when reality is used;
    Step further comprises in (2): fill in header information in the front-end information of described memory block, and will apply for that code address is set at the code address that calls the application memory interface that is obtained;
    Step further comprises in (3): comprise application code address information in the abnormal information of described prompting memory accessing outside.
  3. 3, method as claimed in claim 2 is characterized in that, in the described step (2), if application program has only a code segment, then only needs record-shifted address in application code address information.
  4. 4, method as claimed in claim 2 is characterized in that, in the described step (2), if application program comprises a plurality of code segments, and the further sector address of record code in application code address information then.
  5. 5, the method for claim 1 is characterized in that, in the described step (2), the protection that the protection word in the tail end information is set is labeled as special uncommon numerical value.
  6. 6, the method for claim 1 is characterized in that, in the described step (2), the protection of filling in the free area is labeled as special uncommon numerical value.
  7. 7, method as claimed in claim 2, it is characterized in that the described code address that calls the application memory interface of step (2) obtains by an interface function, this interface function is when calling in certain function F uncA, and its rreturn value is the address of calling the code of FuncA.
CNB2006101032630A 2006-07-20 2006-07-20 Method for detecting memory accessing outside Active CN100487658C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2006101032630A CN100487658C (en) 2006-07-20 2006-07-20 Method for detecting memory accessing outside

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2006101032630A CN100487658C (en) 2006-07-20 2006-07-20 Method for detecting memory accessing outside

Publications (2)

Publication Number Publication Date
CN101110042A CN101110042A (en) 2008-01-23
CN100487658C true CN100487658C (en) 2009-05-13

Family

ID=39042123

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2006101032630A Active CN100487658C (en) 2006-07-20 2006-07-20 Method for detecting memory accessing outside

Country Status (1)

Country Link
CN (1) CN100487658C (en)

Families Citing this family (18)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101630276B (en) * 2009-08-18 2012-12-19 深圳市融创天下科技股份有限公司 High-efficiency memory access method
CN102214147A (en) * 2011-06-29 2011-10-12 深圳市五巨科技有限公司 Method and device for detecting transborder memory access
CN102541748B (en) * 2011-12-28 2014-06-25 青岛海信宽带多媒体技术有限公司 Memory protection method
CN102789407B (en) * 2012-06-18 2015-05-27 上海斐讯数据通信技术有限公司 Validity detection method of memory block
CN102866951B (en) * 2012-09-21 2015-07-15 武汉烽火网络有限责任公司 Rapid positioning method of internal storage boundary crossing errors of embedded system
CN103914356A (en) * 2014-03-12 2014-07-09 汉柏科技有限公司 Memory rewriting location method
CN104461880B (en) * 2014-12-04 2018-01-09 福建星网视易信息系统有限公司 The method and system of automatic detection memory overwriting in a kind of embedded system
CN105988921A (en) * 2015-02-06 2016-10-05 中兴通讯股份有限公司 Method and device for detecting out of range problem of memory
CN104657275A (en) * 2015-03-09 2015-05-27 浪潮软件集团有限公司 Memory out-of-range positioning method and device
CN106201851A (en) * 2015-04-29 2016-12-07 中兴通讯股份有限公司 The detection method of heap memory operation and device
CN105183542B (en) * 2015-08-13 2019-07-12 上海斐讯数据通信技术有限公司 A kind of EMS memory management process and system
CN106682492B (en) * 2015-11-06 2019-08-16 大唐移动通信设备有限公司 A kind of management method and device of memory overwriting
CN107797864A (en) * 2017-10-19 2018-03-13 浪潮金融信息技术有限公司 Process resource method and device, computer-readable recording medium, terminal
CN110032529B (en) * 2018-01-11 2021-11-09 武汉斗鱼网络科技有限公司 Memory management method and related device
CN110413521B (en) * 2019-07-24 2023-01-24 杭州迪普信息技术有限公司 Write-crossing detection method and device for heap memory
CN110569037B (en) * 2019-09-06 2023-03-31 北京小米移动软件有限公司 Data writing method and device
CN111061614B (en) * 2019-12-23 2023-07-04 无锡中感微电子股份有限公司 Memory real-time monitoring processing method and system
CN111124921B (en) * 2019-12-25 2023-09-26 抖音视界有限公司 Method, device, equipment and storage medium for detecting memory boundary crossing

Also Published As

Publication number Publication date
CN101110042A (en) 2008-01-23

Similar Documents

Publication Publication Date Title
CN100487658C (en) Method for detecting memory accessing outside
US8539452B2 (en) Virtual machine tool interface for tracking objects
CN101561775B (en) Method and device for monitoring memory
CN106919454B (en) Memory pool problem positioning method and system based on LTE protocol stack
US20020073402A1 (en) Method for inserting global breakpoints
CN103064784B (en) Towards Xen environment run-time memory leakage detection method and realize system
US20080046673A1 (en) Method and system to optimize java virtual machine performance
US7769964B2 (en) Technique to perform memory reference filtering
CN1996258A (en) Method for implementing dynamic memory pool
CN103440457B (en) Based on the binary program analytic system of process simulation
US20180373871A1 (en) Hardened safe stack for return oriented programming attack mitigation
CN101251822A (en) Supervising method of internal memory being rewrited
CN101145129A (en) Embedded system memory write-overflow detection method and system
WO2022126470A1 (en) Flash data power failure protection method and device
US20060161913A1 (en) Method and apparatus for marking code for data versioning
CN100392606C (en) Method for leaking memory of positioning virtual operation system
CN110287695B (en) Java card and management method of temporary object thereof
JP7003470B2 (en) Information processing equipment, information processing methods, and programs
US20070067358A1 (en) Method and apparatus for restoring versionable objects
CN113835620A (en) Method and system for improving application execution efficiency of security chip
US20120221821A1 (en) Method of managing memory in computer system, computer system and memory managing program
CN115994348A (en) Control method for program pipeline, processing device and storage medium
US11055202B1 (en) Compilation scheme for tagged global variables
CN111737357B (en) Intelligent contract stain tracking method and device
CN102156631B (en) Method and system for managing indicator in programming language

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