mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
lx_emul: support for 'alloc_pages_exact'
This commit is contained in:
parent
dc77417396
commit
c74a8c9fa8
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/version.h>
|
||||
#include <lx_emul/alloc.h>
|
||||
#include <lx_emul/debug.h>
|
||||
@ -41,11 +42,9 @@ unsigned long __alloc_pages_bulk(gfp_t gfp,int preferred_nid,
|
||||
return nr_pages;
|
||||
}
|
||||
|
||||
|
||||
void __free_pages(struct page * page, unsigned int order)
|
||||
static void lx_free_pages(struct page *page, unsigned const num_pages)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned const num_pages = (1 << order);
|
||||
void * const virt_addr = page->virtual;
|
||||
|
||||
if (atomic_read(&page->_refcount) && !atomic_dec_and_test(&page->_refcount))
|
||||
@ -59,15 +58,20 @@ void __free_pages(struct page * page, unsigned int order)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* In earlier kernel versions, '__alloc_pages' was an inline function.
|
||||
*/
|
||||
#if LINUX_VERSION_CODE > KERNEL_VERSION(5,12,0)
|
||||
struct page * __alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid,
|
||||
nodemask_t * nodemask)
|
||||
void __free_pages(struct page * page, unsigned int order)
|
||||
{
|
||||
unsigned const nr_pages = (1u << order);
|
||||
lx_free_pages(page, (1u << order));
|
||||
}
|
||||
|
||||
|
||||
void free_pages_exact(void *virt_addr, size_t size)
|
||||
{
|
||||
lx_free_pages(virt_to_page(virt_addr), PAGE_ALIGN(size) / PAGE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
static struct page * lx_alloc_pages(unsigned const nr_pages)
|
||||
{
|
||||
void const *ptr = lx_emul_mem_alloc_aligned(PAGE_SIZE*nr_pages, PAGE_SIZE);
|
||||
struct page *page = lx_emul_virt_to_pages(ptr, nr_pages);
|
||||
|
||||
@ -75,4 +79,20 @@ struct page * __alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid,
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
/*
|
||||
* In earlier kernel versions, '__alloc_pages' was an inline function.
|
||||
*/
|
||||
#if LINUX_VERSION_CODE > KERNEL_VERSION(5,12,0)
|
||||
struct page * __alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid,
|
||||
nodemask_t * nodemask)
|
||||
{
|
||||
return lx_alloc_pages(1u << order);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void *alloc_pages_exact(size_t size, gfp_t gfp_mask)
|
||||
{
|
||||
return lx_alloc_pages(PAGE_ALIGN(size) / PAGE_SIZE)->virtual;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user