Movatterモバイル変換


[0]ホーム

URL:


CN112084013B - Program calling method, chip and computer storage medium - Google Patents

Program calling method, chip and computer storage medium
Download PDF

Info

Publication number
CN112084013B
CN112084013BCN201910512465.8ACN201910512465ACN112084013BCN 112084013 BCN112084013 BCN 112084013BCN 201910512465 ACN201910512465 ACN 201910512465ACN 112084013 BCN112084013 BCN 112084013B
Authority
CN
China
Prior art keywords
program
register
variable
addresses
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
CN201910512465.8A
Other languages
Chinese (zh)
Other versions
CN112084013A (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.)
Wuhan Jiekai Technology Co ltd
Original Assignee
Wuhan Jiekai Technology Co ltd
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 Wuhan Jiekai Technology Co ltdfiledCriticalWuhan Jiekai Technology Co ltd
Priority to CN201910512465.8ApriorityCriticalpatent/CN112084013B/en
Publication of CN112084013ApublicationCriticalpatent/CN112084013A/en
Application grantedgrantedCritical
Publication of CN112084013BpublicationCriticalpatent/CN112084013B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

The invention discloses a program calling method, a chip and a computer storage medium, wherein the program calling method comprises the steps of fixing the address of a variable in a second program in a first program; wherein the first program and the second program are compiled independently; the first program calls the second program to protect registers required for running the first program. By the method, the problems of variable address overlapping and register conflict when a plurality of programs are compiled independently and function call relations exist can be avoided, and safety is improved.

Description

