headers: utsname.h redux
[firewire-audio.git] / arch / frv / kernel / sys_frv.c
blob2b6b5289cdccefbd2d5029d5da4e62ebdc989803
1 /* sys_frv.c: FRV arch-specific syscall wrappers
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
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.
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/syscalls.h>
25 #include <linux/ipc.h>
27 #include <asm/setup.h>
28 #include <asm/uaccess.h>
30 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
31 unsigned long prot, unsigned long flags,
32 unsigned long fd, unsigned long pgoff)
34 int error = -EBADF;
35 struct file * file = NULL;
37 /* As with sparc32, make sure the shift for mmap2 is constant
38 (12), no matter what PAGE_SIZE we have.... */
40 /* But unlike sparc32, don't just silently break if we're
41 trying to map something we can't */
42 if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
43 return -EINVAL;
44 pgoff >>= PAGE_SHIFT - 12;
46 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
47 if (!(flags & MAP_ANONYMOUS)) {
48 file = fget(fd);
49 if (!file)
50 goto out;
53 down_write(&current->mm->mmap_sem);
54 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
55 up_write(&current->mm->mmap_sem);
57 if (file)
58 fput(file);
59 out:
60 return error;
63 #if 0 /* DAVIDM - do we want this */
64 struct mmap_arg_struct64 {
65 __u32 addr;
66 __u32 len;
67 __u32 prot;
68 __u32 flags;
69 __u64 offset; /* 64 bits */
70 __u32 fd;
73 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
75 int error = -EFAULT;
76 struct file * file = NULL;
77 struct mmap_arg_struct64 a;
78 unsigned long pgoff;
80 if (copy_from_user(&a, arg, sizeof(a)))
81 return -EFAULT;
83 if ((long)a.offset & ~PAGE_MASK)
84 return -EINVAL;
86 pgoff = a.offset >> PAGE_SHIFT;
87 if ((a.offset >> PAGE_SHIFT) != pgoff)
88 return -EINVAL;
90 if (!(a.flags & MAP_ANONYMOUS)) {
91 error = -EBADF;
92 file = fget(a.fd);
93 if (!file)
94 goto out;
96 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
98 down_write(&current->mm->mmap_sem);
99 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
100 up_write(&current->mm->mmap_sem);
101 if (file)
102 fput(file);
103 out:
104 return error;
106 #endif
109 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
111 * This is really horribly ugly.
113 asmlinkage long sys_ipc(unsigned long call,
114 unsigned long first,
115 unsigned long second,
116 unsigned long third,
117 void __user *ptr,
118 unsigned long fifth)
120 int version, ret;
122 version = call >> 16; /* hack for backward compatibility */
123 call &= 0xffff;
125 switch (call) {
126 case SEMOP:
127 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
128 case SEMTIMEDOP:
129 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
130 (const struct timespec __user *)fifth);
132 case SEMGET:
133 return sys_semget (first, second, third);
134 case SEMCTL: {
135 union semun fourth;
136 if (!ptr)
137 return -EINVAL;
138 if (get_user(fourth.__pad, (void * __user *) ptr))
139 return -EFAULT;
140 return sys_semctl (first, second, third, fourth);
143 case MSGSND:
144 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
145 second, third);
146 case MSGRCV:
147 switch (version) {
148 case 0: {
149 struct ipc_kludge tmp;
150 if (!ptr)
151 return -EINVAL;
153 if (copy_from_user(&tmp,
154 (struct ipc_kludge __user *) ptr,
155 sizeof (tmp)))
156 return -EFAULT;
157 return sys_msgrcv (first, tmp.msgp, second,
158 tmp.msgtyp, third);
160 default:
161 return sys_msgrcv (first,
162 (struct msgbuf __user *) ptr,
163 second, fifth, third);
165 case MSGGET:
166 return sys_msgget ((key_t) first, second);
167 case MSGCTL:
168 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
170 case SHMAT:
171 switch (version) {
172 default: {
173 ulong raddr;
174 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
175 if (ret)
176 return ret;
177 return put_user (raddr, (ulong __user *) third);
179 case 1: /* iBCS2 emulator entry point */
180 if (!segment_eq(get_fs(), get_ds()))
181 return -EINVAL;
182 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
183 return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
185 case SHMDT:
186 return sys_shmdt ((char __user *)ptr);
187 case SHMGET:
188 return sys_shmget (first, second, third);
189 case SHMCTL:
190 return sys_shmctl (first, second,
191 (struct shmid_ds __user *) ptr);
192 default:
193 return -ENOSYS;