[PATCH] replace cad_pid by a struct pid
[pandora-kernel.git] / kernel / sys.c
index fc9ebbb..2314867 100644 (file)
@@ -4,7 +4,6 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/utsname.h>
@@ -13,7 +12,6 @@
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/prctl.h>
-#include <linux/init.h>
 #include <linux/highuid.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
@@ -30,6 +28,7 @@
 #include <linux/tty.h>
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
+#include <linux/getcpu.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
 #ifndef GET_FPEXC_CTL
 # define GET_FPEXC_CTL(a,b)    (-EINVAL)
 #endif
+#ifndef GET_ENDIAN
+# define GET_ENDIAN(a,b)       (-EINVAL)
+#endif
+#ifndef SET_ENDIAN
+# define SET_ENDIAN(a,b)       (-EINVAL)
+#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -87,7 +92,8 @@ EXPORT_SYMBOL(fs_overflowgid);
  */
 
 int C_A_D = 1;
-int cad_pid = 1;
+struct pid *cad_pid;
+EXPORT_SYMBOL(cad_pid);
 
 /*
  *     Notifier list for kernel code which wants to be called
@@ -132,14 +138,15 @@ static int __kprobes notifier_call_chain(struct notifier_block **nl,
                unsigned long val, void *v)
 {
        int ret = NOTIFY_DONE;
-       struct notifier_block *nb;
+       struct notifier_block *nb, *next_nb;
 
        nb = rcu_dereference(*nl);
        while (nb) {
+               next_nb = rcu_dereference(nb->next);
                ret = nb->notifier_call(nb, val, v);
                if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
                        break;
-               nb = rcu_dereference(nb->next);
+               nb = next_nb;
        }
        return ret;
 }
@@ -215,7 +222,7 @@ EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
  *     of the last notifier function called.
  */
  
-int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
+int __kprobes atomic_notifier_call_chain(struct atomic_notifier_head *nh,
                unsigned long val, void *v)
 {
        int ret;
@@ -583,7 +590,7 @@ void emergency_restart(void)
 }
 EXPORT_SYMBOL_GPL(emergency_restart);
 
