Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

copy_from_user in conjunction with vm_area_struct

$
0
0

I'm trying to copy vma's (memory) from a process in user space into a process in kernel space using copy_from_user(). The arguments for copy_from_user() require that you have two buffers (source & destination) as well as a size. My problem is that struct vm_area_struct contains only the start and end addresses of the memory for a particular vma in the linked list. What I'm trying to do is somehow cast these addresses into a buffer that then contains the data I need to read from using the function copy_from_user(). Is this sound reasoning? This is what I have tried so far:

void print_mmap(struct vm_area_struct *mmap){        while (mmap != NULL)        {            printk(KERN_INFO "vm_start: %lu vm_end: %lu difference: %lu\n", mmap->vm_start, mmap->vm_end, (mmap->vm_end-mmap->vm_start));            size_t size = mmap->vm_end-mmap->vm_start;            char buffer[size];            unsigned long incoming_buffer[size];            int i;            for (i=0;i<(mmap->vm_end - mmap->vm_start);i = i + sizeof(long unsigned))            {                long unsigned address = mmap->vm_start+i;                incoming_buffer[i] = address;            }            int success = copy_from_user(buffer, incoming_buffer, size);            printk(KERN_INFO "copied from buffer: %d\n", success);            for (i=0;i<size;i++)            {                printk(KERN_INFO "buffer at index %d is %c", i, buffer[i]);            }            mmap = mmap->vm_next;        }}

I also have another question about the vma's. Are these virtual memory addresses or are they physical memory addresses? If they are virtual, don't I need to first convert them to physical memory addresses prior to converting them to a buffer? If so, is it true that all I need to convert it to the physical address is the page size and number of bits for the virtual address?

When trying to access the page size (and page shift) is it appropriate to just write out:

PAGE_SHIFTPAGE_SIZE

Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>