A method and device for detecting and locating wild pointers

By creating a field pointer information table and resolving the mapping between virtual memory and physical memory, detecting and positioning field pointers in the operating system, the problem of difficulty in detecting and positioning field pointers in the prior art is solved, and the rapid detection and analysis effect is achieved without modifying the code.

CN114385495BActive Publication Date: 2025-07-01FIBERHOME TELECOMMUNICATION TECHNOLOGIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210004629.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-04
Publication Date
2025-07-01
Estimated Expiration
2042-01-04

AI Technical Summary

Technical Problem

The prior art is difficult to detect and locate field pointers in operating systems, resulting in program crashes and data exceptions, and it is difficult to quickly locate and resolve such problems during the software development and maintenance stage.

Method used

By creating and initializing the field pointer information table, the mapping relationship between virtual memory and physical memory is removed, and a tag for prohibiting page mapping is set on the virtual memory page. If you access the virtual memory page that is not mapped to physical memory, it is determined whether it exists in the field pointer information table and has a prohibited page mapping mark to determine whether there is a field pointer, and locate and process it through the address corresponding to the virtual memory page.

Benefits of technology

Without modifying the software code, the detection and rapid positioning of the field pointer in the operating system can be realized, the exception handling program is executed in a timely manner, and the operation problems of the field pointer are quickly detected and analyzed, which is convenient for the positioning and analysis of the problem.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114385495B_ABST
    Figure CN114385495B_ABST
Patent Text Reader

Abstract

The invention discloses a method and device for detecting and locating a wild pointer, the method comprising: creating and initializing a wild pointer information table; after releasing the memory, cancelling the mapping relationship between the virtual memory and the physical memory, setting a mark for prohibiting page mapping on the virtual memory page attribute whose mapping relationship has been canceled; storing a virtual memory page with a mark for prohibiting page mapping and a virtual memory address corresponding to the virtual memory page in the wild pointer information table; if a virtual memory page not mapped to the physical memory is accessed, the virtual memory address of the virtual memory page exists in the wild pointer information table and the virtual memory page attribute accessed by the user has a mark for prohibiting page mapping, then a wild pointer exists, and the wild pointer is located and processed through the virtual memory address corresponding to the virtual memory page. Without modifying the software code, the detection of whether there is a wild pointer in the operating system and the rapid location of the wild pointer are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of network communication, and more specifically, relates to a method and device for detecting and locating wild pointers. Background Art

[0002] As an important basic resource of the operating system, during the operation of a program, the application and release of memory are essential processes. The memory applied by users in the operating system is mainly divided into heap memory and stack memory. Heap memory is mainly dynamically allocated memory, and stack memory is mainly the memory used by local variables or registers on the thread stack. For example, memory is applied to the operating system through malloc / ap, and memory is released to the operating system through free / munmap. This process belongs to the application and release process of heap memory, and this patent mainly relates to this process.

[0003] With the development of technology, software operating systems are becoming increasingly large, and operations such as memory application, operation, and release are also becoming increasingly complex. The normal memory operation process is memory application - memory reading and writing - memory release. When a user, due to the program execution sequence, continues to read and write memory after memory release, wild pointers will occur. The situation of wild pointers may bring catastrophic problems to the program, resulting in inconsistent user data, program crashes due to accessing illegal pointers, etc. Such problems are often highly concealed. Due to the large amount of software code and complex processes nowadays, it is very difficult to find problems simply by reading the code line by line.

[0004] Among the currently used memory detection tools, Asan (Addresssanitizer) is a very efficient memory detection tool that can detect memory problems such as heap memory out-of-bounds, stack out-of-bounds, and wild pointers. It mainly compares the memory accessed by the user with the shadow memory. If the attributes of the accessed memory and the shadow memory are the same, it continues; otherwise, an exception is thrown. The Asan detection method cannot detect, for example, when user A applies for memory, then user A releases the memory address, and then the memory is applied by user B, and then user A uses the already released address again. In this case, Asan cannot detect that user A has a wild pointer situation. (Wild pointer: Continuing to read and write memory due to program flow reasons after memory release)

[0005] Because the application process will release the memory after operating it, if the application process continues to operate the memory after releasing it, wild pointers will appear in the operating system, causing data anomalies for other users or the operating system to crash. It will be difficult to locate the wild pointers after the operating system crashes. Moreover, in the later stage of software development or the software maintenance stage, it will be time-consuming and laborious to locate and solve the wild pointer problem in the operating system. How to quickly locate such causes without modifying the software code has become a problem that needs to be solved urgently.

[0006] In view of this, overcoming the defects of the prior art is an urgent problem to be solved in the field of this technology. Summary of the invention

[0007] In view of the above defects or improvement needs of the prior art, the present invention provides a method and device for detecting and locating wild pointers, the purpose of which is to determine whether there are wild pointers in the operating system and to locate and process the wild pointers, thereby solving the technical problem of wild pointers occurring in the operating system.

[0008] To achieve the above object, according to one aspect of the present invention, a method for detecting and locating a wild pointer is provided, the method comprising:

[0009] Create and initialize the wild pointer information table;

[0010] After releasing the memory, the mapping relationship between the virtual memory and the physical memory is released, and a page mapping prohibition mark is set on the virtual memory page attribute whose mapping relationship has been released;

[0011] The wild pointer information table stores the virtual memory page with a prohibited page mapping mark and the virtual memory address corresponding to the virtual memory page;

[0012] If a virtual memory page that is not mapped to physical memory is accessed, the virtual memory address of the virtual memory page exists in the wild pointer information table and the attribute of the virtual memory page accessed by the user is marked with a mark prohibiting page mapping, then a wild pointer exists, and the wild pointer is located and processed through the virtual memory address corresponding to the virtual memory page.

[0013] Preferably, the method of creating and initializing the wild pointer information table includes:

[0014] Creating a TCB control block, creating a wild pointer information table in the TCB control block, wherein the wild pointer information table includes one or more of a virtual memory address, a virtual memory address length, and a virtual memory page attribute;

[0015] After the wild pointer information table is created, the wild pointer information table is initialized.

[0016] Preferably, after the memory is released, the mapping relationship between the virtual memory and the physical memory is released. The specific process includes:

[0017] When releasing the memory, the operating system calls the memory release interface to release the memory, and the operating system switches from the user-mode address space to the kernel-mode address space;

[0018] The operating system releases the mapping relationship between the virtual memory and the physical memory in the kernel-mode address space. The physical memory is released to the operating system, and the virtual memory remains in the process space.

[0019] Preferably, the virtual memory page with the prohibited page mapping flag and the virtual memory address corresponding to the virtual memory page are stored in the wild pointer information table. The specific method includes:

[0020] Save the virtual memory address and the virtual memory address length of the virtual memory page in the wild pointer information table;

[0021] In the wild pointer information table, set the attribute of the virtual memory page that has been unmapped from the physical memory to prohibit the page from being mapped to the physical memory.

[0022] Preferably, the method for determining whether there is a wild pointer when accessing a virtual memory page that is not mapped to physical memory includes:

[0023] Determine whether the accessed virtual memory address already exists in the wild pointer information table;

[0024] If the virtual memory address does not exist in the wild pointer information table, it is determined as a normal operation process;

[0025] If the virtual memory address exists in the wild pointer information table, determine whether the attribute of the virtual memory page accessed by the user has a flag prohibiting the page from being mapped to the physical memory;

[0026] If the attribute of the virtual memory page accessed by the user does not have a flag prohibiting the page from being mapped to the physical memory, it is determined as a normal operation process;

[0027] If the attribute of the virtual memory page accessed by the user has a flag prohibiting the page from being mapped to the physical memory, it is determined that there is a wild pointer, and the function stack information of the obtained wild pointer is recorded in the crash log.

[0028] Preferably, the method for determining whether there is a wild pointer when accessing a virtual memory page that is not mapped to physical memory further includes:

[0029] If the virtual memory page accessed by the user has no mapping relationship with the physical memory and the virtual memory address does not exist in the wild pointer information table, it is determined as a normal operation process.

[0030] Preferably, the method of recording the function stack information of the obtained wild pointer into the crash log specifically includes:

[0031] The function stack information of the wild pointer includes: the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer;

[0032] In the crash log, the function stack information of the wild pointer is used as a thread, and the thread is named with a set name. Under the thread, the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer are recorded.

[0033] Preferably, the method of positioning and processing the wild pointer through the virtual memory address corresponding to the virtual memory page specifically includes:

[0034] The user applies to the operating system for a signal. After it is determined that there is a wild pointer, the operating system sends the signal to the application process and attaches the register information of the application process;

[0035] The application process locates the wild pointer according to the corresponding virtual memory address in the wild pointer information table;

[0036] Through the register information of the application process, the application process obtains the data information of the wild pointer and sends it to the engineer for processing.

[0037] Preferably, the method further includes:

[0038] If the virtual memory page accessed by the user has a mapping relationship with the physical memory, it is determined as a normal operation process.

[0039] According to another aspect of the present invention, there is provided a device for detecting and positioning wild pointers, the device includes:

[0040] At least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are set by the processor to execute the method for detecting and positioning wild pointers according to the first aspect.

[0041] In a third aspect, the present invention further provides a non-volatile computer storage medium, the computer storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors to complete the method for detecting and positioning wild pointers according to the first aspect.

[0042] Generally speaking, compared with the prior art, the above technical solution conceived by the present invention has the following beneficial effects:

[0043] A method and device for detecting and locating wild pointers provided by the present invention can detect whether there are wild pointers in the operating system and quickly locate the positions where wild pointers appear without modifying the software code. When it is found that there are wild pointers in the application process, the exception handling program can be executed in time, so as to quickly detect the operation problems of wild pointers in the application process and facilitate the location and analysis of wild pointers. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 is a flowchart of the method for detecting and locating wild pointers in the first embodiment;

[0045] Figure 2 is a diagram of the original user memory operation framework in the prior art;

[0046] Figure 3 is a diagram of the memory operation framework for detecting and locating wild pointers in the first embodiment;

[0047] Figure 4 is a specific flowchart of the process for detecting wild pointers in the first embodiment;

[0048] Figure 5 is a schematic diagram of the device for detecting and locating wild pointers in the second embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0050] In the description of the present invention, the orientation or positional relationship indicated by terms such as "inner", "outer", "longitudinal", "transverse", "upper", "lower", "top", "bottom", etc. is based on the orientation or positional relationship shown in the drawings, and is only for the convenience of describing the present invention rather than requiring the present invention to be constructed and operated in a specific orientation. Therefore, it should not be construed as a limitation of the present invention.

[0051] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may include that the first and second features are in direct contact, or may include that the first and second features are not in direct contact but are in contact through another feature between them. Moreover, a first feature being "above", "above" and "above" a second feature includes that the first feature is directly above and obliquely above the second feature, or simply indicates that the first feature is higher in level than the second feature. A first feature being "below", "below" and "below" a second feature includes that the first feature is directly below and obliquely below the second feature, or simply indicates that the first feature is lower in level than the second feature.

[0052] Embodiment 1:

[0053] like Figure 2 The figure shows the original operating system memory management operation framework diagram. It can be seen from the framework diagram that the operating system treats all users' memory operations equally. As long as the virtual memory resides in the application process, any user of the same process can operate the memory. If the virtual memory has been released to the operating system, the operating system will report a signal of accessing an illegal address.

[0054] The first embodiment of the present invention provides a wild pointer detection and positioning method. After the user releases the memory, the mapping relationship between the virtual memory and the physical memory is released. The virtual address still resides in the application process, and the secondary mapping of the virtual memory and the physical memory is prohibited. If the user continues to access the virtual memory after releasing the memory, an abnormal signal will be triggered and the application process will be notified.

[0055] In this embodiment 1, the method includes the following steps: Figure 1 As shown:

[0056] S101: Create and initialize a wild pointer information table.

[0057] In the first embodiment, the overall (TASK CONTROLBLOCK, abbreviated as: TCB) control block of the computer protection device is created during the process initialization phase. When the operating system creates a process, it will create a TCB control block for each process to save information such as private resources of each process. When the process creates the TCB control block, a wild pointer information table is created in the TCB control block. The wild pointer information table includes information such as virtual memory address, address length, and virtual memory page attributes. After the wild pointer information table is created, the wild pointer information table is initialized.

[0058] S102: canceling the mapping relationship between the virtual memory and the physical memory, and setting a page mapping prohibition mark on the virtual memory page attribute whose mapping relationship has been canceled.

[0059] In the first embodiment, the application process calls the memory release interface provided in the initialization phase to release memory, enters the process memory release phase, and the user state address space switches to the kernel state address space.

[0060] After the mapping relationship between the virtual memory address and the physical memory address is released, the virtual memory still resides in the process address space, and the physical memory is released to the operating system.

[0061] S103: The virtual memory page with the prohibited page mapping mark and the virtual memory address corresponding to the virtual memory page attribute are stored in the wild pointer information table.

[0062] In the first embodiment, the virtual memory address and the length of the virtual memory address are stored in the wild pointer information table in the TCB control block. The attribute of the virtual memory is set in the wild pointer information table to prohibit re-mapping of the physical memory.

[0063] S104: If a virtual memory page not mapped to physical memory is accessed, it is determined whether the virtual memory address of the virtual memory page exists in the wild pointer information table and whether there is a wild pointer according to the attributes of the virtual memory page accessed by the user.

[0064] In the first embodiment, the user accesses a virtual memory page that is not mapped to the physical memory in the following situations:

[0065] 1. The user accesses the virtual memory page for the first time;

[0066] 2. Access a virtual memory page with a prohibited mapping.

[0067] The conditions for determining the existence of wild pointers are: there is no mapping relationship between the virtual memory page accessed by the user and the physical memory, the virtual memory address of the virtual memory page exists in the wild pointer information table, and the attribute of the virtual memory page accessed by the user is marked with page mapping prohibited. Only when all three conditions are met can it be determined that the operating system has a wild pointer.

[0068] If the user accesses a non-existent virtual memory page, the operating system throws an exception signal; if the user accesses unmapped virtual memory for the first time, the operating system performs virtual mapping and the user process can access the memory normally; if the user accesses a virtual memory page with prohibited mapping, the judgment process will be triggered and an exception will be returned.

[0069] S105: If the virtual memory address of the virtual memory page exists in the wild pointer information table and the attribute of the virtual memory page accessed by the user has a mark prohibiting page mapping, then a wild pointer exists, and the wild pointer is located and processed through the virtual memory address corresponding to the virtual memory page.

[0070] In the first embodiment, the Linux operating system is selected, and the Linux operating system runs in protected mode, and manages physical memory through virtual memory. If it is detected that the application process is accessing a released memory page, that is, there is a wild pointer in the operating system, the information of the wild pointer needs to be transmitted to the application process in the form of a signal. When the wild pointer signal is sent to the application process, the register information of the current process and the virtual memory address corresponding to the wild pointer in the wild pointer information table are attached. Through the register information of the process, the application process obtains the running context information of the wild pointer and the calling relationship of the function, etc., and the judgment process ends.

[0071] like Figure 3 As shown, it is a memory management operation framework diagram of the operating system in the first embodiment. The first embodiment realizes the detection of whether there are wild pointers in the operating system and quickly locates the position where the wild pointers appear without modifying the software code. When the existence of wild pointers is found in the application process, the exception handling program can be executed in time, so as to quickly detect the operation problems of wild pointers in the application process and facilitate the location analysis of the problem.

[0072] In the first embodiment, in order to save wild pointer information without modifying the overall (Trusted Computing Base, TCB for short) control structure of the protection device in the computer, there is also a preferred implementation scheme in combination with the embodiment of the present invention. Specifically, the wild pointer information table is created and initialized. The specific method includes:

[0073] A TCB control block is created, and a wild pointer information table is created in the TCB control block, wherein the wild pointer information table includes one or more of a virtual memory address, a virtual memory address length, and a virtual memory page attribute.

[0074] After the wild pointer information table is created, the wild pointer information table is initialized.

[0075] The wild pointer information table is created by adding a field, and the wild pointer information table is used to store the related information of the wild pointer. The virtual memory address length includes the length of the virtual memory address, and the range of the virtual memory address is determined according to the virtual memory address length.

[0076] In the first embodiment, in order to allow the user to operate the physical memory of the application process, in combination with the embodiment of the present invention, there is also a preferred implementation scheme. Specifically, after the memory is released, the mapping relationship between the virtual memory of the application process and the physical memory is released. The specific process includes:

[0077] First, the user calls the memory application interface, and the operating system completes the normal memory application according to the user request, thereby completing the memory application operation.

[0078] When releasing memory, the operating system calls the memory release interface to release the memory, and the operating system switches from the user state address space to the kernel state address space.

[0079] Applications can only run in user state, and the memory space is the user state memory space. The kernel can only run in kernel state space. The address space of user state and kernel state is different, so the operating system needs to automatically switch from user state address space to kernel state address space.

[0080] The operating system unmaps the virtual memory and the physical memory in the kernel address space, releases the physical memory to the operating system, and leaves the virtual memory in the process space. The user applies for a virtual address, which is first mapped to the physical memory, and then the mapping relationship between the application process virtual memory and the physical memory is unmapped, so that the user can directly operate the physical memory.

[0081] In the first embodiment, in order to avoid the situation that the application process is accessing a memory page that has been released by the user, there is also a preferred implementation scheme in combination with the embodiment of the present invention. Specifically, the virtual memory page with a prohibited page mapping mark and the virtual memory address corresponding to the virtual memory page are stored in the wild pointer information table. The specific method includes:

[0082] The virtual memory address and the virtual memory address length of the virtual memory page are stored in the wild pointer information table.

[0083] In the wild pointer information table, the attribute of the virtual memory page whose mapping relationship with the physical memory has been released is set to prohibit the page from being mapped with the physical memory.

[0084] The virtual memory page attributes are modified in the wild pointer information table, and the attributes of the virtual memory pages that have been unmapped from the physical memory are changed to prohibit the page from being mapped from the physical memory. The attributes of the virtual memory pages that have not been unmapped from the physical memory are not changed.

[0085] In the wild pointer information table, page attributes can quickly manage virtual pages without querying the information table. Relying on the virtual page table attributes, you can know whether the virtual page is allowed to map physical memory. If it is only managed through the wild pointer information table, the wild pointer information table must be queried for each virtual memory address, which is inefficient.

[0086] In the first embodiment, in order to determine whether there is a wild pointer in the operating system, in combination with the embodiment of the present invention, there is also a preferred implementation scheme. Specifically, if a virtual memory page that is not mapped to the physical memory is accessed, it is determined whether the virtual memory address of the virtual memory page exists in the wild pointer information table and whether there is a wild pointer according to the attributes of the virtual memory page accessed by the user, such asFigure 4 As shown, the judgment method includes the following steps:

[0087] S400: Trigger the judgment process.

[0088] If a virtual memory page that is not mapped to physical memory is accessed, the trigger signal directly proceeds to the judgment process without interrupt warning.

[0089] S401: Judge whether the virtual memory address of the virtual memory page accessed by the user already exists in the wild pointer information table.

[0090] Check whether the virtual memory address of the virtual memory page accessed by the user exists in the wild pointer information table. If it does not exist, execute S402; if it exists, execute S403.

