Ok, I tried an even simpler example. Now I just allocate some kernel
memory with kmalloc() and try to export it to userspace:
dev_info.mem[0].memtype = UIO_MEM_LOGICAL;
dev_info.mem[0].addr = (unsigned long) kmalloc(16, GFP_KERNEL);
dev_info.mem[0].size = 16;
I also registered an interrupt (interrupts work like a charm!) and in
my interrupt handler I have:
printk("address %p is %i\n",
(void*) dev_info->mem[1].addr,
*((unsigned char*)dev_info->mem[1].addr));
This will print the first byte of my allocated buffer everytime an
interrupt occurs.
>From userspace I do the same thing as before:
uio_fd = open(/dev/uio0, O_RDWR);
access_address = mmap(NULL, 0x10400, PROT_READ|PROT_WRITE,
MAP_SHARED, uio_fd, 0);
while(1){
read(uio_fd, &r, 4);
printf("address %p is %i\n", access_address, (*access_address)++);
}
The loop will wait for an interrupt, increment the byte at the mapped
memory address and print it's contents.
Now I load the module, and start the userspace program. The userspace
app is happily incrementing everytime I press the button to generate
the interrupt. With dmesg I can see the messages from the module, but
the value never changes. Now I stop the userspace app and restart it,
it continues counting from where it was before. So just for fun I
unloaded the kernel module, insmod it again and ran the userspace app
once more: It goes on incrementing it's old value! How is that
possible when the module allocated a new buffer with kmalloc? As you
can see from the following output, the address of the buffer changes,
but the counter continues incrementing as usual...
$ myapp
address 0xb7fc5000 is 0
address 0xb7fc5000 is 1
$ myapp
address 0xb7f40000 is 2
address 0xb7f40000 is 3
$ dmesg -c
address c11456e0 is 0
address c11456e0 is 0
address c11456e0 is 0
address c11456e0 is 0
$ rmmod mydev
$ insmod mydev.ko
$ myapp
address 0xb7f2f000 is 4
address 0xb7f2f000 is 5
$ dmesg -c
address c7d7e950 is 0
address c7d7e950 is 0
Any hints appreciated...
Christoph
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