]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/cris/kernel/sys_cris.c
Merge branch 'for_paulus' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc
[mirror_ubuntu-bionic-kernel.git] / arch / cris / kernel / sys_cris.c
CommitLineData
1da177e4
LT
1/* $Id: sys_cris.c,v 1.6 2004/03/11 11:38:40 starvik Exp $
2 *
3 * linux/arch/cris/kernel/sys_cris.c
4 *
5 * This file contains various random system calls that
6 * have a non-standard calling sequence on some platforms.
7 * Since we don't have to do any backwards compatibility, our
8 * versions are done in the most "normal" way possible.
9 *
10 */
11
12#include <linux/errno.h>
13#include <linux/sched.h>
14#include <linux/syscalls.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
25#include <asm/uaccess.h>
26#include <asm/ipc.h>
27#include <asm/segment.h>
28
29/*
30 * sys_pipe() is the normal C calling standard for creating
31 * a pipe. It's not the way Unix traditionally does this, though.
32 */
33asmlinkage int sys_pipe(unsigned long __user * fildes)
34{
35 int fd[2];
36 int error;
37
38 lock_kernel();
39 error = do_pipe(fd);
40 unlock_kernel();
41 if (!error) {
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
43 error = -EFAULT;
44 }
45 return error;
46}
47
48/* common code for old and new mmaps */
49static inline long
50do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
51 unsigned long flags, unsigned long fd, unsigned long pgoff)
52{
53 int error = -EBADF;
54 struct file * file = NULL;
55
56 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
57 if (!(flags & MAP_ANONYMOUS)) {
58 file = fget(fd);
59 if (!file)
60 goto out;
61 }
62
63 down_write(&current->mm->mmap_sem);
64 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
65 up_write(&current->mm->mmap_sem);
66
67 if (file)
68 fput(file);
69out:
70 return error;
71}
72
73asmlinkage unsigned long old_mmap(unsigned long __user *args)
74{
75 unsigned long buffer[6];
76 int err = -EFAULT;
77
78 if (copy_from_user(&buffer, args, sizeof(buffer)))
79 goto out;
80
81 err = -EINVAL;
82 if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */
83 goto out;
84
85 err = do_mmap2(buffer[0], buffer[1], buffer[2], buffer[3],
86 buffer[4], buffer[5] >> PAGE_SHIFT);
87out:
88 return err;
89}
90
91asmlinkage long
92sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
93 unsigned long flags, unsigned long fd, unsigned long pgoff)
94{
95 return do_mmap2(addr, len, prot, flags, fd, pgoff);
96}
97
98/*
99 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
100 *
101 * This is really horribly ugly. (same as arch/i386)
102 */
103
104asmlinkage int sys_ipc (uint call, int first, int second,
105 int third, void __user *ptr, long fifth)
106{
107 int version, ret;
108
109 version = call >> 16; /* hack for backward compatibility */
110 call &= 0xffff;
111
112 switch (call) {
113 case SEMOP:
114 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
115 case SEMTIMEDOP:
116 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
117 (const struct timespec __user *)fifth);
118
119 case SEMGET:
120 return sys_semget (first, second, third);
121 case SEMCTL: {
122 union semun fourth;
123 if (!ptr)
124 return -EINVAL;
125 if (get_user(fourth.__pad, (void * __user *) ptr))
126 return -EFAULT;
127 return sys_semctl (first, second, third, fourth);
128 }
129
130 case MSGSND:
131 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
132 second, third);
133 case MSGRCV:
134 switch (version) {
135 case 0: {
136 struct ipc_kludge tmp;
137 if (!ptr)
138 return -EINVAL;
139
140 if (copy_from_user(&tmp,
141 (struct ipc_kludge __user *) ptr,
142 sizeof (tmp)))
143 return -EFAULT;
144 return sys_msgrcv (first, tmp.msgp, second,
145 tmp.msgtyp, third);
146 }
147 default:
148 return sys_msgrcv (first,
149 (struct msgbuf __user *) ptr,
150 second, fifth, third);
151 }
152 case MSGGET:
153 return sys_msgget ((key_t) first, second);
154 case MSGCTL:
155 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
156
157 case SHMAT: {
158 ulong raddr;
159 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
160 if (ret)
161 return ret;
162 return put_user (raddr, (ulong __user *) third);
163 }
164 case SHMDT:
165 return sys_shmdt ((char __user *)ptr);
166 case SHMGET:
167 return sys_shmget (first, second, third);
168 case SHMCTL:
169 return sys_shmctl (first, second,
170 (struct shmid_ds __user *) ptr);
171 default:
172 return -ENOSYS;
173 }
174}