[0091] Check the virtual memory page of the user access page and the wild pointer information table in the TCB control block. Since the wild pointer information table contains the start address and length of the virtual memory address, it is possible to determine whether the accessed virtual memory page is within the address range in the wild pointer information table, and check whether the virtual memory address attribute has a mark prohibiting the page from being mapped to physical memory.

[0092] S402: If the virtual memory address does not exist in the wild pointer information table, it is judged as a normal operation process, and S407 is executed.

[0093] Enter the segment fault process, send a signal to the application process, and the judgment process ends.

[0094] The segment fault process, that is, the 11th signal process of the operating system. If an exception occurs during the operation of the CPU, the operating system passes the exception signal to the user.

[0095] S403: If the virtual memory address exists in the wild pointer information table, judge whether the virtual memory page attribute accessed by the user has a mark prohibiting the page from being mapped to physical memory.

[0096] If the virtual memory page attribute accessed by the user has a mark prohibiting the page from being mapped to physical memory, execute S404; if the virtual memory page attribute accessed by the user does not have a mark prohibiting the page from being mapped to physical memory, execute S405.

[0097] S404: If the virtual memory page attribute accessed by the user does not have a mark prohibiting the page from being mapped to physical memory, it is judged as a normal operation process, and S407 is executed.

[0098] Enter the normal address mapping process, map the virtual memory and physical memory pages, and the judgment process ends.

[0099] S405: If the virtual memory page property accessed by the user has a flag prohibiting the mapping between the page and physical memory, execute S406.

[0100] S406: Determine whether there is a wild pointer, send a signal to the application process, record the stack information of the function of the obtained wild pointer in the crash log, and execute S407.

[0101] S407: Determine that the process ends.

[0102] If it is detected that the application process is accessing a memory page that has been released, that is, there is a wild pointer in the operating system, it is necessary to pass the information of the wild pointer to the application process in the form of a signal. When sending a wild pointer signal to the application process, the register information of the current process and the virtual memory address corresponding to the wild pointer in the wild pointer information table are attached. Through the register information of the process, the application process can obtain the running context information of the wild pointer and the call relationship of the function, etc., and determine that the process ends.

[0103] To avoid misjudging the situation of a wild pointer, in combination with the embodiments of the present invention, there is also a preferred implementation scheme. Specifically, if a virtual memory page not mapped to physical memory is accessed, the method for determining whether there is a wild pointer further includes:

[0104] If there is no mapping relationship between the virtual memory page accessed by the user and physical memory, and the virtual memory address does not exist in the wild pointer information table, it is determined as a normal operation process.

[0105] For example: User A applies for memory, and the operating system will return a virtual memory address to A. What A gets is a virtual address. When User A accesses the memory again, when there is a mapping relationship between the virtual memory and physical memory in the operating system, it will first check the wild pointer information table. When A's virtual memory address is not in the wild pointer information table, it is determined as a normal operation process, and a mapping relationship is established between the virtual memory and physical memory.

[0106] In the first embodiment of the present invention, in order to record the problem of the existing wild pointer, in combination with the embodiments of the present invention, there is also a preferred implementation scheme. Specifically, the method of recording the stack information of the function of the obtained wild pointer in the crash log specifically includes:

[0107] The stack information of the function of the wild pointer includes: the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer;

[0108] In the crash log, take the stack information of the function of the wild pointer as a thread, name the thread with a set name, and record the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer under the thread.

[0109] Since the crash log of the application process records all stack information during the application's operation, it is possible to clearly know the working code situation when a wild pointer occurs through the crash log, which is convenient for the staff to search. The thread of the function stack information of the wild pointer inserted in the crash log can be named so that the staff can find the function stack information of the wild pointer from the crash log.

[0110] In the first embodiment of the present invention, in order to solve the problem of locating the wild pointer and dealing with the wild pointer, in combination with the embodiments of the present invention, there is also a preferred implementation solution. Specifically, it is determined that there is a wild pointer, and the wild pointer is located and processed according to the corresponding virtual memory address in the wild pointer information table. The specific method includes:

