0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/errno.h>
0010 #include <linux/types.h>
0011 #include <linux/sched/signal.h>
0012 #include <linux/sched/mm.h>
0013 #include <linux/sched/debug.h>
0014 #include <linux/mm.h>
0015 #include <linux/fs.h>
0016 #include <linux/file.h>
0017 #include <linux/sem.h>
0018 #include <linux/msg.h>
0019 #include <linux/shm.h>
0020 #include <linux/stat.h>
0021 #include <linux/syscalls.h>
0022 #include <linux/mman.h>
0023 #include <linux/utsname.h>
0024 #include <linux/smp.h>
0025 #include <linux/ipc.h>
0026
0027 #include <linux/uaccess.h>
0028 #include <asm/unistd.h>
0029
0030 #include "systbls.h"
0031
0032
0033
0034
0035
0036
0037 SYSCALL_DEFINE0(getpagesize)
0038 {
0039 return PAGE_SIZE;
0040 }
0041
0042 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
0043 {
0044 struct vm_unmapped_area_info info;
0045
0046 if (flags & MAP_FIXED) {
0047
0048
0049
0050 if ((flags & MAP_SHARED) &&
0051 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
0052 return -EINVAL;
0053 return addr;
0054 }
0055
0056
0057 if (len > TASK_SIZE - PAGE_SIZE)
0058 return -ENOMEM;
0059 if (!addr)
0060 addr = TASK_UNMAPPED_BASE;
0061
0062 info.flags = 0;
0063 info.length = len;
0064 info.low_limit = addr;
0065 info.high_limit = TASK_SIZE;
0066 info.align_mask = (flags & MAP_SHARED) ?
0067 (PAGE_MASK & (SHMLBA - 1)) : 0;
0068 info.align_offset = pgoff << PAGE_SHIFT;
0069 return vm_unmapped_area(&info);
0070 }
0071
0072
0073
0074
0075
0076 SYSCALL_DEFINE0(sparc_pipe)
0077 {
0078 int fd[2];
0079 int error;
0080
0081 error = do_pipe_flags(fd, 0);
0082 if (error)
0083 goto out;
0084 current_pt_regs()->u_regs[UREG_I1] = fd[1];
0085 error = fd[0];
0086 out:
0087 return error;
0088 }
0089
0090 int sparc_mmap_check(unsigned long addr, unsigned long len)
0091 {
0092
0093 if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
0094 return -EINVAL;
0095
0096 return 0;
0097 }
0098
0099
0100
0101 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
0102 unsigned long, prot, unsigned long, flags, unsigned long, fd,
0103 unsigned long, pgoff)
0104 {
0105
0106
0107 return ksys_mmap_pgoff(addr, len, prot, flags, fd,
0108 pgoff >> (PAGE_SHIFT - 12));
0109 }
0110
0111 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
0112 unsigned long, prot, unsigned long, flags, unsigned long, fd,
0113 unsigned long, off)
0114 {
0115
0116 return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
0117 }
0118
0119 SYSCALL_DEFINE5(sparc_remap_file_pages, unsigned long, start, unsigned long, size,
0120 unsigned long, prot, unsigned long, pgoff,
0121 unsigned long, flags)
0122 {
0123
0124
0125
0126 return sys_remap_file_pages(start, size, prot,
0127 (pgoff >> (PAGE_SHIFT - 12)), flags);
0128 }
0129
0130 SYSCALL_DEFINE0(nis_syscall)
0131 {
0132 static int count = 0;
0133 struct pt_regs *regs = current_pt_regs();
0134
0135 if (count++ > 5)
0136 return -ENOSYS;
0137 printk ("%s[%d]: Unimplemented SPARC system call %d\n",
0138 current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
0139 #ifdef DEBUG_UNIMP_SYSCALL
0140 show_regs (regs);
0141 #endif
0142 return -ENOSYS;
0143 }
0144
0145
0146
0147 asmlinkage void
0148 sparc_breakpoint (struct pt_regs *regs)
0149 {
0150
0151 #ifdef DEBUG_SPARC_BREAKPOINT
0152 printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
0153 #endif
0154 force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc);
0155
0156 #ifdef DEBUG_SPARC_BREAKPOINT
0157 printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
0158 #endif
0159 }
0160
0161 SYSCALL_DEFINE3(sparc_sigaction, int, sig,
0162 struct old_sigaction __user *,act,
0163 struct old_sigaction __user *,oact)
0164 {
0165 WARN_ON_ONCE(sig >= 0);
0166 return sys_sigaction(-sig, act, oact);
0167 }
0168
0169 SYSCALL_DEFINE5(rt_sigaction, int, sig,
0170 const struct sigaction __user *, act,
0171 struct sigaction __user *, oact,
0172 void __user *, restorer,
0173 size_t, sigsetsize)
0174 {
0175 struct k_sigaction new_ka, old_ka;
0176 int ret;
0177
0178
0179 if (sigsetsize != sizeof(sigset_t))
0180 return -EINVAL;
0181
0182 if (act) {
0183 new_ka.ka_restorer = restorer;
0184 if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
0185 return -EFAULT;
0186 }
0187
0188 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
0189
0190 if (!ret && oact) {
0191 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
0192 return -EFAULT;
0193 }
0194
0195 return ret;
0196 }
0197
0198 SYSCALL_DEFINE2(getdomainname, char __user *, name, int, len)
0199 {
0200 int nlen, err;
0201 char tmp[__NEW_UTS_LEN + 1];
0202
0203 if (len < 0)
0204 return -EINVAL;
0205
0206 down_read(&uts_sem);
0207
0208 nlen = strlen(utsname()->domainname) + 1;
0209 err = -EINVAL;
0210 if (nlen > len)
0211 goto out_unlock;
0212 memcpy(tmp, utsname()->domainname, nlen);
0213
0214 up_read(&uts_sem);
0215
0216 if (copy_to_user(name, tmp, nlen))
0217 return -EFAULT;
0218 return 0;
0219
0220 out_unlock:
0221 up_read(&uts_sem);
0222 return err;
0223 }