System library access method and device and electronic equipment

文档序号:809173 发布日期:2021-03-26 浏览:18次 中文

阅读说明:本技术 系统库访问方法、装置以及电子设备 (System library access method and device and electronic equipment ) 是由 朴英敏 于 2020-12-01 设计创作,主要内容包括:本公开提供了一种系统库访问方法、装置以及电子设备。该方法包括:当检测到针对系统库的访问指令时,运行主调函数,主调函数用于跳转至被调函数;运行被调函数,通过被调函数执行如下操作:获取预配置的连接寄存器的地址;连接寄存器的地址为系统库区域的地址;基于连接寄存器的地址获取系统库的访问权限;基于访问权限访问连接寄存器的地址对应的系统库区域,并从系统库区域中获取预存储的目标指令;基于目标指令,确定被调函数的返回地址;基于返回地址,从被调函数返回运行主调函数。本公开可以访问系统库后保证主调函数正常运行。(The disclosure provides a system library access method and device and electronic equipment. The method comprises the following steps: when an access instruction for the system library is detected, a calling function is operated, and the calling function is used for jumping to a called function; and running the called function, and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area; determining a return address of the called function based on the target instruction; based on the return address, the home function is returned from the called function to run. The method and the system can ensure the normal operation of the key function after accessing the system library.)

1. A system library access method, comprising:

when an access instruction for a system library is detected, a calling function is operated, and the calling function is used for jumping to a called function;

the called function is run, and the following operations are executed through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of a system library region; acquiring the access authority of a system library based on the address of the connection register; accessing the system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

determining a return address of the called function based on the target instruction;

and returning and running the calling function from the called function based on the return address.

2. The method of claim 1, wherein the running a key function comprises:

executing a stack-in instruction in the callbacking function, and pushing a first instruction address in the stack-in instruction to a stack; the first instruction address is an address corresponding to an instruction of a position where the calling function continues to execute when the called function returns to continue to execute the calling function;

the target instruction comprises a pop instruction, and determining the return address of the called function based on the target instruction comprises:

and executing the pop instruction, acquiring the first instruction address from the stack, and taking the first instruction address as the return address.

3. The method according to claim 1, wherein the accessing, by the called function, the system library region corresponding to the address of the link register based on the access right comprises:

assigning the address of the link register to a program register through a called function so as to use the address of the link register as the address of the program register;

and based on the access authority, accessing the system library region corresponding to the address according to the address of the program register.

4. The method according to any one of claims 1 to 3, wherein before the obtaining of the pre-stored target instruction from the system library area through the called function, the method further comprises:

determining the system library region from the system library based on the address of the system library region;

adjusting the system library area from a read-only mode to a writable mode;

writing the target instruction into the system library area;

and adjusting the attribute of the system library area into an executable program so as to acquire the target instruction from the system library area.

5. The method according to any of claims 1 to 3, wherein the system library area comprises in particular at least one of:

free storage space for variables in the system library;

free storage space of code segments in the system library;

a code region of the system library.

6. The method of any of claims 1 to 3, wherein said running the calling function back from the called function based on the return address comprises:

determining a corresponding instruction of the return address in the key function;

returning the calling function from the called function and running the calling function from the instruction of the calling function.

7. An apparatus for accessing a system library, comprising:

the system comprises a first running module, a second running module and a third running module, wherein the first running module is used for running a calling function when an access instruction aiming at a system library is detected, and the calling function is used for jumping to a called function;

a second running module, configured to run the called function, where the following operations are executed by the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of a system library region; acquiring the access authority of a system library based on the address of the connection register; accessing the system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

a first determining module, configured to determine, based on the target instruction, a return address of the called function;

and the third running module is used for returning and running the calling function from the called function based on the return address.

8. The apparatus of claim 7, wherein the first operating module is specifically configured to:

executing a stack-in instruction in the callbacking function, and pushing a first instruction address in the stack-in instruction to a stack; the first instruction address is an address corresponding to an instruction of a position where the calling function continues to execute when the called function returns to continue to execute the calling function;

the target instruction comprises a pop instruction, and the first determining module is specifically configured to:

and executing the pop instruction, acquiring the first instruction address from the stack, and taking the first instruction address as the return address.

9. A seed device, comprising:

the electronic device comprises a memory and a processor;

the memory has stored therein a computer program;

the processor, when executing the computer program, is configured to perform the method of any of claims 1-6.

10. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method of any one of claims 1 to 6.

Technical Field

The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for accessing a system library, and an electronic device.

Background

Many optimizations and debugs in the development process of the application program need to depend on the system library, so the application program often calls functions to access the system library, but not all the application programs have system library access authority, and for the application program without the system library access authority, the system library needs to be accessed in a special way.

At present, an application program without system library access authority can conveniently and freely access a system library by configuring an address of a Link Register (LR) in a called function to be called, the address of the link register configured in this way is generally an address of a data segment, and the address of the link register also indicates an execution position of a calling function when the called function returns to run the calling function.

Disclosure of Invention

This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.

A first aspect of the present disclosure provides a system library access method, including:

when an access instruction for the system library is detected, a calling function is operated, and the calling function is used for jumping to a called function;

and running the called function, and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

determining a return address of the called function based on the target instruction;

based on the return address, the home function is returned from the called function to run.

A second aspect of the present disclosure provides an apparatus for accessing a system library, including:

the system comprises a first running module, a second running module and a third running module, wherein the first running module is used for running a calling function when an access instruction aiming at a system library is detected, and the calling function is used for jumping to a called function;

the second running module is used for running the called function and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

the first determining module is used for determining the return address of the called function based on the target instruction;

and the third running module is used for returning and running the calling function from the called function based on the return address.

In a third aspect of the present disclosure, an electronic device is provided, which includes:

the electronic device comprises a memory and a processor;

the memory has a computer program stored therein;

a processor for performing the method of the first aspect when executing the computer program.

In a fourth aspect of the disclosure, a computer-readable medium is provided, on which a computer program is stored, which program, when executed by a processor, is the method of the first aspect.

The technical scheme provided by the disclosure has the following beneficial effects:

in this embodiment, when an access instruction for the system library is detected, a calling function may be run, where the calling function is used to jump to a called function, so that the called function may be run, and the following operations may be performed by the called function: acquiring the address of a pre-configured connection register; acquiring the access authority of the system library based on the address of the connection register; the system library area corresponding to the address of the connection register is accessed based on the access authority, and therefore the system library can be freely accessed through the address of the pre-configured connection register, meanwhile, the application can also obtain the pre-stored target instruction from the system library area corresponding to the address of the connection register, and the return address of the called function can be determined based on the target instruction, so that the master call function can be returned and operated from the called function based on the return address.

Drawings

The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.

FIG. 1 is a schematic diagram of one embodiment of a library access method of the disclosed system;

FIG. 2 is a schematic diagram of an instruction execution flow according to the present disclosure;

FIG. 3 is an indication of pointers in the stack of the present disclosure;

FIG. 4 is a schematic diagram of another embodiment of a library access method of the disclosed system;

FIG. 5 is a schematic diagram of a library access device of the disclosed system;

fig. 6 is a schematic structural diagram of an electronic device according to the present disclosure.

Detailed Description

Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.

It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.

The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.

It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the devices, modules or units to be determined as different devices, modules or units, and are not used for limiting the sequence or interdependence relationship of the functions executed by the devices, modules or units.

It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.

The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.

In the following, several technical terms referred to in the present disclosure are explained first.

The system library, which may also be referred to as a dynamic link library or so dynamic library, is a dynamic library under the Linux system.

The link register, i.e., the R14 register, has two roles as the address of the link register of the present disclosure: 1. as the return address of the function being called. When the calling function calls the called function, the return address of the called function is stored in the R14 register, and when the calling function returns, the address in the R14 register is assigned to a PC (program counter), so that the return of the called function can be realized. 2. An object used to indicate access to a system library, for example, may indicate whether an application call was called by a function to access the system library or whether other object (e.g., system library) calls were called by a function to access the system library.

In this embodiment, an address of a certain register indicates an address stored in the register, and assigning a certain address to a register indicates storing the address in the register.

