1a88b5ba8SSam Ravnborg /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls. 2a88b5ba8SSam Ravnborg * 3a88b5ba8SSam Ravnborg * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 4a88b5ba8SSam Ravnborg * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net) 5a88b5ba8SSam Ravnborg * 6a88b5ba8SSam Ravnborg * These routines maintain argument size conversion between 32bit and 64bit 7a88b5ba8SSam Ravnborg * environment. 8a88b5ba8SSam Ravnborg */ 9a88b5ba8SSam Ravnborg 10a88b5ba8SSam Ravnborg #include <linux/kernel.h> 11a88b5ba8SSam Ravnborg #include <linux/sched.h> 12a88b5ba8SSam Ravnborg #include <linux/capability.h> 13a88b5ba8SSam Ravnborg #include <linux/fs.h> 14a88b5ba8SSam Ravnborg #include <linux/mm.h> 15a88b5ba8SSam Ravnborg #include <linux/file.h> 16a88b5ba8SSam Ravnborg #include <linux/signal.h> 17a88b5ba8SSam Ravnborg #include <linux/resource.h> 18a88b5ba8SSam Ravnborg #include <linux/times.h> 19a88b5ba8SSam Ravnborg #include <linux/smp.h> 20a88b5ba8SSam Ravnborg #include <linux/sem.h> 21a88b5ba8SSam Ravnborg #include <linux/msg.h> 22a88b5ba8SSam Ravnborg #include <linux/shm.h> 23a88b5ba8SSam Ravnborg #include <linux/uio.h> 24a88b5ba8SSam Ravnborg #include <linux/nfs_fs.h> 25a88b5ba8SSam Ravnborg #include <linux/quota.h> 26a88b5ba8SSam Ravnborg #include <linux/poll.h> 27a88b5ba8SSam Ravnborg #include <linux/personality.h> 28a88b5ba8SSam Ravnborg #include <linux/stat.h> 29a88b5ba8SSam Ravnborg #include <linux/filter.h> 30a88b5ba8SSam Ravnborg #include <linux/highmem.h> 31a88b5ba8SSam Ravnborg #include <linux/highuid.h> 32a88b5ba8SSam Ravnborg #include <linux/mman.h> 33a88b5ba8SSam Ravnborg #include <linux/ipv6.h> 34a88b5ba8SSam Ravnborg #include <linux/in.h> 35a88b5ba8SSam Ravnborg #include <linux/icmpv6.h> 36a88b5ba8SSam Ravnborg #include <linux/syscalls.h> 37a88b5ba8SSam Ravnborg #include <linux/sysctl.h> 38a88b5ba8SSam Ravnborg #include <linux/binfmts.h> 39a88b5ba8SSam Ravnborg #include <linux/dnotify.h> 40a88b5ba8SSam Ravnborg #include <linux/security.h> 41a88b5ba8SSam Ravnborg #include <linux/compat.h> 42a88b5ba8SSam Ravnborg #include <linux/vfs.h> 43a88b5ba8SSam Ravnborg #include <linux/ptrace.h> 445a0e3ad6STejun Heo #include <linux/slab.h> 45a88b5ba8SSam Ravnborg 46a88b5ba8SSam Ravnborg #include <asm/types.h> 47a88b5ba8SSam Ravnborg #include <asm/uaccess.h> 48a88b5ba8SSam Ravnborg #include <asm/fpumacro.h> 49a88b5ba8SSam Ravnborg #include <asm/mmu_context.h> 50a88b5ba8SSam Ravnborg #include <asm/compat_signal.h> 51a88b5ba8SSam Ravnborg 52a88b5ba8SSam Ravnborg asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low) 53a88b5ba8SSam Ravnborg { 54a88b5ba8SSam Ravnborg if ((int)high < 0) 55a88b5ba8SSam Ravnborg return -EINVAL; 56a88b5ba8SSam Ravnborg else 57a88b5ba8SSam Ravnborg return sys_truncate(path, (high << 32) | low); 58a88b5ba8SSam Ravnborg } 59a88b5ba8SSam Ravnborg 60a88b5ba8SSam Ravnborg asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low) 61a88b5ba8SSam Ravnborg { 62a88b5ba8SSam Ravnborg if ((int)high < 0) 63a88b5ba8SSam Ravnborg return -EINVAL; 64a88b5ba8SSam Ravnborg else 65a88b5ba8SSam Ravnborg return sys_ftruncate(fd, (high << 32) | low); 66a88b5ba8SSam Ravnborg } 67a88b5ba8SSam Ravnborg 68a88b5ba8SSam Ravnborg static int cp_compat_stat64(struct kstat *stat, 69a88b5ba8SSam Ravnborg struct compat_stat64 __user *statbuf) 70a88b5ba8SSam Ravnborg { 71a88b5ba8SSam Ravnborg int err; 72a88b5ba8SSam Ravnborg 73a88b5ba8SSam Ravnborg err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev); 74a88b5ba8SSam Ravnborg err |= put_user(stat->ino, &statbuf->st_ino); 75a88b5ba8SSam Ravnborg err |= put_user(stat->mode, &statbuf->st_mode); 76a88b5ba8SSam Ravnborg err |= put_user(stat->nlink, &statbuf->st_nlink); 77a7c1938eSEric W. Biederman err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid); 78a7c1938eSEric W. Biederman err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid); 79a88b5ba8SSam Ravnborg err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev); 80a88b5ba8SSam Ravnborg err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]); 81a88b5ba8SSam Ravnborg err |= put_user(stat->size, &statbuf->st_size); 82a88b5ba8SSam Ravnborg err |= put_user(stat->blksize, &statbuf->st_blksize); 83a88b5ba8SSam Ravnborg err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]); 84a88b5ba8SSam Ravnborg err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]); 85a88b5ba8SSam Ravnborg err |= put_user(stat->blocks, &statbuf->st_blocks); 86a88b5ba8SSam Ravnborg err |= put_user(stat->atime.tv_sec, &statbuf->st_atime); 87a88b5ba8SSam Ravnborg err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec); 88a88b5ba8SSam Ravnborg err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime); 89a88b5ba8SSam Ravnborg err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec); 90a88b5ba8SSam Ravnborg err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime); 91a88b5ba8SSam Ravnborg err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec); 92a88b5ba8SSam Ravnborg err |= put_user(0, &statbuf->__unused4); 93a88b5ba8SSam Ravnborg err |= put_user(0, &statbuf->__unused5); 94a88b5ba8SSam Ravnborg 95a88b5ba8SSam Ravnborg return err; 96a88b5ba8SSam Ravnborg } 97a88b5ba8SSam Ravnborg 98c7887325SDavid Howells asmlinkage long compat_sys_stat64(const char __user * filename, 99a88b5ba8SSam Ravnborg struct compat_stat64 __user *statbuf) 100a88b5ba8SSam Ravnborg { 101a88b5ba8SSam Ravnborg struct kstat stat; 102a88b5ba8SSam Ravnborg int error = vfs_stat(filename, &stat); 103a88b5ba8SSam Ravnborg 104a88b5ba8SSam Ravnborg if (!error) 105a88b5ba8SSam Ravnborg error = cp_compat_stat64(&stat, statbuf); 106a88b5ba8SSam Ravnborg return error; 107a88b5ba8SSam Ravnborg } 108a88b5ba8SSam Ravnborg 109c7887325SDavid Howells asmlinkage long compat_sys_lstat64(const char __user * filename, 110a88b5ba8SSam Ravnborg struct compat_stat64 __user *statbuf) 111a88b5ba8SSam Ravnborg { 112a88b5ba8SSam Ravnborg struct kstat stat; 113a88b5ba8SSam Ravnborg int error = vfs_lstat(filename, &stat); 114a88b5ba8SSam Ravnborg 115a88b5ba8SSam Ravnborg if (!error) 116a88b5ba8SSam Ravnborg error = cp_compat_stat64(&stat, statbuf); 117a88b5ba8SSam Ravnborg return error; 118a88b5ba8SSam Ravnborg } 119a88b5ba8SSam Ravnborg 120a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fstat64(unsigned int fd, 121a88b5ba8SSam Ravnborg struct compat_stat64 __user * statbuf) 122a88b5ba8SSam Ravnborg { 123a88b5ba8SSam Ravnborg struct kstat stat; 124a88b5ba8SSam Ravnborg int error = vfs_fstat(fd, &stat); 125a88b5ba8SSam Ravnborg 126a88b5ba8SSam Ravnborg if (!error) 127a88b5ba8SSam Ravnborg error = cp_compat_stat64(&stat, statbuf); 128a88b5ba8SSam Ravnborg return error; 129a88b5ba8SSam Ravnborg } 130a88b5ba8SSam Ravnborg 131c7887325SDavid Howells asmlinkage long compat_sys_fstatat64(unsigned int dfd, 132c7887325SDavid Howells const char __user *filename, 133a88b5ba8SSam Ravnborg struct compat_stat64 __user * statbuf, int flag) 134a88b5ba8SSam Ravnborg { 135a88b5ba8SSam Ravnborg struct kstat stat; 1360112fc22SOleg Drokin int error; 137a88b5ba8SSam Ravnborg 1380112fc22SOleg Drokin error = vfs_fstatat(dfd, filename, &stat, flag); 1390112fc22SOleg Drokin if (error) 140a88b5ba8SSam Ravnborg return error; 1410112fc22SOleg Drokin return cp_compat_stat64(&stat, statbuf); 142a88b5ba8SSam Ravnborg } 143a88b5ba8SSam Ravnborg 144a274bd49SAl Viro COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig, 145a274bd49SAl Viro struct compat_old_sigaction __user *,act, 146a274bd49SAl Viro struct compat_old_sigaction __user *,oact) 147a88b5ba8SSam Ravnborg { 148a88b5ba8SSam Ravnborg WARN_ON_ONCE(sig >= 0); 149a274bd49SAl Viro return compat_sys_sigaction(-sig, act, oact); 150a88b5ba8SSam Ravnborg } 151a88b5ba8SSam Ravnborg 152bdc40abfSAl Viro COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig, 153bdc40abfSAl Viro struct compat_sigaction __user *,act, 154bdc40abfSAl Viro struct compat_sigaction __user *,oact, 155bdc40abfSAl Viro void __user *,restorer, 156bdc40abfSAl Viro compat_size_t,sigsetsize) 157a88b5ba8SSam Ravnborg { 158a88b5ba8SSam Ravnborg struct k_sigaction new_ka, old_ka; 159a88b5ba8SSam Ravnborg int ret; 160a88b5ba8SSam Ravnborg compat_sigset_t set32; 161a88b5ba8SSam Ravnborg 162a88b5ba8SSam Ravnborg /* XXX: Don't preclude handling different sized sigset_t's. */ 163a88b5ba8SSam Ravnborg if (sigsetsize != sizeof(compat_sigset_t)) 164a88b5ba8SSam Ravnborg return -EINVAL; 165a88b5ba8SSam Ravnborg 166a88b5ba8SSam Ravnborg if (act) { 167a88b5ba8SSam Ravnborg u32 u_handler, u_restorer; 168a88b5ba8SSam Ravnborg 169a88b5ba8SSam Ravnborg new_ka.ka_restorer = restorer; 170a88b5ba8SSam Ravnborg ret = get_user(u_handler, &act->sa_handler); 171a88b5ba8SSam Ravnborg new_ka.sa.sa_handler = compat_ptr(u_handler); 172a88b5ba8SSam Ravnborg ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)); 173bdc40abfSAl Viro sigset_from_compat(&new_ka.sa.sa_mask, &set32); 174a88b5ba8SSam Ravnborg ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); 175a88b5ba8SSam Ravnborg ret |= __get_user(u_restorer, &act->sa_restorer); 176a88b5ba8SSam Ravnborg new_ka.sa.sa_restorer = compat_ptr(u_restorer); 177a88b5ba8SSam Ravnborg if (ret) 178a88b5ba8SSam Ravnborg return -EFAULT; 179a88b5ba8SSam Ravnborg } 180a88b5ba8SSam Ravnborg 181a88b5ba8SSam Ravnborg ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); 182a88b5ba8SSam Ravnborg 183a88b5ba8SSam Ravnborg if (!ret && oact) { 184bdc40abfSAl Viro sigset_to_compat(&set32, &old_ka.sa.sa_mask); 185a88b5ba8SSam Ravnborg ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler); 186a88b5ba8SSam Ravnborg ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)); 187a88b5ba8SSam Ravnborg ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); 188a88b5ba8SSam Ravnborg ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer); 189a88b5ba8SSam Ravnborg if (ret) 190a88b5ba8SSam Ravnborg ret = -EFAULT; 191a88b5ba8SSam Ravnborg } 192a88b5ba8SSam Ravnborg 193a88b5ba8SSam Ravnborg return ret; 194a88b5ba8SSam Ravnborg } 195a88b5ba8SSam Ravnborg 196a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pread64(unsigned int fd, 197a88b5ba8SSam Ravnborg char __user *ubuf, 198a88b5ba8SSam Ravnborg compat_size_t count, 199a88b5ba8SSam Ravnborg unsigned long poshi, 200a88b5ba8SSam Ravnborg unsigned long poslo) 201a88b5ba8SSam Ravnborg { 202a88b5ba8SSam Ravnborg return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo); 203a88b5ba8SSam Ravnborg } 204a88b5ba8SSam Ravnborg 205a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd, 206a88b5ba8SSam Ravnborg char __user *ubuf, 207a88b5ba8SSam Ravnborg compat_size_t count, 208a88b5ba8SSam Ravnborg unsigned long poshi, 209a88b5ba8SSam Ravnborg unsigned long poslo) 210a88b5ba8SSam Ravnborg { 211a88b5ba8SSam Ravnborg return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo); 212a88b5ba8SSam Ravnborg } 213a88b5ba8SSam Ravnborg 214a88b5ba8SSam Ravnborg asmlinkage long compat_sys_readahead(int fd, 215a88b5ba8SSam Ravnborg unsigned long offhi, 216a88b5ba8SSam Ravnborg unsigned long offlo, 217a88b5ba8SSam Ravnborg compat_size_t count) 218a88b5ba8SSam Ravnborg { 219a88b5ba8SSam Ravnborg return sys_readahead(fd, (offhi << 32) | offlo, count); 220a88b5ba8SSam Ravnborg } 221a88b5ba8SSam Ravnborg 222a88b5ba8SSam Ravnborg long compat_sys_fadvise64(int fd, 223a88b5ba8SSam Ravnborg unsigned long offhi, 224a88b5ba8SSam Ravnborg unsigned long offlo, 225a88b5ba8SSam Ravnborg compat_size_t len, int advice) 226a88b5ba8SSam Ravnborg { 227a88b5ba8SSam Ravnborg return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice); 228a88b5ba8SSam Ravnborg } 229a88b5ba8SSam Ravnborg 230a88b5ba8SSam Ravnborg long compat_sys_fadvise64_64(int fd, 231a88b5ba8SSam Ravnborg unsigned long offhi, unsigned long offlo, 232a88b5ba8SSam Ravnborg unsigned long lenhi, unsigned long lenlo, 233a88b5ba8SSam Ravnborg int advice) 234a88b5ba8SSam Ravnborg { 235a88b5ba8SSam Ravnborg return sys_fadvise64_64(fd, 236a88b5ba8SSam Ravnborg (offhi << 32) | offlo, 237a88b5ba8SSam Ravnborg (lenhi << 32) | lenlo, 238a88b5ba8SSam Ravnborg advice); 239a88b5ba8SSam Ravnborg } 240a88b5ba8SSam Ravnborg 241*2ae80c43SAl Viro long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, unsigned int flags) 242a88b5ba8SSam Ravnborg { 243a88b5ba8SSam Ravnborg return sys_sync_file_range(fd, 244a88b5ba8SSam Ravnborg (off_high << 32) | off_low, 245a88b5ba8SSam Ravnborg (nb_high << 32) | nb_low, 246a88b5ba8SSam Ravnborg flags); 247a88b5ba8SSam Ravnborg } 248a88b5ba8SSam Ravnborg 249a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, 250a88b5ba8SSam Ravnborg u32 lenhi, u32 lenlo) 251a88b5ba8SSam Ravnborg { 252a88b5ba8SSam Ravnborg return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, 253a88b5ba8SSam Ravnborg ((loff_t)lenhi << 32) | lenlo); 254a88b5ba8SSam Ravnborg } 255