Re: How to split a VMA.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  Hi, 
	first of let me know why you are allocating space for the new vma, as 
find_vma will return a pointer to the existing vma and in that case you'll create a 
memory leak there, as you will lose the track for the allocated vma in case if one 
vma is returned by find_vma()	;-) 
 
I think to spilt a vma you can use the functionality explained in 
madvise_fixup_start(), madvise_fixup_end or madvise_fixup_middle() functions 
defined in mm/filemap.c... go through them, I think it'll solve your problem. 
 
Thanks. 
Sumit Sharma. 
 
On Thu, 16 Sep 2004 Naren wrote : 
>Hi, 
>I am trying to write a system call that splits a VMA into two halves. The problem 
is that, as I am using do_mmap() system call, it is only creating one area and that 
too at a different address than the old one. 
> 
>The code: 
>(*addr is passed as some arbitrary address that falls in any VMA) 
> 
>struct mm_struct *mm = current->mm; 
>struct vm_area_struct *vma; 
>unsigned long ret, ret2, old_length,length, start_add, end_add,     second_add; 
> 
> 
>         if (flag == 0) { 
>                 vma = (struct vm_area_struct *) kmalloc(sizeof(struct 
vm_area_struct)); 
>                 vma = find_vma(mm, *addr); 
>                 if (vma == NULL){ 
>                         return ENOMEM; 
>                 } 
>                 old_length = (vma->vm_end - vma->vm_start); 
>                 length = old_length/2; 
>                 start_add = PAGE_ALIGN(vma->vm_start); 
>                 end_add = PAGE_ALIGN(vma->vm_end); 
>                 second_add = PAGE_ALIGN(start_add + length); 
>                 ret = do_mremap(start_add, old_length, length, NULL, NULL); 
>                 ret2 = do_mmap(NULL, second_add, length, PROT_READ, 
MAP_EXECUTABLE, 0); 
> 
>         } 
> 
> 
>Is there anything that i m doing wrong over here .. 
> 
>Thanks and Regards, 
>Narinder 
> 

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux