0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kernel.h>
0012 #include <linux/sched.h>
0013 #include <linux/capability.h>
0014 #include <linux/fs.h>
0015 #include <linux/mm.h>
0016 #include <linux/file.h>
0017 #include <linux/signal.h>
0018 #include <linux/resource.h>
0019 #include <linux/times.h>
0020 #include <linux/smp.h>
0021 #include <linux/sem.h>
0022 #include <linux/msg.h>
0023 #include <linux/shm.h>
0024 #include <linux/uio.h>
0025 #include <linux/quota.h>
0026 #include <linux/poll.h>
0027 #include <linux/personality.h>
0028 #include <linux/stat.h>
0029 #include <linux/filter.h>
0030 #include <linux/highmem.h>
0031 #include <linux/highuid.h>
0032 #include <linux/mman.h>
0033 #include <linux/ipv6.h>
0034 #include <linux/in.h>
0035 #include <linux/icmpv6.h>
0036 #include <linux/syscalls.h>
0037 #include <linux/sysctl.h>
0038 #include <linux/binfmts.h>
0039 #include <linux/dnotify.h>
0040 #include <linux/security.h>
0041 #include <linux/compat.h>
0042 #include <linux/vfs.h>
0043 #include <linux/ptrace.h>
0044 #include <linux/slab.h>
0045
0046 #include <asm/types.h>
0047 #include <linux/uaccess.h>
0048 #include <asm/fpumacro.h>
0049 #include <asm/mmu_context.h>
0050 #include <asm/compat_signal.h>
0051
0052 #include "systbls.h"
0053
0054 COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, path, u32, high, u32, low)
0055 {
0056 return ksys_truncate(path, ((u64)high << 32) | low);
0057 }
0058
0059 COMPAT_SYSCALL_DEFINE3(ftruncate64, unsigned int, fd, u32, high, u32, low)
0060 {
0061 return ksys_ftruncate(fd, ((u64)high << 32) | low);
0062 }
0063
0064 static int cp_compat_stat64(struct kstat *stat,
0065 struct compat_stat64 __user *statbuf)
0066 {
0067 int err;
0068
0069 err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
0070 err |= put_user(stat->ino, &statbuf->st_ino);
0071 err |= put_user(stat->mode, &statbuf->st_mode);
0072 err |= put_user(stat->nlink, &statbuf->st_nlink);
0073 err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
0074 err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
0075 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
0076 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
0077 err |= put_user(stat->size, &statbuf->st_size);
0078 err |= put_user(stat->blksize, &statbuf->st_blksize);
0079 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
0080 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
0081 err |= put_user(stat->blocks, &statbuf->st_blocks);
0082 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
0083 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
0084 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
0085 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
0086 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
0087 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
0088 err |= put_user(0, &statbuf->__unused4);
0089 err |= put_user(0, &statbuf->__unused5);
0090
0091 return err;
0092 }
0093
0094 COMPAT_SYSCALL_DEFINE2(stat64, const char __user *, filename,
0095 struct compat_stat64 __user *, statbuf)
0096 {
0097 struct kstat stat;
0098 int error = vfs_stat(filename, &stat);
0099
0100 if (!error)
0101 error = cp_compat_stat64(&stat, statbuf);
0102 return error;
0103 }
0104
0105 COMPAT_SYSCALL_DEFINE2(lstat64, const char __user *, filename,
0106 struct compat_stat64 __user *, statbuf)
0107 {
0108 struct kstat stat;
0109 int error = vfs_lstat(filename, &stat);
0110
0111 if (!error)
0112 error = cp_compat_stat64(&stat, statbuf);
0113 return error;
0114 }
0115
0116 COMPAT_SYSCALL_DEFINE2(fstat64, unsigned int, fd,
0117 struct compat_stat64 __user *, statbuf)
0118 {
0119 struct kstat stat;
0120 int error = vfs_fstat(fd, &stat);
0121
0122 if (!error)
0123 error = cp_compat_stat64(&stat, statbuf);
0124 return error;
0125 }
0126
0127 COMPAT_SYSCALL_DEFINE4(fstatat64, unsigned int, dfd,
0128 const char __user *, filename,
0129 struct compat_stat64 __user *, statbuf, int, flag)
0130 {
0131 struct kstat stat;
0132 int error;
0133
0134 error = vfs_fstatat(dfd, filename, &stat, flag);
0135 if (error)
0136 return error;
0137 return cp_compat_stat64(&stat, statbuf);
0138 }
0139
0140 COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
0141 struct compat_old_sigaction __user *,act,
0142 struct compat_old_sigaction __user *,oact)
0143 {
0144 WARN_ON_ONCE(sig >= 0);
0145 return compat_sys_sigaction(-sig, act, oact);
0146 }
0147
0148 COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
0149 struct compat_sigaction __user *,act,
0150 struct compat_sigaction __user *,oact,
0151 void __user *,restorer,
0152 compat_size_t,sigsetsize)
0153 {
0154 struct k_sigaction new_ka, old_ka;
0155 int ret;
0156
0157
0158 if (sigsetsize != sizeof(compat_sigset_t))
0159 return -EINVAL;
0160
0161 if (act) {
0162 u32 u_handler, u_restorer;
0163
0164 new_ka.ka_restorer = restorer;
0165 ret = get_user(u_handler, &act->sa_handler);
0166 new_ka.sa.sa_handler = compat_ptr(u_handler);
0167 ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
0168 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
0169 ret |= get_user(u_restorer, &act->sa_restorer);
0170 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
0171 if (ret)
0172 return -EFAULT;
0173 }
0174
0175 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
0176
0177 if (!ret && oact) {
0178 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
0179 ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
0180 sizeof(oact->sa_mask));
0181 ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
0182 ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
0183 if (ret)
0184 ret = -EFAULT;
0185 }
0186
0187 return ret;
0188 }
0189
0190 COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, ubuf,
0191 compat_size_t, count, u32, poshi, u32, poslo)
0192 {
0193 return ksys_pread64(fd, ubuf, count, ((u64)poshi << 32) | poslo);
0194 }
0195
0196 COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, char __user *, ubuf,
0197 compat_size_t, count, u32, poshi, u32, poslo)
0198 {
0199 return ksys_pwrite64(fd, ubuf, count, ((u64)poshi << 32) | poslo);
0200 }
0201
0202 COMPAT_SYSCALL_DEFINE4(readahead, int, fd, u32, offhi, u32, offlo,
0203 compat_size_t, count)
0204 {
0205 return ksys_readahead(fd, ((u64)offhi << 32) | offlo, count);
0206 }
0207
0208 COMPAT_SYSCALL_DEFINE5(fadvise64, int, fd, u32, offhi, u32, offlo,
0209 compat_size_t, len, int, advice)
0210 {
0211 return ksys_fadvise64_64(fd, ((u64)offhi << 32) | offlo, len, advice);
0212 }
0213
0214 COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, u32, offhi, u32, offlo,
0215 u32, lenhi, u32, lenlo, int, advice)
0216 {
0217 return ksys_fadvise64_64(fd,
0218 ((u64)offhi << 32) | offlo,
0219 ((u64)lenhi << 32) | lenlo,
0220 advice);
0221 }
0222
0223 COMPAT_SYSCALL_DEFINE6(sync_file_range, unsigned int, fd, u32, off_high, u32, off_low,
0224 u32, nb_high, u32, nb_low, unsigned int, flags)
0225 {
0226 return ksys_sync_file_range(fd,
0227 ((u64)off_high << 32) | off_low,
0228 ((u64)nb_high << 32) | nb_low,
0229 flags);
0230 }
0231
0232 COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, u32, offhi, u32, offlo,
0233 u32, lenhi, u32, lenlo)
0234 {
0235 return ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
0236 ((loff_t)lenhi << 32) | lenlo);
0237 }