[PATCH] ppc64: Fix PER_LINUX32 behaviour
authorPaul Mackerras <paulus@samba.org>
Wed, 8 Jun 2005 11:59:15 +0000 (21:59 +1000)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Wed, 8 Jun 2005 23:24:15 +0000 (16:24 -0700)
This patch fixes some bugs in the ppc64 PER_LINUX32 implementation,
noted by Juergen Kreileder:

* uname(2) doesn't respect PER_LINUX32, it returns 'ppc64' instead of 'ppc'
* Child processes of a PER_LINUX32 process don't inherit PER_LINUX32

Along the way I took the opportunity to move things around so that
sys_ppc32.c only has 32-bit syscall emulation functions and to remove
the obsolete "fakeppc" command line option.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/ppc64/kernel/misc.S
arch/ppc64/kernel/sys_ppc32.c
arch/ppc64/kernel/syscalls.c
include/asm-ppc64/elf.h

index b944717c1dbd97c7fdfd547a53be87dffec47862..e3c73b3425dc016447d7e417f536d7a66fde39c4 100644 (file)
@@ -792,7 +792,7 @@ _GLOBAL(sys_call_table32)
        .llong .compat_sys_newstat
        .llong .compat_sys_newlstat
        .llong .compat_sys_newfstat
-       .llong .sys_uname
+       .llong .sys32_uname
        .llong .sys_ni_syscall          /* 110 old iopl syscall */
        .llong .sys_vhangup
        .llong .sys_ni_syscall          /* old idle syscall */
index 7cf7a9600025bdfeb793fbb43dbb2b11c22ea743..9c8e317c598d0ed40e6fcd61c41d61abcd847a98 100644 (file)
@@ -791,31 +791,6 @@ asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
 }
 
 
-asmlinkage int ppc64_newuname(struct new_utsname __user * name)
-{
-       int errno = sys_newuname(name);
-
-       if (current->personality == PER_LINUX32 && !errno) {
-               if(copy_to_user(name->machine, "ppc\0\0", 8)) {
-                       errno = -EFAULT;
-               }
-       }
-       return errno;
-}
-
-asmlinkage int ppc64_personality(unsigned long personality)
-{
-       int ret;
-       if (current->personality == PER_LINUX32 && personality == PER_LINUX)
-               personality = PER_LINUX32;
-       ret = sys_personality(personality);
-       if (ret == PER_LINUX32)
-               ret = PER_LINUX;
-       return ret;
-}
-
-
-
 /* Note: it is necessary to treat mode as an unsigned int,
  * with the corresponding cast to a signed int to insure that the 
  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
@@ -1158,26 +1133,47 @@ asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
 }
 #endif
 
+asmlinkage int sys32_uname(struct old_utsname __user * name)
+{
+       int err = 0;
+       
+       down_read(&uts_sem);
+       if (copy_to_user(name, &system_utsname, sizeof(*name)))
+               err = -EFAULT;
+       up_read(&uts_sem);
+       if (!err && personality(current->personality) == PER_LINUX32) {
+               /* change "ppc64" to "ppc" */
+               if (__put_user(0, name->machine + 3)
+                   || __put_user(0, name->machine + 4))
+                       err = -EFAULT;
+       }
+       return err;
+}
+
 asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
 {
        int error;
-       
-       if (!name)
-               return -EFAULT;
+
        if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
                return -EFAULT;
   
        down_read(&uts_sem);
        error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
-       error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
-       error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
-       error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
-       error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
-       error -= __put_user(0,name->release+__OLD_UTS_LEN);
-       error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
-       error -= __put_user(0,name->version+__OLD_UTS_LEN);
-       error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
-       error = __put_user(0,name->machine+__OLD_UTS_LEN);
+       error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
+       error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
+       error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
+       error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
+       error |= __put_user(0,name->release+__OLD_UTS_LEN);
+       error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
+       error |= __put_user(0,name->version+__OLD_UTS_LEN);
+       error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
+       error |= __put_user(0,name->machine+__OLD_UTS_LEN);
+       if (personality(current->personality) == PER_LINUX32) {
+               /* change "ppc64" to "ppc" */
+               error |= __put_user(0, name->machine + 3);
+               error |= __put_user(0, name->machine + 4);
+       }
+       
        up_read(&uts_sem);
 
        error = error ? -EFAULT : 0;
index f2865ff8d2f93863c1d8eb4416f02a82e9a68ad2..a8cbb202b8cd482f8deb05e68287341600c44637 100644 (file)
@@ -199,24 +199,33 @@ out:
        return ret;
 }
 
-static int __init set_fakeppc(char *str)
+long ppc64_personality(unsigned long personality)
 {
-       if (*str)
-               return 0;
-       init_task.personality = PER_LINUX32;
-       return 1;
+       long ret;
+
+       if (personality(current->personality) == PER_LINUX32
+           && personality == PER_LINUX)
+               personality = PER_LINUX32;
+       ret = sys_personality(personality);
+       if (ret == PER_LINUX32)
+               ret = PER_LINUX;
+       return ret;
 }
-__setup("fakeppc", set_fakeppc);
 
-asmlinkage int sys_uname(struct old_utsname __user * name)
+long ppc64_newuname(struct new_utsname __user * name)
 {
-       int err = -EFAULT;
-       
+       int err = 0;
+
        down_read(&uts_sem);
-       if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
-               err = 0;
+       if (copy_to_user(name, &system_utsname, sizeof(*name)))
+               err = -EFAULT;
        up_read(&uts_sem);
-       
+       if (!err && personality(current->personality) == PER_LINUX32) {
+               /* change ppc64 to ppc */
+               if (__put_user(0, name->machine + 3)
+                   || __put_user(0, name->machine + 4))
+                       err = -EFAULT;
+       }
        return err;
 }
 
index 6c42d61bedd13447e219150362a0dbc7e058734a..085eedb956fe02f7a0f34c1cbea0895e476b00ee 100644 (file)
@@ -221,9 +221,7 @@ do {                                                                \
                set_thread_flag(TIF_ABI_PENDING);               \
        else                                                    \
                clear_thread_flag(TIF_ABI_PENDING);             \
-       if (ibcs2)                                              \
-               set_personality(PER_SVR4);                      \
-       else if (current->personality != PER_LINUX32)           \
+       if (personality(current->personality) != PER_LINUX32)   \
                set_personality(PER_LINUX);                     \
 } while (0)