And a program register, wherein the address of the program register is the address of the next instruction to be executed, for example, a first instruction is in an execution stage, a second instruction is in a decoding stage, a third instruction is in an instruction fetching stage, and the address of the program register points to the third instruction when the first instruction is executed.

As described above, in the existing scheme, after accessing the system library by configuring the address of the connection register, because the address of the connection register is the address of one data segment, based on the fact that the data segment cannot be returned from the called function to normally run the callmaker function, the callmaker function is caused to run abnormally, and SIGSEGV is also triggered to be abnormal, and so on, in order to solve the above technical problem, please refer to fig. 1, the present disclosure provides a system library access method, which can be executed by a terminal device, specifically, by an application program on the terminal device, and specifically, the method includes the following steps:

step S101, when an access instruction aiming at a system library is detected, a calling function is operated, and the calling function is used for jumping to a called function;

when the application detects an access instruction to the system library, the calling function is executed. The access instruction for the system library may be input by the user through operating the application program, may be generated by the application program itself, or may be sent to the application program from another module or device.

The application generally refers to an application without system library access rights, and of course, an application with system library access rights may also access the system library using the system library access method of the disclosed system.

The calling function comprises a function jump instruction, and the function jump instruction comprises information of a called function to be jumped to, so that the application program can jump to the called function when running the function jump instruction in the calling function. The calling function refers to a function calling other functions, and the called function refers to a called function.

Step S102, running the called function, and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

after the application program jumps to the called function, the application program starts to run the called function, and the application program can execute the following operations when running the called function:

as described above, the address of the link register may indicate the object accessing the system library, then:

the application program running the called function can obtain the address of the pre-configured connection register, and the address of the pre-configured connection register is pre-configured in the following way: the application program determines the address of the system library region, and takes the address of the system library region as the address of the connection register.

In this embodiment, the system library includes a plurality of libraries (the system library region belongs to one of the libraries, that is, the system library region is a partial region of the system library), each library has an address space mapped thereto, and the address of the system library region is within the address space range corresponding to the system library region.

After the address of the link register is obtained, the application program can send the address of the link register to the system library by running the called function, so that the system library can grant the permission of the application program for accessing the system library based on the address of the link register.

After the access authority of the system library is obtained, the application program can access the system library based on the access authority by running the called function. The application program access system library specifically comprises: and the application program accesses the system library region corresponding to the address based on the address of the connection register.

It can be seen that, in this embodiment, if the application program does not have the access right of the system library, the address of the connection register may be configured to be the address of the system library region by pre-configuring the address of the connection register, so that the application program may access the system library based on the pre-configured address of the connection register, and the application program without the access right of the system library may break through the limitation of the access right of the system library to freely access the system library.

As described above, the address of the link register may also indicate the return address of the called function, then:

in this embodiment, as the above-mentioned link register address points to the system library area, and the system library area is not an executable instruction as the data segment in the existing solution, in order to make the callmaker function operate normally after the application accesses the system library, the present disclosure may pre-store the target instruction in the system library area, so that the application may obtain the target instruction from the system library area after accessing the system library area, and the application may jump to execute the target instruction.

In this embodiment, the called function may be a dlopen or dlsym function.

Step S103, determining a return address of the called function based on the target instruction;

based on the target instruction, the application program may determine to obtain the return address of the called function.

In this embodiment, the return address indicates an address of an instruction at a location where the calling function continues to execute when the calling function is executed after the called function is executed by jumping from the calling function.

And step S104, returning the master function from the called function to operate the master function based on the return address so as to normally operate the master function after the called function is operated to access the system library.

The application program can be based on the return address, when the called function returns to run the calling function, the calling function can be continuously run downwards from the instruction position corresponding to the return address in the calling function, and therefore the application program can still normally run the calling function after the called function is run and the system library is accessed.

As can be seen, in this embodiment, when an access instruction for the system library is detected, a calling function may be run, where the calling function is used to jump to a called function, so that the called function may be run, and the following operations may be performed by the called function: acquiring the address of a pre-configured connection register; acquiring the access authority of the system library based on the address of the connection register; the system library area corresponding to the address of the connection register is accessed based on the access authority, and therefore the system library can be freely accessed through the address of the pre-configured connection register, meanwhile, the application can also obtain the pre-stored target instruction from the system library area corresponding to the address of the connection register, and the return address of the called function can be determined based on the target instruction, so that the master call function can be returned and operated from the called function based on the return address.

