Operating System - HP-UX
1752790 Members
6451 Online
108789 Solutions
New Discussion юеВ

Re: accessing user address in a kernel driver

 
Tarun Jain_1
Advisor

accessing user address in a kernel driver

I have a quick technical question about HP-UX device driver. The prototype of the ioctl routine a device driver registers with HP-UX is:
xxxioctl(dev_t device, int cmd, caddr_t arg, int flags);

Inside of this routine, is there a way to find out the userspace address of the ioctl argument that the calling (userspace) program would have passed to the "ioctl" function in userspace?
I know that for fixed size ioctl args, HP-UX internally does a copyin of the arg before calling the driver routine, and does a copyout after wards. Is there a way to handle variable sized args, e.g.:
struct arg_2_some_ioctl {
unisgned int num_entries;
unsigned char entry[1];
}
Can we use the above declaration & still have an ioctl that can use the entry array in a way that the length is provided by num_entries?


Regards,
Tarun
4 REPLIES 4
Michael Steele_2
Honored Contributor

Re: accessing user address in a kernel driver

I don't know what you are talking about and neither does the search engine when used to find information on "...xxxioctl...".

Could you expand on this comment please?

"..The prototype of the ioctl routine a device driver registers with HP-UX is:..."

Question: Are you rewriting the Hpux kernel device driver?

Support Fatherhood - Stop Family Law
Laurent Menase
Honored Contributor

Re: accessing user address in a kernel driver

Hi, the best is to pass a pointer from user space.
declare it as _IO('z',x)
where z and x are youre values
if you declare it as _IO the 3rd ioctl param will be passed to your driver ioctl directly.

toto_ioctl(dev_t dev, int command, caddr_t * data, int flags)

u.u_error = copyin( *data, buffer, size);

will copy the user buffer pointed by the 3rd param of ioctl.
Dennis Handly
Acclaimed Contributor

Re: accessing user address in a kernel driver

>Michael: when used to find information on "xxxioctl".

You need a search engine that understands wildcards?

>Are you rewriting the HP-UX kernel device driver?

Exactly, Tarun should have mentioned this.

I know what he was asking but not the details that Laurent provided.
Laurent Menase
Honored Contributor

Re: accessing user address in a kernel driver

#define TOTOIOCTL _IO('z',1)

toto_ioctl(dev_t dev, int command, caddr_t * data, int flags)
{
unsigned int numentries;
struct targer *buffer;
u.u_error = copyin( *data, &numentries, sizeof(numentries));
////: test error cases , numentries limit val uerrors ....
allocate your buffer


u.u_error =copyin(*data+sizeof(numentries), buffer,numentries*sizeofentries);


Just a remark, if there are any elements in your entries which alignement is larger than 4 bytes ( like double, long long ...)
you may have padding in the structure.

Also think that the ioctl can be called by a 32 bit application or a 64bit application an that the kernel is always 64bits
so if there are "long" or size_t or any type which is based on "long", the structure will not be the same in the user space and in the kernel space.