From owner-svn-src-all@FreeBSD.ORG Fri Jul 31 20:32:56 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1C5F1106566C; Fri, 31 Jul 2009 20:32:56 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 062348FC12; Fri, 31 Jul 2009 20:32:56 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6VKWuOP080070; Fri, 31 Jul 2009 20:32:56 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6VKWtZG080053; Fri, 31 Jul 2009 20:32:55 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <200907312032.n6VKWtZG080053@svn.freebsd.org> From: John Baldwin Date: Fri, 31 Jul 2009 20:32:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196006 - in stable/7: . lib/libc lib/libc/gen lib/libc/include lib/libc/sys sys sys/compat/freebsd32 sys/compat/linux sys/compat/svr4 sys/contrib/pf sys/i386/ibcs2 sys/kern sys/sys usr... X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jul 2009 20:32:56 -0000 Author: jhb Date: Fri Jul 31 20:32:55 2009 New Revision: 196006 URL: http://svn.freebsd.org/changeset/base/196006 Log: MFC: Change the ABI of some of the structures used by the SYSV IPC API: - Various members of struct ipc_perm use appropriate types instead of unsigned short. - The shm_segsz member of struct shmid_ds is now a size_t instead of an int which should allow for complete support of SYSV SHM regions >= 2GB. - The shm_nattch member of struct shmid_ds is now an int instead of a short. - The existing versions of the __semctl(), msgctl(), and shmctl() system calls have been renamed to freebsd7_*() and implement the old ABI. New versions of these system calls provide the new ABI. The new system calls also use newer symbol versions in libc so old and new binaries will both work under new kernels. - Specific to 7.x: the kern_msgctl(), kern_semctl(), and kern_shmctl() functions now use ABI shims that transparently "rename" the functions to kern_new_*() for all new modules. Existing compat functions under the old names remain to provide compatibility for older kernel modules. Added: stable/7/lib/libc/include/compat.h - copied unchanged from r194910, head/lib/libc/include/compat.h Modified: stable/7/UPDATING stable/7/lib/libc/ (props changed) stable/7/lib/libc/gen/Symbol.map stable/7/lib/libc/gen/msgctl.3 stable/7/lib/libc/gen/semctl.c stable/7/lib/libc/sys/Makefile.inc stable/7/lib/libc/sys/Symbol.map stable/7/lib/libc/sys/semctl.2 stable/7/lib/libc/sys/shmctl.2 stable/7/sys/ (props changed) stable/7/sys/compat/freebsd32/freebsd32_ipc.h stable/7/sys/compat/freebsd32/freebsd32_misc.c stable/7/sys/compat/freebsd32/syscalls.master stable/7/sys/compat/linux/linux_ipc.c stable/7/sys/compat/svr4/svr4_ipc.c stable/7/sys/contrib/pf/ (props changed) stable/7/sys/i386/ibcs2/ibcs2_ipc.c stable/7/sys/kern/syscalls.master stable/7/sys/kern/sysv_ipc.c stable/7/sys/kern/sysv_msg.c stable/7/sys/kern/sysv_sem.c stable/7/sys/kern/sysv_shm.c stable/7/sys/sys/ipc.h stable/7/sys/sys/msg.h stable/7/sys/sys/param.h stable/7/sys/sys/sem.h stable/7/sys/sys/shm.h stable/7/sys/sys/syscallsubr.h stable/7/usr.bin/ipcs/ (props changed) stable/7/usr.bin/ipcs/ipcs.c Modified: stable/7/UPDATING ============================================================================== --- stable/7/UPDATING Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/UPDATING Fri Jul 31 20:32:55 2009 (r196006) @@ -8,6 +8,10 @@ Items affecting the ports and packages s /usr/ports/UPDATING. Please read that file before running portupgrade. +20090731: + The ABI of various structures related to the SYSV IPC API have + been changed. Bump __FreeBSD_version to 702105. + 20090606: The components of PmcTools have been upgraded. Please update world and the kernel. Modified: stable/7/lib/libc/gen/Symbol.map ============================================================================== --- stable/7/lib/libc/gen/Symbol.map Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/gen/Symbol.map Fri Jul 31 20:32:55 2009 (r196006) @@ -257,7 +257,6 @@ FBSD_1.0 { sem_timedwait; sem_post; sem_getvalue; - semctl; setdomainname; sethostname; longjmperror; @@ -339,6 +338,7 @@ FBSD_1.0 { FBSD_1.1 { fdopendir; feature_present; + semctl; }; FBSDprivate_1.0 { Modified: stable/7/lib/libc/gen/msgctl.3 ============================================================================== --- stable/7/lib/libc/gen/msgctl.3 Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/gen/msgctl.3 Fri Jul 31 20:32:55 2009 (r196006) @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\"/ -.Dd November 24, 1997 +.Dd April 3, 2008 .Dt MSGCTL 3 .Os .Sh NAME @@ -65,18 +65,14 @@ struct msqid_ds { struct ipc_perm msg_perm; /* msg queue permission bits */ struct msg *msg_first; /* first message in the queue */ struct msg *msg_last; /* last message in the queue */ - u_long msg_cbytes; /* number of bytes in use on the queue */ - u_long msg_qnum; /* number of msgs in the queue */ - u_long msg_qbytes; /* max # of bytes on the queue */ + msglen_t msg_cbytes; /* number of bytes in use on the queue */ + msgqnum_t msg_qnum; /* number of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ pid_t msg_lspid; /* pid of last msgsnd() */ pid_t msg_lrpid; /* pid of last msgrcv() */ time_t msg_stime; /* time of last msgsnd() */ - long msg_pad1; time_t msg_rtime; /* time of last msgrcv() */ - long msg_pad2; time_t msg_ctime; /* time of last msgctl() */ - long msg_pad3; - long msg_pad4[4]; }; .Ed .Pp @@ -89,13 +85,13 @@ structure is defined in and looks like this: .Bd -literal struct ipc_perm { - ushort cuid; /* creator user id */ - ushort cgid; /* creator group id */ - ushort uid; /* user id */ - ushort gid; /* group id */ - ushort mode; /* r/w permission */ - ushort seq; /* sequence # (to generate unique msg/sem/shm id) */ - key_t key; /* user specified msg/sem/shm key */ + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* r/w permission */ + unsigned short seq; /* sequence # (to generate unique ipcid) */ + key_t key; /* user specified msg/sem/shm key */ }; .Ed .Pp Modified: stable/7/lib/libc/gen/semctl.c ============================================================================== --- stable/7/lib/libc/gen/semctl.c Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/gen/semctl.c Fri Jul 31 20:32:55 2009 (r196006) @@ -29,15 +29,19 @@ #include __FBSDID("$FreeBSD$"); +#define _WANT_SEMUN_OLD + #include #include #include #include #include -extern int __semctl(int semid, int semnum, int cmd, union semun *arg); +int __semctl(int semid, int semnum, int cmd, union semun *arg); +int freebsd7___semctl(int semid, int semnum, int cmd, union semun_old *arg); -int semctl(int semid, int semnum, int cmd, ...) +int +semctl(int semid, int semnum, int cmd, ...) { va_list ap; union semun semun; @@ -55,3 +59,25 @@ int semctl(int semid, int semnum, int cm return (__semctl(semid, semnum, cmd, semun_ptr)); } + +int +freebsd7_semctl(int semid, int semnum, int cmd, ...) +{ + va_list ap; + union semun_old semun; + union semun_old *semun_ptr; + + va_start(ap, cmd); + if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL + || cmd == SETVAL || cmd == SETALL) { + semun = va_arg(ap, union semun_old); + semun_ptr = &semun; + } else { + semun_ptr = NULL; + } + va_end(ap); + + return (freebsd7___semctl(semid, semnum, cmd, semun_ptr)); +} + +__sym_compat(semctl, freebsd7_semctl, FBSD_1.0); Copied: stable/7/lib/libc/include/compat.h (from r194910, head/lib/libc/include/compat.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libc/include/compat.h Fri Jul 31 20:32:55 2009 (r196006, copy of r194910, head/lib/libc/include/compat.h) @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2009 Advanced Computing Technologies LLC + * Written by: John H. Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * This file defines compatiblity symbol versions for old system calls. It + * is included in all generated system call files. + */ + +#ifndef __LIBC_COMPAT_H__ +#define __LIBC_COMPAT_H__ + +#define __sym_compat(sym,impl,verid) \ + .symver impl , sym @ verid + +__sym_compat(__semctl, freebsd7___semctl, FBSD_1.0); +__sym_compat(msgctl, freebsd7_msgctl, FBSD_1.0); +__sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0); + +#undef __sym_compat + +#endif /* __LIBC_COMPAT_H__ */ + Modified: stable/7/lib/libc/sys/Makefile.inc ============================================================================== --- stable/7/lib/libc/sys/Makefile.inc Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/sys/Makefile.inc Fri Jul 31 20:32:55 2009 (r196006) @@ -53,11 +53,13 @@ SYM_MAPS+= ${.CURDIR}/sys/Symbol.map CLEANFILES+= ${SASM} ${SPSEUDO} ${SASM}: - printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' > ${.TARGET} + printf '#include "compat.h"\n' > ${.TARGET} + printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' >> ${.TARGET} ${SPSEUDO}: + printf '#include "compat.h"\n' > ${.TARGET} printf '#include "SYS.h"\nPSEUDO(${.PREFIX:S/_//})\n' \ - > ${.TARGET} + >> ${.TARGET} MAN+= _exit.2 abort2.2 accept.2 access.2 acct.2 adjtime.2 \ aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \ Modified: stable/7/lib/libc/sys/Symbol.map ============================================================================== --- stable/7/lib/libc/sys/Symbol.map Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/sys/Symbol.map Fri Jul 31 20:32:55 2009 (r196006) @@ -31,7 +31,6 @@ FBSD_1.0 { __mac_set_file; __mac_set_link; __mac_set_proc; - __semctl; __setugid; __syscall; __sysctl; @@ -190,7 +189,6 @@ FBSD_1.0 { modstat; mount; mprotect; - msgctl; msgget; msgrcv; msgsnd; @@ -271,7 +269,6 @@ FBSD_1.0 { settimeofday; setuid; shmat; - shmctl; shmdt; shmget; shmsys; @@ -336,13 +333,16 @@ FBSD_1.0 { }; FBSD_1.1 { + __semctl; closefrom; cpuset; cpuset_getid; cpuset_setid; cpuset_getaffinity; cpuset_setaffinity; + msgctl; setfib; + shmctl; }; FBSDprivate_1.0 { Modified: stable/7/lib/libc/sys/semctl.2 ============================================================================== --- stable/7/lib/libc/sys/semctl.2 Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/sys/semctl.2 Fri Jul 31 20:32:55 2009 (r196006) @@ -148,12 +148,9 @@ struct semid_ds { struct sem *sem_base; /* pointer to first semaphore in set */ u_short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ - long sem_pad1; /* SVABI/386 says I need this here */ time_t sem_ctime; /* last change time */ /* Times measured in secs since */ /* 00:00:00 GMT, Jan. 1, 1970 */ - long sem_pad2; /* SVABI/386 says I need this here */ - long sem_pad3[4]; /* SVABI/386 says I need this here */ }; .Ed .Sh RETURN VALUES Modified: stable/7/lib/libc/sys/shmctl.2 ============================================================================== --- stable/7/lib/libc/sys/shmctl.2 Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/lib/libc/sys/shmctl.2 Fri Jul 31 20:32:55 2009 (r196006) @@ -100,14 +100,13 @@ structure is defined as follows: .Bd -literal struct shmid_ds { struct ipc_perm shm_perm; /* operation permission structure */ - int shm_segsz; /* size of segment in bytes */ + size_t shm_segsz; /* size of segment in bytes */ pid_t shm_lpid; /* process ID of last shared memory op */ pid_t shm_cpid; /* process ID of creator */ - short shm_nattch; /* number of current attaches */ + int shm_nattch; /* number of current attaches */ time_t shm_atime; /* time of last shmat() */ time_t shm_dtime; /* time of last shmdt() */ time_t shm_ctime; /* time of last change by shmctl() */ - void *shm_internal; /* sysv stupidity */ }; .Ed .Sh RETURN VALUES @@ -133,16 +132,6 @@ the shared memory segment's owner or cre Permission denied due to mismatch between operation and mode of shared memory segment. .El -.Sh "BUGS" -The segment size has size_t type. -The shm_segsz member of the -.Vt shmid_ds -structure has type int, which is too short to represent the full range -of values for a segment size. -If shared memory limits are raised to allow segments with size > 2 GB -to be created, be aware that IPC_STAT call may return a truncated value -for shm_segsz. -.El .Sh "SEE ALSO" .Xr shmat 2 , .Xr shmdt 2 , Modified: stable/7/sys/compat/freebsd32/freebsd32_ipc.h ============================================================================== --- stable/7/sys/compat/freebsd32/freebsd32_ipc.h Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/compat/freebsd32/freebsd32_ipc.h Fri Jul 31 20:32:55 2009 (r196006) @@ -30,11 +30,11 @@ #define _COMPAT_FREEBSD32_FREEBSD32_IPC_H_ struct ipc_perm32 { - uint16_t cuid; - uint16_t cgid; - uint16_t uid; - uint16_t gid; - uint16_t mode; + uid_t cuid; + gid_t cgid; + uid_t uid; + gid_t gid; + mode_t mode; uint16_t seq; uint32_t key; }; @@ -44,10 +44,7 @@ struct semid_ds32 { uint32_t sem_base; unsigned short sem_nsems; int32_t sem_otime; - int32_t sem_pad1; int32_t sem_ctime; - int32_t sem_pad2; - int32_t sem_pad3[4]; }; union semun32 { @@ -66,24 +63,19 @@ struct msqid_ds32 { pid_t msg_lspid; pid_t msg_lrpid; int32_t msg_stime; - int32_t msg_pad1; int32_t msg_rtime; - int32_t msg_pad2; int32_t msg_ctime; - int32_t msg_pad3; - int32_t msg_pad4[4]; }; struct shmid_ds32 { struct ipc_perm32 shm_perm; int32_t shm_segsz; - int32_t shm_lpid; - int32_t shm_cpid; - int16_t shm_nattch; + pid_t shm_lpid; + pid_t shm_cpid; + int shm_nattch; int32_t shm_atime; int32_t shm_dtime; int32_t shm_ctime; - uint32_t shm_internal; }; struct shm_info32 { @@ -103,4 +95,55 @@ struct shminfo32 { uint32_t shmall; }; +struct ipc_perm32_old { + uint16_t cuid; + uint16_t cgid; + uint16_t uid; + uint16_t gid; + uint16_t mode; + uint16_t seq; + uint32_t key; +}; + +struct semid_ds32_old { + struct ipc_perm32_old sem_perm; + uint32_t sem_base; + unsigned short sem_nsems; + int32_t sem_otime; + int32_t sem_pad1; + int32_t sem_ctime; + int32_t sem_pad2; + int32_t sem_pad3[4]; +}; + +struct msqid_ds32_old { + struct ipc_perm32_old msg_perm; + uint32_t msg_first; + uint32_t msg_last; + uint32_t msg_cbytes; + uint32_t msg_qnum; + uint32_t msg_qbytes; + pid_t msg_lspid; + pid_t msg_lrpid; + int32_t msg_stime; + int32_t msg_pad1; + int32_t msg_rtime; + int32_t msg_pad2; + int32_t msg_ctime; + int32_t msg_pad3; + int32_t msg_pad4[4]; +}; + +struct shmid_ds32_old { + struct ipc_perm32_old shm_perm; + int32_t shm_segsz; + pid_t shm_lpid; + pid_t shm_cpid; + int16_t shm_nattch; + int32_t shm_atime; + int32_t shm_dtime; + int32_t shm_ctime; + uint32_t shm_internal; +}; + #endif /* !_COMPAT_FREEBSD32_FREEBSD32_IPC_H_ */ Modified: stable/7/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- stable/7/sys/compat/freebsd32/freebsd32_misc.c Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/compat/freebsd32/freebsd32_misc.c Fri Jul 31 20:32:55 2009 (r196006) @@ -1310,6 +1310,32 @@ freebsd4_freebsd32_fhstatfs(struct threa #endif static void +freebsd32_ipcperm_old_in(struct ipc_perm32_old *ip32, struct ipc_perm *ip) +{ + + CP(*ip32, *ip, cuid); + CP(*ip32, *ip, cgid); + CP(*ip32, *ip, uid); + CP(*ip32, *ip, gid); + CP(*ip32, *ip, mode); + CP(*ip32, *ip, seq); + CP(*ip32, *ip, key); +} + +static void +freebsd32_ipcperm_old_out(struct ipc_perm *ip, struct ipc_perm32_old *ip32) +{ + + CP(*ip, *ip32, cuid); + CP(*ip, *ip32, cgid); + CP(*ip, *ip32, uid); + CP(*ip, *ip32, gid); + CP(*ip, *ip32, mode); + CP(*ip, *ip32, seq); + CP(*ip, *ip32, key); +} + +static void freebsd32_ipcperm_in(struct ipc_perm32 *ip32, struct ipc_perm *ip) { @@ -1341,14 +1367,86 @@ freebsd32_semsys(struct thread *td, stru switch (uap->which) { case 0: - return (freebsd32_semctl(td, - (struct freebsd32_semctl_args *)&uap->a2)); + return (freebsd7_freebsd32_semctl(td, + (struct freebsd7_freebsd32_semctl_args *)&uap->a2)); default: return (semsys(td, (struct semsys_args *)uap)); } } int +freebsd7_freebsd32_semctl(struct thread *td, + struct freebsd7_freebsd32_semctl_args *uap) +{ + struct semid_ds32_old dsbuf32; + struct semid_ds dsbuf; + union semun semun; + union semun32 arg; + register_t rval; + int error; + + switch (uap->cmd) { + case SEM_STAT: + case IPC_SET: + case IPC_STAT: + case GETALL: + case SETVAL: + case SETALL: + error = copyin(uap->arg, &arg, sizeof(arg)); + if (error) + return (error); + break; + } + + switch (uap->cmd) { + case SEM_STAT: + case IPC_STAT: + semun.buf = &dsbuf; + break; + case IPC_SET: + error = copyin(PTRIN(arg.buf), &dsbuf32, sizeof(dsbuf32)); + if (error) + return (error); + freebsd32_ipcperm_old_in(&dsbuf32.sem_perm, &dsbuf.sem_perm); + PTRIN_CP(dsbuf32, dsbuf, sem_base); + CP(dsbuf32, dsbuf, sem_nsems); + CP(dsbuf32, dsbuf, sem_otime); + CP(dsbuf32, dsbuf, sem_ctime); + semun.buf = &dsbuf; + break; + case GETALL: + case SETALL: + semun.array = PTRIN(arg.array); + break; + case SETVAL: + semun.val = arg.val; + break; + } + + error = kern_semctl(td, uap->semid, uap->semnum, uap->cmd, &semun, + &rval); + if (error) + return (error); + + switch (uap->cmd) { + case SEM_STAT: + case IPC_STAT: + bzero(&dsbuf32, sizeof(dsbuf32)); + freebsd32_ipcperm_old_out(&dsbuf.sem_perm, &dsbuf32.sem_perm); + PTROUT_CP(dsbuf, dsbuf32, sem_base); + CP(dsbuf, dsbuf32, sem_nsems); + CP(dsbuf, dsbuf32, sem_otime); + CP(dsbuf, dsbuf32, sem_ctime); + error = copyout(&dsbuf32, PTRIN(arg.buf), sizeof(dsbuf32)); + break; + } + + if (error == 0) + td->td_retval[0] = rval; + return (error); +} + +int freebsd32_semctl(struct thread *td, struct freebsd32_semctl_args *uap) { struct semid_ds32 dsbuf32; @@ -1384,13 +1482,7 @@ freebsd32_semctl(struct thread *td, stru PTRIN_CP(dsbuf32, dsbuf, sem_base); CP(dsbuf32, dsbuf, sem_nsems); CP(dsbuf32, dsbuf, sem_otime); - CP(dsbuf32, dsbuf, sem_pad1); CP(dsbuf32, dsbuf, sem_ctime); - CP(dsbuf32, dsbuf, sem_pad2); - CP(dsbuf32, dsbuf, sem_pad3[0]); - CP(dsbuf32, dsbuf, sem_pad3[1]); - CP(dsbuf32, dsbuf, sem_pad3[2]); - CP(dsbuf32, dsbuf, sem_pad3[3]); semun.buf = &dsbuf; break; case GETALL: @@ -1410,17 +1502,12 @@ freebsd32_semctl(struct thread *td, stru switch (uap->cmd) { case SEM_STAT: case IPC_STAT: + bzero(&dsbuf32, sizeof(dsbuf32)); freebsd32_ipcperm_out(&dsbuf.sem_perm, &dsbuf32.sem_perm); PTROUT_CP(dsbuf, dsbuf32, sem_base); CP(dsbuf, dsbuf32, sem_nsems); CP(dsbuf, dsbuf32, sem_otime); - CP(dsbuf, dsbuf32, sem_pad1); CP(dsbuf, dsbuf32, sem_ctime); - CP(dsbuf, dsbuf32, sem_pad2); - CP(dsbuf, dsbuf32, sem_pad3[0]); - CP(dsbuf, dsbuf32, sem_pad3[1]); - CP(dsbuf, dsbuf32, sem_pad3[2]); - CP(dsbuf, dsbuf32, sem_pad3[3]); error = copyout(&dsbuf32, PTRIN(arg.buf), sizeof(dsbuf32)); break; } @@ -1436,8 +1523,8 @@ freebsd32_msgsys(struct thread *td, stru switch (uap->which) { case 0: - return (freebsd32_msgctl(td, - (struct freebsd32_msgctl_args *)&uap->a2)); + return (freebsd7_freebsd32_msgctl(td, + (struct freebsd7_freebsd32_msgctl_args *)&uap->a2)); case 2: return (freebsd32_msgsnd(td, (struct freebsd32_msgsnd_args *)&uap->a2)); @@ -1450,6 +1537,51 @@ freebsd32_msgsys(struct thread *td, stru } int +freebsd7_freebsd32_msgctl(struct thread *td, + struct freebsd7_freebsd32_msgctl_args *uap) +{ + struct msqid_ds msqbuf; + struct msqid_ds32_old msqbuf32; + int error; + + if (uap->cmd == IPC_SET) { + error = copyin(uap->buf, &msqbuf32, sizeof(msqbuf32)); + if (error) + return (error); + freebsd32_ipcperm_old_in(&msqbuf32.msg_perm, &msqbuf.msg_perm); + PTRIN_CP(msqbuf32, msqbuf, msg_first); + PTRIN_CP(msqbuf32, msqbuf, msg_last); + CP(msqbuf32, msqbuf, msg_cbytes); + CP(msqbuf32, msqbuf, msg_qnum); + CP(msqbuf32, msqbuf, msg_qbytes); + CP(msqbuf32, msqbuf, msg_lspid); + CP(msqbuf32, msqbuf, msg_lrpid); + CP(msqbuf32, msqbuf, msg_stime); + CP(msqbuf32, msqbuf, msg_rtime); + CP(msqbuf32, msqbuf, msg_ctime); + } + error = kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf); + if (error) + return (error); + if (uap->cmd == IPC_STAT) { + bzero(&msqbuf32, sizeof(msqbuf32)); + freebsd32_ipcperm_old_out(&msqbuf.msg_perm, &msqbuf32.msg_perm); + PTROUT_CP(msqbuf, msqbuf32, msg_first); + PTROUT_CP(msqbuf, msqbuf32, msg_last); + CP(msqbuf, msqbuf32, msg_cbytes); + CP(msqbuf, msqbuf32, msg_qnum); + CP(msqbuf, msqbuf32, msg_qbytes); + CP(msqbuf, msqbuf32, msg_lspid); + CP(msqbuf, msqbuf32, msg_lrpid); + CP(msqbuf, msqbuf32, msg_stime); + CP(msqbuf, msqbuf32, msg_rtime); + CP(msqbuf, msqbuf32, msg_ctime); + error = copyout(&msqbuf32, uap->buf, sizeof(struct msqid_ds32)); + } + return (error); +} + +int freebsd32_msgctl(struct thread *td, struct freebsd32_msgctl_args *uap) { struct msqid_ds msqbuf; @@ -1469,15 +1601,8 @@ freebsd32_msgctl(struct thread *td, stru CP(msqbuf32, msqbuf, msg_lspid); CP(msqbuf32, msqbuf, msg_lrpid); CP(msqbuf32, msqbuf, msg_stime); - CP(msqbuf32, msqbuf, msg_pad1); CP(msqbuf32, msqbuf, msg_rtime); - CP(msqbuf32, msqbuf, msg_pad2); CP(msqbuf32, msqbuf, msg_ctime); - CP(msqbuf32, msqbuf, msg_pad3); - CP(msqbuf32, msqbuf, msg_pad4[0]); - CP(msqbuf32, msqbuf, msg_pad4[1]); - CP(msqbuf32, msqbuf, msg_pad4[2]); - CP(msqbuf32, msqbuf, msg_pad4[3]); } error = kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf); if (error) @@ -1492,15 +1617,8 @@ freebsd32_msgctl(struct thread *td, stru CP(msqbuf, msqbuf32, msg_lspid); CP(msqbuf, msqbuf32, msg_lrpid); CP(msqbuf, msqbuf32, msg_stime); - CP(msqbuf, msqbuf32, msg_pad1); CP(msqbuf, msqbuf32, msg_rtime); - CP(msqbuf, msqbuf32, msg_pad2); CP(msqbuf, msqbuf32, msg_ctime); - CP(msqbuf, msqbuf32, msg_pad3); - CP(msqbuf, msqbuf32, msg_pad4[0]); - CP(msqbuf, msqbuf32, msg_pad4[1]); - CP(msqbuf, msqbuf32, msg_pad4[2]); - CP(msqbuf, msqbuf32, msg_pad4[3]); error = copyout(&msqbuf32, uap->buf, sizeof(struct msqid_ds32)); } return (error); @@ -1568,12 +1686,12 @@ freebsd32_shmsys(struct thread *td, stru return (sysent[SYS_shmget].sy_call(td, &ap)); } case 4: { /* shmctl */ - struct freebsd32_shmctl_args ap; + struct freebsd7_freebsd32_shmctl_args ap; ap.shmid = uap->a2; ap.cmd = uap->a3; ap.buf = PTRIN(uap->a4); - return (freebsd32_shmctl(td, &ap)); + return (freebsd7_freebsd32_shmctl(td, &ap)); } case 1: /* oshmctl */ default: @@ -1582,6 +1700,91 @@ freebsd32_shmsys(struct thread *td, stru } int +freebsd7_freebsd32_shmctl(struct thread *td, + struct freebsd7_freebsd32_shmctl_args *uap) +{ + int error = 0; + union { + struct shmid_ds shmid_ds; + struct shm_info shm_info; + struct shminfo shminfo; + } u; + union { + struct shmid_ds32_old shmid_ds32; + struct shm_info32 shm_info32; + struct shminfo32 shminfo32; + } u32; + size_t sz; + + if (uap->cmd == IPC_SET) { + if ((error = copyin(uap->buf, &u32.shmid_ds32, + sizeof(u32.shmid_ds32)))) + goto done; + freebsd32_ipcperm_old_in(&u32.shmid_ds32.shm_perm, + &u.shmid_ds.shm_perm); + CP(u32.shmid_ds32, u.shmid_ds, shm_segsz); + CP(u32.shmid_ds32, u.shmid_ds, shm_lpid); + CP(u32.shmid_ds32, u.shmid_ds, shm_cpid); + CP(u32.shmid_ds32, u.shmid_ds, shm_nattch); + CP(u32.shmid_ds32, u.shmid_ds, shm_atime); + CP(u32.shmid_ds32, u.shmid_ds, shm_dtime); + CP(u32.shmid_ds32, u.shmid_ds, shm_ctime); + } + + error = kern_shmctl(td, uap->shmid, uap->cmd, (void *)&u, &sz); + if (error) + goto done; + + /* Cases in which we need to copyout */ + switch (uap->cmd) { + case IPC_INFO: + CP(u.shminfo, u32.shminfo32, shmmax); + CP(u.shminfo, u32.shminfo32, shmmin); + CP(u.shminfo, u32.shminfo32, shmmni); + CP(u.shminfo, u32.shminfo32, shmseg); + CP(u.shminfo, u32.shminfo32, shmall); + error = copyout(&u32.shminfo32, uap->buf, + sizeof(u32.shminfo32)); + break; + case SHM_INFO: + CP(u.shm_info, u32.shm_info32, used_ids); + CP(u.shm_info, u32.shm_info32, shm_rss); + CP(u.shm_info, u32.shm_info32, shm_tot); + CP(u.shm_info, u32.shm_info32, shm_swp); + CP(u.shm_info, u32.shm_info32, swap_attempts); + CP(u.shm_info, u32.shm_info32, swap_successes); + error = copyout(&u32.shm_info32, uap->buf, + sizeof(u32.shm_info32)); + break; + case SHM_STAT: + case IPC_STAT: + freebsd32_ipcperm_old_out(&u.shmid_ds.shm_perm, + &u32.shmid_ds32.shm_perm); + if (u.shmid_ds.shm_segsz > INT32_MAX) + u32.shmid_ds32.shm_segsz = INT32_MAX; + else + CP(u.shmid_ds, u32.shmid_ds32, shm_segsz); + CP(u.shmid_ds, u32.shmid_ds32, shm_lpid); + CP(u.shmid_ds, u32.shmid_ds32, shm_cpid); + CP(u.shmid_ds, u32.shmid_ds32, shm_nattch); + CP(u.shmid_ds, u32.shmid_ds32, shm_atime); + CP(u.shmid_ds, u32.shmid_ds32, shm_dtime); + CP(u.shmid_ds, u32.shmid_ds32, shm_ctime); + u32.shmid_ds32.shm_internal = 0; + error = copyout(&u32.shmid_ds32, uap->buf, + sizeof(u32.shmid_ds32)); + break; + } + +done: + if (error) { + /* Invalidate the return value */ + td->td_retval[0] = -1; + } + return (error); +} + +int freebsd32_shmctl(struct thread *td, struct freebsd32_shmctl_args *uap) { int error = 0; @@ -1610,7 +1813,6 @@ freebsd32_shmctl(struct thread *td, stru CP(u32.shmid_ds32, u.shmid_ds, shm_atime); CP(u32.shmid_ds32, u.shmid_ds, shm_dtime); CP(u32.shmid_ds32, u.shmid_ds, shm_ctime); - PTRIN_CP(u32.shmid_ds32, u.shmid_ds, shm_internal); } error = kern_shmctl(td, uap->shmid, uap->cmd, (void *)&u, &sz); @@ -1642,14 +1844,16 @@ freebsd32_shmctl(struct thread *td, stru case IPC_STAT: freebsd32_ipcperm_out(&u.shmid_ds.shm_perm, &u32.shmid_ds32.shm_perm); - CP(u.shmid_ds, u32.shmid_ds32, shm_segsz); + if (u.shmid_ds.shm_segsz > INT32_MAX) + u32.shmid_ds32.shm_segsz = INT32_MAX; + else + CP(u.shmid_ds, u32.shmid_ds32, shm_segsz); CP(u.shmid_ds, u32.shmid_ds32, shm_lpid); CP(u.shmid_ds, u32.shmid_ds32, shm_cpid); CP(u.shmid_ds, u32.shmid_ds32, shm_nattch); CP(u.shmid_ds, u32.shmid_ds32, shm_atime); CP(u.shmid_ds, u32.shmid_ds32, shm_dtime); CP(u.shmid_ds, u32.shmid_ds32, shm_ctime); - PTROUT_CP(u.shmid_ds, u32.shmid_ds32, shm_internal); error = copyout(&u32.shmid_ds32, uap->buf, sizeof(u32.shmid_ds32)); break; Modified: stable/7/sys/compat/freebsd32/syscalls.master ============================================================================== --- stable/7/sys/compat/freebsd32/syscalls.master Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/compat/freebsd32/syscalls.master Fri Jul 31 20:32:55 2009 (r196006) @@ -406,15 +406,15 @@ ; The following were introduced with NetBSD/4.4Lite-2 ; They are initialized by thier respective modules/sysinits ; XXX PROBLEM!! -220 AUE_SEMCTL STD { int freebsd32_semctl(int semid, int semnum, \ - int cmd, union semun32 *arg); } +220 AUE_SEMCTL STD { int freebsd7_freebsd32_semctl(int semid, \ + int semnum, int cmd, union semun32 *arg); } 221 AUE_SEMGET NOPROTO { int semget(key_t key, int nsems, \ int semflg); } 222 AUE_SEMOP NOPROTO { int semop(int semid, struct sembuf *sops, \ u_int nsops); } 223 AUE_NULL UNIMPL semconfig -224 AUE_MSGCTL STD { int freebsd32_msgctl(int msqid, int cmd, \ - struct msqid_ds32 *buf); } +224 AUE_MSGCTL STD { int freebsd7_freebsd32_msgctl(int msqid, \ + int cmd, struct msqid_ds32_old *buf); } 225 AUE_MSGGET NOPROTO { int msgget(key_t key, int msgflg); } 226 AUE_MSGSND STD { int freebsd32_msgsnd(int msqid, void *msgp, \ size_t msgsz, int msgflg); } @@ -422,8 +422,8 @@ size_t msgsz, long msgtyp, int msgflg); } 228 AUE_SHMAT NOPROTO { int shmat(int shmid, void *shmaddr, \ int shmflg); } -229 AUE_SHMCTL STD { int freebsd32_shmctl(int shmid, int cmd, \ - struct shmid_ds *buf); } +229 AUE_SHMCTL STD { int freebsd7_freebsd32_shmctl(int shmid, \ + int cmd, struct shmid_ds32_old *buf); } 230 AUE_SHMDT NOPROTO { int shmdt(void *shmaddr); } 231 AUE_SHMGET NOPROTO { int shmget(key_t key, int size, \ int shmflg); } @@ -878,3 +878,9 @@ 507 AUE_NULL UNIMPL freebsd32_jail_set 508 AUE_NULL UNIMPL jail_remove 509 AUE_CLOSEFROM NOPROTO { int closefrom(int lowfd); } +510 AUE_SEMCTL STD { int freebsd32_semctl(int semid, int semnum, \ + int cmd, union semun32 *arg); } +511 AUE_MSGCTL STD { int freebsd32_msgctl(int msqid, int cmd, \ + struct msqid_ds32 *buf); } +512 AUE_SHMCTL STD { int freebsd32_shmctl(int shmid, int cmd, \ + struct shmid_ds32 *buf); } Modified: stable/7/sys/compat/linux/linux_ipc.c ============================================================================== --- stable/7/sys/compat/linux/linux_ipc.c Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/compat/linux/linux_ipc.c Fri Jul 31 20:32:55 2009 (r196006) @@ -230,23 +230,26 @@ linux_to_bsd_shmid_ds(struct l_shmid_ds bsp->shm_atime = lsp->shm_atime; bsp->shm_dtime = lsp->shm_dtime; bsp->shm_ctime = lsp->shm_ctime; - /* this goes (yet) SOS */ - bsp->shm_internal = PTRIN(lsp->private3); } static void 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; + if (bsp->shm_segsz > INT_MAX) + lsp->shm_segsz = INT_MAX; + else + lsp->shm_segsz = bsp->shm_segsz; lsp->shm_lpid = bsp->shm_lpid; lsp->shm_cpid = bsp->shm_cpid; - lsp->shm_nattch = bsp->shm_nattch; + if (bsp->shm_nattch > SHRT_MAX) + lsp->shm_nattch = SHRT_MAX; + else + lsp->shm_nattch = bsp->shm_nattch; lsp->shm_atime = bsp->shm_atime; lsp->shm_dtime = bsp->shm_dtime; lsp->shm_ctime = bsp->shm_ctime; - /* this goes (yet) SOS */ - lsp->private3 = PTROUT(bsp->shm_internal); + lsp->private3 = 0; } static void @@ -424,6 +427,15 @@ linux_shmid_pushdown(l_int ver, struct l { struct l_shmid64_ds linux_shmid64; + /* + * XXX: This is backwards and loses information in shm_nattch + * and shm_segsz. We should probably either expose the BSD + * shmid structure directly and convert it to either the + * non-64 or 64 variant directly or the code should always + * convert to the 64 variant and then truncate values into the + * non-64 variant if needed since the 64 variant has more + * precision. + */ if (ver == LINUX_IPC_64) { bzero(&linux_shmid64, sizeof(linux_shmid64)); Modified: stable/7/sys/compat/svr4/svr4_ipc.c ============================================================================== --- stable/7/sys/compat/svr4/svr4_ipc.c Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/compat/svr4/svr4_ipc.c Fri Jul 31 20:32:55 2009 (r196006) @@ -169,13 +169,12 @@ bsd_to_svr4_semid_ds(bds, sds) const struct semid_ds *bds; struct svr4_semid_ds *sds; { + bzero(sds, sizeof(*sds)); bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm); sds->sem_base = (struct svr4_sem *) bds->sem_base; sds->sem_nsems = bds->sem_nsems; sds->sem_otime = bds->sem_otime; - sds->sem_pad1 = bds->sem_pad1; sds->sem_ctime = bds->sem_ctime; - sds->sem_pad2 = bds->sem_pad2; } static void @@ -187,9 +186,7 @@ svr4_to_bsd_semid_ds(sds, bds) bds->sem_base = (struct sem *) bds->sem_base; bds->sem_nsems = sds->sem_nsems; bds->sem_otime = sds->sem_otime; - bds->sem_pad1 = sds->sem_pad1; bds->sem_ctime = sds->sem_ctime; - bds->sem_pad2 = sds->sem_pad2; } struct svr4_sys_semctl_args { @@ -350,6 +347,7 @@ bsd_to_svr4_msqid_ds(bds, sds) const struct msqid_ds *bds; struct svr4_msqid_ds *sds; { + bzero(sds, sizeof(*sds)); bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm); sds->msg_first = (struct svr4_msg *) bds->msg_first; sds->msg_last = (struct svr4_msg *) bds->msg_last; @@ -359,18 +357,8 @@ bsd_to_svr4_msqid_ds(bds, sds) sds->msg_lspid = bds->msg_lspid; sds->msg_lrpid = bds->msg_lrpid; sds->msg_stime = bds->msg_stime; - sds->msg_pad1 = bds->msg_pad1; sds->msg_rtime = bds->msg_rtime; - sds->msg_pad2 = bds->msg_pad2; sds->msg_ctime = bds->msg_ctime; - sds->msg_pad3 = bds->msg_pad3; - - /* use the padding for the rest of the fields */ - { - const short *pad = (const short *) bds->msg_pad4; - sds->msg_cv = pad[0]; - sds->msg_qnum_cv = pad[1]; - } } static void @@ -387,18 +375,8 @@ svr4_to_bsd_msqid_ds(sds, bds) bds->msg_lspid = sds->msg_lspid; bds->msg_lrpid = sds->msg_lrpid; bds->msg_stime = sds->msg_stime; - bds->msg_pad1 = sds->msg_pad1; bds->msg_rtime = sds->msg_rtime; - bds->msg_pad2 = sds->msg_pad2; bds->msg_ctime = sds->msg_ctime; - bds->msg_pad3 = sds->msg_pad3; - - /* use the padding for the rest of the fields */ - { - short *pad = (short *) bds->msg_pad4; - pad[0] = sds->msg_cv; - pad[1] = sds->msg_qnum_cv; - } } struct svr4_sys_msgsnd_args { @@ -543,20 +521,18 @@ bsd_to_svr4_shmid_ds(bds, sds) const struct shmid_ds *bds; struct svr4_shmid_ds *sds; { + bzero(sds, sizeof(*sds)); bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm); sds->shm_segsz = bds->shm_segsz; sds->shm_lkcnt = 0; sds->shm_lpid = bds->shm_lpid; sds->shm_cpid = bds->shm_cpid; - sds->shm_amp = bds->shm_internal; + sds->shm_amp = 0; sds->shm_nattch = bds->shm_nattch; sds->shm_cnattch = 0; sds->shm_atime = bds->shm_atime; - sds->shm_pad1 = 0; sds->shm_dtime = bds->shm_dtime; - sds->shm_pad2 = 0; sds->shm_ctime = bds->shm_ctime; - sds->shm_pad3 = 0; } static void @@ -568,7 +544,6 @@ svr4_to_bsd_shmid_ds(sds, bds) bds->shm_segsz = sds->shm_segsz; bds->shm_lpid = sds->shm_lpid; bds->shm_cpid = sds->shm_cpid; - bds->shm_internal = sds->shm_amp; bds->shm_nattch = sds->shm_nattch; bds->shm_atime = sds->shm_atime; bds->shm_dtime = sds->shm_dtime; Modified: stable/7/sys/i386/ibcs2/ibcs2_ipc.c ============================================================================== --- stable/7/sys/i386/ibcs2/ibcs2_ipc.c Fri Jul 31 19:13:16 2009 (r196005) +++ stable/7/sys/i386/ibcs2/ibcs2_ipc.c Fri Jul 31 20:32:55 2009 (r196006) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***