It can be seen that, in this embodiment, the addresses of the continuous registers may not only point to the system library region to facilitate the application program to access the system library, but also store a legal instruction in the system library region, for example, the target instruction may jump back to the instruction corresponding to the return address in the callmaker function based on the target instruction to continue running the callmaker function.

Therefore, the scheme of the embodiment can avoid the occurrence of abnormal SIGSEGVGV and other phenomena.

Optionally, step S102, by using the called function, accesses the system library region corresponding to the address of the link register based on the access right, including:

assigning the address of the link register to the program register through the called function so as to take the address of the link register as the address of the program register;

and based on the access authority, accessing the system library region corresponding to the address according to the address of the program register.

In this embodiment, when the called function runs to the last instruction, the instruction means: assigning the address of the link register to the program register, enabling the called function to run the last instruction to assign the value to the program register, and using the address of the link register as the address of the program register, where the program register is used to store the address of an instruction to be executed next to the current instruction (i.e., the last instruction), and after the last instruction is executed, the application program may access a system library area corresponding to the address based on the address of the program register, obtain a pre-stored target instruction from the area, and execute the target instruction.

Optionally, the step S101 of running the key function may include:

executing a stack-in instruction in the callbacking function, and pressing a first instruction address in the stack-in instruction into a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the calling function when the called function returns to continuously execute the calling function;

the target instruction includes a pop instruction, and the step S103 determines, based on the target instruction, a return address of the called function, including:

and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.

In this embodiment, the callmaker function further includes a stack instruction, the stack instruction is configured with a program register, and the program register stores the first instruction address, so that the application program runs the stack instruction in the callmaker function, can obtain the first instruction address stored in the program register, and pushes the first instruction address to the stack.

It should be noted that the first instruction address stored in the program register points to an address of an instruction to be executed next to the current push instruction, that is, an address of an instruction at a position to be continuously executed in the main function when the called function returns to execute the main function, where the first instruction address is actually a return address.

In this embodiment, after the target instruction is obtained from the system library area, the target instruction may be a pop instruction, the pop instruction is executed, the first instruction address may be taken out from the stack, and the first instruction address is assigned to the program register, so that the instruction corresponding to the first instruction address may be used as a next instruction to be executed after the pop instruction is executed, after the application program executes the pop instruction, the instruction corresponding to the first instruction address is skipped to execute, which is equivalent to returning the key function, and the key function may be continuously executed from the instruction corresponding to the first instruction address in the key function.

Optionally, the address of the preconfigured connection register is preconfigured by a key function.

In this embodiment, the callmaker function further includes an address configuration instruction, and when the application program runs the address configuration instruction of the connection register in the callmaker function, the application program may assign an address of the system library area to the connection register as an address of the connection register, so that the subsequent callmaker function may directly obtain the address of the connection register preconfigured by the callmaker function.

As shown in fig. 2, a flowchart of instruction execution of a key function in the present application is shown, where the key function includes an initial instruction, an address configuration instruction, a stack entry instruction, a function jump instruction, and an instruction corresponding to a first instruction address, and an instruction execution operation sequence in the key function is as follows:

after the main program starts to run, firstly running an initial instruction and initializing;

the main function runs to an address configuration instruction, and the address of the system library area is configured to be the address of the connection register;

the callmaker function runs to the stack-in instruction and acquires an address in a first program register, wherein the address in the first program register points to an address which is added with 8 bytes of a current instruction address, the current instruction address is the address of the stack-in instruction, and the address added with 8 bytes is the first instruction address;

the method comprises the steps that a calling function runs to a function jump instruction, an application program jumps from the running of the calling function to the running of a called function, the running called function can firstly obtain the access authority of a system library based on the address of a connection register so as to realize free access to the system library, and when the application program runs to the last instruction of the called function, the address in the connection register can be assigned to a program register, so that after the application program executes the last instruction of the called function, a stack-out instruction can be obtained from the system library region corresponding to the address in the connection register, and the stack-out instruction is executed;

the application program can take out the first instruction address from the stack when executing the pop instruction, and assigns the first instruction address to the program register, so that the application program executes the instruction corresponding to the first instruction address after the pop instruction is executed, the main function can be returned from the called function to run, and the main function can run normally.

Fig. 3 is a situation indicated by a pointer during instruction execution, where the stack top position during instruction execution corresponding to an initial instruction, a called function, and a first instruction address is as in fig. 3, it needs to be emphasized that, when an instruction is executed to stack, an address written in a stack is two words (a word represents a word length), and the stack top position is as in fig. 3, when an instruction is executed to stack, two words are also read in the stack, and the stack top position is consistent with that when the instruction is executed to stack, it is apparent that positions of the stack top before and after a main call function calls the called function are unchanged, so that the first instruction address can be accurately fetched, and normal operation of the main call function can be ensured based on the first instruction address.

Optionally, in this embodiment, the system library area specifically includes at least one of the following:

free storage space for variables in the system library;

free storage space of code segments in the system library;

code area of the system library.

The application program only needs to configure the address of the connection register to the address range corresponding to any one of the plurality of libraries included in the system library, and the system library considers that the address of the connection register points to the system library, and the system library calls the called function to access the system library, so that the system library grants the access right of the application program to access the system library, and therefore, the address of the connection register can be configured to the address corresponding to the system library region, and the system library region includes at least one of the following possible cases:

the system library comprises variables, wherein the variables can be global variables, the variables comprise free storage spaces, and the system library area can be the free storage spaces in the variables;

the system library also comprises code segments, the code segments are page-aligned and have a plurality of free storage spaces, and the free storage spaces are generally at the end positions of the code segments, so that the system library area can also be the free storage space at the end positions of the code segments;

the system library region may also be a code region in the system library, which refers to a region in which a large amount of code is stored.

The target instruction is obtained from the system library area, namely the machine code (i.e. the code) of the target instruction is substantially obtained, if the system library area is a code area in the system library, the code area itself comprises the machine code requiring many instructions, and the application program can directly scan the code area of the system library to find the machine code of the target instruction, so that the target instruction does not need to be written in the system library area in advance.

If the system library area is a free storage space of a variable in the system library or a free storage space of an end position of a code segment in the system library, the application program needs to write a target instruction (i.e. a machine code of the target instruction) into the system library area before accessing the system library, specifically:

before step S102 obtains the pre-stored target instruction from the system library area through the called function, the method may further include:

determining a system library area from the system library based on the address of the system library area;

adjusting the system library area from a read-only mode to a writable mode;

writing the target instruction into a system library area;

and adjusting the attribute of the system library area into an executable program so as to acquire the target instruction from the system library area.

In this embodiment, the application program may determine an address of the system library area, so that the system library area in the system library may be determined based on the address of the system library area, the application program may adjust the system library area from a read-only mode to a writable mode, so as to write the target instruction into the system library area, and the application program further needs to adjust an attribute of the system library area to an executable program, so that the subsequent application program can obtain the target instruction from the system library area.

If the system library area is the free storage space of the variable, then: the application program can determine that the address of the system library area is determined by analyzing an ELF (executable and linkable format) file structure; writing the target instruction to the system library area includes: writing a machine code of a target instruction in the last word in the memory page of the variable; the adjusting of the attribute of the system library area to be an executable program specifically comprises the following steps: and calling the mprotect function by the application program to set the accessibility authority of the memory page of the variable, and adding the ID of the application program into the accessibility list of the memory page.

Optionally, step S103 returns the master function from the called function to run based on the return address, and includes:

determining a corresponding instruction of a return address in a key function;

and returning the calling function from the called function, and running the calling function from the instruction of the calling function.

In this embodiment, the return address points to a certain instruction in the key function, and the application program may determine the instruction corresponding to the return address in the key function, so that when the called function returns to run the key function, the key function may be continuously run from the instruction, and thus the main function may be normally run.

In summary, referring to fig. 4, the execution flow of the system library access method of the present disclosure is as follows:

s1, when an access instruction for the system library is detected, starting to run a key function;

s2, the application program runs a configuration instruction of a connection register in the calling function, and assigns an address corresponding to the system library area to the connection register;

s3, the application program runs the stack-in instruction in the calling function, and the first instruction address is pressed into the stack;

s4, the application program runs a function call instruction in the calling function and jumps to the called function;

s5, the application program runs the called function, acquires the address of the connection register configured in the calling function through the called function, and sends the address of the connection register to the system library;

s6, the system library determines the address of the connection register as the address of the system library region, and the system library grants the access authority of the application program;

the system library is considered to be accessed by the function called by the system library region call instead of the function called by the application program call based on the address of the connection register, so that the application program access permission is granted.

S7, the application program can access the system library based on the access authority, and meanwhile, the value of the connection register is assigned to the program register by running the last instruction in the called function, so that the application program can obtain the pre-stored pop instruction from the system library area corresponding to the address of the connection register and jump to the pop instruction.

S8, the application program executes the pop instruction, obtains the first instruction address from the stack, and assigns the first instruction address to the program register so as to take the first instruction address as a return address;

only assigning the first instruction address to the program register, and after the application program executes the pop instruction, skipping to execute the instruction corresponding to the first instruction address, wherein the first instruction address is used as the return address of the called function.

S9: and returning to the instruction corresponding to the return address in the operation of the calling function to continue operating the calling function.

The scheme of this embodiment is substantially the same as the scheme of the embodiment shown in fig. 1, and a specific implementation manner of this embodiment may refer to the scheme shown in fig. 1, which is not described herein again.

Referring to fig. 5, the present disclosure further provides an accessing apparatus for a system library, including:

a first running module 501, configured to run a key function when an access instruction for a system library is detected, where the key function is used to jump to a called function;

a second running module 502, configured to run a called function, where the called function performs the following operations: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

a first determining module 503, configured to determine, based on the target instruction, a return address of the called function;

a third execution module 504, configured to return the running of the calling function from the called function based on the return address.

Optionally, the first operation module 501 is specifically configured to:

executing a stack-in instruction in the callbacking function, and pressing a first instruction address in the stack-in instruction into a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the calling function when the called function returns to continuously execute the calling function;

the target instruction includes a pop instruction, and the first determining module 503 is specifically configured to:

and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.

Optionally, when the second running module 502 accesses the system library region corresponding to the address of the connection register based on the access right through the called function, the second running module is specifically configured to:

assigning the address of the link register to the program register through the called function so as to take the address of the link register as the address of the program register;

and based on the access authority, accessing the system library region corresponding to the address according to the address of the program register.

Optionally, the apparatus further includes a second determining module, a first adjusting module, a data writing module, and a second adjusting module; before the second running module 502 obtains the pre-stored target instruction from the system library area through the called function;

the second determining module is used for determining the system library area from the system library based on the address of the system library area;

the first adjusting module is used for adjusting the system library area from a read-only mode to a writable mode;

the data writing module is used for writing the target instruction into the system library area;

and the second adjusting module is used for adjusting the attribute of the system library area into an executable program so as to obtain the target instruction from the system library area.

Optionally, the system library area specifically includes at least one of the following:

free storage space for variables in the system library;

free storage space of code segments in the system library;

code area of the system library.

Optionally, the third operation module 504 is specifically configured to:

determining a corresponding instruction of a return address in a key function;

and returning the calling function from the called function, and running the calling function from the instruction of the calling function.

Referring now to fig. 6, a schematic diagram of an electronic device (e.g., the terminal device of fig. 1) 600 suitable for implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.

The electronic device includes: a memory and a processor, wherein the processor may be referred to as the processing device 601 hereinafter, and the memory may include at least one of a Read Only Memory (ROM)602, a Random Access Memory (RAM)603 and a storage device 608 hereinafter, which are specifically shown as follows:

as shown in fig. 6, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded into a Random Access Memory (RAM)603 from a storage means 606, 608. In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.

Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 606, including, for example, tape, hard disk, etc., storage 608; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.

In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such embodiments, the computer program may be downloaded and installed from a network through the communication device 609, or installed from the storage device 606608, or installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present disclosure.

It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.

In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.

The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.

The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: when an access instruction for the system library is detected, a calling function is operated, and the calling function is used for jumping to a called function; and running the called function, and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area; determining a return address of the called function based on the target instruction; based on the return address, the home function is returned from the called function to run.

Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.

The modules or units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of a module or unit does not in some cases constitute a limitation of the unit itself, for example, the first execution module may also be described as a "module that executes a key function when an access instruction to a system library is detected".

The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.

In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

According to one or more embodiments of the present disclosure, there is provided a system library access method including:

when an access instruction for the system library is detected, a calling function is operated, and the calling function is used for jumping to a called function;

and running the called function, and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

determining a return address of the called function based on the target instruction;

based on the return address, the home function is returned from the called function to run.

Optionally, the running of the key function includes:

executing a stack-in instruction in the callbacking function, and pressing a first instruction address in the stack-in instruction into a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the calling function when the called function returns to continuously execute the calling function;

the target instruction comprises a pop instruction, and the step of determining the return address of the called function based on the target instruction comprises the following steps:

and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.

Optionally, accessing, by the called function, the system library area corresponding to the address of the connection register based on the access right includes:

assigning the address of the link register to the program register through the called function so as to take the address of the link register as the address of the program register;

and based on the access authority, accessing the system library region corresponding to the address according to the address of the program register.

Optionally, before obtaining the pre-stored target instruction from the system library area through the called function, the method further includes:

determining a system library area from the system library based on the address of the system library area;

adjusting the system library area from a read-only mode to a writable mode;

writing the target instruction into a system library area;

and adjusting the attribute of the system library area into an executable program so as to acquire the target instruction from the system library area.

Optionally, the system library area specifically includes at least one of the following:

free storage space for variables in the system library;

free storage space of code segments in the system library;

code area of the system library.

Optionally, based on the return address, returning the running master function from the called function, including:

determining a corresponding instruction of a return address in a key function;

and returning the calling function from the called function, and running the calling function from the instruction of the calling function.

According to one or more embodiments of the present disclosure, there is provided an access device for a system library, including:

the system comprises a first running module, a second running module and a third running module, wherein the first running module is used for running a calling function when an access instruction aiming at a system library is detected, and the calling function is used for jumping to a called function;

the second running module is used for running the called function and executing the following operations through the called function: acquiring the address of a pre-configured connection register; the address of the connection register is the address of the system library region; acquiring the access authority of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access authority, and acquiring a pre-stored target instruction from the system library area;

the first determining module is used for determining the return address of the called function based on the target instruction;

and the third running module is used for returning and running the calling function from the called function based on the return address.

Optionally, the first operation module is specifically configured to:

executing a stack-in instruction in the callbacking function, and pressing a first instruction address in the stack-in instruction into a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the calling function when the called function returns to continuously execute the calling function;

the target instruction comprises a pop instruction, and the first determining module is specifically configured to:

and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.

Optionally, when the second running module accesses the system library region corresponding to the address of the connection register based on the access right through the called function, the second running module is specifically configured to:

assigning the address of the link register to the program register through the called function so as to take the address of the link register as the address of the program register;

and based on the access authority, accessing the system library region corresponding to the address according to the address of the program register.

Optionally, the apparatus further includes a second determining module, a first adjusting module, a data writing module, and a second adjusting module; before the second operation module obtains a pre-stored target instruction from the system library area through the called function;

the second determining module is used for determining the system library area from the system library based on the address of the system library area;

the first adjusting module is used for adjusting the system library area from a read-only mode to a writable mode;

the data writing module is used for writing the target instruction into the system library area;

and the second adjusting module is used for adjusting the attribute of the system library area into an executable program so as to obtain the target instruction from the system library area.

Optionally, the system library area specifically includes at least one of the following:

free storage space for variables in the system library;

free storage space of code segments in the system library;

code area of the system library.

Optionally, the third operation module is specifically configured to:

determining a corresponding instruction of a return address in a key function;

and returning the calling function from the called function, and running the calling function from the instruction of the calling function.

The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.

Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.

Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

20页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于双Soc存储系统异常处理机制的继电保护装置及方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类