[luau] kernel module, /proc filesystem, and mmap
Jimen Ching
jching at flex.com
Sat Oct 19 21:05:00 PDT 2002
Hi all,
I am trying to write a kernel module that shares a global variable between
a userland application and the module. In the kernel module, I use this:
mode = ...; /* read/write for all... */
entry = create_proc_entry("jimen", mode, NULL);
entry->proc_fops = my_fops;
Where my_fops contains an mmap entry like so...
int var __attribute__ ((aligned (PAGE_SIZE)));
int
my_mmap(struct file *filp, struct vm_area_struct *vma)
{
vma->vm_flags |= VM_RESERVED;
if (remap_page_range(vma->vm_start, (unsigned long)&var,
vma->vm_end - vma->vm_start, vma->vm_page_prot))
return -EAGAIN;
return 0;
}
struct file_operations my_fops =
{
mmap: my_mmap,
};
Then from an application, I do this:
int fd = open("/proc/jimen", O_RDWR);
int *ptr = mmap(NULL, 4, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
The mmap system call seems to work without error. 'ptr' seems to have a
valid pointer. But '*ptr' is -1. I can't modify it or anything. If I
add in MAP_ANONYMOUS to the flags, I am getting valid values and able to
modify '*ptr'. But if the module modifies 'var', '*ptr' does not reflect
the change. This kind of makes sense since MAP_ANONYMOUS means there is
no underlying file. But without it, I'm not even getting a valid pointer.
I don't think the application's mmap call is at fault. I think the
problem is with the kernel module. Anyone know if I can mmap a kernel
module variable using a /proc filesystem entry? All of the documentation
I found on the net implies this should work with a device in /dev. But I
don't want to deal with mknod, so that is why I'm using /proc. I didn't
read anything that suggests I can't use /proc instead of /dev. Has anyone
done this before?
Any help is greatly appreciated.
--jc
--
Jimen Ching (WH6BRR) jching at flex.com wh6brr at uhm.ampr.org
More information about the LUAU
mailing list