Operating system exception triggering method and device, equipment, storage medium and program product
The construction process of operating system exceptions is simplified by adaptively adjusting the instruction length of the function body, solving the problem of low abnormal triggering efficiency in the prior art, and achieving efficient exception triggering in operating system development and testing.
Patent Information
- Application Number
- CN202411660680.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-18
AI Technical Summary
The prior art is complicated in constructing operating system exceptions, requiring multiple code conversions and insertions, resulting in low efficiency of exception triggering.
The process of constructing exceptions is simplified by pre-defined function bodies for triggering operating system exceptions, and when the function body is called, the instruction length of the function body is adaptively adjusted to adapt to different operating systems.
It improves the efficiency of operating system exception triggering, so that exceptions can be triggered simply and efficiently during operating system development and testing, and is used to check the correctness of operating system handling exceptions.
Smart Images

Figure CN119645690A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of operating system verification, and in particular to an operating system abnormality triggering method, device, equipment, storage medium and program product. Background Art
[0002] Fault injection technology is mainly used to verify the reliability of the system. It usually manually inputs fault information into the system under test according to the established fault injection model, accelerates the fault or failure of the system under test, and conducts quantitative and qualitative verification and evaluation of the system under test by observing and analyzing the feedback results of the system under test on the input fault information. The existing fault injection technology requires the test case to be converted into an assembly file by the compiler, and then triggers the exception by inserting the exception code into the assembly file, thereby verifying whether the function of the CPU (Central Process Unit) is normal. Although the traditional verification method can realize the abnormal triggering of the CPU, the abnormal construction process is cumbersome and requires continuous code conversion and code insertion, including generating assembly files, allocating memory, inserting target exception codes, modifying the original jump code, and generating assembly code again, etc., resulting in low efficiency of abnormal triggering of the operating system. Summary of the invention
[0003] The purpose of the embodiments of the present invention is to provide an operating system exception triggering method, device, equipment, storage medium and program product, which has a simple process of constructing an exception and can effectively improve the efficiency of operating system exception triggering.
[0004] To achieve the above object, an embodiment of the present invention provides an operating system abnormality triggering method, comprising:
[0005] Get the architecture information of the current operating system;
[0006] Calling a function body; wherein the function body is a program for triggering an exception in the operating system;
[0007] The instruction length of the function body is adjusted according to the architecture information, and the function body after the instruction length is adjusted is written into the test thread of the current operating system.
[0008] As an improvement of the above solution, the function body includes four first instructions and two second instructions, and the first instructions and the second instructions are different hexadecimal constants.
[0009] As an improvement of the above solution, adjusting the instruction length of the function body according to the architecture information includes:
[0010] The number of the first instruction and / or the second instruction in the function body is adjusted according to the architecture information.
[0011] As an improvement to the above solution, the function body is constructed using inline assembly syntax.
[0012] As an improvement of the above solution, the embedded assembly syntax is the asm keyword.
[0013] As an improvement to the above solution, the function body is defined using pseudo operations.
[0014] To achieve the above purpose, an embodiment of the present invention further provides an operating system abnormality triggering device, comprising:
[0015] An architecture information acquisition module is used to obtain the architecture information of the current operating system;
[0016] A function body calling module, used to call a function body; wherein the function body is a program for triggering an exception in the operating system;
[0017] An instruction length adjustment module, which adjusts the instruction length of the function body according to the architecture information;
[0018] The function body writing module is used to write the function body after adjusting the instruction length into the test thread of the current operating system.
[0019] To achieve the above-mentioned objectives, an embodiment of the present invention further provides an operating system exception triggering device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the operating system exception triggering method as described in any of the above-mentioned embodiments is implemented.
[0020] To achieve the above-mentioned purpose, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the operating system exception triggering method as described in any of the above-mentioned embodiments.
[0021] To achieve the above objectives, an embodiment of the present invention further provides a computer program product, including computer instructions, which, when executed by a processor, implement the operating system exception triggering method as described in any of the above embodiments.
[0022] Compared with the prior art, the operating system exception triggering method, device, equipment, storage medium and program product disclosed in the present invention predefines the function body used to trigger the operating system exception, and when the function body is called, the instruction length of the function body is adaptively adjusted to adapt to different operating systems to trigger interrupts or exceptions. The process of constructing the function body is simple, and during the operating system development and testing process, exceptions can be triggered simply and efficiently, which can be used to check the correctness of the operating system's exception handling, and can effectively improve the efficiency of the operating system exception triggering. In addition, the function body is implemented in C code, which is highly portable, and because the instruction length of the function body can be adapted to different operating systems, the function body has high versatility. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a flow chart of an operating system abnormality triggering method provided by an embodiment of the present invention;
[0024] Figure 2 It is a structural block diagram of an operating system abnormality triggering device provided by an embodiment of the present invention;
[0025] Figure 3 It is a structural block diagram of an operating system exception triggering device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] When a computer is executing a program, it may encounter some abnormal situations or special requests. At this time, the computer needs to pause the running program and handle these abnormalities or special requests first. After the processing is completed, it returns to the breakpoint of the program to continue execution. This processing method is called "interrupt", and this function of the computer is called interrupt processing. The software and hardware technologies required to implement this function are collectively referred to as interrupt technology. In order to verify the interrupt processing function of the operating system, fault information is manually input into the system to be tested, so that the operating system triggers an exception, and then verifies its interrupt processing function. In order to improve the efficiency of the operating system's exception triggering, an embodiment of the present invention provides an operating system exception triggering method.
[0028] See also Figure 1 , Figure 1 1 is a flowchart of an operating system abnormality triggering method provided by an embodiment of the present invention, wherein the operating system abnormality triggering method comprises:
[0029] S1. Obtain the architecture information of the current operating system;
[0030] S2, calling a function body; wherein the function body is a program for triggering an exception in the operating system;
[0031] S3. Adjust the instruction length of the function body according to the architecture information, and write the function body after the instruction length is adjusted into the test thread of the current operating system.
[0032] Specifically, in step S1, the architecture information includes X86, X64, ARM32, ARM64, etc. Among them, X86 is the Intel CPU 32-bit architecture system, which is widely used in the fields of personal computers and servers, and has a strong ecosystem and backward compatibility; X64, also known as X86_64 or AMD64, is a 64-bit extension of the X86 architecture, which can run 64-bit operating systems and applications, and is backward compatible with 32-bit software; ARM32 is a computer architecture system, usually used in mobile devices, Internet of Things devices, etc.; ARM64 is a 64-bit version of the ARM architecture, also known as AArch642, which is mainly used in mobile devices, cloud computing and other fields, and supports 64-bit operating systems and applications.
[0033] Specifically, in step S2, a function "triger_exception" is defined in an embodiment of the present invention. This function is the function body triggered by the exception, and the function can be called directly and an exception can be generated in this function. The function body is constructed using an embedded assembly syntax, and the embedded assembly syntax is the asm keyword, that is, the embedded assembly statement is defined in the C language using the asm keyword. The function body is defined using a pseudo operation, such as using the .byte pseudo operation to define the function body. The function body includes four first instructions and two second instructions, and the first instruction and the second instruction are different hexadecimal constants.
[0034] Exemplarily, the first instruction is "0xff", the second instruction is "0x00", and the content of the function body obtained by combining the asm keyword and the .byte pseudo operation definition is as follows:
[0035]
[0036]
[0037] In the embodiment of the present invention, the function trigger_exception is constructed using inline assembly asm syntax, and the .byte pseudo operation is used to construct the function body that triggers the exception. Among them, 0xffffffff0000 is a general CPU invalid machine code carefully constructed by integrating the currently common X86, X64, ARM32, and ARM64 CPU instructions (fixed length / variable length), wherein the machine code generally refers to the machine instruction statement, and the machine instruction is the command code for the computer CPU to perform a certain operation, and the machine code is different for different CPU architectures.
[0038] Specifically, in step S3, adjusting the instruction length of the function body according to the architecture information includes: adjusting the number of first instructions and / or second instructions in the function body according to the architecture information.
[0039] Exemplarily, the instruction length of the function body can be adaptively adjusted. For example, the illegal instruction of THUMB is 0xffff, and the following two ffffs are automatically ignored (because the exception has occurred). If the operating system architecture is ARM32 or ARM64, then the illegal instruction is 0xffffffff, that is, the second instruction is not needed at this time, and the number of second instructions needs to be set to 0; X86 and X64 are variable-length instructions, and 0xffffffff0000 will be interpreted as an illegal instruction, that is, four first instructions and two second instructions are required at this time.
[0040] For example, the operating system can generate an exception by calling this function body in the test thread. For example, an exception object is introduced in the main function, that is, main(){trigger_exception();}, which can generate an exception in the main thread. The C code example is as follows:
[0041]
[0042] Compared with the prior art, the operating system exception triggering method disclosed in the present invention predefines a function body for triggering an operating system exception, and when the function body is called, the instruction length of the function body is adaptively adjusted to adapt to different operating systems to trigger interrupts or exceptions. The process of constructing the function body is simple, and in the operating system development and testing process, the exception can be triggered simply and efficiently, which can be used to check the correctness of the operating system's exception handling, and can effectively improve the efficiency of the operating system exception triggering. In addition, the function body is implemented in C code, which has strong portability, and because the instruction length of the function body can adapt to different operating systems, the function body has high versatility.
[0043] See also Figure 2 , Figure 21 is a structural block diagram of an operating system abnormality triggering device 100 provided in an embodiment of the present invention, wherein the operating system abnormality triggering device 100 comprises:
[0044] The architecture information acquisition module 11 is used to acquire the architecture information of the current operating system;
[0045] A function body calling module 12, used to call a function body; wherein the function body is a program for triggering an exception in the operating system;
[0046] An instruction length adjustment module 13, which adjusts the instruction length of the function body according to the architecture information;
[0047] The function body writing module 14 is used to write the function body after adjusting the instruction length into the test thread of the current operating system.
[0048] Specifically, the function body includes four first instructions and two second instructions, and the first instructions and the second instructions are different hexadecimal constants.
[0049] Specifically, the instruction length adjustment module 13 is specifically used to: adjust the number of the first instructions and / or the second instructions in the function body according to the architecture information.
[0050] Specifically, the function body is constructed using inline assembly syntax.
[0051] Specifically, the embedded assembly syntax is the asm keyword.
[0052] Specifically, the function body is defined using pseudo operations.
[0053] It is worth noting that the working process of each module in the operating system abnormality triggering device 100 described in the embodiment of the present invention can refer to the working process of the operating system abnormality triggering method described in the above embodiment, and will not be repeated here.
[0054] Compared with the prior art, the operating system exception triggering device 100 disclosed in the present invention predefines a function body for triggering an operating system exception, and when the function body is called, the instruction length of the function body is adaptively adjusted to adapt to different operating systems to trigger interrupts or exceptions. The process of constructing the function body is simple, and during the operating system development and testing process, the exception can be triggered simply and efficiently, which can be used to check the correctness of the operating system's exception handling, and can effectively improve the efficiency of the operating system exception triggering. In addition, the function body is implemented in C code, which has strong portability, and because the instruction length of the function body can adapt to different operating systems, the function body has high versatility.
[0055] See also Figure 3 , Figure 31 is a structural block diagram of an operating system abnormality triggering device 200 provided in an embodiment of the present invention, and the operating system abnormality triggering device 200 includes a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, the steps in the above-mentioned operating system abnormality triggering method embodiments are implemented, such as steps S1 to S3.
[0056] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 22 and executed by the processor 21 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the operating system abnormality triggering device 200.
[0057] The operating system abnormality triggering device 200 may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art may understand that the schematic diagram is merely an example of the operating system abnormality triggering device 200 and does not constitute a limitation on the operating system abnormality triggering device 200. The operating system abnormality triggering device 200 may include more or fewer components than shown in the figure, or may combine certain components, or different components. For example, the operating system abnormality triggering device 200 may also include input and output devices, network access devices, buses, etc.
[0058] The processor 21 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 21 is the control center of the operating system abnormality triggering device 200, and uses various interfaces and lines to connect various parts of the entire operating system abnormality triggering device 200.
[0059] The memory 22 can be used to store the computer program and / or module. The processor 21 implements various functions of the operating system abnormal triggering device 200 by running or executing the computer program and / or module stored in the memory 22 and calling the data stored in the memory 22. The memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store the operating system, at least one application required for a function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.). In addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0060] Wherein, if the module / unit integrated in the operating system abnormality triggering device 200 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor 21. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0061] An embodiment of the present invention further provides a computer program product, including computer instructions, which, when executed by a processor, implement the operating system exception triggering method as described in the above embodiment.
[0062] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for triggering an operating system exception, characterized in that: include: Get the architecture information of the current operating system; Calling a function body; wherein the function body is a program for triggering an exception in the operating system; The instruction length of the function body is adjusted according to the architecture information, and the function body after the instruction length is adjusted is written into the test thread of the current operating system.
2. The operating system abnormality triggering method according to claim 1, characterized in that: The function body includes four first instructions and two second instructions, and the first instructions and the second instructions are different hexadecimal constants.
3. The operating system abnormality triggering method according to claim 2, characterized in that: The step of adjusting the instruction length of the function body according to the architecture information comprises: The number of the first instruction and / or the second instruction in the function body is adjusted according to the architecture information.
4. The operating system abnormality triggering method according to claim 1, characterized in that: The function body is constructed using inline assembly syntax.
5. The operating system abnormality triggering method according to claim 4, characterized in that: The inline assembly syntax is the asm keyword.
6. The operating system abnormality triggering method according to claim 1, characterized in that: The function body is defined using pseudo operations.
7. An operating system abnormality triggering device, characterized in that: include: An architecture information acquisition module is used to obtain the architecture information of the current operating system; A function body calling module, used to call a function body; wherein the function body is a program for triggering an exception in the operating system; An instruction length adjustment module, which adjusts the instruction length of the function body according to the architecture information; The function body writing module is used to write the function body after adjusting the instruction length into the test thread of the current operating system.
8. An operating system abnormality triggering device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the operating system exception triggering method as claimed in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the operating system exception triggering method according to any one of claims 1 to 6.
10. A computer program product, characterized in that It comprises computer instructions, which, when executed by a processor, implement the operating system exception triggering method as described in any one of claims 1 to 6.