[PATCH] powerpc: Add compat_sys_truncate

Chase Douglas cndougla at linux.vnet.ibm.com
Fri Jul 24 01:12:26 EST 2009


The truncate syscall has a signed long parameter, so when using a 32- 
bit userspace with a 64-bit kernel the argument is zero-extended  
instead of sign-extended. Adding the compat_sys_truncate function  
fixes the issue.

This was noticed during an LSB truncate test failure. The test was  
checking for the correct error number set when truncate is called with  
a length of -1. The test can be found at:

http://bzr.linuxfoundation.org/lsb/devel/runtime-test?cmd=inventory;rev=stewb%40linux-foundation.org-20090626205411-sfb23cc0tjj7jzgm;path=modules/vsx-pcts/tset/POSIX.os/files/truncate/

Signed-off-by: Chase Douglas <cndougla at linux.vnet.ibm.com>

diff --git a/arch/powerpc/include/asm/systbl.h b/arch/powerpc/include/ 
asm/systbl.h
index 370600c..3cca167 100644
--- a/arch/powerpc/include/asm/systbl.h
+++ b/arch/powerpc/include/asm/systbl.h
@@ -95,7 +95,7 @@ SYSCALL(reboot)
SYSX(sys_ni_syscall,compat_sys_old_readdir,sys_old_readdir)
SYSCALL_SPU(mmap)
SYSCALL_SPU(munmap)
-SYSCALL_SPU(truncate)
+COMPAT_SYS_SPU(truncate)
SYSCALL_SPU(ftruncate)
SYSCALL_SPU(fchmod)
SYSCALL_SPU(fchown)
diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/ 
sys_ppc32.c
index bb1cfcf..da9a65b 100644
--- a/arch/powerpc/kernel/sys_ppc32.c
+++ b/arch/powerpc/kernel/sys_ppc32.c
@@ -343,6 +343,12 @@ off_t ppc32_lseek(unsigned int fd, u32 offset,  
unsigned int origin)
        return sys_lseek(fd, (int)offset, origin);
}

+long compat_sys_truncate(const char __user * path, u32 length)
+{
+       /* sign extend length */
+       return sys_truncate(path, (int)length);
+}
+
/* Note: it is necessary to treat bufsiz 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)



More information about the Linuxppc-dev mailing list