1/* 2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#include <unistd.h> 24#include <sys/shm.h> 25 26/* 27 * Stub function to account for the differences in the ipc_perm structure, 28 * while maintaining binary backward compatibility. 29 * 30 * This is only the legacy behavior. 31 */ 32extern int __shmctl(int, int, void *); 33 34int 35shmctl(int shmid, int cmd, struct shmid_ds *ds) 36{ 37 struct __shmid_ds_old *ds_old = (struct __shmid_ds_old *)ds; 38 struct __shmid_ds_new ds2; 39 struct __shmid_ds_new *ds_new = &ds2; 40 int rv; 41 42#define _UP_CVT(x) ds_new-> x = ds_old-> x 43#define _DN_CVT(x) ds_old-> x = ds_new-> x 44 45 if (cmd == IPC_SET) { 46 /* convert before call */ 47 _UP_CVT(shm_perm.uid); 48 _UP_CVT(shm_perm.gid); 49 _UP_CVT(shm_perm.cuid); 50 _UP_CVT(shm_perm.cgid); 51 _UP_CVT(shm_perm.mode); 52 ds_new->shm_perm._seq = ds_old->shm_perm.seq; 53 ds_new->shm_perm._key = ds_old->shm_perm.key; 54 _UP_CVT(shm_segsz); 55 _UP_CVT(shm_lpid); 56 _UP_CVT(shm_cpid); 57 _UP_CVT(shm_nattch); 58 _UP_CVT(shm_atime); 59 _UP_CVT(shm_dtime); 60 _UP_CVT(shm_ctime); 61 _UP_CVT(shm_internal); 62 } 63 64 rv = __shmctl(shmid, cmd, (void *)ds_new); 65 66 if (cmd == IPC_STAT) { 67 /* convert after call */ 68 _DN_CVT(shm_perm.uid); /* warning! precision loss! */ 69 _DN_CVT(shm_perm.gid); /* warning! precision loss! */ 70 _DN_CVT(shm_perm.cuid); /* warning! precision loss! */ 71 _DN_CVT(shm_perm.cgid); /* warning! precision loss! */ 72 _DN_CVT(shm_perm.mode); 73 ds_old->shm_perm.seq = ds_new->shm_perm._seq; 74 ds_old->shm_perm.key = ds_new->shm_perm._key; 75 _DN_CVT(shm_segsz); 76 _DN_CVT(shm_lpid); 77 _DN_CVT(shm_cpid); 78 _DN_CVT(shm_nattch); 79 _DN_CVT(shm_atime); 80 _DN_CVT(shm_dtime); 81 _DN_CVT(shm_ctime); 82 _DN_CVT(shm_internal); 83 } 84 85 return (rv); 86} 87