diff options
Diffstat (limited to 'sys/compat/linux/linux_ipc.c')
-rw-r--r-- | sys/compat/linux/linux_ipc.c | 225 |
1 files changed, 99 insertions, 126 deletions
diff --git a/sys/compat/linux/linux_ipc.c b/sys/compat/linux/linux_ipc.c index e68580f..de9b47a 100644 --- a/sys/compat/linux/linux_ipc.c +++ b/sys/compat/linux/linux_ipc.c @@ -40,18 +40,18 @@ #include <compat/linux/linux_ipc.h> #include <compat/linux/linux_util.h> -struct linux_ipc_perm { - linux_key_t key; - unsigned short uid; - unsigned short gid; - unsigned short cuid; - unsigned short cgid; - unsigned short mode; - unsigned short seq; +struct l_ipc_perm { + l_key_t key; + l_uid16_t uid; + l_gid16_t gid; + l_uid16_t cuid; + l_gid16_t cgid; + l_ushort mode; + l_ushort seq; }; static void -linux_to_bsd_ipc_perm(struct linux_ipc_perm *lpp, struct ipc_perm *bpp) +linux_to_bsd_ipc_perm(struct l_ipc_perm *lpp, struct ipc_perm *bpp) { bpp->key = lpp->key; bpp->uid = lpp->uid; @@ -64,7 +64,7 @@ linux_to_bsd_ipc_perm(struct linux_ipc_perm *lpp, struct ipc_perm *bpp) static void -bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct linux_ipc_perm *lpp) +bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc_perm *lpp) { lpp->key = bpp->key; lpp->uid = bpp->uid; @@ -75,33 +75,33 @@ bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct linux_ipc_perm *lpp) lpp->seq = bpp->seq; } -struct linux_semid_ds { - struct linux_ipc_perm sem_perm; - linux_time_t sem_otime; - linux_time_t sem_ctime; +struct l_semid_ds { + struct l_ipc_perm sem_perm; + l_time_t sem_otime; + l_time_t sem_ctime; void *sem_base; void *sem_pending; void *sem_pending_last; void *undo; - ushort sem_nsems; + l_ushort sem_nsems; }; -struct linux_shmid_ds { - struct linux_ipc_perm shm_perm; - int shm_segsz; - linux_time_t shm_atime; - linux_time_t shm_dtime; - linux_time_t shm_ctime; - ushort shm_cpid; - ushort shm_lpid; - short shm_nattch; - ushort private1; - void *private2; - void *private3; +struct l_shmid_ds { + struct l_ipc_perm shm_perm; + l_int shm_segsz; + l_time_t shm_atime; + l_time_t shm_dtime; + l_time_t shm_ctime; + l_ushort shm_cpid; + l_ushort shm_lpid; + l_short shm_nattch; + l_ushort private1; + void *private2; + void *private3; }; static void -linux_to_bsd_semid_ds(struct linux_semid_ds *lsp, struct semid_ds *bsp) +linux_to_bsd_semid_ds(struct l_semid_ds *lsp, struct semid_ds *bsp) { linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm); bsp->sem_otime = lsp->sem_otime; @@ -111,7 +111,7 @@ linux_to_bsd_semid_ds(struct linux_semid_ds *lsp, struct semid_ds *bsp) } static void -bsd_to_linux_semid_ds(struct semid_ds *bsp, struct linux_semid_ds *lsp) +bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid_ds *lsp) { bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm); lsp->sem_otime = bsp->sem_otime; @@ -121,7 +121,7 @@ bsd_to_linux_semid_ds(struct semid_ds *bsp, struct linux_semid_ds *lsp) } static void -linux_to_bsd_shmid_ds(struct linux_shmid_ds *lsp, struct shmid_ds *bsp) +linux_to_bsd_shmid_ds(struct l_shmid_ds *lsp, struct shmid_ds *bsp) { linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm); bsp->shm_segsz = lsp->shm_segsz; @@ -135,7 +135,7 @@ linux_to_bsd_shmid_ds(struct linux_shmid_ds *lsp, struct shmid_ds *bsp) } static void -bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct linux_shmid_ds *lsp) +bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid_ds *lsp) { bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm); lsp->shm_segsz = bsp->shm_segsz; @@ -157,9 +157,9 @@ linux_semop(struct proc *p, struct linux_semop_args *args) int nsops; } */ bsd_args; - bsd_args.semid = args->arg1; - bsd_args.sops = (struct sembuf *)args->ptr; - bsd_args.nsops = args->arg2; + bsd_args.semid = args->semid; + bsd_args.sops = (struct sembuf *)args->tsops; + bsd_args.nsops = args->nsops; return semop(p, &bsd_args); } @@ -172,33 +172,32 @@ linux_semget(struct proc *p, struct linux_semget_args *args) int semflg; } */ bsd_args; - bsd_args.key = args->arg1; - bsd_args.nsems = args->arg2; - bsd_args.semflg = args->arg3; + bsd_args.key = args->key; + bsd_args.nsems = args->nsems; + bsd_args.semflg = args->semflg; return semget(p, &bsd_args); } int linux_semctl(struct proc *p, struct linux_semctl_args *args) { - struct linux_semid_ds linux_semid; - struct semid_ds bsd_semid; + struct l_semid_ds linux_semid; struct __semctl_args /* { - int semid; - int semnum; - int cmd; - union semun *arg; + int semid; + int semnum; + int cmd; + union semun *arg; } */ bsd_args; - int error; - caddr_t sg, unptr, dsp, ldsp; + int error; + union semun *unptr; + caddr_t sg; sg = stackgap_init(); - bsd_args.semid = args->arg1; - bsd_args.semnum = args->arg2; - bsd_args.cmd = args->arg3; - bsd_args.arg = (union semun *)args->ptr; + bsd_args.semid = args->semid; + bsd_args.semnum = args->semnum; + bsd_args.arg = (union semun *)&args->arg; - switch (args->arg3) { + switch (args->cmd) { case LINUX_IPC_RMID: bsd_args.cmd = IPC_RMID; break; @@ -219,48 +218,32 @@ linux_semctl(struct proc *p, struct linux_semctl_args *args) break; case LINUX_IPC_SET: bsd_args.cmd = IPC_SET; - error = copyin(args->ptr, &ldsp, sizeof(ldsp)); + error = copyin((caddr_t)args->arg.buf, &linux_semid, + sizeof(linux_semid)); if (error) - return error; - error = copyin(ldsp, (caddr_t)&linux_semid, sizeof(linux_semid)); - if (error) - return error; - linux_to_bsd_semid_ds(&linux_semid, &bsd_semid); + return (error); unptr = stackgap_alloc(&sg, sizeof(union semun)); - dsp = stackgap_alloc(&sg, sizeof(struct semid_ds)); - error = copyout((caddr_t)&bsd_semid, dsp, sizeof(bsd_semid)); - if (error) - return error; - error = copyout((caddr_t)&dsp, unptr, sizeof(dsp)); - if (error) - return error; - bsd_args.arg = (union semun *)unptr; + unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds)); + linux_to_bsd_semid_ds(&linux_semid, unptr->buf); + bsd_args.arg = unptr; return __semctl(p, &bsd_args); case LINUX_IPC_STAT: bsd_args.cmd = IPC_STAT; - unptr = stackgap_alloc(&sg, sizeof(union semun *)); - dsp = stackgap_alloc(&sg, sizeof(struct semid_ds)); - error = copyout((caddr_t)&dsp, unptr, sizeof(dsp)); - if (error) - return error; - bsd_args.arg = (union semun *)unptr; + unptr = stackgap_alloc(&sg, sizeof(union semun)); + unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds)); + bsd_args.arg = unptr; error = __semctl(p, &bsd_args); if (error) return error; - error = copyin(dsp, (caddr_t)&bsd_semid, sizeof(bsd_semid)); - if (error) - return error; - bsd_to_linux_semid_ds(&bsd_semid, &linux_semid); - error = copyin(args->ptr, &ldsp, sizeof(ldsp)); - if (error) - return error; - return copyout((caddr_t)&linux_semid, ldsp, sizeof(linux_semid)); + bsd_to_linux_semid_ds(unptr->buf, &linux_semid); + return copyout(&linux_semid, (caddr_t)args->arg.buf, + sizeof(linux_semid)); case LINUX_GETALL: /* FALLTHROUGH */ case LINUX_SETALL: /* FALLTHROUGH */ default: - uprintf("LINUX: 'ipc' typ=%d not implemented\n", args->arg3); + uprintf("linux: 'ipc' typ=%d not implemented\n", args->cmd); return EINVAL; } return __semctl(p, &bsd_args); @@ -276,10 +259,10 @@ linux_msgsnd(struct proc *p, struct linux_msgsnd_args *args) int msgflg; } */ bsd_args; - bsd_args.msqid = args->arg1; - bsd_args.msgp = args->ptr; - bsd_args.msgsz = args->arg2; - bsd_args.msgflg = args->arg3; + bsd_args.msqid = args->msqid; + bsd_args.msgp = args->msgp; + bsd_args.msgsz = args->msgsz; + bsd_args.msgflg = args->msgflg; return msgsnd(p, &bsd_args); } @@ -294,11 +277,11 @@ linux_msgrcv(struct proc *p, struct linux_msgrcv_args *args) int msgflg; } */ bsd_args; - bsd_args.msqid = args->arg1; - bsd_args.msgp = args->ptr; - bsd_args.msgsz = args->arg2; - bsd_args.msgtyp = 0; - bsd_args.msgflg = args->arg3; + bsd_args.msqid = args->msqid; + bsd_args.msgp = args->msgp; + bsd_args.msgsz = args->msgsz; + bsd_args.msgtyp = 0; /* XXX - args->msgtyp; */ + bsd_args.msgflg = args->msgflg; return msgrcv(p, &bsd_args); } @@ -310,8 +293,8 @@ linux_msgget(struct proc *p, struct linux_msgget_args *args) int msgflg; } */ bsd_args; - bsd_args.key = args->arg1; - bsd_args.msgflg = args->arg2; + bsd_args.key = args->key; + bsd_args.msgflg = args->msgflg; return msgget(p, &bsd_args); } @@ -325,11 +308,11 @@ linux_msgctl(struct proc *p, struct linux_msgctl_args *args) } */ bsd_args; int error; - bsd_args.msqid = args->arg1; - bsd_args.cmd = args->arg2; - bsd_args.buf = (struct msqid_ds *)args->ptr; + bsd_args.msqid = args->msqid; + bsd_args.cmd = args->cmd; + bsd_args.buf = (struct msqid_ds *)args->buf; error = msgctl(p, &bsd_args); - return ((args->arg2 == LINUX_IPC_RMID && error == EINVAL) ? 0 : error); + return ((args->cmd == LINUX_IPC_RMID && error == EINVAL) ? 0 : error); } int @@ -342,13 +325,13 @@ linux_shmat(struct proc *p, struct linux_shmat_args *args) } */ bsd_args; int error; - bsd_args.shmid = args->arg1; - bsd_args.shmaddr = args->ptr; - bsd_args.shmflg = args->arg2; + bsd_args.shmid = args->shmid; + bsd_args.shmaddr = args->shmaddr; + bsd_args.shmflg = args->shmflg; if ((error = shmat(p, &bsd_args))) return error; #ifdef __i386__ - if ((error = copyout(p->p_retval, (caddr_t)args->arg3, sizeof(int)))) + if ((error = copyout(p->p_retval, (caddr_t)args->raddr, sizeof(l_ulong)))) return error; p->p_retval[0] = 0; #endif @@ -362,7 +345,7 @@ linux_shmdt(struct proc *p, struct linux_shmdt_args *args) void *shmaddr; } */ bsd_args; - bsd_args.shmaddr = args->ptr; + bsd_args.shmaddr = args->shmaddr; return shmdt(p, &bsd_args); } @@ -375,17 +358,16 @@ linux_shmget(struct proc *p, struct linux_shmget_args *args) int shmflg; } */ bsd_args; - bsd_args.key = args->arg1; - bsd_args.size = args->arg2; - bsd_args.shmflg = args->arg3; + bsd_args.key = args->key; + bsd_args.size = args->size; + bsd_args.shmflg = args->shmflg; return shmget(p, &bsd_args); } int linux_shmctl(struct proc *p, struct linux_shmctl_args *args) { - struct shmid_ds bsd_shmid; - struct linux_shmid_ds linux_shmid; + struct l_shmid_ds linux_shmid; struct shmctl_args /* { int shmid; int cmd; @@ -394,46 +376,37 @@ linux_shmctl(struct proc *p, struct linux_shmctl_args *args) int error; caddr_t sg = stackgap_init(); - switch (args->arg2) { + switch (args->cmd) { case LINUX_IPC_STAT: - bsd_args.shmid = args->arg1; + bsd_args.shmid = args->shmid; bsd_args.cmd = IPC_STAT; bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); if ((error = shmctl(p, &bsd_args))) return error; - if ((error = copyin((caddr_t)bsd_args.buf, (caddr_t)&bsd_shmid, - sizeof(struct shmid_ds)))) - return error; - bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid); - return copyout((caddr_t)&linux_shmid, args->ptr, sizeof(linux_shmid)); + bsd_to_linux_shmid_ds(bsd_args.buf, &linux_shmid); + return copyout(&linux_shmid, (caddr_t)args->buf, sizeof(linux_shmid)); case LINUX_IPC_SET: - if ((error = copyin(args->ptr, (caddr_t)&linux_shmid, - sizeof(linux_shmid)))) + if ((error = copyin((caddr_t)args->buf, &linux_shmid, + sizeof(linux_shmid)))) return error; - linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid); bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); - if ((error = copyout((caddr_t)&bsd_shmid, (caddr_t)bsd_args.buf, - sizeof(struct shmid_ds)))) - return error; - bsd_args.shmid = args->arg1; + linux_to_bsd_shmid_ds(&linux_shmid, bsd_args.buf); + bsd_args.shmid = args->shmid; bsd_args.cmd = IPC_SET; return shmctl(p, &bsd_args); case LINUX_IPC_RMID: - bsd_args.shmid = args->arg1; + bsd_args.shmid = args->shmid; bsd_args.cmd = IPC_RMID; - if (NULL == args->ptr) + if (args->buf == NULL) bsd_args.buf = NULL; else { - if ((error = copyin(args->ptr, (caddr_t)&linux_shmid, + if ((error = copyin((caddr_t)args->buf, &linux_shmid, sizeof(linux_shmid)))) return error; - linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid); bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); - if ((error = copyout((caddr_t)&bsd_shmid, (caddr_t)bsd_args.buf, - sizeof(struct shmid_ds)))) - return error; + linux_to_bsd_shmid_ds(&linux_shmid, bsd_args.buf); } return shmctl(p, &bsd_args); @@ -443,7 +416,7 @@ linux_shmctl(struct proc *p, struct linux_shmctl_args *args) case LINUX_SHM_LOCK: case LINUX_SHM_UNLOCK: default: - uprintf("LINUX: 'ipc' typ=%d not implemented\n", args->arg2); + uprintf("linux: 'ipc' typ=%d not implemented\n", args->cmd); return EINVAL; } } |