CN109117357A - It record global variable information and detects global variable and crosses the border the method, apparatus of operation - Google Patents
It record global variable information and detects global variable and crosses the border the method, apparatus of operation Download PDFInfo
- Publication number
- CN109117357A CN109117357A CN201710486350.7A CN201710486350A CN109117357A CN 109117357 A CN109117357 A CN 109117357A CN 201710486350 A CN201710486350 A CN 201710486350A CN 109117357 A CN109117357 A CN 109117357A
- Authority
- CN
- China
- Prior art keywords
- global variable
- memory
- module
- information table
- variable information
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 54
- 238000007689 inspection Methods 0.000 claims description 21
- 230000008859 change Effects 0.000 claims description 10
- 238000003780 insertion Methods 0.000 claims description 6
- 230000037431 insertion Effects 0.000 claims description 6
- 238000011017 operating method Methods 0.000 claims description 2
- 238000001514 detection method Methods 0.000 abstract description 29
- 238000005516 engineering process Methods 0.000 description 16
- 230000006870 function Effects 0.000 description 10
- 238000010586 diagram Methods 0.000 description 7
- 230000008569 process Effects 0.000 description 7
- 230000007717 exclusion Effects 0.000 description 6
- 238000013507 mapping Methods 0.000 description 5
- 230000006399 behavior Effects 0.000 description 2
- 230000007547 defect Effects 0.000 description 2
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/3624—Software debugging by performing operations on the source code, e.g. via a compiler
Abstract
A kind of record global variable information is disclosed herein and detects global variable and is crossed the border the method, apparatus of operation, pre-establishes module information table, the module information table is Hash table;The described method includes: obtaining the initial address and data segment size of current block data segment in memory;The global variable information table of current block is created, and the global variable information of the module is registered in the global variable information table;The module information table is stored in using initial address, the data segment size and the global variable information table address of the data segment of current block in memory as the module information of current block;Wherein, the module is one of following: dynamic base;Main program.The application can check global variable cross the border operate when significant increase concurrent software in global variable detection efficiency;Meanwhile also memory consumption can be greatly reduced when checking that global variable crosses the border and operates.
Description
Technical field
The present invention relates to technique of compiling fields, and in particular to a kind of record global variable information and detection global variable cross the border
The method, apparatus of operation.
Background technique
The existing leading C/C++ global variable detection instrument of crossing the border based on compiling pitching pile technology mainly uses entirely
Office's information table and address of cache two kinds of technologies are realized.
Global information table establishes a kind of data structure of overall situation to save the initial address and size of each global variable
Etc. information.The data structure that the overall situation is inquired once internal storage access occurs obtains the information of accessed global variable, thus
Judge whether to cross the border.Due to data structure be it is global, concurrently access when have to carry out mutual exclusion protection, this is resulted in
This technology haves the defects that detection efficiency is low, especially may be unable to operate normally in concurrently fiercer software.
Address mapping technique is that the memory headroom of entire process is mapped to according to a certain percentage in some region of memory,
The region of memory is called map section.Magic value is set in the corresponding map section range of global variable, once internal storage access occurs
Corresponding map section is inquired, judges whether to cross the border according to magic value.The defect of map section is consumption memory especially virtual memory
Very big, possibly can not normal use in embedded environment.
Summary of the invention
In order to solve the technical problem that detection instrument detection efficiency is low in the related technology and/or consumption memory is big, this hair
Bright embodiment, which provides a kind of record global variable information and detects global variable, crosses the border the method, apparatus of operation.
This application provides:
A method of record global variable information pre-establishes module information table, and the module information table is Hash table;
The described method includes:
Obtain the initial address and data segment size of current block data segment in memory;
The global variable information table of current block is created, and the global variable information of the module is registered to the overall situation
In variable information table;
By initial address, the data segment size and the global variable letter of the data segment of current block in memory
The module information for ceasing table address as current block is stored in the module information table;
Wherein, the module is one of following: dynamic base;Main program.
Wherein, the global variable information table of the creation current block, comprising: according to the affiliated global variable of current block
Information table total size dynamic application memory, and all elements of the global variable information table are reset.
Wherein, before according to the affiliated global variable information table total size dynamic application memory of current block, further includes: will work as
The data segment size of front module obtains the number of elements of the global variable information table divided by 8, and after quotient is rounded up,
And the size based on element in number of elements obtained and the global variable information table, obtain the overall situation belonging to current block
Variable information table total size.
Wherein, the global variable information of the module is registered in the global variable information table, comprising: according to the overall situation
The initial address of variable initial address and the current block data segment in memory obtains starting index value;Become according to the overall situation
The number of elements N that amount acquiring size need to occupy;N number of member in the global variable information table since the starting index value
Global variable information is all inserted in element, the global variable information includes the global variable initial address and the global change
Measure size.
Wherein, the initial address according to global variable initial address and the current block data segment in memory,
Obtain starting index value, comprising: by the global variable initial address according to 8 byte-aligneds after, subtract the current block number
According to the initial address of section in memory, then obtained difference is rounded up divided by 8 quotient and obtains the starting index value.
Wherein, the number of elements N that need to be occupied according to global variable acquiring size, comprising: the global variable is big
It is small to round up divided by 8 quotient, obtain the number of elements N that need to be occupied.
Wherein, before the initial address and data segment size of the acquisition current block data segment in memory, further includes:
The insertion initialization stake in current block;
It is described to obtain the initial address and data segment size of current block data segment in memory, comprising: the initialization
Stake is run after current block load prior to tested program code, to obtain the starting of current block data segment in memory
Address and data segment size.
Wherein, before the global variable information of the module being registered in the global variable information table, further includes:
It is that each global variable generates a global variable registration stake in current block;The global variable information of the module is registered
Into the global variable information table, comprising: the global variable registration stake is called by the initialization stake, will be described
The global variable information of module is registered in the global variable information table.
A method of checking that global variable crosses the border operation, comprising:
When after tested program operation and attempting to carry out internal storage access, according to the memory address and access profile attempted to access that,
The module information to match with the memory address is searched from pre-established module information table;
According to the memory address and its matched module information, corresponding global variable information is obtained;
The memory address and the corresponding memory address range of access profile is corresponding with the global variable information complete
Office's variable memory range compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;
Wherein, the module is one of following: dynamic base;Main program.
Wherein, described according to the memory address and its matched module information, obtain corresponding global variable letter
Breath, comprising: by the memory address according to 8 byte-aligneds after, subtract in the module information data segment in the starting point of memory
Location, then the quotient that difference is obtained divided by 8 is rounded up, obtain global variable corresponding index in corresponding global variable information table
Value;Global variable information is read from the global variable information table according to index value, the global variable information includes: the overall situation
Variable initial address and global variable size.
Wherein, the memory address and the corresponding memory address range of access profile is corresponding with the global variable information
Global varible internal memory range compare, make this operation judgement of crossing the border, comprising: the memory address and access profile correspondence
Memory address range completely within the scope of the corresponding global varible internal memory of the global variable information, then determine this operation close
Method;The memory address and the corresponding memory address range of access profile are not exclusively in the corresponding overall situation of the global variable information
In variable memory range, then determine that this operation is crossed the border.
A kind of device recording global variable information, comprising:
First acquisition unit, for obtaining the initial address and data segment size of current block data segment in memory;
Second creating unit, for creating the global variable information table of current block;
Registering unit, for the global variable information of the module to be registered in the global variable information table;
Storage unit, for initial address, the data segment size by the data segment of current block in memory
And global variable information table address is stored in the module information table pre-established as the module information of current block;
Wherein, the module is one of following: dynamic base;Main program;The module information table is Hash table.
Wherein, first creating unit, is specifically used for: dynamic according to the affiliated global variable information table total size of current block
State application memory, and all elements of the global variable information table are reset.
Wherein, the registering unit, is specifically used for: being existed according to global variable initial address and the current block data segment
Initial address in memory obtains starting index value;The number of elements N that need to be occupied according to global variable acquiring size;Described
Global variable information, the overall situation are all inserted since N number of element the starting index value in global variable information table
Variable information includes the global variable initial address and the global variable size.
Wherein, the first acquisition unit, specifically for by after current block loads prior to tested program code
The initialization stake in current block is run, it is big to obtain current block data segment initial address in memory and data segment
It is small.
Wherein, the registering unit is specifically used for being called by global variable registration stake by the initialization stake, with
The global variable information of the module is registered in the global variable information table.
It is a kind of to check that global variable crosses the border the device of operation, comprising:
Searching unit, after being run for tested program and when attempting to carry out internal storage access, according to the memory attempted to access that
Location and access profile search the module information to match with the memory address from pre-established module information table;
Second acquisition unit, for obtaining corresponding complete according to the memory address and its matched module information
Office's variable information;
Decision unit is used for the memory address and the corresponding memory address range of access profile and the global variable
The corresponding global varible internal memory range of information compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;
Wherein, the module is one of following: dynamic base;Main program.
A kind of device recording global variable information, comprising:
It is stored with the memory of record global variable information program;
Processor is configured to execute the record global variable information program to execute operations described below: pre-establishing module
Information table, the module information table are Hash table;It obtains current block data segment initial address in memory and data segment is big
It is small;The global variable information table of current block is created, and the global variable information of the module is registered to the global variable
In information table;By initial address, the data segment size and the global variable of the data segment of current block in memory
Information table address is stored in the module information table as the module information of current block;Wherein, the module is one of following: dynamic
State library;Main program.
A kind of computer readable storage medium is stored with record global variable information on the computer readable storage medium
Program, the record global variable information program realize the step of above-mentioned record global variable information method when being executed by processor
Suddenly.
It is a kind of to check that global variable crosses the border the device of operation, comprising:
It is stored with and checks that global variable crosses the border the memory of operation sequence;
Processor is configured to execute the inspection global variable and crosses the border operation sequence to execute operations described below: tested program
After operation and when attempting to carry out internal storage access, according to the memory address and access profile attempted to access that, believe from pre-established module
The module information to match with the memory address is searched in breath table;According to the memory address and its matched module letter
Breath, obtains corresponding global variable information;By the memory address and the corresponding memory address range of access profile and described complete
The corresponding global varible internal memory range of office's variable information compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;Wherein, the module is one of following: dynamic base;Main program.
A kind of computer readable storage medium is stored on the computer readable storage medium and checks that global variable crosses the border
Operation sequence, the inspection global variable, which crosses the border, realizes that above-mentioned inspection global variable crosses the border behaviour when operation sequence is executed by processor
The step of making method.
In the embodiment of the present invention, by Hash table logging modle information, each module (i.e. main program or dynamic base) possesses
One independent global variable information table is avoided concurrent by the global variable information table that can only will be written in initialization
Mutual exclusion protection, so as to which the detection of global variable is imitated in significant increase concurrent software when inspection global variable crosses the border and operates
Rate;Meanwhile the data segment of main program and dynamic base is only mapped, it does not need to carry out memory mapping to entire process, can examine yet
It looks into global variable and crosses the border and memory consumption can be greatly reduced when operating.
Other features and advantages of the present invention will be illustrated in the following description, also, partly becomes from specification
It obtains it is clear that understand through the implementation of the invention.The objectives and other advantages of the invention can be by specification, right
Specifically noted structure is achieved and obtained in claim and attached drawing.
Detailed description of the invention
Attached drawing is used to provide to further understand technical solution of the present invention, and constitutes part of specification, with this
The embodiment of application technical solution for explaining the present invention together, does not constitute the limitation to technical solution of the present invention.
Fig. 1 is the method flow schematic diagram that the embodiment of the present invention records global variable information;
Fig. 2 is 1 main program global variable register flow path schematic diagram of example;
Fig. 3 is 2 dynamic base global variable register flow path schematic diagram of example;
Fig. 4 is the apparatus structure schematic diagram that the embodiment of the present invention records global variable information;
Fig. 5 is that the embodiment of the present invention checks that global variable crosses the border the method flow schematic diagram of operation;
Fig. 6 is that example 3 detects global variable and crosses the border the flow diagram of operation;
Fig. 7 is that the embodiment of the present invention checks that global variable crosses the border the apparatus structure schematic diagram of operation.
Specific embodiment
To make the objectives, technical solutions, and advantages of the present invention clearer, below in conjunction with attached drawing to the present invention
Embodiment be described in detail.It should be noted that in the absence of conflict, in the embodiment and embodiment in the application
Feature can mutual any combination.
Step shown in the flowchart of the accompanying drawings can be in a computer system such as a set of computer executable instructions
It executes.Also, although logical order is shown in flow charts, and it in some cases, can be to be different from herein suitable
Sequence executes shown or described step.
The linker of C/C++ language can put global variable when generating binary file (main program or dynamic base)
Enter specific space.By taking the binary file of ELF format as an example, all global variables will be placed among data segment.This Shen
It please be exactly to provide a set of detection algorithm that crosses the border that is quick, not needing mutual exclusion protection using this characteristic.That is, the application
Provide a kind of lower memory consumption, record global variable information that is more quick and not needing mutual exclusion protection and global change
The method for measuring detection of crossing the border.Specifically, the present invention relates to operate detection field for the crossing the border for software that C/C++ language is write.
Specifically, it provides a kind of logging software global variable information and phase inspection software global variable crosses the border behaviour at runtime
The method of work.
In the application, the technology using compiler compiling pitching pile is needed.Compiling pitching pile technology refers to compiler in compiling mesh
On demand in the technology of specific position insertion stake function when marking source file.The present invention is compiling source document to be detected using the technology
It is inserted into stake function in specific position when part, these stake functions will complete the function detected and auxiliary detection global variable crosses the border
Energy.These stake functions may include: to initialize stake, the global variable registration stake of each global variable, detection device etc..
In the application, guarantee each global variable address according to 8 byte-aligneds using compiler.
Embodiment one
As shown in Figure 1, providing a kind of method for recording global variable information, module information table, the module are pre-established
Information table is Hash table;The method may include:
Step 101, the initial address and data segment size of current block data segment in memory are obtained;
Step 102, the global variable information table of current block is created, and the global variable information of the module is registered to
In the global variable information table;
Step 103, by the data segment of current block initial address in memory, the data segment size and complete
Office's variable information table address is stored in the module information table as the module information of current block.
In the present embodiment, module information may include: the initial address of the data segment of the module time of running in memory
Pm, the data segment size Sm of the module, the affiliated global variable information table of module address Gm.Module information table is really a Kazakhstan
Uncommon table is realized using open addressing law technology.The node stored in module information table is module information.The key of module information table
Value is the high and low address of one section of memory, is exactly Pm and Pm+Sm-1 for module.Therefore, module information table have with it is general
The identical method be inserted into node (module information), node is retrieved according to key assignments of Hash table.
In the present embodiment, global variable information table is belonging to module, and each module possesses an independent global variable
Information table.Module specifically refers to main program or dynamic base.Global variable information table is made of a number of segment group, the element in array
The information of global variable is stored, the information of global variable includes the initial address Ga and global variable of memory where global variable
Size Sg.
In the present embodiment, by Hash table logging modle information, each module (i.e. main program or dynamic base) possesses one
Independent global variable information table avoids concurrent mutual exclusion by the global variable information table that can only will be written in initialization
Protection, so as to check global variable cross the border operate when significant increase concurrent software in global variable detection efficiency;Together
When, the data segment of main program and dynamic base is only mapped, does not need to carry out memory mapping to entire process, can also check the overall situation
Variable, which crosses the border, can be greatly reduced memory consumption when operating.
In a kind of implementation, the global variable information table of the creation current block, may include: according to current block
Affiliated global variable information table total size dynamic application memory, and all elements of the global variable information table are reset.This
In, before the affiliated global variable information table total size dynamic application memory of current block, it can obtain in the following way
The affiliated global variable information table total size of current block: the data segment size of current block is taken upwards divided by 8, and by quotient
The number of elements of the global variable information table is obtained after whole, and is believed based on number of elements obtained and the global variable
The size of element in table is ceased, the affiliated global variable information table total size of current block is obtained.
For example, establishing global variable information table, specific step is as follows: obtaining the affiliated global variable information table of this module
Number of elements;By number of elements obtained multiplied by the size of each element, the affiliated global variable information of this module can be obtained
Table total size;According to this module affiliated global variable information table total size dynamic application memory, and by global variable information table
All elements are reset.Wherein it is possible to by module data section size Sm divided by 8, and global variable letter is obtained after quotient is rounded up
Cease the number of elements of table.
In a kind of implementation, the global variable information of the module is registered in the global variable information table, it can
To include: the initial address according to global variable initial address and the current block data segment in memory, starting rope is obtained
Draw value;The number of elements N that need to be occupied according to global variable acquiring size;From the starting rope in the global variable information table
Draw and all insert global variable information in N number of element of value beginning, the global variable information includes the global variable starting
Address and the global variable size.Wherein it is possible to by the global variable initial address according to 8 byte-aligneds after, subtract institute
The initial address of current block data segment in memory is stated, then obtained difference is rounded up divided by 8 quotient and obtains described rise
Beginning index value.Wherein it is possible to which the global variable size is rounded up divided by 8 quotient, the number of elements N that need to be occupied is obtained.
For example, by the global variable information registration global variable letter of global variable initial address Ga, global variable size Sg
The process of breath table may include steps of:
1, the initial address Pm of module data section in memory is obtained from module information table;
2, according to formulaI.e. by global variable initial address Ga
After 8 byte-aligneds, the initial address Pm of module data section is subtracted, then by difference divided by 8, finally quotient rounds up acquisition
Originate index value index0;
3, according to formulaGlobal variable size Sg is rounded up divided by 8, then by quotient, it is complete to obtain this
Number of elements N shared by office's variable;
4, in global variable information table, to index0+N-1 element since indexing index0, all filling is originally complete
The information of office's variable, i.e. the initial address Ga of the memory and size Sg of global variable where this global variable.
In the present embodiment, before the initial address and data segment size of the acquisition current block data segment in memory,
Initialization stake can also be inserted into current block.In this way, described obtain the starting point of current block data segment in memory
Location and data segment size may include: that the initialization stake is run after current block load prior to tested program code,
To obtain the initial address and data segment size of current block data segment in memory.
In the present embodiment, before the global variable information of the module is registered in the global variable information table, also
It can be that each global variable generates a global variable registration stake in current block.In this way, by the overall situation of the module
Variable information is registered in the global variable information table, may include: the global variable registration stake by the initialization
Stake calls, and the global variable information of the module is registered in the global variable information table.
It is described in detail separately below for the global variable information record of main program, dynamic base.
Example 1: the method for record main program global variable information
In this example, need to use compiling pitching pile technology insertion main program initialization stake and global variable registration stake.
It is called prior to tested program code in program initial start stage that main program initializes stake, crosses the border detection function to complete the overall situation
Initial work.Global variable is registered stake and is called by main program initialization stake, completes to be inserted into global variable information table
The work of global variable information.Particularly, each global variable generates a global variable and registers stake.
Main program global variable register flow path is as shown in Figure 2:
Step 201, initialization stake is inserted into tested program using compiling pitching pile technology, prior to tested when program starts
Program code operation enters initialization stake when being detected program operation;
Step 202, the initial address and data segment size of main program data segment in memory are obtained;
Step 203, the creation module information table in the way of Hash table;
Step 204, the global variable information table of main program is created;
Step 205, global variable registration stake to be registered is checked for;There is no global variable to be registered notes
Volume stake, then jump to step 207;There are global variables to be registered to register stake, then continues to execute step 206;
Step 206, the global variable information of main program is registered in global variable information table, and returns to step 205;
Specifically, global variable to be registered is successively called to register stake, the global variable information of main program is registered to
In global variable information table.
Step 207, initial address, data segment size and global variable information table by main program data segment in memory
Location is stored in the module information table as the module information of main program;
Step 208, main program initialization terminates, and detected program continues to run.
Example 2: the method for record dynamic base global variable information
In this example, stake is registered using compiling pitching pile technology insertion dynamic library initialization stake and global variable.Dynamically
Library initialization stake is called prior to tested program code after dynamic base load, to complete global detection function of crossing the border
Initial work.Global variable is registered stake and is called by dynamic library initialization stake, completes to be inserted into global variable information table complete
The work of office's variable information.Particularly, each global variable generates a global variable and registers stake.
As shown in figure 3, record dynamic base global variable information, that is, dynamic base global variable registration process may include:
Step 301, initialization stake, load dynamic base, into initial be inserted intos in dynamic base using compiling pitching pile technology
Change stake;
Step 302, the initial address and data segment size of dynamic base data segment in memory are obtained;
Step 303, the global variable information table of this dynamic base is created;
Step 304, global variable registration stake to be registered is checked for;There are the overall situations of global variable to be registered
Variable registers stake, then jumps to step 306;There are the global variables of global variable to be registered to register stake, then continues to execute
Step 305;
Step 305, the global variable information of dynamic base is registered in global variable information table, and returns to step 304;
Specifically, global variable to be registered is called to register stake, the global variable information of dynamic base is registered to the overall situation
In variable information table.
Step 306, by this dynamic base data segment memory initial address, data segment size and global variable information table
Location is as in the module information insertion module information table of this dynamic base.
Step 307, dynamic library initialization terminates, and detected program continues to run.
Embodiment two
As shown in figure 4, providing a kind of device for recording global variable information, comprising:
First acquisition unit 42, for obtaining the initial address and data segment size of current block data segment in memory;
Second creating unit 43, for creating the global variable information table of current block;
Registering unit 44, for the global variable information of the module to be registered in the global variable information table;
Storage unit 45, for the data segment of current block initial address in memory, the data segment is big
Small and global variable information table address is stored in the module information table pre-established as the module information of current block;
Wherein, the module is one of following: dynamic base;Main program.
It wherein, can also include: the first creating unit 41, for pre-establishing the module information table, the module letter
Breath table is Hash table.
Wherein, second creating unit 43, specifically can be used for: total according to the affiliated global variable information table of current block
Size dynamic application memory, and all elements of the global variable information table are reset.
Wherein, the registering unit 44, specifically can be used for: according to global variable initial address and the current block number
According to the initial address of section in memory, starting index value is obtained;The number of elements N that need to be occupied according to global variable acquiring size;
Global variable information is all inserted since N number of element the starting index value in the global variable information table, institute
Stating global variable information includes the global variable initial address and the global variable size.
In practical application, the initialization stake of current block is previously inserted using compiling pitching pile technology and global variable is infused
Volume stake.Particularly, a global variable can be generated for each global variable register stake.
Wherein, the first acquisition unit 42, be particularly used in by after current block loads prior to tested program
Code runs the initialization stake in current block, to obtain current block data segment initial address in memory and data segment
Size.
Wherein, the registering unit specifically can be used for registering stake by global variable by the initialization stake tune
With the global variable information of the module is registered in the global variable information table.
In the present embodiment, the device of above-mentioned record global variable information can realize all thin of one the method for embodiment
Section.In practical application, the first creating unit 41, first acquisition unit 42, the second creating unit 43, registering unit 44, storage are single
Member 45 can be the combination of software, hardware or both respectively.The device of the above-mentioned record global variable information of the present embodiment can lead to
It crosses to be set to and calculate in equipment, or directly realized by calculating equipment.
Embodiment three
A kind of device recording global variable information, comprising:
It is stored with the memory of record global variable information program;
Processor is configured to execute the record global variable information program to execute operations described below: pre-establishing module
Information table, the module information table are Hash table;It obtains current block data segment initial address in memory and data segment is big
It is small;The global variable information table of current block is created, and the global variable information of the module is registered to the global variable
In information table;By initial address, the data segment size and the global variable of the data segment of current block in memory
Information table address is stored in the module information table as the module information of current block.
Wherein, the module is one of following: dynamic base;Main program.
In the present embodiment, the device of above-mentioned record global variable information can realize all thin of one the method for embodiment
Section.In practical application, the device of the above-mentioned record global variable information of the present embodiment can be calculated in equipment by being set to, or
Directly realized by calculating equipment.
Example IV
It crosses the border the method for operation as shown in figure 5, providing a kind of inspection global variable, comprising:
Step 501, after tested program operation and when attempting to carry out internal storage access, according to the memory address and visit attempted to access that
It asks range, the module information to match with the memory address is searched from pre-established module information table;
Step 502, according to the memory address and its matched module information, corresponding global variable letter is obtained
Breath;
Step 503, by the memory address and the corresponding memory address range of access profile and the global variable information
Corresponding global varible internal memory range compares, and makes the judgement of crossing the border of this operation.
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;
Wherein, the module is one of following: dynamic base;Main program.
In the present embodiment, by searching for matched module information, then the global of this access is obtained based on module information and is become
Information is measured, judgement of crossing the border finally is made based on the global variable information again, due to can only believe write-in global variable in initialization
Breath table avoids concurrent mutual exclusion protection, therefore, the global variable detection efficiency being greatly improved in concurrent software;Meanwhile only
The data segment for mapping main program and dynamic base does not need to carry out memory mapping to entire process, greatly reduces memory yet and disappear
Consumption.
It is described according to the memory address and its matched module information in a kind of implementation, it obtains corresponding
Global variable information, may include: by the memory address according to 8 byte-aligneds after, subtract data segment in the module information
It rounds up in the initial address of memory, then by the quotient that difference is obtained divided by 8, obtains global variable in corresponding global variable information
Corresponding index value in table;Global variable information, the global change are read from the global variable information table according to index value
Measuring information includes: global variable initial address and global variable size.
For example, obtaining corresponding global variable information according to arbitrary address Gx (such as memory address) within the scope of global varible internal memory
Specific step is as follows:
1, the initial address Pm of module data section is obtained from module information table;
2, according to formulaIt i.e. will be any within the scope of global variable
After address Gx is according to 8 byte-aligneds, the initial address Pm of module data section is subtracted, then by difference divided by 8, is finally taken quotient upwards
Whole acquisition global variable corresponding index in the affiliated global variable information table of module;
3, the information of the global variable is read from the affiliated global variable information table of module according to index index, i.e., this is complete
The initial address Ga of the memory and size Sg of global variable where office's variable.
In the present embodiment, the memory address and the corresponding memory address range of access profile and the global variable are believed
It ceases corresponding global varible internal memory range to compare, makes the judgement of crossing the border of this operation, may include: the memory address and visit
Ask that the corresponding memory address range of range within the scope of the corresponding global varible internal memory of the global variable information, then determines completely
This operation is legal;The memory address and the corresponding memory address range of access profile are not exclusively in the global variable information
Within the scope of corresponding global varible internal memory, then determine that this operation is crossed the border.
Here, memory address range (M~M+S-1) is then sentenced completely in global varible internal memory range (Ga~Ga+Sg-1)
This fixed operation is legal, otherwise determines that this operation is crossed the border.Wherein, M is the memory address, and S is the access profile, and Ga is
Global variable initial address in the global variable information, Sg are the global variable size in the global variable information.
In the present embodiment, detection stake is inserted into when internal storage access occurs in detected code using compiler.In this way, tested
When after program operation and attempting to carry out internal storage access, detection stake is inserted into internal storage access using compiling pitching pile technology.It is tested
Program enters detection stake when attempting to carry out internal storage access after running, described interior so as to be passed to using the detection stake
Deposit address and access profile.
In the present embodiment, if search matched module information according to the memory address and access profile attempted to access that,
Can be determined that this if it can not find matched module information not is that global varible internal memory access directly returns.If found
The module information matched, then read module information, the module information may include: the data segment of the module time of running in memory
The address of initial address, the affiliated global variable information table of data segment size, the module of the module.
For example, the detailed process of operation detection may include: as shown in fig. 6, global variable crosses the border
Step 601, it is detected program operation;
Step 602, it is detected routine access memory, into detection stake;
Detection stake is inserted into internal storage access using compiling pitching pile technology.Tested program operation after when attempt carry out memory
Enter detection stake when access.
Step 603, the memory address M that attempts to access that and access profile S incoming according to detection stake, utilize module information
The retrieval technique (for example, hash algorithm or other be capable of the algorithm of quick-searching) of table searches whether exist in module information table
This accesses corresponding module information;There is no this to access corresponding module information, then shows that the memory of this access is not
Global variable jumps to step 608;There are this to access corresponding module information, then continues step 604;
Step 604, detection stake reads module information, it may be assumed that the starting point of the data segment of the module time of running in memory
Location Pm, the data segment size Sm of the module, the affiliated global variable information table of module address Gm;
Step 605, the memory address M that attempts to access that and the module information incoming according to detection stake, obtain this
It is secondary to access corresponding global variable information, it may be assumed that the initial address Ga of the memory and size Sg of global variable where global variable;
Step 606, judge memory address range (M~M+S-1) that this is attempted to access that whether completely in global variable
It deposits in range (Ga~Ga+Sg-1).This memory address range attempted to access that (M~M+S-1) is completely in global varible internal memory
In range (Ga~Ga+Sg-1), then this access is legal, jumps to step 608;This memory address range (M attempted to access that
~M+S-1) not exclusively in global varible internal memory range (Ga~Ga+Sg-1), then this Access Violation, carries out step 607;
Step 607, detection information of crossing the border is exported;
Step 608, detection terminates, and detected program continues to run.
Embodiment five
It crosses the border the device of operation as shown in fig. 7, providing a kind of inspection global variable, comprising:
Searching unit 71, after being run for tested program and when attempting to carry out internal storage access, according to the memory attempted to access that
Address and access profile search the module information to match with the memory address from pre-established module information table;
Second acquisition unit 72, for obtaining corresponding according to the memory address and its matched module information
Global variable information;
Decision unit 73, for becoming the memory address and the corresponding memory address range of access profile and the overall situation
The corresponding global varible internal memory range of amount information compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;
Wherein, the module is one of following: dynamic base;Main program.
In a kind of implementation, second acquisition unit 72 specifically can be used for: by the memory address according to 8 bytes pair
Qi Hou subtracts data segment in the module information and rounds up in the initial address of memory, then by the quotient that difference is obtained divided by 8,
Obtain global variable corresponding index value in corresponding global variable information table;According to index value from the global variable information table
Middle reading global variable information, the global variable information include: global variable initial address and global variable size.
In a kind of implementation, decision unit 73 specifically can be used for: corresponding in the memory address and access profile
When memory address range is completely within the scope of the corresponding global varible internal memory of the global variable information, then determine that this operation is closed
Method;It is not exclusively corresponding complete in the global variable information in the memory address and the corresponding memory address range of access profile
When in office's variable memory range, then determine that this operation is crossed the border.
In the present embodiment, the cross the border device of operation of above-mentioned inspection global variable can realize all of example IV the method
Details.In practical application, searching unit 71, second acquisition unit 72, decision unit 73 can be software, hardware or both respectively
Combination.The above-mentioned inspection global variable of the present embodiment cross the border operation device can by be set to calculate equipment in, Huo Zhezhi
Calculating equipment was connected to realize.
Embodiment six
It crosses the border the device of operation the present embodiment provides a kind of inspection global variable, comprising:
It is stored with and checks that global variable crosses the border the memory of operation sequence;
Processor is configured to execute the inspection global variable and crosses the border operation sequence to execute operations described below: tested program
After operation and when attempting to carry out internal storage access, according to the memory address and access profile attempted to access that, believe from pre-established module
The module information to match with the memory address is searched in breath table;According to the memory address and its matched module letter
Breath, obtains corresponding global variable information;By the memory address and the corresponding memory address range of access profile and described complete
The corresponding global varible internal memory range of office's variable information compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes the data segment of module initial address in memory, data segment size and complete
Office's variable information table address;
Wherein, the module is one of following: dynamic base;Main program.
In the present embodiment, the cross the border device of operation of above-mentioned inspection global variable can realize all of example IV the method
Details.In practical application, the above-mentioned inspection global variable of the present embodiment crosses the border the device of operation can be by being set to calculating equipment
In, or directly realized by calculating equipment.
In addition, the embodiment of the present application also provides a kind of computer readable storage medium, the computer readable storage medium
On be stored with record global variable information program, the record global variable information program realizes above-mentioned note when being executed by processor
The step of recording global variable information method.
In addition, the embodiment of the present application also provides a kind of computer readable storage medium, the computer readable storage medium
On be stored with and check that global variable crosses the border operation sequence, the inspections global variable crosses the border operation sequence reality when being executed by processor
Existing above-mentioned inspection global variable cross the border operating method the step of.
Optionally, in the present embodiment, above-mentioned storage medium can include but is not limited to: USB flash disk, read-only memory (ROM,
Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or
The various media that can store program code such as CD.
Optionally, in the present embodiment, processor executes above-mentioned implementation according to program code stored in storage medium
The method and step of example.
Optionally, the specific example in the present embodiment can be with reference to described in above-described embodiment and optional embodiment
Example, details are not described herein for the present embodiment.
Those of ordinary skill in the art will appreciate that all or part of the steps in the above method can be instructed by program
Related hardware (such as processor) is completed, and described program can store in computer readable storage medium, as read-only memory,
Disk or CD etc..Optionally, one or more integrated circuits also can be used in all or part of the steps of above-described embodiment
It realizes.Correspondingly, each module/unit in above-described embodiment can take the form of hardware realization, such as pass through integrated circuit
It realizes its corresponding function, can also be realized in the form of software function module, such as be stored in and deposited by processor execution
Program/instruction in reservoir realizes its corresponding function.The application is not limited to the knot of the hardware and software of any particular form
It closes.
The advantages of basic principles and main features and the application of the application have been shown and described above.The application is not by upper
The limitation for stating embodiment, the above embodiments and description only describe the principles of the application, are not departing from the application
Under the premise of spirit and scope, the application be will also have various changes and improvements, these changes and improvements both fall within claimed
Within the scope of the application.
Claims (21)
1. a kind of method for recording global variable information, which is characterized in that pre-establish module information table, the module information table
For Hash table;The described method includes:
Obtain the initial address and data segment size of current block data segment in memory;
The global variable information table of current block is created, and the global variable information of the module is registered to the global variable
In information table;
By initial address, the data segment size and the global variable information table of the data segment of current block in memory
Address is stored in the module information table as the module information of current block;
Wherein, the module is one of following: dynamic base;Main program.
2. the method according to claim 1, wherein the global variable information table of the creation current block, packet
It includes:
According to current block affiliated global variable information table total size dynamic application memory, and by the global variable information table
All elements are reset.
3. according to the method described in claim 2, it is characterized in that, according to the affiliated global variable information table total size of current block
Before dynamic application memory, further includes:
The data segment size of current block is obtained into the global variable information table divided by 8, and after quotient is rounded up
Number of elements, and the size based on element in number of elements obtained and the global variable information table, obtain current mould
The affiliated global variable information table total size of block.
4. the method according to claim 1, wherein the global variable information of the module is registered to described complete
In office's variable information table, comprising:
According to the initial address of global variable initial address and the current block data segment in memory, starting index is obtained
Value;
The number of elements N that need to be occupied according to global variable acquiring size;
Global variable letter is all inserted since N number of element the starting index value in the global variable information table
Breath, the global variable information includes the global variable initial address and the global variable size.
5. according to the method described in claim 4, it is characterized in that, described according to global variable initial address and the current mould
The initial address of block data segment in memory obtains starting index value, comprising:
By the global variable initial address according to 8 byte-aligneds after, subtract the current block data segment in memory rise
Beginning address, then obtained difference is rounded up divided by 8 quotient and obtains the starting index value.
6. according to the method described in claim 4, it is characterized in that, the element that need to be occupied according to global variable acquiring size
Quantity N, comprising:
The global variable size is rounded up divided by 8 quotient, obtains the number of elements N that need to be occupied.
7. method according to any one of claims 1 to 6, which is characterized in that
Before the initial address and data segment size of the acquisition current block data segment in memory, further includes: in current mould
Insertion initialization stake in block;
It is described to obtain the initial address and data segment size of current block data segment in memory, comprising:
The initialization stake is run after current block load prior to tested program code, to obtain current block data segment
Initial address and data segment size in memory.
8. the method according to the description of claim 7 is characterized in that
Before the global variable information of the module is registered in the global variable information table, further includes: in current block
In be that each global variable generates a global variable registration stake;
The global variable information of the module is registered in the global variable information table, comprising: the global variable registration
Stake is called by the initialization stake, and the global variable information of the module is registered to the global variable information table
In.
A kind of method of operation 9. inspection global variable crosses the border characterized by comprising
When after tested program operation and attempting to carry out internal storage access, according to the memory address and access profile attempted to access that, from pre-
The module information to match with the memory address is searched in the module information table of foundation;
According to the memory address and its matched module information, corresponding global variable information is obtained;
By the global change corresponding with the global variable information of the memory address and the corresponding memory address range of access profile
Amount memory range compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes initial address, data segment size and the global change of the data segment of module in memory
Measure information table address;
Wherein, the module is one of following: dynamic base;Main program.
10. according to the method described in claim 9, it is characterized in that, described according to the memory address and its matched described
Module information obtains corresponding global variable information, comprising:
By the memory address according to 8 byte-aligneds after, subtract data segment in the module information in the initial address of memory, then
The quotient that difference is obtained divided by 8 is rounded up, global variable corresponding index value in corresponding global variable information table is obtained;
Global variable information is read from the global variable information table according to index value, the global variable information includes: complete
Office's variable initial address and global variable size.
11. according to the method described in claim 9, it is characterized in that, by the memory address and the corresponding memory of access profile
Compared with address range global varible internal memory range corresponding with the global variable information, the judgement of crossing the border of this operation is made,
Include:
The memory address and the corresponding memory address range of access profile are completely in the corresponding overall situation of the global variable information
In variable memory range, then determine that this operation is legal;
The memory address and the corresponding memory address range of access profile are not exclusively corresponding complete in the global variable information
In office's variable memory range, then determine that this operation is crossed the border.
12. a kind of device for recording global variable information characterized by comprising
First acquisition unit, for obtaining the initial address and data segment size of current block data segment in memory;
Second creating unit, for creating the global variable information table of current block;
Registering unit, for the global variable information of the module to be registered in the global variable information table;
Storage unit, for by the data segment of current block initial address in memory, the data segment size and
Global variable information table address is stored in the module information table pre-established as the module information of current block;
Wherein, the module is one of following: dynamic base;Main program;The module information table is Hash table.
13. device according to claim 12, which is characterized in that
First creating unit, is specifically used for: according in the affiliated global variable information table total size dynamic application of current block
It deposits, and all elements of the global variable information table is reset.
14. device according to claim 12, which is characterized in that
The registering unit, is specifically used for: in memory according to global variable initial address and the current block data segment
Initial address obtains starting index value;The number of elements N that need to be occupied according to global variable acquiring size;In the global variable
Global variable information, the global variable information are all inserted since N number of element the starting index value in information table
Including the global variable initial address and the global variable size.
15. 2 to 14 described in any item devices according to claim 1, which is characterized in that
The first acquisition unit, specifically for by running current mould prior to tested program code after current block loads
Initialization stake in block, to obtain the initial address and data segment size of current block data segment in memory.
16. device according to claim 15, which is characterized in that
The registering unit is specifically used for being called by global variable registration stake by the initialization stake, by the mould
The global variable information of block is registered in the global variable information table.
The device of operation 17. a kind of inspection global variable crosses the border characterized by comprising
Searching unit, for after tested program operation and when attempting to carry out internal storage access, according to the memory address that attempts to access that and
Access profile searches the module information to match with the memory address from pre-established module information table;
Second acquisition unit, for obtaining corresponding global change according to the memory address and its matched module information
Measure information;
Decision unit is used for the memory address and the corresponding memory address range of access profile and the global variable information
Corresponding global varible internal memory range compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes initial address, data segment size and the global change of the data segment of module in memory
Measure information table address;
Wherein, the module is one of following: dynamic base;Main program.
18. a kind of device for recording global variable information characterized by comprising
It is stored with the memory of record global variable information program;
Processor is configured to execute the record global variable information program to execute operations described below: pre-establishing module information
Table, the module information table are Hash table;Obtain the initial address and data segment size of current block data segment in memory;Wound
The global variable information table of current block is built, and the global variable information of the module is registered to the global variable information table
In;By initial address, the data segment size and the global variable information table of the data segment of current block in memory
Address is stored in the module information table as the module information of current block;Wherein, the module is one of following: dynamic base;
Main program.
19. a kind of computer readable storage medium, which is characterized in that it is complete to be stored with record on the computer readable storage medium
Office's variable information program is realized when the record global variable information program is executed by processor as any in claim 1 to 8
The step of item record global variable information method.
The device of operation 20. a kind of inspection global variable crosses the border characterized by comprising
It is stored with and checks that global variable crosses the border the memory of operation sequence;
Processor is configured to execute the inspection global variable and crosses the border operation sequence to execute operations described below: tested program operation
When afterwards and attempting to carry out internal storage access, according to the memory address and access profile attempted to access that, from pre-established module information table
The module information that middle lookup matches with the memory address;According to the memory address and its matched module information,
Obtain corresponding global variable information;By the memory address and the corresponding memory address range of access profile and the global change
The corresponding global varible internal memory range of amount information compares, and makes the judgement of crossing the border of this operation;
Wherein, the module information includes initial address, data segment size and the global change of the data segment of module in memory
Measure information table address;Wherein, the module is one of following: dynamic base;Main program.
21. a kind of computer readable storage medium, which is characterized in that it is complete to be stored with inspection on the computer readable storage medium
Office's variable crosses the border operation sequence, and the inspections global variable, which crosses the border when operation sequence is executed by processor, realizes such as claim 9
The step of crossing the border operating method to inspection global variable described in any one of 11.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710486350.7A CN109117357A (en) | 2017-06-23 | 2017-06-23 | It record global variable information and detects global variable and crosses the border the method, apparatus of operation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710486350.7A CN109117357A (en) | 2017-06-23 | 2017-06-23 | It record global variable information and detects global variable and crosses the border the method, apparatus of operation |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109117357A true CN109117357A (en) | 2019-01-01 |
Family
ID=64733275
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710486350.7A Pending CN109117357A (en) | 2017-06-23 | 2017-06-23 | It record global variable information and detects global variable and crosses the border the method, apparatus of operation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109117357A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110321674A (en) * | 2019-07-12 | 2019-10-11 | 北京智游网安科技有限公司 | A kind of anti-tune method for testing, intelligent terminal and storage medium based on shell script |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1851671A (en) * | 2005-07-01 | 2006-10-25 | 华为技术有限公司 | Method for saving global varible internal memory space |
CN101425038A (en) * | 2008-12-19 | 2009-05-06 | 北京中星微电子有限公司 | Method and system for searching software error |
US20100192026A1 (en) * | 2009-01-27 | 2010-07-29 | Microsoft Corporation | Implementations of program runtime checks |
CN106201851A (en) * | 2015-04-29 | 2016-12-07 | 中兴通讯股份有限公司 | The detection method of heap memory operation and device |
-
2017
- 2017-06-23 CN CN201710486350.7A patent/CN109117357A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1851671A (en) * | 2005-07-01 | 2006-10-25 | 华为技术有限公司 | Method for saving global varible internal memory space |
CN101425038A (en) * | 2008-12-19 | 2009-05-06 | 北京中星微电子有限公司 | Method and system for searching software error |
US20100192026A1 (en) * | 2009-01-27 | 2010-07-29 | Microsoft Corporation | Implementations of program runtime checks |
CN106201851A (en) * | 2015-04-29 | 2016-12-07 | 中兴通讯股份有限公司 | The detection method of heap memory operation and device |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110321674A (en) * | 2019-07-12 | 2019-10-11 | 北京智游网安科技有限公司 | A kind of anti-tune method for testing, intelligent terminal and storage medium based on shell script |
CN110321674B (en) * | 2019-07-12 | 2021-04-06 | 北京智游网安科技有限公司 | Anti-debugging method based on script program, intelligent terminal and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8412881B2 (en) | Modified B+ tree to store NAND memory indirection maps | |
US20080052488A1 (en) | Method for a Hash Table Lookup and Processor Cache | |
KR100873943B1 (en) | System and method of reading non-volatile computer memory | |
CN107729752B (en) | One kind extorting software defense method and system | |
US20110161602A1 (en) | Lock-free concurrent object dictionary | |
CN110334009A (en) | Automatic example generation method, device, terminal and storage medium | |
CN108121628B (en) | Method and device for testing read-write speed and electronic equipment | |
CN107729227A (en) | Application testing range determining method, system, server and storage medium | |
CN102306503A (en) | Method and system for detecting false capacity memory | |
CN109656815A (en) | There are test statement write method, device, medium and the electronic equipment of configuration file | |
CN106844676A (en) | Date storage method and device | |
CN105653906A (en) | Anti-kernel-hook method based on address randomization | |
CN104461880B (en) | The method and system of automatic detection memory overwriting in a kind of embedded system | |
WO2016173172A1 (en) | Method and apparatus for detecting heap memory operation | |
CN109117357A (en) | It record global variable information and detects global variable and crosses the border the method, apparatus of operation | |
CN109977020B (en) | Automatic testing method | |
CN107832227A (en) | Interface parameters method of testing, device, equipment and the storage medium of operation system | |
CN105260130B (en) | A kind of reading/writing method of Seagate hard-disk system file | |
CN111341374B (en) | Memory test method and device and readable memory | |
CN110457905A (en) | Method for detecting virus, device, computer equipment and the storage medium of sample | |
CN116028022A (en) | Java technology-based zero code Excel data importing method, device and medium | |
CN107943415A (en) | The method and system of lookup free cluster based on FAT file system | |
CN107783904A (en) | Unit testing stake De-weight method, device, computer-readable recording medium and equipment | |
CN107656863A (en) | A kind of data flow method of testing and its test system based on key point guiding | |
CN103729260B (en) | Data management/inspection method and related content addressing accumulator system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20190101 |
|
WD01 | Invention patent application deemed withdrawn after publication |