Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-linus
[linux-2.6] / arch / frv / kernel / sys_frv.c
1 /* sys_frv.c: FRV arch-specific syscall wrappers
2  *
3  * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  * - Derived from arch/m68k/kernel/sys_m68k.c
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version
10  * 2 of the License, or (at your option) any later version.
11  */
12
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/fs.h>
17 #include <linux/smp.h>
18 #include <linux/sem.h>
19 #include <linux/msg.h>
20 #include <linux/shm.h>
21 #include <linux/stat.h>
22 #include <linux/mman.h>
23 #include <linux/file.h>
24 #include <linux/utsname.h>
25 #include <linux/syscalls.h>
26 #include <linux/ipc.h>
27
28 #include <asm/setup.h>
29 #include <asm/uaccess.h>
30
31 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
32                           unsigned long prot, unsigned long flags,
33                           unsigned long fd, unsigned long pgoff)
34 {
35         int error = -EBADF;
36         struct file * file = NULL;
37
38         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
39         if (!(flags & MAP_ANONYMOUS)) {
40                 file = fget(fd);
41                 if (!file)
42                         goto out;
43         }
44
45         /* As with sparc32, make sure the shift for mmap2 is constant
46            (12), no matter what PAGE_SIZE we have.... */
47
48         /* But unlike sparc32, don't just silently break if we're
49            trying to map something we can't */
50         if (pgoff & ((1<<(PAGE_SHIFT-12))-1))
51                 return -EINVAL;
52
53         pgoff >>= (PAGE_SHIFT - 12);
54
55         down_write(&current->mm->mmap_sem);
56         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
57         up_write(&current->mm->mmap_sem);
58
59         if (file)
60                 fput(file);
61 out:
62         return error;
63 }
64
65 #if 0 /* DAVIDM - do we want this */
66 struct mmap_arg_struct64 {
67         __u32 addr;
68         __u32 len;
69         __u32 prot;
70         __u32 flags;
71         __u64 offset; /* 64 bits */
72         __u32 fd;
73 };
74
75 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
76 {
77         int error = -EFAULT;
78         struct file * file = NULL;
79         struct mmap_arg_struct64 a;
80         unsigned long pgoff;
81
82         if (copy_from_user(&a, arg, sizeof(a)))
83                 return -EFAULT;
84
85         if ((long)a.offset & ~PAGE_MASK)
86                 return -EINVAL;
87
88         pgoff = a.offset >> PAGE_SHIFT;
89         if ((a.offset >> PAGE_SHIFT) != pgoff)
90                 return -EINVAL;
91
92         if (!(a.flags & MAP_ANONYMOUS)) {
93                 error = -EBADF;
94                 file = fget(a.fd);
95                 if (!file)
96                         goto out;
97         }
98         a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
99
100         down_write(&current->mm->mmap_sem);
101         error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
102         up_write(&current->mm->mmap_sem);
103         if (file)
104                 fput(file);
105 out:
106         return error;
107 }
108 #endif
109
110 /*
111  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
112  *
113  * This is really horribly ugly.
114  */
115 asmlinkage long sys_ipc(unsigned long call,
116                         unsigned long first,
117                         unsigned long second,
118                         unsigned long third,
119                         void __user *ptr,
120                         unsigned long fifth)
121 {
122         int version, ret;
123
124         version = call >> 16; /* hack for backward compatibility */
125         call &= 0xffff;
126
127         switch (call) {
128         case SEMOP:
129                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
130         case SEMTIMEDOP:
131                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
132                                       (const struct timespec __user *)fifth);
133
134         case SEMGET:
135                 return sys_semget (first, second, third);
136         case SEMCTL: {
137                 union semun fourth;
138                 if (!ptr)
139                         return -EINVAL;
140                 if (get_user(fourth.__pad, (void * __user *) ptr))
141                         return -EFAULT;
142                 return sys_semctl (first, second, third, fourth);
143         }
144
145         case MSGSND:
146                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
147                                    second, third);
148         case MSGRCV:
149                 switch (version) {
150                 case 0: {
151                         struct ipc_kludge tmp;
152                         if (!ptr)
153                                 return -EINVAL;
154
155                         if (copy_from_user(&tmp,
156                                            (struct ipc_kludge __user *) ptr,
157                                            sizeof (tmp)))
158                                 return -EFAULT;
159                         return sys_msgrcv (first, tmp.msgp, second,
160                                            tmp.msgtyp, third);
161                 }
162                 default:
163                         return sys_msgrcv (first,
164                                            (struct msgbuf __user *) ptr,
165                                            second, fifth, third);
166                 }
167         case MSGGET:
168                 return sys_msgget ((key_t) first, second);
169         case MSGCTL:
170                 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
171
172         case SHMAT:
173                 switch (version) {
174                 default: {
175                         ulong raddr;
176                         ret = do_shmat (first, (char __user *) ptr, second, &raddr);
177                         if (ret)
178                                 return ret;
179                         return put_user (raddr, (ulong __user *) third);
180                 }
181                 case 1: /* iBCS2 emulator entry point */
182                         if (!segment_eq(get_fs(), get_ds()))
183                                 return -EINVAL;
184                         /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
185                         return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
186                 }
187         case SHMDT:
188                 return sys_shmdt ((char __user *)ptr);
189         case SHMGET:
190                 return sys_shmget (first, second, third);
191         case SHMCTL:
192                 return sys_shmctl (first, second,
193                                    (struct shmid_ds __user *) ptr);
194         default:
195                 return -ENOSYS;
196         }
197 }