Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com) |
| 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
| 6 | #include "linux/sched.h" |
| 7 | #include "linux/shm.h" |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 8 | #include "linux/ipc.h" |
Al Viro | ff64b4c | 2008-08-18 04:01:47 -0400 | [diff] [blame] | 9 | #include "linux/syscalls.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "asm/mman.h" |
| 11 | #include "asm/uaccess.h" |
| 12 | #include "asm/unistd.h" |
| 13 | |
| 14 | /* |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 15 | * The prototype on i386 is: |
| 16 | * |
| 17 | * int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls, int * child_tidptr) |
| 18 | * |
| 19 | * and the "newtls" arg. on i386 is read by copy_thread directly from the |
| 20 | * register saved on the stack. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | long sys_clone(unsigned long clone_flags, unsigned long newsp, |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 23 | int __user *parent_tid, void *newtls, int __user *child_tid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
| 25 | long ret; |
| 26 | |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 27 | if (!newsp) |
| 28 | newsp = UPT_SP(¤t->thread.regs.regs); |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | current->thread.forking = 1; |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 31 | ret = do_fork(clone_flags, newsp, ¤t->thread.regs, 0, parent_tid, |
| 32 | child_tid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | current->thread.forking = 0; |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 34 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* |
| 38 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 39 | * |
| 40 | * This is really horribly ugly. |
| 41 | */ |
| 42 | long sys_ipc (uint call, int first, int second, |
| 43 | int third, void __user *ptr, long fifth) |
| 44 | { |
| 45 | int version, ret; |
| 46 | |
| 47 | version = call >> 16; /* hack for backward compatibility */ |
| 48 | call &= 0xffff; |
| 49 | |
| 50 | switch (call) { |
| 51 | case SEMOP: |
Al Viro | b8719c3 | 2006-06-04 02:51:48 -0700 | [diff] [blame] | 52 | return sys_semtimedop(first, (struct sembuf __user *) ptr, |
| 53 | second, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | case SEMTIMEDOP: |
Al Viro | b8719c3 | 2006-06-04 02:51:48 -0700 | [diff] [blame] | 55 | return sys_semtimedop(first, (struct sembuf __user *) ptr, |
| 56 | second, |
| 57 | (const struct timespec __user *) fifth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | case SEMGET: |
| 59 | return sys_semget (first, second, third); |
| 60 | case SEMCTL: { |
| 61 | union semun fourth; |
| 62 | if (!ptr) |
| 63 | return -EINVAL; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 64 | if (get_user(fourth.__pad, (void __user * __user *) ptr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | return -EFAULT; |
| 66 | return sys_semctl (first, second, third, fourth); |
| 67 | } |
| 68 | |
| 69 | case MSGSND: |
| 70 | return sys_msgsnd (first, (struct msgbuf *) ptr, |
| 71 | second, third); |
| 72 | case MSGRCV: |
| 73 | switch (version) { |
| 74 | case 0: { |
| 75 | struct ipc_kludge tmp; |
| 76 | if (!ptr) |
| 77 | return -EINVAL; |
| 78 | |
| 79 | if (copy_from_user(&tmp, |
| 80 | (struct ipc_kludge *) ptr, |
| 81 | sizeof (tmp))) |
| 82 | return -EFAULT; |
| 83 | return sys_msgrcv (first, tmp.msgp, second, |
| 84 | tmp.msgtyp, third); |
| 85 | } |
| 86 | default: |
| 87 | panic("msgrcv with version != 0"); |
| 88 | return sys_msgrcv (first, |
| 89 | (struct msgbuf *) ptr, |
| 90 | second, fifth, third); |
| 91 | } |
| 92 | case MSGGET: |
| 93 | return sys_msgget ((key_t) first, second); |
| 94 | case MSGCTL: |
| 95 | return sys_msgctl (first, second, (struct msqid_ds *) ptr); |
| 96 | |
| 97 | case SHMAT: |
| 98 | switch (version) { |
| 99 | default: { |
| 100 | ulong raddr; |
| 101 | ret = do_shmat (first, (char *) ptr, second, &raddr); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | return put_user (raddr, (ulong *) third); |
| 105 | } |
| 106 | case 1: /* iBCS2 emulator entry point */ |
| 107 | if (!segment_eq(get_fs(), get_ds())) |
| 108 | return -EINVAL; |
| 109 | return do_shmat (first, (char *) ptr, second, (ulong *) third); |
| 110 | } |
| 111 | case SHMDT: |
| 112 | return sys_shmdt ((char *)ptr); |
| 113 | case SHMGET: |
| 114 | return sys_shmget (first, second, third); |
| 115 | case SHMCTL: |
| 116 | return sys_shmctl (first, second, |
| 117 | (struct shmid_ds *) ptr); |
| 118 | default: |
| 119 | return -ENOSYS; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | long sys_sigaction(int sig, const struct old_sigaction __user *act, |
| 124 | struct old_sigaction __user *oact) |
| 125 | { |
| 126 | struct k_sigaction new_ka, old_ka; |
| 127 | int ret; |
| 128 | |
| 129 | if (act) { |
| 130 | old_sigset_t mask; |
| 131 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 132 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
| 133 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) |
| 134 | return -EFAULT; |
| 135 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 136 | __get_user(mask, &act->sa_mask); |
| 137 | siginitset(&new_ka.sa.sa_mask, mask); |
| 138 | } |
| 139 | |
| 140 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 141 | |
| 142 | if (!ret && oact) { |
| 143 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 144 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
| 145 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) |
| 146 | return -EFAULT; |
| 147 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 148 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); |
| 149 | } |
| 150 | |
| 151 | return ret; |
| 152 | } |