Program calling method, chip and computer storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a program calling method, a chip, and a computer storage medium.
Background
In the software development project of independent compiling of multiple programs/functions, as the multiple programs/functions are independently compiled, the allocation situation of variable addresses of the opposite side is not known between the programs, and under the condition that a function call relation exists, the problem that the variable addresses are mutually overlapped often exists, so that the problem of some application is brought; taking A, B two programs as an example, abnormal problems may occur when the program a calls the sub-function in the program B or when the program B calls the sub-function in the program a, such as incorrect return values, modification of variables that should not be modified, program run-away, and the like, and the case of multiple programs is similar.
The inventors of the present invention have found in long-term research and development that, for a relatively advanced central processing unit (CPU, central Processing Unit), the problem of overlapping variable addresses during independent compilation is considered when designing the CPU, for example, most of the CPUs of advanced reduced instruction set computers (ARM, advanced Reduced Instruction Set Computer Machines) support the ARM-Thumb procedure call standard (ATPCS, ARM-THUMB Procedure Call Standard) or ARM architecture procedure call standard (AAPCS, ARM Architecture Procedure Call Standard) rule, which ensures that function call of independent compilation does not have adverse effects such as variable coverage or tampering. The existing practice is that the corresponding rule (such as ATPCS/AAPCS of ARM) is considered and formulated when the CPU is designed, and the problem of variable address overlapping during independent compiling is avoided in the process of developing a software program by the CPU. However, for simple CPUs, such as 8051 kernel, and more simple CPUs with 8 bits, 16 bits or 32 bits, the problem of variable address overlapping during independent compiling is not considered, that is, there is no rule such as ATPCS/AAPCS like ARM, the variable address overlapping cannot be avoided, the incorrect return value of the program is difficult to be avoided, the variable which should not be modified is modified or the program runs off, and the normal running of the program cannot be ensured.
Disclosure of Invention
The invention mainly solves the problem of overlapping variable addresses and conflicting registers when a plurality of programs are independently compiled and have function calling relations, and improves the safety.
In order to solve the technical problems, the technical scheme adopted by the invention is to provide a program calling method, which comprises the following steps: fixing the address of a variable in the second program in the first program; wherein the first program and the second program are compiled independently; the first program calls the second program to protect registers required for running the first program.
In order to solve the above technical problem, another technical solution adopted by the present invention is to provide a chip, which includes a memory and a processor connected to each other, wherein the memory is used for storing a computer program, and the computer program is used for implementing the program calling method when being executed by the processor.
In order to solve the above technical problem, another technical solution adopted by the present invention is to provide a computer storage medium, where the computer storage medium is used to store a computer program, and the computer program is used to implement the method for calling the program when the computer program is executed by a processor.
Through the scheme, the invention has the beneficial effects that: fixing the address of the variable in the second program in advance so as to avoid conflict with the address of the variable in the first program; the address of the variable in the called program can be fixed, so that the address of the variable in the called program cannot be overlapped with the address of the variable in the called program, the problem that the variable addresses are overlapped when a plurality of programs are independently compiled and have function call relations can be avoided, the safety can be further improved by protecting the register, the condition that the register conflicts in the procedure call process is effectively avoided, the problem that unexpected results appear in operation after the procedure call is avoided, and the operation result is prevented from being wrong or the procedure runs and flies.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Wherein:
FIG. 1 is a flowchart of an embodiment of a procedure call method provided by the present invention;
FIG. 2 is a flowchart illustrating another embodiment of a procedure call method according to the present invention;
FIG. 3 is a schematic diagram of an embodiment of a chip according to the present invention;
fig. 4 is a schematic structural diagram of an embodiment of a computer storage medium provided by the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a flowchart of an embodiment of a procedure call method according to the present invention, where the method includes:
step 11: the addresses of variables in the second program are fixed in the first program.
The first program and the second program are compiled independently, and the first program calls the second program; for example, there are three programs A, B and C in the compiler, programs A, B and C are compiled independently of each other, but program B or a middle molecular function of program B is called when executing program a and/or C.
The variables in the second program may be assigned fixed addresses and the addresses used by these variables are reserved in the first program to ensure that the data is not covered. For example, the addresses of variables A1 and A2 required to be used in the second program may be defined as Add1 and Add2, and the addresses Add1 and Add2 may be reserved in the first program, and the two addresses may be avoided when the addresses are allocated to the variables in the first program.
Step 12: the first program calls the second program to protect registers required for running the first program.
In a specific embodiment, when the first program calls the second program, the registers required by the first program running in the processor are protected, so that data in the registers are kept unchanged before and after the second program is called, and the situation of register address conflict is avoided.
In a specific embodiment, the processor is a chip that does not have a function of handling the problem that the variable addresses overlap each other when independently compiling, such as an 8051 single-chip microcomputer, and the registers required by the first program are kernel-related registers, and specifically may be at least one of 4 sets of working registers R0 to R7, an Accumulator (ACC), an auxiliary register (B), or a program status flag register (PSW, programStatus Word), etc.
The 4 groups of working registers R0-R7 correspond to 00H-1 FH units in the memory, and 0 groups: 00H-07H units, group 1: 08H-0 FH unit, group 2: 10H-17H units, 3 groups: the 18H-1 FH units, only one of the four groups is a current working register, 8 units in the current working register are used by a program, the current working register is determined by a third bit RS0 and a fourth bit RS1 in a program state flag register PSW, the third bit RS0 and the fourth bit RS1 in the program state flag register PSW have four states of 00, 01, 10 and 11, and 0 group, 1 group, 2 group and 3 group of the working registers are respectively designated, and the current working register group can be changed only by changing the values of the third bit RS0 and the fourth bit RS1 by instructions, so that 32 working registers can be selected in practice; the accumulator ACC is commonly used for storing the execution number and the operation result of arithmetic or logical operation; the auxiliary register B can be matched with the accumulator ACC in multiplication and trigger operation and can also be used as a general temporary register; the program status flag register PSW may be used to store status information related to instruction execution, and the status information of each bit in the program status flag register PSW is typically formed during instruction execution, or may be changed by a user using a transfer instruction as needed.
For example, the register required by the first program is an accumulator ACC, the data stored in the accumulator ACC is an 8-bit binary number 01000110 before the first program calls the second program, the second program is a summation program, the values of variables in the first program are respectively 2 and 3, for correct calculation, when the first program calls the second program, the accumulator ACC is protected, after the second program is called, the data stored in the accumulator ACC becomes 00000101, after the first program calls the second program, the return value is 5, and then the data in the accumulator ACC is reset to the original value 00100110; this achieves protection of the accumulator ACC during the invocation of the second program by the first program.
For relatively simple CPUs, the simple CPUs do not formulate rules/methods for solving the problem of variable address overlapping during independent compiling in design, and under the conditions of meeting independent compiling of multiple projects/functions and having function calling relations, as programmers cannot know the address allocation condition in advance in the process of programming, the problem of overlapping addresses possibly exists in variables in each project.
Compared with the prior art, the method and the device have the advantages that for the problem that variable addresses are mutually overlapped, the variable addresses in the called program can be fixed, so that the variable addresses in the called program can not be overlapped with the variable addresses in the called program, the problem that the variable addresses are overlapped when a plurality of programs are independently compiled and have function call relations can be avoided, the safety can be further improved by protecting the registers, the condition that the registers collide in the process of calling the programs is effectively avoided, the return value of the programs is incorrect, the variables which should not be modified are modified or the programs run away, and the normal running of the programs is ensured.
Referring to fig. 2, fig. 2 is a flowchart of another embodiment of a program calling method provided by the present invention, where the method includes:
step 21: the variables in the second program are set as global variables.
For convenience of implementation, variables used by the second program may be defined as global variables in the second program in advance, and addresses of the global variables may be fixed as reserved addresses. Taking 8051 single chip microcomputer as an example, the reserved address is an address in a memory, and the memory can be an internal random access memory (RAM, random Access Memory), wherein the internal random access memory comprises a general register area (RAMA), a non-general Register Area (RAMB) and an external random access memory area (RAMC); for example, for the 8051 single-chip microcomputer, variables A1, A2, A3 required to be used in the second program can be defined as global variables, and their addresses are set to 0x8051, 0x8052, 0x8053, respectively, and the addresses are reserved in the first program.
Step 22: the addresses of variables in the second program are reserved in the first program so that the addresses of variables in the first program do not overlap with the addresses of variables in the second program.
If the data in the register is to be avoided from being covered, on the one hand, the addresses of variables used by the second program can be reserved in the first program so as to avoid the addresses of the variables in the second program when the addresses of the variables in the first program are allocated, and the addresses of the variables are prevented from overlapping; specifically, the implementation of the method can be realized by reserved words in the 8051 singlechip.
The address of the variable in the second program reserved in the first program may be an address other than the address of the core-related register; the kernel-related register includes 4 sets of working registers R0-R7, an accumulator, an auxiliary register or a program status flag register, etc.
Since the kernel-related register also has a ram area, the kernel-related register in the ram area needs to be excluded when the address is reserved, so as to avoid that the kernel-related register corresponding to the first program is covered by the variable address in the second program. Addresses of 4 groups of working registers R0-R7 are fixed in the RAMA area; some core-related registers are addressed in special function registers such as accumulators, auxiliary registers or program status flag registers.
Step 23: and calling a second program to protect registers required by running the first program.
The data in the register required to be used for running the first program can be actively protected, and the protection is realized by a push mode.
Further, when the first program calls the second program, a push operation is executed, and data in the register is moved into a preset data protection area of the memory; when the first program finishes calling the second program, the pop operation is executed, and the data in the preset data protection area is moved back to the register.
Step 24: after the second program is called, the registers required to run the first program are restored.
If the data in the register is to be avoided being covered, on the other hand, the operation of popping and pushing the stack can be carried out before the first program is executed to call the second program, even if the second program can temporarily occupy the register when running, the popping operation can be carried out when the second program is completely executed, and the data originally stored in the register can be moved back to the register, so that the data in the register can be prevented from being tampered.
In a specific embodiment, an area may be reserved in the ram and the ram b as a preset data protection area to temporarily store the data in the register, before the first program needs to run the second program, the data in the register is sequentially moved to the preset data protection area, when the first program finishes calling the second program, and the second program is about to exit, the data is moved back from the preset data protection area to the register, so as to realize the protection of the register, and the data in the register is unchanged before and after the first program calls the second program.
In a specific implementation, two independently compiled projects P1 and P2 under an 8051 single chip microcomputer are taken as an example for illustration, a main function in the project P1 calls a sub-function S in the project P2, the project P1 has variables tmp 1-tmp 3, and the number of addresses occupied by the variables in the sub-function S is 3; other more projects or one project calls another project for more variables in multiple sub-functions or sub-functions, and so on.
According to the complexity of the code in the project P1, it is possible that the variables tmp 1-tmp 3 in the project P1 are distributed in the RAMA area, the RAMB area and the RAMC area, the addresses of the four groups of working registers R0-R7 are fixed in the RAMA area, and for the registers such as the accumulator ACC, the auxiliary Register B and the program status flag Register PSW in the special function Register (SFR, spacialFunction Register), the addresses are uniquely determined, and the contents in the addresses cannot be changed due to calling; the addresses of the variable and 4 sets of working registers R0 to R7 allocated in the RAM area cannot be overlapped or the contents cannot be covered due to the execution of the call operation, otherwise, the program operation is wrong, and unexpected results are generated.
If the scheme in this embodiment is not adopted, variable addresses in the engineering P2 may be randomly allocated to the ram area, the ram area or the ram area due to different complexity of codes, and the sub-function S in the engineering P2 may cover or tamper with the variable addresses or the addresses of the registers in the engineering P1, so that unexpected results occur after the main function in the engineering P1 calls the sub-function S in the engineering P2.
After the scheme is adopted, the variable addresses used by the subfunction S in the project P2 are fixed, 3 variable addresses of the subfunction S are reserved in the project P1, part of registers in the related registers of the kernel are needed to be avoided when the addresses are reserved, the variables in the project P1 can freely use the addresses of the related registers of the kernel, so that the variables in the subfunction S in the project P2 can be ensured not to influence the variables distributed in the RAMA area, the RAMB area or the RAMC area in the project P1, meanwhile, the data in the registers can be immediately stacked after the project P1 enters the subfunction S in the project P2 and immediately stacked before the subfunction S is exited, the values of the registers before the subfunction S is called by the project P1 can be ensured not to be covered or tampered, and the conflict can be avoided when the subfunction S is called.
Compared with the prior art, the method of the embodiment reserves the variable address of the second program in the first program in advance, protects the register in a stack entering and exiting mode, can avoid the conflict of the variable address, can avoid the conflict or the falsification of the register, is simple to realize, and can save the space of the RAM; and the variable address conflict and the register address conflict are fundamentally solved by adopting a software programming method, manual re-intervention is not needed, and the operation of a programmer is simplified.
Referring to fig. 3, fig. 3 is a schematic structural diagram of an embodiment of a chip provided by the present invention, where a control chip 30 includes a memory 31 and a processor 32 connected to each other, and the memory 31 is used for storing a computer program, and when the computer program is executed by the processor 32, the computer program is used for implementing a program calling method in the above embodiment, so that overlapping of variable addresses and register conflicts can be effectively avoided; the chip 30 may be a CPU, specifically, it may be an 8051 single-chip microcomputer.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an embodiment of a computer storage medium provided by the present invention, where the computer storage medium 40 is used to store a computer program 41, and the computer program 41, when executed by a processor, is used to implement the program calling method in the above embodiment.
The computer storage medium 40 may be a server, a usb disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory, a magnetic disk, or an optical disk, etc. that may store the program code.
In the several embodiments provided in the present invention, it should be understood that the disclosed method and apparatus may be implemented in other manners. For example, the above-described device embodiments are merely illustrative, e.g., the division of modules or units is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
In addition, each functional unit in each embodiment of the present invention may be integrated in one processing unit, each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The foregoing is only illustrative of the present invention and is not to be construed as limiting the scope of the invention, and all equivalent structures or equivalent flow modifications which may be made by the teachings of the present invention and the accompanying drawings or which may be directly or indirectly employed in other related art are within the scope of the invention.