[0111] The user applies to the operating system for a signal. After it is determined that there is a wild pointer, the operating system sends the signal to the application process and attaches the register information of the application process.

[0112] The application process locates the wild pointer according to the corresponding virtual memory address in the wild pointer information table.

[0113] Through the register information of the application process, the application process obtains the data information of the wild pointer and sends it to the engineer for processing.

[0114] The occurrence of a wild pointer is a pc pointer or a function. However, for the user, a certain function may be called in many places. It is necessary to find the specific call process. According to the register information carried in the signal capturing the wild pointer, the pc pointer, stack information, function call stack, etc. at the moment when the wild pointer appears can be obtained. This is convenient for the engineer to coordinate and solve the problems caused by the occurrence of the wild pointer.

[0115] In the first embodiment of the present invention, in order to avoid triggering the judgment process, in combination with the embodiments of the present invention, there is also a preferred implementation solution. Specifically, it is determined whether the virtual memory address of the virtual memory page exists in the wild pointer information table and whether there is a wild pointer according to the virtual memory page attribute accessed by the user. The judgment method further includes:

[0116] If the virtual memory page accessed by the user has a mapping relationship with the physical memory, it is judged as a normal operation process.

[0117] For example: User A applies for a piece of memory. When applying for memory for the first time, memory mapping is not performed. What User A gets is only a virtual address. When User A accesses the virtual memory page under the virtual address again, a mapping relationship is established between the virtual memory page and the physical memory.

[0118] Embodiment 2:

[0119] Embodiment 2 provides a wild pointer detection and positioning device, which includes:

[0120] At least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are programmed to execute any one of the wild pointer detection and positioning methods in Embodiment 1.

[0121] As Figure 5 shown, it is a schematic diagram of the wild pointer detection and positioning device according to an embodiment of the present invention. The wild pointer detection and positioning device of this embodiment includes one or more processors 21 and a memory 22. Among them, Figure 5 One processor 21 is taken as an example.

[0122] The processor 21 and the memory 22 can be connected by a bus or other means, Figure 5 Taking the connection by bus as an example.

[0123] The memory 22, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs and non-volatile computer-executable programs, such as the wild pointer detection and positioning method in Embodiment 1. The processor 21 executes the wild pointer detection and positioning method by running the non-volatile software programs and instructions stored in the memory 22.

[0124] The memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 22 may optionally include a memory remotely provided with respect to the processor 21, and these remote memories can be connected to the processor 21 through a network. Examples of the above networks include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0125] The program instructions / modules are stored in the memory 22, and when executed by the one or more processors 21, execute the wild pointer detection and positioning method in the above Embodiment 1. For example, execute each step described above Figure 1 shown.

[0126] It should be noted that the content such as information interaction and execution process between modules and units in the above device and system, due to being based on the same concept as the method embodiment of the present invention, the specific content can be referred to the description in the method embodiment of the present invention, and will not be elaborated here.

[0127] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the embodiments can be completed by instructing relevant hardware through a program, and the program can be stored in a computer-readable storage medium. The storage medium can include: read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical discs, etc.

[0128] Those skilled in the art can easily understand that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for detecting and locating wild pointers, characterized in that the method include: Create and initialize the wild pointer information table; When the operating system creates a process, it creates a TCB control block for each process. When the process creates a TCB control block, it creates a wild pointer information table in the TCB control block. After releasing the memory, the mapping relationship between the virtual memory and the physical memory is released, and a mark prohibiting page mapping is set on the attribute of the virtual memory page whose mapping relationship has been released; When releasing memory, the operating system calls a memory release interface to release the memory, and the operating system switches from the user state address space to the kernel state address space; The operating system releases the mapping relationship between the virtual memory and the physical memory in the kernel state address space, the physical memory is released to the operating system, and the virtual memory remains in the process space; As long as the virtual memory resides in the application process, any user of the same process can operate the memory; The wild pointer information table stores a virtual memory page with a prohibited page mapping mark and a virtual memory address corresponding to the virtual memory page; If a virtual memory page that is not mapped to physical memory is accessed, and the virtual memory address of the virtual memory page exists in the wild pointer information table and the attribute of the virtual memory page accessed by the user has a mark that prohibits page mapping, then a wild pointer exists, and the wild pointer is located and processed through the virtual memory address corresponding to the virtual memory page; If the user accesses unmapped virtual memory for the first time, the operating system performs virtual mapping and the user process accesses the memory normally.

