mmap'ing vmalloc()'ed memory

mmap'ing vmalloc()'ed memory

Post by Andrew M. Kuchli » Sat, 12 Feb 2000 04:00:00



I'm implementing a Linux character device.  (It imitates the
Video4Linux API, but instead of acquiring images from an actual
device, userspace programs can place new frames that will then be
returned.  The intent is to allow using RealProducer, which only
supports the Video4Linux API, with any random source of frames.)

Anyway, RealProducer uses mmap() on /dev/video0, and I can't make my
device work properly.  I've used vmalloc() inside the kernel to
allocate a large buffer to hold the image data.  The bttv.c driver
does the same thing and supports mmap(), but when I copy it from
bttv.c, it doesn't work. Reading from the device returns the
previously stored data, but the mmap()'ed pages are always filled with
zeros, so I assume the wrong physical address is being mapped.  

I've never done kernel-level programming before, and so I'm kind of
lost as to how to proceed.  Anyone have any suggestions on how to
debug this?  I've included my mmap() handler below; anyone see some
obvious problem with it?  (The kvirt_to_pa() function has been copied
exactly from drivers/char/bttv.c.)

Thanks in advance!

--
A.M. Kuchling                   http://starship.python.net/crew/amk/
Not all readers are prepared, at all times, to make independent judgments. But
the failure of modern education to equip them to do so even when they have the
inclination creates a serious gap in modern culture.
    -- Robertson Davies, _A Voice from the Attic_

static int fakev4l_mmap(Fakev4l_Dev *dev, struct vm_area_struct *vma)
{
        unsigned long size = vma->vm_end - vma->vm_start;
        unsigned long start= vma->vm_start;
        unsigned long pos;

        PDEBUG("fakev4l_mmap called %p %lx %li\n", dev, start, size);
        if (size> MAX_BUFFER_SIZE)
                return -EINVAL;
        if (fakev4l_device.data == NULL)
          {
            printk(KERN_ERR "Fake V4L data area not yet allocated");
            return -EINVAL;
        }
        /* XXX Only mmaps the first buffer */
        pos=(unsigned long) fakev4l_device.data[0];
        while (size > 0)
        {
                unsigned long page = kvirt_to_pa(pos);
                if (remap_page_range(start, page, PAGE_SIZE,
                                     vma->vm_page_prot))
                        return -EAGAIN;
                start+=PAGE_SIZE;
                pos+=PAGE_SIZE;
                size-=PAGE_SIZE;    
        }
        return 0;

Quote:}

 
 
 

1. Error make'ing Appache; Undef'ed symbol '_crypt'...

Could someone please help me...This is probable a simple fix (I hope). I tryed to make the package and I get and error
of:
$ make
gcc -c -O2 -m486 alloc.c
gcc -c -O2 -m486 http_main.c
gcc -c -O2 -m486 http_core.c
gcc -c -O2 -m486 util.c
gcc -c -O2 -m486 util_script.c
gcc -c -O2 -m486 buff.c
gcc -c -O2 -m486 util_md5.c
gcc -c -O2 -m486 explain.c
gcc   -o httpd alloc.o http_main.o http_core.o http_config.o http_request.o  http_log.o http_protocol.o rfc1413.o
util.o util_script.o modules.o buff.o md5c.o util_md5.o explain.o http_bprintf.o mod_mime.o  mod_access.o  mod_auth.o
mod_negotiation.o  mod_include.o  mod_dir.o  mod_cgi.o  mod_userdir.o  mod_alias.o  mod_env.o  mod_log_common.o
mod_asis.o  mod_imap.o  mod_actions.o  
mod_auth.o: Undefined symbol `_crypt' referenced from text segment
*** Error code 1

Stop.

$

What am I doiing wrong?  I uncommented support for FreeBSD...

        please help!

        Michael Pelletier

2. Another X Fool

3. mmap'ed memory segments and malloc()

4. ide0: buggy RZ100 Interface

5. Howto use a mmap'ed and shared memory segment?

6. revving up the kshell

7. Howto use mmap'ed and shared memory ?

8. XFree86 3.1 : WD90C31 probs. - finding dot clock freqs.

9. Timeout'ing a exec'ed process via bash

10. SSH'ing out of an SSH'ed chroot environment

11. Device driver: can't read mmap'ed buffer

12. mmap'ing 2 or more mem-area's to 1 mem-area?

13. wield directory entry for tar'ed gzip'ed files