blob: 5d3f7a119ed1e91a5baf6fe5af7a33d842146533 [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 */
18#include <asm/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>
28#include <linux/shm.h>
29
30typedef void (*syscall_t)(void);
31
32syscall_t sys_call_table[__NR_syscall_count] /* FIXME __cacheline_aligned */= {
33 [0 ... __NR_syscall_count - 1] = (syscall_t)&sys_ni_syscall,
34
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080035#define __SYSCALL(nr,symbol,nargs) [ nr ] = (syscall_t)symbol,
Chris Zankel2f72d4f2012-10-23 20:17:05 -070036#include <uapi/asm/unistd.h>
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080037};
38
Max Filippovde73b6b2012-12-22 06:35:04 +040039#define COLOUR_ALIGN(addr, pgoff) \
40 ((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
41 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
42
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080043asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
44{
45 unsigned long ret;
46 long err;
47
Will Deacon079a96a2012-07-30 14:42:38 -070048 err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
Chris Zankelfc4fb2a2006-12-10 02:18:52 -080049 if (err)
50 return err;
51 return (long)ret;
52}
53
Chris Zankel2f72d4f2012-10-23 20:17:05 -070054asmlinkage long xtensa_fadvise64_64(int fd, int advice,
55 unsigned long long offset, unsigned long long len)
Chris Zankelbc671aa2007-08-05 10:22:58 -070056{
57 return sys_fadvise64_64(fd, offset, len, advice);
58}
Max Filippovde73b6b2012-12-22 06:35:04 +040059
60unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
61 unsigned long len, unsigned long pgoff, unsigned long flags)
62{
63 struct vm_area_struct *vmm;
64
65 if (flags & MAP_FIXED) {
66 /* We do not accept a shared mapping if it would violate
67 * cache aliasing constraints.
68 */
69 if ((flags & MAP_SHARED) &&
70 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
71 return -EINVAL;
72 return addr;
73 }
74
75 if (len > TASK_SIZE)
76 return -ENOMEM;
77 if (!addr)
78 addr = TASK_UNMAPPED_BASE;
79
80 if (flags & MAP_SHARED)
81 addr = COLOUR_ALIGN(addr, pgoff);
82 else
83 addr = PAGE_ALIGN(addr);
84
85 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
86 /* At this point: (!vmm || addr < vmm->vm_end). */
87 if (TASK_SIZE - len < addr)
88 return -ENOMEM;
89 if (!vmm || addr + len <= vmm->vm_start)
90 return addr;
91 addr = vmm->vm_end;
92 if (flags & MAP_SHARED)
93 addr = COLOUR_ALIGN(addr, pgoff);
94 }
95}