Claims (5)

CN201910512465.8A2019-06-132019-06-13Program calling method, chip and computer storage mediumActiveCN112084013B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201910512465.8ACN112084013B (en)2019-06-132019-06-13Program calling method, chip and computer storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201910512465.8ACN112084013B (en)2019-06-132019-06-13Program calling method, chip and computer storage medium

Publications (2)

Publication NumberPublication Date
CN112084013A CN112084013A (en)2020-12-15
CN112084013Btrue CN112084013B (en)2024-04-05

Family

ID=73733752

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201910512465.8AActiveCN112084013B (en)2019-06-132019-06-13Program calling method, chip and computer storage medium

Country Status (1)

CountryLink
CN (1)CN112084013B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
JP2000099344A (en)*1998-09-222000-04-07Hitachi Ltd Program creation method and computer-readable recording medium
CN1430142A (en)*2001-12-292003-07-16深圳市中兴通讯股份有限公司上海第二研究所Device for realizing software down loading using single-chip processor in communication system and its method
JP2004326760A (en)*2003-04-102004-11-18Matsushita Electric Ind Co Ltd Compiler, recording medium, compiling device, communication terminal device, and compiling method
JP2005050227A (en)*2003-07-312005-02-24Chuo Electronics Co LtdElectronic device
CN1820252A (en)*2003-01-062006-08-16松下电器产业株式会社Compiler program, a computer-readable storage medium storing a compiler program, a compiling method and a compiling unit
CN1987797A (en)*2005-12-232007-06-27国际商业机器公司Method and system for avoiding software conflict
CN101076780A (en)*2004-12-132007-11-21皇家飞利浦电子股份有限公司 Compiling method, compiling device and computer system for cycle in program
CN101226488A (en)*2008-01-252008-07-23中兴通讯股份有限公司Method and system for solving collision of multiple case application programs in inner core state address space
CN103034593A (en)*2012-12-112013-04-10中国人民解放军国防科学技术大学Multi--core processor oriented on-chip lock variable global addressing storage method and device
CN108037982A (en)*2017-11-202018-05-15大唐微电子技术有限公司A kind of method and device of routine call

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7797505B2 (en)*2005-04-252010-09-14Hewlett-Packard Development Company, L.P.Program stack handling
KR100967761B1 (en)*2007-02-192010-07-05미쓰비시덴키 가부시키가이샤 Programmable Controller Peripherals, Replacement Methods, and Programs
RU2634172C1 (en)*2016-06-022017-10-24Акционерное общество "Лаборатория Касперского"Method of communication transmission between address spaces

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
JP2000099344A (en)*1998-09-222000-04-07Hitachi Ltd Program creation method and computer-readable recording medium
CN1430142A (en)*2001-12-292003-07-16深圳市中兴通讯股份有限公司上海第二研究所Device for realizing software down loading using single-chip processor in communication system and its method
CN1820252A (en)*2003-01-062006-08-16松下电器产业株式会社Compiler program, a computer-readable storage medium storing a compiler program, a compiling method and a compiling unit
JP2004326760A (en)*2003-04-102004-11-18Matsushita Electric Ind Co Ltd Compiler, recording medium, compiling device, communication terminal device, and compiling method
JP2005050227A (en)*2003-07-312005-02-24Chuo Electronics Co LtdElectronic device
CN101076780A (en)*2004-12-132007-11-21皇家飞利浦电子股份有限公司 Compiling method, compiling device and computer system for cycle in program
CN1987797A (en)*2005-12-232007-06-27国际商业机器公司Method and system for avoiding software conflict
CN101226488A (en)*2008-01-252008-07-23中兴通讯股份有限公司Method and system for solving collision of multiple case application programs in inner core state address space
CN103034593A (en)*2012-12-112013-04-10中国人民解放军国防科学技术大学Multi--core processor oriented on-chip lock variable global addressing storage method and device
CN108037982A (en)*2017-11-202018-05-15大唐微电子技术有限公司A kind of method and device of routine call

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ARM子程序嵌套调用怎样防止返回地址覆盖;刘志燕;郑维智;;科技资讯(12);32-33*
二进制程序跨平台移植时用户过程的数据恢复;刘晓楠;赵荣彩;庞建民;魏振方;;计算机工程与设计(第01期);161-167*

