PERFORCE change 109706 for review
Jung-uk Kim
jkim at FreeBSD.org
Fri Nov 10 23:01:45 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=109706
Change 109706 by jkim at jkim_hammer on 2006/11/10 22:59:53
Add (ugly) 32-bit msgsnd/msgrcv support for amd64.
msgp points to msghdr and msghdr contains msg_type, which is long.
When we copyin/copyout, we copy the correct msg_type and advance msgp
by msg_type size.
This fixes LTP test cases msgget01, msgrcv01, msgrcv02, msgrcv04, and
msgsnd03.
Note: There is only one test case blocked in msgwait state after this
change, which seems to be arch-independent issue.
Affected files ...
.. //depot/projects/linuxolator/src/sys/compat/linux/linux_ipc.c#3 edit
.. //depot/projects/linuxolator/src/sys/kern/sysv_msg.c#5 edit
Differences ...
==== //depot/projects/linuxolator/src/sys/compat/linux/linux_ipc.c#3 (text+ko) ====
@@ -83,6 +83,10 @@
l_ulong swap_successes;
};
+/* XXX This should not be here. */
+int do_msgsnd(struct thread *, struct msgsnd_args *, size_t);
+int do_msgrcv(struct thread *, struct msgrcv_args *, size_t);
+
static void
bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo *lpp)
{
@@ -586,7 +590,8 @@
bsd_args.msgp = PTRIN(args->msgp);
bsd_args.msgsz = args->msgsz;
bsd_args.msgflg = args->msgflg;
- return msgsnd(td, &bsd_args);
+
+ return (do_msgsnd(td, &bsd_args, sizeof(l_long)));
}
int
@@ -605,7 +610,8 @@
bsd_args.msgsz = args->msgsz;
bsd_args.msgtyp = args->msgtyp;
bsd_args.msgflg = args->msgflg;
- return msgrcv(td, &bsd_args);
+
+ return (do_msgrcv(td, &bsd_args, sizeof(l_long)));
}
int
==== //depot/projects/linuxolator/src/sys/kern/sysv_msg.c#5 (text+ko) ====
@@ -662,6 +662,11 @@
return (error);
}
+union msgtyp {
+ long mtype;
+ int32_t mtype32;
+};
+
#ifndef _SYS_SYSPROTO_H_
struct msgsnd_args {
int msqid;
@@ -671,14 +676,16 @@
};
#endif
-/*
- * MPSAFE
- */
+/* XXX This should not be here. */
+int do_msgsnd(struct thread *, struct msgsnd_args *, size_t);
+
int
-msgsnd(td, uap)
+do_msgsnd(td, uap, mtsz)
struct thread *td;
register struct msgsnd_args *uap;
+ size_t mtsz;
{
+ union msgtyp msgt;
int msqid = uap->msqid;
const void *user_msgp = uap->msgp;
size_t msgsz = uap->msgsz;
@@ -693,6 +700,9 @@
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
+ if (mtsz != sizeof(msgt.mtype) && mtsz != sizeof(msgt.mtype32))
+ return (EINVAL);
+
mtx_lock(&msq_mtx);
msqid = IPCID_TO_IX(msqid);
@@ -875,8 +885,7 @@
*/
mtx_unlock(&msq_mtx);
- if ((error = copyin(user_msgp, &msghdr->msg_type,
- sizeof(msghdr->msg_type))) != 0) {
+ if ((error = copyin(user_msgp, &msgt, mtsz)) != 0) {
mtx_lock(&msq_mtx);
DPRINTF(("error %d copying the message type\n", error));
msg_freehdr(msghdr);
@@ -884,8 +893,9 @@
wakeup(msqkptr);
goto done2;
}
+ msghdr->msg_type = (mtsz == sizeof(long)) ? msgt.mtype : msgt.mtype32;
mtx_lock(&msq_mtx);
- user_msgp = (const char *)user_msgp + sizeof(msghdr->msg_type);
+ user_msgp = (const char *)user_msgp + mtsz;
/*
* Validate the message type
@@ -995,6 +1005,17 @@
return (error);
}
+/*
+ * MPSAFE
+ */
+int
+msgsnd(td, uap)
+ struct thread *td;
+ register struct msgsnd_args *uap;
+{
+ return (do_msgsnd(td, uap, sizeof(long)));
+}
+
#ifndef _SYS_SYSPROTO_H_
struct msgrcv_args {
int msqid;
@@ -1005,14 +1026,16 @@
};
#endif
-/*
- * MPSAFE
- */
+/* XXX This should not be here. */
+int do_msgrcv(struct thread *, struct msgrcv_args *, size_t);
+
int
-msgrcv(td, uap)
+do_msgrcv(td, uap, mtsz)
struct thread *td;
register struct msgrcv_args *uap;
+ size_t mtsz;
{
+ union msgtyp msgt;
int msqid = uap->msqid;
void *user_msgp = uap->msgp;
size_t msgsz = uap->msgsz;
@@ -1030,6 +1053,9 @@
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
+ if (mtsz != sizeof(msgt.mtype) && mtsz != sizeof(msgt.mtype32))
+ return (EINVAL);
+
msqid = IPCID_TO_IX(msqid);
if (msqid < 0 || msqid >= msginfo.msgmni) {
@@ -1226,8 +1252,11 @@
*/
mtx_unlock(&msq_mtx);
- error = copyout(&(msghdr->msg_type), user_msgp,
- sizeof(msghdr->msg_type));
+ if (mtsz == sizeof(long))
+ msgt.mtype = msghdr->msg_type;
+ else
+ msgt.mtype32 = msghdr->msg_type;
+ error = copyout(&msgt, user_msgp, mtsz);
mtx_lock(&msq_mtx);
if (error != 0) {
DPRINTF(("error (%d) copying out message type\n", error));
@@ -1235,7 +1264,7 @@
wakeup(msqkptr);
goto done2;
}
- user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
+ user_msgp = (char *)user_msgp + mtsz;
/*
* Return the segments to the user
@@ -1280,6 +1309,17 @@
return (error);
}
+/*
+ * MPSAFE
+ */
+int
+msgrcv(td, uap)
+ struct thread *td;
+ register struct msgrcv_args *uap;
+{
+ return (do_msgrcv(td, uap, sizeof(long)));
+}
+
static int
sysctl_msqids(SYSCTL_HANDLER_ARGS)
{
More information about the p4-projects
mailing list