linux_ipc.c (69539) | linux_ipc.c (83221) |
---|---|
1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/compat/linux/linux_ipc.c 69539 2000-12-03 01:30:31Z marcel $ | 28 * $FreeBSD: head/sys/compat/linux/linux_ipc.c 83221 2001-09-08 19:07:04Z marcel $ |
29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/sysproto.h> 34#include <sys/proc.h> 35#include <sys/sem.h> 36#include <sys/shm.h> 37 38#include <machine/../linux/linux.h> 39#include <machine/../linux/linux_proto.h> 40#include <compat/linux/linux_ipc.h> 41#include <compat/linux/linux_util.h> 42 | 29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/sysproto.h> 34#include <sys/proc.h> 35#include <sys/sem.h> 36#include <sys/shm.h> 37 38#include <machine/../linux/linux.h> 39#include <machine/../linux/linux_proto.h> 40#include <compat/linux/linux_ipc.h> 41#include <compat/linux/linux_util.h> 42 |
43struct linux_ipc_perm { 44 linux_key_t key; 45 unsigned short uid; 46 unsigned short gid; 47 unsigned short cuid; 48 unsigned short cgid; 49 unsigned short mode; 50 unsigned short seq; | 43struct l_ipc_perm { 44 l_key_t key; 45 l_uid16_t uid; 46 l_gid16_t gid; 47 l_uid16_t cuid; 48 l_gid16_t cgid; 49 l_ushort mode; 50 l_ushort seq; |
51}; 52 53static void | 51}; 52 53static void |
54linux_to_bsd_ipc_perm(struct linux_ipc_perm *lpp, struct ipc_perm *bpp) | 54linux_to_bsd_ipc_perm(struct l_ipc_perm *lpp, struct ipc_perm *bpp) |
55{ 56 bpp->key = lpp->key; 57 bpp->uid = lpp->uid; 58 bpp->gid = lpp->gid; 59 bpp->cuid = lpp->cuid; 60 bpp->cgid = lpp->cgid; 61 bpp->mode = lpp->mode; 62 bpp->seq = lpp->seq; 63} 64 65 66static void | 55{ 56 bpp->key = lpp->key; 57 bpp->uid = lpp->uid; 58 bpp->gid = lpp->gid; 59 bpp->cuid = lpp->cuid; 60 bpp->cgid = lpp->cgid; 61 bpp->mode = lpp->mode; 62 bpp->seq = lpp->seq; 63} 64 65 66static void |
67bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct linux_ipc_perm *lpp) | 67bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc_perm *lpp) |
68{ 69 lpp->key = bpp->key; 70 lpp->uid = bpp->uid; 71 lpp->gid = bpp->gid; 72 lpp->cuid = bpp->cuid; 73 lpp->cgid = bpp->cgid; 74 lpp->mode = bpp->mode; 75 lpp->seq = bpp->seq; 76} 77 | 68{ 69 lpp->key = bpp->key; 70 lpp->uid = bpp->uid; 71 lpp->gid = bpp->gid; 72 lpp->cuid = bpp->cuid; 73 lpp->cgid = bpp->cgid; 74 lpp->mode = bpp->mode; 75 lpp->seq = bpp->seq; 76} 77 |
78struct linux_semid_ds { 79 struct linux_ipc_perm sem_perm; 80 linux_time_t sem_otime; 81 linux_time_t sem_ctime; | 78struct l_semid_ds { 79 struct l_ipc_perm sem_perm; 80 l_time_t sem_otime; 81 l_time_t sem_ctime; |
82 void *sem_base; 83 void *sem_pending; 84 void *sem_pending_last; 85 void *undo; | 82 void *sem_base; 83 void *sem_pending; 84 void *sem_pending_last; 85 void *undo; |
86 ushort sem_nsems; | 86 l_ushort sem_nsems; |
87}; 88 | 87}; 88 |
89struct linux_shmid_ds { 90 struct linux_ipc_perm shm_perm; 91 int shm_segsz; 92 linux_time_t shm_atime; 93 linux_time_t shm_dtime; 94 linux_time_t shm_ctime; 95 ushort shm_cpid; 96 ushort shm_lpid; 97 short shm_nattch; 98 ushort private1; 99 void *private2; 100 void *private3; | 89struct l_shmid_ds { 90 struct l_ipc_perm shm_perm; 91 l_int shm_segsz; 92 l_time_t shm_atime; 93 l_time_t shm_dtime; 94 l_time_t shm_ctime; 95 l_ushort shm_cpid; 96 l_ushort shm_lpid; 97 l_short shm_nattch; 98 l_ushort private1; 99 void *private2; 100 void *private3; |
101}; 102 103static void | 101}; 102 103static void |
104linux_to_bsd_semid_ds(struct linux_semid_ds *lsp, struct semid_ds *bsp) | 104linux_to_bsd_semid_ds(struct l_semid_ds *lsp, struct semid_ds *bsp) |
105{ 106 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm); 107 bsp->sem_otime = lsp->sem_otime; 108 bsp->sem_ctime = lsp->sem_ctime; 109 bsp->sem_nsems = lsp->sem_nsems; 110 bsp->sem_base = lsp->sem_base; 111} 112 113static void | 105{ 106 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm); 107 bsp->sem_otime = lsp->sem_otime; 108 bsp->sem_ctime = lsp->sem_ctime; 109 bsp->sem_nsems = lsp->sem_nsems; 110 bsp->sem_base = lsp->sem_base; 111} 112 113static void |
114bsd_to_linux_semid_ds(struct semid_ds *bsp, struct linux_semid_ds *lsp) | 114bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid_ds *lsp) |
115{ 116 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm); 117 lsp->sem_otime = bsp->sem_otime; 118 lsp->sem_ctime = bsp->sem_ctime; 119 lsp->sem_nsems = bsp->sem_nsems; 120 lsp->sem_base = bsp->sem_base; 121} 122 123static void | 115{ 116 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm); 117 lsp->sem_otime = bsp->sem_otime; 118 lsp->sem_ctime = bsp->sem_ctime; 119 lsp->sem_nsems = bsp->sem_nsems; 120 lsp->sem_base = bsp->sem_base; 121} 122 123static void |
124linux_to_bsd_shmid_ds(struct linux_shmid_ds *lsp, struct shmid_ds *bsp) | 124linux_to_bsd_shmid_ds(struct l_shmid_ds *lsp, struct shmid_ds *bsp) |
125{ 126 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm); 127 bsp->shm_segsz = lsp->shm_segsz; 128 bsp->shm_lpid = lsp->shm_lpid; 129 bsp->shm_cpid = lsp->shm_cpid; 130 bsp->shm_nattch = lsp->shm_nattch; 131 bsp->shm_atime = lsp->shm_atime; 132 bsp->shm_dtime = lsp->shm_dtime; 133 bsp->shm_ctime = lsp->shm_ctime; 134 bsp->shm_internal = lsp->private3; /* this goes (yet) SOS */ 135} 136 137static void | 125{ 126 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm); 127 bsp->shm_segsz = lsp->shm_segsz; 128 bsp->shm_lpid = lsp->shm_lpid; 129 bsp->shm_cpid = lsp->shm_cpid; 130 bsp->shm_nattch = lsp->shm_nattch; 131 bsp->shm_atime = lsp->shm_atime; 132 bsp->shm_dtime = lsp->shm_dtime; 133 bsp->shm_ctime = lsp->shm_ctime; 134 bsp->shm_internal = lsp->private3; /* this goes (yet) SOS */ 135} 136 137static void |
138bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct linux_shmid_ds *lsp) | 138bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid_ds *lsp) |
139{ 140 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm); 141 lsp->shm_segsz = bsp->shm_segsz; 142 lsp->shm_lpid = bsp->shm_lpid; 143 lsp->shm_cpid = bsp->shm_cpid; 144 lsp->shm_nattch = bsp->shm_nattch; 145 lsp->shm_atime = bsp->shm_atime; 146 lsp->shm_dtime = bsp->shm_dtime; --- 5 unchanged lines hidden (view full) --- 152linux_semop(struct proc *p, struct linux_semop_args *args) 153{ 154 struct semop_args /* { 155 int semid; 156 struct sembuf *sops; 157 int nsops; 158 } */ bsd_args; 159 | 139{ 140 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm); 141 lsp->shm_segsz = bsp->shm_segsz; 142 lsp->shm_lpid = bsp->shm_lpid; 143 lsp->shm_cpid = bsp->shm_cpid; 144 lsp->shm_nattch = bsp->shm_nattch; 145 lsp->shm_atime = bsp->shm_atime; 146 lsp->shm_dtime = bsp->shm_dtime; --- 5 unchanged lines hidden (view full) --- 152linux_semop(struct proc *p, struct linux_semop_args *args) 153{ 154 struct semop_args /* { 155 int semid; 156 struct sembuf *sops; 157 int nsops; 158 } */ bsd_args; 159 |
160 bsd_args.semid = args->arg1; 161 bsd_args.sops = (struct sembuf *)args->ptr; 162 bsd_args.nsops = args->arg2; | 160 bsd_args.semid = args->semid; 161 bsd_args.sops = (struct sembuf *)args->tsops; 162 bsd_args.nsops = args->nsops; |
163 return semop(p, &bsd_args); 164} 165 166int 167linux_semget(struct proc *p, struct linux_semget_args *args) 168{ 169 struct semget_args /* { 170 key_t key; 171 int nsems; 172 int semflg; 173 } */ bsd_args; 174 | 163 return semop(p, &bsd_args); 164} 165 166int 167linux_semget(struct proc *p, struct linux_semget_args *args) 168{ 169 struct semget_args /* { 170 key_t key; 171 int nsems; 172 int semflg; 173 } */ bsd_args; 174 |
175 bsd_args.key = args->arg1; 176 bsd_args.nsems = args->arg2; 177 bsd_args.semflg = args->arg3; | 175 bsd_args.key = args->key; 176 bsd_args.nsems = args->nsems; 177 bsd_args.semflg = args->semflg; |
178 return semget(p, &bsd_args); 179} 180 181int 182linux_semctl(struct proc *p, struct linux_semctl_args *args) 183{ | 178 return semget(p, &bsd_args); 179} 180 181int 182linux_semctl(struct proc *p, struct linux_semctl_args *args) 183{ |
184 struct linux_semid_ds linux_semid; 185 struct semid_ds bsd_semid; | 184 struct l_semid_ds linux_semid; |
186 struct __semctl_args /* { | 185 struct __semctl_args /* { |
187 int semid; 188 int semnum; 189 int cmd; 190 union semun *arg; | 186 int semid; 187 int semnum; 188 int cmd; 189 union semun *arg; |
191 } */ bsd_args; | 190 } */ bsd_args; |
192 int error; 193 caddr_t sg, unptr, dsp, ldsp; | 191 int error; 192 union semun *unptr; 193 caddr_t sg; |
194 195 sg = stackgap_init(); | 194 195 sg = stackgap_init(); |
196 bsd_args.semid = args->arg1; 197 bsd_args.semnum = args->arg2; 198 bsd_args.cmd = args->arg3; 199 bsd_args.arg = (union semun *)args->ptr; | 196 bsd_args.semid = args->semid; 197 bsd_args.semnum = args->semnum; 198 bsd_args.arg = (union semun *)&args->arg; |
200 | 199 |
201 switch (args->arg3) { | 200 switch (args->cmd) { |
202 case LINUX_IPC_RMID: 203 bsd_args.cmd = IPC_RMID; 204 break; 205 case LINUX_GETNCNT: 206 bsd_args.cmd = GETNCNT; 207 break; 208 case LINUX_GETPID: 209 bsd_args.cmd = GETPID; --- 4 unchanged lines hidden (view full) --- 214 case LINUX_GETZCNT: 215 bsd_args.cmd = GETZCNT; 216 break; 217 case LINUX_SETVAL: 218 bsd_args.cmd = SETVAL; 219 break; 220 case LINUX_IPC_SET: 221 bsd_args.cmd = IPC_SET; | 201 case LINUX_IPC_RMID: 202 bsd_args.cmd = IPC_RMID; 203 break; 204 case LINUX_GETNCNT: 205 bsd_args.cmd = GETNCNT; 206 break; 207 case LINUX_GETPID: 208 bsd_args.cmd = GETPID; --- 4 unchanged lines hidden (view full) --- 213 case LINUX_GETZCNT: 214 bsd_args.cmd = GETZCNT; 215 break; 216 case LINUX_SETVAL: 217 bsd_args.cmd = SETVAL; 218 break; 219 case LINUX_IPC_SET: 220 bsd_args.cmd = IPC_SET; |
222 error = copyin(args->ptr, &ldsp, sizeof(ldsp)); | 221 error = copyin((caddr_t)args->arg.buf, &linux_semid, 222 sizeof(linux_semid)); |
223 if (error) | 223 if (error) |
224 return error; 225 error = copyin(ldsp, (caddr_t)&linux_semid, sizeof(linux_semid)); 226 if (error) 227 return error; 228 linux_to_bsd_semid_ds(&linux_semid, &bsd_semid); | 224 return (error); |
229 unptr = stackgap_alloc(&sg, sizeof(union semun)); | 225 unptr = stackgap_alloc(&sg, sizeof(union semun)); |
230 dsp = stackgap_alloc(&sg, sizeof(struct semid_ds)); 231 error = copyout((caddr_t)&bsd_semid, dsp, sizeof(bsd_semid)); 232 if (error) 233 return error; 234 error = copyout((caddr_t)&dsp, unptr, sizeof(dsp)); 235 if (error) 236 return error; 237 bsd_args.arg = (union semun *)unptr; | 226 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds)); 227 linux_to_bsd_semid_ds(&linux_semid, unptr->buf); 228 bsd_args.arg = unptr; |
238 return __semctl(p, &bsd_args); 239 case LINUX_IPC_STAT: 240 bsd_args.cmd = IPC_STAT; | 229 return __semctl(p, &bsd_args); 230 case LINUX_IPC_STAT: 231 bsd_args.cmd = IPC_STAT; |
241 unptr = stackgap_alloc(&sg, sizeof(union semun *)); 242 dsp = stackgap_alloc(&sg, sizeof(struct semid_ds)); 243 error = copyout((caddr_t)&dsp, unptr, sizeof(dsp)); 244 if (error) 245 return error; 246 bsd_args.arg = (union semun *)unptr; | 232 unptr = stackgap_alloc(&sg, sizeof(union semun)); 233 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds)); 234 bsd_args.arg = unptr; |
247 error = __semctl(p, &bsd_args); 248 if (error) 249 return error; | 235 error = __semctl(p, &bsd_args); 236 if (error) 237 return error; |
250 error = copyin(dsp, (caddr_t)&bsd_semid, sizeof(bsd_semid)); 251 if (error) 252 return error; 253 bsd_to_linux_semid_ds(&bsd_semid, &linux_semid); 254 error = copyin(args->ptr, &ldsp, sizeof(ldsp)); 255 if (error) 256 return error; 257 return copyout((caddr_t)&linux_semid, ldsp, sizeof(linux_semid)); | 238 bsd_to_linux_semid_ds(unptr->buf, &linux_semid); 239 return copyout(&linux_semid, (caddr_t)args->arg.buf, 240 sizeof(linux_semid)); |
258 case LINUX_GETALL: 259 /* FALLTHROUGH */ 260 case LINUX_SETALL: 261 /* FALLTHROUGH */ 262 default: | 241 case LINUX_GETALL: 242 /* FALLTHROUGH */ 243 case LINUX_SETALL: 244 /* FALLTHROUGH */ 245 default: |
263 uprintf("LINUX: 'ipc' typ=%d not implemented\n", args->arg3); | 246 uprintf("linux: 'ipc' typ=%d not implemented\n", args->cmd); |
264 return EINVAL; 265 } 266 return __semctl(p, &bsd_args); 267} 268 269int 270linux_msgsnd(struct proc *p, struct linux_msgsnd_args *args) 271{ 272 struct msgsnd_args /* { 273 int msqid; 274 void *msgp; 275 size_t msgsz; 276 int msgflg; 277 } */ bsd_args; 278 | 247 return EINVAL; 248 } 249 return __semctl(p, &bsd_args); 250} 251 252int 253linux_msgsnd(struct proc *p, struct linux_msgsnd_args *args) 254{ 255 struct msgsnd_args /* { 256 int msqid; 257 void *msgp; 258 size_t msgsz; 259 int msgflg; 260 } */ bsd_args; 261 |
279 bsd_args.msqid = args->arg1; 280 bsd_args.msgp = args->ptr; 281 bsd_args.msgsz = args->arg2; 282 bsd_args.msgflg = args->arg3; | 262 bsd_args.msqid = args->msqid; 263 bsd_args.msgp = args->msgp; 264 bsd_args.msgsz = args->msgsz; 265 bsd_args.msgflg = args->msgflg; |
283 return msgsnd(p, &bsd_args); 284} 285 286int 287linux_msgrcv(struct proc *p, struct linux_msgrcv_args *args) 288{ 289 struct msgrcv_args /* { 290 int msqid; 291 void *msgp; 292 size_t msgsz; 293 long msgtyp; 294 int msgflg; 295 } */ bsd_args; 296 | 266 return msgsnd(p, &bsd_args); 267} 268 269int 270linux_msgrcv(struct proc *p, struct linux_msgrcv_args *args) 271{ 272 struct msgrcv_args /* { 273 int msqid; 274 void *msgp; 275 size_t msgsz; 276 long msgtyp; 277 int msgflg; 278 } */ bsd_args; 279 |
297 bsd_args.msqid = args->arg1; 298 bsd_args.msgp = args->ptr; 299 bsd_args.msgsz = args->arg2; 300 bsd_args.msgtyp = 0; 301 bsd_args.msgflg = args->arg3; | 280 bsd_args.msqid = args->msqid; 281 bsd_args.msgp = args->msgp; 282 bsd_args.msgsz = args->msgsz; 283 bsd_args.msgtyp = 0; /* XXX - args->msgtyp; */ 284 bsd_args.msgflg = args->msgflg; |
302 return msgrcv(p, &bsd_args); 303} 304 305int 306linux_msgget(struct proc *p, struct linux_msgget_args *args) 307{ 308 struct msgget_args /* { 309 key_t key; 310 int msgflg; 311 } */ bsd_args; 312 | 285 return msgrcv(p, &bsd_args); 286} 287 288int 289linux_msgget(struct proc *p, struct linux_msgget_args *args) 290{ 291 struct msgget_args /* { 292 key_t key; 293 int msgflg; 294 } */ bsd_args; 295 |
313 bsd_args.key = args->arg1; 314 bsd_args.msgflg = args->arg2; | 296 bsd_args.key = args->key; 297 bsd_args.msgflg = args->msgflg; |
315 return msgget(p, &bsd_args); 316} 317 318int 319linux_msgctl(struct proc *p, struct linux_msgctl_args *args) 320{ 321 struct msgctl_args /* { 322 int msqid; 323 int cmd; 324 struct msqid_ds *buf; 325 } */ bsd_args; 326 int error; 327 | 298 return msgget(p, &bsd_args); 299} 300 301int 302linux_msgctl(struct proc *p, struct linux_msgctl_args *args) 303{ 304 struct msgctl_args /* { 305 int msqid; 306 int cmd; 307 struct msqid_ds *buf; 308 } */ bsd_args; 309 int error; 310 |
328 bsd_args.msqid = args->arg1; 329 bsd_args.cmd = args->arg2; 330 bsd_args.buf = (struct msqid_ds *)args->ptr; | 311 bsd_args.msqid = args->msqid; 312 bsd_args.cmd = args->cmd; 313 bsd_args.buf = (struct msqid_ds *)args->buf; |
331 error = msgctl(p, &bsd_args); | 314 error = msgctl(p, &bsd_args); |
332 return ((args->arg2 == LINUX_IPC_RMID && error == EINVAL) ? 0 : error); | 315 return ((args->cmd == LINUX_IPC_RMID && error == EINVAL) ? 0 : error); |
333} 334 335int 336linux_shmat(struct proc *p, struct linux_shmat_args *args) 337{ 338 struct shmat_args /* { 339 int shmid; 340 void *shmaddr; 341 int shmflg; 342 } */ bsd_args; 343 int error; 344 | 316} 317 318int 319linux_shmat(struct proc *p, struct linux_shmat_args *args) 320{ 321 struct shmat_args /* { 322 int shmid; 323 void *shmaddr; 324 int shmflg; 325 } */ bsd_args; 326 int error; 327 |
345 bsd_args.shmid = args->arg1; 346 bsd_args.shmaddr = args->ptr; 347 bsd_args.shmflg = args->arg2; | 328 bsd_args.shmid = args->shmid; 329 bsd_args.shmaddr = args->shmaddr; 330 bsd_args.shmflg = args->shmflg; |
348 if ((error = shmat(p, &bsd_args))) 349 return error; 350#ifdef __i386__ | 331 if ((error = shmat(p, &bsd_args))) 332 return error; 333#ifdef __i386__ |
351 if ((error = copyout(p->p_retval, (caddr_t)args->arg3, sizeof(int)))) | 334 if ((error = copyout(p->p_retval, (caddr_t)args->raddr, sizeof(l_ulong)))) |
352 return error; 353 p->p_retval[0] = 0; 354#endif 355 return 0; 356} 357 358int 359linux_shmdt(struct proc *p, struct linux_shmdt_args *args) 360{ 361 struct shmdt_args /* { 362 void *shmaddr; 363 } */ bsd_args; 364 | 335 return error; 336 p->p_retval[0] = 0; 337#endif 338 return 0; 339} 340 341int 342linux_shmdt(struct proc *p, struct linux_shmdt_args *args) 343{ 344 struct shmdt_args /* { 345 void *shmaddr; 346 } */ bsd_args; 347 |
365 bsd_args.shmaddr = args->ptr; | 348 bsd_args.shmaddr = args->shmaddr; |
366 return shmdt(p, &bsd_args); 367} 368 369int 370linux_shmget(struct proc *p, struct linux_shmget_args *args) 371{ 372 struct shmget_args /* { 373 key_t key; 374 int size; 375 int shmflg; 376 } */ bsd_args; 377 | 349 return shmdt(p, &bsd_args); 350} 351 352int 353linux_shmget(struct proc *p, struct linux_shmget_args *args) 354{ 355 struct shmget_args /* { 356 key_t key; 357 int size; 358 int shmflg; 359 } */ bsd_args; 360 |
378 bsd_args.key = args->arg1; 379 bsd_args.size = args->arg2; 380 bsd_args.shmflg = args->arg3; | 361 bsd_args.key = args->key; 362 bsd_args.size = args->size; 363 bsd_args.shmflg = args->shmflg; |
381 return shmget(p, &bsd_args); 382} 383 384int 385linux_shmctl(struct proc *p, struct linux_shmctl_args *args) 386{ | 364 return shmget(p, &bsd_args); 365} 366 367int 368linux_shmctl(struct proc *p, struct linux_shmctl_args *args) 369{ |
387 struct shmid_ds bsd_shmid; 388 struct linux_shmid_ds linux_shmid; | 370 struct l_shmid_ds linux_shmid; |
389 struct shmctl_args /* { 390 int shmid; 391 int cmd; 392 struct shmid_ds *buf; 393 } */ bsd_args; 394 int error; 395 caddr_t sg = stackgap_init(); 396 | 371 struct shmctl_args /* { 372 int shmid; 373 int cmd; 374 struct shmid_ds *buf; 375 } */ bsd_args; 376 int error; 377 caddr_t sg = stackgap_init(); 378 |
397 switch (args->arg2) { | 379 switch (args->cmd) { |
398 case LINUX_IPC_STAT: | 380 case LINUX_IPC_STAT: |
399 bsd_args.shmid = args->arg1; | 381 bsd_args.shmid = args->shmid; |
400 bsd_args.cmd = IPC_STAT; 401 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); 402 if ((error = shmctl(p, &bsd_args))) 403 return error; | 382 bsd_args.cmd = IPC_STAT; 383 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); 384 if ((error = shmctl(p, &bsd_args))) 385 return error; |
404 if ((error = copyin((caddr_t)bsd_args.buf, (caddr_t)&bsd_shmid, 405 sizeof(struct shmid_ds)))) 406 return error; 407 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid); 408 return copyout((caddr_t)&linux_shmid, args->ptr, sizeof(linux_shmid)); | 386 bsd_to_linux_shmid_ds(bsd_args.buf, &linux_shmid); 387 return copyout(&linux_shmid, (caddr_t)args->buf, sizeof(linux_shmid)); |
409 410 case LINUX_IPC_SET: | 388 389 case LINUX_IPC_SET: |
411 if ((error = copyin(args->ptr, (caddr_t)&linux_shmid, 412 sizeof(linux_shmid)))) | 390 if ((error = copyin((caddr_t)args->buf, &linux_shmid, 391 sizeof(linux_shmid)))) |
413 return error; | 392 return error; |
414 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid); | |
415 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); | 393 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); |
416 if ((error = copyout((caddr_t)&bsd_shmid, (caddr_t)bsd_args.buf, 417 sizeof(struct shmid_ds)))) 418 return error; 419 bsd_args.shmid = args->arg1; | 394 linux_to_bsd_shmid_ds(&linux_shmid, bsd_args.buf); 395 bsd_args.shmid = args->shmid; |
420 bsd_args.cmd = IPC_SET; 421 return shmctl(p, &bsd_args); 422 423 case LINUX_IPC_RMID: | 396 bsd_args.cmd = IPC_SET; 397 return shmctl(p, &bsd_args); 398 399 case LINUX_IPC_RMID: |
424 bsd_args.shmid = args->arg1; | 400 bsd_args.shmid = args->shmid; |
425 bsd_args.cmd = IPC_RMID; | 401 bsd_args.cmd = IPC_RMID; |
426 if (NULL == args->ptr) | 402 if (args->buf == NULL) |
427 bsd_args.buf = NULL; 428 else { | 403 bsd_args.buf = NULL; 404 else { |
429 if ((error = copyin(args->ptr, (caddr_t)&linux_shmid, | 405 if ((error = copyin((caddr_t)args->buf, &linux_shmid, |
430 sizeof(linux_shmid)))) 431 return error; | 406 sizeof(linux_shmid)))) 407 return error; |
432 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid); | |
433 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); | 408 bsd_args.buf = (struct shmid_ds*)stackgap_alloc(&sg, sizeof(struct shmid_ds)); |
434 if ((error = copyout((caddr_t)&bsd_shmid, (caddr_t)bsd_args.buf, 435 sizeof(struct shmid_ds)))) 436 return error; | 409 linux_to_bsd_shmid_ds(&linux_shmid, bsd_args.buf); |
437 } 438 return shmctl(p, &bsd_args); 439 440 case LINUX_IPC_INFO: 441 case LINUX_SHM_STAT: 442 case LINUX_SHM_INFO: 443 case LINUX_SHM_LOCK: 444 case LINUX_SHM_UNLOCK: 445 default: | 410 } 411 return shmctl(p, &bsd_args); 412 413 case LINUX_IPC_INFO: 414 case LINUX_SHM_STAT: 415 case LINUX_SHM_INFO: 416 case LINUX_SHM_LOCK: 417 case LINUX_SHM_UNLOCK: 418 default: |
446 uprintf("LINUX: 'ipc' typ=%d not implemented\n", args->arg2); | 419 uprintf("linux: 'ipc' typ=%d not implemented\n", args->cmd); |
447 return EINVAL; 448 } 449} | 420 return EINVAL; 421 } 422} |