[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing variables to/from kernel space



On Tue, Jul 17, 2001 at 01:01:45PM +0100, Oliver Ryan wrote:
| 1.  How do I pass register values entered in user space to the module so 
| that these values are loaded into the registers?  I've read up on 
| copy_to/from_user and put/get_user but don't know how to implement them in 
| working code.

I'd faced similar situation; I had a device entry in /dev, and a
xxx_ioctl file operation registered. On receiving the ioctl from a user
application, which would also pass as an argument to ioctl, an address
to a buffer, which contained the values to be read (and written to the
registers), one can use copy_from_user() to get those values, and then
write it to the registers. For passing multiple values (of same kind),
you would need to pass address of array; and for passing multiple values
of different kinds, an address to an struct.

| 2.  In a kernel module I want to call some function which will give me the 
| time elapsed in seconds since Jan1 1970 - time() would do this in a user 
| program, but what is it's equivalent for the kernel module?

Rubini did talk about this in his book; IIRC, it's not possible. I
think, the reason, given was, that you wouldn't need such a function in
the kernel.

| 3.  Is there a HOWTO or example code somewhere I can read up on (for system 
| calls too, which might be a better way of doing things?) ?  I've looked at 
| most kernel hacking stuff I think, but still can't find what I need.

If you don't have Rubini's book on 'Writing Linux Device Drivers', then
get it. It's worth it's weight in gold. Also, if you haven't, try
www.kernelnewbies.org.

chyrag.
-- 
Chirag Kantharia, slashetc.net/chyrag/

-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/