Click to See Complete Forum and Search --> : kernel level code accessing user level program's variables arrays and structures


mnsharif
12-14-2002, 08:26 AM
hi all,

i have a user level program written in C, that has gathered all the information required from the network using sockets and stuff like that.

also

i have a module loaded in the kernel (or some system call hooked)

and i want to use the information gathered by my user level process in the kernel module or the hooked system call.


Is it possible???

how??


PS: i m not asking about how to copy data to and from userSpace and kernelSpace.

thanx a lot

binaryDigit
12-14-2002, 09:13 AM
i believe this is usually done through the /proc directory.
of course i could be wrong.

mnsharif
12-14-2002, 09:33 AM
ummm, ok, throug /proc

but how??


thanx for your help

binaryDigit
12-14-2002, 12:08 PM
the kernel module would read from /proc/somefile your program would write to /proc/somefile
or the other way around.

Ddruid
12-14-2002, 05:15 PM
Take a look in the excellent documentation supplied with the kernel source. In particular information about 'procfs'. There is also an example of using the proc filesystem to query a module. One thing to watch out for is the roles of reading and writing to the kernel are reversed and easily mistaken. I would suggest picking up the book 'Linux Device Drivers' 2nd Edition (for 2.4 kernels) it is a great resource to have handy when writing kernel modules.

majidpics
12-17-2002, 06:24 AM
whereas i remember, i studied a book about, using /proc

the book was "Linux Kernel Module Programming Guide" by Peter Jay Salzman and Ori Pomerantz (2001 version). In its 5th and 6th chapter it uses /proc to do some stuff. But the problem was that proc_register() and proc_unregister() were unavailable.

I mean i also tried proc_register_dynamic(), but it didnt worked
and i browsed throug the /proc/ksyms file, neither of the functions was listed there??

so besdied everything was ok, i was unable to run that program successfully??

so, what should i do???


i beleive that there can be two cases

1-Kernel-2.4.18 (the one i m using) dont support it anymore

2-there needs to be a module loaded as a pre-requisite, which registers all above mentioined procedures into /proc/ksyms and then we can use the proc_register() etc. etc.


so, anyone please guide me in this respect.

mnsharif
12-19-2002, 05:38 AM
ok, leave the /proc and all the related stuff

i beleive that the similiar kind of work can be done through a character device. I mean i make a characterfile through
mknod DEVICE_NAME c AMJOR MINOR
and then write a simple character device driver just like /proc.

But the problem is that the data which i want to share between kernel module and a userspace program is not simple raw data, i mean its not simple characters. Actually its a structure containing all status info, so what should i do???

i think, that when asking that character device to write, we can type-cast the structure to (char *) so that it can write it on the character file and when asking to read from the file, the device must read sizeof(structure) bytes and return it to the program, where we can type-cast it back to structure type


amybe not all of you understand what i said, but those who understand, is that approach CORRECT
and for those, who didnt got what i said, ask me, i will explain it

thanx for your help