A cross-memory page difference compatible operation method based on virtual hierarchical page table
By establishing a Hook function for memory allocation functions in the target system and building a virtual hierarchical page table, the problem of executable files running compatible in systems with different memory page sizes is solved, and efficient differential compatible operation across memory pages is achieved.
Patent Information
- Application Number
- CN202411813830.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2044-12-11
AI Technical Summary
The prior art is difficult to implement efficient and compatible operation of executable files in operating systems with different memory page sizes in the case of passive code, especially in the case of execution exceptions caused by different memory page sizes.
By establishing a Hook function for memory allocation functions related to address alignment in the target system, reconstructing dynamically allocated memory, and forming a virtual hierarchical page table by building virtual source memory pages or virtual page table entries, the executable file is realized in the target system. The cross-memory page difference runs compatible.
Without source code, executable files are efficiently and compatible in systems with different memory page sizes, solving the problem of execution exceptions caused by different memory page sizes.
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of computer software development, and in particular relates to a cross-memory page difference compatible operation method based on a virtual hierarchical page table. Background Art
[0002] Memory page is a mechanism used to manage memory in computer operating systems. It divides physical memory into fixed-size blocks, each of which is called a memory page. The size of a memory page depends on the design of the operating system and the hardware architecture. Common memory page sizes include 4K, 16K, 2MB, 1GB, etc. In an operating system with a memory page size of 4K, operations such as memory allocation and address mapping are performed in units of 4K; while in an operating system with a memory page size of 16K, it is performed in units of 16K. When an executable file is running, it may involve operations such as memory allocation, loading library files, and dynamic memory management, which may be affected in operating systems with different memory page sizes. Specifically, when an executable file is compiled in an operating system with a memory page size of 4K, the compiler and linker will generate code and data layout based on the assumption of 4K memory pages. For example, pointer offsets and memory alignment in the code may be set according to the granularity of 4K memory pages.
[0003] Static memory allocation refers to a method that determines the location and size of memory allocation when the program is compiled. Statically allocated memory exists during the entire running period of the program, and its life cycle is the same as the life cycle of the program. Common static memory allocation methods include: global variables and static variables, local variables on the stack, statically allocated arrays, etc. Because the operating system or runtime environment automatically handles memory allocation and release, statically allocated memory management is relatively simple.
[0004] Dynamic memory allocation refers to the process of allocating and releasing memory as needed while the program is running. Unlike static memory allocation, dynamic memory allocation does not fix the size and life cycle of memory, but allocates and recycles memory according to actual needs during program execution. This provides greater flexibility and efficiency, but also requires programmers to manually manage memory to avoid memory leaks and other memory management errors. Common functions for dynamic memory allocation are: malloc(size_t size) allocates a memory block of a specified size from the heap, calloc(size_t num, size_t size) allocates memory and initializes it to 0, realloc(void *ptr, size_t new_size) changes the size of a previously allocated memory block, and free(void *ptr) releases previously allocated memory.
[0005] However, when the executable file needs to be executed in a target operating system with a different memory page size from the operating system on which it was compiled, execution exceptions may occur due to the difference in memory page size. Usually, the best solution available is to recompile the executable file on a target operating system with a memory page size of 16K, so that the compiler and linker can be optimized according to the memory page characteristics of the target operating system to ensure that the program can fully utilize the memory management mechanism of the target operating system. However, this method requires the complete source code of the executable file, which is difficult to achieve in many cases. Summary of the invention
[0006] In view of this, the present invention provides a cross-memory page difference compatible operation method based on a virtual hierarchical page table, which realizes efficient and compatible operation of executable files in a system with memory page differences without source code.
[0007] The present invention provides a cross-memory page difference compatible operation method based on a virtual hierarchical page table, which specifically includes the following steps:
[0008] Step 1, establishing a Hook function for a memory allocation function related to address alignment in a target system, so as to reconstruct dynamically allocated memory according to a second memory page size, wherein a first memory page size of a source system is different from a second memory page size of a target system;
[0009] Step 2, loading the executable file compiled by the source system in the target system, monitoring the loading process, executing step 3 for dynamically allocated memory, executing step 4 for memory statically allocated by using a function for allocating physical memory pages, and executing step 7 for memory statically allocated by using a function related to page table entry allocation;
[0010] Step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size; execute step 8;
[0011] Step 4: If the virtual memory pool is empty, add a set number of target memory pages to the virtual memory pool, use a virtual memory page linked list to manage the virtual memory pool, the elements in the virtual memory page linked list correspond to the target memory pages one by one, divide the target memory page into M virtual source memory pages, use the target memory page start address and the allocation status representation element of the M virtual source memory pages, and execute step 5; otherwise, execute step 5;
[0012] Step 5, select a target memory page from the virtual memory pool and record it as the current target memory page, obtain the allocation status of the virtual source memory page of the current target memory page, if there is an unallocated virtual source memory page, allocate it to the executable program, and set its allocation status to allocated, and then execute step 8; otherwise, execute step 6;
[0013] Step 6: If the current target memory page is the last target memory page in the virtual memory pool, add a set number of target memory pages to the virtual memory pool, add elements corresponding to the newly added target memory pages to the virtual memory page linked list, and then execute step 5; otherwise, execute step 5;
[0014] Step 7: allocate a page table entry for the process corresponding to the executable file as the first page table entry, and record the virtual address pointed to by the first page table entry as the first virtual address; construct M virtual page table entries to form a virtual hierarchical page table, and set the virtual addresses pointed to by the M virtual page table entries to the first virtual address, the sum of the first virtual address and the first memory page size, and so on until the sum of the first virtual address and (M-1) times the first memory page size; the first page table entry serves as the parent page table entry of the M virtual page table entries, and the pointers of the M virtual page table entries are added to the first page table entry;
[0015] Step 8, the executable file completes execution, releases the dynamically allocated address, releases the target memory page in the virtual memory page linked list and the virtual memory pool for the memory statically allocated using the physical memory page allocation function, releases the page table entry to be released for the memory statically allocated using the function related to page table entry allocation, and ends this process.
[0016] Furthermore, the first memory page size is 4K.
[0017] Furthermore, the value of M is the quotient of the second memory page size and the first memory page size.
[0018] Furthermore, when the dynamically allocated memory in step 2 is memory dynamically allocated by using the mmap function, in step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size. The implementation method is as follows: if the starting address of the mapping area is not specified, the system performs a default operation, otherwise the established Hook function is used to record the specified starting address of the mapping area as the first starting address, and 2 of the first starting address is converted into the address aligned based on the second memory page size. n times as the second starting address, and replace the first starting address with the second starting address to achieve alignment based on the second memory page size; record the length of the specified mapping area as the first length, record the sum of the quotient of the first length and the second memory page size and 1 as the expansion multiple, and replace the first length with the product of the expansion multiple and the second memory page size; record the specified starting position offset as the first offset, and replace the first offset with 2 n Times as the second offset, and replacing the first offset with the second offset to achieve alignment based on the second memory page size.
[0019] Furthermore, the method of releasing the dynamically allocated address in step 8 is: using the munmap function to release the mapping area.
[0020] Furthermore, when the dynamically allocated memory in step 2 is memory dynamically allocated by using the shmat function, in step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size. The implementation method is as follows: if the connection address between the shared memory and the process address space is not specified, the system performs a default operation, otherwise the established Hook function is used, the specified connection address is recorded as the first connection address, and 2 of the first connection address is converted into n times as the second connection address, and replacing the first connection address with the second connection address to achieve alignment based on the second memory page size.
[0021] Furthermore, the method of releasing the dynamically allocated address in step 8 is: using the shmdt function to separate the shared memory segment and the process address space.
[0022] Furthermore, the method for releasing the page table entry to be released for the memory statically allocated by the function related to the page table entry allocation described in step 8 is: the page table entry to be released is recorded as the second page table entry; if the second page table entry has a parent page table entry, the virtual page table entry corresponding to the second page table entry in the parent page table entry is set to empty, and then the second page table entry is released; the parent page table entry is released when all the virtual page table entries of the parent page table entry are empty; otherwise, if all the virtual page table entries of the second page table entry are empty, the second page table entry is released; if there is a virtual page table entry that is not empty, the second page table entry is not released. Beneficial Effects
[0023] The present invention aims at dynamically allocated memory, and completes the reconstruction of dynamically allocated memory according to the second memory page size in the target system by establishing a Hook function for the memory allocation function related to address alignment; and aims at statically allocated memory, and forms a virtual hierarchical page table by constructing a virtual source memory page or a virtual page table entry, and provides the executable file with a memory page or page table entry with the same structure as the source system in the target system, and realizes the efficient and compatible operation of the executable file across the memory page difference from the source system to the target system without the source code. DETAILED DESCRIPTION
[0024] The present invention is described in detail with reference to the following embodiments.
[0025] The present invention provides a cross-memory page difference compatible operation method based on a virtual hierarchical page table, the core idea of which is: for dynamically allocated memory, a Hook function is established for a memory allocation function related to address alignment in a target system to reconstruct the dynamically allocated memory according to a second memory page size; for statically allocated memory, a virtual hierarchical page table is formed by constructing a virtual source memory page or a virtual page table entry, and a memory page or page table entry with the same structure as that of the source system is provided for an executable file in the target system, so as to realize cross-memory page difference compatible operation of the executable file from the source system to the target system.
[0026] The present invention provides a cross-memory page difference compatible operation method based on a virtual hierarchical page table, which specifically includes the following steps:
[0027] Step 1: record the operating system that has completed the compilation of the executable file as the source system, record the operating system that needs to execute the executable file as the target system, the memory page size of the target system is different from that of the source system, record the memory page of the source system as the source memory page, record the source memory page size as the first memory page size, record the memory page of the target system as the target memory page, and record the size of the target memory page as the second memory page size. Establish a Hook function for the memory allocation function related to address alignment in the target system to realize the reconstruction of dynamically allocated memory according to the second memory page size.
[0028] Specifically, the memory page size of the source system may be 4K.
[0029] Among them, the memory allocation functions related to address alignment, such as the mmap function and shmat function in the C library. The mmap function is a system call used in POSIX-compatible operating systems for memory-mapped files or devices. It is used to map files or other objects to memory to achieve efficient data exchange between files and memory. Its parameter description includes: addr, used to specify the starting address of the mapping area. If addr is NULL, the system will select a suitable address for mapping, otherwise the system will try to place the mapping area near the specified address; length, used to set the length of the mapping area, which is usually an integer multiple of the file's paging size for file mapping; prot, used to specify the protection method of the mapping area; offset, used to specify the starting position offset of the file mapping, which is usually an integer multiple of the paging size.
[0030] The shmat function is used to connect a shared memory segment to the address space of a process. Its parameter description includes: shmid, which is the identifier of the shared memory segment; shmaddr, which is used to specify the address of the shared memory connected to the process address space. If it is set to NULL, the system will automatically select a suitable address to connect the shared memory, otherwise the system will try to connect the shared memory to the specified address.
[0031] Step 2: Load the executable file in the target system, monitor the loading process, execute step 3 for memory dynamically allocated using mmap function, execute step 4 for memory dynamically allocated using shmat function, and execute step 5 for statically allocated memory.
[0032] Step 3: If the mapping area start address is not specified, the system performs the default operation. Otherwise, the established Hook function is used to record the specified mapping area start address as the first start address and set the 2 n times as the second starting address, and replace the first starting address with the second starting address to achieve alignment based on the second memory page size; record the length of the specified mapping area as the first length, record the sum of the quotient of the first length and the second memory page size and 1 as the expansion multiple, and replace the first length with the product of the expansion multiple and the second memory page size; record the specified starting position offset as the first offset, and replace the first offset with 2 n times as the second offset, and replacing the first offset with the second offset to implement alignment based on the second memory page size; executing step 10.
[0033] Step 4: If the connection address between the shared memory and the process address space is not specified, the system performs the default operation. Otherwise, the established Hook function is used to record the specified connection address as the first connection address and set the 2 ntimes as the second connection address, and replacing the first connection address with the second connection address to implement alignment based on the second memory page size; executing step 10.
[0034] Step 5: For memory statically allocated using a function for allocating physical memory pages, execute step 6; for memory statically allocated using a function related to page table entry (PTE) allocation, execute step 9.
[0035] Step 6: If the virtual memory pool is empty, add a set number of target memory pages to the virtual memory pool, and use a virtual memory page linked list to manage the virtual memory pool. The elements in the virtual memory page linked list correspond to the target memory pages one by one. Each target memory page is divided into M virtual source memory pages according to the size simulation. Each element is represented by the corresponding target memory page starting address and the allocation status of the M virtual source memory pages, and execute step 7; otherwise, execute step 7. Among them, the value of M is the quotient of the second memory page size and the first memory page size. The allocation status of the virtual source memory page includes unallocated and allocated.
[0036] The virtual memory pool is a memory pool for storing memory pages of a specific second memory page size, and the memory pages of the specific second memory page size are memory pages for simulating memory pages of the first memory page size.
[0037] Step 7. Select a target memory page from the virtual memory pool and record it as the current target memory page. Obtain the allocation status of the virtual source memory page corresponding to the current target memory page according to the virtual memory page linked list. If there is an unallocated virtual source memory page, allocate it to the executable program and set its allocation status to allocated, then execute step 10; otherwise, execute step 8.
[0038] Step 8: If the current target memory page is the last target memory page in the virtual memory pool, add a set number of target memory pages to the virtual memory pool, add elements corresponding to the newly added target memory pages to the virtual memory page linked list, and then execute step 7; otherwise, execute step 7.
[0039] Step 9, allocating a page table entry for the process corresponding to the executable file, recording the page table entry as the first page table entry, obtaining the virtual address pointed to by the first page table entry and recording it as the first virtual address; constructing M virtual page table entries to form a virtual hierarchical page table, and setting the virtual addresses pointed to by the M virtual page table entries to the first virtual address, the sum of the first virtual address and the first memory page size, ..., the sum of the first virtual address and (M-1) times the first memory page size, respectively; the first page table entry serves as the parent page table entry of the M virtual page table entries, and adding the pointers of the M virtual page table entries to the first page table entry, so that the executable file uses memory pages in the same way as the source system.
[0040] Step 10, complete the execution of the executable file in the target system, use the munmap function to release the mapped area for the memory dynamically allocated by the mmap function, use the shmdt function to separate the shared memory segment and the process address space for the memory dynamically allocated by the shmat function, release the target memory page in the virtual memory page list and the virtual memory pool for the memory statically allocated by the physical memory page allocation function, and execute step 11 for the memory statically allocated by the function related to the page table entry allocation.
[0041] Step 11, record the page table entry to be released as the second page table entry. If the second page table entry has a parent page table entry, set the virtual page table entry corresponding to the second page table entry in the parent page table entry to empty, and then release the second page table entry. When all virtual page table entries of the parent page table entry are empty, release the parent page table entry; otherwise, if all virtual page table entries of the second page table entry are empty, release the second page table entry. If there is a virtual page table entry that is not empty, do not release the second page table entry, and end this process. Example
[0042] In this embodiment, a cross-memory page difference compatible operation method based on a virtual hierarchical page table provided by the present invention is adopted to realize the compatible operation of an executable file from a source system with a memory page size of 4K to a target system with a memory page size of 16K, which specifically includes the following steps:
[0043] In this embodiment, COMPILING_OS_PAGE is the first memory page size, and RUNNING_OS_PAGE is the second memory page size.
[0044] S1. Monitor the loading of executable files compiled under the COMPILING_OS_PAGE system in the target system. For dynamically allocated memory, hook the mmap function and the shmat function in the C library, and modify the function parameters to make the parameters adapt to the COMPILING_OS_PAGE of the target system, for example, modify the 4K alignment parameters to 16K alignment.
[0045] The function prototype of mmap is: void *mmap(void *addr, size_t length, int prot, intflags, int fd, off_t offset).
[0046] The mmap function after Hook executes the following steps:
[0047] If addr is not NULL, it is converted to RUNNING_OS_PAGE alignment;
[0048] Recalculate length, length = (length / RUNNING_OS_PAGE + 1) * RUNNING_OS_PAGE;
[0049] Convert offset to RUNNING_OS_PAGE alignment.
[0050] The function prototype of shmat is: void *shmeat(int shmid, const void *shmaddr, intshmflg).
[0051] The execution steps of the shmat function after hooking are as follows: Convert shmaddr to RUNNING_OS_PAGE alignment.
[0052] S2. For statically allocated memory, the memory page allocation mechanism of the target system kernel is modified to enable the kernel to simulate and support 4K memory pages, so as to achieve compatible operation of the executable program in the target system.
[0053] S2.1. For allocations on the kernel heap, such as the code segments of the program, that is, memory pages dynamically allocated by calling __alloc_pages, the implementation of __alloc_pages is modified to simulate 4K pages based on 16K pages. The specific steps are as follows:
[0054] S2.1.1. In the kernel's __alloc_pages function, obtain the id (pid) of the current process through the current data structure. For the process compiled from the source system, execute S2.1.2. Otherwise, execute the system default processing process.
[0055] Among them, the current data structure is a macro used to obtain the task_struct pointer of the currently running process.
[0056] S2.1.2. If the virtual memory pool is recorded as pageCacheEmulated and is empty, apply for a number of 16K memory pages to be added to pageCacheEmulated; the 16K memory pages in pageCacheEmulated are managed through a virtual memory page linked list, which is recorded as statusPageCacheEmulated. Each element in statusPageCacheEmulated contains the following information: the starting address of the 16K memory page and the allocation status of four 4K memory pages.
[0057] S2.1.3. Loop through all memory pages in pageCacheEmulated, record each memory page as currentPage, and determine through the corresponding element of currentPage in statusPageCacheEmulated whether there are any unallocated free memory pages in the allocation status of the four 4K memory pages of currentPage. If so, execute S2.1.4; otherwise, execute S2.1.5.
[0058] S2.1.4. Return the free 4K memory page, and mark the allocated 4K memory page as allocated in the element corresponding to currentPage in statusPageCacheEmulated, ending the loop.
[0059] S2.1.5. If currentPage is the last page of pageCacheEmulated, apply for a certain number of 16K memory pages to add to pageCacheEmulated, and add the corresponding status element in statusPageCacheEmulated; otherwise, execute S2.1.3.
[0060] Different architectures in the Linux kernel use different multi-level page table structures to achieve the mapping of virtual memory to physical memory. Taking the common Linux system based on x86 architecture as an example, a four-level page table is generally used, including PGD, PUD, PMD and PTE. In the 16K memory page system, the memory range pointed to by the page table entries at each level is managed based on the span of 16K. The pud_alloc function is responsible for allocating the upper page table entries (Page Upper Directory), the pmd_alloc function is responsible for allocating the middle page table entries (Page Middle Directory), and the pte_alloc function is responsible for allocating the page table entries (Page Table Entry). The present invention achieves compatibility with 4K memory pages by adding a virtual hierarchical page table on the basis of the existing page table structure.
[0061] S2.2. For allocation on the kernel stack, such as the static data segment of the program that can be determined based on the attributes of the current data segment, an intermediate conversion layer is added to the `arch / x86 / mm / pgtable.c` file. This embodiment is implemented by modifying the pte_alloc or pte_free function.
[0062] The prototype of the pte_alloc function is as follows: pte_t *pte_alloc(struct mm_struct *mm, structvm_area_struct *vma, unsigned long address).
[0063] First, modify the definition of the kernel pte_t data structure and add the following two members at the end: one is a pointer of type pte_t, i.e. pte_t*, and the other is an array of 4 elements, i.e. pte_t* ar_virtual_pte [4]. Among them, pte_t* is used to save the parent page table entry of the current memory page, i.e. pte_t* parent_pte.
[0064] The execution process of the modified pte_alloc function includes:
[0065] Execute the kernel standard pte allocation operation, and remember the obtained pte_t data structure pointer as parentPTE;
[0066] Execute the subsequent standard operations of the pte_alloc function, such as virtual address allocation, etc.
[0067] Get the virtual address pointed to by pte and record it as vaddress, allocate four virtual pte_t, fill the pointers of these four virtual pte into the ar_virtual_pte array of the current pte, and set parent_pte to NULL; at the same time, get the physical address of the memory page, and add the offset to get the physical address of the four virtual pte_t, and add it to the pte data structure;
[0068] Set the virtual addresses of the four virtual pte to vaddress, vaddress+4K, vaddress+8K, and vaddress+12K respectively; and set the parent_pte of the four virtual pte to parentPTE.
[0069] The above steps can add these four virtual PTEs to the PTE list of the current process so that the executable file can actually use these virtual memory pages according to 4K.
[0070] The execution process of the modified pte_free function includes:
[0071] Determine the value of parent_pte of the pte currently to be released. If it is empty, it means that the current memory page is a 16K memory page. Then determine whether the four virtual pte in the ar_virtual_pte array are empty. If they are all empty, execute the subsequent standard process of releasing pte; otherwise, it means that there are virtual 4K memory pages in this 16K memory page that have not been released, then return directly without releasing the current memory page;
[0072] If it is not empty, it means that the current memory page is a 4K memory page. Then get the value of parent_pte, get the 16K memory page where it is located and record it as parentPTE, set the element corresponding to the current virtual pte in the ar_virtual_pte array of parentPTE to NULL, and then execute the subsequent standard process of releasing pte; determine whether the four elements in the ar_virtual_pte array of parentPTE are all empty. If they are all empty, call the pte_free function with parentPTE as the parameter to release parentPTE.
[0073] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A cross-memory page difference compatible operation method based on a virtual hierarchical page table, characterized in that: The specific steps include: Step 1, establishing a Hook function for a memory allocation function related to address alignment in a target system, so as to reconstruct dynamically allocated memory according to a second memory page size, wherein a first memory page size of a source system is different from a second memory page size of a target system; Step 2, loading the executable file compiled by the source system in the target system, monitoring the loading process, executing step 3 for dynamically allocated memory, executing step 4 for memory statically allocated by using a function for allocating physical memory pages, and executing step 7 for memory statically allocated by using a function related to page table entry allocation; Step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size; execute step 8; Step 4: If the virtual memory pool is empty, add a set number of target memory pages to the virtual memory pool, use a virtual memory page linked list to manage the virtual memory pool, the elements in the virtual memory page linked list correspond to the target memory pages one by one, divide the target memory page into M virtual source memory pages, use the target memory page start address and the allocation status representation element of the M virtual source memory pages, and execute step 5; otherwise, execute step 5; Step 5, select a target memory page from the virtual memory pool and record it as the current target memory page, obtain the allocation status of the virtual source memory page of the current target memory page, if there is an unallocated virtual source memory page, allocate it to the executable program, and set its allocation status to allocated, and then execute step 8; otherwise, execute step 6; Step 6: If the current target memory page is the last target memory page in the virtual memory pool, add a set number of target memory pages to the virtual memory pool, add elements corresponding to the newly added target memory pages to the virtual memory page linked list, and then execute step 5; otherwise, execute step 5; Step 7: allocate a page table entry for the process corresponding to the executable file as the first page table entry, and record the virtual address pointed to by the first page table entry as the first virtual address; construct M virtual page table entries to form a virtual hierarchical page table, and set the virtual addresses pointed to by the M virtual page table entries to the first virtual address, the sum of the first virtual address and the first memory page size, and so on until the sum of the first virtual address and (M-1) times the first memory page size; the first page table entry serves as the parent page table entry of the M virtual page table entries, and the pointers of the M virtual page table entries are added to the first page table entry; Step 8, the executable file completes execution, releases the dynamically allocated address, releases the target memory page in the virtual memory page linked list and the virtual memory pool for the memory statically allocated by the physical memory page allocation function, releases the page table entry to be released for the memory statically allocated by the function related to the page table entry allocation, and ends this process; The value of M is the quotient of the second memory page size and the first memory page size.
2. The cross-memory page difference compatible operation method according to claim 1, characterized in that: The first memory page size is 4K.
3. The cross-memory page difference compatible operation method according to claim 1, characterized in that: When the dynamically allocated memory in step 2 is memory dynamically allocated by using the mmap function, in step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size, and the implementation method is as follows: if the starting address of the mapping area is not specified, the system performs a default operation, otherwise the established Hook function is used, the specified starting address of the mapping area is recorded as the first starting address, and 2 of the first starting address is converted into n times as the second starting address, and replace the first starting address with the second starting address to achieve alignment based on the second memory page size; record the length of the specified mapping area as the first length, record the sum of the quotient of the first length and the second memory page size and 1 as the expansion multiple, and replace the first length with the product of the expansion multiple and the second memory page size; record the specified starting position offset as the first offset, and replace the first offset with 2 n Times as the second offset, and replacing the first offset with the second offset to achieve alignment based on the second memory page size.
4. The cross-memory page difference compatible operation method according to claim 3 is characterized in that: The method of releasing the dynamically allocated address in step 8 is: using the munmap function to release the mapping area.
5. The cross-memory page difference compatible operation method according to claim 1, characterized in that: When the dynamically allocated memory in step 2 is memory dynamically allocated by using the shmat function, in step 3, if the address is not specified, the system performs a default operation, otherwise the established Hook function is used to convert the specified address into an address aligned based on the second memory page size. The implementation method is as follows: if the connection address between the shared memory and the process address space is not specified, the system performs a default operation, otherwise the established Hook function is used, the specified connection address is recorded as the first connection address, and 2 of the first connection address is converted into n times as the second connection address, and replacing the first connection address with the second connection address to achieve alignment based on the second memory page size.
6. The cross-memory page difference compatible operation method according to claim 5, characterized in that: The method of releasing the dynamically allocated address in step 8 is: using the shmdt function to separate the shared memory segment and the process address space.
7. The cross-memory page difference compatible operation method according to claim 1, characterized in that: The method of releasing the page table entry to be released for the memory statically allocated by the function related to the page table entry allocation described in step 8 is: the page table entry to be released is recorded as the second page table entry; if the second page table entry has a parent page table entry, the virtual page table entry corresponding to the second page table entry in the parent page table entry is set to empty, and then the second page table entry is released; the parent page table entry is released when all the virtual page table entries of the parent page table entry are empty; otherwise, if all the virtual page table entries of the second page table entry are empty, the second page table entry is released, and if there is a virtual page table entry that is not empty, the second page table entry is not released.
Citation Information
Patent Citations
Memory defect positioning method based on extended address identification
CN118585456A