Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jesper Nilsson | 5978e79 | 2007-11-14 17:00:53 -0800 | [diff] [blame] | 16 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/smp.h> |
| 18 | #include <linux/smp_lock.h> |
| 19 | #include <linux/sem.h> |
| 20 | #include <linux/msg.h> |
| 21 | #include <linux/shm.h> |
| 22 | #include <linux/stat.h> |
| 23 | #include <linux/mman.h> |
| 24 | #include <linux/file.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 25 | #include <linux/ipc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/segment.h> |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* common code for old and new mmaps */ |
| 31 | static inline long |
| 32 | do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
| 33 | unsigned long flags, 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 | down_write(¤t->mm->mmap_sem); |
| 46 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 47 | up_write(¤t->mm->mmap_sem); |
| 48 | |
| 49 | if (file) |
| 50 | fput(file); |
| 51 | out: |
| 52 | return error; |
| 53 | } |
| 54 | |
| 55 | asmlinkage unsigned long old_mmap(unsigned long __user *args) |
| 56 | { |
| 57 | unsigned long buffer[6]; |
| 58 | int err = -EFAULT; |
| 59 | |
| 60 | if (copy_from_user(&buffer, args, sizeof(buffer))) |
| 61 | goto out; |
| 62 | |
| 63 | err = -EINVAL; |
| 64 | if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */ |
| 65 | goto out; |
| 66 | |
| 67 | err = do_mmap2(buffer[0], buffer[1], buffer[2], buffer[3], |
| 68 | buffer[4], buffer[5] >> PAGE_SHIFT); |
| 69 | out: |
| 70 | return err; |
| 71 | } |
| 72 | |
| 73 | asmlinkage long |
| 74 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
| 75 | unsigned long flags, unsigned long fd, unsigned long pgoff) |
| 76 | { |
| 77 | return do_mmap2(addr, len, prot, flags, fd, pgoff); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 82 | * |
| 83 | * This is really horribly ugly. (same as arch/i386) |
| 84 | */ |
| 85 | |
| 86 | asmlinkage int sys_ipc (uint call, int first, int second, |
| 87 | int third, void __user *ptr, long fifth) |
| 88 | { |
| 89 | int version, ret; |
| 90 | |
| 91 | version = call >> 16; /* hack for backward compatibility */ |
| 92 | call &= 0xffff; |
| 93 | |
| 94 | switch (call) { |
| 95 | case SEMOP: |
| 96 | return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL); |
| 97 | case SEMTIMEDOP: |
| 98 | return sys_semtimedop(first, (struct sembuf __user *)ptr, second, |
| 99 | (const struct timespec __user *)fifth); |
| 100 | |
| 101 | case SEMGET: |
| 102 | return sys_semget (first, second, third); |
| 103 | case SEMCTL: { |
| 104 | union semun fourth; |
| 105 | if (!ptr) |
| 106 | return -EINVAL; |
| 107 | if (get_user(fourth.__pad, (void * __user *) ptr)) |
| 108 | return -EFAULT; |
| 109 | return sys_semctl (first, second, third, fourth); |
| 110 | } |
| 111 | |
| 112 | case MSGSND: |
| 113 | return sys_msgsnd (first, (struct msgbuf __user *) ptr, |
| 114 | second, third); |
| 115 | case MSGRCV: |
| 116 | switch (version) { |
| 117 | case 0: { |
| 118 | struct ipc_kludge tmp; |
| 119 | if (!ptr) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | if (copy_from_user(&tmp, |
| 123 | (struct ipc_kludge __user *) ptr, |
| 124 | sizeof (tmp))) |
| 125 | return -EFAULT; |
| 126 | return sys_msgrcv (first, tmp.msgp, second, |
| 127 | tmp.msgtyp, third); |
| 128 | } |
| 129 | default: |
| 130 | return sys_msgrcv (first, |
| 131 | (struct msgbuf __user *) ptr, |
| 132 | second, fifth, third); |
| 133 | } |
| 134 | case MSGGET: |
| 135 | return sys_msgget ((key_t) first, second); |
| 136 | case MSGCTL: |
| 137 | return sys_msgctl (first, second, (struct msqid_ds __user *) ptr); |
| 138 | |
| 139 | case SHMAT: { |
| 140 | ulong raddr; |
| 141 | ret = do_shmat (first, (char __user *) ptr, second, &raddr); |
| 142 | if (ret) |
| 143 | return ret; |
| 144 | return put_user (raddr, (ulong __user *) third); |
| 145 | } |
| 146 | case SHMDT: |
| 147 | return sys_shmdt ((char __user *)ptr); |
| 148 | case SHMGET: |
| 149 | return sys_shmget (first, second, third); |
| 150 | case SHMCTL: |
| 151 | return sys_shmctl (first, second, |
| 152 | (struct shmid_ds __user *) ptr); |
| 153 | default: |
| 154 | return -ENOSYS; |
| 155 | } |
| 156 | } |