fix mismerge in ll_rw_blk.c
[pandora-kernel.git] / arch / um / sys-i386 / syscalls.c
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"
8 #include "asm/ipc.h"
9 #include "asm/mman.h"
10 #include "asm/uaccess.h"
11 #include "asm/unistd.h"
12
13 /*
14  * Perform the select(nd, in, out, ex, tv) and mmap() system
15  * calls. Linux/i386 didn't use to be able to handle more than
16  * 4 system call parameters, so these system calls used a memory
17  * block for parameter passing..
18  */
19
20 struct mmap_arg_struct {
21         unsigned long addr;
22         unsigned long len;
23         unsigned long prot;
24         unsigned long flags;
25         unsigned long fd;
26         unsigned long offset;
27 };
28
29 extern int old_mmap(unsigned long addr, unsigned long len,
30                     unsigned long prot, unsigned long flags,
31                     unsigned long fd, unsigned long offset);
32
33 long old_mmap_i386(struct mmap_arg_struct __user *arg)
34 {
35         struct mmap_arg_struct a;
36         int err = -EFAULT;
37
38         if (copy_from_user(&a, arg, sizeof(a)))
39                 goto out;
40
41         err = old_mmap(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
42  out:
43         return err;
44 }
45
46 struct sel_arg_struct {
47         unsigned long n;
48         fd_set __user *inp;
49         fd_set __user *outp;
50         fd_set __user *exp;
51         struct timeval __user *tvp;
52 };
53
54 long old_select(struct sel_arg_struct __user *arg)
55 {
56         struct sel_arg_struct a;
57
58         if (copy_from_user(&a, arg, sizeof(a)))
59                 return -EFAULT;
60         /* sys_select() does the appropriate kernel locking */
61         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
62 }
63
64 /* The i386 version skips reading from %esi, the fourth argument. So we must do
65  * this, too.
66  */
67 long sys_clone(unsigned long clone_flags, unsigned long newsp,
68                int __user *parent_tid, int unused, int __user *child_tid)
69 {
70         long ret;
71
72         if (!newsp)
73                 newsp = UPT_SP(&current->thread.regs.regs);
74         current->thread.forking = 1;
75         ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
76                       child_tid);
77         current->thread.forking = 0;
78         return(ret);
79 }
80
81 /*
82  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
83  *
84  * This is really horribly ugly.
85  */
86 long sys_ipc (uint call, int first, int second,
87              int third, void __user *ptr, long fifth)
88 {
89         int version, ret;
90
91         version = call >> 16; /* hack for backward compatibility */
92         call &= 0xffff;
93
94         switch (call) {
95         case SEMOP:
96                 return sys_semtimedop(first, (struct sembuf *) ptr, second,
97                                       NULL);
98         case SEMTIMEDOP:
99                 return sys_semtimedop(first, (struct sembuf *) ptr, second,
100                                       (const struct timespec *) fifth);
101         case SEMGET:
102                 return sys_semget (first, second, third);
103         case SEMCTL: {
104                 union semun fourth;
105                 if (!ptr)
106                         return -EINVAL;
107                 if (get_user(fourth.__pad, (void **) ptr))
108                         return -EFAULT;
109                 return sys_semctl (first, second, third, fourth);
110         }
111
112         case MSGSND:
113                 return sys_msgsnd (first, (struct msgbuf *) ptr,
114                                    second, third);
115         case MSGRCV:
116                 switch (version) {
117                 case 0: {
118                         struct ipc_kludge tmp;
119                         if (!ptr)
120                                 return -EINVAL;
121
122                         if (copy_from_user(&tmp,
123                                            (struct ipc_kludge *) ptr,
124                                            sizeof (tmp)))
125                                 return -EFAULT;
126                         return sys_msgrcv (first, tmp.msgp, second,
127                                            tmp.msgtyp, third);
128                 }
129                 default:
130                         panic("msgrcv with version != 0");
131                         return sys_msgrcv (first,
132                                            (struct msgbuf *) ptr,
133                                            second, fifth, third);
134                 }
135         case MSGGET:
136                 return sys_msgget ((key_t) first, second);
137         case MSGCTL:
138                 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
139
140         case SHMAT:
141                 switch (version) {
142                 default: {
143                         ulong raddr;
144                         ret = do_shmat (first, (char *) ptr, second, &raddr);
145                         if (ret)
146                                 return ret;
147                         return put_user (raddr, (ulong *) third);
148                 }
149                 case 1: /* iBCS2 emulator entry point */
150                         if (!segment_eq(get_fs(), get_ds()))
151                                 return -EINVAL;
152                         return do_shmat (first, (char *) ptr, second, (ulong *) third);
153                 }
154         case SHMDT:
155                 return sys_shmdt ((char *)ptr);
156         case SHMGET:
157                 return sys_shmget (first, second, third);
158         case SHMCTL:
159                 return sys_shmctl (first, second,
160                                    (struct shmid_ds *) ptr);
161         default:
162                 return -ENOSYS;
163         }
164 }
165
166 long sys_sigaction(int sig, const struct old_sigaction __user *act,
167                          struct old_sigaction __user *oact)
168 {
169         struct k_sigaction new_ka, old_ka;
170         int ret;
171
172         if (act) {
173                 old_sigset_t mask;
174                 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
175                     __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
176                     __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
177                         return -EFAULT;
178                 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
179                 __get_user(mask, &act->sa_mask);
180                 siginitset(&new_ka.sa.sa_mask, mask);
181         }
182
183         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
184
185         if (!ret && oact) {
186                 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
187                     __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
188                     __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
189                         return -EFAULT;
190                 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
191                 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
192         }
193
194         return ret;
195 }