Skip to contentSkip to conversation

2/6 POSIX message queues

RFC PATCH Arnd Bergmann 2 participants 3 messages Feb 20, 2004 – Feb 22, 2004

lore
Share & tools
lore
#0 lore raw

Review

Quoted 8 lines · Krzysztof Benedyczak
(quoted diff) +8 -0
+
+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.

	Arnd <><
#1 lore raw
Quoted 16 lines · Arnd Bergmann

Review

Quoted 8 lines · Krzysztof Benedyczak
(quoted diff) +8 -0
+
+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?

Krzysztof Benedyczak

#2 lore raw
Quoted 16 lines · Krzysztof Benedyczak
Quoted 14 lines · Arnd Bergmann

Review

Quoted 8 lines · Krzysztof Benedyczak
(quoted diff) +8 -0
+
+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.

Quoted 2 lines

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