[luau] kernel module, /proc filesystem, and mmap
Ray Strode
halfline at hawaii.rr.com
Sun Oct 20 00:00:01 PDT 2002
I've never actually done any kernel programming, so I probably won't be
of much
help (actually probably won't be of any help, i'm just shooting in the
dark),
but...
>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;
>
My guess is that you probably need to set entry->read_proc and
entry->write_proc
also. (I don't know if you've seen
linux/Documentation/DocBook/procfs_example.c
or not, but it seems like a pretty easy example to follow).
>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,
>
offtopic, but that cast doesn't sit well with me (because whose to say
sizeof(int *) == sizeof(long) ?)
For instance on sparc i think that long is 32-bit and pointers are
64-bit, so
a cast like that would cut off half the address's bits.
That said... I think it must be right because the kernel developers are
a lot
smarter than me :-) and they've prototyped the function that way.
> 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.
>
So /proc/jimen exists? What happens if you cat /proc/jimen ?
>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.
>
right.
> But without it, I'm not even getting a valid pointer.
>
You mean you are getting a valid pointer, but the value the pointer
points to
doesn't change?
If you sent me your code, I wouldn't mind playing around with it. I've
always
kinda wanted to learn kernel programming.
--Ray
More information about the LUAU
mailing list