Application memory error detection method, device and storage medium
By replacing the memory allocation function in the terminal device and configuring the GWP-ASan allocator, the problem of memory error detection in passive code applications is solved, and more efficient memory error detection is achieved.
Patent Information
- Application Number
- CN202210022811.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-10
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2042-01-10
AI Technical Summary
The prior art cannot effectively detect memory errors in applications, especially in passive code applications, resulting in frequent problems such as memory leakage and overflow.
By replacing the memory allocation-related functions in the terminal device as the objective function and configuring the GWP-ASan allocator, it uses its memory error detection function to realize the detection of memory allocation applications.
Improve the ability to detect application memory errors, especially in passive applications, which can more accurately detect memory leaks and overflows.
Smart Images

Figure CN116450474B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an application memory error detection method, device, and storage medium. Background Art
[0002] With the development of computer technology, application developers have developed a variety of applications for terminal devices. Before the applications are officially put into use, they need to undergo multiple functional tests.
[0003] Currently, applications are put into production after their various functions have functioned normally during testing. However, these applications may still experience memory errors such as memory leaks or memory overflows. Summary of the Invention
[0004] Embodiments of the present application provide an application memory error detection method, device, and storage medium, which relate to the field of computer technology and help solve the current problem of being unable to detect application memory errors.
[0005] In a first aspect, an embodiment of the present application provides an application memory error detection method, which is applied to a terminal device; the method includes: the terminal device replaces a function related to memory allocation in an application with a target function; the terminal device executes the target function to obtain a first application related to memory allocation; the first application is set with a first mark; when the terminal device executes the first application including the first mark, the terminal device performs memory error detection on the execution process of the first application.
[0006] In an embodiment of the present application, a terminal device replaces a memory allocation-related function in an application with a target function. The terminal device executes the target function, resulting in a first application that is configured with a first tag. This allows the terminal device to selectively perform memory error detection on memory allocation-related applications that include the first tag, such as the first application. This allows memory error detection to be performed on specific applications or libraries.
[0007] In a possible implementation, a terminal device is configured with a GWP-ASan allocator; the GWP-ASan allocator is configured to perform memory error detection on executed memory allocation-related applications; the method further includes: the terminal device enabling the GWP-ASan allocator based on a memory check mode configuration file or a configuration state of the GWP-ASan allocator; the configuration state is used to indicate that the GWP-ASan allocator is enabled; the memory check mode configuration file includes configuration items for applications; the configuration items are used to indicate that memory error detection is to be performed on the applications; the terminal device performing memory error detection on the execution process of a first application includes: the terminal device using the GWP-ASan allocator to perform memory error detection on the execution process of the first application. In this way, the memory allocation-related application including the first flag can be executed by the GWP-ASan allocator, and the memory error detection function of the GWP-ASan allocator can be used to perform memory error detection.
[0008] In a possible implementation, an application process is running on a terminal device; the terminal device activates the GWP-ASan allocator based on a memory check mode configuration file or the configuration status of the GWP-ASan allocator. This includes: during the application startup process, the application process obtains the memory check mode configuration file; if the memory check mode configuration file includes configuration items for the application, the application process activates the GWP-ASan allocator. By adding the configuration items of the application to be tested to the memory check mode configuration file, the GWP-ASan allocator can be activated during the execution of the application, and memory error detection can be performed on the application using the GWP-ASan allocator.
[0009] In a possible implementation, a terminal device runs a system service and an incubator process. The terminal device enables the GWP-ASan allocator based on a memory check mode configuration file or the configuration status of the GWP-ASan allocator. This includes: during application startup, the system service obtains the configuration status of the GWP-ASan allocator; the configuration status indicates the start of the GWP-ASan allocator; the system service sends a process creation instruction to the incubator process; the process creation instruction includes a second flag, which instructs the incubator process to enable the GWP-ASan allocator; in response to the process creation instruction, the incubator process creates an application process; and the application process enables the GWP-ASan allocator based on the second flag. In this way, even without adding logic for enabling the GWP-ASan allocator based on the memory check mode configuration file, the terminal device can enable the GWP-ASan allocator based on the configuration status of the GWP-ASan allocator.
[0010] In a possible implementation, a terminal device runs a system service and an application's main thread. The terminal device replaces a function related to memory allocation in the application with a target function, including: the system service receives a trigger instruction; and in response to the trigger instruction, the system service calls the application's main thread to replace the function related to memory allocation in the application with the target function. In this way, the system service can replace the memory allocation function with the target function based on the received instruction.
[0011] In a possible implementation, the trigger instruction comes from any one of a command line interface, a Java interface, a C interface, or a C++ interface. In this way, the memory allocation-related function can be flexibly replaced with the target function according to the interface or command line trigger.
[0012] In a possible implementation, an incubator process runs on a terminal device, and the terminal device replaces memory allocation-related functions in an application with target functions. This includes: the incubator process creates the application's main thread. If a memory check mode configuration file contains a configuration item for the application, the application's main thread replaces the application's memory allocation-related functions with the target function; the configuration item is used to instruct the application to perform memory error detection. Thus, if the application's configuration item is configured in the memory check mode configuration file, the application automatically replaces memory allocation-related functions with the target function during startup.
[0013] In a second aspect, an embodiment of the present application provides an application memory error detection device, comprising a storage module and a processing module: the storage module stores a correspondence between functions related to memory allocation and target functions; the processing module is used to: replace a first function in the application with a target function corresponding to the first function according to the correspondence; the first function is a function related to memory allocation; executing the target function obtains a first application related to memory allocation; the first application is set with a first mark; when executing the first application including the first mark, memory error detection is performed on the execution process of the first application.
[0014] Optionally, a GWP-ASan allocator is configured in the processing module; the GWP-ASan allocator is used to perform memory error detection on the executed memory allocation-related applications; the processing module is also used to: turn on the GWP-ASan allocator according to the memory check mode configuration file or the configuration status of the GWP-ASan allocator; the configuration status is used to characterize the turning on of the GWP-ASan allocator; the memory check mode configuration file includes configuration items of the application; the configuration items are used to indicate memory error detection for the application; the processing module is specifically used to use the GWP-ASan allocator to perform memory error detection on the execution process of the first application.
[0015] Optionally, an application process is running in the processing module; during the startup of the application, the application process is used to obtain a memory check mode configuration file; when the memory check mode configuration file includes configuration items of the application, the application process is used to start the GWP-ASan allocator.
[0016] Optionally, a system service and an incubator process are running in the processing module. During the startup of the application, the system service is used to obtain the configuration status of the GWP-ASan allocator; the configuration status is used to indicate the start of the GWP-ASan allocator; the system service is also used to send a process creation instruction to the incubator process; the process creation instruction includes a second flag, and the second flag is used to instruct the incubator process to turn on the GWP-ASan allocator; in response to the process creation instruction, the incubator process is used to create an application process; the application process is used to turn on the GWP-ASan allocator according to the second flag.
[0017] Optionally, a system service and a main thread of an application are running in the terminal device, and the system service is used to receive a trigger instruction; in response to the trigger instruction, the system service is also used to call the main thread of the application to replace the function related to memory allocation in the application with the target function.
[0018] Optionally, the trigger instruction comes from any one of a command line interface, a Java interface, a C interface, or a C++ interface.
[0019] Optionally, an incubator process is running in the terminal device, and the incubator process is used to create the main thread of the application. When it is determined that the memory check mode configuration file includes configuration items of the application, the main thread of the application is used to replace functions related to memory allocation in the application with target functions; the configuration items are used to instruct memory error detection on the application.
[0020] In a third aspect, an embodiment of the present application provides an electronic device comprising a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program to perform the application memory error detection method described in the first aspect or any possible implementation of the first aspect.
[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program or instructions. When the computer program or instructions are run on a computer, the computer executes the application memory error detection method described in the first aspect or any possible implementation of the first aspect.
[0022] In a fifth aspect, an embodiment of the present application provides a computer program product comprising a computer program. When the computer program runs on a computer, the computer executes the application memory error detection method described in the first aspect or any possible implementation of the first aspect.
[0023] In a sixth aspect, the present application provides a chip or chip system, comprising at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via a line, and the at least one processor is configured to run a computer program or instruction to execute the application memory error detection method described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip may be an input / output interface, a pin, or a circuit.
[0024] In one possible implementation, the chip or chip system described above in this application further includes at least one memory, in which instructions are stored. The memory may be a storage unit within the chip, such as a register, a cache, etc., or a storage unit of the chip (e.g., a read-only memory, a random access memory, etc.).
[0025] It should be understood that the third to sixth aspects of the present application correspond to the technical solutions of the first aspect of the present application respectively, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A schematic diagram of the structure of a terminal device applicable to an embodiment of the present application;
[0027] Figure 2 A software structure block diagram of a terminal device to which the embodiments of the present application are applicable;
[0028] Figure 3 A schematic diagram of an application startup process in an application memory error detection method provided in an embodiment of the present application;
[0029] Figure 4 A flowchart of replacing a first function in a code library corresponding to an application with a target function using a command line method provided in an embodiment of the present application;
[0030] Figure 5 A flowchart of replacing a first function with a target function during the startup of an application provided in an embodiment of the present application;
[0031] Figure 6 A schematic diagram of an application memory error detection process in an application memory error detection method provided in an embodiment of the present application;
[0032] Figure 7 A flowchart of an application memory error detection method provided in an embodiment of the present application;
[0033] Figure 8A flowchart of another application memory error detection method provided in an embodiment of the present application;
[0034] Figure 9 A schematic diagram of the structure of an application memory error detection device provided in an embodiment of the present application;
[0035] Figure 10 A schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] In the embodiments of this application, terms such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. For example, the terms "first chip" and "second chip" are used solely to distinguish between different chips and do not define their order. Those skilled in the art will understand that terms such as "first" and "second" do not define the quantity or execution order, and do not necessarily define differences.
[0037] It should be noted that in the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described in this application as "exemplary" or "for example" should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0038] In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, c can be single or multiple.
[0039] With the advancement of computer technology, different application developers are dedicated to developing different applications. Some applications are outsourced to third parties, and these third-party applications are typically delivered without the source code. For ease of explanation, applications without source code are referred to as "sourceless applications" below. For example, a terminal device manufacturer may outsource a camera-related application to a third party, and the source code for such applications is not delivered to the terminal device manufacturer.
[0040] It is difficult to find memory errors when performing functional testing on source-free applications. However, memory errors such as memory leaks and memory overflows may occur when source-free applications are put into use.
[0041] Taking the Android system as an example, the memory error detection tool that can currently be used for memory error detection is GWP-ASan. GWP-ASan is a native memory allocator function that can help find memory errors. For example, heap buffer overflow errors, etc. When the application process starts (or when zygote is derived), GWP-ASan will be enabled on some randomly selected system applications and platform executable files. Once enabled, GWP-ASan will intercept randomly selected memory allocation requests. For example, GWP-ASan intercepts the heap allocation of randomly selected memory and puts it into a special area to capture difficult-to-detect heap memory corruption errors. GWP-ASan collects exception information related to all memory allocations it intercepts.
[0042] However, the GWP-ASan tool randomly selects memory allocation requests for testing. Because the tool is designed to detect memory errors in a production environment, it sets a random sampling rate and a maximum number of memory allocations to limit its impact on device performance and memory usage. Due to the large number of memory allocation requests in the system library, the probability of the tool actually detecting memory allocation requests from third-party applications or libraries is relatively low, making it difficult to detect memory errors during functional testing of third-party applications or libraries.
[0043] In view of this, an embodiment of the present application provides an application memory error detection method, in which the terminal device replaces the memory allocation-related functions in the code library that enables memory detection with functions including a first tag. In this way, when the terminal device obtains a memory allocation application including the first tag, the application is executed by a first memory allocator, such as the above-mentioned GWP-ASan, to perform memory error detection, thereby obtaining the memory error detection results in the code library.
[0044] The application memory error detection method provided in the embodiment of the present application can be applied to a terminal device. In the embodiment of the present application, the terminal device can also be referred to as a terminal, user equipment (UE), mobile station (MS) or mobile terminal (MT), etc. The terminal device can be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a desktop computer, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a vehicle-mounted terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, etc. The embodiment of the present application does not limit the specific technology and specific device form adopted by the terminal device.
[0045] In order to better understand the embodiments of the present application, the structure of the terminal device to which the embodiments of the present application are applicable is described below. Figure 1 FIG. 1 is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Figure 1 The terminal device 10 shown may include a processor 110, a memory 120, a universal serial bus (USB) interface 130, a power supply 140, a communication module 150, an audio module 170, a sensor module 180, a button 190, a camera 191, and a display screen 160. The sensor module 180 may include a pressure sensor 180A, a fingerprint sensor 180B, a touch sensor 180C, etc.
[0046] It should be understood that the structure illustrated in the embodiments of the present invention does not constitute a specific limitation on the terminal device 10. In other embodiments of the present application, the terminal device 10 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0047] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a digital signal processor (DSP), a baseband processor, etc. The different processing units may be independent devices or integrated into one or more processors.
[0048] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0049] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0050] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0051] The I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple I2C bus lines. The processor 110 may be coupled to the touch sensor 180C, the charger, the flash, the camera 191, and the like via different I2C bus interfaces. For example, the processor 110 may be coupled to the touch sensor 180C via the I2C interface, enabling communication between the processor 110 and the touch sensor 180C via the I2C bus interface, thereby implementing the touch function of the terminal device 10.
[0052] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface, enabling the function of answering calls through a Bluetooth headset.
[0053] The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0054] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface, enabling the function of playing music through Bluetooth headphones.
[0055] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display 160 and the camera 191. MIPI interfaces include the camera serial interface (CSI) and the display serial interface (DSI). In some embodiments, the processor 110 and the camera 191 communicate via the CSI interface to implement the camera function of the terminal device 10. The processor 110 and the display 160 communicate via the DSI interface to implement the display function of the terminal device 10.
[0056] The USB interface 130 is an interface that complies with USB standards and may be a Mini USB interface, a Micro USB interface, a USB Type-C interface, or the like. The USB interface 130 can be used to connect a charger to charge the terminal device 10, or to transfer data between the terminal device 10 and peripheral devices. It can also be used to connect headphones to play audio. This interface can also be used to connect other electronic devices, such as AR devices.
[0057] It is understood that the interface connection relationship between the modules illustrated in the embodiment of the present invention is merely an illustrative illustration and does not constitute a structural limitation on the terminal device 10. In other embodiments of the present application, the terminal device 10 may also adopt a different interface connection method from the above embodiment, or a combination of multiple interface connection methods.
[0058] The power supply 140 supplies power to the terminal device 10 .
[0059] The communication module 150 can use any transceiver or other device to communicate with other devices or communication networks, such as wide area networks (WAN), local area networks (LAN), etc.
[0060] The terminal device 10 implements display functions through a GPU, display screen 160, and an application processor. The GPU is a microprocessor for image processing that connects the display screen 160 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0061] The display screen 160 is used to display images, videos, etc. The display screen 160 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, the terminal device 10 may include one or N display screens 160, where N is a positive integer greater than 1.
[0062] The terminal device 10 can implement the shooting function through the ISP, camera 191, video codec, GPU, display screen 160 and application processor.
[0063] The ISP processes data fed back by camera 191. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and converted into a visible image. The ISP can also perform algorithmic optimization on image noise, brightness, and skin tone. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 191.
[0064] The camera 191 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the terminal device 10 may include 1 or N cameras 191, where N is a positive integer greater than 1.
[0065] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the terminal device 10 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0066] The memory 120 may be used to store one or more computer programs, which include instructions. The processor 110 may execute the instructions stored in the memory 120 to enable the terminal device 10 to perform various functional applications and data processing.
[0067] The memory 120 may include a program storage area and a data storage area. The program storage area may store an operating system; the program storage area may also store one or more applications (such as gallery, contacts, etc.). Exemplarily, the program storage area of the memory 120 may store the target correspondence relationship and the target function including the first tag in the method provided in the embodiment of the present application. The target correspondence relationship is the correspondence relationship between the universal function identifier and the identifier of the target function. The universal function identifier is used to characterize functions related to memory allocation. The target correspondence relationship and the target function including the first tag may be pre-stored in the memory 120.
[0068] The data storage area can store data (such as photos, etc.) created during the use of the terminal device 10. In addition, the memory 120 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. In some embodiments, the processor 110 can execute instructions stored in the memory 120 and / or instructions stored in a memory provided in the processor 110 to enable the terminal device 10 to perform various functional applications and data processing.
[0069] The terminal device 10 can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0070] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.
[0071] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 180A can be located on display screen 160. There are many types of pressure sensors 180A, such as resistive, inductive, and capacitive. A capacitive pressure sensor can include at least two parallel plates made of conductive material. When force is applied to pressure sensor 180A, the capacitance between the electrodes changes. Terminal device 10 determines the intensity of the pressure based on the change in capacitance. When a touch operation is applied to display screen 160, terminal device 10 detects the intensity of the touch operation based on pressure sensor 180A. Terminal device 10 can also calculate the location of the touch based on the detection signal from pressure sensor 180A. In some embodiments, touch operations applied to the same touch location but with different touch operation intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, an instruction to view short messages is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to a short message application icon, an instruction to create a new short message is executed.
[0072] The fingerprint sensor 180B is used to collect fingerprints. The terminal device 10 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint answering calls, etc.
[0073] Touch sensor 180C, also known as a "touch device," can be provided on display screen 160. The touch sensor 180C and display screen 160 form a touch screen, also known as a "touch screen." Touch sensor 180C is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to an application processor to determine the type of touch event. Visual output related to the touch operations can be provided via display screen 160. In other embodiments, touch sensor 180C can also be provided on the surface of terminal device 10, at a location different from that of display screen 160.
[0074] The buttons 190 include a power button, a volume button, etc. The buttons 190 may be mechanical buttons or touch buttons. The terminal device 10 may receive key inputs and generate key signal inputs related to user settings and function control of the terminal device 10.
[0075] The software system of the terminal device 10 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the Android system with a layered architecture is used as an example to illustrate the software structure of the terminal device 10.
[0076] Figure 2This is a block diagram of the software structure of the current terminal device. The layered architecture divides the software system of the terminal device 10 into several layers, each with clear roles and divisions of labor. Layers communicate with each other via software interfaces. In some embodiments, the Android system may include an application layer (applications), an application framework layer (application framework), and a system library layer.
[0077] like Figure 2 As shown, the application layer runs the application by calling the application programming interface (API) provided by the application framework layer. The application layer may include the binary library file of the application (also known as the installation package or application library of the application) and the preset file. The directory where the application library is stored may be: / data / application / *, *.so. Among them, * is used to represent the identifier of the application library. The application library may include: a procedure link table (PLT) and a global offset table (GOT). Among them, the PLT can store jump functions, which are functions used by the executable program to call external libraries, and the GOT can be used to store address information, which may include the destination address of the executable program calling the external library function. The preset file may include the AndroidMainfest.xml file.
[0078] The application framework layer provides API and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 2 As shown, the application framework layer may include a hook library. For example, the hook library may include libgwp_asan_malloc_hooks.so. After the terminal device is started, the application framework layer runs a zygote process and system services. System services may include an activity manager service (AMS) and a package manager service (PMS).
[0079] AMS can be used to uniformly schedule various application processes. PMS can be used to manage the installation of application packages and the uninstallation of applications. For example, when installing an application, PMS can be used to scan a preset file. If the first memory allocator is set to be enabled in the preset file, when AMS starts the application, AMS can send a second flag to the incubator process via runtimeFlags, and the incubator process synchronizes the second flag to the application process. The second flag is used for the application process to enable the first memory allocator during the application startup process. The first memory allocator can be GWP-Asan.a.
[0080] The hook library includes a hook function. The hook function is a function identified by the identifier of the target function in the target correspondence stored in the memory. During application startup, the application process can replace the memory allocation-related functions in the application's binary library file with the hook function in the hook library based on the target correspondence; the memory allocation-related application obtained by the application process executing the hook function includes a first tag. The first tag is used to indicate that the memory allocation-related application is executed by the first memory allocator. In this way, memory error detection can be performed on the memory allocation-related application.
[0081] The system library may include a standard function library, a memory allocator, and a crash handler. The memory allocator may be used to process memory allocation requests and memory release requests. The memory allocator may include a first memory allocator and a second memory allocator. The first memory allocator may be Figure 2 In the GWP-ASan allocator shown, the second memory allocator may be a common memory allocator without a memory error detection function. For example, the second memory allocator may be malloc.
[0082] The standard function library can be Android Bionic Libc. Android Bionic Libc includes memory application dispatch judgment logic, that is, memory application allocation method. The memory application dispatch judgment logic includes a random sampling dispatch mechanism (corresponding to Figure 2 Gwp_asan_dispatch), tag-aware dispatch mechanism (corresponding to Figure 2hook context) and property configuration file, the random sampling dispatch mechanism is used to use random sampling to determine whether the memory allocation-related application goes to GWP-Asan.a for memory allocation, and the tag-aware dispatch mechanism may include a first tag judgment function, which can be used to determine whether the memory allocation-related application includes the first tag. In the case that the memory allocation-related application includes the first tag, the tag-aware dispatch mechanism assigns the application to the first memory allocator for processing. The first memory allocator detects memory allocation errors during the execution of the memory allocation-related application. The first memory allocator can be GWP-Asan.a. The property configuration file can be used to configure the third tag of the application. In the case that the third tag of the application is included in the property configuration file, during the startup of the application, the process of the application can replace the memory allocation-related function with the corresponding target function according to the target correspondence.
[0083] The crash handler can be used to obtain memory detection data. For example, Figure 2 The tombstoned process in the system library layer can be used to obtain instrumentation data from application processes to generate memory crash reports for the applications. The tombstoned process can be used to execute a crash handler to obtain instrumentation data from the application processes. The instrumentation data may include information about the application process's crash type, allocation metadata, and associated allocation and deallocation stack traces. For example, the instrumentation data obtained may be GwpAsanCrashData. The crash handler may be gwp_asan_crash_handler.a.
[0084] The following first describes the application startup process provided by the embodiment of the present application with reference to the accompanying drawings. Figure 3 A schematic diagram of an application startup process in an application memory error detection method provided in an embodiment of the present application. Figure 3 The application startup process shown may include the following steps:
[0085] S300: The desktop launcher in the terminal device receives a launch operation for a first application.
[0086] In the embodiment of the present application, after the terminal device is started, a desktop launcher (eg, launcher), system services, and a zygote process are run in the terminal device.
[0087] In a possible implementation, a desktop launcher in a terminal device receives a click operation of a user on an icon of a first application program, and the click operation is used to launch the first application program.
[0088] S301: The desktop launcher sends a process creation instruction to the system service in response to the launch instruction, where the process creation instruction is used to create a process of the first application.
[0089] S302: The system service obtains the configuration status of the first memory allocator in response to the process creation instruction.
[0090] In an embodiment of the present application, the configuration status of the first memory allocator can be obtained by PMS scanning the preset file when the first application is installed. The configuration status of the first memory allocator in the preset file can be used to indicate that the first memory allocator is enabled for the first application.
[0091] In one example, the preset file is an AndroidMainfest.xml file, which includes:
[0092] <application android:gwpAsanMode=”always”>
[0093] …
[0094]
[0095] In this file, android:gwpAsanMode="always" is used to indicate that the first memory allocator is enabled for the application.
[0096] Regarding step S302, in a possible implementation, in response to the process creation instruction, the AMS calls the PMS to obtain the configuration status of the first memory allocator.
[0097] S303: The system service sends a process creation request to the incubator process.
[0098] In the embodiment of the present application, the process creation request may include a second flag. The second flag is used to indicate that the first memory allocator is enabled.
[0099] In a possible implementation, when the configuration state of the first memory allocator indicates that the first memory allocator is enabled for the first application, the process creation request sent by the system service to the incubator process includes the second flag. When the configuration state of the first memory allocator indicates that the first memory allocator is not enabled, the process creation request sent by the system service to the incubator process includes other flags.
[0100] Exemplarily, when the configuration state of the first memory allocator is used by the system service to characterize that the first memory allocator is enabled for the first application, the second tag included in the process creation request sent to the incubator process can be characterized by the first value of runtimeFlags, and the first value of runtimeFlags can indicate that the first memory allocator is enabled for the first application. When the configuration state of the first memory allocator is used to characterize that the first memory allocator is not enabled, the other tags included in the process creation request sent by the system service to the incubator process can be characterized by the second value of runtimeFlags, and the second value of runtimeFlags can indicate that the first memory allocator is not enabled.
[0101] S304: The incubator process creates a process of the first application according to the process creation request.
[0102] Regarding step S304, in a possible implementation, the incubator process creates a process of the first application according to the process creation request and synchronizes the second tag to the process of the first application.
[0103] S305: During the startup of the first application, the process of the first application starts the first memory allocator according to the memory check mode configuration file or the second mark.
[0104] The process of the first application program may assign a preset value to the third flag to enable the first memory allocator. The third flag is used to indicate whether the first memory allocator is enabled or disabled. For example, when the value of the third flag is 1 (true), the first memory allocator is enabled, and when the value of the third flag is 0 (false), the first memory allocator is disabled.
[0105] In an embodiment of the present application, the memory check mode configuration file may be a property configuration file.
[0106] In one possible implementation, a process of a first application obtains a memory check mode configuration file. When the memory check mode configuration file includes configuration items for the first application, the process of the first application assigns a preset value to a third flag to enable a first memory allocator. The configuration items for the first application are used to instruct the first application to perform memory error detection. The third flag is a preset value that indicates the activation of the first memory allocator on the terminal device. The first memory allocator can detect memory allocation errors during the execution of a memory request.
[0107] In one example, the property configuration file read during the startup of the first application includes the value of gwp_asan_app as "all." gwp_asan_app is used to identify a configuration item. When the value of this startup flag is "all," it indicates that memory check mode is enabled for all applications running on the terminal device. The first application's process assigns the third flag, forceEnableGwpAsan, a preset value of true. A value of true for forceEnableGwpAsan indicates that the first memory allocator is enabled.
[0108] In another example, a property configuration file read during startup of a first application includes a value of gwp_asan_app as an identifier of the first application. gwp_asan_app is used to identify a configuration item. In this case, the identifier indicates that memory check mode is enabled when the terminal device runs the first application. The process of the first application assigns a third flag, forceEnableGwpAsan, to a preset value of true. ForceEnableGwpAsan being true indicates that the first memory allocator is enabled.
[0109] In another possible implementation, the configuration state of the first memory allocator is characterized by the first application program starting the first memory allocator and the process of the first application program assigning a preset value to the third flag.
[0110] In the embodiment of the present application, S300 to S305 enable the first memory allocator during the startup of the first application.
[0111] In the embodiment of the present application, during the application startup process, the functions related to memory allocation in the target library need to be replaced with hook functions provided by gwp hooks. The hook functions are located in the hook library of the application framework layer.
[0112] S306: The process of the first application replaces the first function in the code library corresponding to the first application with the target function corresponding to the first function.
[0113] In an embodiment of the present application, the first function is a function related to memory allocation. When the first function is replaced with the target function, the process of the first application program executing the target function may generate a request related to memory allocation that includes a first tag. The first tag can be perceived by the memory request dispatch judgment logic in the system library. When the request related to memory allocation includes the first tag, the memory request dispatch judgment logic assigns the request to the first memory allocator for processing. For example, the memory request dispatch judgment logic assigns the request to the GWP-Asan allocator for processing.
[0114] In one possible implementation, a system service receives a trigger instruction, which may be input in the form of a command line. In response to the trigger instruction, the system service calls a main thread of a first application to execute a replacement function. The main thread of the first application executes the replacement function to replace a first function in a code base corresponding to the first application with a target function corresponding to the first function.
[0115] For example, Figure 4 The command line tool executes adb shell dumpsys meminfo_gwp-hook to send a trigger instruction to the system service. In response to the trigger instruction, the system service calls the activityThread.dumpMemInfo instruction to call the main thread of the first application to execute the replacement function, thereby replacing the first function in the code library corresponding to the first application with the target function corresponding to the first function.
[0116] The replacement function may include a first replacement function debug.performGwpHook() and a second replacement function perform_malloc_hooks(). debug.performGwpHook() is a function written in Java, and perform_malloc_hooks() is a function written in C. The process of the first application executes debug.performGwpHook(), which calls perform_malloc_hooks() during execution to replace the first function in the code base corresponding to the first application with the target function corresponding to the first function.
[0117] In another possible implementation, the incubator process creates a main thread of the first application. If it is determined that the configuration item in the memory check mode configuration file includes the identifier of the first application, the main thread of the first application replaces the first function in the code base corresponding to the first application with the target function corresponding to the first function. If the configuration item in the memory check mode configuration file includes the identifier of the first application, the memory check mode configuration file indicates that memory checking is enabled in the code base corresponding to the first application.
[0118] In one example, Figure 5 When the incubator process calls the creation instruction to create (fork) the main thread of the first application, the main thread of the first application executes the first replacement function debug.performGwpHook(), and the first replacement function calls the second replacement function perform_malloc_hooks() to replace the first function in the code library corresponding to the first application with the target function corresponding to the first function.
[0119] The main thread of the first application can obtain the target function corresponding to the first function according to the target correspondence, and replace the first function in the code library corresponding to the first application with the target function.
[0120] For example, the target correspondence is shown in Table 1 below:
[0121] Table 1
[0122] First function Objective function Malloc gwp_malloc_hook calloc gwp_calloc_hook realloc gwp_realloc_hook
[0123] In Table 1, the target function corresponding to the first function Malloc is gwp_malloc_hook, the target function corresponding to the first function calloc is gwp_calloc_hook, and the target function corresponding to the first function realloc is gwp_realloc_hook.
[0124] It is understandable that the target correspondence relationship can also be expressed in other ways, and the embodiments of the present application are not limited to this.
[0125] Exemplarily, the replacement function defines a correspondence between a first function and a target function. If the replacement function includes the first function included in the correspondence in the code library corresponding to the application, the first function is replaced with the target function. Subsequently, the address corresponding to the target function is stored in the global offset table.
[0126] It should be noted that the code implementation in the embodiment of the present application may include a command line interface, a Java interface, and a C / C++ interface. Among them, the command line interface is used to trigger the call of the replacement function to replace the first function in the program library of the application with the target function, and replace the first judgment logic in the system library layer with a memory application dispatch judgment logic that combines the first judgment logic with the second judgment logic. The replaced memory application dispatch judgment logic can assign the application to the first memory allocator for processing when it is determined that the application related to memory allocation includes the first mark, and can assign the application to the second memory allocator for processing when it is determined that the application does not include the first mark. The Java interface is used to implement the triggering of the first replacement function, and the C / C++ interface is used to trigger the triggering of the second replacement function.
[0127] At this point, after the first application is started, the memory error check configuration for the specific code base in the first application is completed, or the memory error check configuration for the first application is completed.
[0128] The following describes the application memory error detection process provided by the embodiment of the present application with reference to the accompanying drawings. Figure 6A schematic diagram of an application memory error detection process in an application memory error detection method provided in an embodiment of the present application. Figure 6 The application memory error detection process shown may include the following steps:
[0129] S600: The terminal device obtains a first application from a first application program.
[0130] In the embodiment of the present application, the first application is an application related to memory allocation.
[0131] In a possible implementation, a thread of the first application in the terminal device searches the global offset table for the location of the target function based on the identifier of the target function, and executes the target function to obtain the first application. The identifier of the target function may be the function name of the target function.
[0132] In a possible implementation, a first tag may be set for the first application obtained by executing the target function. The first tag of the first application may be set at an address stored in a thread local storage (TLS) corresponding to the first application.
[0133] For example, since the lowest bit of the address stored in the TLS of the first application is usually 0, the embodiment of the present application can set the first flag of the first application by setting the lowest bit of the address stored in the TLS corresponding to the first application to 1. The first flag can be used to determine whether the first application is executed by the hook function in the hook library.
[0134] S601: When the first application includes a first tag, the terminal device performs memory error detection on the execution process of the first application.
[0135] In a possible implementation, the terminal device determines whether the first application includes a first tag. If the first application includes the first tag, the terminal device uses a first memory allocator to execute the first application to perform memory error detection on the execution process of the first application.
[0136] Based on the example in S600, the terminal device determines whether the lowest bit of the address in TLS corresponding to the first application is 1. If so, it is determined that the first application includes the first mark; if not, it is determined that the first application does not include the first mark.
[0137] S602: The terminal device obtains a detection result of a memory error detection.
[0138] In a possible implementation, a system service in the terminal device reads a detection result of memory error detection performed by the first memory allocator.
[0139] In an embodiment of the present application, a terminal device replaces a memory allocation-related function in a code base that enables memory detection with a function that includes a first tag. In this way, a memory request obtained by executing the replaced function includes the first tag. When the terminal device obtains a memory allocation request including the first tag, the terminal device executes the request with a first memory allocator (such as the aforementioned GWP-Asan allocator) to perform memory error detection, thereby obtaining a memory error detection result in the code base. This is helpful for detecting memory errors in binary third-party applications.
[0140] like Figure 7 The figure is a flow chart of an application memory error detection method provided in an embodiment of the present application. Figure 7 In the application memory error detection method shown, the application is first started. The possible implementation methods refer to the above Figure 3 The startup process of the corresponding application will not be described in detail. After the application is started, the terminal device executes the hook function. Exemplarily, the hook function can be gwp_malloc_hook, which can be provided by the libgwp_asan_malloc_hooks.so library. During the execution process, the hook function intercepts memory allocation-related applications and sets a first mark for memory allocation-related applications. The terminal device executes the memory application dispatch judgment logic, which can be gwp_asan_malloc in the standard function library libc. The terminal device determines whether the memory allocation-related application includes the first mark. If so, the GWP-Asan allocator is used to execute the memory allocation-related application. If not, malloc is used to execute the memory allocation-related application.
[0141] In this way, memory allocation-related applications with the first mark set can use the GWP-Asan allocator to execute the application to record memory allocation errors, and memory allocation-related applications that do not include the first mark can use malloc to execute the memory allocation-related applications, which helps to solve the current problem of being unable to detect memory errors in applications.
[0142] like Figure 8 Shown is a flow chart of another application memory error detection method provided in an embodiment of the present application. Figure 8 The application memory error detection method shown includes the following steps:
[0143] S800: The terminal device replaces the function related to memory allocation in the application with the target function.
[0144] In the embodiment of the present application, the function related to memory allocation may be the first function in the above embodiment, and the target function may be the target function in the above embodiment.
[0145] For possible implementation methods, please refer to the description in S306 and will not be repeated here.
[0146] S801: The terminal device executes a target function to obtain a first application related to memory allocation.
[0147] In the embodiment of the present application, the first application is provided with a first mark.
[0148] For possible implementation methods, please refer to the description in S600 and will not be repeated here.
[0149] S802: When executing a first application including a first tag, the terminal device performs memory error detection on an execution process of the first application.
[0150] For possible implementation methods, please refer to the description in S601 and will not be repeated here.
[0151] In an embodiment of the present application, the terminal device replaces the memory allocation-related functions in the code library that enables memory detection with functions including the first tag. In this way, when the terminal device obtains a memory allocation application including the first tag, the application is executed by the first memory allocator, such as the above-mentioned GWP-ASan, to perform memory error detection, thereby obtaining the memory error detection result in the code library.
[0152] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of method. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the method steps of each example described in the embodiment disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software driven hardware manner depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0153] The embodiment of the present application can divide the functional modules of the device for implementing the application memory error detection method according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. Exemplarily, the functions of the target application, the drawing interface, and the display engine are integrated into the display control unit. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0154] like Figure 9FIG. 1 is a schematic diagram showing the structure of an application memory error detection device provided by an embodiment of the present application. Figure 9 The application memory error detection device 90 shown includes a storage module 901 and a processing module 902: the storage module 901 stores the correspondence between the function related to memory allocation and the target function; the processing module 902 is used to: replace the first function in the application with the target function corresponding to the first function according to the correspondence; the first function is a function related to memory allocation; execute the target function to obtain a first application related to memory allocation; the first application is set with a first mark; when executing the first application including the first mark, perform memory error detection on the execution process of the first application. For example, in combination with Figure 8 , the processing module 902 can be used to execute S800~S802, combined with Figure 3 , the processing module 902 can be used to execute S300~S306, combined with Figure 6 , the processing module 902 can be used to execute S600 to S602.
[0155] Optionally, a GWP-ASan allocator is configured in the processing module 902; the GWP-ASan allocator is used to perform memory error detection on the executed memory allocation-related applications; the processing module 902 is also used to: turn on the GWP-ASan allocator according to the memory check mode configuration file or the configuration status of the GWP-ASan allocator; the configuration status is used to characterize the turning on of the GWP-ASan allocator; the memory check mode configuration file includes configuration items of the application; the configuration items are used to indicate memory error detection for the application; the processing module 902 is specifically used to use the GWP-ASan allocator to perform memory error detection on the execution process of the first application.
[0156] Optionally, an application process is running in the processing module 902; during the startup of the application, the application process is used to obtain a memory check mode configuration file; when the memory check mode configuration file includes configuration items of the application, the application process is used to enable the GWP-ASan allocator.
[0157] Optionally, a system service and an incubator process are running in the processing module 902. During the startup of the application, the system service is used to obtain the configuration status of the GWP-ASan allocator; the configuration status is used to indicate the start of the GWP-ASan allocator; the system service is also used to send a process creation instruction to the incubator process; the process creation instruction includes a second flag, and the second flag is used to instruct the incubator process to turn on the GWP-ASan allocator; in response to the process creation instruction, the incubator process is used to create an application process; the application process is used to turn on the GWP-ASan allocator according to the second flag.
[0158] Optionally, a system service and a main thread of an application are running in the terminal device, and the system service is used to receive a trigger instruction; in response to the trigger instruction, the system service is also used to call the main thread of the application to replace the function related to memory allocation in the application with the target function.
[0159] Optionally, the trigger instruction comes from any one of a command line interface, a Java interface, a C interface, or a C++ interface.
[0160] Optionally, an incubator process is running in the terminal device, and the incubator process is used to create the main thread of the application. When it is determined that the memory check mode configuration file includes configuration items of the application, the main thread of the application is used to replace functions related to memory allocation in the application with target functions; the configuration items are used to instruct memory error detection on the application.
[0161] In one example, combining Figure 1 , the function of the storage module 901 can be Figure 1 The memory 120 is implemented, and the function of the processing module 902 can be realized by Figure 1 The processor 110 calls the computer program instructions in the memory 120 to implement it.
[0162] like Figure 10 FIG2 is a schematic diagram of a chip structure according to an embodiment of the present application. The chip 100 includes one or more (including two) processors 1001 , a communication circuit 1002 , and a communication interface 1003 . Optionally, the chip 100 also includes a memory 1004 .
[0163] In some embodiments, the memory 1004 stores the following elements: executable modules or data structures, or a subset thereof, or an extended set thereof.
[0164] The method described in the above embodiment of the present application can be applied to the processor 1001, or implemented by the processor 1001. The processor 1001 may be an integrated circuit chip with signal processing capabilities. During implementation, the steps of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 1001. The above-mentioned processor 1001 can be a general-purpose processor (for example, a microprocessor or a conventional processor), a digital signal processor (digital signal processing, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field-programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates, transistor logic devices or discrete hardware components. The processor 1001 can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.
[0165] The steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. Among them, the software module can be located in a storage medium mature in the art such as a random access memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable read only memory (EEPROM). The storage medium is located in the memory 1004, and the processor 1001 reads the information in the memory 1004 and completes the steps of the above method in combination with its hardware.
[0166] The processor 1001 , the memory 1004 , and the communication interface 1003 can communicate with each other via the communication line 1002 .
[0167] In the above embodiment, the instructions stored in the memory for execution by the processor may be implemented in the form of a computer program product, wherein the computer program product may be pre-written in the memory or downloaded and installed in the memory in the form of software.
[0168] The present application also provides a computer program product including one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. For example, the available medium can include magnetic media (e.g., floppy disk, hard disk or tape), optical media (e.g., digital versatile disc (DVD)), or semiconductor media (e.g., solid state disk (SSD)).
[0169] An embodiment of the present application provides an electronic device, which includes a processor and a memory, the memory being used to store a computer program, and the processor being used to execute the computer program to perform any one of the above-mentioned application memory error detection methods.
[0170] The present application also provides a computer-readable storage medium. The methods described in the above embodiments can be implemented in whole or in part via software, hardware, firmware, or any combination thereof. Computer-readable media can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one location to another. The storage medium can be any target medium that can be accessed by a computer.
[0171] As one possible design, computer-readable media may include compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM or other optical disc storage; computer-readable media may include magnetic disk storage or other magnetic disk storage devices. Moreover, any connecting line may also be appropriately referred to as a computer-readable medium. For example, if the software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL or wireless technologies such as infrared, radio and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technologies such as infrared, radio and microwave are included in the definition of medium. Disk and disc as used herein include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while discs reproduce data optically using lasers.
[0172] The above combinations should also be included within the scope of computer-readable media. The above description is only a specific embodiment of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by any person skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A method for detecting an application memory error, characterized in that: Applied to a terminal device; the method comprises: The terminal device replaces the function related to memory allocation in the application with the target function; The terminal device executes the target function to obtain a first application related to memory allocation; the first application is set with a first flag; When the terminal device executes the first application including the first tag, the terminal device performs memory error detection on the execution process of the first application; The terminal device is configured with a GWP-ASan allocator; the GWP-ASan allocator is used to perform memory error detection on the executed memory allocation related application; the method further includes: The terminal device enables the GWP-ASan allocator according to a memory check mode configuration file or a configuration state of the GWP-ASan allocator; the configuration state is used to indicate that the GWP-ASan allocator is enabled; the memory check mode configuration file includes a configuration item of the application; the configuration item is used to instruct the application to perform memory error detection; The terminal device performs memory error detection on the execution process of the first application, including: The terminal device uses the GWP-ASan allocator to perform memory error detection on the execution process of the first application.
2. The application memory error detection method according to claim 1, characterized in that: A process of the application is running in the terminal device; The terminal device starts the GWP-ASan distributor according to a memory check mode configuration file or a configuration state of the GWP-ASan distributor, including: During the startup of the application, the process of the application obtains the memory check mode configuration file; In a case where the memory check mode configuration file includes the configuration item of the application, the process of the application starts the GWP-ASan allocator.
3. The application memory error detection method according to claim 1, characterized in that: The terminal device runs a system service and an incubator process, and the terminal device starts the GWP-ASan distributor according to a memory check mode configuration file or a configuration state of the GWP-ASan distributor, including: During the startup of the application, the system service obtains the configuration state of the GWP-ASan allocator; the configuration state is used to indicate the start of the GWP-ASan allocator; The system service sends a process creation instruction to the incubator process; the process creation instruction includes a second flag, and the second flag is used to instruct the incubator process to start the GWP-ASan distributor; In response to the process creation instruction, the incubator process creates a process of the application; The application process starts the GWP-ASan allocator according to the second flag.
4. The application memory error detection method according to any one of claims 1 to 3, characterized in that: The terminal device runs a system service and a main thread of the application, and the terminal device replaces a function related to memory allocation in the application with a target function, including: The system service receives a trigger instruction; In response to the trigger instruction, the system service calls the main thread of the application to replace the function related to memory allocation in the application with the target function.
5. The application memory error detection method according to claim 4, characterized in that: The trigger instruction comes from any one of a command line interface, a Java interface, a C interface or a C++ interface.
6. The application memory error detection method according to any one of claims 1 to 3, characterized in that: The terminal device runs an incubator process, and the terminal device replaces a function related to memory allocation in the application with a target function, including: The incubator process creates the main thread of the application; When it is determined that the memory check mode configuration file includes a configuration item of the application, the main thread of the application replaces a function related to memory allocation in the application with the target function; the configuration item is used to instruct memory error detection for the application.
7. An application memory error detection device, characterized in that: Including storage module and processing module: The storage module stores a correspondence between functions related to memory allocation and target functions; The processing module is configured to: replace a first function in an application with a target function corresponding to the first function according to the corresponding relationship; the first function is a function related to memory allocation; execute the target function to obtain a first application related to memory allocation; the first application is provided with a first flag; and when executing the first application including the first flag, perform memory error detection on the execution process of the first application; The processing module is provided with a GWP-ASan allocator; the GWP-ASan allocator is used to perform memory error detection on the executed memory allocation related application; The processing module is further configured to: enable the GWP-ASan allocator according to a memory check mode configuration file or a configuration state of the GWP-ASan allocator; the configuration state is used to indicate that the GWP-ASan allocator is enabled; the memory check mode configuration file includes a configuration item of the application; the configuration item is used to instruct to perform memory error detection on the application; The processing module is specifically configured to perform memory error detection on the execution process of the first application using the GWP-ASan allocator.
8. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program to perform the application memory error detection method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed, the computer executes the application memory error detection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Memory detecting system and method
CN103294588A
Method and system for dynamically detecting C / C++ memory leak
CN105912458A