diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-05-03 17:38:49 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-05-03 17:38:49 +0000 |
commit | 7ee12b987c71eed938605394f2489b79a5bddd78 (patch) | |
tree | c476ccbe6a8e1e76cd7563cd6d01810d4fff3351 | |
parent | ca3f78ca5742c4bebeeeebecaa0d76df2987c4f7 (diff) |
POSIX says the length parameter for semop(2) and shmget(2) should be size_t.
Create new syscalls with the correct parameters and add compat versions
for the old ones under COMPAT_35.
-rw-r--r-- | sys/compat/common/Makefile | 8 | ||||
-rw-r--r-- | sys/compat/common/kern_ipc_35.c | 79 | ||||
-rw-r--r-- | sys/kern/syscalls.conf | 4 | ||||
-rw-r--r-- | sys/kern/syscalls.master | 17 | ||||
-rw-r--r-- | sys/kern/sysv_sem.c | 18 | ||||
-rw-r--r-- | sys/kern/sysv_shm.c | 7 | ||||
-rw-r--r-- | sys/sys/sem.h | 4 | ||||
-rw-r--r-- | sys/sys/shm.h | 4 |
8 files changed, 116 insertions, 25 deletions
diff --git a/sys/compat/common/Makefile b/sys/compat/common/Makefile index cd44db92fb3..90c4e67399f 100644 --- a/sys/compat/common/Makefile +++ b/sys/compat/common/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.16 2004/02/27 17:36:16 deraadt Exp $ +# $OpenBSD: Makefile,v 1.17 2004/05/03 17:38:48 millert Exp $ # $NetBSD: Makefile,v 1.8 1996/05/18 15:52:19 christos Exp $ LIB= compat @@ -10,9 +10,9 @@ MACHINE_ARCH= ${XMACHINE_ARCH} .PATH: ${COMPATDIR} SRCS= compat_exec.c compat_util.c compat_dir.c compat_vm.c \ - kern_exit_43.c kern_ipc_23.c kern_info_09.c kern_info_43.c \ - kern_resource_43.c kern_sig_43.c tty_43.c uipc_syscalls_43.c \ - vfs_syscalls_25.c vfs_syscalls_43.c vm_43.c + kern_exit_43.c kern_ipc_23.c kern_ipc_35.c kern_info_09.c \ + kern_info_43.c kern_resource_43.c kern_sig_43.c tty_43.c \ + uipc_syscalls_43.c vfs_syscalls_25.c vfs_syscalls_43.c vm_43.c # really, all machines where sizeof(int) != sizeof(long) .if (${MACHINE_ARCH} != "alpha") && (${MACHINE_ARCH} != "amd64") && \ diff --git a/sys/compat/common/kern_ipc_35.c b/sys/compat/common/kern_ipc_35.c new file mode 100644 index 00000000000..d3956b24070 --- /dev/null +++ b/sys/compat/common/kern_ipc_35.c @@ -0,0 +1,79 @@ +/* $OpenBSD: kern_ipc_35.c,v 1.1 2004/05/03 17:38:48 millert Exp $ */ + +/* + * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/proc.h> +#include <sys/sem.h> +#include <sys/shm.h> + +#include <sys/mount.h> +#include <sys/syscallargs.h> + +#ifdef SYSVMSG +/* + * Old-style shmget(2) used int for the size parameter, we now use size_t. + */ +int +compat_35_sys_shmget(struct proc *p, void *v, register_t *retval) +{ + struct compat_35_sys_shmget_args /* { + syscallarg(key_t) key; + syscallarg(int) size; + syscallarg(int) shmflg; + } */ *uap = v; + struct sys_shmget_args /* { + syscallarg(key_t) key; + syscallarg(size_t) size; + syscallarg(int) shmflg; + } */ shmget_args; + + SCARG(&shmget_args, key) = SCARG(uap, key); + SCARG(&shmget_args, size) = (size_t)SCARG(uap, size); + SCARG(&shmget_args, shmflg) = SCARG(uap, shmflg); + + return (sys_shmget(p, &shmget_args, retval)); +} +#endif + +#ifdef SYSVSEM +/* + * Old-style shmget(2) used u_int for the nsops parameter, we now use size_t. + */ +int +compat_35_sys_semop(struct proc *p, void *v, register_t *retval) +{ + struct compat_35_sys_semop_args /* { + syscallarg(int) semid; + syscallarg(struct sembuf *) sops; + syscallarg(u_int) nsops; + } */ *uap = v; + struct sys_semop_args /* { + syscallarg(int) semid; + syscallarg(struct sembuf *) sops; + syscallarg(size_t) nsops; + } */ semop_args; + + SCARG(&semop_args, semid) = SCARG(uap, semid); + SCARG(&semop_args, sops) = SCARG(uap, sops); + SCARG(&semop_args, nsops) = (size_t)SCARG(uap, nsops); + + return (sys_semop(p, &semop_args, retval)); +} +#endif diff --git a/sys/kern/syscalls.conf b/sys/kern/syscalls.conf index dfe018accce..a3ecd66c8d1 100644 --- a/sys/kern/syscalls.conf +++ b/sys/kern/syscalls.conf @@ -1,11 +1,11 @@ -# $OpenBSD: syscalls.conf,v 1.5 2001/05/16 17:14:35 millert Exp $ +# $OpenBSD: syscalls.conf,v 1.6 2004/05/03 17:38:48 millert Exp $ # $NetBSD: syscalls.conf,v 1.2 1994/10/26 06:45:57 cgd Exp $ sysnames="syscalls.c" sysnumhdr="../sys/syscall.h" syssw="init_sysent.c" sysarghdr="../sys/syscallargs.h" -compatopts="compat_43 compat_09 compat_10 compat_23 compat_25" +compatopts="compat_43 compat_09 compat_10 compat_23 compat_25 compat_35" libcompatopts="" switchname="sysent" diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 27b4f403fcd..f7d6f63b48a 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.68 2004/02/28 19:44:16 miod Exp $ +; $OpenBSD: syscalls.master,v 1.69 2004/05/03 17:38:48 millert Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -419,7 +419,7 @@ 220 COMPAT_23 { int sys___semctl(int semid, int semnum, int cmd, \ union semun *arg); } __osemctl 221 STD { int sys_semget(key_t key, int nsems, int semflg); } -222 STD { int sys_semop(int semid, struct sembuf *sops, \ +222 COMPAT_35 { int sys_semop(int semid, struct sembuf *sops, \ u_int nsops); } 223 OBSOL sys_semconfig #else @@ -448,7 +448,7 @@ 229 COMPAT_23 { int sys_shmctl(int shmid, int cmd, \ struct oshmid_ds *buf); } oshmctl 230 STD { int sys_shmdt(const void *shmaddr); } -231 STD { int sys_shmget(key_t key, int size, int shmflg); } +231 COMPAT_35 { int sys_shmget(key_t key, int size, int shmflg); } #else 228 UNIMPL shmat 229 UNIMPL shmctl @@ -575,3 +575,14 @@ 287 STD { int sys_closefrom(int fd); } 288 STD { int sys_sigaltstack(const struct sigaltstack *nss, \ struct sigaltstack *oss); } +#ifdef SYSVSHM +289 STD { int sys_shmget(key_t key, size_t size, int shmflg); } +#else +289 UNIMPL shmget +#endif +#ifdef SYSVSEM +290 STD { int sys_semop(int semid, struct sembuf *sops, \ + size_t nsops); } +#else +290 UNIMPL semop +#endif diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index f6024698520..8255a6f0160 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysv_sem.c,v 1.28 2004/03/17 19:54:24 millert Exp $ */ +/* $OpenBSD: sysv_sem.c,v 1.29 2004/05/03 17:38:48 millert Exp $ */ /* $NetBSD: sysv_sem.c,v 1.26 1996/02/09 19:00:25 christos Exp $ */ /* @@ -500,23 +500,23 @@ sys_semop(struct proc *p, void *v, register_t *retval) struct sys_semop_args /* { syscallarg(int) semid; syscallarg(struct sembuf *) sops; - syscallarg(u_int) nsops; + syscallarg(size_t) nsops; } */ *uap = v; #define NSOPS 8 struct sembuf sopbuf[NSOPS]; int semid = SCARG(uap, semid); - u_int nsops = SCARG(uap, nsops); + size_t nsops = SCARG(uap, nsops); struct sembuf *sops; struct semid_ds *semaptr; struct sembuf *sopptr = NULL; struct sem *semptr = NULL; struct sem_undo *suptr = NULL; struct ucred *cred = p->p_ucred; - u_int i, j; + size_t i, j; int do_wakeup, do_undos, error; - DPRINTF(("call to semop(%d, %p, %u)\n", semid, SCARG(uap, sops), - nsops)); + DPRINTF(("call to semop(%d, %p, %lu)\n", semid, SCARG(uap, sops), + (u_long)nsops)); semid = IPCID_TO_IX(semid); /* Convert back to zero origin */ @@ -535,9 +535,9 @@ sys_semop(struct proc *p, void *v, register_t *retval) if (nsops == 0) { *retval = 0; return (0); - } else if (nsops > (u_int)seminfo.semopm) { - DPRINTF(("too many sops (max=%d, nsops=%u)\n", seminfo.semopm, - nsops)); + } else if (nsops > (size_t)seminfo.semopm) { + DPRINTF(("too many sops (max=%d, nsops=%lu)\n", seminfo.semopm, + (u_long)nsops)); return (E2BIG); } diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 046c3bc2481..ff614d7655e 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysv_shm.c,v 1.42 2004/04/16 17:55:13 tedu Exp $ */ +/* $OpenBSD: sysv_shm.c,v 1.43 2004/05/03 17:38:48 millert Exp $ */ /* $NetBSD: sysv_shm.c,v 1.50 1998/10/21 22:24:29 tron Exp $ */ /* @@ -384,8 +384,9 @@ shmget_allocate_segment(struct proc *p, } */ *uap, int mode, register_t *retval) { + size_t size; key_t key; - int segnum, size; + int segnum; struct ucred *cred = p->p_ucred; struct shmid_ds *shmseg; struct shm_handle *shm_handle; @@ -457,7 +458,7 @@ sys_shmget(struct proc *p, void *v, register_t *retval) { struct sys_shmget_args /* { syscallarg(key_t) key; - syscallarg(int) size; + syscallarg(size_t) size; syscallarg(int) shmflg; } */ *uap = v; int segnum, mode, error; diff --git a/sys/sys/sem.h b/sys/sys/sem.h index 841ce80e502..809eb676ec1 100644 --- a/sys/sys/sem.h +++ b/sys/sys/sem.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sem.h,v 1.14 2003/12/17 20:40:56 millert Exp $ */ +/* $OpenBSD: sem.h,v 1.15 2004/05/03 17:38:47 millert Exp $ */ /* $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos Exp $ */ /* @@ -198,7 +198,7 @@ __BEGIN_DECLS int semctl(int, int, int, ...); int __semctl(int, int, int, union semun *); int semget(key_t, int, int); -int semop(int, struct sembuf *, u_int); +int semop(int, struct sembuf *, size_t); int semconfig(int); __END_DECLS #else diff --git a/sys/sys/shm.h b/sys/sys/shm.h index a18d4989b92..b02075d3950 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: shm.h,v 1.15 2003/10/12 23:44:39 millert Exp $ */ +/* $OpenBSD: shm.h,v 1.16 2004/05/03 17:38:47 millert Exp $ */ /* $NetBSD: shm.h,v 1.20 1996/04/09 20:55:35 cgd Exp $ */ /* @@ -166,7 +166,7 @@ __BEGIN_DECLS void *shmat(int, const void *, int); int shmctl(int, int, struct shmid_ds *); int shmdt(const void *); -int shmget(key_t, int, int); +int shmget(key_t, size_t, int); __END_DECLS #endif /* !_KERNEL */ |