Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, all. I have kernel module that using mmap to communicte with usepscae program. Full code of this module paste.org.ru/?ii68m5. Compiliting ok, but when i try to read data drom ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    2

    Mmap kernel <-> userspace


    Hello, all. I have kernel module that using mmap to communicte with usepscae program. Full code of this module paste.org.ru/?ii68m5. Compiliting ok, but when i try to read data drom userspace program(full code of userspace program paste.org.ru/?drk1vp) i get error "invalid address"
    Code:
    ...
    struct page *mmap_nopage(struct vm_area_struct *vma, unsigned long address, int *type)
    {
        struct page *page;
        struct mmap_info *info;
        /* is the address valid? */
        if (address > vma->vm_end) {
            printk("invalid address\n");
            return NULL;
        }
    ...
    Please, help me to fix this mistake. Thank you
    Last edited by dasalam; 08-06-2011 at 03:01 PM.

  2. #2
    Just Joined!
    Join Date
    Jul 2011
    Posts
    16
    struct vm_operations_struct mmap_vm_ops = {
    .open = mmap_open,
    .close = mmap_close,
    .fault = mmap_nopage,
    };

    Check the prototype of the fault. it is int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);, I think you are referring to nopage method. But nopage method is not there in latest kernels.
    Last edited by oz; 08-09-2011 at 03:38 PM. Reason: removed spam redirect

  3. #3
    Just Joined!
    Join Date
    Aug 2011
    Posts
    2
    Thank you for answer. I tryed to use remap_pfn_range method. My code i borrowed it from LDD 3 (cs.fsu.edu/~baker/devices/lxr/http/source/ldd-examples/simple/simple.c) paste.org.ru/?5zs0xh . But i can't get data from kernel with userspace program.
    PS. It's normal that vma->vm_pgoff << PAGE_SHIFT in mmap_open = 0 ?

    PPS. I wrote working module using chrdev. Module code paste.org.ru/?d6jt5k. User space code paste.org.ru/?vtb1ki (/dev/simple char device created with "mknod /dev/simple c 241 0"). I understand how to read and write info from userspace, but i dont khow how do it from kernel space. Can anybody explain me?
    Last edited by dasalam; 08-09-2011 at 04:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •