From owner-p4-projects@FreeBSD.ORG Fri Nov 10 23:01:45 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CA43216A4A7; Fri, 10 Nov 2006 23:01:44 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9F05B16A47E for ; Fri, 10 Nov 2006 23:01:44 +0000 (UTC) (envelope-from jkim@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6F8AA43E33 for ; Fri, 10 Nov 2006 23:00:12 +0000 (GMT) (envelope-from jkim@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kAAN0Cmv045681 for ; Fri, 10 Nov 2006 23:00:12 GMT (envelope-from jkim@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kAAN0Cn1045678 for perforce@freebsd.org; Fri, 10 Nov 2006 23:00:12 GMT (envelope-from jkim@freebsd.org) Date: Fri, 10 Nov 2006 23:00:12 GMT Message-Id: <200611102300.kAAN0Cn1045678@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jkim@freebsd.org using -f From: Jung-uk Kim To: Perforce Change Reviews Cc: Subject: PERFORCE change 109706 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Nov 2006 23:01:45 -0000 http://perforce.freebsd.org/chv.cgi?CH=109706 Change 109706 by jkim@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) {