bug.h, compiler.h: introduce compiletime_assert & BUILD_BUG_ON_MSG
[linux/fpc-iii.git] / ipc / compat.c
blob2547f29dcd1b5e00ab93ed37c594e93d6e1f5b75
1 /*
2 * 32 bit compatibility code for System V IPC
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
7 * Copyright (C) 2000 VA Linux Co
8 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
9 * Copyright (C) 2000 Hewlett-Packard Co.
10 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
11 * Copyright (C) 2000 Gerhard Tonn (ton@de.ibm.com)
12 * Copyright (C) 2000-2002 Andi Kleen, SuSE Labs (x86-64 port)
13 * Copyright (C) 2000 Silicon Graphics, Inc.
14 * Copyright (C) 2001 IBM
15 * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
16 * Copyright (C) 2004 Arnd Bergmann (arnd@arndb.de)
18 * This code is collected from the versions for sparc64, mips64, s390x, ia64,
19 * ppc64 and x86_64, all of which are based on the original sparc64 version
20 * by Jakub Jelinek.
23 #include <linux/compat.h>
24 #include <linux/errno.h>
25 #include <linux/highuid.h>
26 #include <linux/init.h>
27 #include <linux/msg.h>
28 #include <linux/shm.h>
29 #include <linux/syscalls.h>
30 #include <linux/ptrace.h>
32 #include <linux/mutex.h>
33 #include <asm/uaccess.h>
35 #include "util.h"
37 struct compat_msgbuf {
38 compat_long_t mtype;
39 char mtext[1];
42 struct compat_ipc_perm {
43 key_t key;
44 __compat_uid_t uid;
45 __compat_gid_t gid;
46 __compat_uid_t cuid;
47 __compat_gid_t cgid;
48 compat_mode_t mode;
49 unsigned short seq;
52 struct compat_semid_ds {
53 struct compat_ipc_perm sem_perm;
54 compat_time_t sem_otime;
55 compat_time_t sem_ctime;
56 compat_uptr_t sem_base;
57 compat_uptr_t sem_pending;
58 compat_uptr_t sem_pending_last;
59 compat_uptr_t undo;
60 unsigned short sem_nsems;
63 struct compat_msqid_ds {
64 struct compat_ipc_perm msg_perm;
65 compat_uptr_t msg_first;
66 compat_uptr_t msg_last;
67 compat_time_t msg_stime;
68 compat_time_t msg_rtime;
69 compat_time_t msg_ctime;
70 compat_ulong_t msg_lcbytes;
71 compat_ulong_t msg_lqbytes;
72 unsigned short msg_cbytes;
73 unsigned short msg_qnum;
74 unsigned short msg_qbytes;
75 compat_ipc_pid_t msg_lspid;
76 compat_ipc_pid_t msg_lrpid;
79 struct compat_shmid_ds {
80 struct compat_ipc_perm shm_perm;
81 int shm_segsz;
82 compat_time_t shm_atime;
83 compat_time_t shm_dtime;
84 compat_time_t shm_ctime;
85 compat_ipc_pid_t shm_cpid;
86 compat_ipc_pid_t shm_lpid;
87 unsigned short shm_nattch;
88 unsigned short shm_unused;
89 compat_uptr_t shm_unused2;
90 compat_uptr_t shm_unused3;
93 struct compat_ipc_kludge {
94 compat_uptr_t msgp;
95 compat_long_t msgtyp;
98 struct compat_shminfo64 {
99 compat_ulong_t shmmax;
100 compat_ulong_t shmmin;
101 compat_ulong_t shmmni;
102 compat_ulong_t shmseg;
103 compat_ulong_t shmall;
104 compat_ulong_t __unused1;
105 compat_ulong_t __unused2;
106 compat_ulong_t __unused3;
107 compat_ulong_t __unused4;
110 struct compat_shm_info {
111 compat_int_t used_ids;
112 compat_ulong_t shm_tot, shm_rss, shm_swp;
113 compat_ulong_t swap_attempts, swap_successes;
116 extern int sem_ctls[];
117 #define sc_semopm (sem_ctls[2])
119 static inline int compat_ipc_parse_version(int *cmd)
121 #ifdef CONFIG_ARCH_WANT_COMPAT_IPC_PARSE_VERSION
122 int version = *cmd & IPC_64;
124 /* this is tricky: architectures that have support for the old
125 * ipc structures in 64 bit binaries need to have IPC_64 set
126 * in cmd, the others need to have it cleared */
127 #ifndef ipc_parse_version
128 *cmd |= IPC_64;
129 #else
130 *cmd &= ~IPC_64;
131 #endif
132 return version;
133 #else
134 /* With the asm-generic APIs, we always use the 64-bit versions. */
135 return IPC_64;
136 #endif
139 static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64,
140 struct compat_ipc64_perm __user *up64)
142 int err;
144 err = __get_user(p64->uid, &up64->uid);
145 err |= __get_user(p64->gid, &up64->gid);
146 err |= __get_user(p64->mode, &up64->mode);
147 return err;
150 static inline int __get_compat_ipc_perm(struct ipc64_perm *p,
151 struct compat_ipc_perm __user *up)
153 int err;
155 err = __get_user(p->uid, &up->uid);
156 err |= __get_user(p->gid, &up->gid);
157 err |= __get_user(p->mode, &up->mode);
158 return err;
161 static inline int __put_compat_ipc64_perm(struct ipc64_perm *p64,
162 struct compat_ipc64_perm __user *up64)
164 int err;
166 err = __put_user(p64->key, &up64->key);
167 err |= __put_user(p64->uid, &up64->uid);
168 err |= __put_user(p64->gid, &up64->gid);
169 err |= __put_user(p64->cuid, &up64->cuid);
170 err |= __put_user(p64->cgid, &up64->cgid);
171 err |= __put_user(p64->mode, &up64->mode);
172 err |= __put_user(p64->seq, &up64->seq);
173 return err;
176 static inline int __put_compat_ipc_perm(struct ipc64_perm *p,
177 struct compat_ipc_perm __user *up)
179 int err;
180 __compat_uid_t u;
181 __compat_gid_t g;
183 err = __put_user(p->key, &up->key);
184 SET_UID(u, p->uid);
185 err |= __put_user(u, &up->uid);
186 SET_GID(g, p->gid);
187 err |= __put_user(g, &up->gid);
188 SET_UID(u, p->cuid);
189 err |= __put_user(u, &up->cuid);
190 SET_GID(g, p->cgid);
191 err |= __put_user(g, &up->cgid);
192 err |= __put_user(p->mode, &up->mode);
193 err |= __put_user(p->seq, &up->seq);
194 return err;
197 static inline int get_compat_semid64_ds(struct semid64_ds *s64,
198 struct compat_semid64_ds __user *up64)
200 if (!access_ok (VERIFY_READ, up64, sizeof(*up64)))
201 return -EFAULT;
202 return __get_compat_ipc64_perm(&s64->sem_perm, &up64->sem_perm);
205 static inline int get_compat_semid_ds(struct semid64_ds *s,
206 struct compat_semid_ds __user *up)
208 if (!access_ok (VERIFY_READ, up, sizeof(*up)))
209 return -EFAULT;
210 return __get_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
213 static inline int put_compat_semid64_ds(struct semid64_ds *s64,
214 struct compat_semid64_ds __user *up64)
216 int err;
218 if (!access_ok (VERIFY_WRITE, up64, sizeof(*up64)))
219 return -EFAULT;
220 err = __put_compat_ipc64_perm(&s64->sem_perm, &up64->sem_perm);
221 err |= __put_user(s64->sem_otime, &up64->sem_otime);
222 err |= __put_user(s64->sem_ctime, &up64->sem_ctime);
223 err |= __put_user(s64->sem_nsems, &up64->sem_nsems);
224 return err;
227 static inline int put_compat_semid_ds(struct semid64_ds *s,
228 struct compat_semid_ds __user *up)
230 int err;
232 if (!access_ok (VERIFY_WRITE, up, sizeof(*up)))
233 return -EFAULT;
234 err = __put_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
235 err |= __put_user(s->sem_otime, &up->sem_otime);
236 err |= __put_user(s->sem_ctime, &up->sem_ctime);
237 err |= __put_user(s->sem_nsems, &up->sem_nsems);
238 return err;
241 static long do_compat_semctl(int first, int second, int third, u32 pad)
243 union semun fourth;
244 int err, err2;
245 struct semid64_ds s64;
246 struct semid64_ds __user *up64;
247 int version = compat_ipc_parse_version(&third);
249 memset(&s64, 0, sizeof(s64));
251 if ((third & (~IPC_64)) == SETVAL)
252 fourth.val = (int) pad;
253 else
254 fourth.__pad = compat_ptr(pad);
255 switch (third & (~IPC_64)) {
256 case IPC_INFO:
257 case IPC_RMID:
258 case SEM_INFO:
259 case GETVAL:
260 case GETPID:
261 case GETNCNT:
262 case GETZCNT:
263 case GETALL:
264 case SETVAL:
265 case SETALL:
266 err = sys_semctl(first, second, third, fourth);
267 break;
269 case IPC_STAT:
270 case SEM_STAT:
271 up64 = compat_alloc_user_space(sizeof(s64));
272 fourth.__pad = up64;
273 err = sys_semctl(first, second, third, fourth);
274 if (err < 0)
275 break;
276 if (copy_from_user(&s64, up64, sizeof(s64)))
277 err2 = -EFAULT;
278 else if (version == IPC_64)
279 err2 = put_compat_semid64_ds(&s64, compat_ptr(pad));
280 else
281 err2 = put_compat_semid_ds(&s64, compat_ptr(pad));
282 if (err2)
283 err = -EFAULT;
284 break;
286 case IPC_SET:
287 if (version == IPC_64) {
288 err = get_compat_semid64_ds(&s64, compat_ptr(pad));
289 } else {
290 err = get_compat_semid_ds(&s64, compat_ptr(pad));
292 up64 = compat_alloc_user_space(sizeof(s64));
293 if (copy_to_user(up64, &s64, sizeof(s64)))
294 err = -EFAULT;
295 if (err)
296 break;
298 fourth.__pad = up64;
299 err = sys_semctl(first, second, third, fourth);
300 break;
302 default:
303 err = -EINVAL;
304 break;
306 return err;
309 long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz)
311 struct compat_msgbuf __user *msgp = dest;
312 size_t msgsz;
314 if (put_user(msg->m_type, &msgp->mtype))
315 return -EFAULT;
317 msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz;
318 if (store_msg(msgp->mtext, msg, msgsz))
319 return -EFAULT;
320 return msgsz;
323 #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
324 long compat_sys_semctl(int first, int second, int third, void __user *uptr)
326 u32 pad;
328 if (!uptr)
329 return -EINVAL;
330 if (get_user(pad, (u32 __user *) uptr))
331 return -EFAULT;
332 return do_compat_semctl(first, second, third, pad);
335 long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
337 struct compat_msgbuf __user *up = uptr;
338 long type;
340 if (first < 0)
341 return -EINVAL;
342 if (second < 0)
343 return -EINVAL;
345 if (get_user(type, &up->mtype))
346 return -EFAULT;
348 return do_msgsnd(first, type, up->mtext, second, third);
351 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
352 int version, void __user *uptr)
354 if (first < 0)
355 return -EINVAL;
356 if (second < 0)
357 return -EINVAL;
359 if (!version) {
360 struct compat_ipc_kludge ipck;
361 if (!uptr)
362 return -EINVAL;
363 if (copy_from_user (&ipck, uptr, sizeof(ipck)))
364 return -EFAULT;
365 uptr = compat_ptr(ipck.msgp);
366 msgtyp = ipck.msgtyp;
368 return do_msgrcv(first, uptr, second, msgtyp, third,
369 compat_do_msg_fill);
371 #else
372 long compat_sys_semctl(int semid, int semnum, int cmd, int arg)
374 return do_compat_semctl(semid, semnum, cmd, arg);
377 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
378 compat_ssize_t msgsz, int msgflg)
380 compat_long_t mtype;
382 if (get_user(mtype, &msgp->mtype))
383 return -EFAULT;
384 return do_msgsnd(msqid, mtype, msgp->mtext, (ssize_t)msgsz, msgflg);
387 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
388 compat_ssize_t msgsz, long msgtyp, int msgflg)
390 return do_msgrcv(msqid, msgp, (ssize_t)msgsz, msgtyp, msgflg,
391 compat_do_msg_fill);
393 #endif
395 static inline int get_compat_msqid64(struct msqid64_ds *m64,
396 struct compat_msqid64_ds __user *up64)
398 int err;
400 if (!access_ok(VERIFY_READ, up64, sizeof(*up64)))
401 return -EFAULT;
402 err = __get_compat_ipc64_perm(&m64->msg_perm, &up64->msg_perm);
403 err |= __get_user(m64->msg_qbytes, &up64->msg_qbytes);
404 return err;
407 static inline int get_compat_msqid(struct msqid64_ds *m,
408 struct compat_msqid_ds __user *up)
410 int err;
412 if (!access_ok(VERIFY_READ, up, sizeof(*up)))
413 return -EFAULT;
414 err = __get_compat_ipc_perm(&m->msg_perm, &up->msg_perm);
415 err |= __get_user(m->msg_qbytes, &up->msg_qbytes);
416 return err;
419 static inline int put_compat_msqid64_ds(struct msqid64_ds *m64,
420 struct compat_msqid64_ds __user *up64)
422 int err;
424 if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
425 return -EFAULT;
426 err = __put_compat_ipc64_perm(&m64->msg_perm, &up64->msg_perm);
427 err |= __put_user(m64->msg_stime, &up64->msg_stime);
428 err |= __put_user(m64->msg_rtime, &up64->msg_rtime);
429 err |= __put_user(m64->msg_ctime, &up64->msg_ctime);
430 err |= __put_user(m64->msg_cbytes, &up64->msg_cbytes);
431 err |= __put_user(m64->msg_qnum, &up64->msg_qnum);
432 err |= __put_user(m64->msg_qbytes, &up64->msg_qbytes);
433 err |= __put_user(m64->msg_lspid, &up64->msg_lspid);
434 err |= __put_user(m64->msg_lrpid, &up64->msg_lrpid);
435 return err;
438 static inline int put_compat_msqid_ds(struct msqid64_ds *m,
439 struct compat_msqid_ds __user *up)
441 int err;
443 if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
444 return -EFAULT;
445 err = __put_compat_ipc_perm(&m->msg_perm, &up->msg_perm);
446 err |= __put_user(m->msg_stime, &up->msg_stime);
447 err |= __put_user(m->msg_rtime, &up->msg_rtime);
448 err |= __put_user(m->msg_ctime, &up->msg_ctime);
449 err |= __put_user(m->msg_cbytes, &up->msg_cbytes);
450 err |= __put_user(m->msg_qnum, &up->msg_qnum);
451 err |= __put_user(m->msg_qbytes, &up->msg_qbytes);
452 err |= __put_user(m->msg_lspid, &up->msg_lspid);
453 err |= __put_user(m->msg_lrpid, &up->msg_lrpid);
454 return err;
457 long compat_sys_msgctl(int first, int second, void __user *uptr)
459 int err, err2;
460 struct msqid64_ds m64;
461 int version = compat_ipc_parse_version(&second);
462 void __user *p;
464 memset(&m64, 0, sizeof(m64));
466 switch (second & (~IPC_64)) {
467 case IPC_INFO:
468 case IPC_RMID:
469 case MSG_INFO:
470 err = sys_msgctl(first, second, uptr);
471 break;
473 case IPC_SET:
474 if (version == IPC_64) {
475 err = get_compat_msqid64(&m64, uptr);
476 } else {
477 err = get_compat_msqid(&m64, uptr);
479 if (err)
480 break;
481 p = compat_alloc_user_space(sizeof(m64));
482 if (copy_to_user(p, &m64, sizeof(m64)))
483 err = -EFAULT;
484 else
485 err = sys_msgctl(first, second, p);
486 break;
488 case IPC_STAT:
489 case MSG_STAT:
490 p = compat_alloc_user_space(sizeof(m64));
491 err = sys_msgctl(first, second, p);
492 if (err < 0)
493 break;
494 if (copy_from_user(&m64, p, sizeof(m64)))
495 err2 = -EFAULT;
496 else if (version == IPC_64)
497 err2 = put_compat_msqid64_ds(&m64, uptr);
498 else
499 err2 = put_compat_msqid_ds(&m64, uptr);
500 if (err2)
501 err = -EFAULT;
502 break;
504 default:
505 err = -EINVAL;
506 break;
508 return err;
511 #ifndef COMPAT_SHMLBA
512 #define COMPAT_SHMLBA SHMLBA
513 #endif
515 #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
516 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
517 void __user *uptr)
519 int err;
520 unsigned long raddr;
521 compat_ulong_t __user *uaddr;
523 if (version == 1)
524 return -EINVAL;
525 err = do_shmat(first, uptr, second, &raddr, COMPAT_SHMLBA);
526 if (err < 0)
527 return err;
528 uaddr = compat_ptr(third);
529 return put_user(raddr, uaddr);
531 #else
532 long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg)
534 unsigned long ret;
535 long err;
537 err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret, COMPAT_SHMLBA);
538 if (err)
539 return err;
540 force_successful_syscall_return();
541 return (long)ret;
543 #endif
545 static inline int get_compat_shmid64_ds(struct shmid64_ds *s64,
546 struct compat_shmid64_ds __user *up64)
548 if (!access_ok(VERIFY_READ, up64, sizeof(*up64)))
549 return -EFAULT;
550 return __get_compat_ipc64_perm(&s64->shm_perm, &up64->shm_perm);
553 static inline int get_compat_shmid_ds(struct shmid64_ds *s,
554 struct compat_shmid_ds __user *up)
556 if (!access_ok(VERIFY_READ, up, sizeof(*up)))
557 return -EFAULT;
558 return __get_compat_ipc_perm(&s->shm_perm, &up->shm_perm);
561 static inline int put_compat_shmid64_ds(struct shmid64_ds *s64,
562 struct compat_shmid64_ds __user *up64)
564 int err;
566 if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
567 return -EFAULT;
568 err = __put_compat_ipc64_perm(&s64->shm_perm, &up64->shm_perm);
569 err |= __put_user(s64->shm_atime, &up64->shm_atime);
570 err |= __put_user(s64->shm_dtime, &up64->shm_dtime);
571 err |= __put_user(s64->shm_ctime, &up64->shm_ctime);
572 err |= __put_user(s64->shm_segsz, &up64->shm_segsz);
573 err |= __put_user(s64->shm_nattch, &up64->shm_nattch);
574 err |= __put_user(s64->shm_cpid, &up64->shm_cpid);
575 err |= __put_user(s64->shm_lpid, &up64->shm_lpid);
576 return err;
579 static inline int put_compat_shmid_ds(struct shmid64_ds *s,
580 struct compat_shmid_ds __user *up)
582 int err;
584 if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
585 return -EFAULT;
586 err = __put_compat_ipc_perm(&s->shm_perm, &up->shm_perm);
587 err |= __put_user(s->shm_atime, &up->shm_atime);
588 err |= __put_user(s->shm_dtime, &up->shm_dtime);
589 err |= __put_user(s->shm_ctime, &up->shm_ctime);
590 err |= __put_user(s->shm_segsz, &up->shm_segsz);
591 err |= __put_user(s->shm_nattch, &up->shm_nattch);
592 err |= __put_user(s->shm_cpid, &up->shm_cpid);
593 err |= __put_user(s->shm_lpid, &up->shm_lpid);
594 return err;
597 static inline int put_compat_shminfo64(struct shminfo64 *smi,
598 struct compat_shminfo64 __user *up64)
600 int err;
602 if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
603 return -EFAULT;
604 if (smi->shmmax > INT_MAX)
605 smi->shmmax = INT_MAX;
606 err = __put_user(smi->shmmax, &up64->shmmax);
607 err |= __put_user(smi->shmmin, &up64->shmmin);
608 err |= __put_user(smi->shmmni, &up64->shmmni);
609 err |= __put_user(smi->shmseg, &up64->shmseg);
610 err |= __put_user(smi->shmall, &up64->shmall);
611 return err;
614 static inline int put_compat_shminfo(struct shminfo64 *smi,
615 struct shminfo __user *up)
617 int err;
619 if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
620 return -EFAULT;
621 if (smi->shmmax > INT_MAX)
622 smi->shmmax = INT_MAX;
623 err = __put_user(smi->shmmax, &up->shmmax);
624 err |= __put_user(smi->shmmin, &up->shmmin);
625 err |= __put_user(smi->shmmni, &up->shmmni);
626 err |= __put_user(smi->shmseg, &up->shmseg);
627 err |= __put_user(smi->shmall, &up->shmall);
628 return err;
631 static inline int put_compat_shm_info(struct shm_info __user *ip,
632 struct compat_shm_info __user *uip)
634 int err;
635 struct shm_info si;
637 if (!access_ok(VERIFY_WRITE, uip, sizeof(*uip)) ||
638 copy_from_user(&si, ip, sizeof(si)))
639 return -EFAULT;
640 err = __put_user(si.used_ids, &uip->used_ids);
641 err |= __put_user(si.shm_tot, &uip->shm_tot);
642 err |= __put_user(si.shm_rss, &uip->shm_rss);
643 err |= __put_user(si.shm_swp, &uip->shm_swp);
644 err |= __put_user(si.swap_attempts, &uip->swap_attempts);
645 err |= __put_user(si.swap_successes, &uip->swap_successes);
646 return err;
649 long compat_sys_shmctl(int first, int second, void __user *uptr)
651 void __user *p;
652 struct shmid64_ds s64;
653 struct shminfo64 smi;
654 int err, err2;
655 int version = compat_ipc_parse_version(&second);
657 memset(&s64, 0, sizeof(s64));
659 switch (second & (~IPC_64)) {
660 case IPC_RMID:
661 case SHM_LOCK:
662 case SHM_UNLOCK:
663 err = sys_shmctl(first, second, uptr);
664 break;
666 case IPC_INFO:
667 p = compat_alloc_user_space(sizeof(smi));
668 err = sys_shmctl(first, second, p);
669 if (err < 0)
670 break;
671 if (copy_from_user(&smi, p, sizeof(smi)))
672 err2 = -EFAULT;
673 else if (version == IPC_64)
674 err2 = put_compat_shminfo64(&smi, uptr);
675 else
676 err2 = put_compat_shminfo(&smi, uptr);
677 if (err2)
678 err = -EFAULT;
679 break;
682 case IPC_SET:
683 if (version == IPC_64) {
684 err = get_compat_shmid64_ds(&s64, uptr);
685 } else {
686 err = get_compat_shmid_ds(&s64, uptr);
688 if (err)
689 break;
690 p = compat_alloc_user_space(sizeof(s64));
691 if (copy_to_user(p, &s64, sizeof(s64)))
692 err = -EFAULT;
693 else
694 err = sys_shmctl(first, second, p);
695 break;
697 case IPC_STAT:
698 case SHM_STAT:
699 p = compat_alloc_user_space(sizeof(s64));
700 err = sys_shmctl(first, second, p);
701 if (err < 0)
702 break;
703 if (copy_from_user(&s64, p, sizeof(s64)))
704 err2 = -EFAULT;
705 else if (version == IPC_64)
706 err2 = put_compat_shmid64_ds(&s64, uptr);
707 else
708 err2 = put_compat_shmid_ds(&s64, uptr);
709 if (err2)
710 err = -EFAULT;
711 break;
713 case SHM_INFO:
714 p = compat_alloc_user_space(sizeof(struct shm_info));
715 err = sys_shmctl(first, second, p);
716 if (err < 0)
717 break;
718 err2 = put_compat_shm_info(p, uptr);
719 if (err2)
720 err = -EFAULT;
721 break;
723 default:
724 err = -EINVAL;
725 break;
727 return err;
730 long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
731 unsigned nsops, const struct compat_timespec __user *timeout)
733 struct timespec __user *ts64 = NULL;
734 if (timeout) {
735 struct timespec ts;
736 ts64 = compat_alloc_user_space(sizeof(*ts64));
737 if (get_compat_timespec(&ts, timeout))
738 return -EFAULT;
739 if (copy_to_user(ts64, &ts, sizeof(ts)))
740 return -EFAULT;
742 return sys_semtimedop(semid, tsems, nsops, ts64);