2. The method for detecting and locating wild pointers according to claim 1, characterized in that, The specific method of creating and initializing the wild pointer information table includes: Creating a TCB control block, creating a wild pointer information table in the TCB control block, wherein the wild pointer information table includes one or more of a virtual memory address, a virtual memory address length, and a virtual memory page attribute; After the wild pointer information table is created, the wild pointer information table is initialized.

3. The method for detecting and locating wild pointers according to claim 1, wherein, The wild pointer information table stores the virtual memory page with a prohibited page mapping mark and the virtual memory address corresponding to the virtual memory page, and the specific method includes: The virtual memory address and the virtual memory address length of the virtual memory page are stored in the wild pointer information table; In the wild pointer information table, the attribute of the virtual memory page whose mapping relationship with the physical memory has been released is set to prohibit the page from being mapped with the physical memory.

4. The method for detecting and locating a wild pointer according to claim 1, characterized in that, If a virtual memory page that is not mapped to physical memory is accessed, the method for determining whether there is a wild pointer includes: Determine whether the accessed virtual memory address already exists in the wild pointer information table; If the virtual memory address does not exist in the wild pointer information table, it is determined to be a normal operation process; If the virtual memory address exists in the wild pointer information table, determining whether the attribute of the virtual memory page accessed by the user carries a mark for prohibiting the page from being mapped to the physical memory; If the attribute of the virtual memory page accessed by the user does not have a mark prohibiting the page from being mapped to the physical memory, it is determined to be a normal operation process; If the virtual memory page property accessed by the user has a flag prohibiting the mapping between the page and physical memory, it is determined that there is a wild pointer, and the function stack information of the obtained wild pointer is recorded in the crash log.

5. The method for detecting and locating wild pointers according to claim 4, wherein If a virtual memory page that is not mapped to physical memory is accessed, the method for determining whether there is a wild pointer further includes: If there is no mapping relationship between the virtual memory page accessed by the user and physical memory, and the virtual memory address does not exist in the wild pointer information table, it is determined as a normal operation process.

6. The method for detecting and locating a wild pointer according to claim 4, wherein The method for recording the function stack information of the obtained wild pointer in the crash log specifically includes: The function stack information of the wild pointer includes: the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer; In the crash log, the function stack information of the wild pointer is used as a thread, and the thread is named with a set name. Under the thread, the stack information of the memory allocation function and the stack information of the memory release function of the memory area pointed to by the wild pointer are recorded.

7. The method for detecting and locating wild pointers according to claim 6, characterized in that, The method for locating and processing the wild pointer through the virtual memory address corresponding to the virtual memory page specifically includes: The user applies to the operating system for a signal. After it is determined that there is a wild pointer, the operating system sends the signal to the application process and attaches the register information of the application process; The application process locates the wild pointer according to the corresponding virtual memory address in the wild pointer information table; Through the register information of the application process, the application process obtains the data information of the wild pointer and sends it to the engineer for processing.

8. The method for detecting and locating a wild pointer according to claim 1, wherein The method further includes: If there is a mapping relationship between the virtual memory page accessed by the user and physical memory, it is determined as a normal operation process.

9. A detection and positioning device for wild pointers, characterized in that, The device includes: At least one processor; And a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are set by the processor to execute the method for detecting and locating the wild pointer according to any one of claims 1-8.

Citation Information

Patent Citations

  • Function stack information determining method and apparatus of wild pointer, and electronic device

    CN106557300A

  • Internal memory distributing method

    CN1673979A