]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/frv/kernel/sys_frv.c
Linux-2.6.12-rc2
[mirror_ubuntu-bionic-kernel.git] / 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/smp.h>
17 #include <linux/smp_lock.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
27 #include <asm/setup.h>
28 #include <asm/uaccess.h>
29 #include <asm/ipc.h>
30
31 /*
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way unix traditionally does this, though.
34 */
35 asmlinkage long sys_pipe(unsigned long * fildes)
36 {
37 int fd[2];
38 int error;
39
40 error = do_pipe(fd);
41 if (!error) {
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
43 error = -EFAULT;
44 }
45 return error;
46 }
47
48 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
49 unsigned long prot, unsigned long flags,
50 unsigned long fd, unsigned long pgoff)
51 {
52 int error = -EBADF;
53 struct file * file = NULL;
54
55 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
56 if (!(flags & MAP_ANONYMOUS)) {
57 file = fget(fd);
58 if (!file)
59 goto out;
60 }
61
62 /* As with sparc32, make sure the shift for mmap2 is constant
63 (12), no matter what PAGE_SIZE we have.... */
64
65 /* But unlike sparc32, don't just silently break if we're
66 trying to map something we can't */
67 if (pgoff & ((1<<(PAGE_SHIFT-12))-1))
68 return -EINVAL;
69
70 pgoff >>= (PAGE_SHIFT - 12);
71
72 down_write(&current->mm->mmap_sem);
73 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
74 up_write(&current->mm->mmap_sem);
75
76 if (file)
77 fput(file);
78 out:
79 return error;
80 }
81
82 #if 0 /* DAVIDM - do we want this */
83 struct mmap_arg_struct64 {
84 __u32 addr;
85 __u32 len;
86 __u32 prot;
87 __u32 flags;
88 __u64 offset; /* 64 bits */
89 __u32 fd;
90 };
91
92 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
93 {
94 int error = -EFAULT;
95 struct file * file = NULL;
96 struct mmap_arg_struct64 a;
97 unsigned long pgoff;
98
99 if (copy_from_user(&a, arg, sizeof(a)))
100 return -EFAULT;
101
102 if ((long)a.offset & ~PAGE_MASK)
103 return -EINVAL;
104
105 pgoff = a.offset >> PAGE_SHIFT;
106 if ((a.offset >> PAGE_SHIFT) != pgoff)
107 return -EINVAL;
108
109 if (!(a.flags & MAP_ANONYMOUS)) {
110 error = -EBADF;
111 file = fget(a.fd);
112 if (!file)
113 goto out;
114 }
115 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
116
117 down_write(&current->mm->mmap_sem);
118 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
119 up_write(&current->mm->mmap_sem);
120 if (file)
121 fput(file);
122 out:
123 return error;
124 }
125 #endif
126
127 /*
128 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
129 *
130 * This is really horribly ugly.
131 */
132 asmlinkage long sys_ipc(unsigned long call,
133 unsigned long first,
134 unsigned long second,
135 unsigned long third,
136 void __user *ptr,
137 unsigned long fifth)
138 {
139 int version, ret;
140
141 version = call >> 16; /* hack for backward compatibility */
142 call &= 0xffff;
143
144 switch (call) {
145 case SEMOP:
146 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
147 case SEMTIMEDOP:
148 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
149 (const struct timespec __user *)fifth);
150
151 case SEMGET:
152 return sys_semget (first, second, third);
153 case SEMCTL: {
154 union semun fourth;
155 if (!ptr)
156 return -EINVAL;
157 if (get_user(fourth.__pad, (void * __user *) ptr))
158 return -EFAULT;
159 return sys_semctl (first, second, third, fourth);
160 }
161
162 case MSGSND:
163 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
164 second, third);
165 case MSGRCV:
166 switch (version) {
167 case 0: {
168 struct ipc_kludge tmp;
169 if (!ptr)
170 return -EINVAL;
171
172 if (copy_from_user(&tmp,
173 (struct ipc_kludge __user *) ptr,
174 sizeof (tmp)))
175 return -EFAULT;
176 return sys_msgrcv (first, tmp.msgp, second,
177 tmp.msgtyp, third);
178 }
179 default:
180 return sys_msgrcv (first,
181 (struct msgbuf __user *) ptr,
182 second, fifth, third);
183 }
184 case MSGGET:
185 return sys_msgget ((key_t) first, second);
186 case MSGCTL:
187 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
188
189 case SHMAT:
190 switch (version) {
191 default: {
192 ulong raddr;
193 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
194 if (ret)
195 return ret;
196 return put_user (raddr, (ulong __user *) third);
197 }
198 case 1: /* iBCS2 emulator entry point */
199 if (!segment_eq(get_fs(), get_ds()))
200 return -EINVAL;
201 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
202 return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
203 }
204 case SHMDT:
205 return sys_shmdt ((char __user *)ptr);
206 case SHMGET:
207 return sys_shmget (first, second, third);
208 case SHMCTL:
209 return sys_shmctl (first, second,
210 (struct shmid_ds __user *) ptr);
211 default:
212 return -ENOSYS;
213 }
214 }