Commit ca768667 authored by Chris Metcalf's avatar Chris Metcalf

tile 32-bit big-endian: fix bugs in syscall argument order

The glibc __LONG_LONG_PAIR passes arguments in a different
order for BE platforms vs LE platforms.  Adjust the expectations
in the kernel 32-bit syscall routines for BE to match.
Signed-off-by: default avatarChris Metcalf <cmetcalf@mellanox.com>
parent 9fbd49cf
...@@ -23,42 +23,50 @@ ...@@ -23,42 +23,50 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/signal.h> #include <linux/signal.h>
#include <asm/syscalls.h> #include <asm/syscalls.h>
#include <asm/byteorder.h>
/* /*
* Syscalls that take 64-bit numbers traditionally take them in 32-bit * Syscalls that take 64-bit numbers traditionally take them in 32-bit
* "high" and "low" value parts on 32-bit architectures. * "high" and "low" value parts on 32-bit architectures.
* In principle, one could imagine passing some register arguments as * In principle, one could imagine passing some register arguments as
* fully 64-bit on TILE-Gx in 32-bit mode, but it seems easier to * fully 64-bit on TILE-Gx in 32-bit mode, but it seems easier to
* adapt the usual convention. * adopt the usual convention.
*/ */
#ifdef __BIG_ENDIAN
#define SYSCALL_PAIR(name) u32, name ## _hi, u32, name ## _lo
#else
#define SYSCALL_PAIR(name) u32, name ## _lo, u32, name ## _hi
#endif
COMPAT_SYSCALL_DEFINE4(truncate64, char __user *, filename, u32, dummy, COMPAT_SYSCALL_DEFINE4(truncate64, char __user *, filename, u32, dummy,
u32, low, u32, high) SYSCALL_PAIR(length))
{ {
return sys_truncate(filename, ((loff_t)high << 32) | low); return sys_truncate(filename, ((loff_t)length_hi << 32) | length_lo);
} }
COMPAT_SYSCALL_DEFINE4(ftruncate64, unsigned int, fd, u32, dummy, COMPAT_SYSCALL_DEFINE4(ftruncate64, unsigned int, fd, u32, dummy,
u32, low, u32, high) SYSCALL_PAIR(length))
{ {
return sys_ftruncate(fd, ((loff_t)high << 32) | low); return sys_ftruncate(fd, ((loff_t)length_hi << 32) | length_lo);
} }
COMPAT_SYSCALL_DEFINE6(pread64, unsigned int, fd, char __user *, ubuf, COMPAT_SYSCALL_DEFINE6(pread64, unsigned int, fd, char __user *, ubuf,
size_t, count, u32, dummy, u32, low, u32, high) size_t, count, u32, dummy, SYSCALL_PAIR(offset))
{ {
return sys_pread64(fd, ubuf, count, ((loff_t)high << 32) | low); return sys_pread64(fd, ubuf, count,
((loff_t)offset_hi << 32) | offset_lo);
} }
COMPAT_SYSCALL_DEFINE6(pwrite64, unsigned int, fd, char __user *, ubuf, COMPAT_SYSCALL_DEFINE6(pwrite64, unsigned int, fd, char __user *, ubuf,
size_t, count, u32, dummy, u32, low, u32, high) size_t, count, u32, dummy, SYSCALL_PAIR(offset))
{ {
return sys_pwrite64(fd, ubuf, count, ((loff_t)high << 32) | low); return sys_pwrite64(fd, ubuf, count,
((loff_t)offset_hi << 32) | offset_lo);
} }
COMPAT_SYSCALL_DEFINE6(sync_file_range2, int, fd, unsigned int, flags, COMPAT_SYSCALL_DEFINE6(sync_file_range2, int, fd, unsigned int, flags,
u32, offset_lo, u32, offset_hi, SYSCALL_PAIR(offset), SYSCALL_PAIR(nbytes))
u32, nbytes_lo, u32, nbytes_hi)
{ {
return sys_sync_file_range(fd, ((loff_t)offset_hi << 32) | offset_lo, return sys_sync_file_range(fd, ((loff_t)offset_hi << 32) | offset_lo,
((loff_t)nbytes_hi << 32) | nbytes_lo, ((loff_t)nbytes_hi << 32) | nbytes_lo,
...@@ -66,8 +74,7 @@ COMPAT_SYSCALL_DEFINE6(sync_file_range2, int, fd, unsigned int, flags, ...@@ -66,8 +74,7 @@ COMPAT_SYSCALL_DEFINE6(sync_file_range2, int, fd, unsigned int, flags,
} }
COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode,
u32, offset_lo, u32, offset_hi, SYSCALL_PAIR(offset), SYSCALL_PAIR(len))
u32, len_lo, u32, len_hi)
{ {
return sys_fallocate(fd, mode, ((loff_t)offset_hi << 32) | offset_lo, return sys_fallocate(fd, mode, ((loff_t)offset_hi << 32) | offset_lo,
((loff_t)len_hi << 32) | len_lo); ((loff_t)len_hi << 32) | len_lo);
...@@ -77,6 +84,8 @@ COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, ...@@ -77,6 +84,8 @@ COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode,
* Avoid bug in generic sys_llseek() that specifies offset_high and * Avoid bug in generic sys_llseek() that specifies offset_high and
* offset_low as "unsigned long", thus making it possible to pass * offset_low as "unsigned long", thus making it possible to pass
* a sign-extended high 32 bits in offset_low. * a sign-extended high 32 bits in offset_low.
* Note that we do not use SYSCALL_PAIR here since glibc passes the
* high and low parts explicitly in that order.
*/ */
COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned int, offset_high, COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned int, offset_high,
unsigned int, offset_low, loff_t __user *, result, unsigned int, offset_low, loff_t __user *, result,
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/homecache.h> #include <asm/homecache.h>
#include <asm/cachectl.h> #include <asm/cachectl.h>
#include <asm/byteorder.h>
#include <arch/chip.h> #include <arch/chip.h>
SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len, SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len,
...@@ -59,13 +60,19 @@ SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len, ...@@ -59,13 +60,19 @@ SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len,
#if !defined(__tilegx__) || defined(CONFIG_COMPAT) #if !defined(__tilegx__) || defined(CONFIG_COMPAT)
ssize_t sys32_readahead(int fd, u32 offset_lo, u32 offset_hi, u32 count) #ifdef __BIG_ENDIAN
#define SYSCALL_PAIR(name) u32 name ## _hi, u32 name ## _lo
#else
#define SYSCALL_PAIR(name) u32 name ## _lo, u32 name ## _hi
#endif
ssize_t sys32_readahead(int fd, SYSCALL_PAIR(offset), u32 count)
{ {
return sys_readahead(fd, ((loff_t)offset_hi << 32) | offset_lo, count); return sys_readahead(fd, ((loff_t)offset_hi << 32) | offset_lo, count);
} }
int sys32_fadvise64_64(int fd, u32 offset_lo, u32 offset_hi, int sys32_fadvise64_64(int fd, SYSCALL_PAIR(offset),
u32 len_lo, u32 len_hi, int advice) SYSCALL_PAIR(len), int advice)
{ {
return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo, return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo,
((loff_t)len_hi << 32) | len_lo, advice); ((loff_t)len_hi << 32) | len_lo, advice);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment