linux/arch/m68knommu/kernel/sys_m68k.c
<<
>>
Prefs
   1/*
   2 * linux/arch/m68knommu/kernel/sys_m68k.c
   3 *
   4 * This file contains various random system calls that
   5 * have a non-standard calling sequence on the Linux/m68k
   6 * platform.
   7 */
   8
   9#include <linux/errno.h>
  10#include <linux/sched.h>
  11#include <linux/mm.h>
  12#include <linux/smp.h>
  13#include <linux/sem.h>
  14#include <linux/msg.h>
  15#include <linux/shm.h>
  16#include <linux/stat.h>
  17#include <linux/syscalls.h>
  18#include <linux/mman.h>
  19#include <linux/file.h>
  20#include <linux/utsname.h>
  21#include <linux/ipc.h>
  22#include <linux/fs.h>
  23
  24#include <asm/setup.h>
  25#include <asm/uaccess.h>
  26#include <asm/cachectl.h>
  27#include <asm/traps.h>
  28#include <asm/cacheflush.h>
  29#include <asm/unistd.h>
  30
  31/* common code for old and new mmaps */
  32static inline long do_mmap2(
  33        unsigned long addr, unsigned long len,
  34        unsigned long prot, unsigned long flags,
  35        unsigned long fd, unsigned long pgoff)
  36{
  37        int error = -EBADF;
  38        struct file * file = NULL;
  39
  40        flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  41        if (!(flags & MAP_ANONYMOUS)) {
  42                file = fget(fd);
  43                if (!file)
  44                        goto out;
  45        }
  46
  47        down_write(&current->mm->mmap_sem);
  48        error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  49        up_write(&current->mm->mmap_sem);
  50
  51        if (file)
  52                fput(file);
  53out:
  54        return error;
  55}
  56
  57asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  58        unsigned long prot, unsigned long flags,
  59        unsigned long fd, unsigned long pgoff)
  60{
  61        return do_mmap2(addr, len, prot, flags, fd, pgoff);
  62}
  63
  64/*
  65 * Perform the select(nd, in, out, ex, tv) and mmap() system
  66 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
  67 * handle more than 4 system call parameters, so these system calls
  68 * used a memory block for parameter passing..
  69 */
  70
  71struct mmap_arg_struct {
  72        unsigned long addr;
  73        unsigned long len;
  74        unsigned long prot;
  75        unsigned long flags;
  76        unsigned long fd;
  77        unsigned long offset;
  78};
  79
  80asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  81{
  82        struct mmap_arg_struct a;
  83        int error = -EFAULT;
  84
  85        if (copy_from_user(&a, arg, sizeof(a)))
  86                goto out;
  87
  88        error = -EINVAL;
  89        if (a.offset & ~PAGE_MASK)
  90                goto out;
  91
  92        a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  93
  94        error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  95out:
  96        return error;
  97}
  98
  99struct sel_arg_struct {
 100        unsigned long n;
 101        fd_set *inp, *outp, *exp;
 102        struct timeval *tvp;
 103};
 104
 105asmlinkage int old_select(struct sel_arg_struct *arg)
 106{
 107        struct sel_arg_struct a;
 108
 109        if (copy_from_user(&a, arg, sizeof(a)))
 110                return -EFAULT;
 111        /* sys_select() does the appropriate kernel locking */
 112        return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
 113}
 114
 115/*
 116 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
 117 *
 118 * This is really horribly ugly.
 119 */
 120asmlinkage int sys_ipc (uint call, int first, int second,
 121                        int third, void *ptr, long fifth)
 122{
 123        int version, ret;
 124
 125        version = call >> 16; /* hack for backward compatibility */
 126        call &= 0xffff;
 127
 128        if (call <= SEMCTL)
 129                switch (call) {
 130                case SEMOP:
 131                        return sys_semop (first, (struct sembuf *)ptr, second);
 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 **) ptr))
 139                                return -EFAULT;
 140                        return sys_semctl (first, second, third, fourth);
 141                        }
 142                default:
 143                        return -EINVAL;
 144                }
 145        if (call <= MSGCTL) 
 146                switch (call) {
 147                case MSGSND:
 148                        return sys_msgsnd (first, (struct msgbuf *) ptr, 
 149                                          second, third);
 150                case MSGRCV:
 151                        switch (version) {
 152                        case 0: {
 153                                struct ipc_kludge tmp;
 154                                if (!ptr)
 155                                        return -EINVAL;
 156                                if (copy_from_user (&tmp,
 157                                                    (struct ipc_kludge *)ptr,
 158                                                    sizeof (tmp)))
 159                                        return -EFAULT;
 160                                return sys_msgrcv (first, tmp.msgp, second,
 161                                                   tmp.msgtyp, third);
 162                                }
 163                        default:
 164                                return sys_msgrcv (first,
 165                                                   (struct msgbuf *) ptr,
 166                                                   second, fifth, third);
 167                        }
 168                case MSGGET:
 169                        return sys_msgget ((key_t) first, second);
 170                case MSGCTL:
 171                        return sys_msgctl (first, second,
 172                                           (struct msqid_ds *) ptr);
 173                default:
 174                        return -EINVAL;
 175                }
 176        if (call <= SHMCTL)
 177                switch (call) {
 178                case SHMAT:
 179                        switch (version) {
 180                        default: {
 181                                ulong raddr;
 182                                ret = do_shmat (first, ptr, second, &raddr);
 183                                if (ret)
 184                                        return ret;
 185                                return put_user (raddr, (ulong __user *) third);
 186                        }
 187                        }
 188                case SHMDT:
 189                        return sys_shmdt (ptr);
 190                case SHMGET:
 191                        return sys_shmget (first, second, third);
 192                case SHMCTL:
 193                        return sys_shmctl (first, second, ptr);
 194                default:
 195                        return -ENOSYS;
 196                }
 197
 198        return -EINVAL;
 199}
 200
 201/* sys_cacheflush -- flush (part of) the processor cache.  */
 202asmlinkage int
 203sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
 204{
 205        flush_cache_all();
 206        return(0);
 207}
 208
 209asmlinkage int sys_getpagesize(void)
 210{
 211        return PAGE_SIZE;
 212}
 213
 214/*
 215 * Do a system call from kernel instead of calling sys_execve so we
 216 * end up with proper pt_regs.
 217 */
 218int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 219{
 220        register long __res asm ("%d0") = __NR_execve;
 221        register long __a asm ("%d1") = (long)(filename);
 222        register long __b asm ("%d2") = (long)(argv);
 223        register long __c asm ("%d3") = (long)(envp);
 224        asm volatile ("trap  #0" : "+d" (__res)
 225                        : "d" (__a), "d" (__b), "d" (__c));
 226        return __res;
 227}
 228