Method for processing memory stepping problem and related device
By detecting memory problems and obtaining fault logs without terminating the process that causes problems, the problem of insufficient processing function of memory problems in the existing technology is solved, and system stability and testing efficiency are improved.
Patent Information
- Application Number
- CN202311194632.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-14
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2043-09-14
AI Technical Summary
When dealing with memory problems, the existing technology can easily lead to frequent system crashes, inability to boot, low testing efficiency and poor ease of use.
By detecting whether there is a memory stepping problem, obtaining the fault log, and without terminating the process that causes the memory stepping problem, in order to avoid the problem of inability to boot, low testing efficiency and poor ease of use caused by process termination.
Improve the handling function of memory problems, avoid system crashes and low testing efficiency caused by process termination, and ensure system stability and ease of use.
Smart Images

Figure CN119668904A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic information technology, and in particular to a method for processing a memory problem and a related device. Background Art
[0002] Memory problems can be simply understood as a process accessing memory that it should not access. Memory problems may cause frequent system crashes. Detection of memory problems is crucial.
[0003] However, there is still room for improvement in the current memory handling function. Summary of the invention
[0004] The present application provides a method and a related device for processing a memory problem to solve the problem of how to improve the processing function of the memory problem. The disclosed technical solution is as follows:
[0005] A first aspect of the present application provides a method for processing a memory problem, which is applied to an electronic device. The method includes: detecting whether there is a memory problem, obtaining a detection result, and in response to the detection result indicating that a first process causes the memory problem, obtaining a fault log of the memory problem, and keeping the first process alive (keeping the running state of the first process). It can be seen that when obtaining the fault log, the first process that causes the memory problem is not terminated, so as to avoid problems such as inability to boot, low testing efficiency, and poor usability caused by terminating the process, thereby improving the processing function of the memory problem.
[0006] In some implementations, keeping the first process alive includes: before obtaining the fault log of the memory problem, pausing the first process to accurately collect relevant data of the first process when the memory problem occurs; after obtaining the fault log of the memory problem, resuming the first process to ensure that the first process remains running.
[0007] In some implementations, before pausing the first process, the method further includes: determining that a preconfigured switch is in an on state, where the on state indicates that the process causing the memory problem is not terminated.
[0008] In some implementations, the method further includes: determining that a pre-configured switch is in an unactivated state, the unactivated state indicating termination of the process causing the memory problem; and generating a fault log in response to the pre-configured parameter being a first value in the process of terminating the first process. The pre-configured switch enables the user to choose to terminate or not terminate the first process based on the state of the switch, which has high flexibility.
[0009] In some implementations, pausing the first process includes: pausing the first process in response to a preset signal sent to the first process, and providing a specific timing for pausing the first process so as to timely suspend the first process.
[0010] In some implementations, the preset signal carries a fault message, which is used to generate a fault log. The fault message is generated based on pre-acquired fault data, which includes pre-collected data associated with memory problems. The preset signal not only serves as a trigger signal for pausing the first process, but also lays the foundation for generating a fault log.
[0011] In some implementations, obtaining a fault log of a memory problem includes: passing a fault message to a first function by running a preset signal carrying a fault message, the fault message being used to generate a fault log, the fault message being generated based on pre-acquired fault data, the fault data including pre-collected data associated with the memory problem; associating the fault message with a tombstone log tombstone by calling the first function; and generating a tombstone with the fault message written therein by calling a second function to obtain the fault log. A tombstone can trigger fault prompt information, so a tombstone with a fault message written therein is not only conducive to prompting a fault in a timely manner, but also conducive to providing a basis for locating and handling memory problems.
[0012] In some implementations, before passing the fault message to the first function by running the preset signal carrying the fault message, the method further includes: generating the preset signal carrying the fault message by constructing parameters of the preset signal to lay a foundation for keeping the first process alive.
[0013] In some implementations, the fault data includes at least one of the following: stack information and heap information during the memory access process of the first process; and the address and address pointer where the memory problem is sent; and the memory size occupied by the memory access type of the first process and the mismatch identifier, the mismatch identifier being the basis for obtaining the detection result; and information on the function call stack operated by the first process; and address description information, the address description information is used to indicate the address value where the memory problem occurs, and at least one item of the content stored in the addresses surrounding the address where the memory problem occurs; and the fault type of the memory problem, the fault type including at least one of: heap buffer overflow, access to a released heap, and stack buffer overflow; and identifiers of the addresses surrounding the address where the memory problem occurs; and the register value of the first process, so as to locate and handle the memory problem.
[0014] In some implementations, an operating system is run in an electronic device, and the operating system includes system services, and the system services include a process keep-alive switch and a memory-trapping processing service; detecting whether there is a memory-trapping problem and obtaining a detection result includes: the memory-trapping processing service detects whether there is a memory-trapping problem and obtains a detection result; keeping a first process alive includes: the memory-trapping processing service keeps the first process alive in response to the process keep-alive switch being turned on.
[0015] The second aspect of the present application provides an electronic device, including: one or more processors, a memory and a touch screen; the memory is used to store program code; the processor is used to run the program code, so that the electronic device can implement the method for processing memory problems provided by the first aspect of the present application.
[0016] The third aspect of the present application provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed on an electronic device, the electronic device executes the method for processing the memory problem provided by the first aspect of the present application.
[0017] The fourth aspect of the present application provides a computer program product having an executable program stored thereon. When the computer program product is run on an electronic device, the electronic device implements the method for processing the memory problem provided by the first aspect of the present application.
[0018] It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all features and advantages can be realized in any single embodiment. On the contrary, it is understood that the description of features or beneficial effects means that specific technical features, technical solutions or beneficial effects are included in at least one embodiment. Therefore, the description of technical features, technical solutions or beneficial effects in this specification does not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions and beneficial effects described in the present embodiment can also be combined in any appropriate manner. Those skilled in the art will understand that the embodiment can be realized without one or more specific technical features, technical solutions or beneficial effects of a specific embodiment. In other embodiments, additional technical features and beneficial effects can also be identified in a specific embodiment that does not embody all embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 This is an example diagram of a memory problem that occurs during the running of a process;
[0021] Figure 2 This is an example diagram of terminating or not terminating a process based on the state of a process keep-alive switch provided in an embodiment of the present application;
[0022] Figure 3 is a structural example diagram of an electronic device provided in an embodiment of the present application;
[0023] Figure 4 An example diagram of a layered framework running in an electronic device;
[0024] Figure 5 A flowchart of a method for processing a memory problem disclosed in an embodiment of the present application;
[0025] Figure 6 A flowchart of detecting memory problems disclosed in an embodiment of the present application;
[0026] Figure 7 This is an example diagram of the principle of detecting memory problems disclosed in the embodiments of the present application;
[0027] Figure 8 A flowchart of obtaining fault data of memory problem disclosed in an embodiment of the present application;
[0028] Fig. 9 A flowchart for generating a fault log disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0029] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the embodiments of the present application, "one or more" refers to one, two or more; "and / or" describes the association relationship of the associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0030] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0031] The multiple involved in the embodiments of the present application means greater than or equal to two. It should be noted that in the description of the embodiments of the present application, the words "first", "second", etc. are only used for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order.
[0032] by Figure 1 For example, if an electronic device has a memory problem, such as Figure 1 The problem points A and B shown in the figure indicate that the memory problem occurs at two different progress points during the running of the process. If the memory problem is not detected on the electronic device, the tester cannot obtain the fault information.
[0033] Therefore, in some implementations, hardware address sanitizer (Hwasan) technology is used to detect memory problems in electronic devices.
[0034] Taking Hwasan as an example, the memory stepping detection technology terminates the process causing the memory stepping problem by default after detecting the memory stepping problem. During the research process, the inventor found that terminating the process causing the memory stepping problem has the following problems:
[0035] 1. During the startup of an electronic device, if a key service process causes a memory problem, the key service process will be terminated, which may cause the electronic device to fail to boot. It is difficult to locate the cause of the failure to boot, which will increase the workload of personnel.
[0036] 2. During the continuity test of the electronic equipment business, if the process is terminated due to memory shortage, the subsequent tests will be interrupted, that is, the subsequent processes of the business cannot be tested until the memory shortage problem of the previous process is solved, resulting in reduced test efficiency.
[0037] 3. When a user (such as a tester) is using a Hwasan-enabled electronic device (such as an internal test version of an electronic device), the process is terminated due to a memory problem, which will cause the service or application to exit, causing the user to feel that the application is unavailable or some service functions are abnormal, further leading to poor usability of the electronic device.
[0038] In order to solve the above problem, it is necessary to detect the memory problem, but not to terminate the process that causes the memory problem. Figure 2For example, in an embodiment of the present application, a process keep-alive switch is set. When the process keep-alive switch is turned off, a memory problem is detected, and after the memory problem is detected, the process causing the memory problem is terminated (i.e., the detected process exits). When the process keep-alive switch is turned on, a memory problem is detected, but after the memory problem is detected, the process causing the memory problem is not terminated (i.e., the detected process does not exit).
[0039] Based on Figure 2 Taking the technical guidance of an example, an embodiment of the present application provides a method for processing a memory problem. The method is applied to an electronic device with an enabled memory detection function.
[0040] In some implementations, the electronic device may be a mobile phone, a tablet computer, a desktop, a laptop, a notebook computer, an ultra-mobile personal computer (UMPC), a handheld computer, a netbook, a personal digital assistant (PDA), a wearable electronic device, a smart watch, or the like.
[0041] Take mobile phones as an example of electronic devices. Figure 3 The figure shows a partial structure of a mobile phone related to an embodiment of the present application, including: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0042] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In other embodiments, the electronic device may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0043] 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 processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc.
[0044] The wireless communication function of the electronic device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor.
[0045] The mobile communication module 120 can provide wireless communication solutions including 2G / 3G / 4G / 5G etc. applied in electronic devices.
[0046] The wireless communication module 130 can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc.
[0047] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device.
[0048] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 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. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 121, and / or the instructions stored in the memory provided in the processor.
[0049] In addition to the components described above, Figure 3 The functions of other components in will not be described in detail.
[0050] The processor 110 implements an operating system such as the iOS operating system, the Android open source operating system, or the Windows operating system by running program codes.
[0051] Taking the Android open source operating system as an example, Figure 4 It is a layered framework running in electronic devices. The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the system service, the Android runtime (Android runtime) and the system library, and the kernel layer.
[0052] The application layer can include a series of application packages. Figure 4 As shown, the application package may include applications such as camera, gallery, calendar, and call. The processes created by applications in the application layer at runtime may cause memory usage issues.
[0053] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 4 As shown, the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, and the like.
[0054] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0055] System services can include libraries written in C or C++, which can be used by different components in the Android system and can also provide services to developers through the application framework layer.
[0056] A system library can contain multiple function modules.
[0057] The modules related to the embodiments of the present application run in the system service and the system library. Specifically, the process keep-alive switch runs in the system service, and through the application interaction with the application framework layer, the application layer and other application settings, the process keep-alive switch is turned on or off. Keep-alive can be understood as keeping running. The service system also runs a memory stepping processing service, which is used to call the memory stepping detection library in the system library to implement a method for handling memory stepping problems.
[0058] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0059] It should be noted that although the embodiments of the present application are described using the Android system as an example, its basic principles are also applicable to electronic devices based on operating systems such as iOS or Windows.
[0060] Figure 5 The process of the method for processing the memory problem disclosed in the embodiment of this application is applied in the following scenarios:
[0061] Any process generated during the running of an application accesses memory. The memory schemes include but are not limited to: applying for memory (malloc) and releasing memory (free).
[0062] Figure 5 The following steps are included:
[0063] S101: In response to a process accessing a memory, determine whether there is a memory overflow problem.
[0064] The specific implementation process of S101 is as follows Figure 6shown.
[0065] If the judgment result is yes, execute S102, if the judgment result is no, end the process or return to execute S101, that is, continue to detect whether the memory problem occurs.
[0066] S102: Obtain abort_message, a fault message indicating a memory problem.
[0067] Fault messages are helpful in locating memory problems.
[0068] The specific implementation of S102 will be combined with Figure 8 The process shown is explained.
[0069] S103, determine whether the process keep-alive switch is turned on, if yes, execute S106-S110, if not, execute S104-S105.
[0070] If the process keep-alive switch is turned on, it means that after a memory problem is detected, the process will not be terminated but kept running. If the process keep-alive switch is turned off, it means that after a memory problem is detected, the process will be terminated.
[0071] Combination Figure 4 As shown, in some implementations, the configured switch status is obtained from a switch service in a system service.
[0072] S104, determine whether the pre-configured parameter is true, if so, execute S105, if not, end the process or return to execute S101, that is, continue to detect whether the memory problem occurs.
[0073] The pre-configured parameter is true, which means terminating the process that caused the memory problem. The pre-configured parameter is false, which means not doing anything.
[0074] In some implementations, the preconfigured parameters are fatal parameters in the destructor.
[0075] S105: terminating the process that causes the memory problem, and generating a fault log in the process of terminating the process.
[0076] Generating a fault log in the process of terminating a process can be understood as generating a fault report in the process of terminating a process, that is, generating a fault report is associated with terminating the process, that is, to obtain a fault report, the process needs to be terminated.
[0077] In some implementations, the native Android Die function is called to generate a fault log from the fault data obtained in S102 by calling the abort messagecallback function, and the process causing the memory problem is terminated after the fault log is generated.
[0078] The specific process of implementing the abort message callback function will be combined with Fig. 9 Provide explanation.
[0079] Combining S104-S105, it can be seen that if the pre-configured parameter is set to false, the process that causes the memory problem can be avoided from being terminated, but S105 is not executed. In other words, if the pre-configured parameter is set to false, the fault log cannot be obtained. Therefore, by changing the value of the pre-configured parameter, the purpose of obtaining the fault log after the memory problem is detected cannot be achieved.
[0080] And combined with Figure 4 As shown, the value of the pre-configured parameter is stored in the system library as a piece of data in a binary document, and therefore, it is not easy to modify.
[0081] It can be seen that the values of pre-configured parameters are not easy to be modified. Even if they are modified, although the process that causes the memory problem can be saved, the fault log cannot be obtained.
[0082] Although fault messages can be written into the log, the log cannot trigger the fault reporting mechanism, so it is not conducive to timely and effective perception of memory problems.
[0083] In summary, in this embodiment, it is necessary to ensure that the process causing the out-of-memory problem is not terminated and the fault log is obtained without modifying the value of the pre-configured parameter.
[0084] In this embodiment, through S106-S110, it is achieved to obtain the fault log without terminating the process that causes the memory problem.
[0085] S106. Construct debug signal parameters.
[0086] In some implementations, the debug signal is the native Android signal 35, whose parameters include info->si_code, info->si_pid, and info->si_value.sival_ptr. Info->si_code and info->si_pid are used to ensure the availability of the debug signal, and info->si_value.sival_ptr is used to deliver fault messages.
[0087] Based on this, the parameters for constructing debug signals include:
[0088] The type of the constructed debug signal is assigned to info->si_code, that is, info->si_code==SI_queue, where SI_queue is a constant indicating the subtype of the currently constructed debug signal.
[0089] The identification number of the process causing the memory trampling is assigned to info->si_pid, that is, info->si_pid==_getpid, where _getpid is the identification number (Process Identification, pid) of the process causing the memory trampling.
[0090] The fault message is assigned to the pointer info->si_value.sival_ptr, that is, info->si_value.sival_ptr = abort_message. This assignment operation means storing abort_message at the address indicated by the pointer info->si_value.sival_ptr.
[0091] S107. Send a debug signal to the process that causes the memory problem.
[0092] In some implementations, the Android native BIONIC_SIGNAL_DEBUGGER function is called through the Android native raise function to send a debug signal to the process.
[0093] S108: In response to sending a debug signal to the process, suspend the process causing the memory problem, and transmit the fault message carried by the debug signal by running the debug signal.
[0094] In some implementations, the debug signal is run by calling the signal callback function debugger_signal_handler. In some implementations, the abort_message in the address indicated by info->si_value.sival_ptr is assigned to process_info.abort_message, that is, process_info.abort_message = info->si_value.sival_ptr&~1, &~1 represents the operation of changing the lowest bit address to 0, which can be understood as abort_message is stored from the low bit in the address indicated by info->si_value.sival_ptr, and the purpose of the operation of changing the lowest bit address to 0 is to take out the complete abort_message from the address without taking out other values.
[0095] The purpose of pausing the process that causes the memory problem is to more accurately capture the fault data when the memory problem occurs.
[0096] Transmitting the fault message may be understood as transmitting the fault message to a function capable of associating the fault message with a tombstone, so as to execute S109.
[0097] S109. Associate abort_message with tombstone by calling dump_abort_message function.
[0098] Tombstone can be understood as a tombstone log, which records the death scene when a process dies, making it easier for developers to debug.
[0099] S110 . Generate a tombstone written into abort_message, that is, a fault log, by calling the engrave_tombstone function.
[0100] S111. Resume the process that caused the memory problem.
[0101] Figure 5 The process shown can choose to terminate or not terminate the process that causes the memory problem when the memory problem occurs, through the state of the process keep-alive switch. In addition, the generation of the fault log is decoupled from the termination of the process, and the fault log can be obtained without terminating the process that causes the memory problem, which is conducive to the reporting and processing of the memory problem. Therefore, the method for processing the memory problem provided in this embodiment can not only obtain the fault log, but also keep the process running, thereby avoiding various problems caused by the termination of the process.
[0102] Figure 6 In response to a process accessing memory, a process for determining whether there is a memory problem includes the following steps:
[0103] S201. In response to a process accessing a memory, encapsulate a system native access function as a target function.
[0104] In some implementations, the system native access functions include a malloc function and a free function, and the malloc function and the free function are encapsulated to obtain a target function.
[0105] by Figure 7 For example, the target function obtained by encapsulating the malloc function is recorded as hwasan_malloc, and the target function obtained by encapsulating the free function is recorded as hwasan_free.
[0106] The purpose of the target function is to replace the native function of the system. In addition to realizing the functions of the native function of the system, it also performs the following steps to detect the memory problem.
[0107] S202: configure an associated tag for the accessed memory, and store the tag in the shadow memory.
[0108] Combination Figure 7 As shown, the tag associated with the memory is stored in the shadow. In some implementations, the tag is the upper 8 bits of the address of the accessed memory. If it is a normal access, the upper 8 bits of the address of the access request will not change. Therefore, it can be used to detect whether a memory problem occurs.
[0109] S203: Store stack information and heap information during memory access.
[0110] The stack information during memory access can be understood as the stack information generated during memory application and / or release. The heap information during memory access can be understood as the heap information generated during memory application and / or release.
[0111] Combination Figure 7 As shown, the stack allocation ring buffer (StackAllocations ringbuffer) is used to store stack information, and the heap allocation ring buffer (HeapAllocations ringbuffer) is used to store heap information.
[0112] The purpose of storing stack information and heap information is to lay the foundation for the subsequent generation of fault logs.
[0113] S204. Compare the high bits of the address of the accessed memory with the tag in the shadow memory.
[0114] If the comparison result shows that the two are the same, it means that there is no memory problem and the process ends. If the comparison result shows that the two are different, it means that there is a memory problem.
[0115] Figure 6 The method for detecting the memory problem shown in the figure uses tags to detect whether the memory problem occurs, and has better accuracy and feasibility.
[0116] Figure 8 The specific process for obtaining fault data for memory problems includes the following steps:
[0117] S301. Create a scoedReport function.
[0118] The function of scoedReport is to collect the memory access related parameters that cause the memory problem, so as to generate the fault log.
[0119] S302: Read the stack information and heap information during the memory access process.
[0120] In combination with S203, stack information is read from the StackAllocations ringbuffer, and heap information is read from the HeapAllocations ringbuffer. It is understandable that there may be no information in the StackAllocations ringbuffer and / or the HeapAllocations ringbuffer, in which case the stack information and heap information cannot be read.
[0121] The stack information and heap information during the memory access process are helpful in determining the fault type of the memory problem.
[0122] S303, by calling scoedReport function, perform the following steps:
[0123] S3031. Read the address and address pointer that do not match the tag.
[0124] It is understandable that a tag mismatch can be understood as the high bit of the accessed address is different from the tag in the shadow memory. The address with a tag mismatch is the address that sends the memory problem. The address pointer can be understood as a pointer to the address with a tag mismatch. In some implementations, the address pointer is stored in a register, and in this step, the address pointer is read from the register.
[0125] S3032. Obtain the memory access type, the occupied memory size, and the mismatched tags of the process causing the memory problem.
[0126] Access types include allocating memory or releasing memory.
[0127] S3033. Obtain information about the function call stack of the process operation that causes the memory problem.
[0128] The function call stack information is used to locate the memory problem, that is, which process caused the memory problem at which step.
[0129] S3034. Obtain address description information.
[0130] The address description information is used to indicate the address value where the memory problem occurs and at least one item of content stored in the addresses around the address where the memory problem occurs.
[0131] S3035. Check the specific fault type of the memory problem.
[0132] In some implementations, the specific type includes at least one of a heap buffer overflow, a heap use after free, and a stack buffer overflow.
[0133] Combination Figure 8 As shown, the specific checking method includes: checking whether Heapbuffer overflow occurs, checking whether heap use after free occurs, and checking whether Stackbuffer overflow occurs, and obtaining a checking result, which indicates that Heapbuffer overflow, heap use after free, or Stackbuffer overflow occurs.
[0134] S3036. Obtain tags of surrounding addresses of the address whose tag does not match.
[0135] The address where the tag does not match is the address indicated by the address description information, that is, the address where the memory problem occurs. The tags of the surrounding addresses are helpful to more accurately locate the address where the memory problem occurs.
[0136] S3037. Read the register value of the process that causes the memory problem.
[0137] All data acquired in the above steps are referred to as fault data, and by executing S304, the fault data is encapsulated into a message. It is understandable that the execution order of S3031-S3037 does not constitute a limitation.
[0138] S304, by calling the abort message callback function, the data obtained in the above steps are aggregated into a message, called abort_message.
[0139] No further details here Figure 8 The specific implementation method of each step in the process shown.
[0140] Figure 8 The process shown is conducive to obtaining comprehensive and accurate fault data and accurate fault logs.
[0141] Fig. 9 The specific process of generating fault logs for the abort message callback function includes the following steps:
[0142] S401. Assign abort_message to _libc_shared_globals()->abort_message by calling android_set_abort_message function.
[0143] S402. Assign shared_globals()->abort_message to process_info.abort_message by calling the signal callback function debugger_signal_handler, that is, process_info.abort_message = shared_globals()->abort_message.
[0144] It can be understood that the purpose of S401-S402 is to implement the transmission of parameters of abort_message.
[0145] S403. Associate abort_message with tombstone by calling dump_abort_message function.
[0146] S404. Generate a tombstone fault log written into abort_message by calling the engrave_tombstone function.
[0147] It is understandable that S401-S403 are examples of generating fault logs with the help of Android native functions and are not intended to be limiting.
[0148] Figure 5-Figure 9 The process shown, combined with Figure 4 As shown, Figure 6 , Figure 8 as well as Fig. 9 The processes shown can all be encapsulated in the memory detection library. Figure 5 The process shown is executed by the memory stepping processing service, and the memory stepping detection library can be called to implement the corresponding steps.
[0149] An embodiment of the present application further provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed on an electronic device, the electronic device executes the above method for processing the memory problem.
[0150] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for processing a memory problem, characterized in that: Applied to electronic equipment, the method comprises: Detect whether there is a memory problem and obtain the detection result; In response to the detection result indicating that the first process causes the memory problem, a fault log of the memory problem is obtained, and the first process is kept alive.
2. The method according to claim 1, characterized in that The keeping the first process alive includes: Before obtaining the fault log of the memory problem, pausing the first process; After obtaining the fault log of the memory problem, resuming the operation of the first process.
3. The method according to claim 2, characterized in that Before suspending the first process, the method further includes: It is determined that a preconfigured switch is in an on state, the on state indicating that the process causing the memory problem is not terminated.
4. The method according to claim 3, characterized in that: Also includes: determining that the preconfigured switch is in an unactivated state, the unactivated state indicating termination of the process causing the memory problem; In response to the preconfigured parameter being a first value, the fault log is generated in the process of terminating the first process.
5. The method according to any one of claims 2 to 4, characterized in that: The suspending the first process comprises: In response to a preset signal sent to the first process, the first process is suspended.
6. The method according to claim 5, characterized in that The preset signal carries a fault message, the fault message is used to generate the fault log, the fault message is generated based on pre-acquired fault data, and the fault data includes pre-collected data associated with the memory problem.
7. The method according to any one of claims 1 to 6, characterized in that: The obtaining of the fault log of the memory problem includes: By running a preset signal carrying a fault message, the fault message is passed to the first function, the fault message is used to generate the fault log, the fault message is generated based on pre-acquired fault data, and the fault data includes pre-collected data associated with the memory problem; By calling the first function, the fault message is associated with the tombstone log tombstone; By calling the second function, the fault log is generated, and the fault log includes a tombstone in which the fault message is written.
8. The method according to claim 7, characterized in that Before passing the fault message to the first function by running the preset signal carrying the fault message, the method further includes: By constructing the parameters of the preset signal, a preset signal carrying the fault message is generated.
9. The method according to claim 7 or 8, characterized in that: The fault data includes at least one of the following: The stack information and heap information during the memory access process of the first process; and Send the address and address pointer of the memory problem; as well as, the memory size occupied by the memory access type of the first process and a mismatch identifier, wherein the mismatch identifier is a basis for obtaining the detection result; and Information on a function call stack operated by the first process; as well as, Address description information, the address description information is used to indicate at least one item of the address value where the memory problem occurs and the content stored in the addresses around the address where the memory problem occurs; as well as, The fault type of the memory problem includes at least one of: heap buffer overflow, access to a released heap, and stack buffer overflow; and Identification of the addresses surrounding the address where the memory issue occurred; and, Register values of the first process.
10. The method according to any one of claims 1 to 9, characterized in that: An operating system is running in the electronic device, the operating system includes system services, and the system services include a process keep-alive switch and a memory processing service; The detecting whether there is a memory problem and obtaining the detection result includes: The memory stepping processing service detects whether there is a memory stepping problem and obtains the detection result; The keeping the first process alive includes: The memory processing service keeps the first process alive in response to the process keep-alive switch being turned on.
11. An electronic device, characterized in that: The electronic device comprises: one or more processors, a memory and a touch screen; the memory is used to store program code; the processor is used to run the program code, so that the electronic device implements the method for processing memory problems as described in any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that: Instructions are stored thereon, and when the instructions are executed on the electronic device, the electronic device executes the method for processing the memory problem as claimed in any one of claims 1 to 10.
Citation Information
Patent Citations
A method and device for eliminating influence of a fault memory on a system
CN109408273A
Memory exception processing method and device
CN111381996A
Fault processing method and device, communication equipment and storage medium
CN116302694A
Positioning method for memory stepping problem and electronic equipment
CN116450473A
Memory anomaly detection method and device, equipment and storage medium
CN116627705A
Cited By
GBase 8s database border-crossing positioning method and GBase 8s database border-crossing positioning system
CN120029859A