Also Published As

Publication numberPublication date
CN112084013A (en)2020-12-15

Similar Documents

PublicationPublication DateTitle
US5038281A (en)Acceleration of system interrupts between operating systems in guest-host relationship
US9075692B2 (en)Method, device and system for activating on-line patch
US5634046A (en)General purpose use of a stack pointer register
US6996677B2 (en)Method and apparatus for protecting memory stacks
US7917753B2 (en)Transferring control between programs of different security levels
CN110598405B (en)Runtime access control method and computing device
CN113672237B (en)Program compiling method and device for preventing memory boundary crossing
US20080301389A1 (en)Memory-protection method and apparatus
CN106055481B (en)Method and device for testing computer program
JP3179536B2 (en) How to operate a digital computer
CN112668008A (en)Method for realizing dynamic system call hijacking based on LSM
US7089242B1 (en)Method, system, program, and data structure for controlling access to sensitive functions
US10496433B2 (en)Modification of context saving functions
CN113485716B (en)Program compiling method and device for preventing memory boundary crossing
JP4754635B2 (en) Control flow protection mechanism
CN112084013B (en)Program calling method, chip and computer storage medium
CN116127445A (en)eBPF memory isolation method and system based on kernel mode memory isolation hardware characteristics
US7290176B2 (en)Method and system for generating stacked register dumps from backing-store memory
US8458790B2 (en)Defending smart cards against attacks by redundant processing
CN111143821B (en)Processor and SBoot processing method of native MPU thereof
US11144329B2 (en)Processor microcode with embedded jump table
CN113392395A (en)Stack protection method and device
US8949868B2 (en)Methods, systems and computer program products for dynamic linkage
CN116627549B (en)General function calling method, device, equipment and medium under SGX multithreading
CN113885887B (en)Concurrent application runtime reinforcement method and device

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
TA01Transfer of patent application right
TA01Transfer of patent application right

Effective date of registration:20210223

Address after:6 / F, building C3, future science and Technology City, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province (Wuhan area of free trade zone)

Applicant after:Wuhan Jiekai Technology Co.,Ltd.

Address before:230000, 10 floor, A3 building, innovation industrial park, 800 Wangjiang West Road, Hefei, Anhui.

Applicant before:Hefei Jiefa Technology Co.,Ltd.

GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp