blob: 74afbf02d07e8b3a7539235eeb2d5cfabe791230 [file] [log] [blame]
Chris Zankelfc4fb2a2006-12-10 02:18:52 -08001/*
2 * arch/xtensa/kernel/syscall.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Copyright (C) 2000 Silicon Graphics, Inc.
10 * Copyright (C) 1995 - 2000 by Ralf Baechle
11 *
12 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
13 * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14 * Chris Zankel <chris@zankel.net>
15 * Kevin Chea
16 *
17 */
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080018#include <linux/uaccess.h>
Chris Zankel1c0350b2006-12-13 00:34:32 -080019#include <asm/syscall.h>
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080020#include <asm/unistd.h>
21#include <linux/linkage.h>
22#include <linux/stringify.h>
23#include <linux/errno.h>
24#include <linux/syscalls.h>
25#include <linux/file.h>
26#include <linux/fs.h>
27#include <linux/mman.h>
Ingo Molnar01042602017-02-08 18:51:31 +010028#include <linux/sched/mm.h>
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080029#include <linux/shm.h>
30
31typedef void (*syscall_t)(void);
32
33syscall_t sys_call_table[__NR_syscall_count] /* FIXME __cacheline_aligned */= {
34 [0 ... __NR_syscall_count - 1] = (syscall_t)&sys_ni_syscall,
35
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080036#define __SYSCALL(nr,symbol,nargs) [ nr ] = (syscall_t)symbol,
Chris Zankel2f72d4f2012-10-23 20:17:05 -070037#include <uapi/asm/unistd.h>
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080038};
39
Max Filippovde73b6b2012-12-22 06:35:04 +040040#define COLOUR_ALIGN(addr, pgoff) \
41 ((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
42 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
43
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080044asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
45{
46 unsigned long ret;
47 long err;
48
Will Deacon079a96a2012-07-30 14:42:38 -070049 err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080050 if (err)
51 return err;
52 return (long)ret;
53}
54
Chris Zankel2f72d4f2012-10-23 20:17:05 -070055asmlinkage long xtensa_fadvise64_64(int fd, int advice,
56 unsigned long long offset, unsigned long long len)
Chris Zankelbc671aa2007-08-05 10:22:58 -070057{
58 return sys_fadvise64_64(fd, offset, len, advice);
59}
Max Filippovde73b6b2012-12-22 06:35:04 +040060
Max Filippovd10fa7c2014-09-22 07:21:48 +040061#ifdef CONFIG_MMU
Max Filippovde73b6b2012-12-22 06:35:04 +040062unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
63 unsigned long len, unsigned long pgoff, unsigned long flags)
64{
65 struct vm_area_struct *vmm;
66
67 if (flags & MAP_FIXED) {
68 /* We do not accept a shared mapping if it would violate
69 * cache aliasing constraints.
70 */
71 if ((flags & MAP_SHARED) &&
72 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
73 return -EINVAL;
74 return addr;
75 }
76
77 if (len > TASK_SIZE)
78 return -ENOMEM;
79 if (!addr)
80 addr = TASK_UNMAPPED_BASE;
81
82 if (flags & MAP_SHARED)
83 addr = COLOUR_ALIGN(addr, pgoff);
84 else
85 addr = PAGE_ALIGN(addr);
86
87 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
88 /* At this point: (!vmm || addr < vmm->vm_end). */
89 if (TASK_SIZE - len < addr)
90 return -ENOMEM;
Hugh Dickins1be71072017-06-19 04:03:24 -070091 if (!vmm || addr + len <= vm_start_gap(vmm))
Max Filippovde73b6b2012-12-22 06:35:04 +040092 return addr;
93 addr = vmm->vm_end;
94 if (flags & MAP_SHARED)
95 addr = COLOUR_ALIGN(addr, pgoff);
96 }
97}
Max Filippovd10fa7c2014-09-22 07:21:48 +040098#endif