From: "Breno" <breno_silva@bandnet.com.br>
To: "Kernel List" <linux-kernel@vger.kernel.org>
Subject: [KERNEL 2.4 or 2.5] New source for allocation anonymous memory+paging demand
Date: Tue, 15 Oct 2002 19:32:56 -0300 [thread overview]
Message-ID: <00bc01c2749a$cf0e4640$cddea7c8@bsb.virtua.com.br> (raw)
[-- 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;
}
reply other threads:[~2002-10-15 22:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='00bc01c2749a$cf0e4640$cddea7c8@bsb.virtua.com.br' \
--to=breno_silva@bandnet.com.br \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.