* [KERNEL 2.4 or 2.5] New source for allocation anonymous memory+paging demand
@ 2002-10-15 22:32 Breno
0 siblings, 0 replies; only message in thread
From: Breno @ 2002-10-15 22:32 UTC (permalink / raw)
To: Kernel List
[-- Attachment #1: Type: text/plain, Size: 303 bytes --]
Hi people
I developed a module for allocation of anonymous memory, I believe that it
is util. it follows attached module+header
the use is sufficiently simple:
..... to char * map; map = (to char *)build_vma(100); ....
What do you think ? it´s possible to enter in kernel 2.4 or 2.5 ?
Breno
[-- Attachment #2: vm.c --]
[-- Type: application/octet-stream, Size: 2530 bytes --]
/*by Breno S. Pinto*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/highmem.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#include <asm/errno.h>
#include <asm/mman.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/processor.h>
#define NUM_mysyscallmem 230
extern void *sys_call_table[];
asmlinkage unsigned long (*original_call) (int numero,unsigned long address);
asmlinkage unsigned long my_syscallmem(int numero,unsigned long address);
struct page *my_teste_page_alloc_mem(struct vm_area_struct *vma,unsigned long address,int unused)
{
struct page *page;
page = alloc_page(GFP_USER);
if(!page) {
printk("<2>Can not alloc new page\n");
return NOPAGE_OOM;
}
return page;
}
struct vm_operations_struct my_vm_operation = {
nopage: my_teste_page_alloc_mem,
};
asmlinkage unsigned long my_syscallmem(int numero,unsigned long address)
{
unsigned long end;
unsigned long len;
unsigned int flags;
unsigned int vmflags;
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
flags = MAP_ANON;
len = PAGE_ALIGN(numero);
down_write(¤t->mm->mmap_sem);
address = get_unmapped_area(NULL,address,len,0,flags);
if(!address)
{
printk("<2>Can not define start address\n");
return -ENOMEM;
}
end = address + len;
if(end > TASK_SIZE)
{
printk("<2>No memory\n");
return -ENOMEM;
}
vma = kmem_cache_alloc(vm_area_cachep,SLAB_KERNEL);
if(!vma)
return -ENOMEM;
vmflags = mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_WRITE | VM_READ;
vma->vm_mm = mm;
vma->vm_start = address; /*Start address*/
vma->vm_end = end; /*Final address*/
vma->vm_ops = &my_vm_operation;
vma->vm_flags = vmflags;
vma->vm_pgoff = 0;
vma->vm_file = NULL; /*MAP_NON*/
vma->vm_private_data = NULL;
vma->vm_raend = 0;
vma->vm_page_prot = protection_map[vmflags & 0x0f];
insert_vm_struct(mm,vma);
up_write(¤t->mm->mmap_sem);
return address;
}
int init_module()
{
original_call = sys_call_table[NUM_mysyscallmem];
sys_call_table[NUM_mysyscallmem] = my_syscallmem;
return 0;
}
int cleanup_module()
{
sys_call_table[NUM_mysyscallmem] = original_call;
return 0;
}
[-- Attachment #3: bvma.h --]
[-- Type: application/octet-stream, Size: 269 bytes --]
/*by Breno S. Pinto*/
#include <asm/unistd.h>
#include <errno.h>
#define __NR_mysyscallmem 230
_syscall2(unsigned long,mysyscallmem,int,numero,unsigned long,address)
void *build_vma(int numero)
{
char *c_vma;
c_vma = (char *)mysyscallmem(numero,0);
return c_vma;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-10-15 22:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-15 22:32 [KERNEL 2.4 or 2.5] New source for allocation anonymous memory+paging demand Breno
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.