Extraction method and device of processor execution context, electronic equipment and storage medium
By obtaining the tracking permissions of the target process and using the process tracking function to obtain the processor execution context, the complex problem of operating system kernel modification in the existing technology is solved, and simple and efficient extraction of the processor execution context is realized, reducing system impact and maintenance costs , improves debugging efficiency.
Patent Information
- Application Number
- CN202411376386.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2024-12-24
AI Technical Summary
Existing processor execution context extraction methods require multiple modifications to the operating system kernel, which is complex in implementation processes and may lead to damage to the system configuration state, increasing maintenance costs and complexity.
By obtaining the tracking permissions of the target process, using the process tracking function to obtain the execution context of the user-state and kernel-state processors, using the process copy function to generate the target process, and running the target program on it, receiving authorization signals to obtain tracking permissions, blocking and revoking Block the target process to achieve context extraction.
It realizes simple and efficient extraction of processor execution context, avoids modifications to the operating system kernel, reduces implementation difficulty and system impact, reduces maintenance costs, and improves debugging and analysis efficiency.
Smart Images

Figure CN119179553A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to processor debugging and verification, and in particular to a method, device, electronic device and storage medium for extracting processor execution context. Background Art
[0002] The CPU (Central Processing Unit) execution context refers to the execution status information recorded by the CPU when executing a process or thread. It contains the status information of various scenarios of program execution on the CPU, such as the usage information of architecture-specific registers (MSRs), general registers, control registers, status registers, and memory. In modern computer systems, the CPU execution context is crucial for program debugging, performance analysis, and fault diagnosis, and the basis of all this is to extract the CPU execution context.
[0003] In some existing technologies, the bootstrap processor (BSP) is used to extract the execution context in the interrupt service program through periodic interrupts, and other APs (Application Processors) enter the interrupt service program to extract the context by sending IPI (Inter-Processor Interrupt). Although this method can implement context extraction in different operating system environments, it requires multiple modifications to the operating system kernel, and the implementation process is relatively complicated. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a processor execution context extraction method, device, electronic device and storage medium, which are convenient for simply and efficiently implementing the extraction of CPU execution context.
[0005] In order to achieve the above application purpose, the following technical solutions are adopted: The present application embodiment provides a method for extracting a processor execution context, the method comprising: Obtain the tracking authority of the target process; based on the tracking authority, track and obtain the user-mode processor execution context of the target program loaded by the target process; if the target process is monitored to execute a system call instruction, obtain the kernel-mode processor execution context of the target program.
[0006] According to a specific implementation of an embodiment of the present application, tracking and obtaining the user-mode processor execution context of the target program loaded by the target process according to the tracking permission includes: The register status information of the target program loaded by the target process is obtained by using a process tracking function.
[0007] According to a specific implementation method of an embodiment of the present application, tracking and obtaining the user-state processor execution context of the target program loaded by the target process based on the tracking permission includes: using a process tracking function to obtain memory status information of the target program loaded by the target process.
[0008] According to a specific implementation of an embodiment of the present application, obtaining the kernel-mode processor execution context of the target program includes: Calling a process tracking function to obtain register status information of the target process; Obtaining a system call number from the register status information; According to the system call number, a complete kernel state execution context of the target process during the execution of the corresponding system call is obtained.
[0009] According to a specific implementation of the embodiment of the present application, obtaining the tracking permission of the target process includes: generating a target process using a process copy function, and running a target program on the target process; Receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used to indicate that the target process authorizes and agrees to be tracked; The target process is tracked based on the authorization signal, and the target process is blocked until it is unblocked.
[0010] According to a specific implementation manner of an embodiment of the present application, after obtaining the kernel-mode processor execution context of the target program, the method further includes: sending an unblocking instruction to the target process to resume the operation of the target program.
[0011] According to a specific implementation manner of the embodiment of the present application, the target program is a single-threaded or multi-threaded program.
[0012] In a second aspect, an embodiment of the present application provides a device for extracting a processor execution context, comprising: A first acquisition program unit is used to obtain the tracking permission of the target process; A tracking program unit, used for tracking and obtaining a user-mode processor execution context of a target program loaded by the target process according to the tracking authority; The monitoring and obtaining program unit is used to obtain the kernel state processor execution context of the target program if it monitors whether the target process executes the system call instruction.
[0013] According to a specific implementation of the embodiment of the present application, the tracking program unit is specifically used to obtain the register state information of the target program loaded by the target process by using a process tracking function; and / or, It is specifically used to obtain the memory status information of the target program loaded by the target process by using the process tracking function.
[0014] According to a specific implementation of the embodiment of the present application, the second acquisition program unit includes: a calling program module, which is used to call a process tracking function to obtain the register state information of the target process; A first acquisition program module is used to obtain a system call number from the register state information; The second acquisition program module is used to acquire the complete kernel state execution context of the target process during the execution of the corresponding system call according to the system call number.
[0015] According to a specific implementation of the embodiment of the present application, the first program acquisition unit includes: a program generation module, which is used to generate a target process using a process copy function and run a target program on the target process; A receiving program module, used for receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used for indicating that the target process authorizes and agrees to be tracked; The tracking program module tracks the target process based on the authorization signal and blocks the target process until it is unblocked.
[0016] According to a specific implementation method of an embodiment of the present application, the device also includes: a recovery program unit, which is used to send an unblocking instruction to the target process after obtaining the kernel-mode processor execution context of the target program to resume the operation of the target program.
[0017] In a third aspect, the present application also provides an electronic device, including: One or more processors; Memory; One or more executable program codes are stored in the memory, and the one or more processors read the executable program codes stored in the memory and run the programs corresponding to the executable program codes to execute the method for extracting the processor execution context described in any one of the first aspects.
[0018] In a fourth aspect, the present application also provides, in an embodiment, a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to execute the processor execution context extraction method described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 A flowchart of a method for extracting a processor execution context provided in one embodiment of the present application.
[0021] Figure 2 A flowchart of a method for extracting a processor execution context provided in one embodiment of the present application.
[0022] Figure 3 A flowchart of a method for extracting a processor execution context provided in one embodiment of the present application.
[0023] Figure 4 A flowchart of a method for extracting processor execution contexts for multiple threads provided in one embodiment of the present application; Figure 5 A schematic block diagram of a device for extracting a processor execution context provided in an embodiment of the present application; Figure 6 This is a schematic diagram of the structure of an embodiment of the electronic device of the present application. DETAILED DESCRIPTION
[0024] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0025] It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0026] At present, in some existing processor execution context extraction schemes, it is usually necessary to make multiple modifications to the operating system kernel, including writing device drivers, modifying the system IDT (Interrupt Descriptor Table), adjusting interrupt service routines, and changing the current system page table. Therefore, the implementation process of this scheme is relatively complicated and cumbersome, and it may also cause the destruction of the system configuration state, thereby causing kernel crashes and system downtime. In addition, device drivers are dependent on the operating system version, and different versions need to maintain compatibility, which increases maintenance costs and complexity.
[0027] Figure 1A flowchart of a method for extracting a processor execution context provided by an embodiment of the present application; at least in view of the above-mentioned problem that the implementation process of some existing processor execution context extraction schemes is relatively complicated and cumbersome, see Figure 1 The embodiment of the present application at least provides a method for extracting a processor execution context, which can be applied to performance debugging and verification scenarios of programs and CPUs. The method for extracting a processor execution context S100 includes: Step S110: Obtain the tracking permission of the target process.
[0028] In this embodiment, before executing the solution provided in the embodiment of the present application, the developer or system administrator will start a master control process for monitoring and controlling other processes. The master control process can obtain the execution context state information of the target process through system calls.
[0029] Specifically, the master process can request the tracking permission for the target process by calling the system call function to implement the tracking of the target process, so as to ensure that the master process can monitor the execution status of the target process, avoid modifying the operating system kernel and writing complex device drivers, thereby reducing the difficulty of implementing CPU execution context extraction to a certain extent.
[0030] S120. According to the tracking authority, track and obtain the user-mode processor execution context of the target program loaded by the target process.
[0031] The program is a static piece of code. A process is a unit of hardware resource allocation. Each time a program is executed, the operating system creates a process and allocates necessary hardware resources to it, such as memory, CPU time, files, and I / O devices. The target process is responsible for loading the target program's instructions and data into memory and starting to execute the program's code.
[0032] After successfully obtaining the tracing permission, the master process uses process tracing functions, such as ptrace (peekuser / getregs / getfpregs), to obtain the register status information of the target program, including MSR, general registers, control registers, and floating-point registers, and saves this information to the memory of the master process.
[0033] S130: If it is monitored whether the target process executes a system call instruction, the kernel state processor execution context of the target program is obtained.
[0034] The master process captures the system call signal sent by the target process by setting ptrace. Specifically, the master process can use the ptrace(SYSCALL) function command to monitor whether the target process executes the system call instruction. If it is detected that the target process passes a SYSCALL (an instruction used to indicate a system call) instruction, it is determined that the target process has executed the system call instruction.
[0035] In this embodiment, the master control process can grasp the interaction between the target process and the operating system kernel in real time by monitoring the target process executing system call instructions. The master control process thereby knows that the target process switches to interact with the operating system, laying the foundation for subsequent kernel state context extraction, so that the master control process can respond to the behavior of the target process in a timely manner.
[0036] When the target program is detected to execute a system call, the master process calls the ptrace function again, such as ptrace(GET REGS), to obtain the register status information of the target program in kernel state and save it. At this point, the execution context information of both user state and kernel state are fully recorded, providing comprehensive data support for subsequent CPU debugging and verification analysis.
[0037] The method for extracting the processor execution context provided in the embodiment of the present application obtains the execution context of the target program through a tracking mechanism between processes. Since there is no need to modify the operating system kernel and page table structure, the implementation process is simpler and more efficient, and has little impact on the system, thereby facilitating the simple and efficient extraction of the CPU execution context.
[0038] In some existing technical solutions, since the operating system kernel needs to be modified, the device driver needs to be rewritten accordingly. The device driver is dependent on the version of the operating system. Different versions of the operating system need to maintain driver compatibility to adapt to different versions of the operating system, which results in high maintenance costs.
[0039] For this purpose, see Figure 2 As shown, in some embodiments, tracking and obtaining the user-mode processor execution context of the target program loaded by the target process according to the tracking permission (S120) includes: S121a, using a process tracking function to obtain register status information of the target program loaded by the target process.
[0040] In some embodiments, after the register state information of the target program loaded by the target process is obtained, the register state information is stored.
[0041] Specifically, the master process calls the ptrace(PEEKUSER) function to obtain the register status information of the target program, including the status information of MSR, general register, control register and floating point register, and stores it in the memory of the master process.
[0042] And, in some other embodiments, tracking and obtaining the user-mode processor execution context of the target program loaded by the target process according to the tracking permission (S120) includes: S121b, using a process tracking function to obtain memory status information of the target program loaded by the target process.
[0043] In some embodiments, after acquiring the memory status information of the target program loaded by the target process, it also includes saving the memory status information.
[0044] Specifically, the master process calls the ptrace(PEEK DATA) function to obtain the data of the target program at a specific memory address and saves the data to the memory of the master process. If the target process loads a multi-threaded target program, the function is called multiple times to extract data in different address ranges.
[0045] In this embodiment, since the process tracking function ptrace in different versions of the operating system is fully compatible with the system, it is not necessary to increase too much maintenance cost while being able to extract the CPU execution context simply and efficiently.
[0046] When a system call occurs, an effective technical solution for capturing the kernel state execution context is required. In some embodiments, in step S140, obtaining the kernel state processor execution context of the target program includes: S141. Call a process tracking function to obtain register status information of the target process.
[0047] When it is detected that the target program executes a system call, the main control process calls the ptrace (GET REGS) function to obtain the register status information of the target program in the kernel state and save it.
[0048] S142. Obtain a system call number from the register status information.
[0049] The main control process parses the system call number from the extracted register status information. Generally, the system call number is stored in a specific register, for example, in the x86 architecture, it is the EAX register.
[0050] S143. According to the system call number, obtain a complete kernel state execution context of the target process during the execution of the corresponding system call.
[0051] The master control process further obtains the complete kernel state execution context of the target process during the execution of the corresponding system call by accessing the kernel data structure, stack information, etc. according to the extracted system call number.
[0052] It can be understood that, in this embodiment, obtaining the tracking permission of the target process is crucial to monitoring the execution context information of the program loaded by the target process. Figure 2 In some embodiments, obtaining the tracking permission of the target process (step S110) includes: generating a target process using a process copy function and running a target program on the target process; receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used to indicate that the target process authorizes and agrees to be tracked; tracking the target process based on the authorization signal, and blocking the target process until it is unblocked.
[0053] Exemplarily, in this embodiment, the main control process generates a new child process, i.e., the target process, by calling a process copy function, such as fork(), wherein when the main control process calls the fork() function, the operating system creates a new subsystem, i.e., the target process, which is a copy of the main control process. In the child process, a target program can be executed.
[0054] In the generated target process, the exec() series of functions are used to load and run the target program, which enables the target program to execute in a new CPU context and be ready to accept subsequent tracing requests.
[0055] The target program calls a specific process tracing function, such as ptrace(TRACEME), and at least returns or sends an authorization signal to the main control process to indicate that it agrees to be traced.
[0056] Once the authorization signal is received, the master process can use the ptrace(ATTACH) command to track the target process. At the same time, the master process will block the target process until it is unblocked. The blocking mechanism ensures that the target program on the target process will not continue to execute during the monitoring period, thereby avoiding the problem of inconsistent CPU execution context data or chaotic state.
[0057] In this embodiment, a target process is generated by utilizing a process copy function, and a target program is run on the process, thereby achieving more efficient tracking permission acquisition. This not only simplifies the authorization process, but also blocks the target process through the master control process, thereby ensuring the reliability of the target program's execution context data in user state and kernel state.
[0058] Please continue to see Figure 2 and Figure 3 In some embodiments, in this embodiment, after obtaining the kernel-mode processor execution context of the target program, the method includes the following steps S150: sending an unblocking instruction to the target process to resume the operation of the target program.
[0059] In this embodiment, after completing the acquisition of the kernel state processor execution context, the master control process sends a blocking removal instruction to the target process. Specifically, the blocking removal of the target process can be achieved by calling the ptrace (PTRACE_CONT) command so that it can continue to execute.
[0060] After unblocking, developers can use the previously captured CPU execution context information to analyze the behavior of the target program during execution. For example, developers can check the parameter values in the registers to ensure the correctness of the file read operation and verify whether the return value meets expectations. This real-time monitoring can help developers detect potential problems in a timely manner, such as incorrect parameter passing or abnormal returns, thereby improving debugging efficiency and program stability.
[0061] In some embodiments, the target program is a single-threaded or multi-threaded program.
[0062] If it is necessary to obtain the CPU execution context fragments of multiple target programs, the CPU execution context fragments of multiple target programs can be obtained by repeating the above steps S110 to S140. After providing them to the CPU emulator, the target program can be replayed to analyze the program execution process, diagnose errors in the program execution process, analyze program performance issues, etc.
[0063] In this embodiment, by sending an unblocking instruction after acquiring the kernel-mode processor execution context of the target program, effective control of the target program's running state is achieved, the integrity of the monitoring process is ensured, and the normal execution of the target program can be restored in a timely manner.
[0064] When applied to program debugging and verification analysis scenarios, it can not only improve debugging and analysis efficiency, but also reduce the impact on system performance, thereby enabling more flexible program problem location and performance optimization.
[0065] The acquisition of CPU execution context for multi-threaded programs is basically the same as that for single-threaded programs. Multi-threaded programs share target process resources. The only difference is that the number of threads monitored by the master process is different. The specific process is basically the same. Figure 4As shown, exemplarily, when the target process includes multiple threads, the process of the master process obtaining the CPU execution context is as follows: after obtaining the tracking permission of the target process, including: S210, obtaining all threads included in the target process, by checking and obtaining all thread IDs running on the target process; This can be achieved by reading the subdirectories under the proc / pid / task directory, where pid is the process ID of the target process. Each subdirectory corresponds to a thread, and the subdirectory name is the thread ID.
[0066] Assuming the PID of the target process is 1234, the master process can access the / proc / 1234 / task directory and list all subdirectories, such as 1234, 1235, 1236, etc. These subdirectories correspond to the threads in the target process.
[0067] S220, traverse all threads and attach to the target process.
[0068] Specifically, the master process uses the ptrace(PTRACE ATTACH, thread_id, NULL, NULL) command to traverse all acquired thread IDs and attach each thread to the target process. At this point, each attached thread will be in a blocked state, waiting for the master process to track it.
[0069] Continuing with the above example, for each thread ID, such as 1234, 1235, and 1236, the master process calls ptrace(PTRACE ATTACH, thread id, NULL, NULL) in sequence, causing these threads to enter a blocked state and prepare to receive subsequent monitoring instructions.
[0070] Execute steps S120 to S130 to obtain the user state and kernel state processor execution context of each thread one by one.
[0071] In this embodiment, after all threads are attached and in a blocked state, the master control process can obtain the user state and kernel state processor execution contexts of each attached thread, such as 1234, 1235 and 1236 mentioned above, by calling ptrace(PTRACE GETREGS, thread id, NULL, regs), where regs is a structure used to save information such as the register state of the current thread; the master control process saves the obtained register state of each thread in the storage space of the master control process for subsequent analysis and simulation.
[0072] S260: After acquiring the user state and kernel state CPU execution contexts of all threads, releasing the target process and cancelling the attachment relationship, and resuming the execution of the target process.
[0073] Specifically, the master process releases the target process by calling the ptrace(PTRACE CONT, target pid, NULL, NULL) command to restore normal operation. Subsequently, the master process uses ptrace(PTRACE DETACH, threadid, NULL, NULL) to traverse all attached threads, remove their attachment relationship with the target process, and make each thread resume execution.
[0074] If developers want to analyze the behavior of the program under different input conditions, they can repeat the above steps at different time points to capture processor execution context fragments at multiple time points for subsequent performance analysis, error location, or simulation replay.
[0075] Specifically, the number of tracing times can be flexibly adjusted to meet the debugging requirements of different types of programs, such as CPU-bound or IO-bound, so as to optimize the debugging strategy.
[0076] In the embodiment of the present application, through the above steps, the main control process can effectively obtain the user state and kernel state CPU execution context of each thread in the multi-threaded program, which not only improves the efficiency of debugging and analysis of the multi-threaded program, but also ensures that the impact on system performance during the monitoring process is minimized.
[0077] Please see Figure 5 As shown, the present application also provides an embodiment of a processor execution context extraction device 300, including: A first acquisition program unit 310 is used to obtain the tracking permission of the target process; A tracking program unit 320, configured to track and obtain a user-mode processor execution context of a target program loaded by the target process according to the tracking authority; The monitoring and obtaining program unit 330 is used to obtain the kernel state processor execution context of the target program if it is monitored whether the target process executes the system call instruction.
[0078] In some specific implementations, the program tracking unit 320 is specifically used to obtain register state information of the target program loaded by the target process using a process tracking function; and / or, It is specifically used to obtain the memory status information of the target program loaded by the target process by using the process tracking function.
[0079] In some further specific implementations, the monitoring acquisition program unit 330 includes: a calling program module, configured to call a process tracking function to acquire the register state information of the target process; A first acquisition program module is used to obtain a system call number from the register state information; The second acquisition program module is used to acquire the complete kernel state execution context of the target process during the execution of the corresponding system call according to the system call number.
[0080] In some specific implementations, the first program acquisition unit 310 includes: a program generation module, which is used to generate a target process using a process copy function and run a target program on the target process; A receiving program module, used for receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used for indicating that the target process authorizes and agrees to be tracked; The tracking program module tracks the target process based on the authorization signal and blocks the target process until it is unblocked.
[0081] In some specific implementations, the device further includes: a recovery program unit, which is used to send an unblocking instruction to the target process to resume the operation of the target program after obtaining the kernel-mode processor execution context of the target program.
[0082] The processor execution context extraction device provided in the embodiment of the present application can be used to execute Figures 1 to 4 The technical solution of the method embodiment shown, the processor execution context extraction device of this embodiment, its implementation principle and technical effect are similar to those of the aforementioned method embodiment, which will not be repeated here, and can be referenced to each other.
[0083] Figure 6 This is a schematic block diagram of the architecture of an embodiment of the electronic device of the present application; based on the technical concept basically the same as the above-mentioned embodiment 1, the electronic device provided by the embodiment of the present application includes: one or more processors; a memory; the memory stores one or more executable program codes, and the one or more processors read the executable program codes stored in the memory to run the program corresponding to the executable program codes, so as to execute the processor execution context extraction method described in any of the above-mentioned method embodiments. Figure 6 As shown, the step flow of the processor executing the context extraction method described in any of the aforementioned method embodiments of the present application can be implemented.
[0084] The above-mentioned electronic device may include: a shell 41, a processor 42, a memory 43, a circuit board 44 and a power supply circuit 45, wherein the circuit board 44 is arranged inside the space enclosed by the shell 41, and the processor 42 and the memory 43 are arranged on the circuit board 44; the power supply circuit 45 is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory 43 is used to store executable program code; the processor 42 runs the program corresponding to the executable program code by reading the executable program code stored in the memory 43, so as to execute the processor execution context extraction method described in any of the above-mentioned embodiments one.
[0085] The specific execution process of the processor 42 for the above steps and the steps further executed by the processor 42 by running the executable program code can be found in the description of the aforementioned method embodiment of the present application, which will not be repeated here.
[0086] The electronic device exists in many forms, including but not limited to: (1) Mobile communication devices: These devices are characterized by their mobile communication functions and their main purpose is to provide voice and data communications. These terminals include: smart phones (such as iPhone), multimedia phones, feature phones, and low-end phones.
[0087] (2) Ultra-mobile personal computer devices: These devices fall into the category of personal computers, have computing and processing capabilities, and generally also have mobile Internet access features. These terminals include: PDA, MID and UMPC devices, such as iPad.
[0088] (3) Portable entertainment devices: These devices can display and play multimedia content. They include audio and video players (such as iPods), handheld game consoles, e-books, smart toys, and portable car navigation devices.
[0089] (4) Server: A device that provides computing services. The server consists of a processor, hard disk, memory, system bus, etc. The server is similar to a general-purpose computer architecture, but because it needs to provide highly reliable services, it has higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0090] (5) Other electronic devices with data interaction functions.
[0091] The present application also provides a computer-readable storage medium in an embodiment, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to execute the processor execution context extraction method described in any of the aforementioned method embodiments.
[0092] In summary, the processor execution context extraction method, device, electronic device and storage medium provided in the embodiments of the present application do not need to modify the operating system kernel and page table structure, and the processor execution context of the target program can be obtained through the application program. The implementation process is simple and efficient, and it is convenient to extract the CPU execution context simply and efficiently, and the impact on the system and resource overhead are relatively small.
[0093] Furthermore, for different versions of operating systems, there is no need to write a driver to adapt the operating system, which has the characteristics of strong compatibility and low maintenance cost.
[0094] It should be noted that, in this article, the emphasis of the scheme described between the various embodiments is different, but the various embodiments have a certain interrelated relationship. When understanding the scheme of the present application, the various embodiments can refer to each other; in addition, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or measurement control unit including a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also includes elements inherent to such process, method, article or measurement control unit. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or measurement control unit including the elements.
[0095] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for extracting a processor execution context, characterized in that: The method comprises: Obtain the tracking permission of the target process; According to the tracking authority, tracking and obtaining the user state processor execution context of the target program loaded by the target process; If the target process is monitored to execute a system call instruction, the kernel state processor execution context of the target program is obtained.
2. The method for extracting a processor execution context according to claim 1, wherein: The step of tracking and obtaining the user-mode processor execution context of the target program loaded by the target process according to the tracking permission includes: The register status information of the target program loaded by the target process is obtained by using a process tracking function.
3. The method for extracting a processor execution context according to claim 1 or 2, wherein: The step of tracking and obtaining the user-mode processor execution context of the target program loaded by the target process according to the tracking permission includes: obtaining memory state information of the target program loaded by the target process by using a process tracking function.
4. The method for extracting a processor execution context according to claim 1, wherein: The obtaining of the kernel-mode processor execution context of the target program comprises: Calling a process tracking function to obtain register status information of the target process; Obtaining a system call number from the register status information; According to the system call number, a complete kernel state execution context of the target process during the execution of the corresponding system call is obtained.
5. The method for extracting a processor execution context according to claim 1, wherein: The obtaining of the tracking authority of the target process includes: generating a target process by using a process copy function, and running a target program on the target process; Receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used to indicate that the target process authorizes and agrees to be tracked; The target process is tracked based on the authorization signal, and the target process is blocked until it is unblocked.
6. The method for extracting a processor execution context according to claim 5, wherein: After acquiring the kernel-mode processor execution context of the target program, the method further includes: sending an unblocking instruction to the target process to resume the operation of the target program.
7. The method for extracting a processor execution context according to claim 1, wherein: The target program is a single-threaded or multi-threaded program.
8. A device for extracting a processor execution context, characterized in that: include: A first acquisition program unit is used to obtain the tracking permission of the target process; A tracking program unit, used for tracking and obtaining a user-mode processor execution context of a target program loaded by the target process according to the tracking authority; The monitoring and obtaining program unit is used to obtain the kernel state processor execution context of the target program if it is monitored whether the target process executes the system call instruction.
9. The device for extracting processor execution context according to claim 8, characterized in that: The program tracking unit is specifically used to obtain register state information of the target program loaded by the target process by using a process tracking function; and / or, It is specifically used to obtain the memory status information of the target program loaded by the target process by using the process tracking function.
10. The device for extracting processor execution context according to claim 8, characterized in that: The second acquisition program unit includes: a calling program module, which is used to call a process tracking function to obtain the register state information of the target process; A first acquisition program module is used to obtain a system call number from the register state information; The second acquisition program module is used to acquire the complete kernel state execution context of the target process during the execution of the corresponding system call according to the system call number.
11. The device for extracting processor execution context according to claim 8, characterized in that: The first program acquisition unit includes: a program generation module, which is used to generate a target process using a process copy function and run a target program on the target process; A receiving program module, used for receiving an authorization signal sent by the target process by calling a process tracking function; the authorization signal is used for indicating that the target process authorizes and agrees to be tracked; The tracking program module tracks the target process based on the authorization signal and blocks the target process until it is unblocked.
12. The device for extracting processor execution context according to claim 8, characterized in that: The device also includes: a recovery program unit, which is used to send an unblocking instruction to the target process after acquiring the kernel-mode processor execution context of the target program to resume the operation of the target program.
13. An electronic device, characterized in that: include: One or more processors; Memory; One or more executable program codes are stored in the memory, and the one or more processors read the executable program codes stored in the memory and run the program corresponding to the executable program codes to execute the processor execution context extraction method described in any one of claims 1 to 7.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to execute the method for extracting the processor execution context as described in any one of claims 1 to 7.
