Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, I found that similar function is implemented in <code>KSplice</code> project and here is it:</p> <pre><code>/* * map_writable creates a shadow page mapping of the range * [addr, addr + len) so that we can write to code mapped read-only. * * It is similar to a generalized version of x86's text_poke. But * because one cannot use vmalloc/vfree() inside stop_machine, we use * map_writable to map the pages before stop_machine, then use the * mapping inside stop_machine, and unmap the pages afterwards. */ static void *map_writable(void *addr, size_t len) { void *vaddr; int nr_pages = DIV_ROUND_UP(offset_in_page(addr) + len, PAGE_SIZE); struct page **pages = kmalloc(nr_pages * sizeof(*pages), GFP_KERNEL); void *page_addr = (void *)((unsigned long)addr &amp; PAGE_MASK); int i; if (pages == NULL) return NULL; for (i = 0; i &lt; nr_pages; i++) { if (__module_address((unsigned long)page_addr) == NULL) { #if LINUX_VERSION_CODE &gt;= KERNEL_VERSION(2,6,22) || !defined(CONFIG_X86_64) pages[i] = virt_to_page(page_addr); #else /* LINUX_VERSION_CODE &lt; &amp;&amp; CONFIG_X86_64 */ /* e3ebadd95cb621e2c7436f3d3646447ac9d5c16d was after 2.6.21 * This works around a broken virt_to_page() from the RHEL 5 backport * of x86-64 relocatable kernel support. */ pages[i] = pfn_to_page(__pa_symbol(page_addr) &gt;&gt; PAGE_SHIFT); #endif /* LINUX_VERSION_CODE || !CONFIG_X86_64 */ WARN_ON(!PageReserved(pages[i])); } else { pages[i] = vmalloc_to_page(addr); } if (pages[i] == NULL) { kfree(pages); return NULL; } page_addr += PAGE_SIZE; } vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); kfree(pages); if (vaddr == NULL) return NULL; return vaddr + offset_in_page(addr); } </code></pre> <p>So, as it comes there is a different handling of kernel's and module's memory. If the page is not belongs to any module then <code>vmalloc_to_page</code> rather then <code>virt_to_phys</code> used. I'll check if it helps and post the result later.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload