]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/mn10300/kernel/sys_mn10300.c
headers: smp_lock.h redux
[mirror_ubuntu-hirsute-kernel.git] / arch / mn10300 / kernel / sys_mn10300.c
1 /* MN10300 Weird system calls
2 *
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/syscalls.h>
14 #include <linux/mm.h>
15 #include <linux/smp.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/utsname.h>
23 #include <linux/syscalls.h>
24 #include <linux/tty.h>
25
26 #include <asm/uaccess.h>
27
28 #define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */
29
30 /*
31 * memory mapping syscall
32 */
33 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
34 unsigned long prot, unsigned long flags,
35 unsigned long fd, unsigned long pgoff)
36 {
37 struct file *file = NULL;
38 long error = -EINVAL;
39
40 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
41
42 if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
43 goto out;
44
45 error = -EBADF;
46 if (!(flags & MAP_ANONYMOUS)) {
47 file = fget(fd);
48 if (!file)
49 goto out;
50 }
51
52 down_write(&current->mm->mmap_sem);
53 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
54 up_write(&current->mm->mmap_sem);
55
56 if (file)
57 fput(file);
58 out:
59 return error;
60 }
61
62 asmlinkage long old_mmap(unsigned long addr, unsigned long len,
63 unsigned long prot, unsigned long flags,
64 unsigned long fd, unsigned long offset)
65 {
66 if (offset & ~PAGE_MASK)
67 return -EINVAL;
68 return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
69 }
70
71 struct sel_arg_struct {
72 unsigned long n;
73 fd_set *inp;
74 fd_set *outp;
75 fd_set *exp;
76 struct timeval *tvp;
77 };
78
79 asmlinkage int old_select(struct sel_arg_struct __user *arg)
80 {
81 struct sel_arg_struct a;
82
83 if (copy_from_user(&a, arg, sizeof(a)))
84 return -EFAULT;
85 /* sys_select() does the appropriate kernel locking */
86 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
87 }
88
89 /*
90 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
91 *
92 * This is really horribly ugly.
93 */
94 asmlinkage long sys_ipc(uint call, int first, int second,
95 int third, void __user *ptr, long fifth)
96 {
97 int version, ret;
98
99 version = call >> 16; /* hack for backward compatibility */
100 call &= 0xffff;
101
102 switch (call) {
103 case SEMOP:
104 return sys_semtimedop(first, (struct sembuf __user *)ptr,
105 second, NULL);
106 case SEMTIMEDOP:
107 return sys_semtimedop(first, (struct sembuf __user *)ptr,
108 second,
109 (const struct timespec __user *)fifth);
110 case SEMGET:
111 return sys_semget(first, second, third);
112 case SEMCTL: {
113 union semun fourth;
114 if (!ptr)
115 return -EINVAL;
116 if (get_user(fourth.__pad, (void __user * __user *) ptr))
117 return -EFAULT;
118 return sys_semctl(first, second, third, fourth);
119 }
120
121 case MSGSND:
122 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
123 second, third);
124 case MSGRCV:
125 switch (version) {
126 case 0: {
127 struct ipc_kludge tmp;
128 if (!ptr)
129 return -EINVAL;
130
131 if (copy_from_user(&tmp,
132 (struct ipc_kludge __user *) ptr,
133 sizeof(tmp)))
134 return -EFAULT;
135 return sys_msgrcv(first, tmp.msgp, second,
136 tmp.msgtyp, third);
137 }
138 default:
139 return sys_msgrcv(first,
140 (struct msgbuf __user *) ptr,
141 second, fifth, third);
142 }
143 case MSGGET:
144 return sys_msgget((key_t) first, second);
145 case MSGCTL:
146 return sys_msgctl(first, second,
147 (struct msqid_ds __user *) ptr);
148
149 case SHMAT:
150 switch (version) {
151 default: {
152 ulong raddr;
153 ret = do_shmat(first, (char __user *) ptr, second,
154 &raddr);
155 if (ret)
156 return ret;
157 return put_user(raddr, (ulong *) third);
158 }
159 case 1: /* iBCS2 emulator entry point */
160 if (!segment_eq(get_fs(), get_ds()))
161 return -EINVAL;
162 return do_shmat(first, (char __user *) ptr, second,
163 (ulong *) third);
164 }
165 case SHMDT:
166 return sys_shmdt((char __user *)ptr);
167 case SHMGET:
168 return sys_shmget(first, second, third);
169 case SHMCTL:
170 return sys_shmctl(first, second,
171 (struct shmid_ds __user *) ptr);
172 default:
173 return -EINVAL;
174 }
175 }