flag parameters: pipe
[safe/jmp/linux-2.6] / arch / sparc64 / kernel / sys_sparc.c
index bf5f14e..39749e3 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id: sys_sparc.c,v 1.57 2002/02/09 19:49:30 davem Exp $
- * linux/arch/sparc64/kernel/sys_sparc.c
+/* linux/arch/sparc64/kernel/sys_sparc.c
  *
  * This file contains various random system calls that
  * have a non-standard calling sequence on the Linux/sparc
@@ -19,7 +18,6 @@
 #include <linux/mman.h>
 #include <linux/utsname.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 #include <linux/ipc.h>
 #include <linux/random.h>
 
 #include <asm/uaccess.h>
-#include <asm/ipc.h>
 #include <asm/utrap.h>
 #include <asm/perfctr.h>
-#include <asm/a.out.h>
+#include <asm/unistd.h>
+
+#include "entry.h"
+#include "systbls.h"
 
 /* #define DEBUG_UNIMP_SYSCALL */
 
@@ -319,7 +319,7 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
 
        if (flags & MAP_FIXED) {
                /* Ok, don't mess with it. */
-               return get_unmapped_area(NULL, addr, len, pgoff, flags);
+               return get_unmapped_area(NULL, orig_addr, len, pgoff, flags);
        }
        flags &= ~MAP_SHARED;
 
@@ -418,7 +418,7 @@ asmlinkage long sparc_pipe(struct pt_regs *regs)
        int fd[2];
        int error;
 
-       error = do_pipe(fd);
+       error = do_pipe_flags(fd, 0);
        if (error)
                goto out;
        regs->u_regs[UREG_I1] = fd[1];
@@ -436,7 +436,7 @@ out:
 asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
                        unsigned long third, void __user *ptr, long fifth)
 {
-       int err;
+       long err;
 
        /* No need for backward compatibility. We can start fresh... */
        if (call <= SEMCTL) {
@@ -447,22 +447,16 @@ asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
                        goto out;
                case SEMTIMEDOP:
                        err = sys_semtimedop(first, ptr, (unsigned)second,
-                               (const struct timespec __user *) fifth);
+                               (const struct timespec __user *)
+                                            (unsigned long) fifth);
                        goto out;
                case SEMGET:
                        err = sys_semget(first, (int)second, (int)third);
                        goto out;
                case SEMCTL: {
-                       union semun fourth;
-                       err = -EINVAL;
-                       if (!ptr)
-                               goto out;
-                       err = -EFAULT;
-                       if (get_user(fourth.__pad,
-                                    (void __user * __user *) ptr))
-                               goto out;
-                       err = sys_semctl(first, (int)second | IPC_64,
-                                        (int)third, fourth);
+                       err = sys_semctl(first, second,
+                                        (int)third | IPC_64,
+                                        (union semun) ptr);
                        goto out;
                }
                default:
@@ -548,20 +542,19 @@ asmlinkage long sparc64_personality(unsigned long personality)
        return ret;
 }
 
-int sparc64_mmap_check(unsigned long addr, unsigned long len,
-               unsigned long flags)
+int sparc_mmap_check(unsigned long addr, unsigned long len)
 {
        if (test_thread_flag(TIF_32BIT)) {
                if (len >= STACK_TOP32)
                        return -EINVAL;
 
-               if ((flags & MAP_FIXED) && addr > STACK_TOP32 - len)
+               if (addr > STACK_TOP32 - len)
                        return -EINVAL;
        } else {
                if (len >= VA_EXCLUDE_START)
                        return -EINVAL;
 
-               if ((flags & MAP_FIXED) && invalid_64bit_range(addr, len))
+               if (invalid_64bit_range(addr, len))
                        return -EINVAL;
        }
 
@@ -615,46 +608,19 @@ asmlinkage unsigned long sys64_mremap(unsigned long addr,
        unsigned long old_len, unsigned long new_len,
        unsigned long flags, unsigned long new_addr)
 {
-       struct vm_area_struct *vma;
        unsigned long ret = -EINVAL;
 
        if (test_thread_flag(TIF_32BIT))
                goto out;
        if (unlikely(new_len >= VA_EXCLUDE_START))
                goto out;
-       if (unlikely(invalid_64bit_range(addr, old_len)))
+       if (unlikely(sparc_mmap_check(addr, old_len)))
+               goto out;
+       if (unlikely(sparc_mmap_check(new_addr, new_len)))
                goto out;
 
        down_write(&current->mm->mmap_sem);
-       if (flags & MREMAP_FIXED) {
-               if (invalid_64bit_range(new_addr, new_len))
-                       goto out_sem;
-       } else if (invalid_64bit_range(addr, new_len)) {
-               unsigned long map_flags = 0;
-               struct file *file = NULL;
-
-               ret = -ENOMEM;
-               if (!(flags & MREMAP_MAYMOVE))
-                       goto out_sem;
-
-               vma = find_vma(current->mm, addr);
-               if (vma) {
-                       if (vma->vm_flags & VM_SHARED)
-                               map_flags |= MAP_SHARED;
-                       file = vma->vm_file;
-               }
-
-               /* MREMAP_FIXED checked above. */
-               new_addr = get_unmapped_area(file, addr, new_len,
-                                   vma ? vma->vm_pgoff : 0,
-                                   map_flags);
-               ret = new_addr;
-               if (new_addr & ~PAGE_MASK)
-                       goto out_sem;
-               flags |= MREMAP_FIXED;
-       }
        ret = do_mremap(addr, old_len, new_len, flags, new_addr);
-out_sem:
        up_write(&current->mm->mmap_sem);
 out:
        return ret;       
@@ -707,61 +673,25 @@ asmlinkage long sys_getdomainname(char __user *name, int len)
 {
         int nlen, err;
 
-       if (len < 0 || len > __NEW_UTS_LEN)
+       if (len < 0)
                return -EINVAL;
 
        down_read(&uts_sem);
        
-       nlen = strlen(system_utsname.domainname) + 1;
-        if (nlen < len)
-                len = nlen;
+       nlen = strlen(utsname()->domainname) + 1;
+       err = -EINVAL;
+       if (nlen > len)
+               goto out;
 
        err = -EFAULT;
-       if (!copy_to_user(name, system_utsname.domainname, len))
+       if (!copy_to_user(name, utsname()->domainname, nlen))
                err = 0;
 
+out:
        up_read(&uts_sem);
        return err;
 }
 
-asmlinkage long solaris_syscall(struct pt_regs *regs)
-{
-       static int count;
-
-       regs->tpc = regs->tnpc;
-       regs->tnpc += 4;
-       if (test_thread_flag(TIF_32BIT)) {
-               regs->tpc &= 0xffffffff;
-               regs->tnpc &= 0xffffffff;
-       }
-       if (++count <= 5) {
-               printk ("For Solaris binary emulation you need solaris module loaded\n");
-               show_regs (regs);
-       }
-       send_sig(SIGSEGV, current, 1);
-
-       return -ENOSYS;
-}
-
-#ifndef CONFIG_SUNOS_EMUL
-asmlinkage long sunos_syscall(struct pt_regs *regs)
-{
-       static int count;
-
-       regs->tpc = regs->tnpc;
-       regs->tnpc += 4;
-       if (test_thread_flag(TIF_32BIT)) {
-               regs->tpc &= 0xffffffff;
-               regs->tnpc &= 0xffffffff;
-       }
-       if (++count <= 20)
-               printk ("SunOS binary emulation not compiled in\n");
-       force_sig(SIGSEGV, current);
-
-       return -ENOSYS;
-}
-#endif
-
 asmlinkage long sys_utrap_install(utrap_entry_t type,
                                  utrap_handler_t new_p,
                                  utrap_handler_t new_d,
@@ -795,7 +725,7 @@ asmlinkage long sys_utrap_install(utrap_entry_t type,
        } else {
                if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
                    current_thread_info()->utraps[0] > 1) {
-                       long *p = current_thread_info()->utraps;
+                       unsigned long *p = current_thread_info()->utraps;
 
                        current_thread_info()->utraps =
                                kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
@@ -823,7 +753,8 @@ asmlinkage long sys_utrap_install(utrap_entry_t type,
        return 0;
 }
 
-long sparc_memory_ordering(unsigned long model, struct pt_regs *regs)
+asmlinkage long sparc_memory_ordering(unsigned long model,
+                                     struct pt_regs *regs)
 {
        if (model >= 3)
                return -EINVAL;
@@ -961,3 +892,23 @@ asmlinkage long sys_perfctr(int opcode, unsigned long arg0, unsigned long arg1,
        };
        return err;
 }
+
+/*
+ * Do a system call from kernel instead of calling sys_execve so we
+ * end up with proper pt_regs.
+ */
+int kernel_execve(const char *filename, char *const argv[], char *const envp[])
+{
+       long __res;
+       register long __g1 __asm__ ("g1") = __NR_execve;
+       register long __o0 __asm__ ("o0") = (long)(filename);
+       register long __o1 __asm__ ("o1") = (long)(argv);
+       register long __o2 __asm__ ("o2") = (long)(envp);
+       asm volatile ("t 0x6d\n\t"
+                     "sub %%g0, %%o0, %0\n\t"
+                     "movcc %%xcc, %%o0, %0\n\t"
+                     : "=r" (__res), "=&r" (__o0)
+                     : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
+                     : "cc");
+       return __res;
+}