-void kernel_restart_prepare(char *cmd)
+static void kernel_restart_prepare(char *cmd)
 {
        blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
        system_state = SYSTEM_RESTART;
@@ -601,12 +608,10 @@ void kernel_restart_prepare(char *cmd)
 void kernel_restart(char *cmd)
 {
        kernel_restart_prepare(cmd);
-       if (!cmd) {
+       if (!cmd)
                printk(KERN_EMERG "Restarting system.\n");
-       } else {
+       else
                printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
-       }
-       printk(".\n");
        machine_restart(cmd);
 }
 EXPORT_SYMBOL_GPL(kernel_restart);
@@ -617,21 +622,19 @@ EXPORT_SYMBOL_GPL(kernel_restart);
  *     Move into place and start executing a preloaded standalone
  *     executable.  If nothing was preloaded return an error.
  */
-void kernel_kexec(void)
+static void kernel_kexec(void)
 {
 #ifdef CONFIG_KEXEC
        struct kimage *image;
        image = xchg(&kexec_image, NULL);
-       if (!image) {
+       if (!image)
                return;
-       }
        kernel_restart_prepare(NULL);
        printk(KERN_EMERG "Starting new kernel\n");
        machine_shutdown();
        machine_kexec(image);
 #endif
 }
-EXPORT_SYMBOL_GPL(kernel_kexec);
 
 void kernel_shutdown_prepare(enum system_states state)
 {
@@ -771,10 +774,9 @@ void ctrl_alt_del(void)
        if (C_A_D)
                schedule_work(&cad_work);
        else
-               kill_proc(cad_pid, SIGINT, 1);
+               kill_cad_pid(SIGINT, 1);
 }
        
-
 /*
  * Unprivileged users may change the real gid to the effective gid
  * or vice versa.  (BSD-style)
@@ -819,12 +821,10 @@ asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
                    (current->sgid == egid) ||
                    capable(CAP_SETGID))
                        new_egid = egid;
-               else {
+               else
                        return -EPERM;
-               }
        }
-       if (new_egid != old_egid)
-       {
+       if (new_egid != old_egid) {
                current->mm->dumpable = suid_dumpable;
                smp_wmb();
        }
@@ -853,19 +853,14 @@ asmlinkage long sys_setgid(gid_t gid)
        if (retval)
                return retval;
 
-       if (capable(CAP_SETGID))
-       {
-               if(old_egid != gid)
-               {
+       if (capable(CAP_SETGID)) {
+               if (old_egid != gid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
                current->gid = current->egid = current->sgid = current->fsgid = gid;
-       }
-       else if ((gid == current->gid) || (gid == current->sgid))
-       {
-               if(old_egid != gid)
-               {
+       } else if ((gid == current->gid) || (gid == current->sgid)) {
+               if (old_egid != gid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
@@ -896,8 +891,7 @@ static int set_user(uid_t new_ruid, int dumpclear)
 
        switch_uid(new_user);
 
-       if(dumpclear)
-       {
+       if (dumpclear) {
                current->mm->dumpable = suid_dumpable;
                smp_wmb();
        }
@@ -953,8 +947,7 @@ asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
        if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
                return -EAGAIN;
 
-       if (new_euid != old_euid)
-       {
+       if (new_euid != old_euid) {
                current->mm->dumpable = suid_dumpable;
                smp_wmb();
        }
@@ -1004,8 +997,7 @@ asmlinkage long sys_setuid(uid_t uid)
        } else if ((uid != current->uid) && (uid != new_suid))
                return -EPERM;
 
-       if (old_euid != uid)
-       {
+       if (old_euid != uid) {
                current->mm->dumpable = suid_dumpable;
                smp_wmb();
        }
@@ -1050,8 +1042,7 @@ asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
                        return -EAGAIN;
        }
        if (euid != (uid_t) -1) {
-               if (euid != current->euid)
-               {
+               if (euid != current->euid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
@@ -1101,8 +1092,7 @@ asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
                        return -EPERM;
        }
        if (egid != (gid_t) -1) {
-               if (egid != current->egid)
-               {
+               if (egid != current->egid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
@@ -1147,10 +1137,8 @@ asmlinkage long sys_setfsuid(uid_t uid)
 
        if (uid == current->uid || uid == current->euid ||
            uid == current->suid || uid == current->fsuid || 
-           capable(CAP_SETUID))
-       {
-               if (uid != old_fsuid)
-               {
+           capable(CAP_SETUID)) {
+               if (uid != old_fsuid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
@@ -1178,10 +1166,8 @@ asmlinkage long sys_setfsgid(gid_t gid)
 
        if (gid == current->gid || gid == current->egid ||
            gid == current->sgid || gid == current->fsgid || 
-           capable(CAP_SETGID))
-       {
-               if (gid != old_fsgid)
-               {
+           capable(CAP_SETGID)) {
+               if (gid != old_fsgid) {
                        current->mm->dumpable = suid_dumpable;
                        smp_wmb();
                }
@@ -1317,9 +1303,9 @@ out:
 
 asmlinkage long sys_getpgid(pid_t pid)
 {
-       if (!pid) {
+       if (!pid)
                return process_group(current);
-       else {
+       else {
                int retval;
                struct task_struct *p;
 
@@ -1349,9 +1335,9 @@ asmlinkage long sys_getpgrp(void)
 
 asmlinkage long sys_getsid(pid_t pid)
 {
-       if (!pid) {
+       if (!pid)
                return current->signal->session;
-       else {
+       else {
                int retval;
                struct task_struct *p;
 
@@ -1359,7 +1345,7 @@ asmlinkage long sys_getsid(pid_t pid)
                p = find_task_by_pid(pid);
 
                retval = -ESRCH;
-               if(p) {
+               if (p) {
                        retval = security_task_getsid(p);
                        if (!retval)
                                retval = p->signal->session;
@@ -1427,9 +1413,9 @@ struct group_info *groups_alloc(int gidsetsize)
        group_info->nblocks = nblocks;
        atomic_set(&group_info->usage, 1);
 
-       if (gidsetsize <= NGROUPS_SMALL) {
+       if (gidsetsize <= NGROUPS_SMALL)
                group_info->blocks[0] = group_info->small_block;
-       else {
+       else {
                for (i = 0; i < nblocks; i++) {
                        gid_t *b;
                        b = (void *)__get_free_page(GFP_USER);
@@ -1485,7 +1471,7 @@ static int groups_to_user(gid_t __user *grouplist,
 /* fill a group_info from a user-space array - it must be allocated already */
 static int groups_from_user(struct group_info *group_info,
     gid_t __user *grouplist)
- {
+{
        int i;
        int count = group_info->ngroups;
 
@@ -1643,9 +1629,8 @@ asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
 int in_group_p(gid_t grp)
 {
        int retval = 1;
-       if (grp != current->fsgid) {
+       if (grp != current->fsgid)
                retval = groups_search(current->group_info, grp);
-       }
        return retval;
 }
 
@@ -1654,9 +1639,8 @@ EXPORT_SYMBOL(in_group_p);
 int in_egroup_p(gid_t grp)
 {
        int retval = 1;
-       if (grp != current->egid) {
+       if (grp != current->egid)
                retval = groups_search(current->group_info, grp);
-       }
        return retval;
 }
 
@@ -1671,7 +1655,7 @@ asmlinkage long sys_newuname(struct new_utsname __user * name)
        int errno = 0;
 
        down_read(&uts_sem);
-       if (copy_to_user(name,&system_utsname,sizeof *name))
+       if (copy_to_user(name, utsname(), sizeof *name))
                errno = -EFAULT;
        up_read(&uts_sem);
        return errno;
@@ -1689,8 +1673,8 @@ asmlinkage long sys_sethostname(char __user *name, int len)
        down_write(&uts_sem);
        errno = -EFAULT;
        if (!copy_from_user(tmp, name, len)) {
-               memcpy(system_utsname.nodename, tmp, len);
-               system_utsname.nodename[len] = 0;
+               memcpy(utsname()->nodename, tmp, len);
+               utsname()->nodename[len] = 0;
                errno = 0;
        }
        up_write(&uts_sem);
@@ -1706,11 +1690,11 @@ asmlinkage long sys_gethostname(char __user *name, int len)
        if (len < 0)
                return -EINVAL;
        down_read(&uts_sem);
-       i = 1 + strlen(system_utsname.nodename);
+       i = 1 + strlen(utsname()->nodename);
        if (i > len)
                i = len;
        errno = 0;
-       if (copy_to_user(name, system_utsname.nodename, i))
+       if (copy_to_user(name, utsname()->nodename, i))
                errno = -EFAULT;
        up_read(&uts_sem);
        return errno;
@@ -1735,8 +1719,8 @@ asmlinkage long sys_setdomainname(char __user *name, int len)
        down_write(&uts_sem);
        errno = -EFAULT;
        if (!copy_from_user(tmp, name, len)) {
-               memcpy(system_utsname.domainname, tmp, len);
-               system_utsname.domainname[len] = 0;
+               memcpy(utsname()->domainname, tmp, len);
+               utsname()->domainname[len] = 0;
                errno = 0;
        }
        up_write(&uts_sem);
@@ -1771,9 +1755,9 @@ asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *r
        task_lock(current->group_leader);
        x = current->signal->rlim[resource];
        task_unlock(current->group_leader);
-       if(x.rlim_cur > 0x7FFFFFFF)
+       if (x.rlim_cur > 0x7FFFFFFF)
                x.rlim_cur = 0x7FFFFFFF;
-       if(x.rlim_max > 0x7FFFFFFF)
+       if (x.rlim_max > 0x7FFFFFFF)
                x.rlim_max = 0x7FFFFFFF;
        return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
 }
@@ -1979,7 +1963,7 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                        error = current->mm->dumpable;
                        break;
                case PR_SET_DUMPABLE:
-                       if (arg2 < 0 || arg2 > 2) {
+                       if (arg2 < 0 || arg2 > 1) {
                                error = -EINVAL;
                                break;
                        }
@@ -2045,9 +2029,46 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                                return -EFAULT;
                        return 0;
                }
+               case PR_GET_ENDIAN:
+                       error = GET_ENDIAN(current, arg2);
+                       break;
+               case PR_SET_ENDIAN:
+                       error = SET_ENDIAN(current, arg2);
+                       break;
+
                default:
                        error = -EINVAL;
                        break;
        }
        return error;
 }
+
+asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep,
+                          struct getcpu_cache __user *cache)
+{
+       int err = 0;
+       int cpu = raw_smp_processor_id();
+       if (cpup)
+               err |= put_user(cpu, cpup);
+       if (nodep)
+               err |= put_user(cpu_to_node(cpu), nodep);
+       if (cache) {
+               /*
+                * The cache is not needed for this implementation,
+                * but make sure user programs pass something
+                * valid. vsyscall implementations can instead make
+                * good use of the cache. Only use t0 and t1 because
+                * these are available in both 32bit and 64bit ABI (no
+                * need for a compat_getcpu). 32bit has enough
+                * padding
+                */
+               unsigned long t0, t1;
+               get_user(t0, &cache->blob[0]);
+               get_user(t1, &cache->blob[1]);
+               t0++;
+               t1++;
+               put_user(t0, &cache->blob[0]);
+               put_user(t1, &cache->blob[1]);
+       }
+       return err ? -EFAULT : 0;
+}