[BACK]Return to kern_ipc_23.c CVS log [TXT][DIR] Up to [local] / sys / compat / common

Annotation of sys/compat/common/kern_ipc_23.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: kern_ipc_23.c,v 1.5 2004/07/15 11:25:59 millert Exp $ */
                      2:
                      3: /*
                      4:  * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/param.h>
                     20: #include <sys/systm.h>
                     21: #include <sys/kernel.h>
                     22: #include <sys/proc.h>
                     23: #include <sys/msg.h>
                     24: #include <sys/sem.h>
                     25: #include <sys/shm.h>
                     26:
                     27: #include <sys/mount.h>
                     28: #include <sys/syscallargs.h>
                     29:
                     30: /*
                     31:  * Convert between new and old struct {msq,sem,shm}id_ds (both ways)
                     32:  */
                     33: #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
                     34: #define cvt_ds(to, from, type, base) do {                              \
                     35:        (to)->type##_perm.cuid = (from)->type##_perm.cuid;              \
                     36:        (to)->type##_perm.cgid = (from)->type##_perm.cgid;              \
                     37:        (to)->type##_perm.uid = (from)->type##_perm.uid;                \
                     38:        (to)->type##_perm.gid = (from)->type##_perm.gid;                \
                     39:        (to)->type##_perm.mode = (from)->type##_perm.mode & 0xffffU;    \
                     40:        (to)->type##_perm.seq = (from)->type##_perm.seq;                \
                     41:        (to)->type##_perm.key = (from)->type##_perm.key;                \
                     42:        bcopy((caddr_t)&(from)->base, (caddr_t)&(to)->base,             \
                     43:            sizeof(*(to)) - ((caddr_t)&(to)->base - (caddr_t)to));      \
                     44: } while (0)
                     45: #endif /* SYSVMSG || SYSVSEM || SYSVSHM */
                     46:
                     47: #ifdef SYSVMSG
                     48: /*
                     49:  * Copy a struct msqid_ds23 from userland and convert to struct msqid_ds
                     50:  */
                     51: static int
                     52: msqid_copyin(const void *uaddr, void *kaddr, size_t len)
                     53: {
                     54:        struct msqid_ds *msqbuf = kaddr;
                     55:        struct msqid_ds23 omsqbuf;
                     56:        int error;
                     57:
                     58:        if (len != sizeof(struct msqid_ds))
                     59:                return (EFAULT);
                     60:        if ((error = copyin(uaddr, &omsqbuf, sizeof(omsqbuf))) == 0)
                     61:                cvt_ds(msqbuf, &omsqbuf, msg, msg_first);
                     62:        return (error);
                     63: }
                     64:
                     65: /*
                     66:  * Convert a struct msqid_ds to struct msqid_ds23 and copy to userland
                     67:  */
                     68: static int
                     69: msqid_copyout(const void *kaddr, void *uaddr, size_t len)
                     70: {
                     71:        const struct msqid_ds *msqbuf = kaddr;
                     72:        struct msqid_ds23 omsqbuf;
                     73:
                     74:        if (len != sizeof(struct msqid_ds))
                     75:                return (EFAULT);
                     76:        cvt_ds(&omsqbuf, msqbuf, msg, msg_first);
                     77:        return (copyout(&omsqbuf, uaddr, sizeof(omsqbuf)));
                     78: }
                     79:
                     80: /*
                     81:  * OpenBSD 2.3 msgctl(2) with 16bit values in struct ipcperm.
                     82:  */
                     83: int
                     84: compat_23_sys_msgctl(struct proc *p, void *v, register_t *retval)
                     85: {
                     86:        struct compat_23_sys_msgctl_args /* {
                     87:                syscallarg(int) msqid;
                     88:                syscallarg(int) cmd;
                     89:                syscallarg(struct msqid_ds23 *) buf;
                     90:        } */ *uap = v;
                     91:
                     92:        return (msgctl1(p, SCARG(uap, msqid), SCARG(uap, cmd),
                     93:            (caddr_t)SCARG(uap, buf), msqid_copyin, msqid_copyout));
                     94: }
                     95: #endif /* SYSVMSG */
                     96:
                     97: #ifdef SYSVSEM
                     98: /*
                     99:  * Copy a struct semid_ds23 from userland and convert to struct semid_ds
                    100:  */
                    101: static int
                    102: semid_copyin(const void *uaddr, void *kaddr, size_t len)
                    103: {
                    104:        struct semid_ds *sembuf = kaddr;
                    105:        struct semid_ds23 osembuf;
                    106:        int error;
                    107:
                    108:        if (len != sizeof(struct semid_ds))
                    109:                return (EFAULT);
                    110:        if ((error = copyin(uaddr, &osembuf, sizeof(osembuf))) == 0)
                    111:                cvt_ds(sembuf, &osembuf, sem, sem_base);
                    112:        return (error);
                    113: }
                    114:
                    115: /*
                    116:  * Convert a struct semid_ds to struct semid_ds23 and copy to userland
                    117:  */
                    118: static int
                    119: semid_copyout(const void *kaddr, void *uaddr, size_t len)
                    120: {
                    121:        const struct semid_ds *sembuf = kaddr;
                    122:        struct semid_ds23 osembuf;
                    123:
                    124:        if (len != sizeof(struct semid_ds))
                    125:                return (EFAULT);
                    126:        cvt_ds(&osembuf, sembuf, sem, sem_base);
                    127:        return (copyout(&osembuf, uaddr, sizeof(osembuf)));
                    128: }
                    129:
                    130: /*
                    131:  * OpenBSD 2.3 semctl(2) with 16bit values in struct ipcperm.
                    132:  */
                    133: int
                    134: compat_23_sys___semctl(struct proc *p, void *v, register_t *retval)
                    135: {
                    136:        struct compat_23_sys___semctl_args /* {
                    137:                syscallarg(int) semid;
                    138:                syscallarg(int) semnum;
                    139:                syscallarg(int) cmd;
                    140:                syscallarg(union semun *) arg;
                    141:        } */ *uap = v;
                    142:        union semun arg;
                    143:        int error = 0, cmd = SCARG(uap, cmd);
                    144:
                    145:        switch (cmd) {
                    146:        case IPC_SET:
                    147:        case IPC_STAT:
                    148:        case GETALL:
                    149:        case SETVAL:
                    150:        case SETALL:
                    151:                error = copyin(SCARG(uap, arg), &arg, sizeof(arg));
                    152:                break;
                    153:        }
                    154:        if (error == 0) {
                    155:                error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum),
                    156:                    cmd, &arg, retval, semid_copyin, semid_copyout);
                    157:        }
                    158:        return (error);
                    159: }
                    160: #endif /* SYSVSEM */
                    161:
                    162: #ifdef SYSVSHM
                    163: /*
                    164:  * Copy a struct shmid_ds23 from userland and convert to struct shmid_ds
                    165:  */
                    166: static int
                    167: shmid_copyin(const void *uaddr, void *kaddr, size_t len)
                    168: {
                    169:        struct shmid_ds *shmbuf = kaddr;
                    170:        struct shmid_ds23 oshmbuf;
                    171:        int error;
                    172:
                    173:        if (len != sizeof(struct shmid_ds))
                    174:                return (EFAULT);
                    175:        if ((error = copyin(uaddr, &oshmbuf, sizeof(oshmbuf))) == 0)
                    176:                cvt_ds(shmbuf, &oshmbuf, shm, shm_segsz);
                    177:        return (error);
                    178: }
                    179:
                    180: /*
                    181:  * Convert a struct shmid_ds to struct shmid_ds23 and copy to userland
                    182:  */
                    183: static int
                    184: shmid_copyout(const void *kaddr, void *uaddr, size_t len)
                    185: {
                    186:        const struct shmid_ds *shmbuf = kaddr;
                    187:        struct shmid_ds23 oshmbuf;
                    188:
                    189:        if (len != sizeof(struct shmid_ds))
                    190:                return (EFAULT);
                    191:        cvt_ds(&oshmbuf, shmbuf, shm, shm_segsz);
                    192:        return (copyout(&oshmbuf, uaddr, sizeof(oshmbuf)));
                    193: }
                    194:
                    195: /*
                    196:  * OpenBSD 2.3 shmctl(2) with 16bit values in struct ipcperm.
                    197:  */
                    198: int
                    199: compat_23_sys_shmctl(struct proc *p, void *v, register_t *retval)
                    200: {
                    201:        struct compat_23_sys_shmctl_args /* {
                    202:                syscallarg(int) shmid;
                    203:                syscallarg(int) cmd;
                    204:                syscallarg(struct shmid_ds23 *) buf;
                    205:        } */ *uap = v;
                    206:
                    207:        return (shmctl1(p, SCARG(uap, shmid), SCARG(uap, cmd),
                    208:            (caddr_t)SCARG(uap, buf), shmid_copyin, shmid_copyout));
                    209: }
                    210: #endif /* SYSVSHM */

CVSweb