lkml.org 
[lkml]   [2004]   [Feb]   [22]   [last100]   RSS Feed
Views: [more markup]   [less markup]   [headers]   [forward]  
 
Messages in this thread
/
FromArnd Bergmann <>
SubjectRe: [RFC][PATCH] 2/6 POSIX message queues
DateSun, 22 Feb 2004 13:23:50 +0100
On Friday 20 February 2004 19:11, Krzysztof Benedyczak wrote:
> On Fri, 20 Feb 2004, Arnd Bergmann wrote:
> > Krzysztof Benedyczak wrote:
> > > +
> > > +struct mq_attr {
> > > +	long	mq_flags;	/* message queue flags			*/
> > > +	long	mq_maxmsg;	/* maximum number of messages		*/
> > > +	long	mq_msgsize;	/* maximum message size			*/
> > > +	long	mq_curmsgs;	/* number of messages currently queued	*/
> > > +};
> > > +
> >
> > Does POSIX mandate that these have to be 'long'? If you can change them
> > all to any of 'int', '__s32' or '__s64', the handlers for 32 bit system
> > call emulation on 64 bit machines will get a lot simpler because the
> > 32 bit user structures are then identical to the 64 bit ones.
>
> Yes, POSIX defines it to longs. And quess that compability issues should
> be handled in kernel?

Yes, compatibility can only be handled in kernel. For each system call
that passes structures with a different layout, you need to do something
like this:

struct compat_mq_attr {
	compat_long_t	mq_flags;
	compat_long_t	mq_maxmsg;
	compat_long_t	mq_msgsize;
	compat_long_t	mq_curmsgs;
};
asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
		const struct compat_mq_attr __user *u_mqstat,
		struct compat_mq_attr __user *u_omqstat)
{
	struct mq_attr mqstat, omqstat;
	mm_segment_t oldfs;
	int err, err2;
	err = get_user(mqstat.mq_flags, &u_mqstat->mq_flags)
	    | get_user(mqstat.mq_maxmsg, &u_mqstat->mq_maxmsgs)
	    | get_user(mqstat.mq_msgsize, &u_mqstat->mq_msgsize)
	    | get_user(mqstat.mq_curmsgs, &u_mqstat->mq_curmsgs);
	if (err)
		return -EFAULT;
	oldfs = get_fs();
	set_fs(KERNEL_DS);
	err2 = sys_mq_getsetattr(mqdes, &mqstat, &omqstat);
	set_fs(old_fs);
	err = get_user(omqstat.mq_flags, &u_omqstat->mq_flags)
	    | get_user(omqstat.mq_maxmsg, &u_omqstat->mq_maxmsgs)
	    | get_user(omqstat.mq_msgsize, &u_omqstat->mq_msgsize)
	    | get_user(omqstat.mq_curmsgs, &u_omqstat->mq_curmsgs);
	if (err)
		return -EFAULT;
	return err2;
}
Nothing difficult here, but slow and avoidable if you have the
structures laid out properly. Normally you can do this with padding,
but that is no good here because 'long' members need sign-extension,
not zero-extension.

	Arnd <><

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:01    [W:0.727 / U:0.140 seconds]
©2003-2008 Jasper Spaans