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

RE: passing variables to/from kernel space



> -----Original Message-----
> From: Oliver Ryan [mailto:oryan@physics.nuigalway.ie]
> Sent: Tuesday, July 17, 2001 2:02 PM
> To: 'kernelnewbies@nl.linux.org'
> Subject: passing variables to/from kernel space
> 
> 
> Hi all,
Hi :)
...
 
> 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.

You can define those values as module parameters, and pass them
to module when you are insmoding it. 
To define a module parameter you should:

declare a _global_ variable that holds a param :

static int foo ; /* number of foos the module should perform */

and then use macro MODULE_PARM to inform insmod that the variable is 
a parameter, and what type it has:

MODULE_PARM(foo, "i" ) ;

"i" describes type and stands for "integer"

Reffer to /usr/src/linux/include/linux/module.h for description of all 
possible parameters types.


> 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?

/usr/src/linux/include/linux/time.h :

extern void do_gettimeofday( struct timeval *tv ) ;

Note that there is no timezone parameter.


> 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.

"Linux device drivers" by Allessandro Rubini is a great book. I would 
recommend it to any programmer who makes his/her first steps in kernel.

In abscence of the book itself, you can get examples  
from http://examples.oreilly.com/linuxdrive/

-- 
Omer Mussaev
Mercury Interactive / Topaz Prism R&D
Core Technologies team 
-
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/