Date: Wed, 28 Jun 2006 20:05:09 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 100228 for review Message-ID: <200606282005.k5SK59rK048576@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100228 Change 100228 by jhb@jhb_mutex on 2006/06/28 20:04:17 Split up ibcs2_msgsys() into subfunctions similar to svr4_sys_msgsys() and use kern_msgctl() in ibcs2_msgctl() to avoid the stackgap. Affected files ... .. //depot/projects/smpng/sys/i386/ibcs2/ibcs2_ipc.c#9 edit Differences ... ==== //depot/projects/smpng/sys/i386/ibcs2/ibcs2_ipc.c#9 (text+ko) ==== @@ -31,6 +31,7 @@ #include <sys/msg.h> #include <sys/sem.h> #include <sys/shm.h> +#include <sys/syscallsubr.h> #include <sys/sysproto.h> #include <i386/ibcs2/ibcs2_types.h> @@ -102,50 +103,118 @@ return; } +struct ibcs2_msgget_args { + int what; + int key; + int msgflg; +}; + +static int +ibcs2_msgget(struct thread *td, void *v) +{ + struct ibcs2_msgget_args *uap = v; + struct msgget_args ap; + + ap.key = uap->key; + ap.msgflg = uap->msgflg; + return msgget(td, &ap); +} + +struct ibcs2_msgctl_args { + int what; + int msqid; + int cmd; + struct ibcs2_msqid_ds *buf; +}; + +static int +ibcs2_msgctl(struct thread *td, void *v) +{ + struct ibcs2_msgctl_args *uap = v; + struct ibcs2_msqid_ds is; + struct msqid_ds bs; + int error; + + switch (uap->cmd) { + case IBCS2_IPC_STAT: + error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs); + if (!error) { + cvt_msqid2imsqid(&bs, &is); + error = copyout(&is, uap->buf, sizeof(is)); + } + return (error); + case IBCS2_IPC_SET: + error = copyin(uap->buf, &is, sizeof(is)); + if (error) + return (error); + cvt_imsqid2msqid(&is, &bs); + return (kern_msgctl(td, uap->msqid, IPC_SET, &bs)); + case IBCS2_IPC_RMID: + return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL)); + } + return (EINVAL); +} + +struct ibcs2_msgrcv_args { + int what; + int msqid; + void *msgp; + size_t msgsz; + long msgtyp; + int msgflg; +}; + +static int +ibcs2_msgrcv(struct thread *td, void *v) +{ + struct ibcs2_msgrcv_args *uap = v; + struct msgrcv_args ap; + + ap.msqid = uap->msqid; + ap.msgp = uap->msgp; + ap.msgsz = uap->msgsz; + ap.msgtyp = uap->msgtyp; + ap.msgflg = uap->msgflg; + return (msgrcv(td, &ap)); +} + +struct ibcs2_msgsnd_args { + int what; + int msqid; + void *msgp; + size_t msgsz; + int msgflg; +}; + +static int +ibcs2_msgsnd(struct thread *td, void *v) +{ + struct ibcs2_msgsnd_args *uap = v; + struct msgsnd_args ap; + + ap.msqid = uap->msqid; + ap.msgp = uap->msgp; + ap.msgsz = uap->msgsz; + ap.msgflg = uap->msgflg; + return (msgsnd(td, &ap)); +} + int ibcs2_msgsys(td, uap) struct thread *td; struct ibcs2_msgsys_args *uap; { switch (uap->which) { - case 0: /* msgget */ - uap->which = 1; - return msgsys(td, (struct msgsys_args *)uap); - case 1: { /* msgctl */ - int error; - struct msgsys_args margs; - caddr_t sg = stackgap_init(); - - margs.which = 0; - margs.a2 = uap->a2; - margs.a4 = - (int)stackgap_alloc(&sg, sizeof(struct msqid_ds)); - margs.a3 = uap->a3; - switch (margs.a3) { - case IBCS2_IPC_STAT: - error = msgsys(td, &margs); - if (!error) - cvt_msqid2imsqid( - (struct msqid_ds *)margs.a4, - (struct ibcs2_msqid_ds *)uap->a4); - return error; - case IBCS2_IPC_SET: - cvt_imsqid2msqid((struct ibcs2_msqid_ds *)uap->a4, - (struct msqid_ds *)margs.a4); - return msgsys(td, &margs); - case IBCS2_IPC_RMID: - return msgsys(td, &margs); - } - return EINVAL; - } - case 2: /* msgrcv */ - uap->which = 3; - return msgsys(td, (struct msgsys_args *)uap); - case 3: /* msgsnd */ - uap->which = 2; - return msgsys(td, (struct msgsys_args *)uap); + case 0: + return (ibcs2_msgget(td, uap)); + case 1: + return (ibcs2_msgctl(td, uap)); + case 2: + return (ibcs2_msgrcv(td, uap)); + case 3: + return (ibcs2_msgsnd(td, uap)); default: - return EINVAL; + return (EINVAL); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606282005.k5SK59rK048576>